64-bit support for CSGO on Linux and macOS (#705)
This commit is contained in:
+37
-190
@@ -36,20 +36,7 @@
|
||||
|
||||
|
||||
#define SMINTERFACE_BINTOOLS_NAME "IBinTools"
|
||||
#define SMINTERFACE_BINTOOLS_VERSION 3
|
||||
|
||||
#if defined METAMOD_PLAPI_VERSION
|
||||
#ifndef HOOKING_ENABLED
|
||||
#define HOOKING_ENABLED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined HOOKING_ENABLED
|
||||
#include <sourcehook_pibuilder.h>
|
||||
|
||||
#define SMINTERFACE_BINTOOLS2_NAME "IBinTools2"
|
||||
#define SMINTERFACE_BINTOOLS2_VERSION 1
|
||||
#endif
|
||||
#define SMINTERFACE_BINTOOLS_VERSION 4
|
||||
|
||||
/**
|
||||
* @brief Function calling encoding utilities
|
||||
@@ -82,15 +69,42 @@ namespace SourceMod
|
||||
#define PASSFLAG_ODTOR (1<<2) /**< Object has a destructor */
|
||||
#define PASSFLAG_OCTOR (1<<3) /**< Object has a constructor */
|
||||
#define PASSFLAG_OASSIGNOP (1<<4) /**< Object has an assignment operator */
|
||||
#define PASSFLAG_OCOPYCTOR (1<<5) /**< Object has non-trivial copy constructor */
|
||||
#define PASSFLAG_OUNALIGN (1<<6) /**< Object contains unaligned fields */
|
||||
|
||||
#define FNFLAG_VARARGS (1<<0) /**< Function has variable arguments */
|
||||
|
||||
enum class ObjectField
|
||||
{
|
||||
Boolean,
|
||||
Int8,
|
||||
Int16,
|
||||
Int32,
|
||||
Int64,
|
||||
Pointer,
|
||||
Float,
|
||||
Double
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Parameter passing information
|
||||
*/
|
||||
struct PassInfo
|
||||
{
|
||||
PassInfo() : fields(nullptr), numFields(0)
|
||||
{ }
|
||||
|
||||
PassInfo(PassType type, unsigned int flags, size_t size, ObjectField *fields, unsigned int numFields)
|
||||
: type(type), flags(flags), size(size), fields(fields), numFields(numFields)
|
||||
{ }
|
||||
|
||||
PassType type; /**< PassType value */
|
||||
unsigned int flags; /**< Pass/return flags */
|
||||
size_t size; /**< Size of the data being passed */
|
||||
ObjectField *fields; /**< List of fields for PassType_Object.
|
||||
Can be ignored if size of object is > 16 bytes */
|
||||
unsigned int numFields; /**< Number of object fields.
|
||||
Can be ignored if size of object is > 16 bytes */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -149,109 +163,13 @@ namespace SourceMod
|
||||
* @brief Destroys all resources used by this object.
|
||||
*/
|
||||
virtual void Destroy() =0;
|
||||
|
||||
#if defined HOOKING_ENABLED
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gets the Return type info.
|
||||
*
|
||||
* @return A PassInfo pointer.
|
||||
* @brief Returns the function's flags.
|
||||
*/
|
||||
virtual const SourceHook::PassInfo *GetSHReturnInfo() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the calling convention.
|
||||
*
|
||||
* @return CallConvention value.
|
||||
*/
|
||||
virtual SourceHook::ProtoInfo::CallConvention GetSHCallConvention() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns parameter info.
|
||||
*
|
||||
* @param num Parameter number to get (starting from 0).
|
||||
* @return A PassInfo pointer.
|
||||
*/
|
||||
virtual const SourceHook::PassInfo *GetSHParamInfo(unsigned int num) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the offset of a given param.
|
||||
*
|
||||
* @param num Parameter number to get (starting from 0).
|
||||
* @return Parameter offset.
|
||||
*/
|
||||
virtual unsigned int GetParamOffset(unsigned int num) =0;
|
||||
|
||||
#endif
|
||||
virtual unsigned int GetFunctionFlags() =0;
|
||||
};
|
||||
|
||||
#if defined HOOKING_ENABLED
|
||||
|
||||
/**
|
||||
* @brief Delegate object that intermediates between SourceHook and the callback function.
|
||||
*/
|
||||
class ISMDelegate : public SourceHook::ISHDelegate
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* @brief Internally used callback function - Do not call!
|
||||
*/
|
||||
virtual void Call() =0; /**< Do not call */
|
||||
public:
|
||||
/**
|
||||
* @brief Retrieves the User data buffer.
|
||||
*
|
||||
* @return User data pointer.
|
||||
*/
|
||||
virtual void *GetUserData() =0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Wrapper around a virtual hook.
|
||||
*/
|
||||
class IHookWrapper
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Creates a hook delegate to pass to SourceHook.
|
||||
*
|
||||
* @param data User data pointer.
|
||||
* @return A new ISMDelegate for the hook.
|
||||
*/
|
||||
virtual ISMDelegate *CreateDelegate(void *data) =0;
|
||||
|
||||
/**
|
||||
* @brief Gets the number of params in the hooked function.
|
||||
*
|
||||
* @return Number of params.
|
||||
*/
|
||||
virtual unsigned int GetParamCount() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the offset of a given param.
|
||||
*
|
||||
* @param argnum Parameter number from 0 to GetParamCount-1.
|
||||
* @param size Optional buffer to store the size of the param.
|
||||
* @return Parameter offset or -1 on error.
|
||||
*/
|
||||
virtual unsigned int GetParamOffset(unsigned int argnum, unsigned int *size) =0;
|
||||
|
||||
/**
|
||||
* @brief Initiates a recall on the function.
|
||||
*
|
||||
* @param params Parameter buffer.
|
||||
* @param retval Buffer to store the return value in.
|
||||
*/
|
||||
virtual void PerformRecall(void *params, void *retval) =0;
|
||||
|
||||
/**
|
||||
* @brief Destroys this HookWrapper.
|
||||
*/
|
||||
virtual void Destroy() =0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Binary tools interface.
|
||||
*/
|
||||
@@ -280,13 +198,15 @@ namespace SourceMod
|
||||
* @param retInfo Return type information, or NULL for void.
|
||||
* @param paramInfo Array of parameters.
|
||||
* @param numParams Number of parameters in the array.
|
||||
* @param fnFlags Function flags. See FNFLAG_* above.
|
||||
* @return A new ICallWrapper function.
|
||||
*/
|
||||
virtual ICallWrapper *CreateCall(void *address,
|
||||
CallConvention cv,
|
||||
const PassInfo *retInfo,
|
||||
const PassInfo paramInfo[],
|
||||
unsigned int numParams) =0;
|
||||
unsigned int numParams,
|
||||
unsigned int fnFlags=0) =0;
|
||||
|
||||
/**
|
||||
* @brief Creates a vtable call decoder.
|
||||
@@ -302,6 +222,7 @@ namespace SourceMod
|
||||
* @param retInfo Return type information, or NULL for void.
|
||||
* @param paramInfo Array of parameters.
|
||||
* @param numParams Number of parameters in the array.
|
||||
* @param fnFlags Function flags. See FNFLAG_* above.
|
||||
* @return A new ICallWrapper function.
|
||||
*/
|
||||
virtual ICallWrapper *CreateVCall(unsigned int vtblIdx,
|
||||
@@ -309,84 +230,10 @@ namespace SourceMod
|
||||
unsigned int thisOffs,
|
||||
const PassInfo *retInfo,
|
||||
const PassInfo paramInfo[],
|
||||
unsigned int numParams) =0;
|
||||
unsigned int numParams,
|
||||
unsigned int fnFlags=0) =0;
|
||||
};
|
||||
|
||||
#if defined HOOKING_ENABLED
|
||||
|
||||
/**
|
||||
* @brief Binary tools interface.
|
||||
*/
|
||||
class IBinTools2 : public SMInterface
|
||||
{
|
||||
public:
|
||||
virtual const char *GetInterfaceName()
|
||||
{
|
||||
return SMINTERFACE_BINTOOLS2_NAME;
|
||||
}
|
||||
virtual unsigned int GetInterfaceVersion()
|
||||
{
|
||||
return SMINTERFACE_BINTOOLS2_VERSION;
|
||||
}
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Creates a call decoder.
|
||||
*
|
||||
* Note: CallConv_ThisCall requires an implicit first parameter
|
||||
* of PassType_Basic / PASSFLAG_BYVAL / sizeof(void *). However,
|
||||
* this should only be given to the Execute() function, and never
|
||||
* listed in the paramInfo array.
|
||||
*
|
||||
* @param address Address to use as a call.
|
||||
* @param protoInfo Parameter type information.
|
||||
* @return A new ICallWrapper function.
|
||||
*/
|
||||
virtual ICallWrapper *CreateCall(void *address,
|
||||
const SourceHook::ProtoInfo *protoInfo) =0;
|
||||
|
||||
/**
|
||||
* @brief Creates a vtable call decoder.
|
||||
*
|
||||
* Note: CallConv_ThisCall requires an implicit first parameter
|
||||
* of PassType_Basic / PASSFLAG_BYVAL / sizeof(void *). However,
|
||||
* this should only be given to the Execute() function, and never
|
||||
* listed in the paramInfo array.
|
||||
*
|
||||
* @param protoInfo Parameter type information.
|
||||
* @param info Function offset information.
|
||||
* @return A new ICallWrapper function.
|
||||
*/
|
||||
virtual ICallWrapper *CreateVirtualCall(const SourceHook::ProtoInfo *protoInfo,
|
||||
const SourceHook::MemFuncInfo *info) =0;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Callback function pointer for Virtual Hooks.
|
||||
*
|
||||
* @param wrapper Call wrapper for this hook.
|
||||
* @param deleg Delegate for this call.
|
||||
* @param params Array of parameters.
|
||||
* @param ret Storage buffer for the return value.
|
||||
*/
|
||||
typedef void (*VIRTUAL_HOOK_PROTO)(IHookWrapper *wrapper, ISMDelegate *deleg, void *params, void *ret);
|
||||
|
||||
/**
|
||||
* @brief Creates a hook on a virtual function.
|
||||
*
|
||||
* @param pSH Global SourceHook pointer.
|
||||
* @param protoInfo Parameter type information.
|
||||
* @param info Function offset information.
|
||||
* @param f Callback function pointer.
|
||||
*/
|
||||
virtual IHookWrapper *CreateVirtualHook(SourceHook::ISourceHook *pSH,
|
||||
const SourceHook::ProtoInfo *protoInfo,
|
||||
const SourceHook::MemFuncInfo *info,
|
||||
VIRTUAL_HOOK_PROTO f) =0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif //_INCLUDE_SMEXT_BINTOOLS_H_
|
||||
|
||||
Reference in New Issue
Block a user