From 3e5313e3d89a0dac206500df99f955285d599b19 Mon Sep 17 00:00:00 2001 From: Dmitry Korolev Date: Sat, 18 Oct 2014 18:23:20 +0400 Subject: [PATCH] Element mono functions --- mta-mono/src/CMonoFunctions.cpp | 743 ++++++++++++++++++++++++++++---- mta-mono/src/CMonoFunctions.h | 78 +++- mta-mono/src/CResource.cpp | 77 +++- mta-mono/src/CResource.h | 14 + 4 files changed, 805 insertions(+), 107 deletions(-) diff --git a/mta-mono/src/CMonoFunctions.cpp b/mta-mono/src/CMonoFunctions.cpp index c4c7e3a..64fcd8b 100644 --- a/mta-mono/src/CMonoFunctions.cpp +++ b/mta-mono/src/CMonoFunctions.cpp @@ -21,6 +21,8 @@ extern CResourceManager *g_pResourceManager; #define RESOURCE g_pResourceManager->GetFromList( mono_domain_get() ) +#define MONO_DECLARE(a,b) mono_add_internal_call("MultiTheftAuto.Native."#a"::"#b,CMonoFunctions::a::b ); + void CMonoFunctions::AddInternals( void ) { mono_add_internal_call( "MultiTheftAuto.Debug::Log", CMonoFunctions::Debug::Log ); @@ -31,22 +33,69 @@ void CMonoFunctions::AddInternals( void ) mono_add_internal_call( "MultiTheftAuto.Native.Config::Set", CMonoFunctions::Config::Set ); // Element create/destroy - mono_add_internal_call( "MultiTheftAuto.Native.Element::Create", CMonoFunctions::Element::Create ); - mono_add_internal_call( "MultiTheftAuto.Native.Element::Destroy", CMonoFunctions::Element::Destroy ); - mono_add_internal_call( "MultiTheftAuto.Native.Element::Clone", CMonoFunctions::Element::Clone ); + MONO_DECLARE( Element, Create ); + MONO_DECLARE( Element, Destroy ); + MONO_DECLARE( Element, Clone ); // Element get funcs - mono_add_internal_call( "MultiTheftAuto.Native.Element::IsElement", CMonoFunctions::Element::IsElement ); - mono_add_internal_call( "MultiTheftAuto.Native.Element::GetType", CMonoFunctions::Element::GetType ); - mono_add_internal_call( "MultiTheftAuto.Native.Element::GetByID", CMonoFunctions::Element::GetByID ); - mono_add_internal_call( "MultiTheftAuto.Native.Element::GetByIndex", CMonoFunctions::Element::GetByIndex ); - mono_add_internal_call( "MultiTheftAuto.Native.Element::GetChild", CMonoFunctions::Element::GetChild ); - mono_add_internal_call( "MultiTheftAuto.Native.Element::GetChildrenCount", CMonoFunctions::Element::GetChildrenCount ); - mono_add_internal_call( "MultiTheftAuto.Native.Element::GetID", CMonoFunctions::Element::GetID ); - mono_add_internal_call( "MultiTheftAuto.Native.Element::GetParent", CMonoFunctions::Element::GetParent ); - mono_add_internal_call( "MultiTheftAuto.Native.Element::GetPosition", CMonoFunctions::Element::GetPosition ); + MONO_DECLARE( Element, IsElement ); + MONO_DECLARE( Element, GetType ); + MONO_DECLARE( Element, GetByID ); + MONO_DECLARE( Element, GetByIndex ); + MONO_DECLARE( Element, GetChild ); + MONO_DECLARE( Element, GetChildrenCount ); + MONO_DECLARE( Element, GetID ); + MONO_DECLARE( Element, GetParent ); + MONO_DECLARE( Element, GetPosition ); + MONO_DECLARE( Element, GetRotation ); + MONO_DECLARE( Element, GetVelocity ); + MONO_DECLARE( Element, GetInterior ); + MONO_DECLARE( Element, IsWithinColShape ); + MONO_DECLARE( Element, IsWithinMarker ); + MONO_DECLARE( Element, GetDimension ); + MONO_DECLARE( Element, GetZoneName ); + MONO_DECLARE( Element, IsAttached ); + MONO_DECLARE( Element, GetAttachedTo ); + MONO_DECLARE( Element, GetColShape ); + MONO_DECLARE( Element, GetAlpha ); + MONO_DECLARE( Element, IsDoubleSided ); + MONO_DECLARE( Element, GetHealth ); + MONO_DECLARE( Element, GetModel ); + MONO_DECLARE( Element, IsInWater ); + MONO_DECLARE( Element, GetAttachedOffsetPosition ); + MONO_DECLARE( Element, GetAttachedOffsetRotation ); + MONO_DECLARE( Element, GetSyncer ); + MONO_DECLARE( Element, GetCollisionsEnabled ); + MONO_DECLARE( Element, IsFrozen ); + MONO_DECLARE( Element, GetLowLod ); + MONO_DECLARE( Element, IsLowLod ); - mono_add_internal_call( "MultiTheftAuto.Native.Vehicle::Create", CMonoFunctions::Vehicle::Create ); + // Element set funcs + MONO_DECLARE( Element, ClearVisibleTo ); + MONO_DECLARE( Element, SetID ); + MONO_DECLARE( Element, SetData ); + MONO_DECLARE( Element, RemoveData ); + MONO_DECLARE( Element, SetParent ); + MONO_DECLARE( Element, SetPosition ); + MONO_DECLARE( Element, SetRotation ); + MONO_DECLARE( Element, SetVelocity ); + MONO_DECLARE( Element, SetVisibleTo ); + MONO_DECLARE( Element, SetInterior ); + MONO_DECLARE( Element, SetDimension ); + MONO_DECLARE( Element, Attach ); + MONO_DECLARE( Element, Detach ); + MONO_DECLARE( Element, SetAlpha ); + MONO_DECLARE( Element, SetDoubleSided ); + MONO_DECLARE( Element, SetHealth ); + MONO_DECLARE( Element, SetModel ); + MONO_DECLARE( Element, SetAttachedOffsets ); + MONO_DECLARE( Element, SetSyncer ); + MONO_DECLARE( Element, SetCollisionsEnabled ); + MONO_DECLARE( Element, SetFrozen ); + MONO_DECLARE( Element, SetLowLod ); + + // Vehicle create/destroy functions + MONO_DECLARE( Vehicle, Create ); } void CMonoFunctions::Debug::Log( MonoString *string ) @@ -102,30 +151,30 @@ bool CMonoFunctions::Config::Set( MonoString *msKey, MonoString *msValue ) // Element create/destroy -unsigned int CMonoFunctions::Element::Create( MonoString* msTypeName, MonoString* msID ) +DWORD CMonoFunctions::Element::Create( MonoString* msTypeName, MonoString* msID ) { if( RESOURCE ) { const char* szTypeName = mono_string_to_utf8( msTypeName ); const char* szID = mono_string_to_utf8( msID ); - return (unsigned int)CLuaFunctionDefinitions::CreateElement( RESOURCE->GetLua(), szTypeName, szID ); + return (DWORD)CLuaFunctionDefinitions::CreateElement( RESOURCE->GetLua(), szTypeName, szID ); } return NULL; } -bool CMonoFunctions::Element::Destroy( unsigned int pElement ) +bool CMonoFunctions::Element::Destroy( DWORD pUserData ) { if( RESOURCE ) { - return CLuaFunctionDefinitions::DestroyElement( RESOURCE->GetLua(), (void*)pElement ); + return CLuaFunctionDefinitions::DestroyElement( RESOURCE->GetLua(), (void*)pUserData ); } return false; } -unsigned int CMonoFunctions::Element::Clone( unsigned int pUserData, MonoObject* vecPosition, bool bCloneElement ) +DWORD CMonoFunctions::Element::Clone( DWORD pUserData, MonoObject* vecPosition, bool bCloneElement ) { if( RESOURCE ) { @@ -135,7 +184,7 @@ unsigned int CMonoFunctions::Element::Clone( unsigned int pUserData, MonoObject* float fY = pPosition.GetPropertyValue( "Y" ); float fZ = pPosition.GetPropertyValue( "Z" ); - return (unsigned int)CLuaFunctionDefinitions::CloneElement( RESOURCE->GetLua(), (void*)pUserData, Vector3( fX, fY, fZ ), bCloneElement ); + return (DWORD)CLuaFunctionDefinitions::CloneElement( RESOURCE->GetLua(), (void*)pUserData, Vector3( fX, fY, fZ ), bCloneElement ); } return false; @@ -143,7 +192,7 @@ unsigned int CMonoFunctions::Element::Clone( unsigned int pUserData, MonoObject* // Element get funcs -bool CMonoFunctions::Element::IsElement( unsigned int pUserData ) +bool CMonoFunctions::Element::IsElement( DWORD pUserData ) { if( RESOURCE ) { @@ -153,7 +202,7 @@ bool CMonoFunctions::Element::IsElement( unsigned int pUserData ) return false; } -MonoString* CMonoFunctions::Element::GetType( unsigned int pUserData ) +MonoString* CMonoFunctions::Element::GetType( DWORD pUserData ) { if( RESOURCE ) { @@ -165,39 +214,39 @@ MonoString* CMonoFunctions::Element::GetType( unsigned int pUserData ) return mono_string_new( mono_domain_get(), "" ); } -unsigned int CMonoFunctions::Element::GetByID( MonoString* msID, unsigned int uiIndex ) +DWORD CMonoFunctions::Element::GetByID( MonoString* msID, unsigned int uiIndex ) { if( RESOURCE ) { const char* szID = mono_string_to_utf8( msID ); - return (unsigned int)CLuaFunctionDefinitions::GetElementByID( RESOURCE->GetLua(), szID, uiIndex ); + return (DWORD)CLuaFunctionDefinitions::GetElementByID( RESOURCE->GetLua(), szID, uiIndex ); } return NULL; } -unsigned int CMonoFunctions::Element::GetByIndex( int iIndex ) +DWORD CMonoFunctions::Element::GetByIndex( int iIndex ) { if( RESOURCE ) { - return (unsigned int)CLuaFunctionDefinitions::GetElementByIndex( RESOURCE->GetLua(), iIndex ); + return (DWORD)CLuaFunctionDefinitions::GetElementByIndex( RESOURCE->GetLua(), iIndex ); } return NULL; } -unsigned int CMonoFunctions::Element::GetChild( unsigned int pUserData, int iIndex ) +DWORD CMonoFunctions::Element::GetChild( DWORD pUserData, int iIndex ) { if( RESOURCE ) { - return (unsigned int)CLuaFunctionDefinitions::GetElementChild( RESOURCE->GetLua(), (void*)pUserData, iIndex ); + return (DWORD)CLuaFunctionDefinitions::GetElementChild( RESOURCE->GetLua(), (void*)pUserData, iIndex ); } return NULL; } -int CMonoFunctions::Element::GetChildrenCount( unsigned int pUserData ) +int CMonoFunctions::Element::GetChildrenCount( DWORD pUserData ) { if( RESOURCE ) { @@ -207,7 +256,7 @@ int CMonoFunctions::Element::GetChildrenCount( unsigned int pUserData ) return 0; } -MonoString* CMonoFunctions::Element::GetID( unsigned int pUserData ) +MonoString* CMonoFunctions::Element::GetID( DWORD pUserData ) { if( RESOURCE ) { @@ -219,7 +268,7 @@ MonoString* CMonoFunctions::Element::GetID( unsigned int pUserData ) return mono_string_new( mono_domain_get(), "" ); } -unsigned int CMonoFunctions::Element::GetParent( unsigned int pUserData ) +unsigned int CMonoFunctions::Element::GetParent( DWORD pUserData ) { if( RESOURCE ) { @@ -229,7 +278,7 @@ unsigned int CMonoFunctions::Element::GetParent( unsigned int pUserData ) return NULL; } -MonoObject* CMonoFunctions::Element::GetPosition( unsigned int pUserData ) +MonoObject* CMonoFunctions::Element::GetPosition( DWORD pUserData ) { if( RESOURCE ) { @@ -237,24 +286,11 @@ MonoObject* CMonoFunctions::Element::GetPosition( unsigned int pUserData ) if( CLuaFunctionDefinitions::GetElementPosition( RESOURCE->GetLua(), (void*)pUserData, vecPosition ) ) { - CMonoClass* pClass = RESOURCE->GetClassFromName( "MultiTheftAuto", "Vector3" ); + CMonoObject* pObject = RESOURCE->NewObject( "MultiTheftAuto", "Vector3", vecPosition ); - if( pClass ) + if( pObject ) { - CMonoObject* pObject = pClass->New( mono_domain_get(), vecPosition ); - - if( pObject ) - { - return pObject->GetObject(); - } - 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 pObject->GetObject(); } } } @@ -262,7 +298,7 @@ MonoObject* CMonoFunctions::Element::GetPosition( unsigned int pUserData ) return NULL; } -MonoObject* CMonoFunctions::Element::GetRotation( unsigned int pUserData ) +MonoObject* CMonoFunctions::Element::GetRotation( DWORD pUserData ) { if( RESOURCE ) { @@ -270,24 +306,11 @@ MonoObject* CMonoFunctions::Element::GetRotation( unsigned int pUserData ) if( CLuaFunctionDefinitions::GetElementRotation( RESOURCE->GetLua(), (void*)pUserData, vecPosition ) ) { - CMonoClass* pClass = RESOURCE->GetClassFromName( "MultiTheftAuto", "Vector3" ); + CMonoObject* pObject = RESOURCE->NewObject( "MultiTheftAuto", "Vector3", vecPosition ); - if( pClass ) + if( pObject ) { - CMonoObject* pObject = pClass->New( mono_domain_get(), vecPosition ); - - if( pObject ) - { - return pObject->GetObject(); - } - 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 pObject->GetObject(); } } } @@ -295,7 +318,7 @@ MonoObject* CMonoFunctions::Element::GetRotation( unsigned int pUserData ) return NULL; } -MonoObject* CMonoFunctions::Element::GetVelocity( unsigned int pUserData ) +MonoObject* CMonoFunctions::Element::GetVelocity( DWORD pUserData ) { if( RESOURCE ) { @@ -303,24 +326,11 @@ MonoObject* CMonoFunctions::Element::GetVelocity( unsigned int pUserData ) if( CLuaFunctionDefinitions::GetElementVelocity( RESOURCE->GetLua(), (void*)pUserData, vecPosition ) ) { - CMonoClass* pClass = RESOURCE->GetClassFromName( "MultiTheftAuto", "Vector3" ); + CMonoObject* pObject = RESOURCE->NewObject( "MultiTheftAuto", "Vector3", vecPosition ); - if( pClass ) + if( pObject ) { - CMonoObject* pObject = pClass->New( mono_domain_get(), vecPosition ); - - if( pObject ) - { - return pObject->GetObject(); - } - 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 pObject->GetObject(); } } } @@ -328,8 +338,569 @@ MonoObject* CMonoFunctions::Element::GetVelocity( unsigned int pUserData ) return NULL; } +unsigned char CMonoFunctions::Element::GetInterior( DWORD pUserData ) +{ + if( RESOURCE ) + { + unsigned char ucInterior; -unsigned int CMonoFunctions::Vehicle::Create( int model, MonoObject* position, MonoObject* rotation, MonoString* numberplate, bool direction, int variant1, int variant2 ) + if( CLuaFunctionDefinitions::GetElementInterior( RESOURCE->GetLua(), (void*)pUserData, ucInterior ) ) + { + return ucInterior; + } + } + + return 0; +} + +bool CMonoFunctions::Element::IsWithinColShape( DWORD pUserData ) +{ + if( RESOURCE ) + { + bool bWithin; + + if( CLuaFunctionDefinitions::IsElementWithinColShape( RESOURCE->GetLua(), (void*)pUserData, bWithin ) ) + { + return bWithin; + } + } + + return false; +} + +bool CMonoFunctions::Element::IsWithinMarker( DWORD pUserData ) +{ + if( RESOURCE ) + { + bool bWithin; + + if( CLuaFunctionDefinitions::IsElementWithinMarker( RESOURCE->GetLua(), (void*)pUserData, bWithin ) ) + { + return bWithin; + } + } + + return false; +} + +unsigned short CMonoFunctions::Element::GetDimension( DWORD pUserData ) +{ + if( RESOURCE ) + { + unsigned short usDimension; + + if( CLuaFunctionDefinitions::GetElementDimension( RESOURCE->GetLua(), (void*)pUserData, usDimension ) ) + { + return usDimension; + } + } + + return 0; +} + +MonoString* CMonoFunctions::Element::GetZoneName( DWORD pUserData, bool bCitiesOnly ) +{ + if( RESOURCE ) + { + string strOutName; + + if( CLuaFunctionDefinitions::GetElementZoneName( RESOURCE->GetLua(), (void*)pUserData, strOutName, bCitiesOnly ) ) + { + return RESOURCE->NewString( strOutName ); + } + } + + return NULL; +} + +bool CMonoFunctions::Element::IsAttached( DWORD pUserData ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::IsElementAttached( RESOURCE->GetLua(), (void*)pUserData ); + } + + return false; +} + +DWORD CMonoFunctions::Element::GetAttachedTo( DWORD pUserData ) +{ + if( RESOURCE ) + { + return (DWORD)CLuaFunctionDefinitions::GetElementAttachedTo( RESOURCE->GetLua(), (void*)pUserData ); + } + + return NULL; +} + +DWORD CMonoFunctions::Element::GetColShape( DWORD pUserData ) +{ + if( RESOURCE ) + { + return (DWORD)CLuaFunctionDefinitions::GetElementColShape( RESOURCE->GetLua(), (void*)pUserData ); + } + + return NULL; +} + +unsigned char CMonoFunctions::Element::GetAlpha( DWORD pUserData ) +{ + if( RESOURCE ) + { + unsigned char ucAlpha; + + if( CLuaFunctionDefinitions::GetElementAlpha( RESOURCE->GetLua(), (void*)pUserData, ucAlpha ) ) + { + return ucAlpha; + } + } + + return 0; +} + +bool CMonoFunctions::Element::IsDoubleSided( DWORD pUserData ) +{ + if( RESOURCE ) + { + bool bDoubleSided; + + if( CLuaFunctionDefinitions::IsElementDoubleSided( RESOURCE->GetLua(), (void*)pUserData, bDoubleSided ) ) + { + return bDoubleSided; + } + } + + return false; +} + +float CMonoFunctions::Element::GetHealth( DWORD pUserData ) +{ + if( RESOURCE ) + { + float fHealth; + + if( CLuaFunctionDefinitions::GetElementHealth( RESOURCE->GetLua(), (void*)pUserData, fHealth ) ) + { + return fHealth; + } + } + + return false; +} + +unsigned short CMonoFunctions::Element::GetModel( DWORD pUserData ) +{ + if( RESOURCE ) + { + unsigned short usModel; + + if( CLuaFunctionDefinitions::GetElementModel( RESOURCE->GetLua(), (void*)pUserData, usModel ) ) + { + return usModel; + } + } + + return false; +} + +bool CMonoFunctions::Element::IsInWater( DWORD pUserData ) +{ + if( RESOURCE ) + { + bool bInWater; + + if( CLuaFunctionDefinitions::IsElementInWater( RESOURCE->GetLua(), (void*)pUserData, bInWater ) ) + { + return bInWater; + } + } + + return false; +} + +MonoObject* CMonoFunctions::Element::GetAttachedOffsetPosition( DWORD pUserData ) +{ + if( RESOURCE ) + { + Vector3 vecPosition, vecRotation; + + if( CLuaFunctionDefinitions::GetElementAttachedOffsets( RESOURCE->GetLua(), (void*)pUserData, vecPosition, vecRotation ) ) + { + CMonoObject* pObject = RESOURCE->NewObject( "MultiTheftAuto", "Vector3", vecPosition ); + + if( pObject ) + { + return pObject->GetObject(); + } + } + } + + return NULL; +} + +MonoObject* CMonoFunctions::Element::GetAttachedOffsetRotation( DWORD pUserData ) +{ + if( RESOURCE ) + { + Vector3 vecPosition, vecRotation; + + if( CLuaFunctionDefinitions::GetElementAttachedOffsets( RESOURCE->GetLua(), (void*)pUserData, vecPosition, vecRotation ) ) + { + CMonoObject* pObject = RESOURCE->NewObject( "MultiTheftAuto", "Vector3", vecRotation ); + + if( pObject ) + { + return pObject->GetObject(); + } + } + } + + return NULL; +} + +DWORD CMonoFunctions::Element::GetSyncer( DWORD pUserData ) +{ + if( RESOURCE ) + { + return (DWORD)CLuaFunctionDefinitions::GetElementSyncer( RESOURCE->GetLua(), (void*)pUserData ); + } + + return NULL; +} + +bool CMonoFunctions::Element::GetCollisionsEnabled( DWORD pUserData ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::GetElementCollisionsEnabled( RESOURCE->GetLua(), (void*)pUserData ); + } + + return false; +} + +bool CMonoFunctions::Element::IsFrozen( DWORD pUserData ) +{ + if( RESOURCE ) + { + bool bFrozen; + + if( CLuaFunctionDefinitions::IsElementFrozen( RESOURCE->GetLua(), (void*)pUserData, bFrozen ) ) + { + return bFrozen; + } + } + + return false; +} + +DWORD CMonoFunctions::Element::GetLowLod( DWORD pUserData ) +{ + if( RESOURCE ) + { + void* pUserData; + + if( CLuaFunctionDefinitions::GetLowLodElement( RESOURCE->GetLua(), (void*)pUserData, pUserData ) ) + { + return (DWORD)pUserData; + } + } + + return NULL; +} + +bool CMonoFunctions::Element::IsLowLod( DWORD pUserData ) +{ + if( RESOURCE ) + { + bool bIsLowLod; + + if( CLuaFunctionDefinitions::IsElementLowLod( RESOURCE->GetLua(), (void*)pUserData, bIsLowLod ) ) + { + return bIsLowLod; + } + } + + return false; +} + +// Element set funcs + +bool CMonoFunctions::Element::ClearVisibleTo( DWORD pUserData ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::ClearElementVisibleTo( RESOURCE->GetLua(), (void*)pUserData ); + } + + return false; +} + +bool CMonoFunctions::Element::SetID( DWORD pUserData, MonoString* msID ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::SetElementID( RESOURCE->GetLua(), (void*)pUserData, string( mono_string_to_utf8( msID ) ) ); + } + + return false; +} + +bool CMonoFunctions::Element::SetData( DWORD pUserData, MonoString* msKey, CLuaArgument& Variable ) +{ + if( RESOURCE ) + { + string strKey( mono_string_to_utf8( msKey ) ); + + return CLuaFunctionDefinitions::SetElementData( RESOURCE->GetLua(), (void*)pUserData, strKey, Variable ); + } + + return false; +} + +bool CMonoFunctions::Element::RemoveData( DWORD pUserData, MonoString* msKey ) +{ + if( RESOURCE ) + { + string strKey( mono_string_to_utf8( msKey ) ); + + return CLuaFunctionDefinitions::RemoveElementData( RESOURCE->GetLua(), (void*)pUserData, strKey ); + } + + return false; +} + +bool CMonoFunctions::Element::SetParent( DWORD pUserData, DWORD pTarget ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::SetElementParent( RESOURCE->GetLua(), (void*)pUserData, (void*)pTarget ); + } + + return false; +} + +bool CMonoFunctions::Element::SetPosition( DWORD pUserData, MonoObject* pPosition, bool bWarp ) +{ + if( RESOURCE ) + { + CMonoObject pPosition( pPosition ); + + float fX = pPosition.GetPropertyValue( "X" ); + float fY = pPosition.GetPropertyValue( "Y" ); + float fZ = pPosition.GetPropertyValue( "Z" ); + + return CLuaFunctionDefinitions::SetElementPosition( RESOURCE->GetLua(), (void*)pUserData, Vector3( fX, fY, fZ ), bWarp ); + } + + return false; +} + +bool CMonoFunctions::Element::SetRotation( DWORD pUserData, MonoObject* pRotation, MonoString* msRotationOrder, bool bNewWay ) +{ + if( RESOURCE ) + { + CMonoObject pPosition( pRotation ); + + float fX = pPosition.GetPropertyValue( "X" ); + float fY = pPosition.GetPropertyValue( "Y" ); + float fZ = pPosition.GetPropertyValue( "Z" ); + + const char* szRotationOrder = mono_string_to_utf8( msRotationOrder ); + + return CLuaFunctionDefinitions::SetElementRotation( RESOURCE->GetLua(), (void*)pUserData, Vector3( fX, fY, fZ ), szRotationOrder, bNewWay ); + } + + return false; +} + +bool CMonoFunctions::Element::SetVelocity( DWORD pUserData, MonoObject* pVelocity ) +{ + if( RESOURCE ) + { + CMonoObject pPosition( pVelocity ); + + float fX = pPosition.GetPropertyValue( "X" ); + float fY = pPosition.GetPropertyValue( "Y" ); + float fZ = pPosition.GetPropertyValue( "Z" ); + + return CLuaFunctionDefinitions::SetElementVelocity( RESOURCE->GetLua(), (void*)pUserData, Vector3( fX, fY, fZ ) ); + } + + return false; +} + +bool CMonoFunctions::Element::SetVisibleTo( DWORD pUserData, DWORD pTarget, bool bVisible ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::SetElementVisibleTo( RESOURCE->GetLua(), (void*)pUserData, (void*)pTarget, bVisible ); + } + + return false; +} + +bool CMonoFunctions::Element::SetInterior( DWORD pUserData, int iInterior ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::SetElementInterior( RESOURCE->GetLua(), (void*)pUserData, iInterior ); + } + + return false; +} + +bool CMonoFunctions::Element::SetDimension( DWORD pUserData, int iDimension ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::SetElementDimension( RESOURCE->GetLua(), (void*)pUserData, iDimension ); + } + + return false; +} + +bool CMonoFunctions::Element::Attach( DWORD pUserData, DWORD pTarget, MonoObject* pMonoPosition, MonoObject* pMonoRotation ) +{ + if( RESOURCE ) + { + Vector3 + vecPosition, vecRotation; + + CMonoObject + pPosition( pMonoPosition ), pRotation( pMonoRotation ); + + vecPosition.fX = pPosition.GetPropertyValue( "X" ); + vecPosition.fY = pPosition.GetPropertyValue( "Y" ); + vecPosition.fZ = pPosition.GetPropertyValue( "Z" ); + + vecRotation.fX = pRotation.GetPropertyValue( "X" ); + vecRotation.fY = pRotation.GetPropertyValue( "Y" ); + vecRotation.fZ = pRotation.GetPropertyValue( "Z" ); + + return CLuaFunctionDefinitions::AttachElements( RESOURCE->GetLua(), (void*)pUserData, (void*)pTarget, vecPosition, vecRotation ); + } + + return false; +} + +bool CMonoFunctions::Element::Detach( DWORD pUserData, DWORD pTarget ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::DetachElements( RESOURCE->GetLua(), (void*)pUserData, (void*)pTarget ); + } + + return false; +} + +bool CMonoFunctions::Element::SetAlpha( DWORD pUserData, int iAlpha ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::SetElementAlpha( RESOURCE->GetLua(), (void*)pUserData, iAlpha ); + } + + return false; +} + +bool CMonoFunctions::Element::SetDoubleSided( DWORD pUserData, bool bDoubleSided ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::SetElementDoubleSided( RESOURCE->GetLua(), (void*)pUserData, bDoubleSided ); + } + + return false; +} + +bool CMonoFunctions::Element::SetHealth( DWORD pUserData, float fHealth ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::SetElementHealth( RESOURCE->GetLua(), (void*)pUserData, fHealth ); + } + + return false; +} + +bool CMonoFunctions::Element::SetModel( DWORD pUserData, int iModel ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::SetElementModel( RESOURCE->GetLua(), (void*)pUserData, iModel ); + } + + return false; +} + +bool CMonoFunctions::Element::SetAttachedOffsets( DWORD pUserData, MonoObject* pMonoPosition, MonoObject* pMonoRotation ) +{ + if( RESOURCE ) + { + Vector3 + vecPosition, vecRotation; + + CMonoObject + pPosition( pMonoPosition ), pRotation( pMonoRotation ); + + vecPosition.fX = pPosition.GetPropertyValue( "X" ); + vecPosition.fY = pPosition.GetPropertyValue( "Y" ); + vecPosition.fZ = pPosition.GetPropertyValue( "Z" ); + + vecRotation.fX = pRotation.GetPropertyValue( "X" ); + vecRotation.fY = pRotation.GetPropertyValue( "Y" ); + vecRotation.fZ = pRotation.GetPropertyValue( "Z" ); + + return CLuaFunctionDefinitions::SetElementAttachedOffsets( RESOURCE->GetLua(), (void*)pUserData, vecPosition, vecRotation ); + } + + return false; +} + +bool CMonoFunctions::Element::SetSyncer( DWORD pUserData, DWORD pPlayer ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::SetElementSyncer( RESOURCE->GetLua(), (void*)pUserData, (void*)pPlayer ); + } + + return false; +} + +bool CMonoFunctions::Element::SetCollisionsEnabled( DWORD pUserData, bool bEnabled ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::SetElementCollisionsEnabled( RESOURCE->GetLua(), (void*)pUserData, bEnabled ); + } + + return false; +} + +bool CMonoFunctions::Element::SetFrozen( DWORD pUserData, bool bFrozen ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::SetElementFrozen( RESOURCE->GetLua(), (void*)pUserData, bFrozen ); + } + + return false; +} + +bool CMonoFunctions::Element::SetLowLod( DWORD pUserData, bool bEnabled ) +{ + if( RESOURCE ) + { + return CLuaFunctionDefinitions::SetLowLodElement( RESOURCE->GetLua(), (void*)pUserData, bEnabled ); + } + + return false; +} + + +// Vehicle create/destroy functions + +DWORD CMonoFunctions::Vehicle::Create( int model, MonoObject* position, MonoObject* rotation, MonoString* numberplate, bool direction, int variant1, int variant2 ) { if( RESOURCE ) { @@ -352,13 +923,7 @@ unsigned int CMonoFunctions::Vehicle::Create( int model, MonoObject* position, M sNumberplate = mono_string_to_utf8( numberplate ); } - void* pVehicle = CLuaFunctionDefinitions::CreateVehicle( RESOURCE->GetLua(), model, fX, fY, fZ, fRX, fRY, fRZ, sNumberplate, direction, variant1, variant2 ); - - if( pVehicle ) - { - return (unsigned int)pVehicle; - //return 0x1337; - } + return (DWORD)CLuaFunctionDefinitions::CreateVehicle( RESOURCE->GetLua(), model, fX, fY, fZ, fRX, fRY, fRZ, sNumberplate, direction, variant1, variant2 ); } return NULL; diff --git a/mta-mono/src/CMonoFunctions.h b/mta-mono/src/CMonoFunctions.h index eeb2c42..6f431a0 100644 --- a/mta-mono/src/CMonoFunctions.h +++ b/mta-mono/src/CMonoFunctions.h @@ -42,30 +42,74 @@ public: { public: // Element create/destroy - static unsigned int Create ( MonoString* msTypeName, MonoString* msID ); - static bool Destroy ( unsigned int pUserData ); - static unsigned int Clone ( unsigned int pUserData, MonoObject* vecPosition, bool bCloneElement ); + static DWORD Create ( MonoString* msTypeName, MonoString* msID ); + static bool Destroy ( DWORD pUserData ); + static DWORD Clone ( DWORD pUserData, MonoObject* vecPosition, bool bCloneElement ); // Element get funcs - static bool IsElement ( unsigned int pUserData ); - static MonoString* GetType ( unsigned int pUserData ); - static unsigned int GetByID ( MonoString* msID, unsigned int uiIndex ); - static unsigned int GetByIndex ( int iIndex ); - static unsigned int GetChild ( unsigned int pUserData, int iIndex ); - static int GetChildrenCount ( unsigned int pUserData ); - static MonoString* GetID ( unsigned int pUserData ); -// static MonoObject* GetData ( unsigned int pUserData, MonoString* sKey, bool bInherit = true ); -// static ?* GetAllData ( unsigned int pUserData ); - static unsigned int GetParent ( unsigned int pUserData ); - static MonoObject* GetPosition ( unsigned int pUserData ); - static MonoObject* GetRotation ( unsigned int pUserData ); - static MonoObject* GetVelocity ( unsigned int pUserData ); + static bool IsElement ( DWORD pUserData ); + static MonoString* GetType ( DWORD pUserData ); + static DWORD GetByID ( MonoString* msID, unsigned int uiIndex ); + static DWORD GetByIndex ( int iIndex ); + static DWORD GetChild ( DWORD pUserData, int iIndex ); + static int GetChildrenCount ( DWORD pUserData ); + static MonoString* GetID ( DWORD pUserData ); +// static MonoObject* GetData ( DWORD pUserData, MonoString* sKey, bool bInherit = true ); +// static ?* GetAllData ( DWORD pUserData ); + static unsigned int GetParent ( DWORD pUserData ); + static MonoObject* GetPosition ( DWORD pUserData ); + static MonoObject* GetRotation ( DWORD pUserData ); + static MonoObject* GetVelocity ( DWORD pUserData ); + static unsigned char GetInterior ( DWORD pUserData ); + static bool IsWithinColShape ( DWORD pUserData ); + static bool IsWithinMarker ( DWORD pUserData ); + static unsigned short GetDimension ( DWORD pUserData ); + static MonoString* GetZoneName ( DWORD pUserData, bool bCitiesOnly = false ); + static bool IsAttached ( DWORD pUserData ); + static DWORD GetAttachedTo ( DWORD pUserData ); + static DWORD GetColShape ( DWORD pUserData ); + static unsigned char GetAlpha ( DWORD pUserData ); + static bool IsDoubleSided ( DWORD pUserData ); + static float GetHealth ( DWORD pUserData ); + static unsigned short GetModel ( DWORD pUserData ); + static bool IsInWater ( DWORD pUserData ); + static MonoObject* GetAttachedOffsetPosition ( DWORD pUserData ); + static MonoObject* GetAttachedOffsetRotation ( DWORD pUserData ); + static DWORD GetSyncer ( DWORD pUserData ); + static bool GetCollisionsEnabled ( DWORD pUserData ); + static bool IsFrozen ( DWORD pUserData ); + static DWORD GetLowLod ( DWORD pUserData ); + static bool IsLowLod ( DWORD pUserData ); + + // Element set funcs + static bool ClearVisibleTo ( DWORD pUserData ); + static bool SetID ( DWORD pUserData, MonoString* msID ); + static bool SetData ( DWORD pUserData, MonoString* msKey, CLuaArgument& Variable ); + static bool RemoveData ( DWORD pUserData, MonoString* msKey ); + static bool SetParent ( DWORD pUserData, DWORD pTarget ); + static bool SetPosition ( DWORD pUserData, MonoObject* pPosition, bool bWarp ); + static bool SetRotation ( DWORD pUserData, MonoObject* pRotation, MonoString* msRotationOrder, bool bNewWay ); + static bool SetVelocity ( DWORD pUserData, MonoObject* pVelocity ); + static bool SetVisibleTo ( DWORD pUserData, DWORD pTarget, bool bVisible ); + static bool SetInterior ( DWORD pUserData, int iInterior ); + static bool SetDimension ( DWORD pUserData, int iDimension ); + static bool Attach ( DWORD pUserData, DWORD pTarget, MonoObject* pPosition, MonoObject* pRotation ); + static bool Detach ( DWORD pUserData, DWORD pTarget ); + static bool SetAlpha ( DWORD pUserData, int iAlpha ); + static bool SetDoubleSided ( DWORD pUserData, bool bDoubleSided ); + static bool SetHealth ( DWORD pUserData, float fHealth ); + static bool SetModel ( DWORD pUserData, int iModel ); + static bool SetAttachedOffsets ( DWORD pUserData, MonoObject* pPosition, MonoObject* pRotation ); + static bool SetSyncer ( DWORD pUserData, DWORD pPlayer ); + static bool SetCollisionsEnabled ( DWORD pUserData, bool bEnabled ); + static bool SetFrozen ( DWORD pUserData, bool bFrozen ); + static bool SetLowLod ( DWORD pUserData, bool bEnabled ); }; class Vehicle { public: - static unsigned int Create ( int model, MonoObject* position, MonoObject* rotation, MonoString* numberplate, bool direction = false, int variant1 = 255, int variant2 = 255 ); + static DWORD Create ( int model, MonoObject* position, MonoObject* rotation, MonoString* numberplate, bool direction = false, int variant1 = 255, int variant2 = 255 ); }; }; diff --git a/mta-mono/src/CResource.cpp b/mta-mono/src/CResource.cpp index fe8bf00..0463462 100644 --- a/mta-mono/src/CResource.cpp +++ b/mta-mono/src/CResource.cpp @@ -133,4 +133,79 @@ CMonoClass* CResource::GetClassFromName( const char* szNamespace, const char* sz } return NULL; -} \ No newline at end of file +} + +CMonoObject* CResource::NewObject( const char* szNamespace, const char* szName ) +{ + CMonoClass* pClass = this->GetClassFromName( szNamespace, szName ); + + if( pClass ) + { + CMonoObject* pObject = pClass->New( mono_domain_get() ); + + 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 NULL; +} + +CMonoObject* CResource::NewObject( const char* szNamespace, const char* szName, Vector3& vecVector ) +{ + CMonoClass* pClass = this->GetClassFromName( szNamespace, szName ); + + if( pClass ) + { + CMonoObject* pObject = pClass->New( mono_domain_get(), vecVector ); + + 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 NULL; +} + +CMonoObject* CResource::NewObject( const char* szNamespace, const char* szName, void** args, int argc ) +{ + CMonoClass* pClass = this->GetClassFromName( szNamespace, szName ); + + if( pClass ) + { + CMonoObject* pObject = pClass->New( 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 NULL; +} diff --git a/mta-mono/src/CResource.h b/mta-mono/src/CResource.h index 5806bc5..4641153 100644 --- a/mta-mono/src/CResource.h +++ b/mta-mono/src/CResource.h @@ -44,6 +44,20 @@ public: CMonoClass* GetClassFromName( const char* szNamespace, const char* szName ); + CMonoObject* NewObject( const char* szNamespace, const char* szName ); + CMonoObject* NewObject( const char* szNamespace, const char* szName, Vector3& vecVector ); + CMonoObject* 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() ); + } + string GetName ( void ) { return this->m_sName; } lua_State *GetLua ( void ) { return this->m_pLuaVM; } };