From a091fe81776828ad866b4544c5ce4759b1fa3ac3 Mon Sep 17 00:00:00 2001 From: Dmitry Korolev Date: Fri, 3 Oct 2014 21:00:46 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=BF=D1=83=D1=89=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mta-mono/src/CMonoFunctions.cpp | 82 +++++++++++++++++++++++++++++++++ mta-mono/src/CMonoFunctions.h | 42 +++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 mta-mono/src/CMonoFunctions.cpp create mode 100644 mta-mono/src/CMonoFunctions.h diff --git a/mta-mono/src/CMonoFunctions.cpp b/mta-mono/src/CMonoFunctions.cpp new file mode 100644 index 0000000..082837d --- /dev/null +++ b/mta-mono/src/CMonoFunctions.cpp @@ -0,0 +1,82 @@ +/********************************************************* +* +* 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" + +#include "CResource.h" +#include "CResourceManager.h" + +extern ILuaModuleManager10 *g_pModuleManager; +extern CResourceManager *g_pResourceManager; + +#define RESOURCE g_pResourceManager->GetFromList( mono_domain_get() ) + +void CMonoFunctions::AddInternals( void ) +{ + mono_add_internal_call( "MultiTheftAuto.Debug::Log", CMonoFunctions::Debug::Log ); + mono_add_internal_call( "MultiTheftAuto.Debug::Info", CMonoFunctions::Debug::Info ); + mono_add_internal_call( "MultiTheftAuto.Debug::Error", CMonoFunctions::Debug::Error ); + mono_add_internal_call( "MultiTheftAuto.Native.Config::Get", CMonoFunctions::Config::Get ); + mono_add_internal_call( "MultiTheftAuto.Native.Config::Set", CMonoFunctions::Config::Set ); +} + +void CMonoFunctions::Debug::Log( MonoString *string ) +{ + if( RESOURCE ) + { + g_pModuleManager->Printf( "%s\n", mono_string_to_utf8( string ) ); + } +} + +void CMonoFunctions::Debug::Info( MonoString *string ) +{ + if( RESOURCE ) + { + g_pModuleManager->DebugPrintf( RESOURCE->GetLua(), "%s\n", mono_string_to_utf8( string ) ); + } +} + +void CMonoFunctions::Debug::Error( MonoString *string ) +{ + if( RESOURCE ) + { + + + g_pModuleManager->ErrorPrintf( "%s\n", mono_string_to_utf8( string ) ); + } +} + +MonoString *CMonoFunctions::Config::Get( MonoString *msKey ) +{ + if( RESOURCE ) + { + string sValue = CLuaFunctionDefinitions::Get( RESOURCE->GetLua(), mono_string_to_utf8( msKey ) ); + + return mono_string_new( mono_domain_get(), sValue.c_str() ); + } + + return mono_string_new( mono_domain_get(), "" ); +} + +bool CMonoFunctions::Config::Set( MonoString *msKey, MonoString *msValue ) +{ + if( RESOURCE ) + { + string + sKey = mono_string_to_utf8( msKey ), + sValue = mono_string_to_utf8( msValue ); + + return CLuaFunctionDefinitions::Set( RESOURCE->GetLua(), sKey, sValue ); + } + + return false; +} diff --git a/mta-mono/src/CMonoFunctions.h b/mta-mono/src/CMonoFunctions.h new file mode 100644 index 0000000..a9dbefb --- /dev/null +++ b/mta-mono/src/CMonoFunctions.h @@ -0,0 +1,42 @@ +/********************************************************* +* +* 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 CMonoFunctions; + +#ifndef __CMONOFUNCTIONS_H +#define __CMONOFUNCTIONS_H + +#include "Common.h" +#include "lua/CLuaFunctionDefinitions.h" + +class CMonoFunctions +{ +public: + static void AddInternals( void ); + + class Debug + { + public: + static void Log ( MonoString *string ); + static void Info ( MonoString *string ); + static void Error ( MonoString *string ); + }; + + class Config + { + public: + static MonoString *Get ( MonoString *msKey ); + static bool Set ( MonoString *msKey, MonoString *msValue ); + }; +}; + +#endif \ No newline at end of file