Merge pull request #54 from r-ex/indev

native server script functions
This commit is contained in:
Amos 2021-09-25 14:58:54 -07:00 committed by GitHub
commit 27536741f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 65 additions and 3 deletions

View File

@ -88,6 +88,7 @@ void Hooks::DedicatedPatch()
*(uintptr_t*)0x14B3800D7 = 0x1; // bDedicated
DisableRenderer();
DisableClient();
DisableVGUI();
@ -138,6 +139,26 @@ void Hooks::DedicatedPatch()
// TODO: this is also used by server.dll library.
e1.Offset(0x213).Patch({ 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 });
//-------------------------------------------------------------------------
// RET
c4.Patch({ 0xC3 });
c5.Patch({ 0xC3 });
c7.Patch({ 0xC3 });
//-------------------------------------------------------------------------
// JNE --> JMP |
c6.Offset(0x23).Patch({ 0xEB, 0x23 });
//-------------------------------------------------------------------------
// JNE --> JMP | (TEMP) jump over some settings block issues. not sure what to do here
s3.Offset(0x16C).Patch({ 0xE9, 0x47, 0x01, 0x00 });
OnLevelLoadingStarted.Offset(0x61).Patch({ 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 });
//-------------------------------------------------------------------------
// ??? 1403DFC30 = 0x94490 ??? // an expensive stuff that wasted many CPU cycles, this one seems to be the best candidate to return
}

View File

@ -59,16 +59,22 @@ namespace
MemoryAddress s0 = 0x0000000140237B00; // server Host_Init()?
MemoryAddress s1 = 0x0000000140231C00; // _Host_RunFrame() with inlined CFrameTimer::MarkFrame()?
MemoryAddress s2 = 0x00000001402312A0; // server HeartBeat? (baseserver.cpp)
MemoryAddress s3 = 0x0000000140FB36D0; // TEMP??
// CLIENT
MemoryAddress c0 = 0x0000000140236640; // client Host_Init()?
MemoryAddress c1 = 0x0000000140299100; // CreateGameWindowInit()?
MemoryAddress c2 = 0x00000001403F4360; // 1403DF870 --> 1403F4360
MemoryAddress c3 = 0x00000001403F8A80; // 1403DF870 --> 1403F8A40
MemoryAddress c4 = 0x00000001405C27B0; // CHLClient + 1000
MemoryAddress c5 = 0x00000001405BAC00; //
MemoryAddress c6 = 0x00000001403CA2D0; //
MemoryAddress c7 = 0x00000001403CC750; // lightmaps?
MemoryAddress CreateGameWindow = 0x0000000140343DE0;
// VGUI
MemoryAddress v0 = 0x0000000140282E40; // jumptable
MemoryAddress OnLevelLoadingStarted = 0x00000001402830D0;
MemoryAddress SCR_BeginLoadingPlaque = 0x000000014023E870;

View File

@ -505,6 +505,7 @@ namespace GameGlobals
void Script_RegisterFunction(void* sqvm, const char* name, const char* helpString, const char* retValType, const char* argTypes, void* funcPtr);
void RegisterUIScriptFunctions(void* sqvm);
void RegisterClientScriptFunctions(void* sqvm);
void RegisterServerScriptFunctions(void* sqvm);
// Init
void InitGameGlobals();

View File

@ -26,6 +26,7 @@ namespace Hooks
__int64 SQVM_LoadRson(const char* rson_name);
bool SQVM_LoadScript(void* sqvm, const char* script_path, const char* script_name, int flag);
void SQVM_RegisterOriginFuncs(void* sqvm);
void SQVM_RegisterCreatePlayerTasklist(void* sqvm);
using SQVM_WarningFn = __int64(*)(void*, int, int, int*, void**);
extern SQVM_WarningFn originalSQVM_Warning;
@ -38,6 +39,9 @@ namespace Hooks
using SQVM_RegisterOriginFuncsFn = void(*)(void*);
extern SQVM_RegisterOriginFuncsFn originalSQVM_RegisterOriginFuncs;
using SQVM_RegisterCreatePlayerTasklistFn = void(*)(void*);
extern SQVM_RegisterCreatePlayerTasklistFn originalSQVM_RegisterCreatePlayerTasklist;
#pragma endregion
#pragma region CServer

View File

@ -61,6 +61,9 @@ namespace
/*0x140834A00*/
FUNC_AT_ADDRESS(addr_SQVM_RegisterOriginFuncs, void(*)(void*), r5_patterns.PatternSearch("E8 ? ? ? ? 48 8B 0D ? ? ? ? 48 8D 15 ? ? ? ? E8 ? ? ? ? 48 8B 05 ? ? ? ? C7 05 ? ? ? ? ? ? ? ?").FollowNearCall().GetPtr());
/*0x140C06B20*/
FUNC_AT_ADDRESS(addr_SQVM_RegisterCreatePlayerTasklist, void(*)(void*), r5_patterns.PatternSearch("E8 ? ? ? ? 48 8B 0D ? ? ? ? E8 ? ? ? ? 48 8B CB").FollowNearCall().GetPtr());
#pragma endregion
#pragma region NetChannel
@ -156,6 +159,7 @@ namespace
PRINT_ADDRESS("SQVM_Warning", addr_SQVM_Warning);
PRINT_ADDRESS("SQVM_Warning_ReturnAddr", addr_SQVM_Warning_ReturnAddr);
PRINT_ADDRESS("SQVM_RegisterOriginFuncs", addr_SQVM_RegisterOriginFuncs);
PRINT_ADDRESS("SQVM_RegisterCreatePlayerTasklist", addr_SQVM_RegisterCreatePlayerTasklist);
PRINT_ADDRESS("sq_arrayappend", addr_sq_arrayappend);
PRINT_ADDRESS("sq_newarray", addr_sq_newarray);
PRINT_ADDRESS("sq_newslot", addr_sq_newslot);

View File

@ -4,7 +4,10 @@ char* sq_getstring(void* sqvm, int i);
int sq_getinteger(void* sqvm, int i);
void sq_pushbool(void* sqvm, int val);
void sq_pushstring(void* sqvm, char* string, int len);
void sq_pushstring(void* sqvm, const char* string, int len);
void sq_pushinteger(void* sqvm, int val);
void sq_newarray(void* sqvm, int size);

View File

@ -3,6 +3,7 @@
#include "id3dx.h"
#include "cgameconsole.h"
#include "squirrel.h"
#include <r5net.h>
// Need this for a re-factor later.
// Interface* interfaces = *reinterpret_cast<Interface**>(0x167F4FA48);
@ -486,12 +487,17 @@ namespace GameGlobals
void RegisterUIScriptFunctions(void* sqvm)
{
// Script_RegisterFunction(sqvm, "UINativeTest", "native ui function", "void", "", &Script_NativeTest);
//Script_RegisterFunction(sqvm, "UINativeTest", "native ui function", "void", "", &Script_NativeTest);
}
void RegisterClientScriptFunctions(void* sqvm)
{
// Script_RegisterFunction(sqvm, "ClientNativeTest", "native client function", "void", "", &Script_NativeTest);
//Script_RegisterFunction(sqvm, "ClientNativeTest", "native client function", "void", "", &Script_NativeTest);
}
void RegisterServerScriptFunctions(void* sqvm)
{
//Script_RegisterFunction(sqvm, "ServerNativeTest", "native server function", "void", "", &Script_NativeTest);
}
void DisconnectClient(CClient* client, const char* reason, unsigned __int8 unk1, char unk2)

View File

@ -22,6 +22,7 @@ void Hooks::InstallHooks()
MH_CreateHook(addr_SQVM_LoadRson, &Hooks::SQVM_LoadRson, reinterpret_cast<void**>(&originalSQVM_LoadRson));
MH_CreateHook(addr_SQVM_LoadScript, &Hooks::SQVM_LoadScript, reinterpret_cast<void**>(&originalSQVM_LoadScript));
MH_CreateHook(addr_SQVM_RegisterOriginFuncs, &Hooks::SQVM_RegisterOriginFuncs, reinterpret_cast<void**>(&originalSQVM_RegisterOriginFuncs));
MH_CreateHook(addr_SQVM_RegisterCreatePlayerTasklist, &Hooks::SQVM_RegisterCreatePlayerTasklist, reinterpret_cast<void**>(&originalSQVM_RegisterCreatePlayerTasklist));
///////////////////////////////////////////////////////////////////////////////
// Hook Game Functions
@ -79,6 +80,7 @@ void Hooks::InstallHooks()
MH_EnableHook(addr_SQVM_LoadRson);
MH_EnableHook(addr_SQVM_LoadScript);
MH_EnableHook(addr_SQVM_RegisterOriginFuncs);
MH_EnableHook(addr_SQVM_RegisterCreatePlayerTasklist);
///////////////////////////////////////////////////////////////////////////////
// Enable Game hooks
@ -114,6 +116,7 @@ void Hooks::RemoveHooks()
MH_RemoveHook(addr_SQVM_LoadRson);
MH_RemoveHook(addr_SQVM_LoadScript);
MH_RemoveHook(addr_SQVM_RegisterOriginFuncs);
MH_RemoveHook(addr_SQVM_RegisterCreatePlayerTasklist);
///////////////////////////////////////////////////////////////////////////////
// Unhook Game Functions

View File

@ -7,6 +7,7 @@ namespace Hooks
SQVM_LoadRsonFn originalSQVM_LoadRson = nullptr;
SQVM_LoadScriptFn originalSQVM_LoadScript = nullptr;
SQVM_RegisterOriginFuncsFn originalSQVM_RegisterOriginFuncs = nullptr;
SQVM_RegisterCreatePlayerTasklistFn originalSQVM_RegisterCreatePlayerTasklist = nullptr;
}
static std::ostringstream oss_print;
@ -181,7 +182,8 @@ bool Hooks::SQVM_LoadScript(void* sqvm, const char* script_path, const char* scr
return originalSQVM_LoadScript(sqvm, script_path, script_name, flag);
}
void Hooks::SQVM_RegisterOriginFuncs(void* sqvm) {
void Hooks::SQVM_RegisterOriginFuncs(void* sqvm)
{
static MemoryAddress UIVM = MemoryAddress(0x14D4151F0);
originalSQVM_RegisterOriginFuncs(sqvm);
@ -192,4 +194,11 @@ void Hooks::SQVM_RegisterOriginFuncs(void* sqvm) {
else {
GameGlobals::RegisterClientScriptFunctions(sqvm);
}
}
void Hooks::SQVM_RegisterCreatePlayerTasklist(void* sqvm)
{
GameGlobals::RegisterServerScriptFunctions(sqvm);
originalSQVM_RegisterCreatePlayerTasklist(sqvm);
}

View File

@ -25,6 +25,11 @@ void sq_pushstring(void* sqvm, char* string, int len)
addr_sq_pushstring(sqvm, string, len);
}
void sq_pushstring(void* sqvm, const char* string, int len)
{
addr_sq_pushstring(sqvm, const_cast<char*>(string), len);
}
void sq_pushinteger(void* sqvm, int val)
{
addr_sq_pushinteger(sqvm, val);