2
0
mirror of https://github.com/rehlds/metamod-r.git synced 2025-02-12 06:38:47 +03:00
metamod-r/metamod/src/meta_eiface.h

106 lines
3.2 KiB
C
Raw Normal View History

2016-07-26 23:31:47 +07:00
#pragma once
2016-07-26 07:22:47 +07:00
// We use our own versions of the engine/dll interface structs. We add a
// few dummy entries to the end and set them to 0. That way we are
// protected from updates to the HL SDK adding new functions which would
// cause a) the game dll copying arbitrary values from us and b) the game
// dll overwriting our memory when using an old Metamod with a new game
2016-07-26 23:31:47 +07:00
// dll.
2016-07-26 07:22:47 +07:00
// meta_new_dll_functions_t
2016-07-26 23:31:47 +07:00
struct meta_new_dll_functions_t: public NEW_DLL_FUNCTIONS
{
2016-07-26 07:22:47 +07:00
meta_new_dll_functions_t();
meta_new_dll_functions_t(
2016-07-26 23:31:47 +07:00
void (*pfnOnFreeEntPrivateData)(edict_t *),
void (*pfnGameShutdown)(),
int (*pfnShouldCollide)(edict_t *, edict_t *),
void (*pfnCvarValue)(const edict_t *, const char *),
void (*pfnCvarValue2)(const edict_t *, int, const char *, const char *)
2016-07-26 07:22:47 +07:00
);
meta_new_dll_functions_t(const meta_new_dll_functions_t&);
meta_new_dll_functions_t& operator=(const meta_new_dll_functions_t&);
// Fill this object with pointers copied from a NEW_DLL_FUNCTIONS struct.
void set_from(NEW_DLL_FUNCTIONS* pFuncs);
2016-07-26 07:22:47 +07:00
// Copy the pointers from this object to a NEW_DLL_FUNCTIONS struct.
void copy_to(NEW_DLL_FUNCTIONS* pFuncs);
2016-07-26 07:22:47 +07:00
};
inline meta_new_dll_functions_t::meta_new_dll_functions_t()
{
2016-07-26 23:31:47 +07:00
Q_memset(this, 0, sizeof(meta_new_dll_functions_t));
2016-07-26 07:22:47 +07:00
}
inline meta_new_dll_functions_t::meta_new_dll_functions_t(const meta_new_dll_functions_t& _rhs)
{
2016-07-26 23:31:47 +07:00
Q_memcpy(this, &_rhs, sizeof(NEW_DLL_FUNCTIONS));
2016-07-26 07:22:47 +07:00
}
inline meta_new_dll_functions_t& meta_new_dll_functions_t::operator=(const meta_new_dll_functions_t& _rhs)
{
2016-07-26 23:31:47 +07:00
Q_memcpy(this, &_rhs, sizeof(NEW_DLL_FUNCTIONS));
2016-07-26 07:22:47 +07:00
return *this;
}
inline void meta_new_dll_functions_t::set_from(NEW_DLL_FUNCTIONS* _pFuncs)
{
2016-07-26 23:31:47 +07:00
Q_memcpy(this, _pFuncs, sizeof(NEW_DLL_FUNCTIONS));
2016-07-26 07:22:47 +07:00
}
// meta_enginefuncs_t
struct meta_enginefuncs_t : public enginefuncs_t
{
2016-07-26 23:31:47 +07:00
meta_enginefuncs_t() {};
meta_enginefuncs_t(enginefuncs_t* pFuncs)
{
set_from(pFuncs);
};
2016-07-26 07:22:47 +07:00
// Fill this object with pointers copied from an enginefuncs_t struct.
void set_from(enginefuncs_t* pFuncs);
2016-07-26 07:22:47 +07:00
// Copy the pointers from this object to an enginefuncs_t struct.
void copy_to(enginefuncs_t* pFuncs);
2016-07-26 07:22:47 +07:00
};
inline void meta_enginefuncs_t::set_from(enginefuncs_t* _pFuncs)
2016-07-26 07:22:47 +07:00
{
2016-07-26 23:31:47 +07:00
Q_memcpy(this, _pFuncs, sizeof(enginefuncs_t));
2016-07-26 07:22:47 +07:00
}
inline void meta_enginefuncs_t::copy_to(enginefuncs_t* _pFuncs)
2016-07-26 07:22:47 +07:00
{
2016-07-26 23:31:47 +07:00
Q_memcpy(_pFuncs, this, sizeof(enginefuncs_t));
2016-07-26 07:22:47 +07:00
}
// This is a specialisation of the meta_enginefuncs_t struct which is only
// used for the initial copy of the engine functions, i.e. those we get
2016-07-26 23:31:47 +07:00
// passed from the HL engine right at the beginning.
2016-07-26 07:22:47 +07:00
// Since there is only one master copy of engine functions this could be
// implemented as a singleton. This is left as an option for later.
2016-07-26 23:31:47 +07:00
struct HL_enginefuncs_t: public meta_enginefuncs_t
{
2016-07-26 23:31:47 +07:00
HL_enginefuncs_t() {};
2016-07-26 07:22:47 +07:00
// Fill this object with pointers copied from an enginefuncs_t struct
// and fixup the interface.
// For this class this happens in the GiveFptrsToDll() function
// with the pointers passed from the HL engine.
void initialise_interface(enginefuncs_t* pFuncs);
2016-07-26 07:22:47 +07:00
private:
// Moving copy_to() and set_from() to the private space.
void set_from(enginefuncs_t* pFuncs)
{
meta_enginefuncs_t::set_from(pFuncs);
2016-07-26 23:31:47 +07:00
}
void copy_to(enginefuncs_t* pFuncs)
{
meta_enginefuncs_t::copy_to(pFuncs);
2016-07-26 23:31:47 +07:00
}
2016-07-26 07:22:47 +07:00
};