Skip to content

Commit 67aefbc

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feature/range-loops
2 parents 2f1c235 + c8bc5eb commit 67aefbc

File tree

14 files changed

+2063
-1594
lines changed

14 files changed

+2063
-1594
lines changed

amx-deps/src/CFunctions.cpp

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ AMX *suspendedAMX = NULL;
6666

6767
// amxLoadPlugin(pluginName)
6868
int CFunctions::amxLoadPlugin(lua_State *luaVM) {
69-
static const char *requiredExports[] = { "Load", "Unload", "Supports", 0 };
69+
static const char *requiredExports[] = { "Load", "Supports", 0 };
7070

7171
const char *pluginName = luaL_checkstring(luaVM, 1);
7272
if(!pluginName || loadedPlugins.find(pluginName) != loadedPlugins.end() || !isSafePath(pluginName)) {
@@ -83,7 +83,7 @@ int CFunctions::amxLoadPlugin(lua_State *luaVM) {
8383
#endif
8484

8585
HMODULE hPlugin = loadLib(pluginPath.c_str());
86-
86+
8787
if(!hPlugin) {
8888
lua_pushboolean(luaVM, 0);
8989
return 1;
@@ -150,14 +150,26 @@ int CFunctions::amxLoad(lua_State *luaVM) {
150150
return 1;
151151
}
152152

153-
char buff[256];
154-
snprintf(buff, sizeof(buff), "%s/mods/deathmatch/resources/[gamemodes]/[amx]/%s/%s", fs::current_path().string().c_str(), resName, amxName);
155-
fs::path amxPath = buff;
156-
amxPath = fs::canonical(amxPath);
153+
lua_State* theirLuaVM = pModuleManager->GetResourceFromName(resName);
154+
if (theirLuaVM == nullptr) {
155+
using namespace std::string_literals;
156+
std::string errMsg = "resource "s + resName + " does not exist!";
157+
lua_pushboolean(luaVM, false);
158+
lua_pushstring(luaVM, errMsg.c_str());
159+
return 2;
160+
}
161+
162+
char amxPath[256];
163+
if (!pModuleManager->GetResourceFilePath(theirLuaVM, amxName, amxPath, 256))
164+
{
165+
lua_pushboolean(luaVM, false);
166+
lua_pushstring(luaVM, "file not found");
167+
return 2;
168+
}
157169

158170
// Load .amx
159171
AMX *amx = new AMX;
160-
int err = aux_LoadProgram(amx, buff, NULL);
172+
int err = aux_LoadProgram(amx, amxPath, NULL);
161173
if(err != AMX_ERR_NONE) {
162174
delete amx;
163175
lua_pushboolean(luaVM, 0);
@@ -196,9 +208,9 @@ int CFunctions::amxLoad(lua_State *luaVM) {
196208

197209
// Save info about the amx
198210
AMXPROPS props;
199-
props.filePath = amxPath.string();
211+
props.filePath = amxPath;
200212
props.resourceName = resName;
201-
props.resourceVM = pModuleManager->GetResourceFromName(resName);
213+
props.resourceVM = theirLuaVM;
202214

203215
lua_register(props.resourceVM, "pawn", CFunctions::pawn);
204216
loadedAMXs[amx] = props;
@@ -391,9 +403,12 @@ int CFunctions::amxUnload(lua_State *luaVM) {
391403
// amxUnloadAllPlugins()
392404
int CFunctions::amxUnloadAllPlugins(lua_State *luaVM) {
393405
for (const auto& plugin : loadedPlugins) {
394-
plugin.second->Unload();
395-
freeLib(plugin.second->pPluginPointer);
396-
delete plugin.second;
406+
Unload_t* Unload = it.second->Unload;
407+
if (Unload) {
408+
Unload();
409+
}
410+
freeLib(it.second->pPluginPointer);
411+
delete it.second;
397412
}
398413
loadedPlugins.clear();
399414
vecPfnProcessTick.clear();
@@ -407,15 +422,15 @@ int CFunctions::amxRegisterLuaPrototypes(lua_State *luaVM) {
407422
luaL_checktype(luaVM, 1, LUA_TTABLE);
408423
int mainTop = lua_gettop(mainVM);
409424

410-
string resName;
411-
pModuleManager->GetResourceName(luaVM, resName);
425+
char resName[255];
426+
pModuleManager->GetResourceName(luaVM, resName, 255);
412427
lua_getfield(mainVM, LUA_REGISTRYINDEX, "amx");
413-
lua_getfield(mainVM, -1, resName.c_str());
428+
lua_getfield(mainVM, -1, resName);
414429
if(lua_isnil(mainVM, -1)) {
415430
lua_pop(mainVM, 1);
416431
lua_newtable(mainVM);
417432
lua_pushvalue(mainVM, -1);
418-
lua_setfield(mainVM, -3, resName.c_str());
433+
lua_setfield(mainVM, -3, resName);
419434
}
420435

421436
lua_newtable(mainVM);
@@ -488,18 +503,18 @@ int CFunctions::pawn(lua_State *luaVM) {
488503

489504
int mainTop = lua_gettop(mainVM);
490505

491-
string resName;
492-
pModuleManager->GetResourceName(luaVM, resName);
506+
char resName[255];
507+
pModuleManager->GetResourceName(luaVM, resName, 255);
493508
lua_getfield(mainVM, LUA_REGISTRYINDEX, "amx");
494-
lua_getfield(mainVM, -1, resName.c_str());
509+
lua_getfield(mainVM, -1, resName);
495510
if(lua_isnil(mainVM, -1)) {
496511
lua_settop(mainVM, mainTop);
497-
return luaL_error(luaVM, "pawn: resource %s is not an amx resource", resName.c_str());
512+
return luaL_error(luaVM, "pawn: resource %s is not an amx resource", resName);
498513
}
499514
lua_getfield(mainVM, -1, "pawnprototypes");
500515
if(lua_isnil(mainVM, -1)) {
501516
lua_settop(mainVM, mainTop);
502-
return luaL_error(luaVM, "pawn: resource %s does not have any registered Pawn functions - see amxRegisterPawnPrototypes", resName.c_str());
517+
return luaL_error(luaVM, "pawn: resource %s does not have any registered Pawn functions - see amxRegisterPawnPrototypes", resName);
503518
}
504519
lua_getfield(mainVM, -1, fnName);
505520
if(lua_isnil(mainVM, -1)) {

amx-deps/src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ CPP = gcc
1010
# Compiler flags
1111
# NOTE: add -g for debug, remove for release!
1212
ASMFLAGS = -O1 -f elf -I./amx/
13-
CPPFLAGS = -MD -O2 -Wall -I./ -I/usr/local/include/boost-1_35 -I./amx -I./include -I./linux -DAMX_DONT_RELOCATE -DFLOATPOINT -DASM32
13+
CPPFLAGS = -MD -O2 -Wall -I./ -I/usr/local/include/boost-1_35 -I./amx -I./include -I./linux -DAMX_DONT_RELOCATE -DFLOATPOINT
1414
LDFLAGS = -fPIC -s -shared -Wl,-soname,$(PROG).1,-R./
1515
LIBS = -lpthread -lstdc++ -llua5.1 -lsqlite3 -lboost_filesystem-gcc41-mt-s -lboost_system-gcc41-mt-s
1616

amx-deps/src/amx/amxexec.obj

-18.5 KB
Binary file not shown.
Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,65 @@
11
/*****************************************************************************
2-
*
3-
* PROJECT: Multi Theft Auto v1.0
4-
* LICENSE: See LICENSE in the top level directory
5-
* FILE: publicsdk/include/ILuaModuleManager.h
6-
* PURPOSE: Lua dynamic module interface
7-
*
8-
* Multi Theft Auto is available from http://www.multitheftauto.com/
9-
*
10-
*****************************************************************************/
2+
*
3+
* PROJECT: Multi Theft Auto v1.0
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: publicsdk/include/ILuaModuleManager.h
6+
* PURPOSE: Lua dynamic module interface
7+
*
8+
* Multi Theft Auto is available from http://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
1111

1212
// INTERFACE for Lua dynamic modules
1313

14-
#ifndef __ILUAMODULEMANAGER_H
15-
#define __ILUAMODULEMANAGER_H
14+
#pragma once
1615

1716
#define MAX_INFO_LENGTH 128
1817

1918
extern "C"
2019
{
21-
#include "lua.h"
22-
#include "lualib.h"
23-
#include "lauxlib.h"
20+
#include <lua.h>
21+
#include <lualib.h>
22+
#include <lauxlib.h>
2423
}
24+
#include <string>
25+
26+
#ifndef __CChecksum_H
27+
class CChecksum
28+
{
29+
public:
30+
unsigned long ulCRC;
31+
unsigned char mD5[16];
32+
};
33+
#endif
2534

2635
/* Interface for modules until DP2.3 */
2736
class ILuaModuleManager
2837
{
2938
public:
30-
virtual void ErrorPrintf ( const char* szFormat, ... ) = 0;
31-
virtual void DebugPrintf ( lua_State * luaVM, const char* szFormat, ... ) = 0;
32-
virtual void Printf ( const char* szFormat, ... ) = 0;
33-
34-
virtual bool RegisterFunction ( lua_State * luaVM, const char *szFunctionName, lua_CFunction Func ) = 0;
35-
virtual bool GetResourceName ( lua_State * luaVM, std::string &strName ) = 0;
36-
virtual unsigned long GetResourceMetaCRC ( lua_State * luaVM ) = 0;
37-
virtual unsigned long GetResourceFileCRC ( lua_State * luaVM, const char* szFile ) = 0;
39+
virtual void ErrorPrintf(const char* szFormat, ...) = 0;
40+
virtual void DebugPrintf(lua_State* luaVM, const char* szFormat, ...) = 0;
41+
virtual void Printf(const char* szFormat, ...) = 0;
42+
43+
virtual bool RegisterFunction(lua_State* luaVM, const char* szFunctionName, lua_CFunction Func) = 0;
44+
virtual bool GetResourceName(
45+
lua_State* luaVM, std::string& strName) = 0; // This function might not work if module and MTA were compiled with different compiler versions
46+
virtual CChecksum GetResourceMetaChecksum(lua_State* luaVM) = 0;
47+
virtual CChecksum GetResourceFileChecksum(lua_State* luaVM, const char* szFile) = 0;
3848
};
3949

4050
/* Interface for modules until 1.0 */
4151
class ILuaModuleManager10 : public ILuaModuleManager
4252
{
4353
public:
44-
virtual unsigned long GetVersion ( ) = 0;
45-
virtual const char* GetVersionString ( ) = 0;
46-
virtual const char* GetVersionName ( ) = 0;
47-
virtual unsigned long GetNetcodeVersion ( ) = 0;
48-
virtual const char* GetOperatingSystemName ( ) = 0;
54+
virtual unsigned long GetVersion() = 0;
55+
virtual const char* GetVersionString() = 0;
56+
virtual const char* GetVersionName() = 0;
57+
virtual unsigned long GetNetcodeVersion() = 0;
58+
virtual const char* GetOperatingSystemName() = 0;
4959

50-
virtual lua_State* GetResourceFromName ( const char* szResourceName ) = 0;
51-
};
60+
virtual lua_State* GetResourceFromName(const char* szResourceName) = 0;
5261

53-
#endif
62+
// GetResourceName above doesn't work if module and MTA were compiled with different compiler versions
63+
virtual bool GetResourceName(lua_State* luaVM, char* szName, size_t length) = 0;
64+
virtual bool GetResourceFilePath(lua_State* luaVM, const char* fileName, char* path, size_t length) = 0;
65+
};

amx-deps/src/lib/lua5.1d.exp

-16.9 KB
Binary file not shown.

amx-deps/src/lib/lua5.1d.lib

-26.3 KB
Binary file not shown.

amx-deps/src/ml_base.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ MTAEXPORT void RegisterFunctions ( lua_State * luaVM )
150150
pModuleManager->RegisterFunction(luaVM, "amxVersion", CFunctions::amxVersion);
151151
pModuleManager->RegisterFunction(luaVM, "amxVersionString", CFunctions::amxVersionString);
152152

153-
string resName;
154-
if(!pModuleManager->GetResourceName(luaVM, resName) || resName.compare("amx"))
153+
char resNameBuf[4];
154+
bool ok = pModuleManager->GetResourceName(luaVM, resNameBuf, 4);
155+
if (!ok || std::string(resNameBuf) != "amx")
155156
return;
156157

157158
mainVM = luaVM;

amx-deps/src/ml_base.vcxproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<ClCompile>
6464
<Optimization>Disabled</Optimization>
6565
<AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
66-
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_USRDLL;__WIN32__;AMX_DONT_RELOCATE;FLOATPOINT;ASM32;%(PreprocessorDefinitions);HAVE_INTTYPES_H;HAVE_MALLOC_H;HAVE_STDINT_H;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
66+
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_USRDLL;__WIN32__;FLOATPOINT;%(PreprocessorDefinitions);HAVE_INTTYPES_H;HAVE_MALLOC_H;HAVE_STDINT_H;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
6767
<MinimalRebuild>true</MinimalRebuild>
6868
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
6969
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
@@ -79,7 +79,6 @@
7979
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
8080
</ResourceCompile>
8181
<Link>
82-
<AdditionalOptions>amx\amxexec.obj %(AdditionalOptions)</AdditionalOptions>
8382
<AdditionalDependencies>./lib/lua5.1.lib;./lib/sqlite3.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
8483
<IgnoreSpecificDefaultLibraries>MSVCRT;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
8584
<ModuleDefinitionFile />
@@ -101,7 +100,7 @@
101100
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
102101
<OmitFramePointers>true</OmitFramePointers>
103102
<AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
104-
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_USRDLL;__WIN32__;AMX_DONT_RELOCATE;FLOATPOINT;ASM32;%(PreprocessorDefinitions);HAVE_INTTYPES_H;HAVE_MALLOC_H;HAVE_STDINT_H;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
103+
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_USRDLL;__WIN32__;FLOATPOINT;%(PreprocessorDefinitions);HAVE_INTTYPES_H;HAVE_MALLOC_H;HAVE_STDINT_H;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
105104
<StringPooling>true</StringPooling>
106105
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
107106
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
@@ -116,7 +115,6 @@
116115
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
117116
</ResourceCompile>
118117
<Link>
119-
<AdditionalOptions>amx\amxexec.obj %(AdditionalOptions)</AdditionalOptions>
120118
<AdditionalDependencies>./lib/lua5.1.lib;./lib/sqlite3.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
121119
<ModuleDefinitionFile />
122120
<GenerateDebugInformation>true</GenerateDebugInformation>

0 commit comments

Comments
 (0)