Fixed traceresults and trace hooks..

This commit is contained in:
Steve Dudenhoeffer 2004-09-15 18:40:18 +00:00
parent 0ea68c81dc
commit 1485014229
4 changed files with 53 additions and 52 deletions

View File

@ -1,5 +1,7 @@
#include "fakemeta_amxx.h" #include "fakemeta_amxx.h"
TraceResult *gfm_tr;
/*enum /*enum
{ {
TR_AllSolid, TR_AllSolid,
@ -16,60 +18,59 @@
static cell AMX_NATIVE_CALL set_tr(AMX *amx, cell *params) static cell AMX_NATIVE_CALL set_tr(AMX *amx, cell *params)
{ {
cell *cPtr = &params[1]; int type = params[1];
int type = params[2]; //TraceResult *tr = (TraceResult*)((void *)cPtr);
TraceResult *tr = (TraceResult*)((void *)cPtr);
if (*params / sizeof(cell) < 3) if (*params / sizeof(cell) < 2)
return 0; //TODO: Error return 0; //TODO: Error
cell *ptr = MF_GetAmxAddr(amx, params[3]); cell *ptr = MF_GetAmxAddr(amx, params[2]);
edict_t *e = 0; edict_t *e = 0;
switch (type) switch (type)
{ {
case TR_AllSolid: case TR_AllSolid:
{ {
tr->fAllSolid = *ptr; gfm_tr->fAllSolid = *ptr;
return 1; return 1;
break; break;
} }
case TR_StartSolid: case TR_StartSolid:
{ {
return tr->fStartSolid; return gfm_tr->fStartSolid;
break; break;
} }
case TR_InWater: case TR_InWater:
{ {
tr->fInWater = *ptr; gfm_tr->fInWater = *ptr;
return 1; return 1;
break; break;
} }
case TR_flFraction: case TR_flFraction:
{ {
tr->flFraction = amx_ctof(*ptr); gfm_tr->flFraction = amx_ctof(*ptr);
return 1; return 1;
break; break;
} }
case TR_vecEndPos: case TR_vecEndPos:
{ {
tr->vecEndPos.x = amx_ctof(ptr[0]); gfm_tr->vecEndPos.x = amx_ctof(ptr[0]);
tr->vecEndPos.y = amx_ctof(ptr[1]); gfm_tr->vecEndPos.y = amx_ctof(ptr[1]);
tr->vecEndPos.z = amx_ctof(ptr[2]); gfm_tr->vecEndPos.z = amx_ctof(ptr[2]);
return 1; return 1;
break; break;
} }
case TR_flPlaneDist: case TR_flPlaneDist:
{ {
tr->flPlaneDist = amx_ctof(*ptr); gfm_tr->flPlaneDist = amx_ctof(*ptr);
return 1; return 1;
break; break;
} }
case TR_vecPlaneNormal: case TR_vecPlaneNormal:
{ {
tr->vecPlaneNormal.x = amx_ctof(ptr[0]); gfm_tr->vecPlaneNormal.x = amx_ctof(ptr[0]);
tr->vecPlaneNormal.y = amx_ctof(ptr[1]); gfm_tr->vecPlaneNormal.y = amx_ctof(ptr[1]);
tr->vecPlaneNormal.z = amx_ctof(ptr[2]); gfm_tr->vecPlaneNormal.z = amx_ctof(ptr[2]);
return 1; return 1;
break; break;
} }
@ -78,13 +79,13 @@ static cell AMX_NATIVE_CALL set_tr(AMX *amx, cell *params)
e = INDEXENT(*ptr); e = INDEXENT(*ptr);
if (!e || FNullEnt(e)) if (!e || FNullEnt(e))
return 0; //TODO: return error return 0; //TODO: return error
tr->pHit = e; gfm_tr->pHit = e;
return 1; return 1;
break; break;
} }
case TR_iHitgroup: case TR_iHitgroup:
{ {
tr->iHitgroup = *ptr; gfm_tr->iHitgroup = *ptr;
return 1; return 1;
break; break;
} }
@ -98,68 +99,66 @@ static cell AMX_NATIVE_CALL set_tr(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_tr(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_tr(AMX *amx, cell *params)
{ {
cell *cPtr = &params[1]; int type = params[1];
int type = params[2];
TraceResult *tr = (TraceResult*)((void *)cPtr);
cell *ptr = 0; cell *ptr = 0;
switch (type) switch (type)
{ {
case TR_AllSolid: case TR_AllSolid:
{ {
return tr->fAllSolid; return gfm_tr->fAllSolid;
break; break;
} }
case TR_StartSolid: case TR_StartSolid:
{ {
return tr->fStartSolid; return gfm_tr->fStartSolid;
break; break;
} }
case TR_InWater: case TR_InWater:
{ {
return tr->fInWater; return gfm_tr->fInWater;
break; break;
} }
case TR_flFraction: case TR_flFraction:
{ {
ptr = MF_GetAmxAddr(amx, params[3]); ptr = MF_GetAmxAddr(amx, params[2]);
*ptr = amx_ftoc(tr->flFraction); *ptr = amx_ftoc(gfm_tr->flFraction);
return 1; return 1;
break; break;
} }
case TR_vecEndPos: case TR_vecEndPos:
{ {
ptr = MF_GetAmxAddr(amx, params[3]); ptr = MF_GetAmxAddr(amx, params[2]);
ptr[0] = amx_ftoc(tr->vecEndPos.x); ptr[0] = amx_ftoc(gfm_tr->vecEndPos.x);
ptr[1] = amx_ftoc(tr->vecEndPos.y); ptr[1] = amx_ftoc(gfm_tr->vecEndPos.y);
ptr[2] = amx_ftoc(tr->vecEndPos.z); ptr[2] = amx_ftoc(gfm_tr->vecEndPos.z);
return 1; return 1;
break; break;
} }
case TR_flPlaneDist: case TR_flPlaneDist:
{ {
ptr = MF_GetAmxAddr(amx, params[3]); ptr = MF_GetAmxAddr(amx, params[2]);
*ptr = amx_ftoc(tr->flPlaneDist); *ptr = amx_ftoc(gfm_tr->flPlaneDist);
return 1; return 1;
break; break;
} }
case TR_vecPlaneNormal: case TR_vecPlaneNormal:
{ {
ptr = MF_GetAmxAddr(amx, params[3]); ptr = MF_GetAmxAddr(amx, params[2]);
ptr[0] = amx_ftoc(tr->vecPlaneNormal.x); ptr[0] = amx_ftoc(gfm_tr->vecPlaneNormal.x);
ptr[1] = amx_ftoc(tr->vecPlaneNormal.y); ptr[1] = amx_ftoc(gfm_tr->vecPlaneNormal.y);
ptr[2] = amx_ftoc(tr->vecPlaneNormal.z); ptr[2] = amx_ftoc(gfm_tr->vecPlaneNormal.z);
return 1; return 1;
break; break;
} }
case TR_pHit: case TR_pHit:
{ {
return ENTINDEX(tr->pHit); return ENTINDEX(gfm_tr->pHit);
break; break;
} }
case TR_iHitgroup: case TR_iHitgroup:
{ {
return tr->iHitgroup; return gfm_tr->iHitgroup;
break; break;
} }
default: default:

View File

@ -1,6 +1,8 @@
#ifndef _INCLUDE_TR_H #ifndef _INCLUDE_TR_H
#define _INCLUDE_TR_H #define _INCLUDE_TR_H
extern TraceResult *gfm_tr;
enum enum
{ {
TR_AllSolid, TR_AllSolid,

View File

@ -92,22 +92,22 @@ void SetModel_post(edict_t *e, const char *m)
void TraceLine(const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr) void TraceLine(const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr)
{ {
TRACE_LINE(v1, v2, fNoMonsters, pentToSkip, ptr); //from fun module - prevents crash? - t(+)rget/freecode /*
cell vec1[3] = {amx_ftoc(v1[0]), amx_ftoc(v1[1]), amx_ftoc(v1[2])}; TRACE_LINE(v1, v2, fNoMonsters, pentToSkip, ptr); //from fun module - prevents crash? - t(+)rget/freecode // well i guess that's what you get for listening, isnt it? =/
cell vec2[3] = {amx_ftoc(v2[0]), amx_ftoc(v2[1]), amx_ftoc(v2[2])}; */
cell retvec1 = MF_PrepareCellArray(vec1, 3); gfm_tr=ptr;
cell retvec2 = MF_PrepareCellArray(vec2, 3); PREPARE_VECTOR(v1);
FM_ENG_HANDLE(FM_TraceLine, (Engine[FM_TraceLine].at(i), retvec1, retvec2, fNoMonsters, ENTINDEX(pentToSkip), (cell)ptr)); PREPARE_VECTOR(v2);
FM_ENG_HANDLE(FM_TraceLine, (Engine[FM_TraceLine].at(i), p_v1, p_v2, fNoMonsters, ENTINDEX(pentToSkip) /*, (cell)ptr*/));
RETURN_META(mswi(lastFmRes)); RETURN_META(mswi(lastFmRes));
} }
void TraceLine_post(const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr) 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])}; gfm_tr=ptr;
cell vec2[3] = {amx_ftoc(v2[0]), amx_ftoc(v2[1]), amx_ftoc(v2[2])}; PREPARE_VECTOR(v1);
cell retvec1 = MF_PrepareCellArray(vec1, 3); PREPARE_VECTOR(v2);
cell retvec2 = MF_PrepareCellArray(vec2, 3); FM_ENG_HANDLE_POST(FM_TraceLine, (EnginePost[FM_TraceLine].at(i), p_v1, p_v2, fNoMonsters, ENTINDEX(pentToSkip)/*, (cell)ptr*/));
FM_ENG_HANDLE(FM_TraceLine, (Engine[FM_TraceLine].at(i), retvec1, retvec2, fNoMonsters, ENTINDEX(pentToSkip), (cell)ptr));
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
@ -590,7 +590,7 @@ static cell AMX_NATIVE_CALL register_forward(AMX *amx, cell *params)
ENGHOOK(EmitAmbientSound); ENGHOOK(EmitAmbientSound);
break; break;
case FM_TraceLine: case FM_TraceLine:
fId = MF_RegisterSPForwardByName(amx, funcname, FP_ARRAY, FP_ARRAY, FP_CELL, FP_CELL, FP_CELL, FP_DONE); fId = MF_RegisterSPForwardByName(amx, funcname, FP_ARRAY, FP_ARRAY, FP_CELL, FP_CELL, FP_DONE);
ENGHOOK(TraceLine); ENGHOOK(TraceLine);
break; break;
case FM_TraceToss: case FM_TraceToss:

View File

@ -40,5 +40,5 @@ native dllfunc(type,{Float,Sql,Result,_}:...);
//only use this with functions that pass a Trace //only use this with functions that pass a Trace
// get: zero extra params - return int, one extra param = byref float or vector // get: zero extra params - return int, one extra param = byref float or vector
// set: use anything // set: use anything
native get_tr(Trace:tr, TraceResult:tr_member, {Float,_}:...); native get_tr(TraceResult:tr_member, {Float,_}:...);
native set_tr(Trace:tr, TraceResult:tr_member, {Float,_}:...); native set_tr(TraceResult:tr_member, {Float,_}:...);