diff --git a/server/filterscripts.cpp b/server/filterscripts.cpp index 6613b7d..c0b68d0 100644 --- a/server/filterscripts.cpp +++ b/server/filterscripts.cpp @@ -1,30 +1,1722 @@ #include "main.h" +extern "C" int amx_CoreInit(AMX* amx); +extern "C" int amx_CoreCleanup(AMX* amx); +extern "C" int amx_FloatInit(AMX* amx); +extern "C" int amx_FloatCleanup(AMX* amx); +extern "C" int amx_StringInit(AMX* amx); +extern "C" int amx_StringCleanup(AMX* amx); +extern "C" int amx_FileInit(AMX* amx); +extern "C" int amx_FileCleanup(AMX* amx); +extern "C" int amx_TimeInit(AMX* amx); +extern "C" int amx_TimeCleanup(AMX* amx); + +int AMXAPI aux_LoadProgram(AMX* amx, char* filename); +int AMXAPI aux_LoadProgramFromMemory(AMX* amx, char* filedata); +int AMXAPI aux_FreeProgram(AMX *amx); +int amx_CustomInit(AMX *amx); +int amx_sampDbInit(AMX *amx); +int amx_sampDbCleanup(AMX *amx); + +//---------------------------------------------------------------------------------- + CFilterScripts::CFilterScripts() { - field_1030 = 0; + m_iFilterScriptCount = 0; for (int i=0; i= MAX_FILTER_SCRIPTS) + return false; + + FILE* f = fopen(&szFilterScriptFile[0], "rb"); + if (!f) return false; + fclose(f); + + // Find a spare slot to load the script into + int iSlot; + for (iSlot = 0; iSlot < MAX_FILTER_SCRIPTS; iSlot++) + { + if (m_pFilterScripts[iSlot] == NULL) break; + if (strcmp(pFileName, m_szFilterScriptName[iSlot]) == 0) return false; + } + if (iSlot == MAX_FILTER_SCRIPTS) return false; + + m_pFilterScripts[iSlot] = new AMX; + AMX* amx = m_pFilterScripts[iSlot]; + + memset((void*)amx, 0, sizeof(AMX)); + int err = aux_LoadProgram(amx, &szFilterScriptFile[0]); + if (err != AMX_ERR_NONE) + { + logprintf("Failed to load '%s.amx' filterscript.", szFilterScriptFile); + return false; + } + + amx_CoreInit(amx); + amx_FloatInit(amx); + amx_StringInit(amx); + amx_FileInit(amx); + amx_TimeInit(amx); + amx_CustomInit(amx); + amx_sampDbInit(amx); + + int tmp; + if (!amx_FindPublic(amx, "OnFilterScriptInit", &tmp)) + amx_Exec(amx, (cell*)&tmp, tmp); + + strcpy(m_szFilterScriptName[iSlot], pFileName); + + m_iFilterScriptCount++; + + return true; } +//---------------------------------------------------------------------------------- + +bool CFilterScripts::LoadFilterScriptFromMemory(char* pFileName, char* pFileData) +{ + if (m_iFilterScriptCount >= MAX_FILTER_SCRIPTS) + return false; + + // Find a spare slot to load the script into + int iSlot; + for (iSlot = 0; iSlot < MAX_FILTER_SCRIPTS; iSlot++) + { + if (m_pFilterScripts[iSlot] == NULL) break; + if (strcmp(pFileName, m_szFilterScriptName[iSlot]) == 0) return false; + } + if (iSlot == MAX_FILTER_SCRIPTS) return false; + + m_pFilterScripts[iSlot] = new AMX; + AMX* amx = m_pFilterScripts[iSlot]; + + memset((void*)amx, 0, sizeof(AMX)); + int err = aux_LoadProgramFromMemory(amx, pFileData); + if (err != AMX_ERR_NONE) + { + return false; + } + + amx_CoreInit(amx); + amx_FloatInit(amx); + amx_StringInit(amx); + amx_FileInit(amx); + amx_TimeInit(amx); + amx_CustomInit(amx); + amx_sampDbInit(amx); + + int tmp; + if (!amx_FindPublic(amx, "OnFilterScriptInit", &tmp)) + amx_Exec(amx, (cell*)&tmp, tmp); + + strcpy(m_szFilterScriptName[iSlot], pFileName); + + m_iFilterScriptCount++; + + return true; +} + +//---------------------------------------------------------------------------------- + void CFilterScripts::UnloadFilterScripts() { - // TODO: CFilterScripts::UnloadFilterScripts W .text:0046CEB0 L .text:080A15B0 + for (int i=0; iGetTimers()) + pNetGame->GetTimers()->DeleteForMode(m_pFilterScripts[iIndex]); + + // Do the other stuff from before + aux_FreeProgram(m_pFilterScripts[iIndex]); + + amx_TimeCleanup(m_pFilterScripts[iIndex]); + amx_FileCleanup(m_pFilterScripts[iIndex]); + amx_StringCleanup(m_pFilterScripts[iIndex]); + amx_FloatCleanup(m_pFilterScripts[iIndex]); + amx_CoreCleanup(m_pFilterScripts[iIndex]); + amx_sampDbCleanup(m_pFilterScripts[iIndex]); + SAFE_DELETE(m_pFilterScripts[iIndex]); + m_szFilterScriptName[iIndex][0] = '\0'; + m_iFilterScriptCount--; } + +//---------------------------------------------------------------------------------- + +void CFilterScripts::Frame(float fElapsedTime) +{ + +} + +//---------------------------------------------------------------------------------- + +int CFilterScripts::CallPublic(char* szFuncName) +{ + int idx; + cell ret = 0; + + for (int i=0; iX); + cell vel_y = amx_ftoc(vecVelocity->Y); + cell vel_z = amx_ftoc(vecVelocity->Z); + cell new_x = amx_ftoc(vecPos->X); + cell new_y = amx_ftoc(vecPos->Y); + cell new_z = amx_ftoc(vecPos->Z); + + for (int i=0; ivecOffset.X); + cell offset_y = amx_ftoc(pInfo->vecOffset.Y); + cell offset_z = amx_ftoc(pInfo->vecOffset.Z); + cell rot_x = amx_ftoc(pInfo->vecRotation.X); + cell rot_y = amx_ftoc(pInfo->vecRotation.Y); + cell rot_z = amx_ftoc(pInfo->vecRotation.Z); + cell scale_x = amx_ftoc(pInfo->vecScale.X); + cell scale_y = amx_ftoc(pInfo->vecScale.Y); + cell scale_z = amx_ftoc(pInfo->vecScale.Z); + + for (int i=0; iiBoneID); + amx_Push(m_pFilterScripts[i], pInfo->iModelID); + amx_Push(m_pFilterScripts[i], index); + amx_Push(m_pFilterScripts[i], response); + amx_Push(m_pFilterScripts[i], playerid); + amx_Exec(m_pFilterScripts[i], &ret, idx); + if(ret) return 1; + } + } + } + return (int)ret; +} + +//---------------------------------------------------------------------------------- + +// forward OnPlayerEditObject( playerid, playerobject, objectid, response, +// Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ ); +int CFilterScripts::OnPlayerEditObject(cell playerid, cell playerobject, cell objectid, cell response, + float fX, float fY, float fZ, float fRotX, float fRotY, float fRotZ) +{ + int idx; + cell ret = 0; + + for (int i=0; iX); + cell y = amx_ftoc(vecPos->Y); + cell z = amx_ftoc(vecPos->Z); + + for (int i=0; i #else