Рефакторинг. Добавлен интерфейс для работы с Mono (раньше вся работа шла через CResource). Библиотеки MTA и mscorlib в отдельных классах (доступ через CMonoDomain). Классы теперь кешируются и хранятся в CMonoDomain.

This commit is contained in:
Kernell 2015-11-29 18:47:19 +03:00
parent ed88279271
commit d8197802d8
43 changed files with 2389 additions and 1733 deletions

View File

@ -10,85 +10,6 @@
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ClCompile Include="src\CMonoClass.cpp" />
<ClCompile Include="src\CMonoFunctions.cpp" />
<ClCompile Include="src\CMonoFunctions_Account.cpp" />
<ClCompile Include="src\CMonoFunctions_Audio.cpp" />
<ClCompile Include="src\CMonoFunctions_Ban.cpp" />
<ClCompile Include="src\CMonoFunctions_Blip.cpp" />
<ClCompile Include="src\CMonoFunctions_Element.cpp" />
<ClCompile Include="src\CMonoFunctions_Explosion.cpp" />
<ClCompile Include="src\CMonoFunctions_Marker.cpp" />
<ClCompile Include="src\CMonoFunctions_Object.cpp" />
<ClCompile Include="src\CMonoFunctions_Ped.cpp" />
<ClCompile Include="src\CMonoFunctions_Pickup.cpp" />
<ClCompile Include="src\CMonoFunctions_Player.cpp" />
<ClCompile Include="src\CMonoFunctions_RadarArea.cpp" />
<ClCompile Include="src\CMonoFunctions_Resource.cpp" />
<ClCompile Include="src\CMonoFunctions_Shape.cpp" />
<ClCompile Include="src\CMonoFunctions_Team.cpp" />
<ClCompile Include="src\CMonoFunctions_Vehicle.cpp" />
<ClCompile Include="src\CMonoFunctions_Water.cpp" />
<ClCompile Include="src\CMonoFunctions_World.cpp" />
<ClCompile Include="src\CMonoObject.cpp" />
<ClCompile Include="src\Common.cpp" />
<ClCompile Include="src\CResource.cpp" />
<ClCompile Include="src\CResourceManager.cpp" />
<ClCompile Include="src\extra\Vector2.cpp" />
<ClCompile Include="src\extra\Vector3.cpp" />
<ClCompile Include="src\mta-mono.cpp" />
<ClCompile Include="src\CFunctions.cpp" />
<ClCompile Include="src\extra\CLuaArgument.cpp" />
<ClCompile Include="src\extra\CLuaArguments.cpp" />
<ClCompile Include="src\lua\CLuaFunctionDefinitions.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\CMonoClass.h" />
<ClInclude Include="src\CMonoFunctions.h" />
<ClInclude Include="src\CMonoObject.h" />
<ClInclude Include="src\CResource.h" />
<ClInclude Include="src\CResourceManager.h" />
<ClInclude Include="src\extra\Vector2.h" />
<ClInclude Include="src\extra\Vector3.h" />
<ClInclude Include="src\include\mono\jit\jit.h" />
<ClInclude Include="src\include\mono\metadata\appdomain.h" />
<ClInclude Include="src\include\mono\metadata\assembly.h" />
<ClInclude Include="src\include\mono\metadata\attrdefs.h" />
<ClInclude Include="src\include\mono\metadata\blob.h" />
<ClInclude Include="src\include\mono\metadata\class.h" />
<ClInclude Include="src\include\mono\metadata\debug-helpers.h" />
<ClInclude Include="src\include\mono\metadata\debug-mono-symfile.h" />
<ClInclude Include="src\include\mono\metadata\environment.h" />
<ClInclude Include="src\include\mono\metadata\exception.h" />
<ClInclude Include="src\include\mono\metadata\image.h" />
<ClInclude Include="src\include\mono\metadata\loader.h" />
<ClInclude Include="src\include\mono\metadata\metadata.h" />
<ClInclude Include="src\include\mono\metadata\mono-config.h" />
<ClInclude Include="src\include\mono\metadata\mono-debug.h" />
<ClInclude Include="src\include\mono\metadata\mono-gc.h" />
<ClInclude Include="src\include\mono\metadata\object.h" />
<ClInclude Include="src\include\mono\metadata\opcodes.h" />
<ClInclude Include="src\include\mono\metadata\profiler.h" />
<ClInclude Include="src\include\mono\metadata\reflection.h" />
<ClInclude Include="src\include\mono\metadata\row-indexes.h" />
<ClInclude Include="src\include\mono\metadata\sgen-bridge.h" />
<ClInclude Include="src\include\mono\metadata\threads.h" />
<ClInclude Include="src\include\mono\metadata\tokentype.h" />
<ClInclude Include="src\include\mono\metadata\verify.h" />
<ClInclude Include="src\include\mono\utils\mono-counters.h" />
<ClInclude Include="src\include\mono\utils\mono-dl-fallback.h" />
<ClInclude Include="src\include\mono\utils\mono-error.h" />
<ClInclude Include="src\include\mono\utils\mono-logger.h" />
<ClInclude Include="src\include\mono\utils\mono-publib.h" />
<ClInclude Include="src\mta-mono.h" />
<ClInclude Include="src\CFunctions.h" />
<ClInclude Include="src\Common.h" />
<ClInclude Include="src\extra\CLuaArgument.h" />
<ClInclude Include="src\extra\CLuaArguments.h" />
<ClInclude Include="src\include\ILuaModuleManager.h" />
<ClInclude Include="src\lua\CLuaFunctionDefinitions.h" />
</ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{5E5C7A85-A869-4D86-88FF-05DCEFC07AC3}</ProjectGuid> <ProjectGuid>{5E5C7A85-A869-4D86-88FF-05DCEFC07AC3}</ProjectGuid>
<RootNamespace>mta-mono</RootNamespace> <RootNamespace>mta-mono</RootNamespace>
@ -131,7 +52,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>D:\Server\MTA\server\mods\deathmatch\modules</OutDir> <OutDir>D:\Server\MTA\server\mods\deathmatch\modules</OutDir>
<IntDir>bin\Release\</IntDir> <IntDir>bin\Release\</IntDir>
<LinkIncremental>false</LinkIncremental> <LinkIncremental>true</LinkIncremental>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Midl> <Midl>
@ -146,10 +67,11 @@
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType> <TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<PrecompiledHeader /> <PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<SDLCheck>false</SDLCheck> <SDLCheck>false</SDLCheck>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat> <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<PrecompiledHeaderFile>StdInc.h</PrecompiledHeaderFile>
</ClCompile> </ClCompile>
<ResourceCompile> <ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -178,18 +100,21 @@
<MkTypLibCompatible>false</MkTypLibCompatible> <MkTypLibCompatible>false</MkTypLibCompatible>
</Midl> </Midl>
<ClCompile> <ClCompile>
<AdditionalIncludeDirectories>.\include;.\src\include;.\vendor\lua51\src;.\vendor\mysql;.\vendor\eglib</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>.\src;.\include;.\src\include;.\vendor\lua51\src;.\vendor\mysql;.\vendor\eglib</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType> <TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<PrecompiledHeader /> <PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<SDLCheck>false</SDLCheck> <Optimization>Disabled</Optimization>
<Optimization>Full</Optimization> <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<BasicRuntimeChecks>Default</BasicRuntimeChecks> <IntrinsicFunctions>false</IntrinsicFunctions>
<IntrinsicFunctions>true</IntrinsicFunctions> <FunctionLevelLinking>
<FunctionLevelLinking>true</FunctionLevelLinking> </FunctionLevelLinking>
<PrecompiledHeaderFile>StdInc.h</PrecompiledHeaderFile>
<StringPooling>true</StringPooling>
<ForcedIncludeFiles>StdInc.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
</ClCompile> </ClCompile>
<ResourceCompile> <ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -201,20 +126,117 @@
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile> <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<ModuleDefinitionFile /> <ModuleDefinitionFile />
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem> <SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding> </OptimizeReferences>
<EnableCOMDATFolding>
</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress> <RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention /> <DataExecutionPrevention />
<ImportLibrary> <ImportLibrary>$(IntDir)$(TargetFileName).lib</ImportLibrary>
</ImportLibrary>
<TargetMachine>MachineX86</TargetMachine> <TargetMachine>MachineX86</TargetMachine>
<IgnoreSpecificDefaultLibraries> <IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries> </IgnoreSpecificDefaultLibraries>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration> <LinkTimeCodeGeneration>
</LinkTimeCodeGeneration>
<AdditionalLibraryDirectories>lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\CMonoClass.cpp" />
<ClCompile Include="src\CMonoCorlib.cpp" />
<ClCompile Include="src\CMonoDomain.cpp" />
<ClCompile Include="src\CMonoFunctions.cpp" />
<ClCompile Include="src\CMonoFunctions_Account.cpp" />
<ClCompile Include="src\CMonoFunctions_Audio.cpp" />
<ClCompile Include="src\CMonoFunctions_Ban.cpp" />
<ClCompile Include="src\CMonoFunctions_Blip.cpp" />
<ClCompile Include="src\CMonoFunctions_Element.cpp" />
<ClCompile Include="src\CMonoFunctions_Event.cpp" />
<ClCompile Include="src\CMonoFunctions_Explosion.cpp" />
<ClCompile Include="src\CMonoFunctions_Marker.cpp" />
<ClCompile Include="src\CMonoFunctions_Object.cpp" />
<ClCompile Include="src\CMonoFunctions_Ped.cpp" />
<ClCompile Include="src\CMonoFunctions_Pickup.cpp" />
<ClCompile Include="src\CMonoFunctions_Player.cpp" />
<ClCompile Include="src\CMonoFunctions_RadarArea.cpp" />
<ClCompile Include="src\CMonoFunctions_Resource.cpp" />
<ClCompile Include="src\CMonoFunctions_Shape.cpp" />
<ClCompile Include="src\CMonoFunctions_Team.cpp" />
<ClCompile Include="src\CMonoFunctions_Vehicle.cpp" />
<ClCompile Include="src\CMonoFunctions_Water.cpp" />
<ClCompile Include="src\CMonoFunctions_World.cpp" />
<ClCompile Include="src\CMonoGC.cpp" />
<ClCompile Include="src\CMonoInterface.cpp" />
<ClCompile Include="src\CMonoMTALib.cpp" />
<ClCompile Include="src\CMonoObject.cpp" />
<ClCompile Include="src\Common.cpp" />
<ClCompile Include="src\CResource.cpp" />
<ClCompile Include="src\CResourceManager.cpp" />
<ClCompile Include="src\extra\Vector2.cpp" />
<ClCompile Include="src\extra\Vector3.cpp" />
<ClCompile Include="src\mta-mono.cpp" />
<ClCompile Include="src\CFunctions.cpp" />
<ClCompile Include="src\extra\CLuaArgument.cpp" />
<ClCompile Include="src\extra\CLuaArguments.cpp" />
<ClCompile Include="src\lua\CLuaFunctionDefinitions.cpp" />
<ClCompile Include="src\StdInc.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\CMonoClass.h" />
<ClInclude Include="src\CMonoCorlib.h" />
<ClInclude Include="src\CMonoDomain.h" />
<ClInclude Include="src\CMonoFunctions.h" />
<ClInclude Include="src\CMonoGC.h" />
<ClInclude Include="src\CMonoInterface.h" />
<ClInclude Include="src\CMonoMTALib.h" />
<ClInclude Include="src\CMonoObject.h" />
<ClInclude Include="src\CResource.h" />
<ClInclude Include="src\CResourceManager.h" />
<ClInclude Include="src\extra\Vector2.h" />
<ClInclude Include="src\extra\Vector3.h" />
<ClInclude Include="src\include\mono\jit\jit.h" />
<ClInclude Include="src\include\mono\metadata\appdomain.h" />
<ClInclude Include="src\include\mono\metadata\assembly.h" />
<ClInclude Include="src\include\mono\metadata\attrdefs.h" />
<ClInclude Include="src\include\mono\metadata\blob.h" />
<ClInclude Include="src\include\mono\metadata\class.h" />
<ClInclude Include="src\include\mono\metadata\debug-helpers.h" />
<ClInclude Include="src\include\mono\metadata\debug-mono-symfile.h" />
<ClInclude Include="src\include\mono\metadata\environment.h" />
<ClInclude Include="src\include\mono\metadata\exception.h" />
<ClInclude Include="src\include\mono\metadata\image.h" />
<ClInclude Include="src\include\mono\metadata\loader.h" />
<ClInclude Include="src\include\mono\metadata\metadata.h" />
<ClInclude Include="src\include\mono\metadata\mono-config.h" />
<ClInclude Include="src\include\mono\metadata\mono-debug.h" />
<ClInclude Include="src\include\mono\metadata\mono-gc.h" />
<ClInclude Include="src\include\mono\metadata\object.h" />
<ClInclude Include="src\include\mono\metadata\opcodes.h" />
<ClInclude Include="src\include\mono\metadata\profiler.h" />
<ClInclude Include="src\include\mono\metadata\reflection.h" />
<ClInclude Include="src\include\mono\metadata\row-indexes.h" />
<ClInclude Include="src\include\mono\metadata\sgen-bridge.h" />
<ClInclude Include="src\include\mono\metadata\threads.h" />
<ClInclude Include="src\include\mono\metadata\tokentype.h" />
<ClInclude Include="src\include\mono\metadata\verify.h" />
<ClInclude Include="src\include\mono\utils\mono-counters.h" />
<ClInclude Include="src\include\mono\utils\mono-dl-fallback.h" />
<ClInclude Include="src\include\mono\utils\mono-error.h" />
<ClInclude Include="src\include\mono\utils\mono-logger.h" />
<ClInclude Include="src\include\mono\utils\mono-publib.h" />
<ClInclude Include="src\CFunctions.h" />
<ClInclude Include="src\Common.h" />
<ClInclude Include="src\extra\CLuaArgument.h" />
<ClInclude Include="src\extra\CLuaArguments.h" />
<ClInclude Include="src\include\ILuaModuleManager.h" />
<ClInclude Include="src\lua\CLuaFunctionDefinitions.h" />
<ClInclude Include="src\StdInc.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>

View File

@ -10,6 +10,7 @@
* *
*********************************************************/ *********************************************************/
#include "StdInc.h"
#include "CFunctions.h" #include "CFunctions.h"
#include "extra/CLuaArguments.h" #include "extra/CLuaArguments.h"
@ -43,3 +44,31 @@ int CFunctions::monoInit( lua_State *pLuaVM )
return 0; return 0;
} }
int CFunctions::monoEventHandler( lua_State *pLuaVM )
{
if( pLuaVM )
{
CResource *pResource = g_pResourceManager->GetFromList( pLuaVM );
if( pResource )
{
// eventName, this, source, client, ...
string strEventName = CLuaArgument( pLuaVM, -4 ).GetString();
void* pThis = CLuaArgument( pLuaVM, -3 ).GetLightUserData();
void* pSource = CLuaArgument( pLuaVM, -2 ).GetLightUserData();
void* pClient = CLuaArgument( pLuaVM, -1 ).GetLightUserData();
//void *args[] = { &vecVector.fX, &vecVector.fY };
g_pModuleManager->DebugPrintf( pLuaVM, "event: %s", strEventName.c_str() );
pResource->CallEvent( strEventName, pThis, pSource, pClient, nullptr );
return 1;
}
}
return 0;
}

View File

@ -28,6 +28,7 @@ class CFunctions
{ {
public: public:
static int monoInit ( lua_State *pLuaVM ); static int monoInit ( lua_State *pLuaVM );
static int monoEventHandler ( lua_State *pLuaVM );
}; };
#endif #endif

View File

@ -1,18 +1,35 @@
/*********************************************************
*
* 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 "CMonoClass.h" #include "CMonoClass.h"
MonoObject* CMonoClass::New( MonoClass* pMonoClass, MonoDomain* pMonoDomain ) CMonoClass::CMonoClass( MonoClass* pMonoClass, CMonoDomain* pDomain )
{ {
MonoObject* pObject = mono_object_new( pMonoDomain, pMonoClass ); this->m_pClass = pMonoClass;
this->m_pDomain = pDomain;
}
CMonoClass::~CMonoClass( void )
{
this->m_pDomain = nullptr;
this->m_pClass = nullptr;
}
MonoObject* CMonoClass::New( void )
{
MonoObject* pObject = this->m_pDomain->CreateObject( this->m_pClass );
if( !pObject ) if( !pObject )
{ {
g_pModuleManager->ErrorPrintf( "%s:%d: Failed to create mono object for %s::%s\n",
CMonoClass::GetNameSpace( pMonoClass ),
CMonoClass::GetName( pMonoClass ),
__FILE__,
__LINE__
);
return nullptr; return nullptr;
} }
@ -21,45 +38,40 @@ MonoObject* CMonoClass::New( MonoClass* pMonoClass, MonoDomain* pMonoDomain )
return pObject; return pObject;
} }
MonoObject* CMonoClass::New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, SColor& pColor ) MonoObject* CMonoClass::New( SColor& pColor )
{ {
void *args[] = { &pColor.R, &pColor.G, &pColor.B, &pColor.A }; void *args[] = { &pColor.R, &pColor.G, &pColor.B, &pColor.A };
return CMonoClass::New( pMonoClass, pMonoDomain, args, 4 ); return this->New( args, 4 );
} }
MonoObject* CMonoClass::New( Vector2& vecVector )
MonoObject* CMonoClass::New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, Vector2& vecVector )
{ {
void *args[] = { &vecVector.fX, &vecVector.fY }; void *args[] = { &vecVector.fX, &vecVector.fY };
return CMonoClass::New( pMonoClass, pMonoDomain, args, 2 ); return this->New( args, 2 );
} }
MonoObject* CMonoClass::New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, Vector3& vecVector ) MonoObject* CMonoClass::New( Vector3& vecVector )
{ {
void *args[] = { &vecVector.fX, &vecVector.fY, &vecVector.fZ }; void *args[] = { &vecVector.fX, &vecVector.fY, &vecVector.fZ };
return CMonoClass::New( pMonoClass, pMonoDomain, args, 3 ); return this->New( args, 3 );
} }
MonoObject* CMonoClass::New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, void** args, int argc ) MonoObject* CMonoClass::New( void** args, int argc )
{ {
MonoObject* pObject = mono_object_new( pMonoDomain, pMonoClass ); MonoObject* pObject = this->m_pDomain->CreateObject( this->m_pClass );
if( !pObject ) if( !pObject )
{ {
g_pModuleManager->ErrorPrintf( "%s:%d: Failed to create mono object for %s::%s\n", GetNameSpace( pMonoClass ), GetName( pMonoClass ), __FILE__, __LINE__ );
return nullptr; return nullptr;
} }
MonoMethod* pMonoMethod = CMonoClass::GetMethod( pMonoClass, ".ctor", argc ); MonoMethod* pMonoMethod = this->GetMethod( ".ctor", argc );
if( !pMonoMethod ) if( !pMonoMethod )
{ {
g_pModuleManager->ErrorPrintf( "%s:%d: Could not lookup constructor for class %s::%s\n", GetNameSpace( pMonoClass ), GetName( pMonoClass ), __FILE__, __LINE__ );
return nullptr; return nullptr;
} }
@ -68,28 +80,29 @@ MonoObject* CMonoClass::New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, voi
return pObject; return pObject;
} }
const char* CMonoClass::GetName( MonoClass* pMonoClass )
const char* CMonoClass::GetName( void )
{ {
return mono_class_get_name( pMonoClass ); return mono_class_get_name( this->m_pClass );
} }
const char* CMonoClass::GetNameSpace( MonoClass* pMonoClass ) const char* CMonoClass::GetNameSpace( void )
{ {
return mono_class_get_namespace( pMonoClass ); return mono_class_get_namespace( this->m_pClass );
} }
MonoMethod* CMonoClass::GetMethod( MonoClass* pMonoClass, const char* szMethodName, int iParamCount ) MonoMethod* CMonoClass::GetMethod( const char* szMethodName, int iParamCount )
{ {
return mono_class_get_method_from_name( pMonoClass, szMethodName, iParamCount ); return mono_class_get_method_from_name( this->m_pClass, szMethodName, iParamCount );
} }
MonoMethod* CMonoClass::GetMethod( MonoClass* pMonoClass, const char* szMethodName ) MonoMethod* CMonoClass::GetMethod( const char* szMethodName )
{ {
MonoMethodDesc* pMonoMethodDesc = mono_method_desc_new( szMethodName, false ); MonoMethodDesc* pMonoMethodDesc = mono_method_desc_new( szMethodName, false );
if( pMonoMethodDesc ) if( pMonoMethodDesc )
{ {
MonoMethod* pMethod = mono_method_desc_search_in_class( pMonoMethodDesc, pMonoClass ); MonoMethod* pMethod = mono_method_desc_search_in_class( pMonoMethodDesc, this->m_pClass );
mono_method_desc_free( pMonoMethodDesc ); mono_method_desc_free( pMonoMethodDesc );

View File

@ -1,28 +1,47 @@
/*********************************************************
*
* 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 CMonoClass; class CMonoClass;
#ifndef _C_MONO_CLASS #ifndef _C_MONOCLASS_H
#define _C_MONO_CLASS #define _C_MONOCLASS_H
#include "Common.h" #include "CMonoDomain.h"
extern ILuaModuleManager10 *g_pModuleManager;
class CMonoClass class CMonoClass
{ {
private:
MonoClass* m_pClass;
CMonoDomain* m_pDomain;
public: public:
static MonoObject* New( MonoClass* pMonoClass, MonoDomain* pMonoDomain ); CMonoClass ( MonoClass* pMonoClass, CMonoDomain* pDomain );
static MonoObject* New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, SColor& pColor ); ~CMonoClass ( void );
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 ); MonoObject* New ( void );
static const char* GetNameSpace( MonoClass* pMonoClass ); MonoObject* New ( SColor& pColor );
MonoObject* New ( Vector2& vecVector );
MonoObject* New ( Vector3& vecVector );
MonoObject* New ( void** args, int argc );
static MonoMethod* GetMethod( MonoClass* pMonoClass, const char* szMethodName, int iParamCount ); const char* GetName ( void );
static MonoMethod* GetMethod( MonoClass* pMonoClass, const char* szMethodName ); const char* GetNameSpace ( void );
static MonoClass* GetClass( MonoClass* pMonoClass ); MonoMethod* GetMethod ( const char* szMethodName, int iParamCount );
MonoMethod* GetMethod ( const char* szMethodName );
MonoClass* GetMonoPtr ( void ) { return this->m_pClass; }
CMonoDomain* GetDomain ( void ) { return this->m_pDomain; }
}; };
#endif #endif

View File

@ -0,0 +1,58 @@
/*********************************************************
*
* 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 "CMonoCorlib.h"
CMonoCorlib::CMonoCorlib( CMonoDomain* pDomain )
{
this->m_pDomain = pDomain;
this->m_pImage = mono_get_corlib();
this->m_pAssembly = mono_image_get_assembly( this->m_pImage );
this->Class[ "intptr" ] = this->GetDomain()->FindOrAdd( mono_get_intptr_class() );
this->Class[ "uintptr" ] = this->GetDomain()->FindOrAdd( mono_get_uintptr_class() );
this->Class[ "boolean" ] = this->GetDomain()->FindOrAdd( mono_get_boolean_class() );
this->Class[ "char" ] = this->GetDomain()->FindOrAdd( mono_get_char_class() );
this->Class[ "sbyte" ] = this->GetDomain()->FindOrAdd( mono_get_sbyte_class() );
this->Class[ "byte" ] = this->GetDomain()->FindOrAdd( mono_get_byte_class() );
this->Class[ "int16" ] = this->GetDomain()->FindOrAdd( mono_get_int16_class() );
this->Class[ "uint16" ] = this->GetDomain()->FindOrAdd( mono_get_uint16_class() );
this->Class[ "int32" ] = this->GetDomain()->FindOrAdd( mono_get_int32_class() );
this->Class[ "uint32" ] = this->GetDomain()->FindOrAdd( mono_get_uint32_class() );
this->Class[ "int64" ] = this->GetDomain()->FindOrAdd( mono_get_int64_class() );
this->Class[ "uint64" ] = this->GetDomain()->FindOrAdd( mono_get_uint64_class() );
this->Class[ "float" ] = this->GetDomain()->FindOrAdd( mono_get_single_class() );
this->Class[ "double" ] = this->GetDomain()->FindOrAdd( mono_get_double_class() );
this->Class[ "string" ] = this->GetDomain()->FindOrAdd( mono_get_string_class() );
this->Class[ "array" ] = this->GetDomain()->FindOrAdd( mono_get_array_class() );
this->Class[ "enum" ] = this->GetDomain()->FindOrAdd( mono_get_enum_class() );
this->Class[ "exception" ] = this->GetDomain()->FindOrAdd( mono_get_exception_class() );
this->Class[ "object" ] = this->GetDomain()->FindOrAdd( mono_get_object_class() );
this->Class[ "thread" ] = this->GetDomain()->FindOrAdd( mono_get_thread_class() );
this->Class[ "Type" ] = this->GetClass( "System", "Type" );
this->Class[ "ValueType" ] = this->GetClass( "System", "ValueType" );
}
CMonoCorlib::~CMonoCorlib( void )
{
this->m_pDomain = nullptr;
this->m_pAssembly = nullptr;
this->m_pImage = nullptr;
this->Class.clear();
}
CMonoClass* CMonoCorlib::GetClass( const char *szNameSpace, const char *szClassName )
{
return this->GetDomain()->FindOrAdd( mono_class_from_name( this->m_pImage, szNameSpace, szClassName ) );
}

View File

@ -0,0 +1,40 @@
/*********************************************************
*
* 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 CMonoCorlib;
#ifndef __CMONOCORLIB_H
#define __CMONOCORLIB_H
#include "CMonoDomain.h"
#include "CMonoClass.h"
class CMonoCorlib
{
private:
MonoAssembly* m_pAssembly;
MonoImage* m_pImage;
CMonoDomain* m_pDomain;
protected:
map< const char*, CMonoClass* > Class;
public:
CMonoCorlib ( CMonoDomain* pDomain );
~CMonoCorlib ( void );
CMonoClass* GetClass ( const char *szNameSpace, const char *szClassName );
CMonoDomain* GetDomain ( void ) { return this->m_pDomain; }
};
#endif

View File

@ -0,0 +1,100 @@
/*********************************************************
*
* 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 "CMonoDomain.h"
CMonoDomain::CMonoDomain( CResource* pResource, MonoDomain* pDomain )
{
this->m_pDomain = pDomain;
this->m_pResource = pResource;
this->m_pCorlib = nullptr;
this->m_pMTALib = nullptr;
}
CMonoDomain::~CMonoDomain( void )
{
SAFE_DELETE( this->m_pMTALib );
SAFE_DELETE( this->m_pCorlib );
for( auto iter : this->m_ClassPool )
{
delete iter;
}
this->m_ClassPool.clear();
this->m_pDomain = nullptr;
}
CMonoClass* CMonoDomain::FindOrAdd( MonoClass* klass )
{
if( !klass )
{
return nullptr;
}
if( this->m_pDomain )
{
for( auto iter : this->m_ClassPool )
{
if( iter->GetMonoPtr() == klass )
{
return iter;
}
}
CMonoClass* pClass = new CMonoClass( klass, this );
this->m_ClassPool.push_back( pClass );
return pClass;
}
return nullptr;
}
void CMonoDomain::Init( void )
{
this->m_pCorlib = new CMonoCorlib( this );
this->m_pMTALib = new CMonoMTALib( this );
}
void CMonoDomain::Unload( void )
{
mono_domain_unload( this->m_pDomain );
}
bool CMonoDomain::Set( bool bForce )
{
return mono_domain_set( this->m_pDomain, bForce );
}
MonoAssembly* CMonoDomain::OpenAssembly( const char *szName )
{
return mono_domain_assembly_open( this->m_pDomain, szName );
}
MonoObject* CMonoDomain::CreateObject( MonoClass* klass )
{
return mono_object_new( this->m_pDomain, klass );
}
MonoString* CMonoDomain::NewString( const char* szText )
{
return mono_string_new( this->m_pDomain, szText );
}
MonoString* CMonoDomain::NewString( string strText )
{
return mono_string_new( this->m_pDomain, strText.c_str() );
}

View File

@ -0,0 +1,97 @@
/*********************************************************
*
* 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 CMonoDomain;
#ifndef __CMONODOMAIN_H
#define __CMONODOMAIN_H
#include "CMonoCorlib.h"
#include "CMonoMTALib.h"
#include "CMonoClass.h"
#include "CResource.h"
#include "extra/CLuaArguments.h"
class CMonoDomain
{
private:
MonoDomain* m_pDomain;
CResource* m_pResource;
CMonoCorlib* m_pCorlib;
CMonoMTALib* m_pMTALib;
vector< CMonoClass* > m_ClassPool;
public:
CMonoDomain ( CResource* pResource, MonoDomain* pDomain );
~CMonoDomain ( void );
CMonoClass* FindOrAdd ( MonoClass* klass );
void Init ( void );
void Unload ( void );
bool Set ( bool bForce );
MonoAssembly* OpenAssembly ( const char *szName );
MonoObject* CreateObject ( MonoClass* klass );
MonoString* NewString ( const char* szText );
MonoString* NewString ( string strText );
template <class T, int LuaType>
MonoArray* NewArray ( MonoClass* pMonoClass, CLuaArguments* pLuaArguments = NULL )
{
MonoArray* pArray = mono_array_new( this->m_pDomain, pMonoClass, pLuaArguments ? pLuaArguments->Count() : 0 );
if( pLuaArguments )
{
int i = 0;
for( auto iter : pLuaArguments->GetArguments() )
{
if( LuaType == LUA_TBOOLEAN )
{
mono_array_set( pArray, T, i++, (T)( iter->GetBoolean() ) );
}
else if( LuaType == LUA_TLIGHTUSERDATA )
{
mono_array_set( pArray, T, i++, (T)( iter->GetLightUserData() ) );
}
else if( LuaType == LUA_TNUMBER )
{
mono_array_set( pArray, T, i++, iter->GetNumber< T >() );
}
else if( LuaType == LUA_TSTRING )
{
mono_array_set( pArray, T, i++, (T)( iter->GetString() ) );
}
else if( LuaType == LUA_TUSERDATA )
{
mono_array_set( pArray, T, i++, (T)( iter->GetLightUserData() ) );
}
}
}
return pArray;
}
MonoDomain* GetMonoPtr ( void ) { return this->m_pDomain; }
CResource* GetResource ( void ) { return this->m_pResource; }
CMonoCorlib* GetCorlib ( void ) { return this->m_pCorlib; }
CMonoMTALib* GetMTALib ( void ) { return this->m_pMTALib; }
};
#endif

View File

@ -37,12 +37,16 @@ void CMonoFunctions::AddInternals( void )
MONO_DECLARE( Server, SetRuleValue ); MONO_DECLARE( Server, SetRuleValue );
MONO_DECLARE( Server, RemoveRuleValue ); MONO_DECLARE( Server, RemoveRuleValue );
MONO_DECLARE( Event, AddHandler );
// Element create/destroy // Element create/destroy
MONO_DECLARE( Element, Create ); MONO_DECLARE( Element, Create );
MONO_DECLARE( Element, Destroy ); MONO_DECLARE( Element, Destroy );
MONO_DECLARE( Element, Clone ); MONO_DECLARE( Element, Clone );
// Element get funcs // Element get funcs
MONO_DECLARE( Element, GetRootElement );
MONO_DECLARE( Element, GetByType ); MONO_DECLARE( Element, GetByType );
MONO_DECLARE( Element, IsElement ); MONO_DECLARE( Element, IsElement );
MONO_DECLARE( Element, GetType ); MONO_DECLARE( Element, GetType );
@ -746,7 +750,7 @@ MonoObject* CMonoFunctions::Server::GetVersion( void )
&szSortable &szSortable
}; };
return RESOURCE->NewObject( "MultiTheftAuto", "ServerVersion", args, 8 ); return RESOURCE->GetDomain()->GetMTALib()->GetClass( "ServerVersion" )->New( args, 8 );
} }
} }
@ -757,7 +761,7 @@ MonoString* CMonoFunctions::Server::GetGameType( void )
{ {
if( RESOURCE ) if( RESOURCE )
{ {
return RESOURCE->NewString( CLuaFunctionDefinitions::GetGameType( RESOURCE->GetLua() ) ); return RESOURCE->GetDomain()->NewString( CLuaFunctionDefinitions::GetGameType( RESOURCE->GetLua() ) );
} }
return NULL; return NULL;
@ -767,7 +771,7 @@ MonoString* CMonoFunctions::Server::GetMapName( void )
{ {
if( RESOURCE ) if( RESOURCE )
{ {
return RESOURCE->NewString( CLuaFunctionDefinitions::GetMapName( RESOURCE->GetLua() ) ); return RESOURCE->GetDomain()->NewString( CLuaFunctionDefinitions::GetMapName( RESOURCE->GetLua() ) );
} }
return NULL; return NULL;
@ -803,7 +807,7 @@ MonoString* CMonoFunctions::Server::GetRuleValue( MonoString* msKey )
{ {
const char* szKey = mono_string_to_utf8( msKey ); const char* szKey = mono_string_to_utf8( msKey );
return RESOURCE->NewString( CLuaFunctionDefinitions::GetRuleValue( RESOURCE->GetLua(), szKey ) ); return RESOURCE->GetDomain()->NewString( CLuaFunctionDefinitions::GetRuleValue( RESOURCE->GetLua(), szKey ) );
} }
return false; return false;

View File

@ -18,10 +18,13 @@ class CMonoFunctions;
#ifndef __CMONOFUNCTIONS_H #ifndef __CMONOFUNCTIONS_H
#define __CMONOFUNCTIONS_H #define __CMONOFUNCTIONS_H
#include "Common.h"
#include "lua/CLuaFunctionDefinitions.h" #include "lua/CLuaFunctionDefinitions.h"
#include "CMonoDomain.h"
#include "CMonoClass.h"
#include "CMonoObject.h" #include "CMonoObject.h"
#include "CMonoCorlib.h"
#include "CMonoMTALib.h"
extern ILuaModuleManager10 *g_pModuleManager; extern ILuaModuleManager10 *g_pModuleManager;
extern CResourceManager *g_pResourceManager; extern CResourceManager *g_pResourceManager;
@ -70,6 +73,12 @@ public:
static bool RemoveRuleValue ( MonoString* msKey ); static bool RemoveRuleValue ( MonoString* msKey );
}; };
class Event
{
public:
static bool AddHandler ( MonoString* msName, DWORD pUserData, lua_CFunction iLuaFunction, bool bPropagated, MonoString* msEventPriority );
};
class Element class Element
{ {
public: public:
@ -79,6 +88,7 @@ public:
static DWORD Clone ( DWORD pUserData, MonoObject* vecPosition, bool bCloneElement ); static DWORD Clone ( DWORD pUserData, MonoObject* vecPosition, bool bCloneElement );
// Element get funcs // Element get funcs
static DWORD GetRootElement ( void );
static MonoArray* GetByType ( MonoString* msType, DWORD pStartElement ); static MonoArray* GetByType ( MonoString* msType, DWORD pStartElement );
static bool IsElement ( DWORD pUserData ); static bool IsElement ( DWORD pUserData );

View File

@ -32,7 +32,7 @@ MonoArray* CMonoFunctions::Account::GetAll( void )
{ {
CLuaArguments* pLuaTable = CLuaFunctionDefinitions::GetAccounts( RESOURCE->GetLua() ); CLuaArguments* pLuaTable = CLuaFunctionDefinitions::GetAccounts( RESOURCE->GetLua() );
return RESOURCE->NewArray<DWORD, LUA_TLIGHTUSERDATA>( mono_get_uint32_class(), pLuaTable ); return RESOURCE->GetDomain()->NewArray<DWORD, LUA_TLIGHTUSERDATA>( mono_get_uint32_class(), pLuaTable );
} }
return NULL; return NULL;
@ -71,7 +71,7 @@ MonoString* CMonoFunctions::Account::GetSerial( DWORD pAccount )
if( CLuaFunctionDefinitions::GetAccountSerial( RESOURCE->GetLua(), (void*)pAccount, strSerial ) ) if( CLuaFunctionDefinitions::GetAccountSerial( RESOURCE->GetLua(), (void*)pAccount, strSerial ) )
{ {
return RESOURCE->NewString( strSerial ); return RESOURCE->GetDomain()->NewString( strSerial );
} }
} }

View File

@ -59,7 +59,7 @@ MonoString* CMonoFunctions::Ban::GetIP( DWORD pBan )
if( CLuaFunctionDefinitions::GetBanIP( RESOURCE->GetLua(), (void*)pBan, strIP ) ) if( CLuaFunctionDefinitions::GetBanIP( RESOURCE->GetLua(), (void*)pBan, strIP ) )
{ {
return RESOURCE->NewString( strIP ); return RESOURCE->GetDomain()->NewString( strIP );
} }
} }
@ -74,7 +74,7 @@ MonoString* CMonoFunctions::Ban::GetSerial( DWORD pBan )
if( CLuaFunctionDefinitions::GetBanSerial( RESOURCE->GetLua(), (void*)pBan, strSerial ) ) if( CLuaFunctionDefinitions::GetBanSerial( RESOURCE->GetLua(), (void*)pBan, strSerial ) )
{ {
return RESOURCE->NewString( strSerial ); return RESOURCE->GetDomain()->NewString( strSerial );
} }
} }
@ -89,7 +89,7 @@ MonoString* CMonoFunctions::Ban::GetUsername( DWORD pBan )
if( CLuaFunctionDefinitions::GetBanUsername( RESOURCE->GetLua(), (void*)pBan, strUsername ) ) if( CLuaFunctionDefinitions::GetBanUsername( RESOURCE->GetLua(), (void*)pBan, strUsername ) )
{ {
return RESOURCE->NewString( strUsername ); return RESOURCE->GetDomain()->NewString( strUsername );
} }
} }
@ -104,7 +104,7 @@ MonoString* CMonoFunctions::Ban::GetNick( DWORD pBan )
if( CLuaFunctionDefinitions::GetBanNick( RESOURCE->GetLua(), (void*)pBan, strNick ) ) if( CLuaFunctionDefinitions::GetBanNick( RESOURCE->GetLua(), (void*)pBan, strNick ) )
{ {
return RESOURCE->NewString( strNick ); return RESOURCE->GetDomain()->NewString( strNick );
} }
} }
@ -119,7 +119,7 @@ MonoString* CMonoFunctions::Ban::GetReason( DWORD pBan )
if( CLuaFunctionDefinitions::GetBanReason( RESOURCE->GetLua(), (void*)pBan, strReason ) ) if( CLuaFunctionDefinitions::GetBanReason( RESOURCE->GetLua(), (void*)pBan, strReason ) )
{ {
return RESOURCE->NewString( strReason ); return RESOURCE->GetDomain()->NewString( strReason );
} }
} }
@ -134,7 +134,7 @@ MonoString* CMonoFunctions::Ban::GetAdmin( DWORD pBan )
if( CLuaFunctionDefinitions::GetBanAdmin( RESOURCE->GetLua(), (void*)pBan, strAdmin ) ) if( CLuaFunctionDefinitions::GetBanAdmin( RESOURCE->GetLua(), (void*)pBan, strAdmin ) )
{ {
return RESOURCE->NewString( strAdmin ); return RESOURCE->GetDomain()->NewString( strAdmin );
} }
} }

View File

@ -79,7 +79,7 @@ MonoObject* CMonoFunctions::Blip::GetColor( DWORD pUserData )
if( CLuaFunctionDefinitions::GetBlipColor( RESOURCE->GetLua(), (void*)pUserData, outColor ) ) if( CLuaFunctionDefinitions::GetBlipColor( RESOURCE->GetLua(), (void*)pUserData, outColor ) )
{ {
return RESOURCE->NewObject( outColor ); return RESOURCE->GetDomain()->GetMTALib()->Color->New( outColor );
} }
} }

View File

@ -49,6 +49,16 @@ DWORD CMonoFunctions::Element::Clone( DWORD pUserData, MonoObject* vecPosition,
// Element get funcs // Element get funcs
DWORD CMonoFunctions::Element::GetRootElement( void )
{
if( RESOURCE )
{
return (DWORD)CLuaFunctionDefinitions::GetRootElement( RESOURCE->GetLua() );
}
return NULL;
}
MonoArray* CMonoFunctions::Element::GetByType( MonoString* msType, DWORD pStartElement ) MonoArray* CMonoFunctions::Element::GetByType( MonoString* msType, DWORD pStartElement )
{ {
if( RESOURCE ) if( RESOURCE )
@ -57,7 +67,7 @@ MonoArray* CMonoFunctions::Element::GetByType( MonoString* msType, DWORD pStartE
CLuaArguments* pLuaArguments = CLuaFunctionDefinitions::GetElementsByType( RESOURCE->GetLua(), szType, (void*)pStartElement ); CLuaArguments* pLuaArguments = CLuaFunctionDefinitions::GetElementsByType( RESOURCE->GetLua(), szType, (void*)pStartElement );
return RESOURCE->NewArray<DWORD, LUA_TLIGHTUSERDATA>( mono_get_uint32_class(), pLuaArguments ); return RESOURCE->GetDomain()->NewArray<DWORD, LUA_TLIGHTUSERDATA>( mono_get_uint32_class(), pLuaArguments );
} }
return NULL; return NULL;
@ -157,7 +167,7 @@ MonoObject* CMonoFunctions::Element::GetPosition( DWORD pUserData )
if( CLuaFunctionDefinitions::GetElementPosition( RESOURCE->GetLua(), (void*)pUserData, vecPosition ) ) if( CLuaFunctionDefinitions::GetElementPosition( RESOURCE->GetLua(), (void*)pUserData, vecPosition ) )
{ {
return RESOURCE->NewObject( vecPosition ); return RESOURCE->GetDomain()->GetMTALib()->Vector3->New( vecPosition );
} }
} }
@ -172,7 +182,7 @@ MonoObject* CMonoFunctions::Element::GetRotation( DWORD pUserData )
if( CLuaFunctionDefinitions::GetElementRotation( RESOURCE->GetLua(), (void*)pUserData, vecPosition ) ) if( CLuaFunctionDefinitions::GetElementRotation( RESOURCE->GetLua(), (void*)pUserData, vecPosition ) )
{ {
return RESOURCE->NewObject( vecPosition ); return RESOURCE->GetDomain()->GetMTALib()->Vector3->New( vecPosition );
} }
} }
@ -187,7 +197,7 @@ MonoObject* CMonoFunctions::Element::GetVelocity( DWORD pUserData )
if( CLuaFunctionDefinitions::GetElementVelocity( RESOURCE->GetLua(), (void*)pUserData, vecPosition ) ) if( CLuaFunctionDefinitions::GetElementVelocity( RESOURCE->GetLua(), (void*)pUserData, vecPosition ) )
{ {
return RESOURCE->NewObject( vecPosition ); return RESOURCE->GetDomain()->GetMTALib()->Vector3->New( vecPosition );
} }
} }
@ -262,7 +272,7 @@ MonoString* CMonoFunctions::Element::GetZoneName( DWORD pUserData, bool bCitiesO
if( CLuaFunctionDefinitions::GetElementZoneName( RESOURCE->GetLua(), (void*)pUserData, strOutName, bCitiesOnly ) ) if( CLuaFunctionDefinitions::GetElementZoneName( RESOURCE->GetLua(), (void*)pUserData, strOutName, bCitiesOnly ) )
{ {
return RESOURCE->NewString( strOutName ); return RESOURCE->GetDomain()->NewString( strOutName );
} }
} }
@ -382,7 +392,7 @@ MonoObject* CMonoFunctions::Element::GetAttachedOffsetPosition( DWORD pUserData
if( CLuaFunctionDefinitions::GetElementAttachedOffsets( RESOURCE->GetLua(), (void*)pUserData, vecPosition, vecRotation ) ) if( CLuaFunctionDefinitions::GetElementAttachedOffsets( RESOURCE->GetLua(), (void*)pUserData, vecPosition, vecRotation ) )
{ {
return RESOURCE->NewObject( vecPosition ); return RESOURCE->GetDomain()->GetMTALib()->Vector3->New( vecPosition );
} }
} }
@ -397,7 +407,7 @@ MonoObject* CMonoFunctions::Element::GetAttachedOffsetRotation( DWORD pUserData
if( CLuaFunctionDefinitions::GetElementAttachedOffsets( RESOURCE->GetLua(), (void*)pUserData, vecPosition, vecRotation ) ) if( CLuaFunctionDefinitions::GetElementAttachedOffsets( RESOURCE->GetLua(), (void*)pUserData, vecPosition, vecRotation ) )
{ {
return RESOURCE->NewObject( vecRotation ); return RESOURCE->GetDomain()->GetMTALib()->Vector3->New( vecRotation );
} }
} }

View File

@ -0,0 +1,20 @@
/*********************************************************
*
* 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 "CMonoFunctions.h"
bool CMonoFunctions::Event::AddHandler( MonoString* msName, DWORD pUserData, lua_CFunction iLuaFunction, bool bPropagated, MonoString* msEventPriority )
{
return false;
}

View File

@ -50,7 +50,7 @@ MonoString* CMonoFunctions::Marker::GetType( DWORD pUserData )
if( CLuaFunctionDefinitions::GetMarkerType( RESOURCE->GetLua(), (void*)pUserData, szType ) ) if( CLuaFunctionDefinitions::GetMarkerType( RESOURCE->GetLua(), (void*)pUserData, szType ) )
{ {
return RESOURCE->NewString( szType ); return RESOURCE->GetDomain()->NewString( szType );
} }
} }
@ -80,7 +80,7 @@ MonoObject* CMonoFunctions::Marker::GetColor( DWORD pUserData )
if( CLuaFunctionDefinitions::GetMarkerColor( RESOURCE->GetLua(), (void*)pUserData, outColor ) ) if( CLuaFunctionDefinitions::GetMarkerColor( RESOURCE->GetLua(), (void*)pUserData, outColor ) )
{ {
return RESOURCE->NewObject( outColor ); return RESOURCE->GetDomain()->GetMTALib()->Color->New( outColor );
} }
} }
@ -95,7 +95,7 @@ MonoObject* CMonoFunctions::Marker::GetTarget( DWORD pUserData )
if( CLuaFunctionDefinitions::GetMarkerTarget( RESOURCE->GetLua(), (void*)pUserData, vecPosition ) ) if( CLuaFunctionDefinitions::GetMarkerTarget( RESOURCE->GetLua(), (void*)pUserData, vecPosition ) )
{ {
return RESOURCE->NewObject( vecPosition ); return RESOURCE->GetDomain()->GetMTALib()->Vector3->New( vecPosition );
} }
} }
@ -110,7 +110,7 @@ MonoString* CMonoFunctions::Marker::GetIcon( DWORD pUserData )
if( CLuaFunctionDefinitions::GetMarkerIcon( RESOURCE->GetLua(), (void*)pUserData, szIcon ) ) if( CLuaFunctionDefinitions::GetMarkerIcon( RESOURCE->GetLua(), (void*)pUserData, szIcon ) )
{ {
return RESOURCE->NewString( szIcon ); return RESOURCE->GetDomain()->NewString( szIcon );
} }
} }

View File

@ -36,7 +36,7 @@ MonoObject* CMonoFunctions::Object::GetScale( DWORD pUserData )
if( CLuaFunctionDefinitions::GetObjectScale( RESOURCE->GetLua(), (void*)pUserData, vecScale ) ) if( CLuaFunctionDefinitions::GetObjectScale( RESOURCE->GetLua(), (void*)pUserData, vecScale ) )
{ {
return RESOURCE->NewObject( vecScale ); return RESOURCE->GetDomain()->GetMTALib()->Vector3->New( vecScale );
} }
} }

View File

@ -131,7 +131,7 @@ MonoString* CMonoFunctions::Ped::GetClothesTexture( DWORD pUserData, unsigned ch
if( CLuaFunctionDefinitions::GetPedClothes( RESOURCE->GetLua(), (void*)pUserData, ucType, strOutTexture, strOutModel ) ) if( CLuaFunctionDefinitions::GetPedClothes( RESOURCE->GetLua(), (void*)pUserData, ucType, strOutTexture, strOutModel ) )
{ {
return RESOURCE->NewString( strOutTexture ); return RESOURCE->GetDomain()->NewString( strOutTexture );
} }
} }
@ -146,7 +146,7 @@ MonoString* CMonoFunctions::Ped::GetClothesModel( DWORD pUserData, unsigned char
if( CLuaFunctionDefinitions::GetPedClothes( RESOURCE->GetLua(), (void*)pUserData, ucType, strOutTexture, strOutModel ) ) if( CLuaFunctionDefinitions::GetPedClothes( RESOURCE->GetLua(), (void*)pUserData, ucType, strOutTexture, strOutModel ) )
{ {
return RESOURCE->NewString( strOutModel ); return RESOURCE->GetDomain()->NewString( strOutModel );
} }
} }
@ -635,7 +635,7 @@ MonoString* CMonoFunctions::Ped::GetBodyPartName( unsigned char ucID )
if( CLuaFunctionDefinitions::GetBodyPartName( RESOURCE->GetLua(), ucID, szName ) ) if( CLuaFunctionDefinitions::GetBodyPartName( RESOURCE->GetLua(), ucID, szName ) )
{ {
return RESOURCE->NewString( szName ); return RESOURCE->GetDomain()->NewString( szName );
} }
} }
@ -651,12 +651,12 @@ MonoArray* CMonoFunctions::Ped::GetClothesByTypeIndex( unsigned char ucType, uns
if( CLuaFunctionDefinitions::GetClothesByTypeIndex( RESOURCE->GetLua(), ucType, ucIndex, szTexture, szModel ) ) if( CLuaFunctionDefinitions::GetClothesByTypeIndex( RESOURCE->GetLua(), ucType, ucIndex, szTexture, szModel ) )
{ {
MonoArray* pArray = mono_array_new( RESOURCE->m_pMonoDomain, mono_get_string_class(), 2 ); MonoArray* pArray = mono_array_new( RESOURCE->GetDomain()->GetMonoPtr(), mono_get_string_class(), 2 );
if( pArray ) if( pArray )
{ {
mono_array_set( pArray, MonoString*, 0, RESOURCE->NewString( szTexture ) ); mono_array_set( pArray, MonoString*, 0, RESOURCE->GetDomain()->NewString( szTexture ) );
mono_array_set( pArray, MonoString*, 1, RESOURCE->NewString( szModel ) ); mono_array_set( pArray, MonoString*, 1, RESOURCE->GetDomain()->NewString( szModel ) );
return pArray; return pArray;
} }
@ -677,7 +677,7 @@ MonoArray* CMonoFunctions::Ped::GetTypeIndexFromClothes( MonoString* msTexture,
if( CLuaFunctionDefinitions::GetTypeIndexFromClothes( RESOURCE->GetLua(), szTexture, szModel, ucType, ucIndex ) ) if( CLuaFunctionDefinitions::GetTypeIndexFromClothes( RESOURCE->GetLua(), szTexture, szModel, ucType, ucIndex ) )
{ {
MonoArray* pArray = mono_array_new( RESOURCE->m_pMonoDomain, mono_get_char_class(), 2 ); MonoArray* pArray = mono_array_new( RESOURCE->GetDomain()->GetMonoPtr(), mono_get_char_class(), 2 );
if( pArray ) if( pArray )
{ {
@ -700,7 +700,7 @@ MonoString* CMonoFunctions::Ped::GetClothesTypeName( unsigned char ucType )
if( CLuaFunctionDefinitions::GetClothesTypeName( RESOURCE->GetLua(), ucType, szName ) ) if( CLuaFunctionDefinitions::GetClothesTypeName( RESOURCE->GetLua(), ucType, szName ) )
{ {
return RESOURCE->NewString( szName ); return RESOURCE->GetDomain()->NewString( szName );
} }
} }

View File

@ -126,7 +126,7 @@ MonoArray* CMonoFunctions::Player::GetAlivePlayers( void )
if( pLuaArguments ) if( pLuaArguments )
{ {
MonoArray* pArray = mono_array_new( RESOURCE->m_pMonoDomain, mono_get_uint32_class(), pLuaArguments->Count() ); MonoArray* pArray = mono_array_new( RESOURCE->GetDomain()->GetMonoPtr(), mono_get_uint32_class(), pLuaArguments->Count() );
vector< CLuaArgument* >::const_iterator iter = pLuaArguments->IterBegin(); vector< CLuaArgument* >::const_iterator iter = pLuaArguments->IterBegin();
@ -150,7 +150,7 @@ MonoArray* CMonoFunctions::Player::GetDeadPlayers( void )
if( pLuaArguments ) if( pLuaArguments )
{ {
MonoArray* pArray = mono_array_new( RESOURCE->m_pMonoDomain, mono_get_uint32_class(), pLuaArguments->Count() ); MonoArray* pArray = mono_array_new( RESOURCE->GetDomain()->GetMonoPtr(), mono_get_uint32_class(), pLuaArguments->Count() );
vector< CLuaArgument* >::const_iterator iter = pLuaArguments->IterBegin(); vector< CLuaArgument* >::const_iterator iter = pLuaArguments->IterBegin();
@ -204,7 +204,7 @@ MonoString* CMonoFunctions::Player::GetNametagText( DWORD pUserData )
if( CLuaFunctionDefinitions::GetPlayerNametagText( RESOURCE->GetLua(), (void*)pUserData, strOutText ) ) if( CLuaFunctionDefinitions::GetPlayerNametagText( RESOURCE->GetLua(), (void*)pUserData, strOutText ) )
{ {
return RESOURCE->NewString( strOutText ); return RESOURCE->GetDomain()->NewString( strOutText );
} }
} }
@ -224,7 +224,7 @@ MonoObject* CMonoFunctions::Player::GetNametagColor( DWORD pUserData )
&ucR, &ucG, &ucB &ucR, &ucG, &ucB
}; };
return RESOURCE->NewObject( "MultiTheftAuto", "Color", args, 3 ); return RESOURCE->GetDomain()->GetMTALib()->Color->New( args, 3 );
} }
} }
@ -250,7 +250,7 @@ MonoString* CMonoFunctions::Player::GetSerial( DWORD pUserData )
{ {
if( RESOURCE ) if( RESOURCE )
{ {
return RESOURCE->NewString( CLuaFunctionDefinitions::GetPlayerSerial( RESOURCE->GetLua(), (void*)pUserData ) ); return RESOURCE->GetDomain()->NewString( CLuaFunctionDefinitions::GetPlayerSerial( RESOURCE->GetLua(), (void*)pUserData ) );
} }
return NULL; return NULL;
@ -260,7 +260,7 @@ MonoString* CMonoFunctions::Player::GetUserName( DWORD pUserData )
{ {
if( RESOURCE ) if( RESOURCE )
{ {
return RESOURCE->NewString( CLuaFunctionDefinitions::GetPlayerUserName( RESOURCE->GetLua(), (void*)pUserData ) ); return RESOURCE->GetDomain()->NewString( CLuaFunctionDefinitions::GetPlayerUserName( RESOURCE->GetLua(), (void*)pUserData ) );
} }
return NULL; return NULL;
@ -289,7 +289,7 @@ MonoString* CMonoFunctions::Player::GetName( DWORD pUserData )
if( CLuaFunctionDefinitions::GetPlayerName( RESOURCE->GetLua(), (void*)pUserData, strOutName ) ) if( CLuaFunctionDefinitions::GetPlayerName( RESOURCE->GetLua(), (void*)pUserData, strOutName ) )
{ {
return RESOURCE->NewString( strOutName ); return RESOURCE->GetDomain()->NewString( strOutName );
} }
} }
@ -304,7 +304,7 @@ MonoString* CMonoFunctions::Player::GetIP( DWORD pUserData )
if( CLuaFunctionDefinitions::GetPlayerIP( RESOURCE->GetLua(), (void*)pUserData, strIP ) ) if( CLuaFunctionDefinitions::GetPlayerIP( RESOURCE->GetLua(), (void*)pUserData, strIP ) )
{ {
return RESOURCE->NewString( strIP ); return RESOURCE->GetDomain()->NewString( strIP );
} }
} }
@ -325,7 +325,7 @@ MonoString* CMonoFunctions::Player::GetVersion( DWORD pUserData )
{ {
if( RESOURCE ) if( RESOURCE )
{ {
return RESOURCE->NewString( CLuaFunctionDefinitions::GetPlayerVersion( RESOURCE->GetLua(), (void*)pUserData ) ); return RESOURCE->GetDomain()->NewString( CLuaFunctionDefinitions::GetPlayerVersion( RESOURCE->GetLua(), (void*)pUserData ) );
} }
return NULL; return NULL;
@ -339,9 +339,9 @@ MonoObject* CMonoFunctions::Player::GetACInfo( DWORD pUserData )
if( !pLuaTable.empty() ) if( !pLuaTable.empty() )
{ {
MonoString* msDetectedAC = RESOURCE->NewString( pLuaTable[ "DetectedAC" ]->GetString() ); MonoString* msDetectedAC = RESOURCE->GetDomain()->NewString( pLuaTable[ "DetectedAC" ]->GetString() );
MonoString* msD3D9MD5 = RESOURCE->NewString( pLuaTable[ "d3d9MD5" ]->GetString() ); MonoString* msD3D9MD5 = RESOURCE->GetDomain()->NewString( pLuaTable[ "d3d9MD5" ]->GetString() );
MonoString* msD3D9SHA256 = RESOURCE->NewString( pLuaTable[ "d3d9SHA256" ]->GetString() ); MonoString* msD3D9SHA256 = RESOURCE->GetDomain()->NewString( pLuaTable[ "d3d9SHA256" ]->GetString() );
unsigned int iD3D9Size = pLuaTable[ "d3d9Size" ]->GetNumber< unsigned int >(); unsigned int iD3D9Size = pLuaTable[ "d3d9Size" ]->GetNumber< unsigned int >();
@ -353,7 +353,7 @@ MonoObject* CMonoFunctions::Player::GetACInfo( DWORD pUserData )
&msD3D9SHA256 &msD3D9SHA256
}; };
return RESOURCE->NewObject( "MultiTheftAuto", "PlayerACInfo", args, 4 ); return RESOURCE->GetDomain()->GetMTALib()->GetClass( "PlayerACInfo" )->New( args, 4 );
} }
} }
return NULL; return NULL;
@ -365,7 +365,7 @@ MonoString* CMonoFunctions::Player::GetPlayerAnnounceValue( DWORD pElement, Mono
{ {
const char* szKey = mono_string_to_utf8( msKey ); const char* szKey = mono_string_to_utf8( msKey );
return RESOURCE->NewString( CLuaFunctionDefinitions::GetPlayerAnnounceValue( RESOURCE->GetLua(), (void*)pElement, szKey ) ); return RESOURCE->GetDomain()->NewString( CLuaFunctionDefinitions::GetPlayerAnnounceValue( RESOURCE->GetLua(), (void*)pElement, szKey ) );
} }
return NULL; return NULL;
@ -785,7 +785,7 @@ MonoObject* CMonoFunctions::Player::GetCameraMatrix( DWORD pPlayer )
&fFOV &fFOV
}; };
return RESOURCE->NewObject( "MultiTheftAuto", "CameraMatrix", args, 8 ); return RESOURCE->GetDomain()->GetMTALib()->GetClass( "CameraMatrix" )->New( args, 8 );
} }
} }

View File

@ -37,7 +37,7 @@ MonoObject* CMonoFunctions::RadarArea::GetSize( DWORD pUserData )
if( CLuaFunctionDefinitions::GetRadarAreaSize( RESOURCE->GetLua(), (void*)pUserData, vecSize ) ) if( CLuaFunctionDefinitions::GetRadarAreaSize( RESOURCE->GetLua(), (void*)pUserData, vecSize ) )
{ {
return RESOURCE->NewObject( vecSize ); return RESOURCE->GetDomain()->GetMTALib()->Vector2->New( vecSize );
} }
} }
@ -52,7 +52,7 @@ MonoObject* CMonoFunctions::RadarArea::GetColor( DWORD pUserData )
if( CLuaFunctionDefinitions::GetRadarAreaColor( RESOURCE->GetLua(), (void*)pUserData, outColor ) ) if( CLuaFunctionDefinitions::GetRadarAreaColor( RESOURCE->GetLua(), (void*)pUserData, outColor ) )
{ {
return RESOURCE->NewObject( outColor ); return RESOURCE->GetDomain()->GetMTALib()->Color->New( outColor );
} }
} }

View File

@ -105,7 +105,7 @@ MonoString* CMonoFunctions::Resource::GetInfo( DWORD pResource, MonoString* msAt
if( CLuaFunctionDefinitions::GetResourceInfo( RESOURCE->GetLua(), (void*)pResource, szAttribute, strOutInfo ) ) if( CLuaFunctionDefinitions::GetResourceInfo( RESOURCE->GetLua(), (void*)pResource, szAttribute, strOutInfo ) )
{ {
return RESOURCE->NewString( strOutInfo ); return RESOURCE->GetDomain()->NewString( strOutInfo );
} }
} }
@ -135,7 +135,7 @@ MonoString* CMonoFunctions::Resource::GetLoadFailureReason( DWORD pResource )
if( CLuaFunctionDefinitions::GetResourceLoadFailureReason( RESOURCE->GetLua(), (void*)pResource, strOutReason ) ) if( CLuaFunctionDefinitions::GetResourceLoadFailureReason( RESOURCE->GetLua(), (void*)pResource, strOutReason ) )
{ {
return RESOURCE->NewString( strOutReason ); return RESOURCE->GetDomain()->NewString( strOutReason );
} }
} }
@ -165,7 +165,7 @@ MonoString* CMonoFunctions::Resource::GetName( DWORD pResource )
if( CLuaFunctionDefinitions::GetResourceName( RESOURCE->GetLua(), (void*)pResource, strOut ) ) if( CLuaFunctionDefinitions::GetResourceName( RESOURCE->GetLua(), (void*)pResource, strOut ) )
{ {
return RESOURCE->NewString( strOut ); return RESOURCE->GetDomain()->NewString( strOut );
} }
} }
@ -178,7 +178,7 @@ MonoArray* CMonoFunctions::Resource::GetResources( void )
{ {
CLuaArguments* pLuaTable = CLuaFunctionDefinitions::GetResources( RESOURCE->GetLua() ); CLuaArguments* pLuaTable = CLuaFunctionDefinitions::GetResources( RESOURCE->GetLua() );
return RESOURCE->NewArray<DWORD, LUA_TLIGHTUSERDATA>( mono_get_uint32_class(), pLuaTable ); return RESOURCE->GetDomain()->NewArray<DWORD, LUA_TLIGHTUSERDATA>( mono_get_uint32_class(), pLuaTable );
} }
return NULL; return NULL;
@ -192,7 +192,7 @@ MonoString* CMonoFunctions::Resource::GetState( DWORD pResource )
if( CLuaFunctionDefinitions::GetResourceState( RESOURCE->GetLua(), (void*)pResource, strOut ) ) if( CLuaFunctionDefinitions::GetResourceState( RESOURCE->GetLua(), (void*)pResource, strOut ) )
{ {
return RESOURCE->NewString( strOut ); return RESOURCE->GetDomain()->NewString( strOut );
} }
} }

View File

@ -46,7 +46,7 @@ MonoString* CMonoFunctions::Team::GetName( DWORD pUserData )
if( CLuaFunctionDefinitions::GetTeamName( RESOURCE->GetLua(), (void*)pUserData, strOutName ) ) if( CLuaFunctionDefinitions::GetTeamName( RESOURCE->GetLua(), (void*)pUserData, strOutName ) )
{ {
return RESOURCE->NewString( strOutName ); return RESOURCE->GetDomain()->NewString( strOutName );
} }
} }
@ -61,7 +61,7 @@ MonoObject* CMonoFunctions::Team::GetColor( DWORD pUserData )
if( CLuaFunctionDefinitions::GetTeamColor( RESOURCE->GetLua(), (void*)pUserData, pColor.R, pColor.G, pColor.B ) ) if( CLuaFunctionDefinitions::GetTeamColor( RESOURCE->GetLua(), (void*)pUserData, pColor.R, pColor.G, pColor.B ) )
{ {
return RESOURCE->NewObject( pColor ); return RESOURCE->GetDomain()->GetMTALib()->Color->New( pColor );
} }
} }

View File

@ -47,7 +47,7 @@ MonoString* CMonoFunctions::Vehicle::GetType( DWORD pUserData )
if( CLuaFunctionDefinitions::GetVehicleType( RESOURCE->GetLua(), (void*)pUserData, strType ) ) if( CLuaFunctionDefinitions::GetVehicleType( RESOURCE->GetLua(), (void*)pUserData, strType ) )
{ {
return RESOURCE->NewString( strType ); return RESOURCE->GetDomain()->NewString( strType );
} }
} }
@ -63,7 +63,7 @@ MonoArray* CMonoFunctions::Vehicle::GetVariant( DWORD pUserData )
if( CLuaFunctionDefinitions::GetVehicleVariant( RESOURCE->GetLua(), (void*)pUserData, ucVariant, ucVariant2 ) ) if( CLuaFunctionDefinitions::GetVehicleVariant( RESOURCE->GetLua(), (void*)pUserData, ucVariant, ucVariant2 ) )
{ {
MonoArray* pArray = mono_array_new( RESOURCE->m_pMonoDomain, mono_get_char_class(), 2 ); MonoArray* pArray = mono_array_new( RESOURCE->GetDomain()->GetMonoPtr(), mono_get_char_class(), 2 );
if( pArray ) if( pArray )
{ {
@ -99,7 +99,7 @@ MonoObject* CMonoFunctions::Vehicle::GetColor( DWORD pUserData )
&pColor4 &pColor4
}; };
return RESOURCE->NewObject( "MultiTheftAuto", "VehicleColor", args, 4 ); return RESOURCE->GetDomain()->GetMTALib()->GetClass( "VehicleColor" )->New( args, 4 );
} }
} }
@ -161,7 +161,7 @@ MonoString* CMonoFunctions::Vehicle::GetName( DWORD pUserData )
if( CLuaFunctionDefinitions::GetVehicleName( RESOURCE->GetLua(), (void*)pUserData, strOutName ) ) if( CLuaFunctionDefinitions::GetVehicleName( RESOURCE->GetLua(), (void*)pUserData, strOutName ) )
{ {
return RESOURCE->NewString( strOutName ); return RESOURCE->GetDomain()->NewString( strOutName );
} }
} }
@ -176,7 +176,7 @@ MonoString* CMonoFunctions::Vehicle::GetNameFromModel( unsigned short usModel )
if( CLuaFunctionDefinitions::GetVehicleNameFromModel( RESOURCE->GetLua(), usModel, strOutName ) ) if( CLuaFunctionDefinitions::GetVehicleNameFromModel( RESOURCE->GetLua(), usModel, strOutName ) )
{ {
return RESOURCE->NewString( strOutName ); return RESOURCE->GetDomain()->NewString( strOutName );
} }
} }
@ -199,7 +199,7 @@ MonoArray* CMonoFunctions::Vehicle::GetOccupants( DWORD pUserData )
{ {
CLuaArguments* pLuaArguments = CLuaFunctionDefinitions::GetVehicleOccupants( RESOURCE->GetLua(), (void*)pUserData ); CLuaArguments* pLuaArguments = CLuaFunctionDefinitions::GetVehicleOccupants( RESOURCE->GetLua(), (void*)pUserData );
return RESOURCE->NewArray<DWORD, LUA_TLIGHTUSERDATA>( mono_get_uint32_class(), pLuaArguments ); return RESOURCE->GetDomain()->NewArray<DWORD, LUA_TLIGHTUSERDATA>( mono_get_uint32_class(), pLuaArguments );
} }
return NULL; return NULL;
@ -238,7 +238,7 @@ MonoObject* CMonoFunctions::Vehicle::GetTurnVelocity( DWORD pUserData )
if( CLuaFunctionDefinitions::GetVehicleTurnVelocity( RESOURCE->GetLua(), (void*)pUserData, vecVelocity ) ) if( CLuaFunctionDefinitions::GetVehicleTurnVelocity( RESOURCE->GetLua(), (void*)pUserData, vecVelocity ) )
{ {
return RESOURCE->NewObject( vecVelocity ); return RESOURCE->GetDomain()->GetMTALib()->Vector3->New( vecVelocity );
} }
} }
@ -253,7 +253,7 @@ MonoObject* CMonoFunctions::Vehicle::GetTurretPosition( DWORD pUserData )
if( CLuaFunctionDefinitions::GetVehicleTurretPosition( RESOURCE->GetLua(), (void*)pUserData, vecPosition ) ) if( CLuaFunctionDefinitions::GetVehicleTurretPosition( RESOURCE->GetLua(), (void*)pUserData, vecPosition ) )
{ {
return RESOURCE->NewObject( vecPosition ); return RESOURCE->GetDomain()->GetMTALib()->Vector3->New( vecPosition );
} }
} }
@ -281,7 +281,7 @@ MonoArray* CMonoFunctions::Vehicle::GetOfType( unsigned int uiModel )
{ {
CLuaArguments* pLuaArguments = CLuaFunctionDefinitions::GetVehiclesOfType( RESOURCE->GetLua(), uiModel ); CLuaArguments* pLuaArguments = CLuaFunctionDefinitions::GetVehiclesOfType( RESOURCE->GetLua(), uiModel );
return RESOURCE->NewArray<DWORD, LUA_TLIGHTUSERDATA>( mono_get_uint32_class(), pLuaArguments ); return RESOURCE->GetDomain()->NewArray<DWORD, LUA_TLIGHTUSERDATA>( mono_get_uint32_class(), pLuaArguments );
} }
return NULL; return NULL;
@ -308,7 +308,7 @@ MonoArray* CMonoFunctions::Vehicle::GetUpgrades( DWORD pUserData )
{ {
CLuaArguments* pLuaArguments = CLuaFunctionDefinitions::GetVehicleUpgrades( RESOURCE->GetLua(), (void*)pUserData ); CLuaArguments* pLuaArguments = CLuaFunctionDefinitions::GetVehicleUpgrades( RESOURCE->GetLua(), (void*)pUserData );
return RESOURCE->NewArray<uint, LUA_TNUMBER>( mono_get_uint32_class(), pLuaArguments ); return RESOURCE->GetDomain()->NewArray<uint, LUA_TNUMBER>( mono_get_uint32_class(), pLuaArguments );
} }
return NULL; return NULL;
@ -322,7 +322,7 @@ MonoString* CMonoFunctions::Vehicle::GetUpgradeSlotName( unsigned short usUpgrad
if( CLuaFunctionDefinitions::GetVehicleUpgradeSlotName( RESOURCE->GetLua(), usUpgrade, strOutName ) ) if( CLuaFunctionDefinitions::GetVehicleUpgradeSlotName( RESOURCE->GetLua(), usUpgrade, strOutName ) )
{ {
return RESOURCE->NewString( strOutName ); return RESOURCE->GetDomain()->NewString( strOutName );
} }
} }
@ -335,7 +335,7 @@ MonoArray* CMonoFunctions::Vehicle::GetCompatibleUpgrades( DWORD pUserData )
{ {
CLuaArguments* pLuaArguments = CLuaFunctionDefinitions::GetVehicleCompatibleUpgrades( RESOURCE->GetLua(), (void*)pUserData ); CLuaArguments* pLuaArguments = CLuaFunctionDefinitions::GetVehicleCompatibleUpgrades( RESOURCE->GetLua(), (void*)pUserData );
return RESOURCE->NewArray<uint, LUA_TNUMBER>( mono_get_uint32_class(), pLuaArguments ); return RESOURCE->GetDomain()->NewArray<uint, LUA_TNUMBER>( mono_get_uint32_class(), pLuaArguments );
} }
return NULL; return NULL;
@ -369,7 +369,7 @@ MonoObject* CMonoFunctions::Vehicle::GetWheelStates( DWORD pUserData )
&ucFrontLeft, &ucRearLeft, &ucFrontRight, &ucRearRight &ucFrontLeft, &ucRearLeft, &ucFrontRight, &ucRearRight
}; };
return RESOURCE->NewObject( "MultiTheftAuto.Vehicle", "VehicleWheelsState", args, 4 ); return RESOURCE->GetDomain()->GetMTALib()->GetClass( "Vehicle", "VehicleWheelsState" )->New( args, 4 );
} }
} }
@ -464,7 +464,7 @@ MonoString* CMonoFunctions::Vehicle::GetPlateText( DWORD pUserData )
if( CLuaFunctionDefinitions::GetVehiclePlateText( RESOURCE->GetLua(), (void*)pUserData, szPlateText ) ) if( CLuaFunctionDefinitions::GetVehiclePlateText( RESOURCE->GetLua(), (void*)pUserData, szPlateText ) )
{ {
return RESOURCE->NewString( szPlateText ); return RESOURCE->GetDomain()->NewString( szPlateText );
} }
} }
@ -624,7 +624,7 @@ MonoObject* CMonoFunctions::Vehicle::GetHeadLightColor( DWORD pUserData )
if( CLuaFunctionDefinitions::GetVehicleHeadLightColor( RESOURCE->GetLua(), (void*)pUserData, outColor ) ) if( CLuaFunctionDefinitions::GetVehicleHeadLightColor( RESOURCE->GetLua(), (void*)pUserData, outColor ) )
{ {
return RESOURCE->NewObject( outColor ); return RESOURCE->GetDomain()->GetMTALib()->Color->New( outColor );
} }
} }

View File

@ -76,7 +76,7 @@ MonoObject* CMonoFunctions::Water::GetVertexPosition( DWORD pUserData, int iVert
if( CLuaFunctionDefinitions::GetWaterVertexPosition( RESOURCE->GetLua(), (void*)pUserData, iVertexIndex, vecPosition ) ) if( CLuaFunctionDefinitions::GetWaterVertexPosition( RESOURCE->GetLua(), (void*)pUserData, iVertexIndex, vecPosition ) )
{ {
return RESOURCE->NewObject( vecPosition ); return RESOURCE->GetDomain()->GetMTALib()->Vector3->New( vecPosition );
} }
} }
@ -103,7 +103,7 @@ MonoObject* CMonoFunctions::Water::GetColor( void )
if( CLuaFunctionDefinitions::GetWaterColor( RESOURCE->GetLua(), pColor.R, pColor.G, pColor.B, pColor.A ) ) if( CLuaFunctionDefinitions::GetWaterColor( RESOURCE->GetLua(), pColor.R, pColor.G, pColor.B, pColor.A ) )
{ {
return RESOURCE->NewObject( pColor ); return RESOURCE->GetDomain()->GetMTALib()->Color->New( pColor );
} }
} }

View File

@ -21,7 +21,7 @@ MonoArray* CMonoFunctions::World::GetTime( void )
if( CLuaFunctionDefinitions::GetTime( RESOURCE->GetLua(), ucHour, ucMinute ) ) if( CLuaFunctionDefinitions::GetTime( RESOURCE->GetLua(), ucHour, ucMinute ) )
{ {
MonoArray* pArray = mono_array_new( RESOURCE->m_pMonoDomain, mono_get_char_class(), 2 ); MonoArray* pArray = mono_array_new( RESOURCE->GetDomain()->GetMonoPtr(), mono_get_char_class(), 2 );
mono_array_set( pArray, unsigned char, 0, ucHour ); mono_array_set( pArray, unsigned char, 0, ucHour );
mono_array_set( pArray, unsigned char, 1, ucMinute ); mono_array_set( pArray, unsigned char, 1, ucMinute );
@ -41,7 +41,7 @@ MonoArray* CMonoFunctions::World::GetWeather( void )
if( CLuaFunctionDefinitions::GetWeather( RESOURCE->GetLua(), ucWeather, ucWeatherBlending ) ) if( CLuaFunctionDefinitions::GetWeather( RESOURCE->GetLua(), ucWeather, ucWeatherBlending ) )
{ {
MonoArray* pArray = mono_array_new( RESOURCE->m_pMonoDomain, mono_get_char_class(), 2 ); MonoArray* pArray = mono_array_new( RESOURCE->GetDomain()->GetMonoPtr(), mono_get_char_class(), 2 );
mono_array_set( pArray, unsigned char, 0, ucWeather ); mono_array_set( pArray, unsigned char, 0, ucWeather );
mono_array_set( pArray, unsigned char, 1, ucWeatherBlending ); mono_array_set( pArray, unsigned char, 1, ucWeatherBlending );
@ -63,7 +63,7 @@ MonoString* CMonoFunctions::World::GetZoneName( MonoObject* mPosition, bool bCit
if( CLuaFunctionDefinitions::GetZoneName( RESOURCE->GetLua(), vecPosition, strOutName, bCitiesOnly ) ) if( CLuaFunctionDefinitions::GetZoneName( RESOURCE->GetLua(), vecPosition, strOutName, bCitiesOnly ) )
{ {
return RESOURCE->NewString( strOutName ); return RESOURCE->GetDomain()->NewString( strOutName );
} }
} }
@ -275,12 +275,12 @@ MonoArray* CMonoFunctions::World::GetSunColor( void )
{ {
pCore.A = pCorona.A = 255; pCore.A = pCorona.A = 255;
MonoObject* pCoreObject = RESOURCE->NewObject( pCore ); MonoObject* pCoreObject = RESOURCE->GetDomain()->GetMTALib()->Color->New( pCore );
MonoObject* pCoronaObject = RESOURCE->NewObject( pCorona ); MonoObject* pCoronaObject = RESOURCE->GetDomain()->GetMTALib()->Color->New( pCorona );
if( pCoreObject && pCoronaObject ) if( pCoreObject && pCoronaObject )
{ {
MonoArray* pMonoArray = mono_array_new( RESOURCE->m_pMonoDomain, CMonoObject::GetClass( pCoreObject ), 2 ); MonoArray* pMonoArray = mono_array_new( RESOURCE->GetDomain()->GetMonoPtr(), CMonoObject::GetClass( pCoreObject ), 2 );
mono_array_set( pMonoArray, MonoObject*, 0, pCoreObject ); mono_array_set( pMonoArray, MonoObject*, 0, pCoreObject );
mono_array_set( pMonoArray, MonoObject*, 1, pCoronaObject ); mono_array_set( pMonoArray, MonoObject*, 1, pCoronaObject );
@ -301,7 +301,7 @@ MonoObject* CMonoFunctions::World::GetWindVelocity( void )
if( CLuaFunctionDefinitions::GetWindVelocity( RESOURCE->GetLua(), vecVelocity.fX, vecVelocity.fY, vecVelocity.fZ ) ) if( CLuaFunctionDefinitions::GetWindVelocity( RESOURCE->GetLua(), vecVelocity.fX, vecVelocity.fY, vecVelocity.fZ ) )
{ {
return RESOURCE->NewObject( vecVelocity ); return RESOURCE->GetDomain()->GetMTALib()->Vector3->New( vecVelocity );
} }
} }
@ -393,12 +393,12 @@ MonoArray* CMonoFunctions::World::GetSkyGradient( void )
{ {
pCore.A = pCorona.A = 255; pCore.A = pCorona.A = 255;
MonoObject* pCoreObject = RESOURCE->NewObject( pCore ); MonoObject* pCoreObject = RESOURCE->GetDomain()->GetMTALib()->Color->New( pCore );
MonoObject* pCoronaObject = RESOURCE->NewObject( pCorona ); MonoObject* pCoronaObject = RESOURCE->GetDomain()->GetMTALib()->Color->New( pCorona );
if( pCoreObject && pCoronaObject ) if( pCoreObject && pCoronaObject )
{ {
MonoArray* pMonoArray = mono_array_new( RESOURCE->m_pMonoDomain, CMonoObject::GetClass( pCoreObject ), 2 ); MonoArray* pMonoArray = mono_array_new( RESOURCE->GetDomain()->GetMonoPtr(), CMonoObject::GetClass( pCoreObject ), 2 );
mono_array_set( pMonoArray, MonoObject*, 0, pCoreObject ); mono_array_set( pMonoArray, MonoObject*, 0, pCoreObject );
mono_array_set( pMonoArray, MonoObject*, 1, pCoronaObject ); mono_array_set( pMonoArray, MonoObject*, 1, pCoronaObject );
@ -424,7 +424,7 @@ MonoObject* CMonoFunctions::World::GetHeatHaze( void )
&heatHazeSettings &heatHazeSettings
}; };
return RESOURCE->NewObject( "MultiTheftAuto", "HeatHazeSettings", args, 1 ); return RESOURCE->GetDomain()->GetMTALib()->GetClass( "HeatHazeSettings" )->New( args, 1 );
} }
} }

92
mta-mono/src/CMonoGC.cpp Normal file
View File

@ -0,0 +1,92 @@
/*********************************************************
*
* 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 "CMonoGC.h"
CMonoGC::CMonoGC( void )
{
}
void CMonoGC::Collect( int generation )
{
mono_gc_collect( generation );
}
unsigned int CMonoGC::Hold( MonoObject* obj )
{
if( obj )
{
mono_gchandle_new_weakref( reinterpret_cast< MonoObject* >( obj ), false );
}
return -1;
}
unsigned int CMonoGC::HoldWithHope( MonoObject* obj )
{
if( obj )
{
return mono_gchandle_new_weakref( reinterpret_cast< MonoObject* >( obj ), true );
}
return -1;
}
unsigned int CMonoGC::Keep( MonoObject* obj )
{
if( obj )
{
return mono_gchandle_new( reinterpret_cast< MonoObject* >( obj ), false );
}
return -1;
}
unsigned int CMonoGC::Pin( MonoObject* obj )
{
if( obj )
{
return mono_gchandle_new( reinterpret_cast< MonoObject* >( obj ), true );
}
return -1;
}
int CMonoGC::GetMaxGeneration()
{
return mono_gc_max_generation();
}
int64 CMonoGC::GetHeapSize()
{
return mono_gc_get_heap_size();
}
void CMonoGC::ReleaseGCHandle( unsigned int handle )
{
if( handle == -1 )
{
return;
}
mono_gchandle_free( handle );
}
MonoObject* CMonoGC::GetGCHandleTarget( unsigned int handle )
{
if( handle == -1 )
{
return nullptr;
}
return mono_gchandle_get_target( handle );
}

36
mta-mono/src/CMonoGC.h Normal file
View File

@ -0,0 +1,36 @@
/*********************************************************
*
* 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 CMonoGC;
#ifndef __CMONOGC_H
#define __CMONOGC_H
class CMonoGC
{
public:
CMonoGC ( void );
void Collect ( int generation = -1 );
unsigned int Hold ( MonoObject* obj );
unsigned int HoldWithHope ( MonoObject* obj );
unsigned int Keep ( MonoObject* obj );
unsigned int Pin ( MonoObject* obj );
int GetMaxGeneration ( void );
int64 GetHeapSize ( void );
void ReleaseGCHandle ( unsigned int handle );
MonoObject* GetGCHandleTarget ( unsigned int handle );
};
#endif

View File

@ -0,0 +1,50 @@
/*********************************************************
*
* 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 "CMonoInterface.h"
#include "CMonoFunctions.h"
CMonoInterface::CMonoInterface( void )
{
mono_set_dirs( "mods/deathmatch/mono/lib", "mods/deathmatch/mono/etc" );
mono_set_signal_chaining( false );
mono_debug_init( MONO_DEBUG_FORMAT_MONO );
this->m_pMonoDomain = mono_jit_init_version( "Mono Root", "v4.0.30319" );
mono_domain_set_config( this->m_pMonoDomain, "mods/deathmatch/", "mods/deathmatch/mono/etc/mono/4.5/machine.config" );
CMonoFunctions::AddInternals();
this->m_pGC = new CMonoGC;
}
CMonoInterface::~CMonoInterface( void )
{
mono_jit_cleanup( this->m_pMonoDomain );
SAFE_DELETE( this->m_pGC );
}
CMonoDomain* CMonoInterface::CreateAppdomain( CResource* pResource, char* szName, char* szConfig )
{
MonoDomain* pMonoDomain = mono_domain_create_appdomain( szName, szConfig );
if( pMonoDomain )
{
return new CMonoDomain( pResource, pMonoDomain );
}
return nullptr;
}

View File

@ -0,0 +1,47 @@
/*********************************************************
*
* 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 CMonoInterface;
#ifndef __CMONOINTERFACE_H
#define __CMONOINTERFACE_H
#include "CMonoGC.h"
#include "CMonoDomain.h"
#include "CResource.h"
class CMonoInterface
{
private:
MonoDomain* m_pMonoDomain;
CMonoGC* m_pGC;
public:
CMonoInterface ( void );
~CMonoInterface ( void );
CMonoDomain* CreateAppdomain ( CResource* pResource, char* szName, char* szConfig );
CMonoGC* GetGC ( void ) { return this->m_pGC; }
#pragma region Static methods
static string GetBinariesDirectory( void )
{
return "mods/deathmatch/resources/[ire]";
}
#pragma endregion
};
#endif

View File

@ -0,0 +1,68 @@
/*********************************************************
*
* 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 "CMonoMTALib.h"
CMonoMTALib::CMonoMTALib( CMonoDomain* pDomain )
{
this->m_pAssembly = nullptr;
this->m_pImage = nullptr;
this->m_pDomain = pDomain;
string strPath( CMonoInterface::GetBinariesDirectory() + "/" + pDomain->GetResource()->GetName() + "/MultiTheftAuto.dll" );
this->m_pAssembly = pDomain->OpenAssembly( strPath.c_str() );
if( this->m_pAssembly )
{
this->m_pImage = mono_assembly_get_image( this->m_pAssembly );
if( this->m_pImage )
{
this->Color = this->GetClass( "Color" );
this->Vector2 = this->GetClass( "Vector2" );
this->Vector3 = this->GetClass( "Vector3" );
MonoClass* pMonoClass = mono_class_from_name( this->m_pImage, "MultiTheftAuto", "MultiTheftAuto" );
if( pMonoClass )
{
MonoObject* pMonoObject = this->m_pDomain->CreateObject( pMonoClass );
mono_gchandle_new( pMonoObject, false );
mono_runtime_object_init( pMonoObject );
}
}
}
}
CMonoMTALib::~CMonoMTALib( void )
{
this->m_pDomain = nullptr;
this->m_pAssembly = nullptr;
this->m_pImage = nullptr;
}
CMonoClass* CMonoMTALib::GetClass( const char* szName )
{
return this->GetDomain()->FindOrAdd( mono_class_from_name( this->m_pImage, "MultiTheftAuto", szName ) );
}
CMonoClass* CMonoMTALib::GetClass( const char* szNameSpace, const char* szName )
{
char szBuffer[ 128 ];
sprintf( szBuffer, "MultiTheftAuto.%s", szNameSpace );
return this->GetDomain()->FindOrAdd( mono_class_from_name( this->m_pImage, szBuffer, szName ) );
}

View File

@ -0,0 +1,43 @@
/*********************************************************
*
* 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 CMonoMTALib;
#ifndef __CMONOMTALIB_H
#define __CMONOMTALIB_H
#include "CMonoDomain.h"
#include "CMonoClass.h"
class CMonoMTALib
{
private:
MonoAssembly* m_pAssembly;
MonoImage* m_pImage;
CMonoDomain* m_pDomain;
public:
CMonoClass* Color;
CMonoClass* Vector2;
CMonoClass* Vector3;
public:
CMonoMTALib ( CMonoDomain* pDomain );
~CMonoMTALib ( void );
CMonoClass* GetClass ( const char* szName );
CMonoClass* GetClass ( const char* szNameSpace, const char* szName );
CMonoDomain* GetDomain ( void ) { return this->m_pDomain; }
};
#endif

View File

@ -10,6 +10,7 @@
* *
*********************************************************/ *********************************************************/
#include "StdInc.h"
#include "CMonoObject.h" #include "CMonoObject.h"
MonoClass* CMonoObject::GetClass( MonoObject* pObject ) MonoClass* CMonoObject::GetClass( MonoObject* pObject )

View File

@ -10,62 +10,121 @@
* *
*********************************************************/ *********************************************************/
#include "StdInc.h"
#include "CResource.h" #include "CResource.h"
#include "CResourceManager.h" #include "CResourceManager.h"
#include "CFunctions.h"
#include "include/ILuaModuleManager.h" #include "include/ILuaModuleManager.h"
#include "lua/CLuaFunctionDefinitions.h" #include "lua/CLuaFunctionDefinitions.h"
extern ILuaModuleManager10 *g_pModuleManager; extern ILuaModuleManager10 *g_pModuleManager;
extern CResourceManager *g_pResourceManager; extern CResourceManager *g_pResourceManager;
CResource::CResource( lua_State *pLuaVM, string sName ) CResource::CResource( CMonoInterface* pMono, lua_State *pLuaVM, string sName )
{ {
this->m_pMono = pMono;
this->m_pLuaVM = pLuaVM; this->m_pLuaVM = pLuaVM;
this->m_sName = sName; this->m_sName = sName;
this->m_pMonoAssembly = NULL; this->m_pMonoAssembly = nullptr;
this->m_pMonoAssemblyLib = NULL; this->m_pMonoGCHandle = 0;
this->m_pMonoGCHandle = NULL; this->m_pMonoDomain = nullptr;
this->m_pMonoDomain = NULL; this->m_pMonoImage = nullptr;
this->m_pMonoImage = NULL; this->m_pMonoClass = nullptr;
this->m_pMonoImageLib = NULL;
this->m_pMonoClass = NULL;
} }
CResource::~CResource( void ) CResource::~CResource( void )
{ {
this->GetMono()->GetGC()->Collect( this->GetMono()->GetGC()->GetMaxGeneration() );
mono_domain_set( mono_get_root_domain(), false ); mono_domain_set( mono_get_root_domain(), false );
if( this->m_pMonoDomain ) if( this->m_pMonoDomain )
{ {
mono_domain_unload( this->m_pMonoDomain ); this->m_pMonoDomain->Unload();
this->m_pMonoDomain = nullptr;
} }
mono_gc_collect( mono_gc_max_generation() );
g_pResourceManager->RemoveFromList( this ); g_pResourceManager->RemoveFromList( this );
this->m_pMonoAssembly = NULL; this->m_pMonoAssembly = nullptr;
this->m_pMonoAssemblyLib = NULL; this->m_pMonoGCHandle = 0;
this->m_pMonoGCHandle = NULL; this->m_pMonoDomain = nullptr;
this->m_pMonoDomain = NULL; this->m_pMonoImage = nullptr;
this->m_pMonoImage = NULL; this->m_pMonoClass = nullptr;
this->m_pMonoImageLib = NULL;
this->m_pMonoClass = NULL;
this->m_pLuaVM = NULL; this->m_pMono = nullptr;
this->m_pLuaVM = nullptr;
this->m_sName = nullptr;
}
bool CResource::CallEvent( string strEventName, void* pThis, void* pSource, void* pClient, void **args )
{
MonoEvent* pEvent = nullptr;
MonoMethod* method = nullptr;
MonoClass* klass = this->GetDomain()->GetMTALib()->GetClass( "Element" )->GetMonoPtr();
g_pModuleManager->DebugPrintf( this->GetLua(), "CResource::CallEvent::%s", strEventName.substr( 2 ).c_str() );
gpointer iter;
while( klass )
{
iter = nullptr;
while( pEvent = mono_class_get_events( klass, &iter ) )
{
if( !strcmp( strEventName.substr( 2 ).c_str(), mono_event_get_name( pEvent ) ) )
{
method = mono_event_get_raise_method( pEvent );
break;
}
}
klass = mono_class_get_parent( klass );
}
if( method )
{
mono_runtime_invoke( method, pThis, args, nullptr );
return true;
}
else
{
g_pModuleManager->ErrorPrintf( "mono: method not found\n" );
}
return false;
}
void CResource::RegisterEvents( void )
{
if( this->m_pLuaVM )
{
if( g_pModuleManager->RegisterFunction( this->m_pLuaVM, "mono_event_handler", CFunctions::monoEventHandler ) )
{
luaL_dostring( this->m_pLuaVM, "addEventHandler( 'onElementDestroy', root, \
function( ... ) \
mono_event_handler( eventName, this, source, client, ... );\
end \
)"
);
}
}
} }
bool CResource::Init( void ) bool CResource::Init( void )
{ {
if( this->m_pLuaVM ) if( this->m_pLuaVM )
{ {
string sDirectory ( "mods/deathmatch/resources/[ire]/" + this->m_sName + "/" ); string sDirectory ( CMonoInterface::GetBinariesDirectory() + "/" + this->m_sName + "/" );
string sPath ( sDirectory + this->m_sName + ".dll" ); string sPath ( sDirectory + this->m_sName + ".dll" );
string sNamespace ( this->m_sName ); string sNamespace ( this->m_sName );
string sClass ( "Program" ); string sClass ( "Program" );
this->m_pMonoDomain = mono_domain_create_appdomain( const_cast< char* >( this->m_sName.c_str( ) ), NULL ); this->m_pMonoDomain = this->GetMono()->CreateAppdomain( this, const_cast< char* >( this->m_sName.c_str() ), nullptr );
if( !this->m_pMonoDomain ) if( !this->m_pMonoDomain )
{ {
@ -74,16 +133,11 @@ bool CResource::Init( void )
return false; return false;
} }
mono_domain_set( this->m_pMonoDomain, false ); this->m_pMonoDomain->Set( false );
this->m_pMonoAssemblyLib = mono_domain_assembly_open( this->m_pMonoDomain, ( sDirectory + "MultiTheftAuto.dll" ).c_str() ); this->m_pMonoDomain->Init();
if( this->m_pMonoAssemblyLib ) this->m_pMonoAssembly = this->m_pMonoDomain->OpenAssembly( sPath.c_str() );
{
this->m_pMonoImageLib = mono_assembly_get_image( this->m_pMonoAssemblyLib );
}
this->m_pMonoAssembly = mono_domain_assembly_open( this->m_pMonoDomain, sPath.c_str() );
if( !this->m_pMonoAssembly ) if( !this->m_pMonoAssembly )
{ {
@ -92,10 +146,12 @@ bool CResource::Init( void )
return false; return false;
} }
this->RegisterEvents();
this->m_pMonoImage = mono_assembly_get_image( this->m_pMonoAssembly ); this->m_pMonoImage = mono_assembly_get_image( this->m_pMonoAssembly );
this->m_pMonoClass = mono_class_from_name( this->m_pMonoImage, sNamespace.c_str(), sClass.c_str() ); this->m_pMonoClass = mono_class_from_name( this->m_pMonoImage, sNamespace.c_str(), sClass.c_str() );
MonoObject *pMonoObject = mono_object_new( this->m_pMonoDomain, this->m_pMonoClass ); MonoObject *pMonoObject = this->m_pMonoDomain->CreateObject( this->m_pMonoClass );
mono_gchandle_new( pMonoObject, false ); mono_gchandle_new( pMonoObject, false );
@ -127,139 +183,47 @@ bool CResource::RegisterFunction( const char *szFunctionName, lua_CFunction Func
return true; return true;
} }
MonoClass* CResource::GetClassFromName( const char* szNamespace, const char* szName ) void CResource::Printf( const char* szFormat, ... )
{ {
MonoClass* pMonoClass = mono_class_from_name( this->m_pMonoImage, szNamespace, szName ); va_list args;
if( !pMonoClass ) va_start( args, szFormat );
{
pMonoClass = mono_class_from_name( this->m_pMonoImageLib, szNamespace, szName );
}
return pMonoClass; char szBuffer[ 255 ];
vsprintf( szBuffer, szFormat, args );
va_end( args );
g_pModuleManager->Printf( szBuffer );
} }
MonoObject* CResource::NewObject( const char* szNamespace, const char* szName ) void CResource::DebugPrintf( const char* szFormat, ... )
{ {
MonoClass* pClass = this->GetClassFromName( szNamespace, szName ); va_list args;
if( pClass ) va_start( args, szFormat );
{
MonoObject* pObject = CMonoClass::New( pClass, mono_domain_get() );
if( pObject ) char szBuffer[ 255 ];
{
return pObject;
}
else
{
g_pModuleManager->ErrorPrintf( "%s:%d: failed to create instance of '%s::%s'\n", __FILE__, __LINE__, szNamespace, szName );
}
}
else
{
g_pModuleManager->ErrorPrintf( "%s:%d: class '%s::%s' not found\n", __FILE__, __LINE__, szNamespace, szName );
}
return nullptr; vsprintf( szBuffer, szFormat, args );
va_end( args );
g_pModuleManager->DebugPrintf( this->m_pLuaVM, szBuffer );
} }
MonoObject* CResource::NewObject( SColor& pColor ) void CResource::ErrorPrintf( const char* szFormat, ... )
{ {
MonoClass* pClass = this->GetClassFromName( "MultiTheftAuto", "Color" ); va_list args;
if( pClass ) va_start( args, szFormat );
{
MonoObject* pObject = CMonoClass::New( pClass, mono_domain_get(), pColor );
if( pObject ) char szBuffer[ 255 ];
{
return pObject;
}
else
{
g_pModuleManager->ErrorPrintf( "%s:%d: failed to create instance of 'MultiTheftAuto::Color'\n", __FILE__, __LINE__ );
}
}
else
{
g_pModuleManager->ErrorPrintf( "%s:%d: class 'MultiTheftAuto::Color' not found\n", __FILE__, __LINE__ );
}
return nullptr; vsprintf( szBuffer, szFormat, args );
}
va_end( args );
MonoObject* CResource::NewObject( Vector2& vecVector )
{ g_pModuleManager->ErrorPrintf( szBuffer );
MonoClass* pClass = this->GetClassFromName( "MultiTheftAuto", "Vector2" );
if( pClass )
{
MonoObject* pObject = CMonoClass::New( pClass, mono_domain_get(), vecVector );
if( pObject )
{
return pObject;
}
else
{
g_pModuleManager->ErrorPrintf( "%s:%d: failed to create instance of 'MultiTheftAuto::Vector2'\n", __FILE__, __LINE__ );
}
}
else
{
g_pModuleManager->ErrorPrintf( "%s:%d: class 'MultiTheftAuto::Vector2' not found\n", __FILE__, __LINE__ );
}
return nullptr;
}
MonoObject* CResource::NewObject( Vector3& vecVector )
{
MonoClass* pClass = this->GetClassFromName( "MultiTheftAuto", "Vector3" );
if( pClass )
{
MonoObject* pObject = CMonoClass::New( pClass, mono_domain_get(), vecVector );
if( pObject )
{
return pObject;
}
else
{
g_pModuleManager->ErrorPrintf( "%s:%d: failed to create instance of 'MultiTheftAuto::Vector3'\n", __FILE__, __LINE__ );
}
}
else
{
g_pModuleManager->ErrorPrintf( "%s:%d: class 'MultiTheftAuto::Vector3' not found\n", __FILE__, __LINE__ );
}
return nullptr;
}
MonoObject* CResource::NewObject( const char* szNamespace, const char* szName, void** args, int argc )
{
MonoClass* pClass = this->GetClassFromName( szNamespace, szName );
if( pClass )
{
MonoObject* pObject = CMonoClass::New( pClass, mono_domain_get(), args, argc );
if( pObject )
{
return pObject;
}
else
{
g_pModuleManager->ErrorPrintf( "%s:%d: failed to create instance of '%s::%s'\n", __FILE__, __LINE__, szNamespace, szName );
}
}
else
{
g_pModuleManager->ErrorPrintf( "%s:%d: class '%s::%s' not found\n", __FILE__, __LINE__, szNamespace, szName );
}
return nullptr;
} }

View File

@ -17,6 +17,7 @@ class CResource;
#include "Common.h" #include "Common.h"
#include "CMonoClass.h" #include "CMonoClass.h"
#include "CMonoInterface.h"
#include "extra/CLuaArguments.h" #include "extra/CLuaArguments.h"
class CResource class CResource
@ -24,81 +25,36 @@ class CResource
private: private:
string m_sName; string m_sName;
MonoAssembly *m_pMonoAssembly; MonoAssembly* m_pMonoAssembly;
MonoAssembly *m_pMonoAssemblyLib; MonoImage* m_pMonoImage;
MonoImage *m_pMonoImage; MonoClass* m_pMonoClass;
MonoImage *m_pMonoImageLib;
MonoClass *m_pMonoClass;
uint32_t m_pMonoGCHandle; uint32_t m_pMonoGCHandle;
public: lua_State* m_pLuaVM;
lua_State *m_pLuaVM;
MonoDomain *m_pMonoDomain;
CResource ( lua_State *pLuaVM, string sName ); CMonoInterface* m_pMono;
CMonoDomain* m_pMonoDomain;
public:
CResource ( CMonoInterface* m_pMono, lua_State *pLuaVM, string sName );
~CResource ( void ); ~CResource ( void );
bool CallEvent ( string strEventName, void* pThis, void* pSource, void* pClient, void **args );
void RegisterEvents ( void );
bool Init ( void ); bool Init ( void );
void OnStopping ( void ); void OnStopping ( void );
void DoPulse ( void ); void DoPulse ( void );
bool RegisterFunction ( const char *szFunctionName, lua_CFunction Func ); bool RegisterFunction ( const char *szFunctionName, lua_CFunction Func );
MonoClass* GetClassFromName( const char* szNamespace, const char* szName ); void Printf ( const char* szFormat, ... );
void DebugPrintf ( const char* szFormat, ... );
MonoObject* NewObject( const char* szNamespace, const char* szName ); void ErrorPrintf ( const char* szFormat, ... );
MonoObject* NewObject( SColor& pColor );
MonoObject* NewObject( Vector2& vecVector );
MonoObject* NewObject( Vector3& vecVector );
MonoObject* NewObject( const char* szNamespace, const char* szName, void** args, int argc );
MonoString* NewString( const char* szText )
{
return mono_string_new( this->m_pMonoDomain, szText );
}
MonoString* NewString( string strText )
{
return mono_string_new( this->m_pMonoDomain, strText.c_str() );
}
template <class T, int LuaType> MonoArray* NewArray( MonoClass* pMonoClass, CLuaArguments* pLuaArguments = NULL )
{
MonoArray* pArray = mono_array_new( this->m_pMonoDomain, pMonoClass, pLuaArguments ? pLuaArguments->Count() : 0 );
if( pLuaArguments )
{
vector< CLuaArgument* >::const_iterator iter = pLuaArguments->IterBegin();
for( unsigned int i = 0; iter != pLuaArguments->IterEnd(); iter++, i++ )
{
if( LuaType == LUA_TBOOLEAN )
{
mono_array_set( pArray, T, i, (T)( ( *iter )->GetBoolean() ) );
}
else if( LuaType == LUA_TLIGHTUSERDATA )
{
mono_array_set( pArray, T, i, (T)( ( *iter )->GetLightUserData() ) );
}
else if( LuaType == LUA_TNUMBER )
{
mono_array_set( pArray, T, i, ( *iter )->GetNumber< T >() );
}
else if( LuaType == LUA_TSTRING )
{
mono_array_set( pArray, T, i, (T)( ( *iter )->GetString() ) );
}
else if( LuaType == LUA_TUSERDATA )
{
mono_array_set( pArray, T, i, (T)( ( *iter )->GetLightUserData() ) );
}
}
}
return pArray;
}
string GetName ( void ) { return this->m_sName; } string GetName ( void ) { return this->m_sName; }
lua_State *GetLua ( void ) { return this->m_pLuaVM; } lua_State* GetLua ( void ) { return this->m_pLuaVM; }
CMonoInterface* GetMono ( void ) { return this->m_pMono; }
CMonoDomain* GetDomain ( void ) { return this->m_pMonoDomain; }
}; };
#endif #endif

View File

@ -10,15 +10,12 @@
* *
*********************************************************/ *********************************************************/
#include "StdInc.h"
#include "CResourceManager.h" #include "CResourceManager.h"
CResourceManager::CResourceManager( void ) CResourceManager::CResourceManager( CMonoInterface* pMono )
{ {
mono_set_dirs( "mods/deathmatch/mono/lib", "mods/deathmatch/mono/etc" ); this->m_pMono = pMono;
this->m_pMonoDomain = mono_jit_init_version( "Mono Root", "v4.0.30319" );
CMonoFunctions::AddInternals();
} }
CResourceManager::~CResourceManager( void ) CResourceManager::~CResourceManager( void )
@ -27,8 +24,6 @@ CResourceManager::~CResourceManager( void )
{ {
delete iter; delete iter;
} }
mono_jit_cleanup( this->m_pMonoDomain );
} }
CResource* CResourceManager::Create( lua_State* luaVM, string strName ) CResource* CResourceManager::Create( lua_State* luaVM, string strName )
@ -44,7 +39,7 @@ CResource* CResourceManager::Create( lua_State* luaVM, string strName )
return nullptr; return nullptr;
} }
CResource *pResource = new CResource( luaVM, strName ); CResource *pResource = new CResource( this->m_pMono, luaVM, strName );
this->AddToList( pResource ); this->AddToList( pResource );
@ -63,7 +58,7 @@ CResource* CResourceManager::GetFromList( lua_State* pLuaVM )
{ {
for( auto iter : this->m_List ) for( auto iter : this->m_List )
{ {
if( iter->m_pLuaVM == pLuaVM ) if( iter->GetLua() == pLuaVM )
{ {
return iter; return iter;
} }
@ -76,7 +71,7 @@ CResource* CResourceManager::GetFromList( MonoDomain* pDomain )
{ {
for( auto iter : this->m_List ) for( auto iter : this->m_List )
{ {
if( iter->m_pMonoDomain == pDomain ) if( iter->GetDomain()->GetMonoPtr() == pDomain )
{ {
return iter; return iter;
} }

View File

@ -15,19 +15,20 @@ class CResourceManager;
#ifndef __CRESOURCEMANAGER_H #ifndef __CRESOURCEMANAGER_H
#define __CRESOURCEMANAGER_H #define __CRESOURCEMANAGER_H
#include "CMonoFunctions.h" #include "CResource.h"
#include "CMonoInterface.h"
extern ILuaModuleManager10 *g_pModuleManager; extern ILuaModuleManager10 *g_pModuleManager;
class CResourceManager class CResourceManager
{ {
private: private:
CMonoInterface* m_pMono;
list< CResource* > m_List; list< CResource* > m_List;
MonoDomain *m_pMonoDomain;
public: public:
CResourceManager ( void ); CResourceManager ( CMonoInterface* pMono );
~CResourceManager ( void ); ~CResourceManager ( void );
CResource* Create ( lua_State* luaVM, string strName ); CResource* Create ( lua_State* luaVM, string strName );

View File

@ -1,3 +1,4 @@
#include "StdInc.h"
#include "Common.h" #include "Common.h"
CVehicleColor::CVehicleColor( void ) CVehicleColor::CVehicleColor( void )

View File

@ -16,44 +16,6 @@
* *
*********************************************************/ *********************************************************/
extern "C"
{
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}
#ifdef WIN32
#define MTAEXPORT extern "C" __declspec(dllexport)
#else
#define MTAEXPORT extern "C"
#endif
#include <list>
#include <vector>
#include <map>
#include <string.h>
#include <sys/stat.h>
#include <assert.h>
#pragma warning( push )
#pragma warning( disable: 4996 )
#include <glib.h>
#pragma warning( pop )
#include <mono/jit/jit.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/mono-debug.h>
#include <mono/metadata/debug-helpers.h>
#include <mono/metadata/environment.h>
#include <mono/metadata/threads.h>
#include <mono/metadata/mono-gc.h>
#include "include/ILuaModuleManager.h"
#include "extra/Vector2.h"
#include "extra/Vector3.h"
using namespace std; using namespace std;
#ifndef __COMMON_H #ifndef __COMMON_H

View File

@ -200,6 +200,30 @@ bool CLuaFunctionDefinitions::SetPlayerAnnounceValue( lua_State* pLuaVM, void* p
return false; return false;
} }
bool CLuaFunctionDefinitions::AddEventHandler( lua_State* pLuaVM, const char* szName, void* pUserData, lua_CFunction iLuaFunction, bool bPropagated, const char* szEventPriority )
{
CLuaArguments pLuaArguments;
pLuaArguments.PushString( szName );
pLuaArguments.PushUserData( pUserData );
pLuaArguments.PushFunction( iLuaFunction );
pLuaArguments.PushBoolean( bPropagated );
pLuaArguments.PushString( szEventPriority );
if( pLuaArguments.Call( pLuaVM, "addEventHandler", 1 ) )
{
CLuaArgument pLuaArgument( pLuaVM, -1 );
if( pLuaArgument.GetType() == LUA_TBOOLEAN )
{
return pLuaArgument.GetBoolean();
}
}
return false;
}
// Element create/destroy // Element create/destroy
void* CLuaFunctionDefinitions::CreateElement( lua_State* pLuaVM, const char* szTypeName, const char* szID ) void* CLuaFunctionDefinitions::CreateElement( lua_State* pLuaVM, const char* szTypeName, const char* szID )

View File

@ -37,23 +37,24 @@ public:
static string GetGameType ( lua_State* pLuaVM ); static string GetGameType ( lua_State* pLuaVM );
static string GetMapName ( lua_State* pLuaVM ); static string GetMapName ( lua_State* pLuaVM );
// static int CallRemote ( lua_State* luaVM ); // static int CallRemote ( lua_State* luaVM );
// static int FetchRemote ( lua_State* luaVM ); // static int FetchRemote ( lua_State* luaVM );
// // Event functions // Event functions
// static int AddEvent ( lua_State* luaVM ); // static bool AddEvent ( lua_State* pLuaVM, const char* szName, bool bAllowRemoteTrigger );
// static int AddEventHandler ( lua_State* luaVM ); static bool AddEventHandler ( lua_State* pLuaVM, const char* szName, void* pUserData, lua_CFunction iLuaFunction, bool bPropagated, const char* szEventPriority );
// static int RemoveEventHandler ( lua_State* luaVM ); // static bool RemoveEventHandler ( lua_State* pLuaVM, const char* szName, void* pUserData, const CLuaFunctionRef& iLuaFunction );
// static int GetEventHandlers ( lua_State* luaVM ); // static bool GetEventHandlers ( lua_State* pLuaVM, const char* szName );
// static int TriggerEvent ( lua_State* luaVM ); // static bool TriggerEvent ( lua_State* pLuaVM, const char* szName, void* pUserData, const CLuaArguments& Arguments, bool& bWasCancelled );
// static int TriggerClientEvent ( lua_State* luaVM ); // static bool CancelEvent ( lua_State* pLuaVM, bool bCancel );
// static int CancelEvent ( lua_State* luaVM ); // static bool WasEventCancelled ( lua_State* pLuaVM );
// static int GetCancelReason ( lua_State* luaVM );
// static int WasEventCancelled ( lua_State* luaVM ); // static int TriggerClientEvent ( lua_State* luaVM );
// static int TriggerLatentClientEvent ( lua_State* luaVM ); // static int GetCancelReason ( lua_State* luaVM );
// static int GetLatentEventHandles ( lua_State* luaVM ); // static int TriggerLatentClientEvent ( lua_State* luaVM );
// static int GetLatentEventStatus ( lua_State* luaVM ); // static int GetLatentEventHandles ( lua_State* luaVM );
// static int CancelLatentEvent ( lua_State* luaVM ); // static int GetLatentEventStatus ( lua_State* luaVM );
// static int CancelLatentEvent ( lua_State* luaVM );
// Element create/destroy // Element create/destroy
static void* CreateElement ( lua_State* pLuaVM, const char* szTypeName, const char* szID ); static void* CreateElement ( lua_State* pLuaVM, const char* szTypeName, const char* szID );

View File

@ -10,12 +10,24 @@
* *
*********************************************************/ *********************************************************/
#include "mta-mono.h" #define MODULE_NAME "Mono 4.2.1"
#define MODULE_AUTHOR "Dmitry Korolev <kernell@mtaroleplay.ru>"
#define MODULE_VERSION 0.1f
#include "CFunctions.h"
#include "CResource.h"
#include "CResourceManager.h"
#include "CMonoInterface.h"
ILuaModuleManager10* g_pModuleManager = nullptr;
CResourceManager* g_pResourceManager = nullptr;
CMonoInterface* g_pMonoInterface = nullptr;
MTAEXPORT bool InitModule( ILuaModuleManager10 *pManager, char *szModuleName, char *szAuthor, float *fVersion ) MTAEXPORT bool InitModule( ILuaModuleManager10 *pManager, char *szModuleName, char *szAuthor, float *fVersion )
{ {
g_pModuleManager = pManager; g_pModuleManager = pManager;
g_pResourceManager = new CResourceManager(); g_pMonoInterface = new CMonoInterface();
g_pResourceManager = new CResourceManager( g_pMonoInterface );
strncpy( szModuleName, MODULE_NAME, MAX_INFO_LENGTH ); strncpy( szModuleName, MODULE_NAME, MAX_INFO_LENGTH );
strncpy( szAuthor, MODULE_AUTHOR, MAX_INFO_LENGTH ); strncpy( szAuthor, MODULE_AUTHOR, MAX_INFO_LENGTH );
@ -29,10 +41,10 @@ MTAEXPORT void RegisterFunctions( lua_State *pLuaVM )
{ {
if( g_pModuleManager && pLuaVM && g_pResourceManager ) if( g_pModuleManager && pLuaVM && g_pResourceManager )
{ {
if( g_pModuleManager->RegisterFunction( pLuaVM, "monoInit", CFunctions::monoInit ) ) if( g_pModuleManager->RegisterFunction( pLuaVM, "mono_init", CFunctions::monoInit ) )
{ {
//luaL_dostring( pLuaVM, "addEventHandler( 'onResourceStart', resourceRoot, monoInit )" ); //luaL_dostring( pLuaVM, "addEventHandler( 'onResourceStart', resourceRoot, monoInit )" );
luaL_dostring( pLuaVM, "addEventHandler( 'onResourceStart', resourceRoot, function( res ) monoInit( getResourceName( res ) ) end )" ); luaL_dostring( pLuaVM, "addEventHandler( 'onResourceStart', resourceRoot, function( res ) mono_init( getResourceName( res ) ) end )" );
} }
} }
} }
@ -54,6 +66,11 @@ MTAEXPORT bool ShutdownModule( void )
delete g_pResourceManager; delete g_pResourceManager;
} }
if( g_pMonoInterface )
{
delete g_pMonoInterface;
}
return true; return true;
} }

View File

@ -1,25 +0,0 @@
/*********************************************************
*
* 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.
*
*********************************************************/
#define MODULE_NAME "Mono 4.2.1"
#define MODULE_AUTHOR "Dmitry Korolev <kernell@mtaroleplay.ru>"
#define MODULE_VERSION 0.1f
#include "Common.h"
#include "CFunctions.h"
#include "CResource.h"
#include "CResourceManager.h"
ILuaModuleManager10 *g_pModuleManager = NULL;
CResourceManager *g_pResourceManager = NULL;