Fix hook callback mistake + fix s2 sample compilation

This commit is contained in:
Kenzzer 2025-08-15 19:54:56 +00:00
parent b0d5161dad
commit 87913ea4c7
No known key found for this signature in database
GPG Key ID: 64C3FD4332686DC1
4 changed files with 15 additions and 18 deletions

View File

@ -417,7 +417,7 @@ KHook::Return<void> Source2Provider::Hook_UnregisterLoopMode(IEngineServiceMgr*,
KHook::Return<ILoopMode*> Source2Provider::Hook_CreateLoopModePost(ILoopModeFactory*)
{
auto pLoopMode = (ILoopMode*)KHook::GetOriginalValuePtr();
auto pLoopMode = *(ILoopMode**)KHook::GetOriginalValuePtr();
m_LoopInit.Add(pLoopMode);
m_LoopShutdown.Add(pLoopMode);

View File

@ -387,7 +387,7 @@ public:
* I'm pretty sure we'll die horribly.
*/
if (!result)
if (result != INIT_OK)
{
gamedll_bridge->Unload();
mm_UnloadMetamodLibrary();
@ -401,7 +401,6 @@ public:
}
mm_PatchDllInit(false);
return result;
}
};
@ -523,43 +522,42 @@ mm_PatchDllInit(bool patch)
{
void **vtable_src;
void **vtable_dest;
std::int32_t mfp;
std::int32_t src_mfp;
if (g_is_source2)
{
mfp = KHook::GetVtableIndex(&ISource2Server::Init);
src_mfp = KHook::GetVtableIndex(&ISource2Server::Init);
}
else
{
mfp = KHook::GetVtableIndex(&IServerGameDLL::DLLInit);
src_mfp = KHook::GetVtableIndex(&IServerGameDLL::DLLInit);
}
assert(mfp != -1);
assert(src_mfp != -1);
if (g_is_source2)
{
vtable_src = *(void ***)&is2s_thunk;
vtable_dest = *(void ***)config_iface;
}
else
{
vtable_src = *(void ***)&isgd_thunk;
vtable_dest = *(void ***)gamedll_iface;
}
vtable_dest = *(void ***)gamedll_iface;
KHook::Memory::SetAccess(&vtable_dest[mfp],
KHook::Memory::SetAccess(&vtable_dest[src_mfp],
sizeof(void*),
KHook::Memory::Flags::READ | KHook::Memory::Flags::WRITE | KHook::Memory::Flags::EXECUTE);
if (patch)
{
assert(isgd_orig_init == NULL);
isgd_orig_init = vtable_dest[mfp];
vtable_dest[mfp] = vtable_src[mfp];
isgd_orig_init = vtable_dest[src_mfp];
vtable_dest[src_mfp] = vtable_src[src_mfp];
}
else
{
assert(isgd_orig_init != NULL);
vtable_dest[mfp] = isgd_orig_init;
vtable_dest[src_mfp] = isgd_orig_init;
isgd_orig_init = NULL;
}
}

View File

@ -323,7 +323,6 @@ const char *PLUGIN_REVISION_COUNT = \"{revision_count}\";
'-Wno-switch',
'-Wno-unknown-pragmas',
'-Wno-dangling-else',
'-Wno-non-pod-varargs',
'-msse',
'-fPIC',
]

View File

@ -116,7 +116,7 @@ bool MMSPlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, boo
META_CONPRINTF( "CConVarRef \"%s\" got value pre = %d [float = %f, bool = %d, string = \"%s\"]\n",
ccvar_ref_example.GetName(), ccvar_ref_example.Get(),
ccvar_ref_example.GetFloat(), ccvar_ref_example.GetBool(),
ccvar_ref_example.GetString() );
ccvar_ref_example.GetString().Get() );
// By default if you are using CConVar or CConVarRef you should be using Get()/Set()
// methods to read/write values, as these are templated for the particular type the cvar is of.
@ -131,7 +131,7 @@ bool MMSPlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, boo
META_CONPRINTF( "CConVarRef \"%s\" got value after = %d [float = %f, bool = %d, string = \"%s\"]\n",
ccvar_ref_example.GetName(), ccvar_ref_example.Get(),
ccvar_ref_example.GetFloat(), ccvar_ref_example.GetBool(),
ccvar_ref_example.GetString() );
ccvar_ref_example.GetString().Get() );
}
// You can also use ConVarRefAbstract class if you don't want typisation support
@ -143,7 +143,7 @@ bool MMSPlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, boo
if(cvar_ref_example.IsValidRef())
{
META_CONPRINTF( "ConVarRefAbstract \"%s\" got value pre [float = %f, bool = %d, string = \"%s\"]\n",
cvar_ref_example.GetName(), cvar_ref_example.GetFloat(), cvar_ref_example.GetBool(), cvar_ref_example.GetString() );
cvar_ref_example.GetName(), cvar_ref_example.GetFloat(), cvar_ref_example.GetBool(), cvar_ref_example.GetString().Get() );
// Since the ref is not typed, you can't use direct Get() and Set() methods,
// instead you need to use methods with type conversion support.
@ -168,7 +168,7 @@ bool MMSPlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, boo
}
META_CONPRINTF( "ConVarRefAbstract \"%s\" got value after [float = %f, bool = %d, string = \"%s\"]\n",
cvar_ref_example.GetName(), cvar_ref_example.GetFloat(), cvar_ref_example.GetBool(), cvar_ref_example.GetString() );
cvar_ref_example.GetName(), cvar_ref_example.GetFloat(), cvar_ref_example.GetBool(), cvar_ref_example.GetString().Get() );
}
return true;