From de1f1eef8df15bb61f43faa58848995664e33068 Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Wed, 10 May 2006 11:19:24 +0000 Subject: [PATCH] Added request at29487 1) New hookable Engine func: GetInfoKeyBuffer 2) New GameDLL func that can be called via engfunc: GetInfoKeyBuffer 3) New native: copy_infokey_buffer that copies data out of the specified info key buffer 4) EngFunc_InfoKeyValue, EngFunc_SetKeyValue, and EngFunc_SetClientKeyValue have been reworked so that they expect pointers to an info key buffer in order to work properly o_O 5) Added some error messages to get_tr --- dlls/fakemeta/Makefile | 2 +- dlls/fakemeta/engfunc.cpp | 36 +++++++++++++++++++++-------- dlls/fakemeta/engfunc.h | 3 ++- dlls/fakemeta/fakemeta.vcproj | 3 +++ dlls/fakemeta/fakemeta_amxx.cpp | 2 ++ dlls/fakemeta/fakemeta_amxx.h | 1 + dlls/fakemeta/fm_tr.cpp | 10 ++++---- dlls/fakemeta/fm_tr2.cpp | 4 ++-- dlls/fakemeta/forward.cpp | 25 ++++++++++++++++---- dlls/fakemeta/forward.h | 3 ++- dlls/fakemeta/misc.cpp | 13 +++++++++++ dlls/fakemeta/msvc8/fakemeta.vcproj | 4 ++++ 12 files changed, 82 insertions(+), 24 deletions(-) create mode 100644 dlls/fakemeta/misc.cpp diff --git a/dlls/fakemeta/Makefile b/dlls/fakemeta/Makefile index e4e1dc3a..21851671 100755 --- a/dlls/fakemeta/Makefile +++ b/dlls/fakemeta/Makefile @@ -15,7 +15,7 @@ BIN_SUFFIX_32 = amxx_i386.so BIN_SUFFIX_64 = amxx_amd64.so OBJECTS = sdk/amxxmodule.cpp dllfunc.cpp engfunc.cpp fakemeta_amxx.cpp pdata.cpp forward.cpp \ - fm_tr.cpp pev.cpp glb.cpp fm_tr2.cpp + fm_tr.cpp pev.cpp glb.cpp fm_tr2.cpp misc.cpp LINK = diff --git a/dlls/fakemeta/engfunc.cpp b/dlls/fakemeta/engfunc.cpp index 0ad9b219..28189234 100755 --- a/dlls/fakemeta/engfunc.cpp +++ b/dlls/fakemeta/engfunc.cpp @@ -997,20 +997,21 @@ static cell AMX_NATIVE_CALL engfunc(AMX *amx, cell *params) (*g_engfuncs.pfnWriteAngle)(fparam1); return 1; case EngFunc_InfoKeyValue: // char* ) (char *infobuffer, char *key); - // Modify the syntax a bit. - // index, key cRet = MF_GetAmxAddr(amx,params[2]); - index = cRet[0]; + temp = reinterpret_cast(cRet[0]); + temp2 = MF_GetAmxString(amx,params[3],0,&len); + + temp = (*g_engfuncs.pfnInfoKeyValue)(temp, temp2); + cRet = MF_GetAmxAddr(amx,params[5]); iparam1 = cRet[0]; - CHECK_ENTITY(index); - temp2 = MF_GetAmxString(amx,params[3],0,&len); - temp = (*g_engfuncs.pfnInfoKeyValue)((*g_engfuncs.pfnGetInfoKeyBuffer)(INDEXENT2(index)),temp2); MF_SetAmxString(amx,params[4],temp,iparam1); + return 1; case EngFunc_SetKeyValue: // void ) (char *infobuffer, char *key, char *value); - temp3 = MF_GetAmxString(amx, params[2], 0, &len); + cRet = MF_GetAmxAddr(amx, params[2]); + temp3 = reinterpret_cast(cRet[0]); temp = MF_GetAmxString(amx, params[3], 1, &len); temp2 = MF_GetAmxString(amx, params[4], 2, &len); (*g_engfuncs.pfnSetKeyValue)(temp3, temp, temp2); @@ -1020,9 +1021,13 @@ static cell AMX_NATIVE_CALL engfunc(AMX *amx, cell *params) cRet = MF_GetAmxAddr(amx, params[2]); index = cRet[0]; CHECK_ENTITY(index); - temp = MF_GetAmxString(amx, params[3], 0, &len); - temp2 = MF_GetAmxString(amx, params[4], 1, &len); - (*g_engfuncs.pfnSetClientKeyValue)(index,(*g_engfuncs.pfnGetInfoKeyBuffer)(INDEXENT2(index)),temp,temp2); + + cRet = MF_GetAmxAddr(amx, params[3]); + temp = reinterpret_cast(cRet[0]); + + temp2 = MF_GetAmxString(amx, params[3], 0, &len); + temp3 = MF_GetAmxString(amx, params[4], 1, &len); + (*g_engfuncs.pfnSetClientKeyValue)(index, temp, temp2, temp3); return 1; case EngFunc_CreateInstancedBaseline: // int ) (int classname, struct entity_state_s *baseline); cRet = MF_GetAmxAddr(amx, params[2]); @@ -1038,6 +1043,17 @@ static cell AMX_NATIVE_CALL engfunc(AMX *amx, cell *params) es = reinterpret_cast(*cRet); return (*g_engfuncs.pfnCreateInstancedBaseline)(iparam1, es); + case EngFunc_GetInfoKeyBuffer: // char *) (edict_t *e); + cRet = MF_GetAmxAddr(amx, params[2]); + index = cRet[0]; + + if (index != -1) + { + CHECK_ENTITY(index); + } + + temp = (*g_engfuncs.pfnGetInfoKeyBuffer)((index == -1) ? NULL : INDEXENT2(index)); + return reinterpret_cast(temp); default: MF_LogError(amx, AMX_ERR_NATIVE, "Unknown engfunc type %d", type); return 0; diff --git a/dlls/fakemeta/engfunc.h b/dlls/fakemeta/engfunc.h index beaeb168..94d7a8d3 100755 --- a/dlls/fakemeta/engfunc.h +++ b/dlls/fakemeta/engfunc.h @@ -78,7 +78,8 @@ enum { EngFunc_InfoKeyValue, // char*) (char *infobuffer, char *key); EngFunc_SetKeyValue, // void ) (char *infobuffer, char *key, char *value); EngFunc_SetClientKeyValue, // void ) (int clientIndex, char *infobuffer, char *key, char *value); - EngFunc_CreateInstancedBaseline // int ) (int classname, struct entity_state_s *baseline); + EngFunc_CreateInstancedBaseline, // int ) (int classname, struct entity_state_s *baseline); + EngFunc_GetInfoKeyBuffer // char*) (edict_t *e); }; #endif //_ENGFUNC_INCLUDE_H diff --git a/dlls/fakemeta/fakemeta.vcproj b/dlls/fakemeta/fakemeta.vcproj index 7e43f534..681b2a6f 100755 --- a/dlls/fakemeta/fakemeta.vcproj +++ b/dlls/fakemeta/fakemeta.vcproj @@ -133,6 +133,9 @@ + + diff --git a/dlls/fakemeta/fakemeta_amxx.cpp b/dlls/fakemeta/fakemeta_amxx.cpp index bd74f37e..8fc3d210 100755 --- a/dlls/fakemeta/fakemeta_amxx.cpp +++ b/dlls/fakemeta/fakemeta_amxx.cpp @@ -14,6 +14,7 @@ void OnAmxxAttach() MF_AddNatives(tr_Natives); MF_AddNatives(glb_natives); MF_AddNatives(ext2_natives); + MF_AddNatives(misc_natives); g_kvd_2.szClassName = ""; g_kvd_2.szKeyName = ""; g_kvd_2.szValue = ""; @@ -140,6 +141,7 @@ void FMH_ServerDeactivate() RESETE(CVarSetString); RESETE(AlertMessage); RESETE(CreateInstancedBaseline); + RESETE(GetInfoKeyBuffer); RESETD(Spawn); RESETD(Think); diff --git a/dlls/fakemeta/fakemeta_amxx.h b/dlls/fakemeta/fakemeta_amxx.h index 1d6ac27b..4fdc5268 100755 --- a/dlls/fakemeta/fakemeta_amxx.h +++ b/dlls/fakemeta/fakemeta_amxx.h @@ -49,6 +49,7 @@ extern AMX_NATIVE_INFO pdata_natives[]; extern AMX_NATIVE_INFO tr_Natives[]; extern AMX_NATIVE_INFO pev_natives[]; extern AMX_NATIVE_INFO glb_natives[]; +extern AMX_NATIVE_INFO misc_natives[]; extern TraceResult g_tr; /* Wouldnt modifying the table AFTER it's memcpy'd be ... pointless? diff --git a/dlls/fakemeta/fm_tr.cpp b/dlls/fakemeta/fm_tr.cpp index 96607fc6..e7661005 100755 --- a/dlls/fakemeta/fm_tr.cpp +++ b/dlls/fakemeta/fm_tr.cpp @@ -6,10 +6,12 @@ KeyValueData *g_fm_keyValueData; static cell AMX_NATIVE_CALL set_tr(AMX *amx, cell *params) { int type = params[1]; - //TraceResult *tr = (TraceResult*)((void *)cPtr); if (*params / sizeof(cell) < 2) - return 0; //TODO: Error + { + MF_LogError(amx, AMX_ERR_NATIVE, "No data passed"); + return 0; + } cell *ptr = MF_GetAmxAddr(amx, params[2]); edict_t *e = 0; @@ -79,7 +81,7 @@ static cell AMX_NATIVE_CALL set_tr(AMX *amx, cell *params) } default: { - //TODO: error + MF_LogError(amx, AMX_ERR_NATIVE, "Unknown TraceResult member %d", params[2]); return 0; } } @@ -153,7 +155,7 @@ static cell AMX_NATIVE_CALL get_tr(AMX *amx, cell *params) } default: { - //TODO: error + MF_LogError(amx, AMX_ERR_NATIVE, "Unknown TraceResult member %d", params[2]); return 0; } } diff --git a/dlls/fakemeta/fm_tr2.cpp b/dlls/fakemeta/fm_tr2.cpp index 7a784e4a..3d224676 100644 --- a/dlls/fakemeta/fm_tr2.cpp +++ b/dlls/fakemeta/fm_tr2.cpp @@ -96,7 +96,7 @@ static cell AMX_NATIVE_CALL set_tr2(AMX *amx, cell *params) } default: { - MF_LogError(amx, AMX_ERR_NATIVE, "Unknown traceresult member %d", params[2]); + MF_LogError(amx, AMX_ERR_NATIVE, "Unknown TraceResult member %d", params[2]); return 0; } } @@ -182,7 +182,7 @@ static cell AMX_NATIVE_CALL get_tr2(AMX *amx, cell *params) } default: { - MF_LogError(amx, AMX_ERR_NATIVE, "Unknown traceresult member %d", params[2]); + MF_LogError(amx, AMX_ERR_NATIVE, "Unknown TraceResult member %d", params[2]); return 0; } } diff --git a/dlls/fakemeta/forward.cpp b/dlls/fakemeta/forward.cpp index 5cc2fbd9..070df9f2 100755 --- a/dlls/fakemeta/forward.cpp +++ b/dlls/fakemeta/forward.cpp @@ -88,13 +88,13 @@ SIMPLE_INT_HOOK_STRING(PrecacheSound); void ClientUserInfoChanged(edict_t *e, char *infobuffer) { - FM_ENG_HANDLE(FM_ClientUserInfoChanged, (Engine[FM_ClientUserInfoChanged].at(i), (cell)ENTINDEX(e))); + FM_ENG_HANDLE(FM_ClientUserInfoChanged, (Engine[FM_ClientUserInfoChanged].at(i), (cell)ENTINDEX(e), (cell)infobuffer)); RETURN_META(mswi(lastFmRes)); } void ClientUserInfoChanged_post(edict_t *e, char *infobuffer) { - FM_ENG_HANDLE_POST(FM_ClientUserInfoChanged, (EnginePost[FM_ClientUserInfoChanged].at(i), (cell)ENTINDEX(e))); + FM_ENG_HANDLE_POST(FM_ClientUserInfoChanged, (EnginePost[FM_ClientUserInfoChanged].at(i), (cell)ENTINDEX(e), (cell)infobuffer)); RETURN_META(MRES_IGNORED); } @@ -625,6 +625,19 @@ int CreateInstancedBaseline_post(int classname, struct entity_state_s *baseline) RETURN_META_VALUE(MRES_IGNORED, (int)mlCellResult); } +char *GetInfoKeyBuffer(edict_t *e) +{ + FM_ENG_HANDLE(FM_GetInfoKeyBuffer, (Engine[FM_GetInfoKeyBuffer].at(i), (cell)ENTINDEX(e))); + RETURN_META_VALUE(mswi(lastFmRes), reinterpret_cast(mlCellResult)); +} + +char *GetInfoKeyBuffer_post(edict_t *e) +{ + origCellRet = reinterpret_cast(META_RESULT_ORIG_RET(char *)); + FM_ENG_HANDLE(FM_GetInfoKeyBuffer, (Engine[FM_GetInfoKeyBuffer].at(i), (cell)ENTINDEX(e))); + RETURN_META_VALUE(MRES_IGNORED, reinterpret_cast(mlCellResult)); +} + /* * Beginning of Engine->Game DLL hooks */ @@ -1165,7 +1178,6 @@ static cell AMX_NATIVE_CALL register_forward(AMX *amx, cell *params) fId = MF_RegisterSPForwardByName(amx, funcname, FP_ARRAY, FP_CELL, FP_CELL, FP_CELL, FP_DONE); ENGHOOK(StaticDecal); break; - case FM_PrecacheGeneric: fId = MF_RegisterSPForwardByName(amx, funcname, FP_STRING, FP_DONE); ENGHOOK(PrecacheGeneric); @@ -1199,7 +1211,6 @@ static cell AMX_NATIVE_CALL register_forward(AMX *amx, cell *params) fId = MF_RegisterSPForwardByName(amx, funcname, FP_CELL, FP_CELL, FP_DONE); ENGHOOK(CheckVisibility); break; - case FM_GetCurrentPlayer: fId = MF_RegisterSPForwardByName(amx, funcname, FP_DONE); ENGHOOK(GetCurrentPlayer); @@ -1413,7 +1424,7 @@ static cell AMX_NATIVE_CALL register_forward(AMX *amx, cell *params) NEWDLLHOOK(ShouldCollide); break; case FM_ClientUserInfoChanged: - fId = MF_RegisterSPForwardByName(amx, funcname, FP_CELL, FP_DONE); + fId = MF_RegisterSPForwardByName(amx, funcname, FP_CELL, FP_CELL, FP_DONE); DLLHOOK(ClientUserInfoChanged); break; case FM_UpdateClientData: @@ -1440,6 +1451,10 @@ static cell AMX_NATIVE_CALL register_forward(AMX *amx, cell *params) fId = MF_RegisterSPForwardByName(amx, funcname, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_ARRAY, FP_ARRAY, FP_DONE); DLLHOOK(CreateBaseline); break; + case FM_GetInfoKeyBuffer: + fId = MF_RegisterSPForwardByName(amx, funcname, FP_CELL, FP_DONE); + ENGHOOK(GetInfoKeyBuffer); + break; #if 0 // I know this does not fit with DLLFUNC(), but I dont want another native just for it. diff --git a/dlls/fakemeta/forward.h b/dlls/fakemeta/forward.h index c5ac2941..b50a3425 100755 --- a/dlls/fakemeta/forward.h +++ b/dlls/fakemeta/forward.h @@ -1,7 +1,7 @@ #ifndef _INCLUDE_FORWARD_H #define _INCLUDE_FORWARD_H -#define ENGFUNC_NUM FM_LAST_DONT_USE_ME // 129 +#define ENGFUNC_NUM FM_LAST_DONT_USE_ME // 130 #define FMV_STRING 1 #define FMV_FLOAT 2 @@ -162,6 +162,7 @@ enum { FM_CmdEnd, FM_CreateInstancedBaseline, FM_CreateBaseline, + FM_GetInfoKeyBuffer, FM_LAST_DONT_USE_ME }; diff --git a/dlls/fakemeta/misc.cpp b/dlls/fakemeta/misc.cpp new file mode 100644 index 00000000..8e736849 --- /dev/null +++ b/dlls/fakemeta/misc.cpp @@ -0,0 +1,13 @@ +#include "fakemeta_amxx.h" + +static cell AMX_NATIVE_CALL copy_infokey_buffer(AMX *amx, cell *params) +{ + char *infobuffer = reinterpret_cast(params[1]); + + return MF_SetAmxString(amx, params[2], infobuffer, params[3]); +} + +AMX_NATIVE_INFO misc_natives[] = { + { "copy_infokey_buffer", copy_infokey_buffer }, + {NULL, NULL}, +}; \ No newline at end of file diff --git a/dlls/fakemeta/msvc8/fakemeta.vcproj b/dlls/fakemeta/msvc8/fakemeta.vcproj index e18a8766..c4aa891f 100644 --- a/dlls/fakemeta/msvc8/fakemeta.vcproj +++ b/dlls/fakemeta/msvc8/fakemeta.vcproj @@ -206,6 +206,10 @@ RelativePath="..\fm_tr2.cpp" > + +