NS: Refactor some bits
This commit is contained in:
parent
2162059352
commit
a35af02494
|
@ -30,7 +30,7 @@ extern BOOL iscombat;
|
|||
TitleManager TitleMan;
|
||||
ParticleManager ParticleMan;
|
||||
|
||||
void MFuncs_Initialize(void);
|
||||
void MFuncs_Initialize(char *base);
|
||||
|
||||
// Native register calls here
|
||||
void AddNatives_MemberFunc();
|
||||
|
@ -86,6 +86,19 @@ void OnAmxxAttach()
|
|||
AddNatives_Structure();
|
||||
AddNatives_General();
|
||||
|
||||
MFuncs_Initialize();
|
||||
char *FuncBase;
|
||||
char FileName[256];
|
||||
DLHANDLE DLLBase;
|
||||
#ifdef __linux__
|
||||
UTIL_Format(FileName, sizeof(FileName), "%s/dlls/ns_i386.so", MF_GetModname());
|
||||
#else
|
||||
UTIL_Format(FileName, sizeof(FileName), "%s\\dlls\\ns.dll", MF_GetModname());
|
||||
#endif
|
||||
|
||||
DLLBase = DLOPEN(FileName);
|
||||
FuncBase = (char *)DLSYM(DLLBase, MAKE_OFFSET(BASE));
|
||||
DLCLOSE(DLLBase);
|
||||
|
||||
MFuncs_Initialize(FuncBase);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,63 +42,10 @@ static void (GenericClass::*MFP_WeldFinished)(float);
|
|||
// AvHGameRules *GetGameRules(void)
|
||||
static void *(*FP_GetGameRules)();
|
||||
|
||||
|
||||
char *FuncBase;
|
||||
|
||||
/**
|
||||
* sizeof(void (detail::GenericClass::*fptr)())
|
||||
* is 8 in GCC. Add an empty void * pointer at
|
||||
* the end to compensate.
|
||||
* Layout in GCC:
|
||||
* union {
|
||||
* void *address; // When this is an address it will always be positive
|
||||
* int vtable_index; // When it is a vtable index it will always be odd = (vindex*2)+1
|
||||
* };
|
||||
* int delta;
|
||||
* -
|
||||
* Delta is the adjustment to the this pointer
|
||||
* For my implementations I will only need it to 0
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
template <typename OutType>
|
||||
inline void set_mfp(OutType &out, void *in)
|
||||
void MFuncs_Initialize(char *base)
|
||||
{
|
||||
union
|
||||
{
|
||||
void *in[2];
|
||||
OutType out;
|
||||
} mfpu;
|
||||
|
||||
mfpu.in[0]=in;
|
||||
mfpu.in[1]=NULL;
|
||||
out=mfpu.out;
|
||||
};
|
||||
#else
|
||||
template <typename OutType>
|
||||
inline void set_mfp(OutType &out, void *in)
|
||||
{
|
||||
out=horrible_cast<OutType>(in);
|
||||
};
|
||||
#endif
|
||||
|
||||
void MFuncs_Initialize(void)
|
||||
{
|
||||
char FileName[256];
|
||||
DLHANDLE DLLBase;
|
||||
#ifdef __linux__
|
||||
UTIL_Format(FileName,sizeof(FileName)-1,"%s/dlls/ns_i386.so",MF_GetModname());
|
||||
#else
|
||||
UTIL_Format(FileName, sizeof(FileName)-1, "%s\\dlls\\ns.dll", MF_GetModname());
|
||||
#endif
|
||||
|
||||
DLLBase=DLOPEN(FileName);
|
||||
FuncBase=(char *)DLSYM(DLLBase, MAKE_OFFSET(BASE));
|
||||
DLCLOSE(DLLBase);
|
||||
|
||||
#define MFP(Offs) (((void *)(((char *)FuncBase)+MAKE_OFFSET(Offs))))
|
||||
|
||||
set_mfp(MFP_Recycle,MFP(MEMBER_RECYCLE));
|
||||
|
||||
|
||||
set_mfp(MFP_WeldFinished,MFP(MEMBER_TRIGGER_WELDABLE));
|
||||
|
||||
// This is not a member function pointer, but use MFP since it
|
||||
|
|
|
@ -233,6 +233,43 @@ inline unsigned char set_private_b(edict_t *pEntity, int offset, unsigned char v
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* sizeof(void (detail::GenericClass::*fptr)())
|
||||
* is 8 in GCC. Add an empty void * pointer at
|
||||
* the end to compensate.
|
||||
* Layout in GCC:
|
||||
* union {
|
||||
* void *address; // When this is an address it will always be positive
|
||||
* int vtable_index; // When it is a vtable index it will always be odd = (vindex*2)+1
|
||||
* };
|
||||
* int delta;
|
||||
* -
|
||||
* Delta is the adjustment to the this pointer
|
||||
* For my implementations I will only need it to 0
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
template <typename OutType>
|
||||
inline void set_mfp(OutType &out, void *in)
|
||||
{
|
||||
union
|
||||
{
|
||||
void *in[2];
|
||||
OutType out;
|
||||
} mfpu;
|
||||
|
||||
mfpu.in[0] = in;
|
||||
mfpu.in[1] = NULL;
|
||||
out = mfpu.out;
|
||||
};
|
||||
#else
|
||||
template <typename OutType>
|
||||
inline void set_mfp(OutType &out, void *in)
|
||||
{
|
||||
out = horrible_cast<OutType>(in);
|
||||
};
|
||||
#endif
|
||||
|
||||
#define MFP(Offs) (((void *)(((char *)base)+MAKE_OFFSET(Offs))))
|
||||
|
||||
#endif // UTILFUNCTIONS_H
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user