mirror of
https://github.com/ChronosX88/mta-mono.git
synced 2024-11-22 10:12:20 +00:00
Рефакторинг. Добавлен интерфейс для работы с Mono (раньше вся работа шла через CResource). Библиотеки MTA и mscorlib в отдельных классах (доступ через CMonoDomain). Классы теперь кешируются и хранятся в CMonoDomain.
This commit is contained in:
parent
ed88279271
commit
d8197802d8
@ -10,85 +10,6 @@
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</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">
|
||||
<ProjectGuid>{5E5C7A85-A869-4D86-88FF-05DCEFC07AC3}</ProjectGuid>
|
||||
<RootNamespace>mta-mono</RootNamespace>
|
||||
@ -131,7 +52,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>D:\Server\MTA\server\mods\deathmatch\modules</OutDir>
|
||||
<IntDir>bin\Release\</IntDir>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Midl>
|
||||
@ -146,10 +67,11 @@
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
|
||||
<PrecompiledHeader />
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>false</SDLCheck>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
<PrecompiledHeaderFile>StdInc.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
@ -178,18 +100,21 @@
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
</Midl>
|
||||
<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>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
|
||||
<PrecompiledHeader />
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<SDLCheck>false</SDLCheck>
|
||||
<Optimization>Full</Optimization>
|
||||
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<IntrinsicFunctions>false</IntrinsicFunctions>
|
||||
<FunctionLevelLinking>
|
||||
</FunctionLevelLinking>
|
||||
<PrecompiledHeaderFile>StdInc.h</PrecompiledHeaderFile>
|
||||
<StringPooling>true</StringPooling>
|
||||
<ForcedIncludeFiles>StdInc.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
@ -201,20 +126,117 @@
|
||||
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
|
||||
<ModuleDefinitionFile />
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>
|
||||
</OptimizeReferences>
|
||||
<EnableCOMDATFolding>
|
||||
</EnableCOMDATFolding>
|
||||
<RandomizedBaseAddress>false</RandomizedBaseAddress>
|
||||
<DataExecutionPrevention />
|
||||
<ImportLibrary>
|
||||
</ImportLibrary>
|
||||
<ImportLibrary>$(IntDir)$(TargetFileName).lib</ImportLibrary>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
<IgnoreSpecificDefaultLibraries>
|
||||
</IgnoreSpecificDefaultLibraries>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
<LinkTimeCodeGeneration>
|
||||
</LinkTimeCodeGeneration>
|
||||
<AdditionalLibraryDirectories>lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
|
||||
</Link>
|
||||
</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" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
@ -10,6 +10,7 @@
|
||||
*
|
||||
*********************************************************/
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "CFunctions.h"
|
||||
#include "extra/CLuaArguments.h"
|
||||
|
||||
@ -43,3 +44,31 @@ int CFunctions::monoInit( lua_State *pLuaVM )
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ class CFunctions
|
||||
{
|
||||
public:
|
||||
static int monoInit ( lua_State *pLuaVM );
|
||||
static int monoEventHandler ( lua_State *pLuaVM );
|
||||
|
||||
};
|
||||
#endif
|
||||
|
@ -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"
|
||||
|
||||
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 )
|
||||
{
|
||||
g_pModuleManager->ErrorPrintf( "%s:%d: Failed to create mono object for %s::%s\n",
|
||||
CMonoClass::GetNameSpace( pMonoClass ),
|
||||
CMonoClass::GetName( pMonoClass ),
|
||||
__FILE__,
|
||||
__LINE__
|
||||
);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -21,45 +38,40 @@ MonoObject* CMonoClass::New( MonoClass* pMonoClass, MonoDomain* pMonoDomain )
|
||||
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 };
|
||||
|
||||
return CMonoClass::New( pMonoClass, pMonoDomain, args, 4 );
|
||||
return this->New( args, 4 );
|
||||
}
|
||||
|
||||
|
||||
MonoObject* CMonoClass::New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, Vector2& vecVector )
|
||||
MonoObject* CMonoClass::New( Vector2& vecVector )
|
||||
{
|
||||
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 };
|
||||
|
||||
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 )
|
||||
{
|
||||
g_pModuleManager->ErrorPrintf( "%s:%d: Failed to create mono object for %s::%s\n", GetNameSpace( pMonoClass ), GetName( pMonoClass ), __FILE__, __LINE__ );
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MonoMethod* pMonoMethod = CMonoClass::GetMethod( pMonoClass, ".ctor", argc );
|
||||
MonoMethod* pMonoMethod = this->GetMethod( ".ctor", argc );
|
||||
|
||||
if( !pMonoMethod )
|
||||
{
|
||||
g_pModuleManager->ErrorPrintf( "%s:%d: Could not lookup constructor for class %s::%s\n", GetNameSpace( pMonoClass ), GetName( pMonoClass ), __FILE__, __LINE__ );
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -68,28 +80,29 @@ MonoObject* CMonoClass::New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, voi
|
||||
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 );
|
||||
|
||||
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 );
|
||||
|
||||
|
@ -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;
|
||||
|
||||
#ifndef _C_MONO_CLASS
|
||||
#define _C_MONO_CLASS
|
||||
#ifndef _C_MONOCLASS_H
|
||||
#define _C_MONOCLASS_H
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
extern ILuaModuleManager10 *g_pModuleManager;
|
||||
#include "CMonoDomain.h"
|
||||
|
||||
class CMonoClass
|
||||
{
|
||||
private:
|
||||
MonoClass* m_pClass;
|
||||
|
||||
CMonoDomain* m_pDomain;
|
||||
|
||||
public:
|
||||
static MonoObject* New( MonoClass* pMonoClass, MonoDomain* pMonoDomain );
|
||||
static MonoObject* New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, SColor& pColor );
|
||||
static MonoObject* New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, Vector2& vecVector );
|
||||
static MonoObject* New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, Vector3& vecVector );
|
||||
static MonoObject* New( MonoClass* pMonoClass, MonoDomain* pMonoDomain, void** args, int argc );
|
||||
CMonoClass ( MonoClass* pMonoClass, CMonoDomain* pDomain );
|
||||
~CMonoClass ( void );
|
||||
|
||||
static const char* GetName( MonoClass* pMonoClass );
|
||||
static const char* GetNameSpace( MonoClass* pMonoClass );
|
||||
MonoObject* New ( void );
|
||||
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 );
|
||||
static MonoMethod* GetMethod( MonoClass* pMonoClass, const char* szMethodName );
|
||||
const char* GetName ( void );
|
||||
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
|
58
mta-mono/src/CMonoCorlib.cpp
Normal file
58
mta-mono/src/CMonoCorlib.cpp
Normal 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 ) );
|
||||
}
|
40
mta-mono/src/CMonoCorlib.h
Normal file
40
mta-mono/src/CMonoCorlib.h
Normal 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
|
100
mta-mono/src/CMonoDomain.cpp
Normal file
100
mta-mono/src/CMonoDomain.cpp
Normal 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() );
|
||||
}
|
97
mta-mono/src/CMonoDomain.h
Normal file
97
mta-mono/src/CMonoDomain.h
Normal 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
|
@ -37,12 +37,16 @@ void CMonoFunctions::AddInternals( void )
|
||||
MONO_DECLARE( Server, SetRuleValue );
|
||||
MONO_DECLARE( Server, RemoveRuleValue );
|
||||
|
||||
MONO_DECLARE( Event, AddHandler );
|
||||
|
||||
// Element create/destroy
|
||||
MONO_DECLARE( Element, Create );
|
||||
MONO_DECLARE( Element, Destroy );
|
||||
MONO_DECLARE( Element, Clone );
|
||||
|
||||
// Element get funcs
|
||||
MONO_DECLARE( Element, GetRootElement );
|
||||
|
||||
MONO_DECLARE( Element, GetByType );
|
||||
MONO_DECLARE( Element, IsElement );
|
||||
MONO_DECLARE( Element, GetType );
|
||||
@ -746,7 +750,7 @@ MonoObject* CMonoFunctions::Server::GetVersion( void )
|
||||
&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 )
|
||||
{
|
||||
return RESOURCE->NewString( CLuaFunctionDefinitions::GetGameType( RESOURCE->GetLua() ) );
|
||||
return RESOURCE->GetDomain()->NewString( CLuaFunctionDefinitions::GetGameType( RESOURCE->GetLua() ) );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -767,7 +771,7 @@ MonoString* CMonoFunctions::Server::GetMapName( void )
|
||||
{
|
||||
if( RESOURCE )
|
||||
{
|
||||
return RESOURCE->NewString( CLuaFunctionDefinitions::GetMapName( RESOURCE->GetLua() ) );
|
||||
return RESOURCE->GetDomain()->NewString( CLuaFunctionDefinitions::GetMapName( RESOURCE->GetLua() ) );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -803,7 +807,7 @@ MonoString* CMonoFunctions::Server::GetRuleValue( MonoString* 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;
|
||||
|
@ -18,10 +18,13 @@ class CMonoFunctions;
|
||||
#ifndef __CMONOFUNCTIONS_H
|
||||
#define __CMONOFUNCTIONS_H
|
||||
|
||||
#include "Common.h"
|
||||
#include "lua/CLuaFunctionDefinitions.h"
|
||||
|
||||
#include "CMonoDomain.h"
|
||||
#include "CMonoClass.h"
|
||||
#include "CMonoObject.h"
|
||||
#include "CMonoCorlib.h"
|
||||
#include "CMonoMTALib.h"
|
||||
|
||||
extern ILuaModuleManager10 *g_pModuleManager;
|
||||
extern CResourceManager *g_pResourceManager;
|
||||
@ -70,6 +73,12 @@ public:
|
||||
static bool RemoveRuleValue ( MonoString* msKey );
|
||||
};
|
||||
|
||||
class Event
|
||||
{
|
||||
public:
|
||||
static bool AddHandler ( MonoString* msName, DWORD pUserData, lua_CFunction iLuaFunction, bool bPropagated, MonoString* msEventPriority );
|
||||
};
|
||||
|
||||
class Element
|
||||
{
|
||||
public:
|
||||
@ -79,6 +88,7 @@ public:
|
||||
static DWORD Clone ( DWORD pUserData, MonoObject* vecPosition, bool bCloneElement );
|
||||
|
||||
// Element get funcs
|
||||
static DWORD GetRootElement ( void );
|
||||
static MonoArray* GetByType ( MonoString* msType, DWORD pStartElement );
|
||||
|
||||
static bool IsElement ( DWORD pUserData );
|
||||
|
@ -32,7 +32,7 @@ MonoArray* CMonoFunctions::Account::GetAll( void )
|
||||
{
|
||||
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;
|
||||
@ -71,7 +71,7 @@ MonoString* CMonoFunctions::Account::GetSerial( DWORD pAccount )
|
||||
|
||||
if( CLuaFunctionDefinitions::GetAccountSerial( RESOURCE->GetLua(), (void*)pAccount, strSerial ) )
|
||||
{
|
||||
return RESOURCE->NewString( strSerial );
|
||||
return RESOURCE->GetDomain()->NewString( strSerial );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ MonoString* CMonoFunctions::Ban::GetIP( DWORD pBan )
|
||||
|
||||
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 ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
return RESOURCE->NewString( strAdmin );
|
||||
return RESOURCE->GetDomain()->NewString( strAdmin );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ MonoObject* CMonoFunctions::Blip::GetColor( DWORD pUserData )
|
||||
|
||||
if( CLuaFunctionDefinitions::GetBlipColor( RESOURCE->GetLua(), (void*)pUserData, outColor ) )
|
||||
{
|
||||
return RESOURCE->NewObject( outColor );
|
||||
return RESOURCE->GetDomain()->GetMTALib()->Color->New( outColor );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,16 @@ DWORD CMonoFunctions::Element::Clone( DWORD pUserData, MonoObject* vecPosition,
|
||||
|
||||
// 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 )
|
||||
{
|
||||
if( RESOURCE )
|
||||
@ -57,7 +67,7 @@ MonoArray* CMonoFunctions::Element::GetByType( MonoString* msType, DWORD pStartE
|
||||
|
||||
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;
|
||||
@ -157,7 +167,7 @@ MonoObject* CMonoFunctions::Element::GetPosition( DWORD pUserData )
|
||||
|
||||
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 ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
return RESOURCE->NewObject( vecRotation );
|
||||
return RESOURCE->GetDomain()->GetMTALib()->Vector3->New( vecRotation );
|
||||
}
|
||||
}
|
||||
|
||||
|
20
mta-mono/src/CMonoFunctions_Event.cpp
Normal file
20
mta-mono/src/CMonoFunctions_Event.cpp
Normal 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;
|
||||
}
|
@ -50,7 +50,7 @@ MonoString* CMonoFunctions::Marker::GetType( DWORD pUserData )
|
||||
|
||||
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 ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
return RESOURCE->NewString( szIcon );
|
||||
return RESOURCE->GetDomain()->NewString( szIcon );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ MonoObject* CMonoFunctions::Object::GetScale( DWORD pUserData )
|
||||
|
||||
if( CLuaFunctionDefinitions::GetObjectScale( RESOURCE->GetLua(), (void*)pUserData, vecScale ) )
|
||||
{
|
||||
return RESOURCE->NewObject( vecScale );
|
||||
return RESOURCE->GetDomain()->GetMTALib()->Vector3->New( vecScale );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ MonoString* CMonoFunctions::Ped::GetClothesTexture( DWORD pUserData, unsigned ch
|
||||
|
||||
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 ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
mono_array_set( pArray, MonoString*, 0, RESOURCE->NewString( szTexture ) );
|
||||
mono_array_set( pArray, MonoString*, 1, RESOURCE->NewString( szModel ) );
|
||||
mono_array_set( pArray, MonoString*, 0, RESOURCE->GetDomain()->NewString( szTexture ) );
|
||||
mono_array_set( pArray, MonoString*, 1, RESOURCE->GetDomain()->NewString( szModel ) );
|
||||
|
||||
return pArray;
|
||||
}
|
||||
@ -677,7 +677,7 @@ MonoArray* CMonoFunctions::Ped::GetTypeIndexFromClothes( MonoString* msTexture,
|
||||
|
||||
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 )
|
||||
{
|
||||
@ -700,7 +700,7 @@ MonoString* CMonoFunctions::Ped::GetClothesTypeName( unsigned char ucType )
|
||||
|
||||
if( CLuaFunctionDefinitions::GetClothesTypeName( RESOURCE->GetLua(), ucType, szName ) )
|
||||
{
|
||||
return RESOURCE->NewString( szName );
|
||||
return RESOURCE->GetDomain()->NewString( szName );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ MonoArray* CMonoFunctions::Player::GetAlivePlayers( void )
|
||||
|
||||
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();
|
||||
|
||||
@ -150,7 +150,7 @@ MonoArray* CMonoFunctions::Player::GetDeadPlayers( void )
|
||||
|
||||
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();
|
||||
|
||||
@ -204,7 +204,7 @@ MonoString* CMonoFunctions::Player::GetNametagText( DWORD pUserData )
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
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 )
|
||||
{
|
||||
return RESOURCE->NewString( CLuaFunctionDefinitions::GetPlayerSerial( RESOURCE->GetLua(), (void*)pUserData ) );
|
||||
return RESOURCE->GetDomain()->NewString( CLuaFunctionDefinitions::GetPlayerSerial( RESOURCE->GetLua(), (void*)pUserData ) );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -260,7 +260,7 @@ MonoString* CMonoFunctions::Player::GetUserName( DWORD pUserData )
|
||||
{
|
||||
if( RESOURCE )
|
||||
{
|
||||
return RESOURCE->NewString( CLuaFunctionDefinitions::GetPlayerUserName( RESOURCE->GetLua(), (void*)pUserData ) );
|
||||
return RESOURCE->GetDomain()->NewString( CLuaFunctionDefinitions::GetPlayerUserName( RESOURCE->GetLua(), (void*)pUserData ) );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -289,7 +289,7 @@ MonoString* CMonoFunctions::Player::GetName( DWORD pUserData )
|
||||
|
||||
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 ) )
|
||||
{
|
||||
return RESOURCE->NewString( strIP );
|
||||
return RESOURCE->GetDomain()->NewString( strIP );
|
||||
}
|
||||
}
|
||||
|
||||
@ -325,7 +325,7 @@ MonoString* CMonoFunctions::Player::GetVersion( DWORD pUserData )
|
||||
{
|
||||
if( RESOURCE )
|
||||
{
|
||||
return RESOURCE->NewString( CLuaFunctionDefinitions::GetPlayerVersion( RESOURCE->GetLua(), (void*)pUserData ) );
|
||||
return RESOURCE->GetDomain()->NewString( CLuaFunctionDefinitions::GetPlayerVersion( RESOURCE->GetLua(), (void*)pUserData ) );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -339,9 +339,9 @@ MonoObject* CMonoFunctions::Player::GetACInfo( DWORD pUserData )
|
||||
|
||||
if( !pLuaTable.empty() )
|
||||
{
|
||||
MonoString* msDetectedAC = RESOURCE->NewString( pLuaTable[ "DetectedAC" ]->GetString() );
|
||||
MonoString* msD3D9MD5 = RESOURCE->NewString( pLuaTable[ "d3d9MD5" ]->GetString() );
|
||||
MonoString* msD3D9SHA256 = RESOURCE->NewString( pLuaTable[ "d3d9SHA256" ]->GetString() );
|
||||
MonoString* msDetectedAC = RESOURCE->GetDomain()->NewString( pLuaTable[ "DetectedAC" ]->GetString() );
|
||||
MonoString* msD3D9MD5 = RESOURCE->GetDomain()->NewString( pLuaTable[ "d3d9MD5" ]->GetString() );
|
||||
MonoString* msD3D9SHA256 = RESOURCE->GetDomain()->NewString( pLuaTable[ "d3d9SHA256" ]->GetString() );
|
||||
|
||||
unsigned int iD3D9Size = pLuaTable[ "d3d9Size" ]->GetNumber< unsigned int >();
|
||||
|
||||
@ -353,7 +353,7 @@ MonoObject* CMonoFunctions::Player::GetACInfo( DWORD pUserData )
|
||||
&msD3D9SHA256
|
||||
};
|
||||
|
||||
return RESOURCE->NewObject( "MultiTheftAuto", "PlayerACInfo", args, 4 );
|
||||
return RESOURCE->GetDomain()->GetMTALib()->GetClass( "PlayerACInfo" )->New( args, 4 );
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
@ -365,7 +365,7 @@ MonoString* CMonoFunctions::Player::GetPlayerAnnounceValue( DWORD pElement, Mono
|
||||
{
|
||||
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;
|
||||
@ -785,7 +785,7 @@ MonoObject* CMonoFunctions::Player::GetCameraMatrix( DWORD pPlayer )
|
||||
&fFOV
|
||||
};
|
||||
|
||||
return RESOURCE->NewObject( "MultiTheftAuto", "CameraMatrix", args, 8 );
|
||||
return RESOURCE->GetDomain()->GetMTALib()->GetClass( "CameraMatrix" )->New( args, 8 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ MonoObject* CMonoFunctions::RadarArea::GetSize( DWORD pUserData )
|
||||
|
||||
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 ) )
|
||||
{
|
||||
return RESOURCE->NewObject( outColor );
|
||||
return RESOURCE->GetDomain()->GetMTALib()->Color->New( outColor );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ MonoString* CMonoFunctions::Resource::GetInfo( DWORD pResource, MonoString* msAt
|
||||
|
||||
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 ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
return RESOURCE->NewString( strOut );
|
||||
return RESOURCE->GetDomain()->NewString( strOut );
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ MonoArray* CMonoFunctions::Resource::GetResources( void )
|
||||
{
|
||||
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;
|
||||
@ -192,7 +192,7 @@ MonoString* CMonoFunctions::Resource::GetState( DWORD pResource )
|
||||
|
||||
if( CLuaFunctionDefinitions::GetResourceState( RESOURCE->GetLua(), (void*)pResource, strOut ) )
|
||||
{
|
||||
return RESOURCE->NewString( strOut );
|
||||
return RESOURCE->GetDomain()->NewString( strOut );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ MonoString* CMonoFunctions::Team::GetName( DWORD pUserData )
|
||||
|
||||
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 ) )
|
||||
{
|
||||
return RESOURCE->NewObject( pColor );
|
||||
return RESOURCE->GetDomain()->GetMTALib()->Color->New( pColor );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ MonoString* CMonoFunctions::Vehicle::GetType( DWORD pUserData )
|
||||
|
||||
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 ) )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
@ -99,7 +99,7 @@ MonoObject* CMonoFunctions::Vehicle::GetColor( DWORD pUserData )
|
||||
&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 ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
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 );
|
||||
|
||||
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;
|
||||
@ -238,7 +238,7 @@ MonoObject* CMonoFunctions::Vehicle::GetTurnVelocity( DWORD pUserData )
|
||||
|
||||
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 ) )
|
||||
{
|
||||
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 );
|
||||
|
||||
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;
|
||||
@ -308,7 +308,7 @@ MonoArray* CMonoFunctions::Vehicle::GetUpgrades( DWORD 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;
|
||||
@ -322,7 +322,7 @@ MonoString* CMonoFunctions::Vehicle::GetUpgradeSlotName( unsigned short usUpgrad
|
||||
|
||||
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 );
|
||||
|
||||
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;
|
||||
@ -369,7 +369,7 @@ MonoObject* CMonoFunctions::Vehicle::GetWheelStates( DWORD pUserData )
|
||||
&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 ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
return RESOURCE->NewObject( outColor );
|
||||
return RESOURCE->GetDomain()->GetMTALib()->Color->New( outColor );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ MonoObject* CMonoFunctions::Water::GetVertexPosition( DWORD pUserData, int iVert
|
||||
|
||||
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 ) )
|
||||
{
|
||||
return RESOURCE->NewObject( pColor );
|
||||
return RESOURCE->GetDomain()->GetMTALib()->Color->New( pColor );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ MonoArray* CMonoFunctions::World::GetTime( void )
|
||||
|
||||
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, 1, ucMinute );
|
||||
@ -41,7 +41,7 @@ MonoArray* CMonoFunctions::World::GetWeather( void )
|
||||
|
||||
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, 1, ucWeatherBlending );
|
||||
@ -63,7 +63,7 @@ MonoString* CMonoFunctions::World::GetZoneName( MonoObject* mPosition, bool bCit
|
||||
|
||||
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;
|
||||
|
||||
MonoObject* pCoreObject = RESOURCE->NewObject( pCore );
|
||||
MonoObject* pCoronaObject = RESOURCE->NewObject( pCorona );
|
||||
MonoObject* pCoreObject = RESOURCE->GetDomain()->GetMTALib()->Color->New( pCore );
|
||||
MonoObject* pCoronaObject = RESOURCE->GetDomain()->GetMTALib()->Color->New( pCorona );
|
||||
|
||||
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*, 1, pCoronaObject );
|
||||
@ -301,7 +301,7 @@ MonoObject* CMonoFunctions::World::GetWindVelocity( void )
|
||||
|
||||
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;
|
||||
|
||||
MonoObject* pCoreObject = RESOURCE->NewObject( pCore );
|
||||
MonoObject* pCoronaObject = RESOURCE->NewObject( pCorona );
|
||||
MonoObject* pCoreObject = RESOURCE->GetDomain()->GetMTALib()->Color->New( pCore );
|
||||
MonoObject* pCoronaObject = RESOURCE->GetDomain()->GetMTALib()->Color->New( pCorona );
|
||||
|
||||
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*, 1, pCoronaObject );
|
||||
@ -424,7 +424,7 @@ MonoObject* CMonoFunctions::World::GetHeatHaze( void )
|
||||
&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
92
mta-mono/src/CMonoGC.cpp
Normal 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
36
mta-mono/src/CMonoGC.h
Normal 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
|
50
mta-mono/src/CMonoInterface.cpp
Normal file
50
mta-mono/src/CMonoInterface.cpp
Normal 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;
|
||||
}
|
47
mta-mono/src/CMonoInterface.h
Normal file
47
mta-mono/src/CMonoInterface.h
Normal 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
|
68
mta-mono/src/CMonoMTALib.cpp
Normal file
68
mta-mono/src/CMonoMTALib.cpp
Normal 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 ) );
|
||||
}
|
43
mta-mono/src/CMonoMTALib.h
Normal file
43
mta-mono/src/CMonoMTALib.h
Normal 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
|
@ -10,6 +10,7 @@
|
||||
*
|
||||
*********************************************************/
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "CMonoObject.h"
|
||||
|
||||
MonoClass* CMonoObject::GetClass( MonoObject* pObject )
|
||||
|
@ -10,62 +10,121 @@
|
||||
*
|
||||
*********************************************************/
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "CResource.h"
|
||||
#include "CResourceManager.h"
|
||||
#include "CFunctions.h"
|
||||
#include "include/ILuaModuleManager.h"
|
||||
#include "lua/CLuaFunctionDefinitions.h"
|
||||
|
||||
extern ILuaModuleManager10 *g_pModuleManager;
|
||||
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_sName = sName;
|
||||
|
||||
this->m_pMonoAssembly = NULL;
|
||||
this->m_pMonoAssemblyLib = NULL;
|
||||
this->m_pMonoGCHandle = NULL;
|
||||
this->m_pMonoDomain = NULL;
|
||||
this->m_pMonoImage = NULL;
|
||||
this->m_pMonoImageLib = NULL;
|
||||
this->m_pMonoClass = NULL;
|
||||
this->m_pMonoAssembly = nullptr;
|
||||
this->m_pMonoGCHandle = 0;
|
||||
this->m_pMonoDomain = nullptr;
|
||||
this->m_pMonoImage = nullptr;
|
||||
this->m_pMonoClass = nullptr;
|
||||
}
|
||||
|
||||
CResource::~CResource( void )
|
||||
{
|
||||
this->GetMono()->GetGC()->Collect( this->GetMono()->GetGC()->GetMaxGeneration() );
|
||||
|
||||
mono_domain_set( mono_get_root_domain(), false );
|
||||
|
||||
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 );
|
||||
|
||||
this->m_pMonoAssembly = NULL;
|
||||
this->m_pMonoAssemblyLib = NULL;
|
||||
this->m_pMonoGCHandle = NULL;
|
||||
this->m_pMonoDomain = NULL;
|
||||
this->m_pMonoImage = NULL;
|
||||
this->m_pMonoImageLib = NULL;
|
||||
this->m_pMonoClass = NULL;
|
||||
this->m_pMonoAssembly = nullptr;
|
||||
this->m_pMonoGCHandle = 0;
|
||||
this->m_pMonoDomain = nullptr;
|
||||
this->m_pMonoImage = nullptr;
|
||||
this->m_pMonoClass = nullptr;
|
||||
|
||||
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 )
|
||||
{
|
||||
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 sNamespace ( this->m_sName );
|
||||
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 )
|
||||
{
|
||||
@ -74,16 +133,11 @@ bool CResource::Init( void )
|
||||
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_pMonoImageLib = mono_assembly_get_image( this->m_pMonoAssemblyLib );
|
||||
}
|
||||
|
||||
this->m_pMonoAssembly = mono_domain_assembly_open( this->m_pMonoDomain, sPath.c_str() );
|
||||
this->m_pMonoAssembly = this->m_pMonoDomain->OpenAssembly( sPath.c_str() );
|
||||
|
||||
if( !this->m_pMonoAssembly )
|
||||
{
|
||||
@ -92,10 +146,12 @@ bool CResource::Init( void )
|
||||
return false;
|
||||
}
|
||||
|
||||
this->RegisterEvents();
|
||||
|
||||
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() );
|
||||
|
||||
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 );
|
||||
|
||||
@ -127,139 +183,47 @@ bool CResource::RegisterFunction( const char *szFunctionName, lua_CFunction Func
|
||||
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 )
|
||||
{
|
||||
pMonoClass = mono_class_from_name( this->m_pMonoImageLib, szNamespace, szName );
|
||||
}
|
||||
va_start( args, szFormat );
|
||||
|
||||
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 )
|
||||
{
|
||||
MonoObject* pObject = CMonoClass::New( pClass, mono_domain_get() );
|
||||
va_start( args, szFormat );
|
||||
|
||||
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 );
|
||||
}
|
||||
char szBuffer[ 255 ];
|
||||
|
||||
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 )
|
||||
{
|
||||
MonoObject* pObject = CMonoClass::New( pClass, mono_domain_get(), pColor );
|
||||
va_start( args, szFormat );
|
||||
|
||||
if( pObject )
|
||||
{
|
||||
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__ );
|
||||
}
|
||||
char szBuffer[ 255 ];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MonoObject* CResource::NewObject( Vector2& vecVector )
|
||||
{
|
||||
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;
|
||||
vsprintf( szBuffer, szFormat, args );
|
||||
|
||||
va_end( args );
|
||||
|
||||
g_pModuleManager->ErrorPrintf( szBuffer );
|
||||
}
|
||||
|
@ -17,88 +17,44 @@ class CResource;
|
||||
|
||||
#include "Common.h"
|
||||
#include "CMonoClass.h"
|
||||
#include "CMonoInterface.h"
|
||||
#include "extra/CLuaArguments.h"
|
||||
|
||||
class CResource
|
||||
{
|
||||
private:
|
||||
string m_sName;
|
||||
string m_sName;
|
||||
|
||||
MonoAssembly *m_pMonoAssembly;
|
||||
MonoAssembly *m_pMonoAssemblyLib;
|
||||
MonoImage *m_pMonoImage;
|
||||
MonoImage *m_pMonoImageLib;
|
||||
MonoClass *m_pMonoClass;
|
||||
uint32_t m_pMonoGCHandle;
|
||||
MonoAssembly* m_pMonoAssembly;
|
||||
MonoImage* m_pMonoImage;
|
||||
MonoClass* m_pMonoClass;
|
||||
uint32_t m_pMonoGCHandle;
|
||||
|
||||
lua_State* m_pLuaVM;
|
||||
|
||||
CMonoInterface* m_pMono;
|
||||
CMonoDomain* m_pMonoDomain;
|
||||
|
||||
public:
|
||||
lua_State *m_pLuaVM;
|
||||
MonoDomain *m_pMonoDomain;
|
||||
CResource ( CMonoInterface* m_pMono, lua_State *pLuaVM, string sName );
|
||||
~CResource ( void );
|
||||
|
||||
CResource ( lua_State *pLuaVM, string sName );
|
||||
~CResource ( void );
|
||||
bool CallEvent ( string strEventName, void* pThis, void* pSource, void* pClient, void **args );
|
||||
|
||||
bool Init ( void );
|
||||
void OnStopping ( void );
|
||||
void DoPulse ( void );
|
||||
bool RegisterFunction ( const char *szFunctionName, lua_CFunction Func );
|
||||
void RegisterEvents ( void );
|
||||
bool Init ( void );
|
||||
void OnStopping ( void );
|
||||
void DoPulse ( void );
|
||||
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, ... );
|
||||
void ErrorPrintf ( const char* szFormat, ... );
|
||||
|
||||
MonoObject* NewObject( const char* szNamespace, const char* szName );
|
||||
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; }
|
||||
lua_State *GetLua ( void ) { return this->m_pLuaVM; }
|
||||
string GetName ( void ) { return this->m_sName; }
|
||||
lua_State* GetLua ( void ) { return this->m_pLuaVM; }
|
||||
CMonoInterface* GetMono ( void ) { return this->m_pMono; }
|
||||
CMonoDomain* GetDomain ( void ) { return this->m_pMonoDomain; }
|
||||
};
|
||||
|
||||
#endif
|
@ -10,15 +10,12 @@
|
||||
*
|
||||
*********************************************************/
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "CResourceManager.h"
|
||||
|
||||
CResourceManager::CResourceManager( void )
|
||||
CResourceManager::CResourceManager( CMonoInterface* pMono )
|
||||
{
|
||||
mono_set_dirs( "mods/deathmatch/mono/lib", "mods/deathmatch/mono/etc" );
|
||||
|
||||
this->m_pMonoDomain = mono_jit_init_version( "Mono Root", "v4.0.30319" );
|
||||
|
||||
CMonoFunctions::AddInternals();
|
||||
this->m_pMono = pMono;
|
||||
}
|
||||
|
||||
CResourceManager::~CResourceManager( void )
|
||||
@ -27,8 +24,6 @@ CResourceManager::~CResourceManager( void )
|
||||
{
|
||||
delete iter;
|
||||
}
|
||||
|
||||
mono_jit_cleanup( this->m_pMonoDomain );
|
||||
}
|
||||
|
||||
CResource* CResourceManager::Create( lua_State* luaVM, string strName )
|
||||
@ -44,7 +39,7 @@ CResource* CResourceManager::Create( lua_State* luaVM, string strName )
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CResource *pResource = new CResource( luaVM, strName );
|
||||
CResource *pResource = new CResource( this->m_pMono, luaVM, strName );
|
||||
|
||||
this->AddToList( pResource );
|
||||
|
||||
@ -63,7 +58,7 @@ CResource* CResourceManager::GetFromList( lua_State* pLuaVM )
|
||||
{
|
||||
for( auto iter : this->m_List )
|
||||
{
|
||||
if( iter->m_pLuaVM == pLuaVM )
|
||||
if( iter->GetLua() == pLuaVM )
|
||||
{
|
||||
return iter;
|
||||
}
|
||||
@ -76,7 +71,7 @@ CResource* CResourceManager::GetFromList( MonoDomain* pDomain )
|
||||
{
|
||||
for( auto iter : this->m_List )
|
||||
{
|
||||
if( iter->m_pMonoDomain == pDomain )
|
||||
if( iter->GetDomain()->GetMonoPtr() == pDomain )
|
||||
{
|
||||
return iter;
|
||||
}
|
||||
|
@ -15,19 +15,20 @@ class CResourceManager;
|
||||
#ifndef __CRESOURCEMANAGER_H
|
||||
#define __CRESOURCEMANAGER_H
|
||||
|
||||
#include "CMonoFunctions.h"
|
||||
#include "CResource.h"
|
||||
#include "CMonoInterface.h"
|
||||
|
||||
extern ILuaModuleManager10 *g_pModuleManager;
|
||||
|
||||
class CResourceManager
|
||||
{
|
||||
private:
|
||||
list< CResource* > m_List;
|
||||
CMonoInterface* m_pMono;
|
||||
|
||||
MonoDomain *m_pMonoDomain;
|
||||
list< CResource* > m_List;
|
||||
|
||||
public:
|
||||
CResourceManager ( void );
|
||||
CResourceManager ( CMonoInterface* pMono );
|
||||
~CResourceManager ( void );
|
||||
|
||||
CResource* Create ( lua_State* luaVM, string strName );
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "StdInc.h"
|
||||
#include "Common.h"
|
||||
|
||||
CVehicleColor::CVehicleColor( void )
|
||||
|
@ -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;
|
||||
|
||||
#ifndef __COMMON_H
|
||||
|
@ -200,6 +200,30 @@ bool CLuaFunctionDefinitions::SetPlayerAnnounceValue( lua_State* pLuaVM, void* p
|
||||
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
|
||||
|
||||
void* CLuaFunctionDefinitions::CreateElement( lua_State* pLuaVM, const char* szTypeName, const char* szID )
|
||||
|
@ -24,36 +24,37 @@ class CLuaFunctionDefinitions
|
||||
{
|
||||
public:
|
||||
// All-Seeing Eye related Functions
|
||||
static bool SetGameType ( lua_State* pLuaVM, const char* szGameType );
|
||||
static bool SetMapName ( lua_State* pLuaVM, const char* szMapName );
|
||||
static string GetRuleValue ( lua_State* pLuaVM, const char* szKey );
|
||||
static bool SetRuleValue ( lua_State* pLuaVM, const char* szKey, const char* szValue );
|
||||
static bool RemoveRuleValue ( lua_State* pLuaVM, const char* szKey );
|
||||
static string GetPlayerAnnounceValue ( lua_State* pLuaVM, void* pElement, const char* szKey );
|
||||
static bool SetPlayerAnnounceValue ( lua_State* pLuaVM, void* pElement, const char* szKey, const char* szValue );
|
||||
static bool SetGameType ( lua_State* pLuaVM, const char* szGameType );
|
||||
static bool SetMapName ( lua_State* pLuaVM, const char* szMapName );
|
||||
static string GetRuleValue ( lua_State* pLuaVM, const char* szKey );
|
||||
static bool SetRuleValue ( lua_State* pLuaVM, const char* szKey, const char* szValue );
|
||||
static bool RemoveRuleValue ( lua_State* pLuaVM, const char* szKey );
|
||||
static string GetPlayerAnnounceValue ( lua_State* pLuaVM, void* pElement, const char* szKey );
|
||||
static bool SetPlayerAnnounceValue ( lua_State* pLuaVM, void* pElement, const char* szKey, const char* szValue );
|
||||
|
||||
static string Get ( lua_State* pLuaVM, const char* szKey );
|
||||
static bool Set ( lua_State* pLuaVM, const char* szKey, const char* szValue );
|
||||
static string GetGameType ( lua_State* pLuaVM );
|
||||
static string GetMapName ( lua_State* pLuaVM );
|
||||
static string Get ( lua_State* pLuaVM, const char* szKey );
|
||||
static bool Set ( lua_State* pLuaVM, const char* szKey, const char* szValue );
|
||||
static string GetGameType ( lua_State* pLuaVM );
|
||||
static string GetMapName ( lua_State* pLuaVM );
|
||||
|
||||
// static int CallRemote ( lua_State* luaVM );
|
||||
// static int FetchRemote ( lua_State* luaVM );
|
||||
// static int CallRemote ( lua_State* luaVM );
|
||||
// static int FetchRemote ( lua_State* luaVM );
|
||||
|
||||
// // Event functions
|
||||
// static int AddEvent ( lua_State* luaVM );
|
||||
// static int AddEventHandler ( lua_State* luaVM );
|
||||
// static int RemoveEventHandler ( lua_State* luaVM );
|
||||
// static int GetEventHandlers ( lua_State* luaVM );
|
||||
// static int TriggerEvent ( lua_State* luaVM );
|
||||
// static int TriggerClientEvent ( lua_State* luaVM );
|
||||
// static int CancelEvent ( lua_State* luaVM );
|
||||
// static int GetCancelReason ( lua_State* luaVM );
|
||||
// static int WasEventCancelled ( lua_State* luaVM );
|
||||
// static int TriggerLatentClientEvent ( lua_State* luaVM );
|
||||
// static int GetLatentEventHandles ( lua_State* luaVM );
|
||||
// static int GetLatentEventStatus ( lua_State* luaVM );
|
||||
// static int CancelLatentEvent ( lua_State* luaVM );
|
||||
// Event functions
|
||||
// static bool AddEvent ( lua_State* pLuaVM, const char* szName, bool bAllowRemoteTrigger );
|
||||
static bool AddEventHandler ( lua_State* pLuaVM, const char* szName, void* pUserData, lua_CFunction iLuaFunction, bool bPropagated, const char* szEventPriority );
|
||||
// static bool RemoveEventHandler ( lua_State* pLuaVM, const char* szName, void* pUserData, const CLuaFunctionRef& iLuaFunction );
|
||||
// static bool GetEventHandlers ( lua_State* pLuaVM, const char* szName );
|
||||
// static bool TriggerEvent ( lua_State* pLuaVM, const char* szName, void* pUserData, const CLuaArguments& Arguments, bool& bWasCancelled );
|
||||
// static bool CancelEvent ( lua_State* pLuaVM, bool bCancel );
|
||||
// static bool WasEventCancelled ( lua_State* pLuaVM );
|
||||
|
||||
// static int TriggerClientEvent ( lua_State* luaVM );
|
||||
// static int GetCancelReason ( lua_State* luaVM );
|
||||
// static int TriggerLatentClientEvent ( lua_State* luaVM );
|
||||
// static int GetLatentEventHandles ( lua_State* luaVM );
|
||||
// static int GetLatentEventStatus ( lua_State* luaVM );
|
||||
// static int CancelLatentEvent ( lua_State* luaVM );
|
||||
|
||||
// Element create/destroy
|
||||
static void* CreateElement ( lua_State* pLuaVM, const char* szTypeName, const char* szID );
|
||||
|
@ -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 )
|
||||
{
|
||||
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( 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->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, 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;
|
||||
}
|
||||
|
||||
if( g_pMonoInterface )
|
||||
{
|
||||
delete g_pMonoInterface;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -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;
|
Loading…
Reference in New Issue
Block a user