mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-25 06:15:37 +03:00
added request at26450
This commit is contained in:
parent
7dae023a98
commit
9283cbe1c2
@ -207,6 +207,16 @@
|
||||
RelativePath="..\..\plugins\include\fakemeta_stocks.inc">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="global"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\glb.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\glb.h">
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
|
@ -5,12 +5,14 @@ edict_t *g_player_edicts[33]; // Used for INDEXENT() forward.
|
||||
void OnAmxxAttach()
|
||||
{
|
||||
initialze_offsets();
|
||||
initialize_glb_offsets();
|
||||
MF_AddNatives(engfunc_natives);
|
||||
MF_AddNatives(dllfunc_natives);
|
||||
MF_AddNatives(pev_natives);
|
||||
MF_AddNatives(forward_natives);
|
||||
MF_AddNatives(pdata_natives);
|
||||
MF_AddNatives(tr_Natives);
|
||||
MF_AddNatives(glb_natives);
|
||||
}
|
||||
int GetHullBounds(int hullnumber, float *mins, float *maxs);
|
||||
// sawce: Do not null out the forward for ServerActivate. It's required for the INDEXENT() fix. (I don't think ServerActivate is planned on being forwarded anyway)
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "pev.h"
|
||||
#include "forward.h"
|
||||
#include "fm_tr.h"
|
||||
#include "glb.h"
|
||||
|
||||
extern edict_t *g_player_edicts[33];
|
||||
|
||||
@ -45,6 +46,7 @@ extern AMX_NATIVE_INFO forward_natives[];
|
||||
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 TraceResult g_tr;
|
||||
|
||||
/* Wouldnt modifying the table AFTER it's memcpy'd be ... pointless?
|
||||
|
166
dlls/fakemeta/glb.cpp
Normal file
166
dlls/fakemeta/glb.cpp
Normal file
@ -0,0 +1,166 @@
|
||||
#include "fakemeta_amxx.h"
|
||||
|
||||
static int g_glob_offset_table[glb_end_pchar] = {-1};
|
||||
|
||||
#define DO_OFFSET_GLB(offset) g_glob_offset_table[offset] = offsetof(globalvars_t, offset)
|
||||
|
||||
void initialize_glb_offsets()
|
||||
{
|
||||
DO_OFFSET_GLB(trace_hitgroup);
|
||||
DO_OFFSET_GLB(trace_flags);
|
||||
DO_OFFSET_GLB(msg_entity);
|
||||
DO_OFFSET_GLB(cdAudioTrack);
|
||||
DO_OFFSET_GLB(maxClients);
|
||||
DO_OFFSET_GLB(maxEntities);
|
||||
DO_OFFSET_GLB(time);
|
||||
DO_OFFSET_GLB(frametime);
|
||||
DO_OFFSET_GLB(force_retouch);
|
||||
DO_OFFSET_GLB(deathmatch);
|
||||
DO_OFFSET_GLB(coop);
|
||||
DO_OFFSET_GLB(teamplay);
|
||||
DO_OFFSET_GLB(serverflags);
|
||||
DO_OFFSET_GLB(found_secrets);
|
||||
DO_OFFSET_GLB(trace_allsolid);
|
||||
DO_OFFSET_GLB(trace_startsolid);
|
||||
DO_OFFSET_GLB(trace_fraction);
|
||||
DO_OFFSET_GLB(trace_plane_dist);
|
||||
DO_OFFSET_GLB(trace_inopen);
|
||||
DO_OFFSET_GLB(trace_inwater);
|
||||
DO_OFFSET_GLB(trace_ent);
|
||||
DO_OFFSET_GLB(v_forward);
|
||||
DO_OFFSET_GLB(v_up);
|
||||
DO_OFFSET_GLB(v_right);
|
||||
DO_OFFSET_GLB(trace_endpos);
|
||||
DO_OFFSET_GLB(trace_plane_normal);
|
||||
DO_OFFSET_GLB(vecLandmarkOffset);
|
||||
DO_OFFSET_GLB(mapname);
|
||||
DO_OFFSET_GLB(startspot);
|
||||
DO_OFFSET_GLB(pStringBase);
|
||||
}
|
||||
|
||||
#define GET_OFFS(v,o) ((char *)v + o)
|
||||
|
||||
static cell AMX_NATIVE_CALL amx_glb(AMX *amx, cell *params)
|
||||
{
|
||||
int iSwitch = params[1];
|
||||
|
||||
if (iSwitch <= glb_start_int || iSwitch >= glb_end_pchar)
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Undefined global index: %d", iSwitch);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int offset = g_glob_offset_table[iSwitch];
|
||||
if (offset == -1)
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Undefined global index: %d", iSwitch);
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
Ret_Int = (1<<0),
|
||||
Ret_Float = (1<<1),
|
||||
Ret_Vec = (1<<2),
|
||||
Ret_Edict = (1<<3),
|
||||
Ret_PChar = (1<<4)
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
int i;
|
||||
float f;
|
||||
const char *c;
|
||||
} rets;
|
||||
Vector vec;
|
||||
|
||||
int Valtype = 0;
|
||||
|
||||
if (iSwitch > glb_start_int && iSwitch < glb_end_int)
|
||||
{
|
||||
rets.i = *(int *)GET_OFFS(gpGlobals, offset);
|
||||
Valtype = Ret_Int;
|
||||
}
|
||||
else if (iSwitch > glb_start_float && iSwitch < glb_end_float)
|
||||
{
|
||||
rets.f = *(float *)GET_OFFS(gpGlobals, offset);
|
||||
Valtype = Ret_Float;
|
||||
}
|
||||
else if (iSwitch > glb_start_edict && iSwitch < glb_end_edict)
|
||||
{
|
||||
edict_t *e = *(edict_t **)GET_OFFS(gpGlobals, offset);
|
||||
rets.i = ENTINDEX(e);
|
||||
Valtype = Ret_Int | Ret_Edict;
|
||||
}
|
||||
else if (iSwitch > glb_start_vector && iSwitch < glb_end_vector)
|
||||
{
|
||||
vec = *(vec3_t *)GET_OFFS(gpGlobals, offset);
|
||||
Valtype = Ret_Vec;
|
||||
}
|
||||
else if (iSwitch > glb_start_string && iSwitch < glb_end_string)
|
||||
{
|
||||
rets.c = STRING(*(string_t *)GET_OFFS(gpGlobals, offset));
|
||||
Valtype = Ret_PChar;
|
||||
}
|
||||
else if (iSwitch > glb_start_pchar && iSwitch < glb_end_pchar)
|
||||
{
|
||||
rets.c = *(const char **)GET_OFFS(gpGlobals, offset);
|
||||
Valtype = Ret_PChar;
|
||||
}
|
||||
|
||||
size_t paramnum = params[0] / sizeof(cell) - 1;
|
||||
|
||||
if (paramnum == 0)
|
||||
{
|
||||
//return an int
|
||||
if (Valtype & Ret_Int)
|
||||
{
|
||||
return rets.i;
|
||||
} else {
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid return type");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (paramnum == 1)
|
||||
{
|
||||
//return a byref float - usually
|
||||
cell *addr = MF_GetAmxAddr(amx, params[2]);
|
||||
if (Valtype == Ret_Float)
|
||||
{
|
||||
*addr = amx_ftoc(rets.f);
|
||||
}
|
||||
else if (Valtype == Ret_Vec)
|
||||
{
|
||||
addr[0] = amx_ftoc(vec.x);
|
||||
addr[1] = amx_ftoc(vec.y);
|
||||
addr[2] = amx_ftoc(vec.z);
|
||||
} else {
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid return type");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else if (paramnum == 2)
|
||||
{
|
||||
cell size = *(MF_GetAmxAddr(amx, params[3]));
|
||||
if (Valtype == Ret_PChar)
|
||||
{
|
||||
const char *str = rets.c;
|
||||
if (!str)
|
||||
str = "";
|
||||
return MF_SetAmxString(amx, params[2], str, size);
|
||||
}
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid return type");
|
||||
}
|
||||
|
||||
//if we got here, something happened
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Unknown global index or return combination %d", iSwitch);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
AMX_NATIVE_INFO glb_natives[] =
|
||||
{
|
||||
{"global_get", amx_glb},
|
||||
{NULL, NULL},
|
||||
};
|
52
dlls/fakemeta/glb.h
Normal file
52
dlls/fakemeta/glb.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef _INCLUDE_GLB_H
|
||||
#define _INCLUDE_GLB_H
|
||||
|
||||
enum glb_pointers
|
||||
{
|
||||
glb_start_int = 0,
|
||||
trace_hitgroup,
|
||||
trace_flags,
|
||||
msg_entity,
|
||||
cdAudioTrack,
|
||||
maxClients,
|
||||
maxEntities,
|
||||
glb_end_int,
|
||||
glb_start_float,
|
||||
time,
|
||||
frametime,
|
||||
force_retouch,
|
||||
deathmatch,
|
||||
coop,
|
||||
teamplay,
|
||||
serverflags,
|
||||
found_secrets,
|
||||
trace_allsolid,
|
||||
trace_startsolid,
|
||||
trace_fraction,
|
||||
trace_plane_dist,
|
||||
trace_inopen,
|
||||
trace_inwater,
|
||||
glb_end_float,
|
||||
glb_start_edict,
|
||||
trace_ent,
|
||||
glb_end_edict,
|
||||
glb_start_vector,
|
||||
v_forward,
|
||||
v_up,
|
||||
v_right,
|
||||
trace_endpos,
|
||||
trace_plane_normal,
|
||||
vecLandmarkOffset,
|
||||
glb_end_vector,
|
||||
glb_start_string,
|
||||
mapname,
|
||||
startspot,
|
||||
glb_end_string,
|
||||
glb_start_pchar,
|
||||
pStringBase,
|
||||
glb_end_pchar
|
||||
};
|
||||
|
||||
void initialize_glb_offsets();
|
||||
|
||||
#endif /* _INCLUDE_GLB_H */
|
Loading…
Reference in New Issue
Block a user