11#include " Runtime/MonoScript.h"
22
3-
43MonoScript* MonoScript::m_instance;
4+ MonoDomain* MonoScript::m_domain;
5+ MonoAssembly* MonoScript::m_asm;
6+ MonoImage* MonoScript::m_image;
57
68MonoScript::MonoScript () {
7-
9+ this ->m_domain = nullptr ;
10+ this ->m_asm = nullptr ;
11+ this ->m_image = nullptr ;
12+ this ->m_filename = " GameScripts.dll" ;
813}
914
1015void MonoScript::Init () {
16+ mono_set_dirs (" C:/Program Files/Mono/lib" , " C:/Program Files/Mono/etc" );
17+ this ->m_domain = mono_jit_init (" ExeonDomain" );
18+
19+ if (!this ->m_domain ) {
20+ spdlog::error (" Failed initializing Mono domain" );
21+ return ;
22+ }
23+
24+ spdlog::debug (" Mono domain initialized" );
25+
26+ char fullPath[MAX_PATH];
27+ GetFullPathName (this ->m_filename .c_str (), MAX_PATH, fullPath, nullptr );
1128
29+ this ->m_asm = mono_domain_assembly_open (this ->m_domain , fullPath);
30+ if (!this ->m_asm ) {
31+ spdlog::error (" Failed to read assembly {0}" , this ->m_filename );
32+ return ;
33+ }
34+
35+ spdlog::debug (" Mono domain assembly open" );
36+
37+ this ->m_image = mono_assembly_get_image (this ->m_asm );
38+
39+ MonoClass* gameScriptClass = mono_class_from_name (this ->m_image , " " , " GameScript" );
1240}
1341
1442void MonoScript::Update () {
1543
1644}
1745
1846MonoScript* MonoScript::GetInstance () {
19- if (MonoScript::m_instance == nullptr ) {
47+ if (MonoScript::m_instance == nullptr )
2048 MonoScript::m_instance = new MonoScript ();
21- }
2249 return MonoScript::m_instance;
2350}
0 commit comments