From 488bb0ed4cb429aa963be957a55d4afcdd36deb4 Mon Sep 17 00:00:00 2001 From: Kernell Date: Mon, 30 Nov 2015 06:23:18 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=B8=D0=B7=20=D0=BF=D1=83=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mta-mono/src/CMonoMTALib.cpp | 30 +++++++++++++++++++++++------- mta-mono/src/CMonoMTALib.h | 4 ++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/mta-mono/src/CMonoMTALib.cpp b/mta-mono/src/CMonoMTALib.cpp index 8bae72e..4e7480c 100644 --- a/mta-mono/src/CMonoMTALib.cpp +++ b/mta-mono/src/CMonoMTALib.cpp @@ -14,10 +14,15 @@ CMonoMTALib::CMonoMTALib( CMonoDomain* pDomain ) { + this->m_pClass = nullptr; + this->m_pObject = nullptr; + this->m_pAssembly = nullptr; this->m_pImage = nullptr; this->m_pDomain = pDomain; + this->m_uiGCHandle = 0; + string strPath( CMonoInterface::GetBinariesDirectory() + "/" + pDomain->GetResource()->GetName() + "/MultiTheftAuto.dll" ); this->m_pAssembly = pDomain->OpenAssembly( strPath.c_str() ); @@ -32,15 +37,13 @@ CMonoMTALib::CMonoMTALib( CMonoDomain* pDomain ) this->Vector2 = this->GetClass( "Vector2" ); this->Vector3 = this->GetClass( "Vector3" ); - MonoClass* pMonoClass = mono_class_from_name( this->m_pImage, "MultiTheftAuto", "MultiTheftAuto" ); + this->m_pClass = this->GetClass( "MultiTheftAuto" ); - if( pMonoClass ) + if( this->m_pClass ) { - MonoObject* pMonoObject = this->m_pDomain->CreateObject( pMonoClass ); - - mono_gchandle_new( pMonoObject, false ); - - mono_runtime_object_init( pMonoObject ); + this->m_pObject = this->m_pClass->New(); + + //this->m_uiGCHandle = mono_gchandle_new( this->m_pObject, true ); } } } @@ -48,9 +51,22 @@ CMonoMTALib::CMonoMTALib( CMonoDomain* pDomain ) CMonoMTALib::~CMonoMTALib( void ) { + if( this->m_uiGCHandle ) + { + mono_gchandle_free( this->m_uiGCHandle ); + + this->m_uiGCHandle = 0; + } + + SAFE_DELETE( this->Color ); + SAFE_DELETE( this->Vector2 ); + SAFE_DELETE( this->Vector3 ); + SAFE_DELETE( this->m_pClass ); + this->m_pDomain = nullptr; this->m_pAssembly = nullptr; this->m_pImage = nullptr; + this->m_pObject = nullptr; } CMonoClass* CMonoMTALib::GetClass( const char* szName ) diff --git a/mta-mono/src/CMonoMTALib.h b/mta-mono/src/CMonoMTALib.h index a602590..4b79639 100644 --- a/mta-mono/src/CMonoMTALib.h +++ b/mta-mono/src/CMonoMTALib.h @@ -23,8 +23,12 @@ class CMonoMTALib private: MonoAssembly* m_pAssembly; MonoImage* m_pImage; + MonoObject* m_pObject; + CMonoClass* m_pClass; CMonoDomain* m_pDomain; + uint32_t m_uiGCHandle; + public: CMonoClass* Color; CMonoClass* Vector2;