From d4c9376ff4867e7fe7f222f9acb4299bc36c99c6 Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 20 Jan 2025 22:35:08 +0000 Subject: [PATCH] fix: Replace git submodules with direct code --- .gitmodules | 6 - lib/cmake-modules | 1 - lib/cmake-modules/.gitattributes | 1 + lib/cmake-modules/AMXConfig.cmake | 18 + lib/cmake-modules/AddSAMPPlugin.cmake | 37 ++ lib/cmake-modules/AddSAMPPluginTest.cmake | 46 ++ lib/cmake-modules/FindPawnCC.cmake | 16 + lib/cmake-modules/FindSAMPGDK.cmake | 17 + lib/cmake-modules/FindSAMPSDK.cmake | 24 + lib/cmake-modules/FindSAMPServer.cmake | 34 ++ lib/cmake-modules/FindSAMPServerCLI.cmake | 28 + lib/cmake-modules/LICENSE.txt | 14 + lib/cmake-modules/README.md | 14 + lib/samp-plugin-sdk | 1 - lib/samp-plugin-sdk/amx/amx.h | 441 +++++++++++++++ lib/samp-plugin-sdk/amx/amx2.h | 49 ++ lib/samp-plugin-sdk/amx/getch.c | 80 +++ lib/samp-plugin-sdk/amx/getch.h | 15 + lib/samp-plugin-sdk/amx/sclinux.h | 51 ++ lib/samp-plugin-sdk/amxplugin.cpp | 630 ++++++++++++++++++++++ lib/samp-plugin-sdk/amxplugin2.cpp | 114 ++++ lib/samp-plugin-sdk/plugincommon.h | 123 +++++ src/main.h | 1 + 23 files changed, 1753 insertions(+), 8 deletions(-) delete mode 160000 lib/cmake-modules create mode 100644 lib/cmake-modules/.gitattributes create mode 100644 lib/cmake-modules/AMXConfig.cmake create mode 100644 lib/cmake-modules/AddSAMPPlugin.cmake create mode 100644 lib/cmake-modules/AddSAMPPluginTest.cmake create mode 100644 lib/cmake-modules/FindPawnCC.cmake create mode 100644 lib/cmake-modules/FindSAMPGDK.cmake create mode 100644 lib/cmake-modules/FindSAMPSDK.cmake create mode 100644 lib/cmake-modules/FindSAMPServer.cmake create mode 100644 lib/cmake-modules/FindSAMPServerCLI.cmake create mode 100644 lib/cmake-modules/LICENSE.txt create mode 100644 lib/cmake-modules/README.md delete mode 160000 lib/samp-plugin-sdk create mode 100644 lib/samp-plugin-sdk/amx/amx.h create mode 100644 lib/samp-plugin-sdk/amx/amx2.h create mode 100644 lib/samp-plugin-sdk/amx/getch.c create mode 100644 lib/samp-plugin-sdk/amx/getch.h create mode 100644 lib/samp-plugin-sdk/amx/sclinux.h create mode 100644 lib/samp-plugin-sdk/amxplugin.cpp create mode 100644 lib/samp-plugin-sdk/amxplugin2.cpp create mode 100644 lib/samp-plugin-sdk/plugincommon.h diff --git a/.gitmodules b/.gitmodules index 55618b8..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +0,0 @@ -[submodule "lib/cmake-modules"] - path = lib/cmake-modules - url = https://github.com/Zeex/cmake-modules.git -[submodule "lib/samp-plugin-sdk"] - path = lib/samp-plugin-sdk - url = https://github.com/maddinat0r/samp-plugin-sdk.git diff --git a/lib/cmake-modules b/lib/cmake-modules deleted file mode 160000 index b5ec035..0000000 --- a/lib/cmake-modules +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b5ec035f5c82d15e4b5ae126786fc8b7ae4a14f6 diff --git a/lib/cmake-modules/.gitattributes b/lib/cmake-modules/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/lib/cmake-modules/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/lib/cmake-modules/AMXConfig.cmake b/lib/cmake-modules/AMXConfig.cmake new file mode 100644 index 0000000..812b34a --- /dev/null +++ b/lib/cmake-modules/AMXConfig.cmake @@ -0,0 +1,18 @@ +include(CheckIncludeFile) + +check_include_file(alloca.h HAVE_ALLOCA_H) +if(HAVE_ALLOCA_H) + add_definitions(-DHAVE_ALLOCA_H) +endif() +check_include_file(inttypes.h HAVE_INTTYPES_H) +if(HAVE_INTTYPES_H) + add_definitions(-DHAVE_INTTYPES_H) +endif() +check_include_file(malloc.h HAVE_MALLOC_H) +if(HAVE_MALLOC_H) + add_definitions(-DHAVE_MALLOC_H) +endif() +check_include_file(stdint.h HAVE_STDINT_H) +if(HAVE_STDINT_H) + add_definitions(-DHAVE_STDINT_H) +endif() diff --git a/lib/cmake-modules/AddSAMPPlugin.cmake b/lib/cmake-modules/AddSAMPPlugin.cmake new file mode 100644 index 0000000..376e5b1 --- /dev/null +++ b/lib/cmake-modules/AddSAMPPlugin.cmake @@ -0,0 +1,37 @@ +function(add_samp_plugin name) + add_library(${name} MODULE ${ARGN}) + + set_target_properties(${name} PROPERTIES PREFIX "") + + if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set_property(TARGET ${name} APPEND_STRING PROPERTY COMPILE_FLAGS " -m32") + set_property(TARGET ${name} APPEND_STRING PROPERTY LINK_FLAGS " -m32") + endif() + + if(CMAKE_COMPILER_IS_GNUCXX) + set_property(TARGET ${name} APPEND_STRING PROPERTY + COMPILE_FLAGS " -Wno-attributes") + endif() + + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set_property(TARGET ${name} APPEND_STRING PROPERTY + COMPILE_FLAGS " -Wno-ignored-attributes") + endif() + + if(WIN32 AND CMAKE_COMPILER_IS_GNUCC) + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,--enable-stdcall-fixup") + endif() + + if(CYGWIN) + set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS "WIN32") + set_property(TARGET ${name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--kill-at") + elseif(UNIX AND NOT WIN32 AND NOT APPLE) + set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS "LINUX") + endif() + + if(MINGW) + # Work around missing #include in /amx/amx.h. + set_property(TARGET ${name} APPEND_STRING PROPERTY COMPILE_FLAGS " -include stddef.h") + endif() +endfunction() diff --git a/lib/cmake-modules/AddSAMPPluginTest.cmake b/lib/cmake-modules/AddSAMPPluginTest.cmake new file mode 100644 index 0000000..763f1df --- /dev/null +++ b/lib/cmake-modules/AddSAMPPluginTest.cmake @@ -0,0 +1,46 @@ +# AddSAMPPluginTest - add tests for SA-MP plugins. +# +# This module reuires the samp-server-cli script to be present in PATH in +# order to be able to run the tests. The script can be downloaded here: +# +# https://github.com/Zeex/samp-server-cli +# +# Additionally the SAMP_SERVER_ROOT environment variable must be defined and +# must point to the SA-MP server's root directory. + +include(CMakeParseArguments) + +function(add_samp_plugin_test) + set(name "${ARGV0}") + + set(options TARGET OUTPUT_FILE SCRIPT TIMEOUT CONFIG WORKING_DIRECTORY) + cmake_parse_arguments(ARG "" "${options}" "" ${ARGN}) + + find_package(SAMPServerCLI REQUIRED) + set(command ${SAMPServerCLI_EXECUTABLE}) + + if(ARG_SCRIPT) + list(APPEND args --gamemode ${ARG_SCRIPT}) + endif() + + if(ARG_TIMEOUT) + list(APPEND args --timeout ${ARG_TIMEOUT}) + endif() + + if(ARG_WORKING_DIRECTORY) + list(APPEND args --workdir ${ARG_WORKING_DIRECTORY}) + endif() + + add_test(NAME ${name} COMMAND ${command} ${args} --output + --plugin $) + + if(ARG_SCRIPT) + get_filename_component(AMX_PATH ${ARG_SCRIPT} DIRECTORY) + set_tests_properties(${name} PROPERTIES ENVIRONMENT AMX_PATH=${AMX_PATH}) + endif() + + if(ARG_OUTPUT_FILE) + file(READ ${ARG_OUTPUT_FILE} output) + set_tests_properties(${name} PROPERTIES PASS_REGULAR_EXPRESSION ${output}) + endif() +endfunction() diff --git a/lib/cmake-modules/FindPawnCC.cmake b/lib/cmake-modules/FindPawnCC.cmake new file mode 100644 index 0000000..b9af085 --- /dev/null +++ b/lib/cmake-modules/FindPawnCC.cmake @@ -0,0 +1,16 @@ +include(FindPackageHandleStandardArgs) + +if(WIN32) + set(_PawnCC_EXECUTABLE_NAME pawncc.exe) +else() + set(_PawnCC_EXECUTABLE_NAME pawncc) +endif() + +find_file(PawnCC_EXECUTABLE ${_PawnCC_EXECUTABLE_NAME}) + +mark_as_advanced(PawnCC_EXECUTABLE) + +find_package_handle_standard_args(PawnCC + FOUND_VAR PawnCC_FOUND + REQUIRED_VARS PawnCC_EXECUTABLE +) diff --git a/lib/cmake-modules/FindSAMPGDK.cmake b/lib/cmake-modules/FindSAMPGDK.cmake new file mode 100644 index 0000000..61bd199 --- /dev/null +++ b/lib/cmake-modules/FindSAMPGDK.cmake @@ -0,0 +1,17 @@ +include(FindPackageHandleStandardArgs) + +find_package(SAMPGDK QUIET CONFIG NAMES SAMPGDK) + +set(SAMPGDK_INCLUDE_DIRS ${SAMPGDK_INCLUDE_DIR}) +set(SAMPGDK_LIBRARY_DIRS ${SAMPGDK_LIBRARY_DIR}) + +mark_as_advanced( + SAMPGDK_VERSION + SAMPGDK_INCLUDE_DIR + SAMPGDK_LIBRARY_DIR +) + +find_package_handle_standard_args(SAMPGDK + REQUIRED_VARS SAMPGDK_INCLUDE_DIRS SAMPGDK_LIBRARY_DIRS + VERSION_VAR SAMPGDK_VERSION +) diff --git a/lib/cmake-modules/FindSAMPSDK.cmake b/lib/cmake-modules/FindSAMPSDK.cmake new file mode 100644 index 0000000..c1c1d54 --- /dev/null +++ b/lib/cmake-modules/FindSAMPSDK.cmake @@ -0,0 +1,24 @@ +include(FindPackageHandleStandardArgs) + +find_path(SAMPSDK_DIR + NAMES plugin.h + plugincommon.h + HINTS ${SAMP_SDK_ROOT} + ENV SAMP_SDK_ROOT + PATH_SUFFIXES sdk SDK + DOC "Path to SA-MP plugin SDK" + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH +) + +set(SAMPSDK_INCLUDE_DIR ${SAMPSDK_DIR}) + +mark_as_advanced( + SAMPSDK_DIR + SAMPSDK_INCLUDE_DIR +) + +find_package_handle_standard_args(SAMPSDK + REQUIRED_VARS SAMPSDK_DIR + SAMPSDK_INCLUDE_DIR +) diff --git a/lib/cmake-modules/FindSAMPServer.cmake b/lib/cmake-modules/FindSAMPServer.cmake new file mode 100644 index 0000000..b514fe1 --- /dev/null +++ b/lib/cmake-modules/FindSAMPServer.cmake @@ -0,0 +1,34 @@ +include(FindPackageHandleStandardArgs) + +if(WIN32) + set(_SAMPServer_EXECUTABLE_NAME samp-server.exe) +else() + set(_SAMPServer_EXECUTABLE_NAME samp03svr) +endif() + +find_file(SAMPServer_EXECUTABLE + NAMES ${_SAMPServer_EXECUTABLE_NAME} + HINTS ENV SAMP_SERVER_ROOT +) +find_path(SAMPServer_DIR + NAMES ${_SAMPServer_EXECUTABLE_NAME} + HINTS ENV SAMP_SERVER_ROOT +) +find_path(SAMPServer_INCLUDE_DIR + NAMES a_samp.inc a_npc.inc + HINTS ${SAMPServer_DIR}/include + ${SAMPServer_DIR}/pawno/include +) + +mark_as_advanced( + SAMPServer_EXECUTABLE + SAMPServer_DIR + SAMPServer_INCLUDE_DIR +) + +find_package_handle_standard_args(SAMPServer + FOUND_VAR SAMPServer_FOUND + REQUIRED_VARS SAMPServer_EXECUTABLE + SAMPServer_DIR + SAMPServer_INCLUDE_DIR +) diff --git a/lib/cmake-modules/FindSAMPServerCLI.cmake b/lib/cmake-modules/FindSAMPServerCLI.cmake new file mode 100644 index 0000000..313792a --- /dev/null +++ b/lib/cmake-modules/FindSAMPServerCLI.cmake @@ -0,0 +1,28 @@ +include(FindPackageHandleStandardArgs) + +if(WIN32) + set(_SAMPServerCLI_EXECUTABLE_NAME samp-server-cli.bat + samp-server-cli.exe) +else() + set(_SAMPServerCLI_EXECUTABLE_NAME samp-server-cli) +endif() + +find_file(SAMPServerCLI_EXECUTABLE + NAMES ${_SAMPServerCLI_EXECUTABLE_NAME} + HINTS ENV SAMP_SERVER_ROOT +) +find_path(SAMPServerCLI_DIR + NAMES ${_SAMPServerCLI_EXECUTABLE_NAME} + HINTS ENV SAMP_SERVER_ROOT +) + +mark_as_advanced( + SAMPServerCLI_EXECUTABLE + SAMPServerCLI_DIR +) + +find_package_handle_standard_args(SAMPServerCLI + FOUND_VAR SAMPServerCLI_FOUND + REQUIRED_VARS SAMPServerCLI_EXECUTABLE + SAMPServerCLI_DIR +) diff --git a/lib/cmake-modules/LICENSE.txt b/lib/cmake-modules/LICENSE.txt new file mode 100644 index 0000000..918ef1d --- /dev/null +++ b/lib/cmake-modules/LICENSE.txt @@ -0,0 +1,14 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2014-2015 Zeex + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. + diff --git a/lib/cmake-modules/README.md b/lib/cmake-modules/README.md new file mode 100644 index 0000000..6c1e2ad --- /dev/null +++ b/lib/cmake-modules/README.md @@ -0,0 +1,14 @@ +Name | Description +:--------------------------------------------|:-------------------------------------------------------- +[AddSAMPPlugin](AddSAMPPlugin.cmake) | Provides `add_samp_plugin()` function +[AddSAMPPluginTest](AddSAMPPluginTest.cmake) | Provides `add_samp_plugin_test()` function +[AMXConfig](AMXConfig.cmake) | Defines platform-specific macros expected by AMX headers +[FindPawnCC](FindPawnCC.cmake) | Finds Pawn compiler executable +[FindSAMPSDK](FindSAMPSDK.cmake) | Finds SA-MP plugin SDK +[FindSAMPGDK](FindSAMPGDK.cmake) | Finds [GDK][sampgdk] library and headers +[FindSAMPServer](FindSAMPServer.cmake) | Finds SA-MP server executable +[FindSAMPServerCLI](FindSAMPServerCLI.cmake) | Finds [samp-server-cli][samp-server-cli] +------------------------------------------------------------------------------------------------------- + +[sampgdk]: https://github.com/Zeex/sampgdk +[samp-server-cli]: https://github.com/Zeex/samp-server-cli diff --git a/lib/samp-plugin-sdk b/lib/samp-plugin-sdk deleted file mode 160000 index a5ce36a..0000000 --- a/lib/samp-plugin-sdk +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a5ce36a9b6ebbea6ad36705603f653bf3d4f41c5 diff --git a/lib/samp-plugin-sdk/amx/amx.h b/lib/samp-plugin-sdk/amx/amx.h new file mode 100644 index 0000000..1856be5 --- /dev/null +++ b/lib/samp-plugin-sdk/amx/amx.h @@ -0,0 +1,441 @@ +/* Pawn Abstract Machine (for the Pawn language) + * + * Copyright (c) ITB CompuPhase, 1997-2005 + * + * This software is provided "as-is", without any express or implied warranty. + * In no event will the authors be held liable for any damages arising from + * the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software in + * a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + * + * Version: $Id: amx.h,v 1.5 2006/03/26 16:56:15 spookie Exp $ + */ + +#if defined FREEBSD && !defined __FreeBSD__ + #define __FreeBSD__ +#endif +#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #include "sclinux.h" +#endif + +#ifndef AMX_H_INCLUDED +#define AMX_H_INCLUDED + +#if defined HAVE_STDINT_H + #include +#else + #if defined __LCC__ || defined __DMC__ || defined LINUX + #if defined HAVE_INTTYPES_H + #include + #else + #include + #endif + #elif !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L + /* The ISO C99 defines the int16_t and int_32t types. If the compiler got + * here, these types are probably undefined. + */ + #if defined __MACH__ + #include + typedef unsigned short int uint16_t; + typedef unsigned long int uint32_t; + #elif defined __FreeBSD__ + #include + #else + typedef short int int16_t; + typedef unsigned short int uint16_t; + #if defined SN_TARGET_PS2 + typedef int int32_t; + typedef unsigned int uint32_t; + #else + typedef long int int32_t; + typedef unsigned long int uint32_t; + #endif + #if defined __WIN32__ || defined _WIN32 || defined WIN32 + typedef __int64 int64_t; + typedef unsigned __int64 uint64_t; + #define HAVE_I64 + #elif defined __GNUC__ + typedef long long int64_t; + typedef unsigned long long uint64_t; + #define HAVE_I64 + #endif + #endif + #endif + #define HAVE_STDINT_H +#endif +#if defined _LP64 || defined WIN64 || defined _WIN64 + #if !defined __64BIT__ + #define __64BIT__ + #endif +#endif + +#if HAVE_ALLOCA_H + #include +#elif HAVE_MALLOC_H //alloca could be also defined here + #include +#endif +#if defined __WIN32__ || defined _WIN32 || defined WIN32 /* || defined __MSDOS__ */ + #if !defined alloca + #define alloca(n) _alloca(n) + #endif +#endif + +#if !defined arraysize + #define arraysize(array) (sizeof(array) / sizeof((array)[0])) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined PAWN_DLL + #if !defined AMX_NATIVE_CALL + #define AMX_NATIVE_CALL __stdcall + #endif + #if !defined AMXAPI + #define AMXAPI __stdcall + #endif +#endif + +/* calling convention for native functions */ +#if !defined AMX_NATIVE_CALL + #define AMX_NATIVE_CALL +#endif +/* calling convention for all interface functions and callback functions */ +#if !defined AMXAPI + #if defined STDECL + #define AMXAPI __stdcall + #elif defined CDECL + #define AMXAPI __cdecl + #elif defined GCC_HASCLASSVISIBILITY + #define AMXAPI __attribute__ ((visibility("default"))) + #else + #define AMXAPI + #endif +#endif +#if !defined AMXEXPORT + #define AMXEXPORT +#endif + +/* File format version Required AMX version + * 0 (original version) 0 + * 1 (opcodes JUMP.pri, SWITCH and CASETBL) 1 + * 2 (compressed files) 2 + * 3 (public variables) 2 + * 4 (opcodes SWAP.pri/alt and PUSHADDR) 4 + * 5 (tagnames table) 4 + * 6 (reformatted header) 6 + * 7 (name table, opcodes SYMTAG & SYSREQ.D) 7 + * 8 (opcode STMT, renewed debug interface) 8 + */ +#define CUR_FILE_VERSION 8 /* current file version; also the current AMX version */ +#define MIN_FILE_VERSION 6 /* lowest supported file format version for the current AMX version */ +#define MIN_AMX_VERSION 8 /* minimum AMX version needed to support the current file format */ + +#if !defined PAWN_CELL_SIZE + #define PAWN_CELL_SIZE 32 /* by default, use 32-bit cells */ +#endif +#if PAWN_CELL_SIZE==16 + typedef uint16_t ucell; + typedef int16_t cell; +#elif PAWN_CELL_SIZE==32 + typedef uint32_t ucell; + typedef int32_t cell; +#elif PAWN_CELL_SIZE==64 + typedef uint64_t ucell; + typedef int64_t cell; +#else + #error Unsupported cell size (PAWN_CELL_SIZE) +#endif + +#define UNPACKEDMAX ((1L << (sizeof(cell)-1)*8) - 1) +#define UNLIMITED (~1u >> 1) + +struct tagAMX; +typedef cell (AMX_NATIVE_CALL *AMX_NATIVE)(struct tagAMX *amx, cell *params); +typedef int (AMXAPI *AMX_CALLBACK)(struct tagAMX *amx, cell index, + cell *result, cell *params); +typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx); +#if !defined _FAR + #define _FAR +#endif + +#if defined _MSC_VER + #pragma warning(disable:4103) /* disable warning message 4103 that complains + * about pragma pack in a header file */ + #pragma warning(disable:4100) /* "'%$S' : unreferenced formal parameter" */ +#endif + +/* Some compilers do not support the #pragma align, which should be fine. Some + * compilers give a warning on unknown #pragmas, which is not so fine... + */ +#if (defined SN_TARGET_PS2 || defined __GNUC__) && !defined AMX_NO_ALIGN + #define AMX_NO_ALIGN +#endif + +#if defined __GNUC__ + #define PACKED __attribute__((packed)) +#else + #define PACKED +#endif + +#if !defined AMX_NO_ALIGN + #if defined LINUX || defined __FreeBSD__ + #pragma pack(1) /* structures must be packed (byte-aligned) */ + #elif defined MACOS && defined __MWERKS__ + #pragma options align=mac68k + #else + #pragma pack(push) + #pragma pack(1) /* structures must be packed (byte-aligned) */ + #if defined __TURBOC__ + #pragma option -a- /* "pack" pragma for older Borland compilers */ + #endif + #endif +#endif + +typedef struct tagAMX_NATIVE_INFO { + const char _FAR *name PACKED; + AMX_NATIVE func PACKED; +} PACKED AMX_NATIVE_INFO; + +#define AMX_USERNUM 4 +#define sEXPMAX 19 /* maximum name length for file version <= 6 */ +#define sNAMEMAX 31 /* maximum name length of symbol name */ + +typedef struct tagAMX_FUNCSTUB { + ucell address PACKED; + char name[sEXPMAX+1] PACKED; +} PACKED AMX_FUNCSTUB; + +typedef struct tagFUNCSTUBNT { + ucell address PACKED; + uint32_t nameofs PACKED; +} PACKED AMX_FUNCSTUBNT; + +/* The AMX structure is the internal structure for many functions. Not all + * fields are valid at all times; many fields are cached in local variables. + */ +typedef struct tagAMX { + unsigned char _FAR *base PACKED; /* points to the AMX header plus the code, optionally also the data */ + unsigned char _FAR *data PACKED; /* points to separate data+stack+heap, may be NULL */ + AMX_CALLBACK callback PACKED; + AMX_DEBUG debug PACKED; /* debug callback */ + /* for external functions a few registers must be accessible from the outside */ + cell cip PACKED; /* instruction pointer: relative to base + amxhdr->cod */ + cell frm PACKED; /* stack frame base: relative to base + amxhdr->dat */ + cell hea PACKED; /* top of the heap: relative to base + amxhdr->dat */ + cell hlw PACKED; /* bottom of the heap: relative to base + amxhdr->dat */ + cell stk PACKED; /* stack pointer: relative to base + amxhdr->dat */ + cell stp PACKED; /* top of the stack: relative to base + amxhdr->dat */ + int flags PACKED; /* current status, see amx_Flags() */ + /* user data */ + long usertags[AMX_USERNUM] PACKED; + void _FAR *userdata[AMX_USERNUM] PACKED; + /* native functions can raise an error */ + int error PACKED; + /* passing parameters requires a "count" field */ + int paramcount; + /* the sleep opcode needs to store the full AMX status */ + cell pri PACKED; + cell alt PACKED; + cell reset_stk PACKED; + cell reset_hea PACKED; + cell sysreq_d PACKED; /* relocated address/value for the SYSREQ.D opcode */ + #if defined JIT + /* support variables for the JIT */ + int reloc_size PACKED; /* required temporary buffer for relocations */ + long code_size PACKED; /* estimated memory footprint of the native code */ + #endif +} PACKED AMX; + +/* The AMX_HEADER structure is both the memory format as the file format. The + * structure is used internaly. + */ +typedef struct tagAMX_HEADER { + int32_t size PACKED; /* size of the "file" */ + uint16_t magic PACKED; /* signature */ + char file_version PACKED; /* file format version */ + char amx_version PACKED; /* required version of the AMX */ + int16_t flags PACKED; + int16_t defsize PACKED; /* size of a definition record */ + int32_t cod PACKED; /* initial value of COD - code block */ + int32_t dat PACKED; /* initial value of DAT - data block */ + int32_t hea PACKED; /* initial value of HEA - start of the heap */ + int32_t stp PACKED; /* initial value of STP - stack top */ + int32_t cip PACKED; /* initial value of CIP - the instruction pointer */ + int32_t publics PACKED; /* offset to the "public functions" table */ + int32_t natives PACKED; /* offset to the "native functions" table */ + int32_t libraries PACKED; /* offset to the table of libraries */ + int32_t pubvars PACKED; /* the "public variables" table */ + int32_t tags PACKED; /* the "public tagnames" table */ + int32_t nametable PACKED; /* name table */ +} PACKED AMX_HEADER; + +#if PAWN_CELL_SIZE==16 + #define AMX_MAGIC 0xf1e2 +#elif PAWN_CELL_SIZE==32 + #define AMX_MAGIC 0xf1e0 +#elif PAWN_CELL_SIZE==64 + #define AMX_MAGIC 0xf1e1 +#endif + +enum { + AMX_ERR_NONE, + /* reserve the first 15 error codes for exit codes of the abstract machine */ + AMX_ERR_EXIT, /* forced exit */ + AMX_ERR_ASSERT, /* assertion failed */ + AMX_ERR_STACKERR, /* stack/heap collision */ + AMX_ERR_BOUNDS, /* index out of bounds */ + AMX_ERR_MEMACCESS, /* invalid memory access */ + AMX_ERR_INVINSTR, /* invalid instruction */ + AMX_ERR_STACKLOW, /* stack underflow */ + AMX_ERR_HEAPLOW, /* heap underflow */ + AMX_ERR_CALLBACK, /* no callback, or invalid callback */ + AMX_ERR_NATIVE, /* native function failed */ + AMX_ERR_DIVIDE, /* divide by zero */ + AMX_ERR_SLEEP, /* go into sleepmode - code can be restarted */ + AMX_ERR_INVSTATE, /* invalid state for this access */ + + AMX_ERR_MEMORY = 16, /* out of memory */ + AMX_ERR_FORMAT, /* invalid file format */ + AMX_ERR_VERSION, /* file is for a newer version of the AMX */ + AMX_ERR_NOTFOUND, /* function not found */ + AMX_ERR_INDEX, /* invalid index parameter (bad entry point) */ + AMX_ERR_DEBUG, /* debugger cannot run */ + AMX_ERR_INIT, /* AMX not initialized (or doubly initialized) */ + AMX_ERR_USERDATA, /* unable to set user data field (table full) */ + AMX_ERR_INIT_JIT, /* cannot initialize the JIT */ + AMX_ERR_PARAMS, /* parameter error */ + AMX_ERR_DOMAIN, /* domain error, expression result does not fit in range */ + AMX_ERR_GENERAL, /* general error (unknown or unspecific error) */ +}; + +/* AMX_FLAG_CHAR16 0x01 no longer used */ +#define AMX_FLAG_DEBUG 0x02 /* symbolic info. available */ +#define AMX_FLAG_COMPACT 0x04 /* compact encoding */ +#define AMX_FLAG_BYTEOPC 0x08 /* opcode is a byte (not a cell) */ +#define AMX_FLAG_NOCHECKS 0x10 /* no array bounds checking; no STMT opcode */ +#define AMX_FLAG_NTVREG 0x1000 /* all native functions are registered */ +#define AMX_FLAG_JITC 0x2000 /* abstract machine is JIT compiled */ +#define AMX_FLAG_BROWSE 0x4000 /* busy browsing */ +#define AMX_FLAG_RELOC 0x8000 /* jump/call addresses relocated */ + +#define AMX_EXEC_MAIN -1 /* start at program entry point */ +#define AMX_EXEC_CONT -2 /* continue from last address */ + +#define AMX_USERTAG(a,b,c,d) ((a) | ((b)<<8) | ((long)(c)<<16) | ((long)(d)<<24)) + +#if !defined AMX_COMPACTMARGIN + #define AMX_COMPACTMARGIN 64 +#endif + +/* for native functions that use floating point parameters, the following + * two macros are convenient for casting a "cell" into a "float" type _without_ + * changing the bit pattern + */ +#if PAWN_CELL_SIZE==32 + #define amx_ftoc(f) ( * ((cell*)&f) ) /* float to cell */ + #define amx_ctof(c) ( * ((float*)&c) ) /* cell to float */ +#elif PAWN_CELL_SIZE==64 + #define amx_ftoc(f) ( * ((cell*)&f) ) /* float to cell */ + #define amx_ctof(c) ( * ((double*)&c) ) /* cell to float */ +#else + #error Unsupported cell size +#endif + +#define amx_StrParam(amx,param,result) \ + do { \ + cell *amx_cstr_; int amx_length_; \ + amx_GetAddr((amx), (param), &amx_cstr_); \ + amx_StrLen(amx_cstr_, &amx_length_); \ + if (amx_length_ > 0 && \ + ((result) = (char*)alloca((amx_length_ + 1) * sizeof(*(result)))) != NULL) \ + amx_GetString((char*)(result), amx_cstr_, sizeof(*(result))>1, amx_length_ + 1); \ + else (result) = NULL; \ + } while (0) + +uint16_t * AMXAPI amx_Align16(uint16_t *v); +uint32_t * AMXAPI amx_Align32(uint32_t *v); +#if defined _I64_MAX || defined HAVE_I64 + uint64_t * AMXAPI amx_Align64(uint64_t *v); +#endif +int AMXAPI amx_Allot(AMX *amx, int cells, cell *amx_addr, cell **phys_addr); +int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params); +int AMXAPI amx_Cleanup(AMX *amx); +int AMXAPI amx_Clone(AMX *amxClone, AMX *amxSource, void *data); +int AMXAPI amx_Exec(AMX *amx, cell *retval, int index); +int AMXAPI amx_FindNative(AMX *amx, const char *name, int *index); +int AMXAPI amx_FindPublic(AMX *amx, const char *funcname, int *index); +int AMXAPI amx_FindPubVar(AMX *amx, const char *varname, cell *amx_addr); +int AMXAPI amx_FindTagId(AMX *amx, cell tag_id, char *tagname); +int AMXAPI amx_Flags(AMX *amx,uint16_t *flags); +int AMXAPI amx_GetAddr(AMX *amx,cell amx_addr,cell **phys_addr); +int AMXAPI amx_GetNative(AMX *amx, int index, char *funcname); +int AMXAPI amx_GetPublic(AMX *amx, int index, char *funcname); +int AMXAPI amx_GetPubVar(AMX *amx, int index, char *varname, cell *amx_addr); +int AMXAPI amx_GetString(char *dest,const cell *source, int use_wchar, size_t size); +int AMXAPI amx_GetTag(AMX *amx, int index, char *tagname, cell *tag_id); +int AMXAPI amx_GetUserData(AMX *amx, long tag, void **ptr); +int AMXAPI amx_Init(AMX *amx, void *program); +int AMXAPI amx_InitJIT(AMX *amx, void *reloc_table, void *native_code); +int AMXAPI amx_MemInfo(AMX *amx, long *codesize, long *datasize, long *stackheap); +int AMXAPI amx_NameLength(AMX *amx, int *length); +AMX_NATIVE_INFO * AMXAPI amx_NativeInfo(const char *name, AMX_NATIVE func); +int AMXAPI amx_NumNatives(AMX *amx, int *number); +int AMXAPI amx_NumPublics(AMX *amx, int *number); +int AMXAPI amx_NumPubVars(AMX *amx, int *number); +int AMXAPI amx_NumTags(AMX *amx, int *number); +int AMXAPI amx_Push(AMX *amx, cell value); +int AMXAPI amx_PushArray(AMX *amx, cell *amx_addr, cell **phys_addr, const cell array[], int numcells); +int AMXAPI amx_PushString(AMX *amx, cell *amx_addr, cell **phys_addr, const char *string, int pack, int use_wchar); +int AMXAPI amx_RaiseError(AMX *amx, int error); +int AMXAPI amx_Register(AMX *amx, const AMX_NATIVE_INFO *nativelist, int number); +int AMXAPI amx_Release(AMX *amx, cell amx_addr); +int AMXAPI amx_SetCallback(AMX *amx, AMX_CALLBACK callback); +int AMXAPI amx_SetDebugHook(AMX *amx, AMX_DEBUG debug); +int AMXAPI amx_SetString(cell *dest, const char *source, int pack, int use_wchar, size_t size); +int AMXAPI amx_SetUserData(AMX *amx, long tag, void *ptr); +int AMXAPI amx_StrLen(const cell *cstring, int *length); +int AMXAPI amx_UTF8Check(const char *string, int *length); +int AMXAPI amx_UTF8Get(const char *string, const char **endptr, cell *value); +int AMXAPI amx_UTF8Len(const cell *cstr, int *length); +int AMXAPI amx_UTF8Put(char *string, char **endptr, int maxchars, cell value); + +#if PAWN_CELL_SIZE==16 + #define amx_AlignCell(v) amx_Align16(v) +#elif PAWN_CELL_SIZE==32 + #define amx_AlignCell(v) amx_Align32(v) +#elif PAWN_CELL_SIZE==64 && (defined _I64_MAX || defined HAVE_I64) + #define amx_AlignCell(v) amx_Align64(v) +#else + #error Unsupported cell size +#endif + +#define amx_RegisterFunc(amx, name, func) \ + amx_Register((amx), amx_NativeInfo((name),(func)), 1); + +#if !defined AMX_NO_ALIGN + #if defined LINUX || defined __FreeBSD__ + #pragma pack() /* reset default packing */ + #elif defined MACOS && defined __MWERKS__ + #pragma options align=reset + #else + #pragma pack(pop) /* reset previous packing */ + #endif +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* AMX_H_INCLUDED */ diff --git a/lib/samp-plugin-sdk/amx/amx2.h b/lib/samp-plugin-sdk/amx/amx2.h new file mode 100644 index 0000000..878275e --- /dev/null +++ b/lib/samp-plugin-sdk/amx/amx2.h @@ -0,0 +1,49 @@ +//---------------------------------------------------------- +// +// SA-MP Multiplayer Modification For GTA:SA +// Copyright 2014 SA-MP Team, Dan, maddinat0r +// +//---------------------------------------------------------- + +#pragma once + +//---------------------------------------------------------- + +#if defined __cplusplus +#include +#endif + +//---------------------------------------------------------- + +#include "amx.h" + +//---------------------------------------------------------- + +#define USENAMETABLE(hdr) \ + ((hdr)->defsize==sizeof(AMX_FUNCSTUBNT)) + +#define NUMENTRIES(hdr,field,nextfield) \ + (unsigned)(((hdr)->nextfield - (hdr)->field) / (hdr)->defsize) + +#define GETENTRY(hdr,table,index) \ + (AMX_FUNCSTUB *)((unsigned char*)(hdr) + (unsigned)(hdr)->table + (unsigned)index*(hdr)->defsize) + +#define GETENTRYNAME(hdr,entry) \ + (USENAMETABLE(hdr) ? \ + (char *)((unsigned char*)(hdr) + (unsigned)((AMX_FUNCSTUBNT*)(entry))->nameofs) : \ + ((AMX_FUNCSTUB*)(entry))->name) + +//---------------------------------------------------------- + +extern int AMXAPI amx_PushAddress(AMX *amx, cell *address); +extern void AMXAPI amx_Redirect(AMX *amx, char *from, ucell to, AMX_NATIVE *store); +extern int AMXAPI amx_GetCString(AMX *amx, cell param, char *&dest); +extern int AMXAPI amx_SetCString(AMX *amx, cell param, const char *str, int len); + +#if defined __cplusplus +extern std::string AMXAPI amx_GetCppString(AMX *amx, cell param); +extern int AMXAPI amx_SetCppString(AMX *amx, cell param, const std::string &str, size_t maxlen); +#endif + +//---------------------------------------------------------- +// EOF diff --git a/lib/samp-plugin-sdk/amx/getch.c b/lib/samp-plugin-sdk/amx/getch.c new file mode 100644 index 0000000..3221ae8 --- /dev/null +++ b/lib/samp-plugin-sdk/amx/getch.c @@ -0,0 +1,80 @@ +/* Extremely inefficient but portable POSIX getch() */ +#ifndef WIN32 + +#include +#include +#include /* for tcgetattr() and tcsetattr() */ +#include /* for read() */ +#include +#include +#include +#include "getch.h" + +#ifndef STDIN_FILENO +# define STDIN_FILENO 0 +#endif + +int +getch (void) +{ + struct termios save_termios; + struct termios ios; + int c = 0; + + if (!isatty (STDIN_FILENO)) + return EOF; + + if (tcgetattr (STDIN_FILENO, &save_termios) < 0) + return EOF; + + ios = save_termios; + ios.c_lflag &= ~(ICANON | ECHO | ISIG); + ios.c_cc[VMIN] = 1; /* read() will return with one char */ + ios.c_cc[VTIME] = 0; /* read() blocks forever */ + + if (tcsetattr (STDIN_FILENO, TCSANOW, &ios) < 0) + return EOF; + + if (read (STDIN_FILENO, &c, 1) != 1) + c = EOF; + + tcsetattr (STDIN_FILENO, TCSANOW, &save_termios); + + return c; +} + +int +kbhit (void) +{ + struct termios save_termios; + struct termios ios; + fd_set inp; + struct timeval timeout = {0, 0}; + int result; + + if (!isatty (STDIN_FILENO)) + return 0; + + if (tcgetattr (STDIN_FILENO, &save_termios) < 0) + return 0; + + ios = save_termios; + ios.c_lflag &= ~(ICANON | ECHO | ISIG); + ios.c_cc[VMIN] = 1; /* read() will return with one char */ + ios.c_cc[VTIME] = 0; /* read() blocks forever */ + + if (tcsetattr (STDIN_FILENO, TCSANOW, &ios) < 0) + return 0; + + /* set up select() args */ + FD_ZERO(&inp); + FD_SET(STDIN_FILENO, &inp); + + result = select (STDIN_FILENO+1, &inp, NULL, NULL, &timeout) == 1; + + tcsetattr (STDIN_FILENO, TCSANOW, &save_termios); + + return result; +} + +#endif diff --git a/lib/samp-plugin-sdk/amx/getch.h b/lib/samp-plugin-sdk/amx/getch.h new file mode 100644 index 0000000..71cdd83 --- /dev/null +++ b/lib/samp-plugin-sdk/amx/getch.h @@ -0,0 +1,15 @@ +/* Extremely inefficient but portable POSIX getch(), see getch.c */ +#ifndef GETCH_H +#define GETCH_H + +#if defined __cplusplus + extern "C" { +#endif +int getch(void); +int kbhit(void); + +#if defined __cplusplus +} +#endif + +#endif /* GETCH_H */ diff --git a/lib/samp-plugin-sdk/amx/sclinux.h b/lib/samp-plugin-sdk/amx/sclinux.h new file mode 100644 index 0000000..f04e9b7 --- /dev/null +++ b/lib/samp-plugin-sdk/amx/sclinux.h @@ -0,0 +1,51 @@ +/* + * Things needed to compile under linux. + * + * Should be reworked totally to use GNU's 'configure' + */ +#ifndef SCLINUX_H +#define SCLINUX_H + +/* getchar() is not a 'cool' replacement for MSDOS getch: Linux/unix depends on the features activated or not about the + * controlling terminal's tty. This means that ioctl(2) calls must be performed, for instance to have the controlling + * terminal tty's in 'raw' mode, if we want to be able to fetch a single character. This also means that everything must + * be put back correctly when the function ends. See GETCH.C for an implementation. + * + * For interactive use of SRUN/SDBG if would be much better to use GNU's readline package: the user would be able to + * have a complete emacs/vi like line editing system. + */ +#include "getch.h" + +#define stricmp(a,b) strcasecmp(a,b) +#define strnicmp(a,b,c) strncasecmp(a,b,c) + +/* + * WinWorld wants '\'. Unices do not. + */ +#define DIRECTORY_SEP_CHAR '/' +#define DIRECTORY_SEP_STR "/" + +/* + * SC assumes that a computer is Little Endian unless told otherwise. It uses + * (and defines) the macros BYTE_ORDER and BIG_ENDIAN. + * For Linux, we must overrule these settings with those defined in glibc. + */ +#if !defined __BYTE_ORDER +# include +#endif + +#if defined __APPLE__ +# include +#endif + +#if defined __OpenBSD__ || defined __FreeBSD__ || defined __APPLE__ +# define __BYTE_ORDER BYTE_ORDER +# define __LITTLE_ENDIAN LITTLE_ENDIAN +# define __BIG_ENDIAN BIG_ENDIAN +#endif + +#if !defined __BYTE_ORDER +# error "Can't figure computer byte order (__BYTE_ORDER macro not found)" +#endif + +#endif /* SCLINUX_H */ diff --git a/lib/samp-plugin-sdk/amxplugin.cpp b/lib/samp-plugin-sdk/amxplugin.cpp new file mode 100644 index 0000000..6a5ed20 --- /dev/null +++ b/lib/samp-plugin-sdk/amxplugin.cpp @@ -0,0 +1,630 @@ +//---------------------------------------------------------- +// +// SA-MP Multiplayer Modification For GTA:SA +// Copyright 2004-2009 SA-MP Team +// +//---------------------------------------------------------- +// +// This provides an interface to call amx library functions +// within samp-server. +// +// To use: +// Define the extern in your main source file: +// extern void *pAMXFunctions; +// And, in your Initialize function, assign: +// pAMXFunctions = data[PLUGIN_DATA_AMX]; +// +// +// WIN32: To regenerate thunks for calls from prototypes in amx.h +// Run a regex with: +// S: ^(.*)(AMXAPI amx_)([^(]*)([^\;]*);$ +// R: NUDE \1\2\3\4\n{\n\t_asm mov eax, pAMXFunctions;\n\t_asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_\3*4];\n}\n +// +// LINUX/BSD: To regenerate thunks for calls from prototypes in amx.h +// Run a regex with: +// S: ^(.*)(AMXAPI amx_)([^(]*)([^\;]*);$ +// R: typedef \1 AMXAPI (*amx_\3_t)\4;\n\1\2\3\4\n{\n\tamx_\3_t fn = ((amx_\3_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_\3];\n\treturn fn\4;\n}\n +// Modify internal function calls as nessesary +// + +//---------------------------------------------------------- + +#include "amx/amx.h" +#include "plugincommon.h" + +//---------------------------------------------------------- + +void *pAMXFunctions; + +//---------------------------------------------------------- + +#if (defined(WIN32) || defined(_WIN32)) && defined(_MSC_VER) + +// Optimized Inline Assembly Thunks for MS VC++ + +#define NUDE _declspec(naked) + +NUDE uint16_t * AMXAPI amx_Align16(uint16_t *v) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_Align16*4]; +} + +NUDE uint32_t * AMXAPI amx_Align32(uint32_t *v) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_Align32*4]; +} + +#if defined _I64_MAX || defined HAVE_I64 +NUDE uint64_t * AMXAPI amx_Align64(uint64_t *v) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_Align64*4]; +} + +#endif +NUDE int AMXAPI amx_Allot(AMX *amx, int cells, cell *amx_addr, cell **phys_addr) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_Allot*4]; +} + +NUDE int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_Callback*4]; +} + +NUDE int AMXAPI amx_Cleanup(AMX *amx) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_Cleanup*4]; +} + +NUDE int AMXAPI amx_Clone(AMX *amxClone, AMX *amxSource, void *data) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_Clone*4]; +} + +NUDE int AMXAPI amx_Exec(AMX *amx, cell *retval, int index) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_Exec*4]; +} + +NUDE int AMXAPI amx_FindNative(AMX *amx, const char *name, int *index) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_FindNative*4]; +} + +NUDE int AMXAPI amx_FindPublic(AMX *amx, const char *funcname, int *index) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_FindPublic*4]; +} + +NUDE int AMXAPI amx_FindPubVar(AMX *amx, const char *varname, cell *amx_addr) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_FindPubVar*4]; +} + +NUDE int AMXAPI amx_FindTagId(AMX *amx, cell tag_id, char *tagname) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_FindTagId*4]; +} + +NUDE int AMXAPI amx_Flags(AMX *amx,uint16_t *flags) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_Flags*4]; +} + +NUDE int AMXAPI amx_GetAddr(AMX *amx,cell amx_addr,cell **phys_addr) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_GetAddr*4]; +} + +NUDE int AMXAPI amx_GetNative(AMX *amx, int index, char *funcname) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_GetNative*4]; +} + +NUDE int AMXAPI amx_GetPublic(AMX *amx, int index, char *funcname) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_GetPublic*4]; +} + +NUDE int AMXAPI amx_GetPubVar(AMX *amx, int index, char *varname, cell *amx_addr) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_GetPubVar*4]; +} + +NUDE int AMXAPI amx_GetString(char *dest,const cell *source, int use_wchar, size_t size) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_GetString*4]; +} + +NUDE int AMXAPI amx_GetTag(AMX *amx, int index, char *tagname, cell *tag_id) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_GetTag*4]; +} + +NUDE int AMXAPI amx_GetUserData(AMX *amx, long tag, void **ptr) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_GetUserData*4]; +} + +NUDE int AMXAPI amx_Init(AMX *amx, void *program) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_Init*4]; +} + +NUDE int AMXAPI amx_InitJIT(AMX *amx, void *reloc_table, void *native_code) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_InitJIT*4]; +} + +NUDE int AMXAPI amx_MemInfo(AMX *amx, long *codesize, long *datasize, long *stackheap) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_MemInfo*4]; +} + +NUDE int AMXAPI amx_NameLength(AMX *amx, int *length) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_NameLength*4]; +} + +NUDE AMX_NATIVE_INFO * AMXAPI amx_NativeInfo(const char *name, AMX_NATIVE func) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_NativeInfo*4]; +} + +NUDE int AMXAPI amx_NumNatives(AMX *amx, int *number) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_NumNatives*4]; +} + +NUDE int AMXAPI amx_NumPublics(AMX *amx, int *number) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_NumPublics*4]; +} + +NUDE int AMXAPI amx_NumPubVars(AMX *amx, int *number) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_NumPubVars*4]; +} + +NUDE int AMXAPI amx_NumTags(AMX *amx, int *number) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_NumTags*4]; +} + +NUDE int AMXAPI amx_Push(AMX *amx, cell value) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_Push*4]; +} + +NUDE int AMXAPI amx_PushArray(AMX *amx, cell *amx_addr, cell **phys_addr, const cell array[], int numcells) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_PushArray*4]; +} + +NUDE int AMXAPI amx_PushString(AMX *amx, cell *amx_addr, cell **phys_addr, const char *string, int pack, int use_wchar) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_PushString*4]; +} + +NUDE int AMXAPI amx_RaiseError(AMX *amx, int error) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_RaiseError*4]; +} + +NUDE int AMXAPI amx_Register(AMX *amx, const AMX_NATIVE_INFO *nativelist, int number) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_Register*4]; +} + +NUDE int AMXAPI amx_Release(AMX *amx, cell amx_addr) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_Release*4]; +} + +NUDE int AMXAPI amx_SetCallback(AMX *amx, AMX_CALLBACK callback) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_SetCallback*4]; +} + +NUDE int AMXAPI amx_SetDebugHook(AMX *amx, AMX_DEBUG debug) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_SetDebugHook*4]; +} + +NUDE int AMXAPI amx_SetString(cell *dest, const char *source, int pack, int use_wchar, size_t size) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_SetString*4]; +} + +NUDE int AMXAPI amx_SetUserData(AMX *amx, long tag, void *ptr) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_SetUserData*4]; +} + +NUDE int AMXAPI amx_StrLen(const cell *cstring, int *length) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_StrLen*4]; +} + +NUDE int AMXAPI amx_UTF8Check(const char *string, int *length) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_UTF8Check*4]; +} + +NUDE int AMXAPI amx_UTF8Get(const char *string, const char **endptr, cell *value) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_UTF8Get*4]; +} + +NUDE int AMXAPI amx_UTF8Len(const cell *cstr, int *length) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_UTF8Len*4]; +} + +NUDE int AMXAPI amx_UTF8Put(char *string, char **endptr, int maxchars, cell value) +{ + _asm mov eax, pAMXFunctions; + _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_UTF8Put*4]; +} + +#else + +// Unoptimized Thunks (Linux/BSD/non MSVC++) + +typedef uint16_t * AMXAPI (*amx_Align16_t)(uint16_t *v); +uint16_t * AMXAPI amx_Align16(uint16_t *v) +{ + amx_Align16_t fn = ((amx_Align16_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_Align16]; + return fn(v); +} + +typedef uint32_t * AMXAPI (*amx_Align32_t)(uint32_t *v); +uint32_t * AMXAPI amx_Align32(uint32_t *v) +{ + amx_Align32_t fn = ((amx_Align32_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_Align32]; + return fn(v); +} + +#if defined _I64_MAX || defined HAVE_I64 +typedef uint64_t * AMXAPI (*amx_Align64_t)(uint64_t *v); + uint64_t * AMXAPI amx_Align64(uint64_t *v) +{ + amx_Align64_t fn = ((amx_Align64_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_Align64]; + return fn(v); +} +#endif + +typedef int AMXAPI (*amx_Allot_t)(AMX *amx, int cells, cell *amx_addr, cell **phys_addr); +int AMXAPI amx_Allot(AMX *amx, int cells, cell *amx_addr, cell **phys_addr) +{ + amx_Allot_t fn = ((amx_Allot_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_Allot]; + return fn(amx, cells, amx_addr, phys_addr); +} + +typedef int AMXAPI (*amx_Callback_t)(AMX *amx, cell index, cell *result, cell *params); +int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params) +{ + amx_Callback_t fn = ((amx_Callback_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_Callback]; + return fn(amx, index, result, params); +} + +typedef int AMXAPI (*amx_Cleanup_t)(AMX *amx); +int AMXAPI amx_Cleanup(AMX *amx) +{ + amx_Cleanup_t fn = ((amx_Cleanup_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_Cleanup]; + return fn(amx); +} + +typedef int AMXAPI (*amx_Clone_t)(AMX *amxClone, AMX *amxSource, void *data); +int AMXAPI amx_Clone(AMX *amxClone, AMX *amxSource, void *data) +{ + amx_Clone_t fn = ((amx_Clone_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_Clone]; + return fn(amxClone, amxSource, data); +} + +typedef int AMXAPI (*amx_Exec_t)(AMX *amx, cell *retval, int index); +int AMXAPI amx_Exec(AMX *amx, cell *retval, int index) +{ + amx_Exec_t fn = ((amx_Exec_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_Exec]; + return fn(amx, retval, index); +} + +typedef int AMXAPI (*amx_FindNative_t)(AMX *amx, const char *name, int *index); +int AMXAPI amx_FindNative(AMX *amx, const char *name, int *index) +{ + amx_FindNative_t fn = ((amx_FindNative_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_FindNative]; + return fn(amx, name, index); +} + +typedef int AMXAPI (*amx_FindPublic_t)(AMX *amx, const char *funcname, int *index); +int AMXAPI amx_FindPublic(AMX *amx, const char *funcname, int *index) +{ + amx_FindPublic_t fn = ((amx_FindPublic_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_FindPublic]; + return fn(amx, funcname, index); +} + +typedef int AMXAPI (*amx_FindPubVar_t)(AMX *amx, const char *varname, cell *amx_addr); +int AMXAPI amx_FindPubVar(AMX *amx, const char *varname, cell *amx_addr) +{ + amx_FindPubVar_t fn = ((amx_FindPubVar_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_FindPubVar]; + return fn(amx, varname, amx_addr); +} + +typedef int AMXAPI (*amx_FindTagId_t)(AMX *amx, cell tag_id, char *tagname); +int AMXAPI amx_FindTagId(AMX *amx, cell tag_id, char *tagname) +{ + amx_FindTagId_t fn = ((amx_FindTagId_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_FindTagId]; + return fn(amx, tag_id, tagname); +} + +typedef int AMXAPI (*amx_Flags_t)(AMX *amx,uint16_t *flags); +int AMXAPI amx_Flags(AMX *amx,uint16_t *flags) +{ + amx_Flags_t fn = ((amx_Flags_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_Flags]; + return fn(amx,flags); +} + +typedef int AMXAPI (*amx_GetAddr_t)(AMX *amx,cell amx_addr,cell **phys_addr); +int AMXAPI amx_GetAddr(AMX *amx,cell amx_addr,cell **phys_addr) +{ + amx_GetAddr_t fn = ((amx_GetAddr_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_GetAddr]; + return fn(amx,amx_addr,phys_addr); +} + +typedef int AMXAPI (*amx_GetNative_t)(AMX *amx, int index, char *funcname); +int AMXAPI amx_GetNative(AMX *amx, int index, char *funcname) +{ + amx_GetNative_t fn = ((amx_GetNative_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_GetNative]; + return fn(amx, index, funcname); +} + +typedef int AMXAPI (*amx_GetPublic_t)(AMX *amx, int index, char *funcname); +int AMXAPI amx_GetPublic(AMX *amx, int index, char *funcname) +{ + amx_GetPublic_t fn = ((amx_GetPublic_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_GetPublic]; + return fn(amx, index, funcname); +} + +typedef int AMXAPI (*amx_GetPubVar_t)(AMX *amx, int index, char *varname, cell *amx_addr); +int AMXAPI amx_GetPubVar(AMX *amx, int index, char *varname, cell *amx_addr) +{ + amx_GetPubVar_t fn = ((amx_GetPubVar_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_GetPubVar]; + return fn(amx, index, varname, amx_addr); +} + +typedef int AMXAPI (*amx_GetString_t)(char *dest,const cell *source, int use_wchar, size_t size); +int AMXAPI amx_GetString(char *dest,const cell *source, int use_wchar, size_t size) +{ + amx_GetString_t fn = ((amx_GetString_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_GetString]; + return fn(dest,source, use_wchar, size); +} + +typedef int AMXAPI (*amx_GetTag_t)(AMX *amx, int index, char *tagname, cell *tag_id); +int AMXAPI amx_GetTag(AMX *amx, int index, char *tagname, cell *tag_id) +{ + amx_GetTag_t fn = ((amx_GetTag_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_GetTag]; + return fn(amx, index, tagname, tag_id); +} + +typedef int AMXAPI (*amx_GetUserData_t)(AMX *amx, long tag, void **ptr); +int AMXAPI amx_GetUserData(AMX *amx, long tag, void **ptr) +{ + amx_GetUserData_t fn = ((amx_GetUserData_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_GetUserData]; + return fn(amx, tag, ptr); +} + +typedef int AMXAPI (*amx_Init_t)(AMX *amx, void *program); +int AMXAPI amx_Init(AMX *amx, void *program) +{ + amx_Init_t fn = ((amx_Init_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_Init]; + return fn(amx, program); +} + +typedef int AMXAPI (*amx_InitJIT_t)(AMX *amx, void *reloc_table, void *native_code); +int AMXAPI amx_InitJIT(AMX *amx, void *reloc_table, void *native_code) +{ + amx_InitJIT_t fn = ((amx_InitJIT_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_InitJIT]; + return fn(amx, reloc_table, native_code); +} + +typedef int AMXAPI (*amx_MemInfo_t)(AMX *amx, long *codesize, long *datasize, long *stackheap); +int AMXAPI amx_MemInfo(AMX *amx, long *codesize, long *datasize, long *stackheap) +{ + amx_MemInfo_t fn = ((amx_MemInfo_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_MemInfo]; + return fn(amx, codesize, datasize, stackheap); +} + +typedef int AMXAPI (*amx_NameLength_t)(AMX *amx, int *length); +int AMXAPI amx_NameLength(AMX *amx, int *length) +{ + amx_NameLength_t fn = ((amx_NameLength_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_NameLength]; + return fn(amx, length); +} + +typedef AMX_NATIVE_INFO * AMXAPI (*amx_NativeInfo_t)(const char *name, AMX_NATIVE func); +AMX_NATIVE_INFO * AMXAPI amx_NativeInfo(const char *name, AMX_NATIVE func) +{ + amx_NativeInfo_t fn = ((amx_NativeInfo_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_NativeInfo]; + return fn(name, func); +} + +typedef int AMXAPI (*amx_NumNatives_t)(AMX *amx, int *number); +int AMXAPI amx_NumNatives(AMX *amx, int *number) +{ + amx_NumNatives_t fn = ((amx_NumNatives_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_NumNatives]; + return fn(amx, number); +} + +typedef int AMXAPI (*amx_NumPublics_t)(AMX *amx, int *number); +int AMXAPI amx_NumPublics(AMX *amx, int *number) +{ + amx_NumPublics_t fn = ((amx_NumPublics_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_NumPublics]; + return fn(amx, number); +} + +typedef int AMXAPI (*amx_NumPubVars_t)(AMX *amx, int *number); +int AMXAPI amx_NumPubVars(AMX *amx, int *number) +{ + amx_NumPubVars_t fn = ((amx_NumPubVars_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_NumPubVars]; + return fn(amx, number); +} + +typedef int AMXAPI (*amx_NumTags_t)(AMX *amx, int *number); +int AMXAPI amx_NumTags(AMX *amx, int *number) +{ + amx_NumTags_t fn = ((amx_NumTags_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_NumTags]; + return fn(amx, number); +} + +typedef int AMXAPI (*amx_Push_t)(AMX *amx, cell value); +int AMXAPI amx_Push(AMX *amx, cell value) +{ + amx_Push_t fn = ((amx_Push_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_Push]; + return fn(amx, value); +} + +typedef int AMXAPI (*amx_PushArray_t)(AMX *amx, cell *amx_addr, cell **phys_addr, const cell array[], int numcells); +int AMXAPI amx_PushArray(AMX *amx, cell *amx_addr, cell **phys_addr, const cell array[], int numcells) +{ + amx_PushArray_t fn = ((amx_PushArray_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_PushArray]; + return fn(amx, amx_addr, phys_addr, array, numcells); +} + +typedef int AMXAPI (*amx_PushString_t)(AMX *amx, cell *amx_addr, cell **phys_addr, const char *string, int pack, int use_wchar); +int AMXAPI amx_PushString(AMX *amx, cell *amx_addr, cell **phys_addr, const char *string, int pack, int use_wchar) +{ + amx_PushString_t fn = ((amx_PushString_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_PushString]; + return fn(amx, amx_addr, phys_addr, string, pack, use_wchar); +} + +typedef int AMXAPI (*amx_RaiseError_t)(AMX *amx, int error); +int AMXAPI amx_RaiseError(AMX *amx, int error) +{ + amx_RaiseError_t fn = ((amx_RaiseError_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_RaiseError]; + return fn(amx, error); +} + +typedef int AMXAPI (*amx_Register_t)(AMX *amx, const AMX_NATIVE_INFO *nativelist, int number); +int AMXAPI amx_Register(AMX *amx, const AMX_NATIVE_INFO *nativelist, int number) +{ + amx_Register_t fn = ((amx_Register_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_Register]; + return fn(amx, nativelist, number); +} + +typedef int AMXAPI (*amx_Release_t)(AMX *amx, cell amx_addr); +int AMXAPI amx_Release(AMX *amx, cell amx_addr) +{ + amx_Release_t fn = ((amx_Release_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_Release]; + return fn(amx, amx_addr); +} + +typedef int AMXAPI (*amx_SetCallback_t)(AMX *amx, AMX_CALLBACK callback); +int AMXAPI amx_SetCallback(AMX *amx, AMX_CALLBACK callback) +{ + amx_SetCallback_t fn = ((amx_SetCallback_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_SetCallback]; + return fn(amx, callback); +} + +typedef int AMXAPI (*amx_SetDebugHook_t)(AMX *amx, AMX_DEBUG debug); +int AMXAPI amx_SetDebugHook(AMX *amx, AMX_DEBUG debug) +{ + amx_SetDebugHook_t fn = ((amx_SetDebugHook_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_SetDebugHook]; + return fn(amx, debug); +} + +typedef int AMXAPI (*amx_SetString_t)(cell *dest, const char *source, int pack, int use_wchar, size_t size); +int AMXAPI amx_SetString(cell *dest, const char *source, int pack, int use_wchar, size_t size) +{ + amx_SetString_t fn = ((amx_SetString_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_SetString]; + return fn(dest, source, pack, use_wchar, size); +} + +typedef int AMXAPI (*amx_SetUserData_t)(AMX *amx, long tag, void *ptr); +int AMXAPI amx_SetUserData(AMX *amx, long tag, void *ptr) +{ + amx_SetUserData_t fn = ((amx_SetUserData_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_SetUserData]; + return fn(amx, tag, ptr); +} + +typedef int AMXAPI (*amx_StrLen_t)(const cell *cstring, int *length); +int AMXAPI amx_StrLen(const cell *cstring, int *length) +{ + amx_StrLen_t fn = ((amx_StrLen_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_StrLen]; + return fn(cstring, length); +} + +typedef int AMXAPI (*amx_UTF8Check_t)(const char *string, int *length); +int AMXAPI amx_UTF8Check(const char *string, int *length) +{ + amx_UTF8Check_t fn = ((amx_UTF8Check_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_UTF8Check]; + return fn(string, length); +} + +typedef int AMXAPI (*amx_UTF8Get_t)(const char *string, const char **endptr, cell *value); +int AMXAPI amx_UTF8Get(const char *string, const char **endptr, cell *value) +{ + amx_UTF8Get_t fn = ((amx_UTF8Get_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_UTF8Get]; + return fn(string, endptr, value); +} + +typedef int AMXAPI (*amx_UTF8Len_t)(const cell *cstr, int *length); +int AMXAPI amx_UTF8Len(const cell *cstr, int *length) +{ + amx_UTF8Len_t fn = ((amx_UTF8Len_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_UTF8Len]; + return fn(cstr, length); +} + +typedef int AMXAPI (*amx_UTF8Put_t)(char *string, char **endptr, int maxchars, cell value); +int AMXAPI amx_UTF8Put(char *string, char **endptr, int maxchars, cell value) +{ + amx_UTF8Put_t fn = ((amx_UTF8Put_t*)pAMXFunctions)[PLUGIN_AMX_EXPORT_UTF8Put]; + return fn(string, endptr, maxchars, value); +} + +#endif + +//---------------------------------------------------------- +// EOF diff --git a/lib/samp-plugin-sdk/amxplugin2.cpp b/lib/samp-plugin-sdk/amxplugin2.cpp new file mode 100644 index 0000000..db68ee6 --- /dev/null +++ b/lib/samp-plugin-sdk/amxplugin2.cpp @@ -0,0 +1,114 @@ +//---------------------------------------------------------- +// +// SA-MP Multiplayer Modification For GTA:SA +// Copyright 2014 SA-MP Team, Dan, maddinat0r +// +//---------------------------------------------------------- + +#include +#include + +//---------------------------------------------------------- + +#include + +//---------------------------------------------------------- + +#include "amx/amx2.h" + +//---------------------------------------------------------- + +int AMXAPI amx_PushAddress(AMX *amx, cell *address) +{ + AMX_HEADER *hdr; + unsigned char *data; + cell xaddr; + /* reverse relocate the address */ + assert(amx != NULL); + hdr = (AMX_HEADER *) amx->base; + assert(hdr != NULL); + assert(hdr->magic == AMX_MAGIC); + data = (amx->data != NULL) ? amx->data : amx->base + (int) hdr->dat; + xaddr = (cell) ((unsigned char*) address-data); + if ((ucell) xaddr >= (ucell) amx->stp) + { + return AMX_ERR_MEMACCESS; + } + return amx_Push(amx,xaddr); +} + +void AMXAPI amx_Redirect(AMX *amx, char *from, ucell to, AMX_NATIVE *store) +{ + AMX_HEADER *hdr = (AMX_HEADER*) amx->base; + AMX_FUNCSTUB *func; + for (int idx = 0, num = NUMENTRIES(hdr, natives, libraries); idx != num; ++idx) + { + func = GETENTRY(hdr, natives, idx); + if (!strcmp(from, GETENTRYNAME(hdr, func))) + { + if (store) + { + *store = (AMX_NATIVE) func->address; + } + func->address = to; + return; + } + } +} + +int AMXAPI amx_GetCString(AMX *amx, cell param, char *&dest) +{ + cell *ptr; + amx_GetAddr(amx, param, &ptr); + int len; + amx_StrLen(ptr, &len); + dest = (char*) malloc((len + 1) * sizeof(char)); + if (dest != NULL) + { + amx_GetString(dest, ptr, 0, UNLIMITED); + dest[len] = 0; + return len; + } + return 0; +} + +int AMXAPI amx_SetCString(AMX *amx, cell param, const char *str, int len) +{ + cell *dest; + int error; + if ((error = amx_GetAddr(amx, param, &dest)) != AMX_ERR_NONE) + return error; + + return amx_SetString(dest, str, 0, 0, len); +} + +#if defined __cplusplus + +std::string AMXAPI amx_GetCppString(AMX *amx, cell param) +{ + cell *addr = nullptr; + amx_GetAddr(amx, param, &addr); + + int len = 0; + amx_StrLen(addr, &len); + + std::string string(len, ' '); + amx_GetString(&string[0], addr, 0, len + 1); + + return string; +} + +int AMXAPI amx_SetCppString(AMX *amx, cell param, const std::string &str, size_t maxlen) +{ + cell *dest = nullptr; + int error; + if ((error = amx_GetAddr(amx, param, &dest)) != AMX_ERR_NONE) + return error; + + return amx_SetString(dest, str.c_str(), 0, 0, maxlen); +} + +#endif // __cplusplus + +//---------------------------------------------------------- +// EOF diff --git a/lib/samp-plugin-sdk/plugincommon.h b/lib/samp-plugin-sdk/plugincommon.h new file mode 100644 index 0000000..7d73344 --- /dev/null +++ b/lib/samp-plugin-sdk/plugincommon.h @@ -0,0 +1,123 @@ +//---------------------------------------------------------- +// +// SA-MP Multiplayer Modification For GTA:SA +// Copyright 2004-2009 SA-MP Team +// +//---------------------------------------------------------- + +#pragma once + +//---------------------------------------------------------- + +#define SAMP_PLUGIN_VERSION 0x0200 + +//---------------------------------------------------------- + +#ifdef __cplusplus + #define PLUGIN_EXTERN_C extern "C" +#else + #define PLUGIN_EXTERN_C +#endif + +#if defined(LINUX) || defined(FREEBSD) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) + #ifndef __GNUC__ + #pragma message "Warning: Not using a GNU compiler." + #endif + #define PLUGIN_CALL + #ifndef SAMPSVR + // Compile code with -fvisibility=hidden to hide non-exported functions. + #define PLUGIN_EXPORT PLUGIN_EXTERN_C __attribute__((visibility("default"))) + #else + #define PLUGIN_EXPORT PLUGIN_EXTERN_C + #endif +#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) + #ifndef _MSC_VER + #pragma message "Warning: Not using a VC++ compiler." + #endif + #define PLUGIN_CALL __stdcall + #define PLUGIN_EXPORT PLUGIN_EXTERN_C +#else + #error "You must define one of WIN32, LINUX or FREEBSD" +#endif + +//---------------------------------------------------------- + +enum SUPPORTS_FLAGS +{ + SUPPORTS_VERSION = SAMP_PLUGIN_VERSION, + SUPPORTS_VERSION_MASK = 0xffff, + SUPPORTS_AMX_NATIVES = 0x10000, + SUPPORTS_PROCESS_TICK = 0x20000 +}; + +//---------------------------------------------------------- + +enum PLUGIN_DATA_TYPE +{ + // For some debugging + PLUGIN_DATA_LOGPRINTF = 0x00, // void (*logprintf)(char* format, ...) + PLUGIN_DATA_NETGAME = 0xE1, // CNetGame* GetNetGame(); + PLUGIN_DATA_RAKSERVER = 0xE2, // RakServerInterface* PluginGetRakServer() + PLUGIN_DATA_LOADFSCRIPT = 0xE3, // bool LoadFilterscriptFromMemory(char* pFileName, char* pFileData) + PLUGIN_DATA_UNLOADFSCRIPT = 0xE5, // bool UnloadFilterScript(char* pFileName) + PLUGIN_DATA_CONSOLE = 0xE4, // CConsole* GetConsole(); + + // AMX + PLUGIN_DATA_AMX_EXPORTS = 0x10, // void* AmxFunctionTable[] (see PLUGIN_AMX_EXPORT) + PLUGIN_DATA_CALLPUBLIC_FS = 0x11, // int (*AmxCallPublicFilterScript)(char *szFunctionName) + PLUGIN_DATA_CALLPUBLIC_GM = 0x12, // int (*AmxCallPublicGameMode)(char *szFunctionName) + +}; + +//---------------------------------------------------------- + +enum PLUGIN_AMX_EXPORT +{ + PLUGIN_AMX_EXPORT_Align16 = 0, + PLUGIN_AMX_EXPORT_Align32 = 1, + PLUGIN_AMX_EXPORT_Align64 = 2, + PLUGIN_AMX_EXPORT_Allot = 3, + PLUGIN_AMX_EXPORT_Callback = 4, + PLUGIN_AMX_EXPORT_Cleanup = 5, + PLUGIN_AMX_EXPORT_Clone = 6, + PLUGIN_AMX_EXPORT_Exec = 7, + PLUGIN_AMX_EXPORT_FindNative = 8, + PLUGIN_AMX_EXPORT_FindPublic = 9, + PLUGIN_AMX_EXPORT_FindPubVar = 10, + PLUGIN_AMX_EXPORT_FindTagId = 11, + PLUGIN_AMX_EXPORT_Flags = 12, + PLUGIN_AMX_EXPORT_GetAddr = 13, + PLUGIN_AMX_EXPORT_GetNative = 14, + PLUGIN_AMX_EXPORT_GetPublic = 15, + PLUGIN_AMX_EXPORT_GetPubVar = 16, + PLUGIN_AMX_EXPORT_GetString = 17, + PLUGIN_AMX_EXPORT_GetTag = 18, + PLUGIN_AMX_EXPORT_GetUserData = 19, + PLUGIN_AMX_EXPORT_Init = 20, + PLUGIN_AMX_EXPORT_InitJIT = 21, + PLUGIN_AMX_EXPORT_MemInfo = 22, + PLUGIN_AMX_EXPORT_NameLength = 23, + PLUGIN_AMX_EXPORT_NativeInfo = 24, + PLUGIN_AMX_EXPORT_NumNatives = 25, + PLUGIN_AMX_EXPORT_NumPublics = 26, + PLUGIN_AMX_EXPORT_NumPubVars = 27, + PLUGIN_AMX_EXPORT_NumTags = 28, + PLUGIN_AMX_EXPORT_Push = 29, + PLUGIN_AMX_EXPORT_PushArray = 30, + PLUGIN_AMX_EXPORT_PushString = 31, + PLUGIN_AMX_EXPORT_RaiseError = 32, + PLUGIN_AMX_EXPORT_Register = 33, + PLUGIN_AMX_EXPORT_Release = 34, + PLUGIN_AMX_EXPORT_SetCallback = 35, + PLUGIN_AMX_EXPORT_SetDebugHook = 36, + PLUGIN_AMX_EXPORT_SetString = 37, + PLUGIN_AMX_EXPORT_SetUserData = 38, + PLUGIN_AMX_EXPORT_StrLen = 39, + PLUGIN_AMX_EXPORT_UTF8Check = 40, + PLUGIN_AMX_EXPORT_UTF8Get = 41, + PLUGIN_AMX_EXPORT_UTF8Len = 42, + PLUGIN_AMX_EXPORT_UTF8Put = 43, +}; + +//---------------------------------------------------------- +// EOF \ No newline at end of file diff --git a/src/main.h b/src/main.h index 6059a1b..ec68a48 100644 --- a/src/main.h +++ b/src/main.h @@ -3,6 +3,7 @@ #include #include "Addresses.h" #include +#include class CNetGame; class RakServer;