commit d7e2c32a9d607366856e123e947bd0283c881da4 Author: yugecin Date: Thu Apr 2 23:46:27 2020 +0200 handle 'uncompress' and RakPeer::ParseConnectionRequestPacket diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5617afb --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +* eol=lf +*.sln eol=crlf +*.vcproj eol=crlf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..286763b --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/*.suo +/*.user +/*.ncb +/Debug/** +/out-debug/** +/server/** +!/server +!/server/server.cfg diff --git a/common.h b/common.h new file mode 100644 index 0000000..12e6701 --- /dev/null +++ b/common.h @@ -0,0 +1,6 @@ + +/* vim: set filetype=c ts=8 noexpandtab: */ + +#define _CRT_SECURE_NO_DEPRECATE +#define STATIC_ASSERT(E) typedef char __static_assert_[(E)?1:-1] +#define EXPECT_SIZE(S,SIZE) STATIC_ASSERT(sizeof(S)==(SIZE)) diff --git a/nethandler.c b/nethandler.c new file mode 100644 index 0000000..aa41b9f --- /dev/null +++ b/nethandler.c @@ -0,0 +1,25 @@ + +/* vim: set filetype=c ts=8 noexpandtab: */ + +#include "common.h" +#include "rakpeer.h" +#include "uncompress.h" +#include +#include +#include +#include + +void simple_redir_call(void *address, void *newtarget) +{ + DWORD oldvp; + + VirtualProtect(address, 4, PAGE_EXECUTE_READWRITE, &oldvp); + *(int*) address = (int) newtarget - ((int) address + 4); +} + +void nethandler_init() +{ + simple_redir_call(UNCOMPRESS_TARGET, uncompress_main); + simple_redir_call(RP_PARSE_CONNECTION_REQ, + RakPeer__ParseConnectionRequestPacket); +} diff --git a/plugin.c b/plugin.c new file mode 100644 index 0000000..eccda26 --- /dev/null +++ b/plugin.c @@ -0,0 +1,347 @@ + +/* vim: set filetype=c ts=8 noexpandtab: */ + +#include "common.h" +#include +#include "io.h" +#include "vendor/SDK/amx/amx.h" +#include "vendor/SDK/plugincommon.h" +#include +#include +#include + +typedef void (*logprintf_t)(char* format, ...); +logprintf_t logprintf; +extern void *pAMXFunctions; + +EXPECT_SIZE(char, 1); +EXPECT_SIZE(short, 2); +EXPECT_SIZE(int, 4); +EXPECT_SIZE(cell, 4); +EXPECT_SIZE(float, 4); + +/*in cells*/ +#define STACK_HEAP_SIZE 1024 + +AMX *amx; +struct FAKEAMX_DATA { + union { + cell ascell[144]; + char aschr[144 * sizeof(cell)]; + float asflt[144]; + } a144; + cell _stackheap[STACK_HEAP_SIZE]; +} fakeamx_data; +#define basea ((int) &fakeamx_data) +#define buf144a ((int) &fakeamx_data.a144 - basea) +#define buf144 (fakeamx_data.a144.ascell) +#define cbuf144 fakeamx_data.a144.aschr +#define fbuf144 fakeamx_data.a144.asflt + +union NCDATA { + cell asint[20]; + float asflt[20]; +} nc_params; + +struct NATIVE { + char *name; + AMX_NATIVE fp; +}; +struct NATIVE natives[] = { + /*this needs to be synced with NC_ definitions*/ + { "CreateObject", 0 }, + { "DestroyObject", 0 }, + { "SetObjectMaterial", 0 }, + { "SetObjectMaterialText", 0 }, + { "SetObjectPos", 0 }, + { "SetObjectRot", 0 }, + { "AddPlayerClass", 0 }, + { "EditObject", 0 }, + { "CreateVehicle", 0 }, + { "DestroyVehicle", 0 }, + { "SetWorldTime", 0 }, + { "SetWeather", 0 }, +}; +#define NUMNATIVES (sizeof(natives)/sizeof(struct NATIVE)) +#define NC_CreateObject 0 +#define NC_DestroyObject 1 +#define NC_SetObjectMaterial 2 +#define NC_SetObjectMaterialText 3 +#define NC_SetObjectPos 4 +#define NC_SetObjectRot 5 +#define NC_AddPlayerClass 6 +#define NC_EditObject 7 +#define NC_CreateVehicle 8 +#define NC_DestroyVehicle 9 +#define NC_SetWorldTime 10 +#define NC_SetWeather 11 + +PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() +{ + return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES | SUPPORTS_PROCESS_TICK; +} + +static +void gen_gamemode_script() +{ +#define cellsize 4 +#define PUBLICS 0 + + FILE *f; + int tmp, size; +#if PUBLICS > 0 + char pubtbl[PUBLICS * 8]; +#endif + char nattbl[NUMNATIVES * 8]; + int pubidx, i; + int cod, cip, dat; + union { + char i1; + short i2; + int i4; + char buf[4]; + } data; + struct { + int addr, sym; + } *table_entry; + + /*error handling is.. missing*/ + f = fopen("samp-re.amx", "wb"); + + /*header*/ + fwrite(data.buf, 4, 1, f); /*size, to be set when done*/ + data.i2 = 0xF1E0; + fwrite(data.buf, 2, 1, f); /*magic*/ + data.i1 = 0x8; + fwrite(data.buf, 1, 1, f); /*file version*/ + data.i1 = 0x8; + fwrite(data.buf, 1, 1, f); /*amx version*/ + data.i2 = 0x14; + fwrite(data.buf, 2, 1, f); /*flags*/ + data.i2 = 0x8; + fwrite(data.buf, 2, 1, f); /*defsize*/ + data.i4 = 0; /*done later*/ + fwrite(data.buf, 4, 1, f); /*cod*/ + data.i4 = 0; /*done later*/ + fwrite(data.buf, 4, 1, f); /*dat*/ + data.i4 = 0; /*done later*/ + fwrite(data.buf, 4, 1, f); /*hea*/ + data.i4 = 0; /*done later*/ + fwrite(data.buf, 4, 1, f); /*stp*/ + data.i4 = 0; /*done later*/ + fwrite(data.buf, 4, 1, f); /*cip*/ + data.i4 = 0x38; + fwrite(data.buf, 4, 1, f); /*publictable*/ +#if PUBLICS > 0 + data.i4 += sizeof(pubtbl); +#endif + fwrite(data.buf, 4, 1, f); /*nativetable*/ + data.i4 += sizeof(nattbl); + fwrite(data.buf, 4, 1, f); /*libraries*/ + fwrite(data.buf, 4, 1, f); /*pubvars*/ + fwrite(data.buf, 4, 1, f); /*tags*/ + fwrite(data.buf, 4, 1, f); /*nametable*/ + size = 0x38; /*header*/ + + /*pubtbl, dummy at this point*/ +#if PUBLICS > 0 + fwrite(pubtbl, sizeof(pubtbl), 1, f); + size += sizeof(pubtbl); +#endif + + /*nattbl, dummy at this point*/ + fwrite(nattbl, sizeof(nattbl), 1, f); + size += sizeof(nattbl); + + /*namtbl*/ + data.i2 = 31; + fwrite(data.buf, 2, 1, f); /*max name len (I suppose?)*/ + size += 2; + pubidx = 0; +#define PUBLIC(NAME) \ + tmp=strlen(NAME)+1;\ + fwrite(NAME,tmp,1,f);\ + table_entry->addr=(2+pubidx*4)*cellsize;\ + table_entry->sym=size;\ + table_entry++;\ + pubidx++;\ + size+=tmp; + /*first [PUBLICS] amount of natives should be the names of the + native plugin functions to passthrough callbacks to*/ +#if PUBLICS > 0 + table_entry = (void*) pubtbl; + PUBLIC("MM"); + PUBLIC("dummies"); +#endif + table_entry = (void*) nattbl; + for (i = 0; i < NUMNATIVES; i++) { + tmp = strlen(natives[i].name) + 1; + fwrite(natives[i].name, tmp, 1, f); + table_entry->addr = 0; + table_entry->sym = size; + table_entry++; + size += tmp; + } +#undef PUBLIC + + cod = size; + + /*code segment*/ + cip = 0; + dat = 0; + data.i1 = 0x80; /*???*/ + fwrite(data.buf, 1, 1, f); + data.i1 = 0x78; /*OP_HALT*/ + fwrite(data.buf, 1, 1, f); + data.i1 = 0x00; /*param*/ + fwrite(data.buf, 1, 1, f); + size += 3; + dat += 2; + /*publics*/ +#if PUBLICS > 0 + /*TODO: something makes the amx not accept this...*/ + for (tmp = 0; tmp < PUBLICS; tmp++) { + data.buf[0] = 46; /*OP_PROC*/ + data.buf[1] = 123; /*OP_SYSREC_C*/ + data.buf[2] = tmp; /*name table entry*/ + data.buf[3] = 48; /*OP_RETN*/ + fwrite(data.buf, 4, 1, f); + size += 4; + dat += 4; + } +#endif + /*entrypoint*/ + cip = (size - cod) * cellsize; + data.i1 = 46; /*OP_PROC*/ + fwrite(data.buf, 1, 1, f); + data.i1 = 48; /*OP_RETN*/ + fwrite(data.buf, 1, 1, f); + size += 2; + dat += 2; + dat = cod + dat * cellsize; + + fseek(f, 0, SEEK_SET); + data.i4 = size; + fwrite(data.buf, 4, 1, f); /*size*/ + fseek(f, 0xC, SEEK_SET); + data.i4 = cod; + fwrite(data.buf, 4, 1, f); /*cod*/ + data.i4 = dat; + fwrite(data.buf, 4, 1, f); /*dat*/ + fwrite(data.buf, 4, 1, f); /*hea*/ + data.i4 += STACK_HEAP_SIZE * cellsize; + fwrite(data.buf, 4, 1, f); /*stp*/ + data.i4 = cip; + fwrite(data.buf, 4, 1, f); /*cip*/ + + fseek(f, 0x38, SEEK_SET); +#if PUBLICS > 0 + fwrite(pubtbl, sizeof(pubtbl), 1, f); /*pubtbl*/ +#endif + fwrite(nattbl, sizeof(nattbl), 1, f); /*nattbl*/ + + fclose(f); +} + +PLUGIN_EXPORT int PLUGIN_CALL Load(void **ppData) +{ + void nethandler_load(); + + pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS]; + logprintf = (logprintf_t) ppData[PLUGIN_DATA_LOGPRINTF]; + gen_gamemode_script(); + + nethandler_init(); + return 1; +} + +PLUGIN_EXPORT void PLUGIN_CALL Unload() +{ +} + +#define REGISTERNATIVE(X) {#X, X} +AMX_NATIVE_INFO PluginNatives[] = +{ + {0, 0} +}; + +static +void collect_natives() +{ + struct NATIVE *n = natives; + AMX_HEADER *header; + unsigned char *nattabl; + int i; + + header = (AMX_HEADER*) amx->base; + nattabl = (unsigned char*) header + header->natives; + + for (i = 0; i < NUMNATIVES; i++) { + /*skipping some steps here...*/ + natives[i].fp = (AMX_NATIVE) *((int*) (nattabl + i * 8)); + } +} + +PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX *a) +{ + AMX_HEADER *hdr; + int tmp; + + amx = a; + collect_natives(); + + nc_params.asint[1] = 0; + nc_params.asflt[2] = 0.0f; + nc_params.asflt[3] = 0.0f; + nc_params.asflt[4] = 4.5f; + nc_params.asflt[5] = 0.0f; + nc_params.asint[6] = nc_params.asint[8] = nc_params.asint[10] = 0; + nc_params.asint[7] = nc_params.asint[9] = nc_params.asint[11] = 0; + natives[NC_AddPlayerClass].fp(amx, nc_params.asint); + + /*relocate the data segment*/ + hdr = (AMX_HEADER*) amx->base; + tmp = hdr->hea - hdr->dat; + if (tmp) { + /*data section will be cleared so whoever references it + will probably overwrite our precious data*/ + logprintf("WARN: data section is not empty! (%d)", tmp); + } + tmp = hdr->stp - hdr->hea - STACK_HEAP_SIZE * sizeof(cell); + if (tmp) { + logprintf("ERR: stack/heap size mismatch! " + "(excess %d cells)", + tmp / sizeof(cell)); + return 0; + } + /*copy content of stack/heap to our data segment (this is most + likely empty, but better safe than sorry)*/ + memcpy(fakeamx_data._stackheap, + amx->base + hdr->hea, + STACK_HEAP_SIZE * sizeof(cell)); + /*finally do the relocation*/ + amx->data = (unsigned char*) &fakeamx_data; + /*adjust pointers since the data segment grew*/ + tmp = (char*) &fakeamx_data._stackheap - (char*) &fakeamx_data; + amx->frm += tmp; + amx->hea += tmp; + amx->hlw += tmp; + amx->stk += tmp; + amx->stp += tmp; + /*samp core doesn't seem to use amx_SetString or amx_GetString + so the data offset needs to be adjusted*/ + hdr->dat = (int) &fakeamx_data - (int) hdr; + /*this won't work on linux because linux builds have assertions + enabled, but this is only targeted for windows anyways*/ + + return amx_Register(a, PluginNatives, -1); +} + +PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX *a) +{ + return AMX_ERR_NONE; +} + +PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() +{ +} diff --git a/plugin.def b/plugin.def new file mode 100644 index 0000000..fef05eb --- /dev/null +++ b/plugin.def @@ -0,0 +1,7 @@ +EXPORTS + Supports + Load + Unload + ProcessTick + AmxLoad + AmxUnload \ No newline at end of file diff --git a/rakpeer.c b/rakpeer.c new file mode 100644 index 0000000..a1d43d9 --- /dev/null +++ b/rakpeer.c @@ -0,0 +1,177 @@ + +/* vim: set filetype=c ts=8 noexpandtab: */ + +//#define COMPRESS_PRINT + +#include "common.h" +#include "rakpeer.h" +#include +#include +#include + +static +int __declspec(naked) RakPeer__OnConnectionRequest( + struct CRakPeer *this, + struct CRakPeer__RemoteSystemStruct *remoteSystem, + char *AESKey, + char setAESkey) +{ + _asm { + mov eax, esp + pop ecx + push [eax+0x10] /*setAESKey*/ + push [eax+0xC] /*AESKey*/ + push [eax+0x8] /*remoteSystem*/ + push ecx /*return address*/ + mov ecx, [eax+0x4] /*this*/ + mov eax, 0x455A60 + jmp eax + } +} + +static +unsigned int __declspec(naked) RakPeer__GetTime(struct CRakPeer *this) +{ + _asm { + mov ecx, [esp+0x4] /*this*/ + mov eax, 0x44E9D0 + jmp eax + } +} + +static +void __declspec(naked) RakPeer__SendImmediate( + struct CRakPeer *this, + char *data, + int numberOfBitsToSend, + int priority, + int reliability, + int orderingChannel, + struct PlayerID playerId, + int broadcast, + int useCallerDataAllocation, + unsigned int currentTime) +{ + _asm { + mov eax, esp + pop ecx + push [eax+0x30] // currentTimeDummy + push [eax+0x2C] // currentTime + push [eax+0x28] // useCallerDataAllocation + push [eax+0x24] // broadcast + push [eax+0x20] // playerId + push [eax+0x1C] // playerId + push [eax+0x18] // orderingChannel + push [eax+0x14] // reliability + push [eax+0x10] // priority + push [eax+0xC] // numberOfBitsToSend + push [eax+0x8] // data + push ecx /*return address*/ + mov ecx, [eax+0x4] /*this*/ + mov eax, 0x453C60 + jmp eax + } +} + +static +short __declspec(naked) RakPeer__AllowIncomingConnectionsInternal( + struct CRakPeer *this) +{ + _asm { + mov ecx, [esp+0x4] + mov eax, 0x4509D0 + call eax + ret + } +} + +static +void RakPeer__ParseConnectionRequestPacketInternal( + struct CRakPeer *this, + struct CRakPeer__RemoteSystemStruct *remoteSystem, + struct PlayerID playerId, + char *data, + char byteSize) +{ + unsigned char responseData; + char *clientPass; + int clientPassLen; + char tmpPlayerDebugPassword[256]; + + printf("ParseConnectionRequestPacket start\n"); + if (!RakPeer__AllowIncomingConnectionsInternal(this)) { + printf("server is full\n"); + responseData = ID_NO_FREE_INCOMING_CONNECTIONS; + goto sendimmediateresponse; + } + + printf("checking password requirements\n"); + clientPassLen = byteSize - sizeof(char); + clientPass = data + sizeof(char); + if (this->incomingPasswordLength != clientPassLen) { + printf("incorrect password length\n"); + printf("client: %d server: %d\n", + clientPassLen, this->incomingPasswordLength); + goto kickplayer; + } + if (memcmp(this->incomingPassword, clientPass, clientPassLen) != 0) { + printf("non-matching password\n"); + /*temp copy player password to print, because it's not zero + termd*/ + memcpy(tmpPlayerDebugPassword, clientPass, clientPassLen); + tmpPlayerDebugPassword[clientPassLen] = 0; + printf("client: %s server: %s\n", + tmpPlayerDebugPassword, this->incomingPassword); + goto kickplayer; + } + printf("password check passed\n"); + + /*security is not used*/ + /*if (this->usingSecurity) { + printf("using security\n"); + //SecuredConnectionResponse(playerId); + goto ret; + }*/ + RakPeer__OnConnectionRequest(this, remoteSystem, NULL, 0); + goto ret; + +kickplayer: + responseData = ID_INVALID_PASSWORD; +sendimmediateresponse: + printf("disconnecting player\n"); + RakPeer__SendImmediate( + this, + &responseData, + sizeof(char) * 8, + SYSTEM_PRIORITY, + RELIABLE, + 0, + playerId, + 0, + 0, + RakPeer__GetTime(this) + ); + remoteSystem->connectMode = DISCONNECT_ASAP_SILENTLY; +ret: + printf("ParseConnectionRequestPacket end\n"); +} + +int __declspec(naked) RakPeer__ParseConnectionRequestPacket( + struct CRakPeer__RemoteSystemStruct *remoteSystem, + struct PlayerID playerId, + int data, + char byteSize) +{ + _asm { + mov eax, esp + push [eax+0x14] // byteSize + push [eax+0x10] // data + push [eax+0xC] // playerId + push [eax+0x8] // playerId + push [eax+0x4] // remoteSystem + push ecx // this + call RakPeer__ParseConnectionRequestPacketInternal + add esp, 0x18 + retn 0x14 /*+4 for playerid*/ + } +} diff --git a/rakpeer.h b/rakpeer.h new file mode 100644 index 0000000..f991899 --- /dev/null +++ b/rakpeer.h @@ -0,0 +1,96 @@ + +/* vim: set filetype=c ts=8 noexpandtab: */ + +#define RP_PARSE_CONNECTION_REQ ((void*) 0x4591D0) + +#define NO_ACTION 0 +#define DISCONNECT_ASAP 1 +#define DISCONNECT_ASAP_SILENTLY 2 +#define DISCONNECT_ON_NO_ACK 3 +#define REQUESTED_CONNECTION 4 +#define HANDLING_CONNECTION_REQUEST 5 +#define UNVERIFIED_SENDER 6 +#define SET_ENCRYPTION_ON_MULTIPLE_16_BYTE_PACKET 7 +#define CONNECTED 8 + +#define ID_CONNECTION_REQUEST 0x0B +#define ID_OPEN_CONNECTION_REQUEST 0x18 +#define ID_OPEN_CONNECTION_REPLY 0x19 +#define ID_CONNECTION_ATTEMPT_FAILED 0x1D +#define ID_NEW_INCOMING_CONNECTION 0x1E +#define ID_NO_FREE_INCOMING_CONNECTIONS 0x1F +#define ID_CONNECTION_BANNED 0x24 +#define ID_INVALID_PASSWORD 0x25 + +#define SYSTEM_PRIORITY 0 +#define HIGH_PRIORITY 1 +#define NUMBER_OF_PRIORITIES 4 + +#define UNRELIABLE_SEQUENCED 7 +#define RELIABLE 8 +#define RELIABLE_ORDENED 9 +#define RELIABLE_SEQUENCED 0xA +#define UNRELIABLE 0xB + +#pragma pack(push,1) +struct PlayerID { + int binaryAddress; + short port; + short __pad; +}; +EXPECT_SIZE(struct PlayerID, 0x8); + +struct CRakPeer__RemoteSystemStruct { + char _pad0[0x10-0x0]; + void *reliabilityLayer; + char _pad14[0x778-0x14]; + int lowestPing; + int nextPingTime; + char _pad780[0xCB0-0x780]; + int connectMode; +}; + +struct CRakPeer { + char _pad0[6]; + char occasionalPing; + char _pad7[0x14-0x7]; + int maximumIncomingConnections; + char _pad18[0x28-0x18]; + int procIsActive; + char _pad2C[0x70-0x2C]; + int procIsBanned; + char _pad74[0xB8-0x74]; + int procPlayerIDToDottedIP; + char _padBC[0xDC-0xBC]; + int procDeleteCompressionLayer; + char _padE0[0x22C-0xE0]; + struct PlayerID mPlayerId; + char _pad234[0x23A-0x234]; + char incomingPassword[256]; + unsigned char incomingPasswordLength; + char _pad33B[0x33C-0x33B]; + struct CRakPeer__RemoteSystemStruct *remoteSystemList; + char _pad340[0x7DC-0x340]; + void *inputTree; /*HuffmanEncodingTree**/ + void *outputTree; /*HuffmanEncodingTree**/ + char _pad7E4[0xC0C-0x7E4]; + int MTUSize; + char _padC10[0xD95-0xC10]; + char usingSecurity; + /*incomplete*/ +}; +#pragma pack(pop) + +/** +int __thiscall RakPeer__ParseConnectionRequestPacket( + CRakPeer *this, + CRakPeer__RemoteSystemStruct *remoteSystem, + PlayerID playerId, + int data, + char byteSize) +*/ +int RakPeer__ParseConnectionRequestPacket( + struct CRakPeer__RemoteSystemStruct *remoteSystem, + struct PlayerID playerId, + int data, + char byteSize); diff --git a/runserver.bat b/runserver.bat new file mode 100644 index 0000000..60d9059 --- /dev/null +++ b/runserver.bat @@ -0,0 +1,12 @@ +@echo off +:a + +COPY /Y out-debug\samp-re.dll server\plugins\samp-re.dll +COPY /Y out-debug\samp-re.pdb server\plugins\samp-re.pdb + +pushd server +"samp-server.exe" +popd +echo :: server exited, restarting in ~3 +sleep 3 +goto a diff --git a/samp-re.sln b/samp-re.sln new file mode 100644 index 0000000..1d7f868 --- /dev/null +++ b/samp-re.sln @@ -0,0 +1,17 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual C++ Express 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "samp-re", "samp-re.vcproj", "{177DE7D3-A7BB-4F99-00D5-E2E8E1846607}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {177DE7D3-A7BB-4F99-00D5-E2E8E1846607}.Debug|Win32.ActiveCfg = Debug|Win32 + {177DE7D3-A7BB-4F99-00D5-E2E8E1846607}.Debug|Win32.Build.0 = Debug|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/samp-re.vcproj b/samp-re.vcproj new file mode 100644 index 0000000..3808e7b --- /dev/null +++ b/samp-re.vcproj @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/server/server.cfg b/server/server.cfg new file mode 100644 index 0000000..c99b995 --- /dev/null +++ b/server/server.cfg @@ -0,0 +1,23 @@ +echo Executing Server Config... +lanmode 0 +rcon_password 0 +maxplayers 1 +port 8888 +hostname samp-re +gamemode0 ../samp-re +announce 0 +query 1 +chatlogging 0 +weburl sa-mp.com +onfoot_rate 40 +incar_rate 40 +weapon_rate 40 +stream_distance 300.0 +stream_rate 1000 +maxnpc 0 +plugins samp-re.dll +logtimeformat [%H:%M:%S] +logqueries 0 +language English +lagcompmode 0 +sleep 1 diff --git a/serverlink.h b/serverlink.h new file mode 100644 index 0000000..12e1737 --- /dev/null +++ b/serverlink.h @@ -0,0 +1,42 @@ + +/* vim: set filetype=c ts=8 noexpandtab: */ + +#define SOCKET_PORT_CLIENT 8887 +#define SOCKET_PORT_SERVER 8889 + +#define NC_CreateObject 0 +#define NC_DestroyObject 1 +#define NC_SetObjectMaterial 2 +#define NC_SetObjectMaterialText 3 +#define NC_SetObjectPos 4 +#define NC_SetObjectRot 5 +#define NC_AddPlayerClass 6 +#define NC_EditObject 7 +#define NC_CreateVehicle 8 +#define NC_DestroyVehicle 9 +#define NC_SetWorldTime 10 +#define NC_SetWeather 11 + +#define MAPEDIT_MSG_RESETOBJECTS 0 +#define MAPEDIT_MSG_NATIVECALL 1 +#define MAPEDIT_MSG_OBJECT_CREATED 2 + +struct MSG { + int id; + int data; +}; + +struct MSG_NC { + struct MSG _parent; + int nc; + union { + int asint[20]; + float asflt[20]; + } params; +}; + +struct MSG_OBJECT_CREATED { + struct MSG _parent; + int samp_objectid; + struct OBJECT *object; +}; diff --git a/uncompress.c b/uncompress.c new file mode 100644 index 0000000..bc83b5e --- /dev/null +++ b/uncompress.c @@ -0,0 +1,69 @@ + +/* vim: set filetype=c ts=8 noexpandtab: */ + +#define COMPRESS_PRINT + +#include "common.h" +#include "uncompress.h" +#include +#include +#include + +static unsigned char *currentPort = (unsigned char*) 0x4F4E78; + +static +__declspec(naked) int sub_46A6F0( + int a, unsigned char portStuff, char *dest, int length) +{ + _asm { + mov eax, 0x46A6F0 + jmp eax + } +} + +static +__declspec(naked) int sub_46A6C0(char *dest, int length) +{ + _asm { + mov eax, 0x46A6C0 + jmp eax + } +} + +int uncompress_main(char *dest, char *source, int *length) +{ + unsigned char res; + +#ifdef COMPRESS_PRINT + int i; + + printf("IN "); + for (i = 0; i < *length; i++) { + printf("%02X ", (unsigned char) source[i]); + } + printf("\n"); +#endif + + + (*length)--; + memcpy(dest, source + 1, *length); + + sub_46A6F0(0, *currentPort, dest, *length); + res = sub_46A6C0(dest, *length); + +#ifdef COMPRESS_PRINT + printf("OUT "); + for (i = 0; i < *length; i++) { + printf("%02X ", (unsigned char) dest[i]); + } + printf("\n"); +#endif + +/* + res -= source[0]; + res = -res; + // sbb eax, eax + // inc eax*/ + /*always accept for now I suppose...*/ + return 1; +} diff --git a/uncompress.h b/uncompress.h new file mode 100644 index 0000000..2a4450d --- /dev/null +++ b/uncompress.h @@ -0,0 +1,6 @@ + +/* vim: set filetype=c ts=8 noexpandtab: */ + +#define UNCOMPRESS_TARGET ((void*) 0x462BE0) + +int uncompress_main(char *dest, char *source, int *length); diff --git a/vendor/SDK/amx/amx.h b/vendor/SDK/amx/amx.h new file mode 100644 index 0000000..bc18312 --- /dev/null +++ b/vendor/SDK/amx/amx.h @@ -0,0 +1,462 @@ +/* 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 $ + */ + +#ifndef AMX_H_INCLUDED +#define AMX_H_INCLUDED + +/* >>> yugecin: added these in so I can compile using the toolsets I use */ +#ifdef __MINGW32__ + #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L + #define __need_size_t + #include + #undef __need_size_t + #else + #define HAVE_STDINT_H + #endif +#elif defined __linux || defined __linux__ + #include + #ifndef __BYTE_ORDER + #include + #endif +#else + #include +#endif +/* <<< end */ + +#if defined __linux || defined __linux__ +#define __LINUX__ +#endif +#if defined FREEBSD && !defined __FreeBSD__ +#define __FreeBSD__ +#endif +#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ +#include "sclinux.h" +#endif + +#if defined HAVE_STDINT_H + #include +#else + #if defined __LCC__ || defined __DMC__ || defined __LINUX__ || (defined __WATCOMC__ && __WATCOMC__ >= 1200) + #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 +#endif +/*#if defined __WIN32__ || defined _WIN32 || defined WIN32 + #if !defined alloca + #define xalloca(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 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; /* file format version */ + char amx_version; /* 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/vendor/SDK/amx/sclinux.h b/vendor/SDK/amx/sclinux.h new file mode 100644 index 0000000..774ecfa --- /dev/null +++ b/vendor/SDK/amx/sclinux.h @@ -0,0 +1,37 @@ +/* + * Things needed to compile under linux. + * + * Should be reworked totally to use GNU's 'configure' + */ +#ifndef SCLINUX_H +#define SCLINUX_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 __OpenBSD__ || defined __FreeBSD__ +# 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/vendor/SDK/amxplugin.c b/vendor/SDK/amxplugin.c new file mode 100644 index 0000000..bea7737 --- /dev/null +++ b/vendor/SDK/amxplugin.c @@ -0,0 +1,342 @@ +/* +yugecin: surrounded // comments with block comments for C89 compat +//---------------------------------------------------------- +// +// 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. +// +//---------------------------------------------------------- +*/ + +#include "amx/amx.h" +#include "plugincommon.h" + +/* +//---------------------------------------------------------- +*/ + +void *pAMXFunctions; + +/* +//---------------------------------------------------------- +*/ + +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); +} + +/* +//---------------------------------------------------------- +// EOF +*/ \ No newline at end of file diff --git a/vendor/SDK/plugincommon.h b/vendor/SDK/plugincommon.h new file mode 100644 index 0000000..71e43ab --- /dev/null +++ b/vendor/SDK/plugincommon.h @@ -0,0 +1,143 @@ +/* +yugecin: surrounded // comments with block comments for C89 compat + +//---------------------------------------------------------- +// +// 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(__OpenBSD__) + #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 + /* yugecin: added this ifndef around the message to not show it when using gcc on win */ + #ifndef __MINGW32__ + #pragma message "Warning: Not using a VC++ compiler." + #endif + #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, ...)*/ + + /* + // 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 +*/