Skip to content

Commit d705602

Browse files
Cleanup coreclr
1 parent 68999b5 commit d705602

File tree

3 files changed

+30
-35
lines changed

3 files changed

+30
-35
lines changed

runtime/include/CoreClr.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ class CoreClr {
112112
/*bool GetDelegate(alt::ICore* server, void* runtimeHost, unsigned int domainId, const char* moduleName,
113113
const char* classPath, const char* methodName, void** callback);*/
114114

115-
alt::Array<alt::String> getTrustedAssemblies(alt::ICore* server, const char* appPath);
115+
//alt::Array<alt::String> getTrustedAssemblies(alt::ICore* server, const char* appPath);
116116

117117
/*void CreateAppDomain(alt::ICore* server, alt::IResource* resource, const char* appPath, void** runtimeHost,
118118
unsigned int* domainId, bool executable, uint64_t resourceIndex, const char* domainName);*/
119119

120-
int Execute(alt::ICore* server, alt::IResource* resource, const char* appPath, uint64_t resourceIndex,
120+
/*int Execute(alt::ICore* server, alt::IResource* resource, const char* appPath, uint64_t resourceIndex,
121121
void** runtimeHost,
122-
const unsigned int* domainId);
122+
const unsigned int* domainId);*/
123123

124124
/*void Shutdown(alt::ICore* server, void* runtimeHost,
125125
unsigned int domainId);*/
@@ -136,10 +136,10 @@ class CoreClr {
136136

137137
void CreateManagedHost();
138138

139-
void ExecuteManagedResource(alt::ICore* server, const char* resourcePath, const char* resourceName,
139+
void ExecuteManagedResource(const char* resourcePath, const char* resourceName,
140140
const char* resourceMain, alt::IResource* resource);
141141

142-
void ExecuteManagedResourceUnload(alt::ICore* server, const char* resourcePath, const char* resourceMain);
142+
void ExecuteManagedResourceUnload(const char* resourcePath, const char* resourceMain);
143143

144144
private:
145145
#ifdef _WIN32
@@ -165,6 +165,7 @@ class CoreClr {
165165
hostfxr_close_fn _closeFxr;
166166
hostfxr_handle cxt;
167167
std::thread thread;
168+
alt::ICore* core;
168169
};
169170

170171
EXPORT void CoreClr_SetResourceLoadDelegates(CoreClrDelegate_t resourceExecute, CoreClrDelegate_t resourceExecuteUnload);

runtime/src/CSharpResourceImpl.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ CSharpResourceImpl::CSharpResourceImpl(alt::ICore* server, CoreClr* coreClr, alt
77
this->invokers = new alt::Array<CustomInvoker*>();
88
this->coreClr = coreClr;
99

10-
//auto isDll = true;
11-
12-
/*auto mainSize = main.GetSize();
13-
if (mainSize < 5 || memcmp(main.CStr() + mainSize - 4, ".dll", 4) != 0) {
14-
isDll = false;
15-
}*/
16-
1710
runtimeHost = nullptr;
1811
domainId = 0;
1912
MainDelegate = nullptr;
@@ -50,7 +43,7 @@ CSharpResourceImpl::CSharpResourceImpl(alt::ICore* server, CoreClr* coreClr, alt
5043
}
5144

5245
bool CSharpResourceImpl::Start() {
53-
coreClr->ExecuteManagedResource(server, this->resource->GetPath().CStr(), this->resource->GetName().CStr(), this->resource->GetMain().CStr(),
46+
coreClr->ExecuteManagedResource(this->resource->GetPath().CStr(), this->resource->GetName().CStr(), this->resource->GetMain().CStr(),
5447
this->resource);
5548
if (MainDelegate == nullptr) return false;
5649
MainDelegate(this->server, this->resource, this->resource->GetName().CStr(), resource->GetMain().CStr());
@@ -65,7 +58,7 @@ bool CSharpResourceImpl::Stop() {
6558
delete invokers;
6659
if (OnStopDelegate == nullptr) return false;
6760
OnStopDelegate();
68-
coreClr->ExecuteManagedResourceUnload(server, this->resource->GetPath().CStr(), this->resource->GetMain().CStr());
61+
coreClr->ExecuteManagedResourceUnload(this->resource->GetPath().CStr(), this->resource->GetMain().CStr());
6962
return true;
7063
}
7164

@@ -310,22 +303,22 @@ void CSharpResourceImpl::OnTick() {
310303

311304
void CSharpResource_Reload(CSharpResourceImpl* resource) {
312305
resource->OnStopDelegate();
313-
resource->coreClr->ExecuteManagedResourceUnload(resource->server, resource->resource->GetPath().CStr(),
306+
resource->coreClr->ExecuteManagedResourceUnload(resource->resource->GetPath().CStr(),
314307
resource->resource->GetMain().CStr());
315-
resource->coreClr->ExecuteManagedResource(resource->server, resource->resource->GetPath().CStr(), resource->resource->GetName().CStr(),
308+
resource->coreClr->ExecuteManagedResource(resource->resource->GetPath().CStr(), resource->resource->GetName().CStr(),
316309
resource->resource->GetMain().CStr(), resource->resource);
317310
resource->MainDelegate(resource->server, resource->resource, resource->resource->GetName().CStr(), resource->resource->GetMain().CStr());
318311
}
319312

320313
void CSharpResource_Load(CSharpResourceImpl* resource) {
321-
resource->coreClr->ExecuteManagedResource(resource->server, resource->resource->GetPath().CStr(), resource->resource->GetName().CStr(),
314+
resource->coreClr->ExecuteManagedResource(resource->resource->GetPath().CStr(), resource->resource->GetName().CStr(),
322315
resource->resource->GetMain().CStr(), resource->resource);
323316
resource->MainDelegate(resource->server, resource->resource, resource->resource->GetName().CStr(), resource->resource->GetMain().CStr());
324317
}
325318

326319
void CSharpResource_Unload(CSharpResourceImpl* resource) {
327320
resource->OnStopDelegate();
328-
resource->coreClr->ExecuteManagedResourceUnload(resource->server, resource->resource->GetPath().CStr(),
321+
resource->coreClr->ExecuteManagedResourceUnload(resource->resource->GetPath().CStr(),
329322
resource->resource->GetMain().CStr());
330323
}
331324

runtime/src/CoreClr.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ void CoreClr_SetResourceLoadDelegates(CoreClrDelegate_t resourceExecute, CoreClr
1919
cv.notify_all();
2020
}
2121

22-
CoreClr::CoreClr(alt::ICore* server) {
22+
CoreClr::CoreClr(alt::ICore* core) {
23+
this->core = core;
2324
_initializeCoreCLR = nullptr;
2425
_shutdownCoreCLR = nullptr;
2526
_createDelegate = nullptr;
@@ -48,7 +49,7 @@ CoreClr::CoreClr(alt::ICore* server) {
4849
auto currDotnetDirectory = "/usr/share/dotnet/";
4950
dotnetDirectory = new char[strlen(currDotnetDirectory) + 1];
5051
strcpy(dotnetDirectory, currDotnetDirectory);
51-
GetPath(server, "/usr/share/dotnet/host/fxr/");
52+
GetPath(core, "/usr/share/dotnet/host/fxr/");
5253
#endif
5354
#ifdef _WIN32
5455
const char *fileName = "/hostfxr.dll";
@@ -76,7 +77,7 @@ CoreClr::CoreClr(alt::ICore* server) {
7677
strcat(fullPath, fileName);
7778
_coreClrLib = dlopen(fullPath, RTLD_NOW | RTLD_LOCAL);
7879
if (_coreClrLib == nullptr) {
79-
server->LogInfo(alt::String("coreclr-module: Unable to find CoreCLR dll [") + fullPath + "]: " + dlerror());
80+
core->LogInfo(alt::String("coreclr-module: Unable to find CoreCLR dll [") + fullPath + "]: " + dlerror());
8081
return;
8182
}
8283
_initializeFxr = (hostfxr_initialize_for_runtime_config_fn) dlsym(_coreClrLib,
@@ -89,7 +90,7 @@ CoreClr::CoreClr(alt::ICore* server) {
8990
#endif
9091
if (_initializeFxr == nullptr || _getDelegate == nullptr || _closeFxr == nullptr || _runApp == nullptr ||
9192
_initForCmd == nullptr) {
92-
server->LogInfo(alt::String("coreclr-module: Unable to find CoreCLR dll methods"));
93+
core->LogInfo(alt::String("coreclr-module: Unable to find CoreCLR dll methods"));
9394
return;
9495
}
9596
}
@@ -124,11 +125,11 @@ CoreClr::~CoreClr() {
124125
}*/
125126

126127
//TODO: don't include own dll or exe ect that is in the directory
127-
alt::Array<alt::String> CoreClr::getTrustedAssemblies(alt::ICore* server, const char* appPath) {
128+
/*alt::Array<alt::String> CoreClr::getTrustedAssemblies(alt::ICore* server, const char* appPath) {
128129
alt::Array<alt::String> assemblies;
129130
const char* const tpaExtensions[] = {".ni.dll", ".dll", ".ni.exe", ".exe", ".winmd"};
130131
131-
const char* directories[] = {runtimeDirectory/*, appPath*/ };
132+
const char* directories[] = {runtimeDirectory//, appPath// };
132133
133134
for (auto path : directories) {
134135
auto directory = opendir(path);
@@ -181,9 +182,9 @@ alt::Array<alt::String> CoreClr::getTrustedAssemblies(alt::ICore* server, const
181182
//std::string filenameWithoutExt(filename.substr(0, extPos));
182183
183184
// Ensure assemblies are unique in the list
184-
/*if (assemblies.find(filenameWithoutExt) != assemblies.end()) {//TODO: use alt::Set which doesnt exists
185-
continue;
186-
}*/
185+
//if (assemblies.find(filenameWithoutExt) != assemblies.end()) {//TODO: use alt::Set which doesnt exists
186+
// continue;
187+
//}
187188
188189
if (strcmp(entry->d_name, "AltV.Net.dll") == 0) {
189190
continue;
@@ -199,7 +200,7 @@ alt::Array<alt::String> CoreClr::getTrustedAssemblies(alt::ICore* server, const
199200
#endif
200201
}
201202
return assemblies;
202-
}
203+
}*/
203204

204205
//TODO: use APP_PATHS via path from main assembly because all assemblies are most likely in same path
205206
/*void CoreClr::CreateAppDomain(alt::ICore* server, alt::IResource* resource, const char* appPath, void** runtimeHost,
@@ -276,7 +277,7 @@ alt::Array<alt::String> CoreClr::getTrustedAssemblies(alt::ICore* server, const
276277
}
277278
}*/
278279

279-
int CoreClr::Execute(alt::ICore* server, alt::IResource* resource, const char* appPath, uint64_t resourceIndex,
280+
/*int CoreClr::Execute(alt::ICore* server, alt::IResource* resource, const char* appPath, uint64_t resourceIndex,
280281
void** runtimeHost,
281282
const unsigned int* domainId) {
282283
auto executablePath = alt::String(appPath) + PATH_SEPARATOR + resource->GetMain();
@@ -305,7 +306,7 @@ int CoreClr::Execute(alt::ICore* server, alt::IResource* resource, const char* a
305306
server->LogInfo(alt::String("coreclr-module: Assembly executed"));
306307
}
307308
return result;
308-
}
309+
}*/
309310

310311
/*void CoreClr::Shutdown(alt::ICore* server, void* runtimeHost,
311312
unsigned int domainId) {
@@ -451,12 +452,12 @@ void CoreClr::CreateManagedHost() {
451452
thread = std::thread(thread_proc, userData);
452453
}
453454

454-
void CoreClr::ExecuteManagedResource(alt::ICore* server, const char* resourcePath, const char* resourceName,
455+
void CoreClr::ExecuteManagedResource(const char* resourcePath, const char* resourceName,
455456
const char* resourceMain, alt::IResource* resource) {
456457
std::unique_lock<std::mutex> lck(mtx);
457458
while(hostResourceExecute == nullptr){ cv.wait(lck); }
458459
if (hostResourceExecute == nullptr) {
459-
server->LogInfo(alt::String("coreclr-module: Core CLR host not loaded"));
460+
core->LogInfo(alt::String("coreclr-module: Core CLR host not loaded"));
460461
return;
461462
}
462463

@@ -475,18 +476,18 @@ void CoreClr::ExecuteManagedResource(alt::ICore* server, const char* resourcePat
475476
resourcePath,
476477
resourceName,
477478
resourceMain,
478-
server,
479+
core,
479480
resource
480481
};
481482

482483
hostResourceExecute(&args, sizeof(args));
483484
}
484485

485-
void CoreClr::ExecuteManagedResourceUnload(alt::ICore* server, const char* resourcePath, const char* resourceMain) {
486+
void CoreClr::ExecuteManagedResourceUnload(const char* resourcePath, const char* resourceMain) {
486487
std::unique_lock<std::mutex> lck(mtx);
487488
while(hostResourceExecuteUnload == nullptr){ cv.wait(lck); }
488489
if (hostResourceExecuteUnload == nullptr) {
489-
server->LogInfo(alt::String("coreclr-module: Core CLR host not loaded"));
490+
core->LogInfo(alt::String("coreclr-module: Core CLR host not loaded"));
490491
return;
491492
}
492493

0 commit comments

Comments
 (0)