mirror of
https://github.com/alliedmodders/metamod-source.git
synced 2024-11-28 10:24:20 +01:00
fix(sourcehook): Fix compilation issues with standalone SourceHook
This commit is contained in:
parent
018033d5a6
commit
994b382754
@ -94,7 +94,7 @@ static bool g_bIsVspBridged = false;
|
||||
|
||||
MetamodSource g_Metamod;
|
||||
PluginId g_PLID = Pl_Console;
|
||||
CSourceHookImpl g_SourceHook;
|
||||
CSourceHookImpl g_SourceHook(mm_LogMessage);
|
||||
ISourceHook *g_SHPtr = &g_SourceHook;
|
||||
SourceMM::ISmmAPI *g_pMetamod = &g_Metamod;
|
||||
|
||||
@ -430,12 +430,13 @@ private:
|
||||
T old_;
|
||||
};
|
||||
|
||||
void
|
||||
int
|
||||
mm_LogMessage(const char *msg, ...)
|
||||
{
|
||||
int ret = 0;
|
||||
static bool g_logging = false;
|
||||
if (g_logging) {
|
||||
return;
|
||||
return ret;
|
||||
}
|
||||
SaveAndSet<bool>(&g_logging, true);
|
||||
|
||||
@ -446,7 +447,7 @@ mm_LogMessage(const char *msg, ...)
|
||||
size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
|
||||
len = std::min<size_t>(len, sizeof(buffer) - 2);
|
||||
if (len < 0) {
|
||||
return;
|
||||
return ret;
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
@ -454,11 +455,14 @@ mm_LogMessage(const char *msg, ...)
|
||||
buffer[len++] = '\n';
|
||||
buffer[len] = '\0';
|
||||
|
||||
|
||||
if (!provider->LogMessage(buffer))
|
||||
{
|
||||
fprintf(stdout, "%s", buffer);
|
||||
ret = fprintf(stdout, "%s", buffer);
|
||||
}
|
||||
provider->ConsolePrint(buffer);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -102,7 +102,7 @@ public:
|
||||
bool
|
||||
mm_DetectGameInformation();
|
||||
|
||||
void
|
||||
int
|
||||
mm_LogMessage(const char *msg, ...);
|
||||
|
||||
int
|
||||
|
@ -132,6 +132,11 @@ enum META_RES
|
||||
|
||||
namespace SourceHook
|
||||
{
|
||||
/**
|
||||
* @brief SourceHook's debug log function
|
||||
*/
|
||||
typedef int (*DebugLogFunc)(const char*, ...);
|
||||
|
||||
/**
|
||||
* @brief Specifies the size (in bytes) for the internal buffer of vafmt(printf-like) function handlers
|
||||
*/
|
||||
@ -194,7 +199,7 @@ namespace SourceHook
|
||||
// SH tries to auto-detect these
|
||||
// If you want to override SH's auto-detection, pass them in yourself
|
||||
PassFlag_RetMem = (1<<6), /**< Object is returned in memory (through hidden first param */
|
||||
PassFlag_RetReg = (1<<7) /**< Object is returned in EAX(:EDX) */
|
||||
PassFlag_RetReg = (1<<7) /**< Object is returned in EAX(:EDX)/RAX(x86_64) */
|
||||
};
|
||||
|
||||
size_t size; //!< Size of the data being passed
|
||||
@ -499,6 +504,8 @@ namespace SourceHook
|
||||
const void *origRetPtr, void *overrideRetPtr) = 0;
|
||||
|
||||
virtual void EndContext(IHookContext *pCtx) = 0;
|
||||
|
||||
virtual void LogDebug(const char *pFormat, ...) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -80,8 +80,9 @@ namespace SourceHook
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
CSourceHookImpl::CSourceHookImpl()
|
||||
CSourceHookImpl::CSourceHookImpl(DebugLogFunc logfunc)
|
||||
{
|
||||
m_LogFunc = logfunc;
|
||||
}
|
||||
CSourceHookImpl::~CSourceHookImpl()
|
||||
{
|
||||
@ -639,6 +640,14 @@ namespace SourceHook
|
||||
ResolvePendingUnloads();
|
||||
}
|
||||
|
||||
void CSourceHookImpl::LogDebug(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
m_LogFunc(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void CSourceHookImpl::CompleteShutdown()
|
||||
{
|
||||
CVector<int> removehooks;
|
||||
|
@ -52,7 +52,6 @@
|
||||
#endif
|
||||
|
||||
#ifdef SH_DEBUG
|
||||
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
@ -133,6 +132,11 @@ enum META_RES
|
||||
|
||||
namespace SourceHook
|
||||
{
|
||||
/**
|
||||
* @brief SourceHook's debug log function
|
||||
*/
|
||||
typedef int (*DebugLogFunc)(const char*, ...);
|
||||
|
||||
/**
|
||||
* @brief Specifies the size (in bytes) for the internal buffer of vafmt(printf-like) function handlers
|
||||
*/
|
||||
@ -500,6 +504,8 @@ namespace SourceHook
|
||||
const void *origRetPtr, void *overrideRetPtr) = 0;
|
||||
|
||||
virtual void EndContext(IHookContext *pCtx) = 0;
|
||||
|
||||
virtual void LogDebug(const char *pFormat, ...) = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -4929,4 +4935,4 @@ namespace SourceHook
|
||||
}
|
||||
|
||||
#endif
|
||||
// The pope is dead. -> :(
|
||||
// The pope is dead. -> :(
|
||||
|
@ -179,9 +179,10 @@ New SH_CALL
|
||||
#include "sourcehook_impl_ciface.h"
|
||||
#include "sourcehook_impl_cvfnptr.h"
|
||||
#include "sourcehook_impl_chookidman.h"
|
||||
#include <cstdio>
|
||||
#include <stdarg.h>
|
||||
|
||||
void mm_LogMessage(const char* msg, ...);
|
||||
extern SourceHook::ISourceHook *g_SHPtr;
|
||||
|
||||
namespace SourceHook
|
||||
{
|
||||
@ -203,10 +204,13 @@ namespace SourceHook
|
||||
template<typename... Args>
|
||||
inline void SH_DEBUG_LOG(SH_LOG log_level, const char* message, Args... args)
|
||||
{
|
||||
#ifndef SOURCEHOOK_TESTS
|
||||
if (log_level < sh_log_level) {
|
||||
return;
|
||||
}
|
||||
mm_LogMessage(message, args...);
|
||||
|
||||
SH_GLOB_SHPTR->LogDebug(message, args...);
|
||||
#endif
|
||||
}
|
||||
|
||||
struct CHookContext : IHookContext
|
||||
@ -322,12 +326,13 @@ namespace SourceHook
|
||||
CHookIDManager m_HookIDMan;
|
||||
HookContextStack m_ContextStack;
|
||||
List<PendingUnload *> m_PendingUnloads;
|
||||
DebugLogFunc m_LogFunc;
|
||||
|
||||
bool SetHookPaused(int hookid, bool paused);
|
||||
CHookManList::iterator RemoveHookManager(CHookManList::iterator iter);
|
||||
List<CVfnPtr>::iterator RevertAndRemoveVfnPtr(List<CVfnPtr>::iterator vfnptr_iter);
|
||||
public:
|
||||
CSourceHookImpl();
|
||||
CSourceHookImpl(DebugLogFunc logfunc = printf);
|
||||
virtual ~CSourceHookImpl();
|
||||
|
||||
/**
|
||||
@ -381,6 +386,8 @@ namespace SourceHook
|
||||
|
||||
void DoRecall();
|
||||
|
||||
void LogDebug(const char *pFormat, ...) override;
|
||||
|
||||
IHookContext *SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origCallAddr, META_RES *statusPtr,
|
||||
META_RES *prevResPtr, META_RES *curResPtr, const void *origRetPtr, void *overrideRetPtr);
|
||||
|
||||
|
@ -4,6 +4,11 @@ import os
|
||||
for cxx in MMS.all_targets:
|
||||
name = 'test_sourcehook'
|
||||
binary = MMS.Program(cxx, name)
|
||||
|
||||
binary.compiler.defines += [
|
||||
'SOURCEHOOK_TESTS',
|
||||
]
|
||||
|
||||
binary.compiler.cxxincludes += [
|
||||
os.path.join(builder.sourcePath, 'core', 'sourcehook'),
|
||||
]
|
||||
@ -19,6 +24,7 @@ for cxx in MMS.all_targets:
|
||||
'../sourcehook_impl_chookidman.cpp',
|
||||
'../sourcehook_impl_cproto.cpp',
|
||||
'../sourcehook_impl_cvfnptr.cpp',
|
||||
'../sourcehook_hookmangen.cpp',
|
||||
'test1.cpp',
|
||||
'test2.cpp',
|
||||
'test3.cpp',
|
||||
@ -36,7 +42,9 @@ for cxx in MMS.all_targets:
|
||||
'testrefret.cpp',
|
||||
'testvphooks.cpp',
|
||||
]
|
||||
if binary.compiler.target.arch == 'x86':
|
||||
binary.sources += ['../sourcehook_hookmangen.cpp']
|
||||
if cxx.target.arch == 'x86':
|
||||
binary.sources += ['../sourcehook_hookmangen_x86.cpp']
|
||||
elif binary.compiler.target.arch == 'x86_64':
|
||||
binary.sources += ['../sourcehook_hookmangen_x86_64.cpp']
|
||||
|
||||
builder.Add(binary)
|
||||
|
Loading…
Reference in New Issue
Block a user