Skip to content

Commit 0f8b294

Browse files
Improve coreclr execution results
1 parent 759edbb commit 0f8b294

File tree

3 files changed

+67
-57
lines changed

3 files changed

+67
-57
lines changed

runtime/include/CoreClr.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,36 +136,36 @@ class CoreClr {
136136

137137
void CreateManagedHost();
138138

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

142-
void ExecuteManagedResourceUnload(const char* resourcePath, const char* resourceMain);
142+
bool ExecuteManagedResourceUnload(const char* resourcePath, const char* resourceMain);
143143

144144
private:
145145
#ifdef _WIN32
146146
HMODULE _coreClrLib;
147147
#else
148148
void* _coreClrLib;
149149
#endif
150-
char* runtimeDirectory;
151-
char* dotnetDirectory;
152-
coreclr_initialize_ptr _initializeCoreCLR;
150+
char* runtimeDirectory = nullptr;
151+
char* dotnetDirectory = nullptr;
152+
/*coreclr_initialize_ptr _initializeCoreCLR;
153153
coreclr_shutdown_2_ptr _shutdownCoreCLR;
154154
coreclr_create_delegate_ptr _createDelegate;
155155
coreclr_execute_assembly_ptr _executeAssembly;
156156
void* managedRuntimeHost;
157157
unsigned int managedDomainId;
158158
component_entry_point_fn ExecuteResourceDelegate;
159-
component_entry_point_fn ExecuteResourceUnloadDelegate;
160-
161-
hostfxr_initialize_for_runtime_config_fn _initializeFxr;
162-
hostfxr_get_runtime_delegate_fn _getDelegate;
163-
hostfxr_run_app_fn _runApp;
164-
hostfxr_initialize_for_dotnet_command_line_fn _initForCmd;
165-
hostfxr_close_fn _closeFxr;
166-
hostfxr_handle cxt;
159+
component_entry_point_fn ExecuteResourceUnloadDelegate;*/
160+
161+
hostfxr_initialize_for_runtime_config_fn _initializeFxr = nullptr;
162+
hostfxr_get_runtime_delegate_fn _getDelegate = nullptr;
163+
hostfxr_run_app_fn _runApp = nullptr;
164+
hostfxr_initialize_for_dotnet_command_line_fn _initForCmd = nullptr;
165+
hostfxr_close_fn _closeFxr = nullptr;
166+
hostfxr_handle cxt = nullptr;
167167
std::thread thread;
168-
alt::ICore* core;
168+
alt::ICore* core = nullptr;
169169
};
170170

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

runtime/src/CSharpResourceImpl.cpp

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,46 @@ CSharpResourceImpl::CSharpResourceImpl(alt::ICore* server, CoreClr* coreClr, alt
99
}
1010

1111
void CSharpResourceImpl::ResetDelegates() {
12-
MainDelegate = [](auto var, auto var2, auto var3, auto var4){ };
13-
OnCheckpointDelegate = [](auto var, auto var2, auto var3, auto var4){ };
14-
OnClientEventDelegate = [](auto var, auto var2, auto var3){ };
15-
OnPlayerConnectDelegate = [](auto var, auto var2, auto var3){ };
16-
OnPlayerDamageDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5, auto var6){ };
17-
OnPlayerDeathDelegate = [](auto var, auto var2, auto var3, auto var4){ };
18-
OnPlayerDisconnectDelegate = [](auto var, auto var2){ };
19-
OnPlayerRemoveDelegate = [](auto var){ };
20-
OnVehicleRemoveDelegate = [](auto var){ };
21-
OnServerEventDelegate = [](auto var, auto var2){ };
22-
OnPlayerChangeVehicleSeatDelegate = [](auto var, auto var2, auto var3, auto var4){ };
23-
OnPlayerEnterVehicleDelegate = [](auto var, auto var2, auto var3){ };
24-
OnPlayerLeaveVehicleDelegate = [](auto var, auto var2, auto var3){ };
25-
OnStopDelegate = [](){ };
26-
OnTickDelegate = [](){ };
27-
OnCreatePlayerDelegate = [](auto var, auto var2){ };
28-
OnRemovePlayerDelegate = [](auto var){ };
29-
OnCreateVehicleDelegate = [](auto var, auto var2){ };
30-
OnRemoveVehicleDelegate = [](auto var){ };
31-
OnCreateBlipDelegate = [](auto var){ };
32-
OnRemoveBlipDelegate = [](auto var){ };
33-
OnCreateCheckpointDelegate = [](auto var){ };
34-
OnRemoveCheckpointDelegate = [](auto var){ };
35-
OnCreateVoiceChannelDelegate = [](auto var){ };
36-
OnRemoveVoiceChannelDelegate = [](auto var){ };
37-
OnConsoleCommandDelegate = [](auto var, auto var2){ };
38-
OnMetaChangeDelegate = [](auto var, auto var2, auto var3, auto var4){ };
39-
OnSyncedMetaChangeDelegate = [](auto var, auto var2, auto var3, auto var4){ };
40-
OnCreateColShapeDelegate = [](auto var){ };
41-
OnRemoveColShapeDelegate = [](auto var){ };
42-
ColShapeDelegate = [](auto var, auto var2, auto var3, auto var4){ };
12+
MainDelegate = [](auto var, auto var2, auto var3, auto var4) {};
13+
OnCheckpointDelegate = [](auto var, auto var2, auto var3, auto var4) {};
14+
OnClientEventDelegate = [](auto var, auto var2, auto var3) {};
15+
OnPlayerConnectDelegate = [](auto var, auto var2, auto var3) {};
16+
OnPlayerDamageDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5, auto var6) {};
17+
OnPlayerDeathDelegate = [](auto var, auto var2, auto var3, auto var4) {};
18+
OnPlayerDisconnectDelegate = [](auto var, auto var2) {};
19+
OnPlayerRemoveDelegate = [](auto var) {};
20+
OnVehicleRemoveDelegate = [](auto var) {};
21+
OnServerEventDelegate = [](auto var, auto var2) {};
22+
OnPlayerChangeVehicleSeatDelegate = [](auto var, auto var2, auto var3, auto var4) {};
23+
OnPlayerEnterVehicleDelegate = [](auto var, auto var2, auto var3) {};
24+
OnPlayerLeaveVehicleDelegate = [](auto var, auto var2, auto var3) {};
25+
OnStopDelegate = []() {};
26+
OnTickDelegate = []() {};
27+
OnCreatePlayerDelegate = [](auto var, auto var2) {};
28+
OnRemovePlayerDelegate = [](auto var) {};
29+
OnCreateVehicleDelegate = [](auto var, auto var2) {};
30+
OnRemoveVehicleDelegate = [](auto var) {};
31+
OnCreateBlipDelegate = [](auto var) {};
32+
OnRemoveBlipDelegate = [](auto var) {};
33+
OnCreateCheckpointDelegate = [](auto var) {};
34+
OnRemoveCheckpointDelegate = [](auto var) {};
35+
OnCreateVoiceChannelDelegate = [](auto var) {};
36+
OnRemoveVoiceChannelDelegate = [](auto var) {};
37+
OnConsoleCommandDelegate = [](auto var, auto var2) {};
38+
OnMetaChangeDelegate = [](auto var, auto var2, auto var3, auto var4) {};
39+
OnSyncedMetaChangeDelegate = [](auto var, auto var2, auto var3, auto var4) {};
40+
OnCreateColShapeDelegate = [](auto var) {};
41+
OnRemoveColShapeDelegate = [](auto var) {};
42+
ColShapeDelegate = [](auto var, auto var2, auto var3, auto var4) {};
4343
}
4444

4545
bool CSharpResourceImpl::Start() {
4646
ResetDelegates();
47-
coreClr->ExecuteManagedResource(this->resource->GetPath().CStr(), this->resource->GetName().CStr(), this->resource->GetMain().CStr(),
48-
this->resource);
47+
if (!coreClr->ExecuteManagedResource(this->resource->GetPath().CStr(), this->resource->GetName().CStr(),
48+
this->resource->GetMain().CStr(),
49+
this->resource)) {
50+
return false;
51+
}
4952
if (MainDelegate == nullptr) return false;
5053
MainDelegate(this->server, this->resource, this->resource->GetName().CStr(), resource->GetMain().CStr());
5154
return true;
@@ -54,7 +57,9 @@ bool CSharpResourceImpl::Start() {
5457
bool CSharpResourceImpl::Stop() {
5558
if (OnStopDelegate == nullptr) return false;
5659
OnStopDelegate();
57-
coreClr->ExecuteManagedResourceUnload(this->resource->GetPath().CStr(), this->resource->GetMain().CStr());
60+
if (!coreClr->ExecuteManagedResourceUnload(this->resource->GetPath().CStr(), this->resource->GetMain().CStr())) {
61+
return false;
62+
}
5863
ResetDelegates();
5964
return true;
6065
}
@@ -285,15 +290,19 @@ void CSharpResource_Reload(CSharpResourceImpl* resource) {
285290
resource->OnStopDelegate();
286291
resource->coreClr->ExecuteManagedResourceUnload(resource->resource->GetPath().CStr(),
287292
resource->resource->GetMain().CStr());
288-
resource->coreClr->ExecuteManagedResource(resource->resource->GetPath().CStr(), resource->resource->GetName().CStr(),
293+
resource->coreClr->ExecuteManagedResource(resource->resource->GetPath().CStr(),
294+
resource->resource->GetName().CStr(),
289295
resource->resource->GetMain().CStr(), resource->resource);
290-
resource->MainDelegate(resource->server, resource->resource, resource->resource->GetName().CStr(), resource->resource->GetMain().CStr());
296+
resource->MainDelegate(resource->server, resource->resource, resource->resource->GetName().CStr(),
297+
resource->resource->GetMain().CStr());
291298
}
292299

293300
void CSharpResource_Load(CSharpResourceImpl* resource) {
294-
resource->coreClr->ExecuteManagedResource(resource->resource->GetPath().CStr(), resource->resource->GetName().CStr(),
301+
resource->coreClr->ExecuteManagedResource(resource->resource->GetPath().CStr(),
302+
resource->resource->GetName().CStr(),
295303
resource->resource->GetMain().CStr(), resource->resource);
296-
resource->MainDelegate(resource->server, resource->resource, resource->resource->GetName().CStr(), resource->resource->GetMain().CStr());
304+
resource->MainDelegate(resource->server, resource->resource, resource->resource->GetName().CStr(),
305+
resource->resource->GetMain().CStr());
297306
}
298307

299308
void CSharpResource_Unload(CSharpResourceImpl* resource) {

runtime/src/CoreClr.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ void CoreClr_SetResourceLoadDelegates(CoreClrDelegate_t resourceExecute, CoreClr
2121

2222
CoreClr::CoreClr(alt::ICore* core) {
2323
this->core = core;
24-
_initializeCoreCLR = nullptr;
24+
/*_initializeCoreCLR = nullptr;
2525
_shutdownCoreCLR = nullptr;
2626
_createDelegate = nullptr;
27-
_executeAssembly = nullptr;
27+
_executeAssembly = nullptr;*/
2828
#ifdef _WIN32
2929
char pf[MAX_PATH];
3030
SHGetSpecialFolderPath(
@@ -452,13 +452,13 @@ void CoreClr::CreateManagedHost() {
452452
thread = std::thread(thread_proc, userData);
453453
}
454454

455-
void CoreClr::ExecuteManagedResource(const char* resourcePath, const char* resourceName,
455+
bool CoreClr::ExecuteManagedResource(const char* resourcePath, const char* resourceName,
456456
const char* resourceMain, alt::IResource* resource) {
457457
std::unique_lock<std::mutex> lck(mtx);
458458
while(hostResourceExecute == nullptr){ cv.wait(lck); }
459459
if (hostResourceExecute == nullptr) {
460460
core->LogInfo(alt::String("coreclr-module: Core CLR host not loaded"));
461-
return;
461+
return false;
462462
}
463463

464464
// Run managed code
@@ -481,9 +481,10 @@ void CoreClr::ExecuteManagedResource(const char* resourcePath, const char* resou
481481
};
482482

483483
hostResourceExecute(&args, sizeof(args));
484+
return true;
484485
}
485486

486-
void CoreClr::ExecuteManagedResourceUnload(const char* resourcePath, const char* resourceMain) {
487+
bool CoreClr::ExecuteManagedResourceUnload(const char* resourcePath, const char* resourceMain) {
487488
std::unique_lock<std::mutex> lck(mtx);
488489
while(hostResourceExecuteUnload == nullptr){ cv.wait(lck); }
489490
if (hostResourceExecuteUnload == nullptr) {

0 commit comments

Comments
 (0)