mirror of
https://github.com/ChronosX88/mta-mono.git
synced 2024-11-22 02:02:23 +00:00
Переведены в статические классы (не правильная реализация, утечка памяти)
This commit is contained in:
parent
7a155160f8
commit
7e62cf4d7e
@ -1,105 +1,100 @@
|
||||
#include "CMonoClass.h"
|
||||
|
||||
CMonoClass::CMonoClass( MonoClass* pMonoClass )
|
||||
{
|
||||
this->m_pMonoClass = pMonoClass;
|
||||
}
|
||||
|
||||
|
||||
CMonoClass::~CMonoClass()
|
||||
{
|
||||
}
|
||||
|
||||
CMonoObject* CMonoClass::New( MonoDomain* pMonoDomain )
|
||||
#include "CMonoClass.h"
|
||||
|
||||
MonoObject* CMonoClass::New( MonoClass* pMonoClass, MonoDomain* pMonoDomain )
|
||||
{
|
||||
MonoObject* pObject = mono_object_new( pMonoDomain, this->m_pMonoClass );
|
||||
MonoObject* pObject = mono_object_new( pMonoDomain, pMonoClass );
|
||||
|
||||
if( !pObject )
|
||||
{
|
||||
g_pModuleManager->ErrorPrintf( "%s:%d: Failed to create mono object for %s::%s\n", this->GetNameSpace(), this->GetName(), __FILE__, __LINE__ );
|
||||
g_pModuleManager->ErrorPrintf( "%s:%d: Failed to create mono object for %s::%s\n",
|
||||
CMonoClass::GetNameSpace( pMonoClass ),
|
||||
CMonoClass::GetName( pMonoClass ),
|
||||
__FILE__,
|
||||
__LINE__
|
||||
);
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
mono_runtime_object_init( pObject );
|
||||
|
||||
return new CMonoObject( pObject );
|
||||
}
|
||||
|
||||
CMonoObject* CMonoClass::New( MonoDomain* pMonoDomain, SColor& pColor )
|
||||
{
|
||||
void *args[] = { &pColor.R, &pColor.G, &pColor.B, &pColor.A };
|
||||
|
||||
return this->New( pMonoDomain, args, 4 );
|
||||
}
|
||||
|
||||
|
||||
CMonoObject* CMonoClass::New( MonoDomain* pMonoDomain, Vector2& vecVector )
|
||||
{
|
||||
void *args[] = { &vecVector.fX, &vecVector.fY };
|
||||
|
||||
return this->New( pMonoDomain, args, 2 );
|
||||
}
|
||||
|
||||
CMonoObject* CMonoClass::New( MonoDomain* pMonoDomain, Vector3& vecVector )
|
||||
{
|
||||
void *args[] = { &vecVector.fX, &vecVector.fY, &vecVector.fZ };
|
||||
|
||||
return this->New( pMonoDomain, args, 3 );
|
||||
}
|
||||
|
||||
CMonoObject* CMonoClass::New( MonoDomain* pMonoDomain, void** args, int argc )
|
||||
return pObject;
|
||||
}
|
||||
|
||||
MonoObject* CMonoClass::New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, SColor& pColor )
|
||||
{
|
||||
MonoObject* pObject = mono_object_new( pMonoDomain, this->m_pMonoClass );
|
||||
void *args[] = { &pColor.R, &pColor.G, &pColor.B, &pColor.A };
|
||||
|
||||
return CMonoClass::New( pMonoClass, pMonoDomain, args, 4 );
|
||||
}
|
||||
|
||||
|
||||
MonoObject* CMonoClass::New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, Vector2& vecVector )
|
||||
{
|
||||
void *args[] = { &vecVector.fX, &vecVector.fY };
|
||||
|
||||
return CMonoClass::New( pMonoClass, pMonoDomain, args, 2 );
|
||||
}
|
||||
|
||||
MonoObject* CMonoClass::New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, Vector3& vecVector )
|
||||
{
|
||||
void *args[] = { &vecVector.fX, &vecVector.fY, &vecVector.fZ };
|
||||
|
||||
return CMonoClass::New( pMonoClass, pMonoDomain, args, 3 );
|
||||
}
|
||||
|
||||
MonoObject* CMonoClass::New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, void** args, int argc )
|
||||
{
|
||||
MonoObject* pObject = mono_object_new( pMonoDomain, pMonoClass );
|
||||
|
||||
if( !pObject )
|
||||
{
|
||||
g_pModuleManager->ErrorPrintf( "%s:%d: Failed to create mono object for %s::%s\n", this->GetNameSpace(), this->GetName(), __FILE__, __LINE__ );
|
||||
g_pModuleManager->ErrorPrintf( "%s:%d: Failed to create mono object for %s::%s\n", GetNameSpace( pMonoClass ), GetName( pMonoClass ), __FILE__, __LINE__ );
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MonoMethod* pMonoMethod = this->GetMethod( ".ctor", argc );
|
||||
MonoMethod* pMonoMethod = CMonoClass::GetMethod( pMonoClass, ".ctor", argc );
|
||||
|
||||
if( !pMonoMethod )
|
||||
{
|
||||
g_pModuleManager->ErrorPrintf( "%s:%d: Could not lookup constructor for class %s::%s\n", this->GetNameSpace(), this->GetName(), __FILE__, __LINE__ );
|
||||
g_pModuleManager->ErrorPrintf( "%s:%d: Could not lookup constructor for class %s::%s\n", GetNameSpace( pMonoClass ), GetName( pMonoClass ), __FILE__, __LINE__ );
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
mono_runtime_invoke( pMonoMethod, pObject, args, NULL );
|
||||
|
||||
return new CMonoObject( pObject );
|
||||
}
|
||||
|
||||
const char* CMonoClass::GetName()
|
||||
{
|
||||
return mono_class_get_name( this->m_pMonoClass );
|
||||
}
|
||||
|
||||
const char* CMonoClass::GetNameSpace()
|
||||
{
|
||||
return mono_class_get_namespace( this->m_pMonoClass );
|
||||
}
|
||||
|
||||
MonoMethod* CMonoClass::GetMethod( const char* szMethodName, int iParamCount )
|
||||
{
|
||||
return mono_class_get_method_from_name( this->m_pMonoClass, szMethodName, iParamCount );
|
||||
}
|
||||
|
||||
MonoMethod* CMonoClass::GetMethod( const char* szMethodName )
|
||||
mono_runtime_invoke( pMonoMethod, pObject, args, nullptr );
|
||||
|
||||
return pObject;
|
||||
}
|
||||
|
||||
const char* CMonoClass::GetName( MonoClass* pMonoClass )
|
||||
{
|
||||
return mono_class_get_name( pMonoClass );
|
||||
}
|
||||
|
||||
const char* CMonoClass::GetNameSpace( MonoClass* pMonoClass )
|
||||
{
|
||||
return mono_class_get_namespace( pMonoClass );
|
||||
}
|
||||
|
||||
MonoMethod* CMonoClass::GetMethod( MonoClass* pMonoClass, const char* szMethodName, int iParamCount )
|
||||
{
|
||||
return mono_class_get_method_from_name( pMonoClass, szMethodName, iParamCount );
|
||||
}
|
||||
|
||||
MonoMethod* CMonoClass::GetMethod( MonoClass* pMonoClass, const char* szMethodName )
|
||||
{
|
||||
MonoMethodDesc* pMonoMethodDesc = mono_method_desc_new( szMethodName, false );
|
||||
|
||||
if( pMonoMethodDesc )
|
||||
{
|
||||
MonoMethod* pMethod = mono_method_desc_search_in_class( pMonoMethodDesc, this->m_pMonoClass );
|
||||
MonoMethod* pMethod = mono_method_desc_search_in_class( pMonoMethodDesc, pMonoClass );
|
||||
|
||||
mono_method_desc_free( pMonoMethodDesc );
|
||||
|
||||
return pMethod;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
@ -1,40 +1,28 @@
|
||||
class CMonoClass;
|
||||
|
||||
#ifndef _C_MONO_CLASS
|
||||
#define _C_MONO_CLASS
|
||||
|
||||
#include "Common.h"
|
||||
#include "CMonoObject.h"
|
||||
|
||||
extern ILuaModuleManager10 *g_pModuleManager;
|
||||
|
||||
class CMonoClass
|
||||
{
|
||||
private:
|
||||
MonoClass* m_pMonoClass;
|
||||
|
||||
public:
|
||||
CMonoClass( MonoClass* pMonoClass );
|
||||
~CMonoClass();
|
||||
|
||||
CMonoObject* New( MonoDomain* pMonoDomain );
|
||||
CMonoObject* New( MonoDomain* pMonoDomain, SColor& pColor );
|
||||
CMonoObject* New( MonoDomain* pMonoDomain, Vector2& vecVector );
|
||||
CMonoObject* New( MonoDomain* pMonoDomain, Vector3& vecVector );
|
||||
CMonoObject* New( MonoDomain* pMonoDomain, void** args, int argc );
|
||||
|
||||
const char* GetName();
|
||||
const char* GetNameSpace();
|
||||
|
||||
MonoMethod* GetMethod( const char* szMethodName, int iParamCount );
|
||||
MonoMethod* GetMethod( const char* szMethodName );
|
||||
|
||||
MonoClass* GetMonoClass() { return this->m_pMonoClass; };
|
||||
|
||||
MonoClass* GetClass()
|
||||
{
|
||||
return this->m_pMonoClass;
|
||||
}
|
||||
};
|
||||
|
||||
class CMonoClass;
|
||||
|
||||
#ifndef _C_MONO_CLASS
|
||||
#define _C_MONO_CLASS
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
extern ILuaModuleManager10 *g_pModuleManager;
|
||||
|
||||
class CMonoClass
|
||||
{
|
||||
public:
|
||||
static MonoObject* New( MonoClass* pMonoClass, MonoDomain* pMonoDomain );
|
||||
static MonoObject* New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, SColor& pColor );
|
||||
static MonoObject* New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, Vector2& vecVector );
|
||||
static MonoObject* New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, Vector3& vecVector );
|
||||
static MonoObject* New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, void** args, int argc );
|
||||
|
||||
static const char* GetName( MonoClass* pMonoClass );
|
||||
static const char* GetNameSpace( MonoClass* pMonoClass );
|
||||
|
||||
static MonoMethod* GetMethod( MonoClass* pMonoClass, const char* szMethodName, int iParamCount );
|
||||
static MonoMethod* GetMethod( MonoClass* pMonoClass, const char* szMethodName );
|
||||
|
||||
static MonoClass* GetClass( MonoClass* pMonoClass );
|
||||
};
|
||||
|
||||
#endif
|
@ -1,82 +1,65 @@
|
||||
/*********************************************************
|
||||
*
|
||||
* Copyright © 2013, Innovation Roleplay Engine.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms,
|
||||
* with or without modification,
|
||||
* is permitted only for authors.
|
||||
*
|
||||
*********************************************************/
|
||||
|
||||
#include "CMonoObject.h"
|
||||
|
||||
CMonoObject::CMonoObject( MonoObject* pMonoObject )
|
||||
{
|
||||
this->m_pMonoObject = pMonoObject;
|
||||
}
|
||||
|
||||
|
||||
CMonoObject::~CMonoObject()
|
||||
{
|
||||
}
|
||||
|
||||
CMonoClass* CMonoObject::GetClass()
|
||||
{
|
||||
MonoClass* pMonoClass = mono_object_get_class( this->m_pMonoObject );
|
||||
|
||||
if( pMonoClass )
|
||||
{
|
||||
return new CMonoClass( pMonoClass );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MonoObject* CMonoObject::GetPropertyValue( const char* szPropertyName )
|
||||
{
|
||||
MonoClass* pMonoClass = mono_object_get_class( this->m_pMonoObject );
|
||||
|
||||
MonoProperty* pMonoProperty = mono_class_get_property_from_name( pMonoClass, szPropertyName );
|
||||
|
||||
if( !pMonoProperty )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mono_property_get_value( pMonoProperty, this->m_pMonoObject, NULL, NULL );
|
||||
}
|
||||
|
||||
bool CMonoObject::SetPropertyValue( const char* szPropertyName, int iValue )
|
||||
{
|
||||
return this->SetPropertyValue( szPropertyName, (void*)&iValue );
|
||||
}
|
||||
|
||||
bool CMonoObject::SetPropertyValue( const char* szPropertyName, float fValue )
|
||||
{
|
||||
return this->SetPropertyValue( szPropertyName, (void*)&fValue );
|
||||
}
|
||||
|
||||
bool CMonoObject::SetPropertyValue( const char* szPropertyName, char* szValue )
|
||||
{
|
||||
return this->SetPropertyValue( szPropertyName, mono_string_new( mono_domain_get(), szValue ) );
|
||||
}
|
||||
|
||||
bool CMonoObject::SetPropertyValue( const char* szPropertyName, gpointer gValue )
|
||||
{
|
||||
MonoClass* pMonoClass = mono_object_get_class( this->m_pMonoObject );
|
||||
|
||||
MonoProperty* pMonoProperty = mono_class_get_property_from_name( pMonoClass, szPropertyName );
|
||||
|
||||
if( !pMonoProperty )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
gpointer args[ 1 ] = { gValue };
|
||||
|
||||
mono_property_set_value( pMonoProperty, this->m_pMonoObject, args, NULL );
|
||||
|
||||
return true;
|
||||
/*********************************************************
|
||||
*
|
||||
* Copyright © 2013, Innovation Roleplay Engine.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms,
|
||||
* with or without modification,
|
||||
* is permitted only for authors.
|
||||
*
|
||||
*********************************************************/
|
||||
|
||||
#include "CMonoObject.h"
|
||||
|
||||
MonoClass* CMonoObject::GetClass( MonoObject* pObject )
|
||||
{
|
||||
return mono_object_get_class( pObject );
|
||||
}
|
||||
|
||||
MonoObject* CMonoObject::GetPropertyValue( MonoObject* pObject, const char* szPropertyName )
|
||||
{
|
||||
MonoClass* pMonoClass = mono_object_get_class( pObject );
|
||||
|
||||
MonoProperty* pMonoProperty = mono_class_get_property_from_name( pMonoClass, szPropertyName );
|
||||
|
||||
if( !pMonoProperty )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return mono_property_get_value( pMonoProperty, pObject, NULL, NULL );
|
||||
}
|
||||
|
||||
bool CMonoObject::SetPropertyValue( MonoObject* pObject, const char* szPropertyName, int iValue )
|
||||
{
|
||||
return CMonoObject::SetPropertyValue( pObject, szPropertyName, (void*)&iValue );
|
||||
}
|
||||
|
||||
bool CMonoObject::SetPropertyValue( MonoObject* pObject, const char* szPropertyName, float fValue )
|
||||
{
|
||||
return CMonoObject::SetPropertyValue( pObject, szPropertyName, (void*)&fValue );
|
||||
}
|
||||
|
||||
bool CMonoObject::SetPropertyValue( MonoObject* pObject, const char* szPropertyName, char* szValue )
|
||||
{
|
||||
return CMonoObject::SetPropertyValue( pObject, szPropertyName, mono_string_new( mono_domain_get(), szValue ) );
|
||||
}
|
||||
|
||||
bool CMonoObject::SetPropertyValue( MonoObject* pObject, const char* szPropertyName, gpointer gValue )
|
||||
{
|
||||
MonoClass* pMonoClass = mono_object_get_class( pObject );
|
||||
|
||||
MonoProperty* pMonoProperty = mono_class_get_property_from_name( pMonoClass, szPropertyName );
|
||||
|
||||
if( !pMonoProperty )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
gpointer args[ 1 ] = { gValue };
|
||||
|
||||
mono_property_set_value( pMonoProperty, pObject, args, NULL );
|
||||
|
||||
return true;
|
||||
}
|
@ -1,89 +1,60 @@
|
||||
/*********************************************************
|
||||
*
|
||||
* Copyright © 2013, Innovation Roleplay Engine.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms,
|
||||
* with or without modification,
|
||||
* is permitted only for authors.
|
||||
*
|
||||
*********************************************************/
|
||||
|
||||
class CMonoObject;
|
||||
|
||||
#ifndef _C_MONO_OBJECT
|
||||
#define _C_MONO_OBJECT
|
||||
|
||||
#include "Common.h"
|
||||
#include "CMonoClass.h"
|
||||
|
||||
class CMonoObject
|
||||
{
|
||||
private:
|
||||
MonoObject* m_pMonoObject;
|
||||
|
||||
public:
|
||||
CMonoObject( MonoObject* pMonoObject );
|
||||
~CMonoObject();
|
||||
|
||||
CMonoClass* GetClass();
|
||||
|
||||
bool SetPropertyValue( const char* szPropertyName, int iValue );
|
||||
bool SetPropertyValue( const char* szPropertyName, float fValue );
|
||||
bool SetPropertyValue( const char* szPropertyName, char* szValue );
|
||||
bool SetPropertyValue( const char* szPropertyName, gpointer gValue );
|
||||
|
||||
MonoObject* GetPropertyValue( const char* szPropertyName );
|
||||
|
||||
Vector2 GetVector2()
|
||||
{
|
||||
float fX = this->GetPropertyValue< float >( "X" );
|
||||
float fY = this->GetPropertyValue< float >( "Y" );
|
||||
|
||||
return Vector2( fX, fY );
|
||||
}
|
||||
|
||||
Vector3 GetVector3()
|
||||
{
|
||||
float fX = this->GetPropertyValue< float >( "X" );
|
||||
float fY = this->GetPropertyValue< float >( "Y" );
|
||||
float fZ = this->GetPropertyValue< float >( "Z" );
|
||||
|
||||
return Vector3( fX, fY, fZ );
|
||||
}
|
||||
|
||||
SColor GetColor()
|
||||
{
|
||||
SColor pColor;
|
||||
|
||||
pColor.R = this->GetPropertyValue< unsigned char >( "R" );
|
||||
pColor.G = this->GetPropertyValue< unsigned char >( "G" );
|
||||
pColor.B = this->GetPropertyValue< unsigned char >( "B" );
|
||||
pColor.A = this->GetPropertyValue< unsigned char >( "A" );
|
||||
|
||||
return pColor;
|
||||
}
|
||||
|
||||
template <class T> T GetPropertyValue( char* szPropertyName )
|
||||
/*********************************************************
|
||||
*
|
||||
* Copyright © 2013, Innovation Roleplay Engine.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms,
|
||||
* with or without modification,
|
||||
* is permitted only for authors.
|
||||
*
|
||||
*********************************************************/
|
||||
|
||||
class CMonoObject;
|
||||
|
||||
#ifndef _C_MONO_OBJECT
|
||||
#define _C_MONO_OBJECT
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
class CMonoObject
|
||||
{
|
||||
public:
|
||||
static MonoClass* GetClass( MonoObject* pMonoObject );
|
||||
|
||||
static bool SetPropertyValue( MonoObject* pMonoObject, const char* szPropertyName, int iValue );
|
||||
static bool SetPropertyValue( MonoObject* pMonoObject, const char* szPropertyName, float fValue );
|
||||
static bool SetPropertyValue( MonoObject* pMonoObject, const char* szPropertyName, char* szValue );
|
||||
static bool SetPropertyValue( MonoObject* pMonoObject, const char* szPropertyName, gpointer gValue );
|
||||
|
||||
static MonoObject* GetPropertyValue( MonoObject* pMonoObject, const char* szPropertyName );
|
||||
|
||||
static SColor GetColor( MonoObject* pMonoObject )
|
||||
{
|
||||
return *( reinterpret_cast<T*>( mono_object_unbox( this->GetPropertyValue( szPropertyName ) ) ) );
|
||||
}
|
||||
|
||||
void* GetValue()
|
||||
{
|
||||
return mono_object_unbox( this->m_pMonoObject );
|
||||
}
|
||||
|
||||
template <class T> T GetValue()
|
||||
SColor pColor;
|
||||
|
||||
pColor.R = GetPropertyValue< unsigned char >( pMonoObject, "R" );
|
||||
pColor.G = GetPropertyValue< unsigned char >( pMonoObject, "G" );
|
||||
pColor.B = GetPropertyValue< unsigned char >( pMonoObject, "B" );
|
||||
pColor.A = GetPropertyValue< unsigned char >( pMonoObject, "A" );
|
||||
|
||||
return pColor;
|
||||
}
|
||||
|
||||
template <class T> static T GetPropertyValue( MonoObject* pMonoObject, char* szPropertyName )
|
||||
{
|
||||
return *( reinterpret_cast<T*>( mono_object_unbox( this->m_pMonoObject ) ) );
|
||||
}
|
||||
|
||||
MonoObject *GetObject()
|
||||
{
|
||||
return this->m_pMonoObject;
|
||||
}
|
||||
};
|
||||
|
||||
return *( reinterpret_cast<T*>( mono_object_unbox( GetPropertyValue( pMonoObject, szPropertyName ) ) ) );
|
||||
}
|
||||
|
||||
static void* GetValue( MonoObject* pMonoObject )
|
||||
{
|
||||
return mono_object_unbox( pMonoObject );
|
||||
}
|
||||
|
||||
template <class T> static T GetValue( MonoObject* pMonoObject )
|
||||
{
|
||||
return *( reinterpret_cast<T*>( mono_object_unbox( pMonoObject ) ) );
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user