diff --git a/dlls/fakemeta/fakemeta.vcproj b/dlls/fakemeta/fakemeta.vcproj index 760b2de7..e37963c1 100755 --- a/dlls/fakemeta/fakemeta.vcproj +++ b/dlls/fakemeta/fakemeta.vcproj @@ -123,6 +123,12 @@ + + + + diff --git a/dlls/fakemeta/fakemeta_amxx.h b/dlls/fakemeta/fakemeta_amxx.h index 83ae1a3e..05c487ac 100755 --- a/dlls/fakemeta/fakemeta_amxx.h +++ b/dlls/fakemeta/fakemeta_amxx.h @@ -7,6 +7,7 @@ #include "dllfunc.h" #include "pev.h" #include "forward.h" +#include "fm_tr.h" extern edict_t *g_player_edicts[33]; @@ -25,6 +26,7 @@ extern AMX_NATIVE_INFO dllfunc_natives[]; extern AMX_NATIVE_INFO pev_natives[]; extern AMX_NATIVE_INFO forward_natives[]; extern AMX_NATIVE_INFO pdata_natives[]; +extern AMX_NATIVE_INFO tr_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 new file mode 100755 index 00000000..8134b92a --- /dev/null +++ b/dlls/fakemeta/fm_tr.cpp @@ -0,0 +1,177 @@ +#include "fakemeta_amxx.h" + +/*enum +{ + TR_AllSolid, + TR_StartSolid, + TR_InOpen, + TR_InWater, + TR_flFraction, + TR_vecEndPos, + TR_flPlaneDist, + TR_vecPlaneNormal, + TR_pHit, + TR_iHitgroup, +};*/ + +static cell AMX_NATIVE_CALL set_tr(AMX *amx, cell *params) +{ + cell *cPtr = ¶ms[1]; + int type = params[2]; + TraceResult *tr = (TraceResult*)((void *)cPtr); + + if (*params / sizeof(cell) < 3) + return 0; //TODO: Error + + cell *ptr = MF_GetAmxAddr(amx, params[3]); + edict_t *e = 0; + + switch (type) + { + case TR_AllSolid: + { + tr->fAllSolid = *ptr; + return 1; + break; + } + case TR_StartSolid: + { + return tr->fStartSolid; + break; + } + case TR_InWater: + { + tr->fInWater = *ptr; + return 1; + break; + } + case TR_flFraction: + { + tr->flFraction = amx_ctof(*ptr); + return 1; + break; + } + case TR_vecEndPos: + { + tr->vecEndPos.x = amx_ctof(ptr[0]); + tr->vecEndPos.y = amx_ctof(ptr[1]); + tr->vecEndPos.z = amx_ctof(ptr[2]); + return 1; + break; + } + case TR_flPlaneDist: + { + tr->flPlaneDist = amx_ctof(*ptr); + return 1; + break; + } + case TR_vecPlaneNormal: + { + tr->vecPlaneNormal.x = amx_ctof(ptr[0]); + tr->vecPlaneNormal.y = amx_ctof(ptr[1]); + tr->vecPlaneNormal.z = amx_ctof(ptr[2]); + return 1; + break; + } + case TR_pHit: + { + e = INDEXENT(*ptr); + if (!e || FNullEnt(e)) + return 0; //TODO: return error + tr->pHit = e; + return 1; + break; + } + case TR_iHitgroup: + { + tr->iHitgroup = *ptr; + return 1; + break; + } + default: + { + //TODO: error + return 0; + } + } +} + +static cell AMX_NATIVE_CALL get_tr(AMX *amx, cell *params) +{ + cell *cPtr = ¶ms[1]; + int type = params[2]; + TraceResult *tr = (TraceResult*)((void *)cPtr); + cell *ptr = 0; + + switch (type) + { + case TR_AllSolid: + { + return tr->fAllSolid; + break; + } + case TR_StartSolid: + { + return tr->fStartSolid; + break; + } + case TR_InWater: + { + return tr->fInWater; + break; + } + case TR_flFraction: + { + ptr = MF_GetAmxAddr(amx, params[3]); + *ptr = amx_ftoc(tr->flFraction); + return 1; + break; + } + case TR_vecEndPos: + { + ptr = MF_GetAmxAddr(amx, params[3]); + ptr[0] = amx_ftoc(tr->vecEndPos.x); + ptr[1] = amx_ftoc(tr->vecEndPos.y); + ptr[2] = amx_ftoc(tr->vecEndPos.z); + return 1; + break; + } + case TR_flPlaneDist: + { + ptr = MF_GetAmxAddr(amx, params[3]); + *ptr = amx_ftoc(tr->flPlaneDist); + return 1; + break; + } + case TR_vecPlaneNormal: + { + ptr = MF_GetAmxAddr(amx, params[3]); + ptr[0] = amx_ftoc(tr->vecPlaneNormal.x); + ptr[1] = amx_ftoc(tr->vecPlaneNormal.y); + ptr[2] = amx_ftoc(tr->vecPlaneNormal.z); + return 1; + break; + } + case TR_pHit: + { + return ENTINDEX(tr->pHit); + break; + } + case TR_iHitgroup: + { + return tr->iHitgroup; + break; + } + default: + { + //TODO: error + return 0; + } + } +} + +AMX_NATIVE_INFO tr_Natives[] = { + {"get_tr", get_tr}, + {"set_tr", set_tr}, + {NULL, NULL}, +}; \ No newline at end of file diff --git a/dlls/fakemeta/fm_tr.h b/dlls/fakemeta/fm_tr.h new file mode 100755 index 00000000..811cb7b2 --- /dev/null +++ b/dlls/fakemeta/fm_tr.h @@ -0,0 +1,18 @@ +#ifndef _INCLUDE_TR_H +#define _INCLUDE_TR_H + +enum +{ + TR_AllSolid, + TR_StartSolid, + TR_InOpen, + TR_InWater, + TR_flFraction, + TR_vecEndPos, + TR_flPlaneDist, + TR_vecPlaneNormal, + TR_pHit, + TR_iHitgroup, +}; + +#endif //_INCLUDE_TR_H \ No newline at end of file diff --git a/dlls/fakemeta/forward.cpp b/dlls/fakemeta/forward.cpp index b311e737..73db7ecb 100755 --- a/dlls/fakemeta/forward.cpp +++ b/dlls/fakemeta/forward.cpp @@ -90,6 +90,26 @@ void SetModel_post(edict_t *e, const char *m) RETURN_META(MRES_IGNORED); } +void TraceLine(const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr) +{ + cell vec1[3] = {amx_ftoc(v1[0]), amx_ftoc(v1[1]), amx_ftoc(v1[2])}; + cell vec2[3] = {amx_ftoc(v2[0]), amx_ftoc(v2[1]), amx_ftoc(v2[2])}; + cell retvec1 = MF_PrepareCellArray(vec1, 3); + cell retvec2 = MF_PrepareCellArray(vec2, 3); + FM_ENG_HANDLE(FM_TraceLine, (Engine[FM_TraceLine].at(i), vec1, vec2, fNoMonsters, ENTINDEX(pentToSkip), (cell)ptr)); + RETURN_META(mswi(lastFmRes)); +} + +void TraceLine_post(const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr) +{ + cell vec1[3] = {amx_ftoc(v1[0]), amx_ftoc(v1[1]), amx_ftoc(v1[2])}; + cell vec2[3] = {amx_ftoc(v2[0]), amx_ftoc(v2[1]), amx_ftoc(v2[2])}; + cell retvec1 = MF_PrepareCellArray(vec1, 3); + cell retvec2 = MF_PrepareCellArray(vec2, 3); + FM_ENG_HANDLE(FM_TraceLine, (Engine[FM_TraceLine].at(i), vec1, vec2, fNoMonsters, ENTINDEX(pentToSkip), (cell)ptr)); + RETURN_META(MRES_IGNORED); +} + // pfnModelIndex SIMPLE_INT_HOOK_CONSTSTRING(ModelIndex); @@ -569,8 +589,8 @@ static cell AMX_NATIVE_CALL register_forward(AMX *amx, cell *params) ENGHOOK(EmitAmbientSound); break; case FM_TraceLine: - fId = MF_RegisterSPForwardByName(amx, funcname, FP_ARRAY, FP_ARRAY, FP_CELL, FP_CELL, FP_DONE); -// ENGHOOK(TraceLine); + fId = MF_RegisterSPForwardByName(amx, funcname, FP_ARRAY, FP_ARRAY, FP_CELL, FP_CELL, FP_CELL, FP_DONE); + ENGHOOK(TraceLine); break; case FM_TraceToss: fId = MF_RegisterSPForwardByName(amx, funcname, FP_CELL, FP_CELL, FP_DONE); diff --git a/dlls/fakemeta/sdk/amxxmodule.cpp b/dlls/fakemeta/sdk/amxxmodule.cpp index 1d01d24c..bad7af48 100755 --- a/dlls/fakemeta/sdk/amxxmodule.cpp +++ b/dlls/fakemeta/sdk/amxxmodule.cpp @@ -2681,7 +2681,7 @@ void ValidateMacros_DontCallThis_Smiley() MF_AmxExecv(0, 0, 0, 0, 0); MF_AmxFindPublic(0, 0, 0); MF_AmxAllot(0, 0, 0, 0); - MF_LoadAmxScript(0, 0, 0, 0); + MF_LoadAmxScript(0, 0, 0, 0, 0); MF_UnloadAmxScript(0, 0); MF_RegisterSPForward(0, 0, 0, 0, 0, 0); MF_RegisterSPForwardByName(0, 0, 0, 0, 0, 0); diff --git a/plugins/include/fakemeta.inc b/plugins/include/fakemeta.inc index 4413e34d..08648c0d 100755 --- a/plugins/include/fakemeta.inc +++ b/plugins/include/fakemeta.inc @@ -35,4 +35,10 @@ native register_forward(_forwardType,_function[],_post=0); native forward_return(type,{Float,Sql,Result,_}:...); native engfunc(type,{Float,Sql,Result,_}:...); -native dllfunc(type,{Float,Sql,Result,_}:...); \ No newline at end of file +native dllfunc(type,{Float,Sql,Result,_}:...); + +//only use this with functions that pass a Trace +// get: zero extra params - return int, one extra param = byref float or vector +// set: use anything +native get_tr(Trace:tr, TraceResult:tr_member, {Float,_}:...); +native set_tr(Trace:tr, TraceResult:tr_member, {Float,_}:...); \ No newline at end of file diff --git a/plugins/include/fakemeta_const.inc b/plugins/include/fakemeta_const.inc index 31a7fcac..10bd2d97 100755 --- a/plugins/include/fakemeta_const.inc +++ b/plugins/include/fakemeta_const.inc @@ -437,3 +437,17 @@ enum { FM_CreateInstancedBaseline, // done FM_AllowLagCompensation, // done }; + +enum TraceResult +{ + TR_AllSolid, + TR_StartSolid, + TR_InOpen, + TR_InWater, + TR_flFraction, + TR_vecEndPos, + TR_flPlaneDist, + TR_vecPlaneNormal, + TR_pHit, + TR_iHitgroup, +}; \ No newline at end of file