From e73ede2ef871b4d48805d6e4e187e2b8d5df343f Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Sat, 31 Aug 2024 00:36:03 +0100 Subject: [PATCH 01/13] core: Remove uses of Autohook from `filesystem.cpp` (#795) Replace cases of autohook macro with manual hook calls --- primedev/core/filesystem/filesystem.cpp | 69 +++++++++++++------------ 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/primedev/core/filesystem/filesystem.cpp b/primedev/core/filesystem/filesystem.cpp index b39939e45..2c3a50a1d 100644 --- a/primedev/core/filesystem/filesystem.cpp +++ b/primedev/core/filesystem/filesystem.cpp @@ -5,8 +5,6 @@ #include #include -AUTOHOOK_INIT() - bool bReadingOriginalFile = false; std::string sCurrentModPath; @@ -44,18 +42,17 @@ std::string ReadVPKOriginalFile(const char* path) return ret; } -// clang-format off -HOOK(AddSearchPathHook, AddSearchPath, -void, __fastcall, (IFileSystem * fileSystem, const char* pPath, const char* pathID, SearchPathAdd_t addType)) -// clang-format on +static void(__fastcall* o_pAddSearchPath)(IFileSystem* fileSystem, const char* pPath, const char* pathID, SearchPathAdd_t addType) = + nullptr; +static void __fastcall h_AddSearchPath(IFileSystem* fileSystem, const char* pPath, const char* pathID, SearchPathAdd_t addType) { - AddSearchPath(fileSystem, pPath, pathID, addType); + o_pAddSearchPath(fileSystem, pPath, pathID, addType); // make sure current mod paths are at head if (!strcmp(pathID, "GAME") && sCurrentModPath.compare(pPath) && addType == PATH_ADD_TO_HEAD) { - AddSearchPath(fileSystem, sCurrentModPath.c_str(), "GAME", PATH_ADD_TO_HEAD); - AddSearchPath(fileSystem, GetCompiledAssetsPath().string().c_str(), "GAME", PATH_ADD_TO_HEAD); + o_pAddSearchPath(fileSystem, sCurrentModPath.c_str(), "GAME", PATH_ADD_TO_HEAD); + o_pAddSearchPath(fileSystem, GetCompiledAssetsPath().string().c_str(), "GAME", PATH_ADD_TO_HEAD); } } @@ -67,13 +64,13 @@ void SetNewModSearchPaths(Mod* mod) { if ((fs::absolute(mod->m_ModDirectory) / MOD_OVERRIDE_DIR).string().compare(sCurrentModPath)) { - AddSearchPath( + o_pAddSearchPath( &*(*g_pFilesystem), (fs::absolute(mod->m_ModDirectory) / MOD_OVERRIDE_DIR).string().c_str(), "GAME", PATH_ADD_TO_HEAD); sCurrentModPath = (fs::absolute(mod->m_ModDirectory) / MOD_OVERRIDE_DIR).string(); } } else // push compiled to head - AddSearchPath(&*(*g_pFilesystem), fs::absolute(GetCompiledAssetsPath()).string().c_str(), "GAME", PATH_ADD_TO_HEAD); + o_pAddSearchPath(&*(*g_pFilesystem), fs::absolute(GetCompiledAssetsPath()).string().c_str(), "GAME", PATH_ADD_TO_HEAD); } bool TryReplaceFile(const char* pPath, bool shouldCompile) @@ -97,22 +94,17 @@ bool TryReplaceFile(const char* pPath, bool shouldCompile) } // force modded files to be read from mods, not cache -// clang-format off -HOOK(ReadFromCacheHook, ReadFromCache, -bool, __fastcall, (IFileSystem * filesystem, char* pPath, void* result)) -// clang-format off +static bool(__fastcall* o_pReadFromCache)(IFileSystem* filesystem, char* pPath, void* result) = nullptr; +static bool __fastcall h_ReadFromCache(IFileSystem* filesystem, char* pPath, void* result) { if (TryReplaceFile(pPath, true)) return false; - return ReadFromCache(filesystem, pPath, result); + return o_pReadFromCache(filesystem, pPath, result); } -// force modded files to be read from mods, not vpk -// clang-format off -AUTOHOOK(ReadFileFromVPK, filesystem_stdio.dll + 0x5CBA0, -FileHandle_t, __fastcall, (VPKData* vpkInfo, uint64_t* b, char* filename)) -// clang-format on +static FileHandle_t(__fastcall* o_pReadFileFromVPK)(VPKData* vpkInfo, uint64_t* b, char* filename) = nullptr; +static FileHandle_t __fastcall h_ReadFileFromVPK(VPKData* vpkInfo, uint64_t* b, char* filename) { // don't compile here because this is only ever called from OpenEx, which already compiles if (TryReplaceFile(filename, false)) @@ -121,22 +113,24 @@ FileHandle_t, __fastcall, (VPKData* vpkInfo, uint64_t* b, char* filename)) return b; } - return ReadFileFromVPK(vpkInfo, b, filename); + return o_pReadFileFromVPK(vpkInfo, b, filename); } -// clang-format off -AUTOHOOK(CBaseFileSystem__OpenEx, filesystem_stdio.dll + 0x15F50, -FileHandle_t, __fastcall, (IFileSystem* filesystem, const char* pPath, const char* pOptions, uint32_t flags, const char* pPathID, char **ppszResolvedFilename)) -// clang-format on +static FileHandle_t(__fastcall* o_pCBaseFileSystem__OpenEx)( + IFileSystem* filesystem, const char* pPath, const char* pOptions, uint32_t flags, const char* pPathID, char** ppszResolvedFilename) = + nullptr; +static FileHandle_t __fastcall h_CBaseFileSystem__OpenEx( + IFileSystem* filesystem, const char* pPath, const char* pOptions, uint32_t flags, const char* pPathID, char** ppszResolvedFilename) { TryReplaceFile(pPath, true); - return CBaseFileSystem__OpenEx(filesystem, pPath, pOptions, flags, pPathID, ppszResolvedFilename); + return o_pCBaseFileSystem__OpenEx(filesystem, pPath, pOptions, flags, pPathID, ppszResolvedFilename); } -HOOK(MountVPKHook, MountVPK, VPKData*, , (IFileSystem * fileSystem, const char* pVpkPath)) +static VPKData* (*o_pMountVPK)(IFileSystem* fileSystem, const char* pVpkPath) = nullptr; +static VPKData* h_MountVPK(IFileSystem* fileSystem, const char* pVpkPath) { NS::log::fs->info("MountVPK {}", pVpkPath); - VPKData* ret = MountVPK(fileSystem, pVpkPath); + VPKData* ret = o_pMountVPK(fileSystem, pVpkPath); for (Mod mod : g_pModManager->m_LoadedMods) { @@ -156,7 +150,7 @@ HOOK(MountVPKHook, MountVPK, VPKData*, , (IFileSystem * fileSystem, const char* continue; } - VPKData* loaded = MountVPK(fileSystem, vpkEntry.m_sVpkPath.c_str()); + VPKData* loaded = o_pMountVPK(fileSystem, vpkEntry.m_sVpkPath.c_str()); if (!ret) // this is primarily for map vpks and stuff, so the map's vpk is what gets returned from here ret = loaded; } @@ -167,11 +161,18 @@ HOOK(MountVPKHook, MountVPK, VPKData*, , (IFileSystem * fileSystem, const char* ON_DLL_LOAD("filesystem_stdio.dll", Filesystem, (CModule module)) { - AUTOHOOK_DISPATCH() + o_pReadFileFromVPK = module.Offset(0x5CBA0).RCast(); + HookAttach(&(PVOID&)o_pReadFileFromVPK, (PVOID)h_ReadFileFromVPK); + + o_pCBaseFileSystem__OpenEx = module.Offset(0x15F50).RCast(); + HookAttach(&(PVOID&)o_pCBaseFileSystem__OpenEx, (PVOID)h_CBaseFileSystem__OpenEx); g_pFilesystem = new SourceInterface("filesystem_stdio.dll", "VFileSystem017"); - AddSearchPathHook.Dispatch((LPVOID)(*g_pFilesystem)->m_vtable->AddSearchPath); - ReadFromCacheHook.Dispatch((LPVOID)(*g_pFilesystem)->m_vtable->ReadFromCache); - MountVPKHook.Dispatch((LPVOID)(*g_pFilesystem)->m_vtable->MountVPK); + o_pAddSearchPath = reinterpret_cast((*g_pFilesystem)->m_vtable->AddSearchPath); + HookAttach(&(PVOID&)o_pAddSearchPath, (PVOID)h_AddSearchPath); + o_pReadFromCache = reinterpret_cast((*g_pFilesystem)->m_vtable->ReadFromCache); + HookAttach(&(PVOID&)o_pReadFromCache, (PVOID)h_ReadFromCache); + o_pMountVPK = reinterpret_cast((*g_pFilesystem)->m_vtable->MountVPK); + HookAttach(&(PVOID&)o_pMountVPK, (PVOID)h_MountVPK); } From a60c2738a2a0247ef46db8bae55f5dfd0c0f14c3 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Sat, 31 Aug 2024 10:31:08 +0100 Subject: [PATCH 02/13] core: Remove uses of Autohook from `hooks.cpp` (#796) Removes AUTOHOOK macro from `hooks.cpp`. --- primedev/core/hooks.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/primedev/core/hooks.cpp b/primedev/core/hooks.cpp index a57340cfa..6146c93c6 100644 --- a/primedev/core/hooks.cpp +++ b/primedev/core/hooks.cpp @@ -12,8 +12,6 @@ namespace fs = std::filesystem; -AUTOHOOK_INIT() - // called from the ON_DLL_LOAD macros __dllLoadCallback::__dllLoadCallback( eDllLoadCallbackSide side, const std::string dllName, DllLoadCallbackFuncType callback, std::string uniqueStr, std::string reliesOn) @@ -223,14 +221,15 @@ void MakeHook(LPVOID pTarget, LPVOID pDetour, void* ppOriginal, const char* pFun spdlog::error("MH_CreateHook failed for function {}", pStrippedFuncName); } -AUTOHOOK_ABSOLUTEADDR(_GetCommandLineA, (LPVOID)GetCommandLineA, LPSTR, WINAPI, ()) +static LPSTR(WINAPI* o_pGetCommandLineA)() = nullptr; +static LPSTR WINAPI h_GetCommandLineA() { static char* cmdlineModified; static char* cmdlineOrg; if (cmdlineOrg == nullptr || cmdlineModified == nullptr) { - cmdlineOrg = _GetCommandLineA(); + cmdlineOrg = o_pGetCommandLineA(); bool isDedi = strstr(cmdlineOrg, "-dedicated"); // well, this one has to be a real argument bool ignoreStartupArgs = strstr(cmdlineOrg, "-nostartupargs"); @@ -394,6 +393,7 @@ void HookSys_Init() { spdlog::error("MH_Initialize (minhook initialization) failed"); } - // todo: remove remaining instances of autohook in this file - AUTOHOOK_DISPATCH() + + o_pGetCommandLineA = GetCommandLineA; + HookAttach(&(PVOID&)o_pGetCommandLineA, (PVOID)h_GetCommandLineA); } From 4d609a8d1cafae13b5ec14ad05f6e44e990cd403 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Sat, 31 Aug 2024 10:34:12 +0100 Subject: [PATCH 03/13] client: Remove uses of Autohook from `latencyflex.cpp` (#789) Removes AUTOHOOK macro from `latencyflex.cpp`. --- primedev/client/latencyflex.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/primedev/client/latencyflex.cpp b/primedev/client/latencyflex.cpp index 395578709..be93fabdc 100644 --- a/primedev/client/latencyflex.cpp +++ b/primedev/client/latencyflex.cpp @@ -1,20 +1,16 @@ #include "core/convar/convar.h" -AUTOHOOK_INIT() - ConVar* Cvar_r_latencyflex; void (*m_winelfx_WaitAndBeginFrame)(); -// clang-format off -AUTOHOOK(OnRenderStart, client.dll + 0x1952C0, -void, __fastcall, ()) -// clang-format on +void(__fastcall* o_pOnRenderStart)() = nullptr; +void __fastcall h_OnRenderStart() { if (Cvar_r_latencyflex->GetBool() && m_winelfx_WaitAndBeginFrame) m_winelfx_WaitAndBeginFrame(); - OnRenderStart(); + o_pOnRenderStart(); } ON_DLL_LOAD_CLIENT_RELIESON("client.dll", LatencyFlex, ConVar, (CModule module)) @@ -36,7 +32,8 @@ ON_DLL_LOAD_CLIENT_RELIESON("client.dll", LatencyFlex, ConVar, (CModule module)) return; } - AUTOHOOK_DISPATCH() + o_pOnRenderStart = module.Offset(0x1952C0).RCast(); + HookAttach(&(PVOID&)o_pOnRenderStart, (PVOID)h_OnRenderStart); spdlog::info("LatencyFleX initialized."); Cvar_r_latencyflex = new ConVar("r_latencyflex", "1", FCVAR_ARCHIVE, "Whether or not to use LatencyFleX input latency reduction."); From cb62662816c1e1f38de3567f83140d2adf21eebb Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Sat, 31 Aug 2024 10:42:55 +0100 Subject: [PATCH 04/13] client: Remove uses of Autohook from `languagehooks.cpp` (#787) Removes AUTOHOOK macro from `languagehooks.cpp`. --- primedev/client/languagehooks.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/primedev/client/languagehooks.cpp b/primedev/client/languagehooks.cpp index 36b5d5aed..80d3c31d9 100644 --- a/primedev/client/languagehooks.cpp +++ b/primedev/client/languagehooks.cpp @@ -5,8 +5,6 @@ namespace fs = std::filesystem; -AUTOHOOK_INIT() - typedef LANGID (*Tier0_DetectDefaultLanguageType)(); bool CheckLangAudioExists(char* lang) @@ -48,10 +46,8 @@ std::string GetAnyInstalledAudioLanguage() return "NO LANGUAGE DETECTED"; } -// clang-format off -AUTOHOOK(GetGameLanguage, tier0.dll + 0xF560, -char*, __fastcall, ()) -// clang-format on +static char*(__fastcall* o_pGetGameLanguage)() = nullptr; +static char* __fastcall h_GetGameLanguage() { auto tier0Handle = GetModuleHandleA("tier0.dll"); auto Tier0_DetectDefaultLanguageType = GetProcAddress(tier0Handle, "Tier0_DetectDefaultLanguage"); @@ -78,7 +74,7 @@ char*, __fastcall, ()) canOriginDictateLang = true; // let it try { - auto lang = GetGameLanguage(); + auto lang = o_pGetGameLanguage(); if (!CheckLangAudioExists(lang)) { if (strcmp(lang, "russian") != @@ -96,7 +92,7 @@ char*, __fastcall, ()) Tier0_DetectDefaultLanguageType(); // force the global in tier0 to be populated with language inferred from user's system rather than // defaulting to Russian canOriginDictateLang = false; // Origin has no say anymore, we will fallback to user's system setup language - auto lang = GetGameLanguage(); + auto lang = o_pGetGameLanguage(); spdlog::info("Detected system language: {}", lang); if (!CheckLangAudioExists(lang)) { @@ -113,5 +109,6 @@ char*, __fastcall, ()) ON_DLL_LOAD_CLIENT("tier0.dll", LanguageHooks, (CModule module)) { - AUTOHOOK_DISPATCH() + o_pGetGameLanguage = module.Offset(0xF560).RCast(); + HookAttach(&(PVOID&)o_pGetGameLanguage, (PVOID)h_GetGameLanguage); } From f2d07f5d19d824194a6595455e577810b9d71762 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Sat, 31 Aug 2024 16:25:59 +0100 Subject: [PATCH 05/13] core: Remove uses of Autohook from `sourceinterface.cpp` (#798) Replaces the AUTOHOOK macro in `sourceinterface.cpp` with HookAttach. --- primedev/core/sourceinterface.cpp | 48 +++++++++++++++++-------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/primedev/core/sourceinterface.cpp b/primedev/core/sourceinterface.cpp index 5a72beb07..74e4a9963 100644 --- a/primedev/core/sourceinterface.cpp +++ b/primedev/core/sourceinterface.cpp @@ -1,16 +1,12 @@ #include "sourceinterface.h" #include "logging/sourceconsole.h" -AUTOHOOK_INIT() - // really wanted to do a modular callback system here but honestly couldn't be bothered so hardcoding stuff for now: todo later -// clang-format off -AUTOHOOK_PROCADDRESS(ClientCreateInterface, client.dll, CreateInterface, -void*, __fastcall, (const char* pName, const int* pReturnCode)) -// clang-format on +static void*(__fastcall* o_pClientCreateInterface)(const char* pName, const int* pReturnCode) = nullptr; +static void* __fastcall h_ClientCreateInterface(const char* pName, const int* pReturnCode) { - void* ret = ClientCreateInterface(pName, pReturnCode); + void* ret = o_pClientCreateInterface(pName, pReturnCode); spdlog::info("CreateInterface CLIENT {}", pName); if (!strcmp(pName, "GameClientExports001")) @@ -19,30 +15,38 @@ void*, __fastcall, (const char* pName, const int* pReturnCode)) return ret; } -// clang-format off -AUTOHOOK_PROCADDRESS(ServerCreateInterface, server.dll, CreateInterface, -void*, __fastcall, (const char* pName, const int* pReturnCode)) -// clang-format on +static void*(__fastcall* o_pServerCreateInterface)(const char* pName, const int* pReturnCode) = nullptr; +static void* __fastcall h_ServerCreateInterface(const char* pName, const int* pReturnCode) { - void* ret = ServerCreateInterface(pName, pReturnCode); + void* ret = o_pServerCreateInterface(pName, pReturnCode); spdlog::info("CreateInterface SERVER {}", pName); return ret; } -// clang-format off -AUTOHOOK_PROCADDRESS(EngineCreateInterface, engine.dll, CreateInterface, -void*, __fastcall, (const char* pName, const int* pReturnCode)) -// clang-format on +static void*(__fastcall* o_pEngineCreateInterface)(const char* pName, const int* pReturnCode) = nullptr; +static void* __fastcall h_EngineCreateInterface(const char* pName, const int* pReturnCode) { - void* ret = EngineCreateInterface(pName, pReturnCode); + void* ret = o_pEngineCreateInterface(pName, pReturnCode); spdlog::info("CreateInterface ENGINE {}", pName); return ret; } -// clang-format off -ON_DLL_LOAD("client.dll", ClientInterface, (CModule module)) {AUTOHOOK_DISPATCH_MODULE(client.dll)} -ON_DLL_LOAD("server.dll", ServerInterface, (CModule module)) {AUTOHOOK_DISPATCH_MODULE(server.dll)} -ON_DLL_LOAD("engine.dll", EngineInterface, (CModule module)) {AUTOHOOK_DISPATCH_MODULE(engine.dll)} -// clang-format on +ON_DLL_LOAD("client.dll", ClientInterface, (CModule module)) +{ + o_pClientCreateInterface = module.GetExportedFunction("CreateInterface").RCast(); + HookAttach(&(PVOID&)o_pClientCreateInterface, (PVOID)h_ClientCreateInterface); +} + +ON_DLL_LOAD("server.dll", ServerInterface, (CModule module)) +{ + o_pServerCreateInterface = module.GetExportedFunction("CreateInterface").RCast(); + HookAttach(&(PVOID&)o_pServerCreateInterface, (PVOID)h_ServerCreateInterface); +} + +ON_DLL_LOAD("engine.dll", EngineInterface, (CModule module)) +{ + o_pEngineCreateInterface = module.GetExportedFunction("CreateInterface").RCast(); + HookAttach(&(PVOID&)o_pEngineCreateInterface, (PVOID)h_EngineCreateInterface); +} From 96c34f64ab4ed6099d08f458178e4686dff96b00 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Sun, 1 Sep 2024 18:44:04 +0100 Subject: [PATCH 06/13] Remove uses of Autohook from `gl_matsysiface.cpp` (#801) Removes AUTOHOOK macro from gl_matsysiface.cpp and replaces it with HookAttach --- primedev/engine/gl_matsysiface.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/primedev/engine/gl_matsysiface.cpp b/primedev/engine/gl_matsysiface.cpp index 903a01134..075a56acc 100644 --- a/primedev/engine/gl_matsysiface.cpp +++ b/primedev/engine/gl_matsysiface.cpp @@ -2,9 +2,8 @@ CMaterialGlue* (*GetMaterialAtCrossHair)(); -AUTOHOOK_INIT() - -AUTOHOOK(CC_mat_crosshair_printmaterial_f, engine.dll + 0xB3C40, void, __fastcall, (const CCommand& args)) +static void(__fastcall* o_pCC_mat_crosshair_printmaterial_f)(const CCommand& args) = nullptr; +static void __fastcall h_CC_mat_crosshair_printmaterial_f(const CCommand& args) { CMaterialGlue* pMat = GetMaterialAtCrossHair(); @@ -44,7 +43,8 @@ AUTOHOOK(CC_mat_crosshair_printmaterial_f, engine.dll + 0xB3C40, void, __fastcal ON_DLL_LOAD("engine.dll", GlMatSysIFace, (CModule module)) { - AUTOHOOK_DISPATCH() + o_pCC_mat_crosshair_printmaterial_f = module.Offset(0xB3C40).RCast(); + HookAttach(&(PVOID&)o_pCC_mat_crosshair_printmaterial_f, (PVOID)h_CC_mat_crosshair_printmaterial_f); GetMaterialAtCrossHair = module.Offset(0xB37D0).RCast(); } From 669fdaed4c00728e798ee911c4426a6339f93951 Mon Sep 17 00:00:00 2001 From: F1F7Y <64418963+F1F7Y@users.noreply.github.com> Date: Mon, 2 Sep 2024 17:10:57 +0200 Subject: [PATCH 07/13] core: Remove use of `SourceInterface` for `CCvar` (#804) `SourceInteface` class goes back to icepick and is not good. We have a replacement, let's use it. --- primedev/core/convar/convar.cpp | 5 ++--- primedev/core/convar/cvar.cpp | 1 - primedev/core/convar/cvar.h | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/primedev/core/convar/convar.cpp b/primedev/core/convar/convar.cpp index 87a1e1591..802c088dc 100644 --- a/primedev/core/convar/convar.cpp +++ b/primedev/core/convar/convar.cpp @@ -1,7 +1,7 @@ #include "bits.h" #include "cvar.h" #include "convar.h" -#include "core/sourceinterface.h" +#include "core/tier1.h" #include @@ -35,8 +35,7 @@ ON_DLL_LOAD("engine.dll", ConVar, (CModule module)) g_pConVar_Vtable = module.Offset(0x67FD28); g_pIConVar_Vtable = module.Offset(0x67FDC8); - g_pCVarInterface = new SourceInterface("vstdlib.dll", "VEngineCvar007"); - g_pCVar = *g_pCVarInterface; + g_pCVar = Sys_GetFactoryPtr("vstdlib.dll", "VEngineCvar007").RCast(); } //----------------------------------------------------------------------------- diff --git a/primedev/core/convar/cvar.cpp b/primedev/core/convar/cvar.cpp index aa5f03653..78da1ad2e 100644 --- a/primedev/core/convar/cvar.cpp +++ b/primedev/core/convar/cvar.cpp @@ -22,5 +22,4 @@ std::unordered_map CCvar::DumpToMap() return allConVars; } -SourceInterface* g_pCVarInterface; CCvar* g_pCVar; diff --git a/primedev/core/convar/cvar.h b/primedev/core/convar/cvar.h index beaa84f47..024f2b879 100644 --- a/primedev/core/convar/cvar.h +++ b/primedev/core/convar/cvar.h @@ -34,5 +34,4 @@ class CCvar std::unordered_map DumpToMap(); }; -extern SourceInterface* g_pCVarInterface; extern CCvar* g_pCVar; From 79fbb9b9a751d6c3a863b1fed95cd8480a1586ab Mon Sep 17 00:00:00 2001 From: F1F7Y <64418963+F1F7Y@users.noreply.github.com> Date: Mon, 2 Sep 2024 17:11:47 +0200 Subject: [PATCH 08/13] logging: Remove use of `SourceInterface` for `CGameConsole` (#803) `SourceInteface` class goes back to icepick and is not good. We have a replacement, let's use it. --- primedev/logging/sourceconsole.cpp | 32 +++++++++++++++--------------- primedev/logging/sourceconsole.h | 2 -- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/primedev/logging/sourceconsole.cpp b/primedev/logging/sourceconsole.cpp index 55be47237..c9063d198 100644 --- a/primedev/logging/sourceconsole.cpp +++ b/primedev/logging/sourceconsole.cpp @@ -1,35 +1,35 @@ #include "core/convar/convar.h" #include "sourceconsole.h" -#include "core/sourceinterface.h" +#include "core/tier1.h" #include "core/convar/concommand.h" #include "util/printcommands.h" -SourceInterface* g_pSourceGameConsole; +CGameConsole* g_pGameConsole; void ConCommand_toggleconsole(const CCommand& arg) { NOTE_UNUSED(arg); - if ((*g_pSourceGameConsole)->IsConsoleVisible()) - (*g_pSourceGameConsole)->Hide(); + if (g_pGameConsole->IsConsoleVisible()) + g_pGameConsole->Hide(); else - (*g_pSourceGameConsole)->Activate(); + g_pGameConsole->Activate(); } void ConCommand_showconsole(const CCommand& arg) { NOTE_UNUSED(arg); - (*g_pSourceGameConsole)->Activate(); + g_pGameConsole->Activate(); } void ConCommand_hideconsole(const CCommand& arg) { NOTE_UNUSED(arg); - (*g_pSourceGameConsole)->Hide(); + g_pGameConsole->Hide(); } void SourceConsoleSink::custom_sink_it_(const custom_log_msg& msg) { - if (!(*g_pSourceGameConsole)->m_bInitialized) + if (!g_pGameConsole->m_bInitialized) return; spdlog::memory_buf_t formatted; @@ -41,11 +41,11 @@ void SourceConsoleSink::custom_sink_it_(const custom_log_msg& msg) SourceColor levelColor = m_LogColours[msg.level]; std::string name {msg.logger_name.begin(), msg.logger_name.end()}; - (*g_pSourceGameConsole)->m_pConsole->m_pConsolePanel->ColorPrint(msg.origin->SRCColor, ("[" + name + "]").c_str()); - (*g_pSourceGameConsole)->m_pConsole->m_pConsolePanel->Print(" "); - (*g_pSourceGameConsole)->m_pConsole->m_pConsolePanel->ColorPrint(levelColor, ("[" + std::string(level_names[msg.level]) + "]").c_str()); - (*g_pSourceGameConsole)->m_pConsole->m_pConsolePanel->Print(" "); - (*g_pSourceGameConsole)->m_pConsole->m_pConsolePanel->Print(fmt::to_string(formatted).c_str()); + g_pGameConsole->m_pConsole->m_pConsolePanel->ColorPrint(msg.origin->SRCColor, ("[" + name + "]").c_str()); + g_pGameConsole->m_pConsole->m_pConsolePanel->Print(" "); + g_pGameConsole->m_pConsole->m_pConsolePanel->ColorPrint(levelColor, ("[" + std::string(level_names[msg.level]) + "]").c_str()); + g_pGameConsole->m_pConsole->m_pConsolePanel->Print(" "); + g_pGameConsole->m_pConsole->m_pConsolePanel->Print(fmt::to_string(formatted).c_str()); } void SourceConsoleSink::sink_it_(const spdlog::details::log_msg& msg) @@ -73,9 +73,9 @@ void, __fastcall, (CConsoleDialog* consoleDialog, const char* pCommand)) // called from sourceinterface.cpp in client createinterface hooks, on GameClientExports001 void InitialiseConsoleOnInterfaceCreation() { - (*g_pSourceGameConsole)->Initialize(); + g_pGameConsole->Initialize(); // hook OnCommandSubmitted so we print inputted commands - OnCommandSubmittedHook.Dispatch((LPVOID)(*g_pSourceGameConsole)->m_pConsole->m_vtable->OnCommandSubmitted); + OnCommandSubmittedHook.Dispatch((LPVOID)g_pGameConsole->m_pConsole->m_vtable->OnCommandSubmitted); auto consoleSink = std::make_shared(); if (g_bSpdLog_UseAnsiColor) @@ -87,7 +87,7 @@ void InitialiseConsoleOnInterfaceCreation() ON_DLL_LOAD_CLIENT_RELIESON("client.dll", SourceConsole, ConCommand, (CModule module)) { - g_pSourceGameConsole = new SourceInterface("client.dll", "GameConsole004"); + g_pGameConsole = Sys_GetFactoryPtr("client.dll", "GameConsole004").RCast(); RegisterConCommand("toggleconsole", ConCommand_toggleconsole, "Show/hide the console.", FCVAR_DONTRECORD); RegisterConCommand("showconsole", ConCommand_showconsole, "Show the console.", FCVAR_DONTRECORD); diff --git a/primedev/logging/sourceconsole.h b/primedev/logging/sourceconsole.h index 215dae1a3..35cc1723c 100644 --- a/primedev/logging/sourceconsole.h +++ b/primedev/logging/sourceconsole.h @@ -61,8 +61,6 @@ class CGameConsole CConsoleDialog* m_pConsole; }; -extern SourceInterface* g_pSourceGameConsole; - // spdlog logger class SourceConsoleSink : public CustomSink { From ce21abe9c4c58d7c7d986fb01824ab107081ad2f Mon Sep 17 00:00:00 2001 From: F1F7Y <64418963+F1F7Y@users.noreply.github.com> Date: Mon, 2 Sep 2024 17:50:37 +0200 Subject: [PATCH 09/13] vscript: Move squirrel types to their respective files (#788) Refactor logic to move Squirrel types to their own respective files and extend existing layouts in the process where applicable. Contains additional smaller fixes. --- primedev/Northstar.cmake | 18 +- primedev/mods/modsavefiles.cpp | 2 +- primedev/scripts/scriptdatatables.cpp | 6 +- primedev/scripts/scripthttprequesthandler.cpp | 10 +- primedev/scripts/scriptjson.cpp | 12 +- primedev/scripts/scriptjson.h | 2 +- primedev/squirrel/squirrel.cpp | 22 +- primedev/squirrel/squirrel.h | 64 +-- primedev/squirrel/squirrelautobind.h | 8 +- primedev/squirrel/squirrelclasstypes.h | 137 ++--- primedev/squirrel/squirreldatatypes.h | 501 ------------------ .../languages/squirrel_re/include/squirrel.h | 95 ++++ .../languages/squirrel_re/squirrel/sqarray.h | 12 + .../squirrel_re/squirrel/sqclosure.h | 29 + .../squirrel_re/squirrel/sqcompiler.h | 26 + .../squirrel_re/squirrel/sqfunctionproto.h | 24 + .../languages/squirrel_re/squirrel/sqlexer.h | 9 + .../languages/squirrel_re/squirrel/sqobject.h | 93 ++++ .../squirrel_re/squirrel/sqopcodes.h | 13 + .../languages/squirrel_re/squirrel/sqstate.h | 120 +++++ .../languages/squirrel_re/squirrel/sqstring.h | 15 + .../languages/squirrel_re/squirrel/sqstruct.h | 24 + .../languages/squirrel_re/squirrel/sqtable.h | 21 + .../squirrel_re/squirrel/squserdata.h | 15 + .../languages/squirrel_re/squirrel/sqvector.h | 12 + .../languages/squirrel_re/squirrel/sqvm.h | 69 +++ .../vscript/languages/squirrel_re/vsquirrel.h | 16 + primedev/vscript/vscript.h | 20 + 28 files changed, 728 insertions(+), 667 deletions(-) delete mode 100644 primedev/squirrel/squirreldatatypes.h create mode 100644 primedev/vscript/languages/squirrel_re/include/squirrel.h create mode 100644 primedev/vscript/languages/squirrel_re/squirrel/sqarray.h create mode 100644 primedev/vscript/languages/squirrel_re/squirrel/sqclosure.h create mode 100644 primedev/vscript/languages/squirrel_re/squirrel/sqcompiler.h create mode 100644 primedev/vscript/languages/squirrel_re/squirrel/sqfunctionproto.h create mode 100644 primedev/vscript/languages/squirrel_re/squirrel/sqlexer.h create mode 100644 primedev/vscript/languages/squirrel_re/squirrel/sqobject.h create mode 100644 primedev/vscript/languages/squirrel_re/squirrel/sqopcodes.h create mode 100644 primedev/vscript/languages/squirrel_re/squirrel/sqstate.h create mode 100644 primedev/vscript/languages/squirrel_re/squirrel/sqstring.h create mode 100644 primedev/vscript/languages/squirrel_re/squirrel/sqstruct.h create mode 100644 primedev/vscript/languages/squirrel_re/squirrel/sqtable.h create mode 100644 primedev/vscript/languages/squirrel_re/squirrel/squserdata.h create mode 100644 primedev/vscript/languages/squirrel_re/squirrel/sqvector.h create mode 100644 primedev/vscript/languages/squirrel_re/squirrel/sqvm.h create mode 100644 primedev/vscript/languages/squirrel_re/vsquirrel.h create mode 100644 primedev/vscript/vscript.h diff --git a/primedev/Northstar.cmake b/primedev/Northstar.cmake index b80380732..05c3c72af 100644 --- a/primedev/Northstar.cmake +++ b/primedev/Northstar.cmake @@ -151,7 +151,6 @@ add_library( "squirrel/squirrelautobind.cpp" "squirrel/squirrelautobind.h" "squirrel/squirrelclasstypes.h" - "squirrel/squirreldatatypes.h" "util/printcommands.cpp" "util/printcommands.h" "util/printmaps.cpp" @@ -162,6 +161,23 @@ add_library( "util/version.h" "util/wininfo.cpp" "util/wininfo.h" + "vscript/languages/squirrel_re/include/squirrel.h" + "vscript/languages/squirrel_re/squirrel/sqarray.h" + "vscript/languages/squirrel_re/squirrel/sqclosure.h" + "vscript/languages/squirrel_re/squirrel/sqcompiler.h" + "vscript/languages/squirrel_re/squirrel/sqfunctionproto.h" + "vscript/languages/squirrel_re/squirrel/sqlexer.h" + "vscript/languages/squirrel_re/squirrel/sqobject.h" + "vscript/languages/squirrel_re/squirrel/sqopcodes.h" + "vscript/languages/squirrel_re/squirrel/sqstate.h" + "vscript/languages/squirrel_re/squirrel/sqstring.h" + "vscript/languages/squirrel_re/squirrel/sqstruct.h" + "vscript/languages/squirrel_re/squirrel/sqtable.h" + "vscript/languages/squirrel_re/squirrel/squserdata.h" + "vscript/languages/squirrel_re/squirrel/sqvector.h" + "vscript/languages/squirrel_re/squirrel/sqvm.h" + "vscript/languages/squirrel_re/vsquirrel.h" + "vscript/vscript.h" "windows/libsys.cpp" "windows/libsys.h" "dllmain.cpp" diff --git a/primedev/mods/modsavefiles.cpp b/primedev/mods/modsavefiles.cpp index 68e33864b..13239c99f 100644 --- a/primedev/mods/modsavefiles.cpp +++ b/primedev/mods/modsavefiles.cpp @@ -537,7 +537,7 @@ ADD_SQFUNC("int", NSGetTotalSpaceRemaining, "", "", ScriptContext::CLIENT | Scri // ok, I'm just gonna explain what the fuck is going on here because this // is the pinnacle of my stupidity and I do not want to touch this ever // again, yet someone will eventually have to maintain this. -template std::string EncodeJSON(HSquirrelVM* sqvm) +template std::string EncodeJSON(HSQUIRRELVM sqvm) { // new rapidjson rapidjson_document doc; diff --git a/primedev/scripts/scriptdatatables.cpp b/primedev/scripts/scriptdatatables.cpp index 5e685b48c..76e57b956 100644 --- a/primedev/scripts/scriptdatatables.cpp +++ b/primedev/scripts/scriptdatatables.cpp @@ -44,7 +44,7 @@ struct Datatable ConVar* Cvar_ns_prefer_datatable_from_disk; -template Datatable* (*SQ_GetDatatableInternal)(HSquirrelVM* sqvm); +template Datatable* (*SQ_GetDatatableInternal)(HSQUIRRELVM sqvm); struct CSVData { @@ -852,12 +852,12 @@ void ConCommand_dump_datatables(const CCommand& args) ON_DLL_LOAD_RELIESON("server.dll", ServerScriptDatatables, ServerSquirrel, (CModule module)) { - SQ_GetDatatableInternal = module.Offset(0x1250f0).RCast(); + SQ_GetDatatableInternal = module.Offset(0x1250f0).RCast(); } ON_DLL_LOAD_RELIESON("client.dll", ClientScriptDatatables, ClientSquirrel, (CModule module)) { - SQ_GetDatatableInternal = module.Offset(0x1C9070).RCast(); + SQ_GetDatatableInternal = module.Offset(0x1C9070).RCast(); SQ_GetDatatableInternal = SQ_GetDatatableInternal; } diff --git a/primedev/scripts/scripthttprequesthandler.cpp b/primedev/scripts/scripthttprequesthandler.cpp index 69828a5a2..f45e83f0d 100644 --- a/primedev/scripts/scripthttprequesthandler.cpp +++ b/primedev/scripts/scripthttprequesthandler.cpp @@ -450,7 +450,7 @@ template int HttpRequestHandler::MakeHttpRequest(const H // int NS_InternalMakeHttpRequest(int method, string baseUrl, table headers, table queryParams, // string contentType, string body, int timeout, string userAgent) -template SQRESULT SQ_InternalMakeHttpRequest(HSquirrelVM* sqvm) +template SQRESULT SQ_InternalMakeHttpRequest(HSQUIRRELVM sqvm) { if (!g_httpRequestHandler || !g_httpRequestHandler->IsRunning()) { @@ -475,7 +475,7 @@ template SQRESULT SQ_InternalMakeHttpRequest(HSquirrelVM SQTable* headerTable = sqvm->_stackOfCurrentFunction[3]._VAL.asTable; for (int idx = 0; idx < headerTable->_numOfNodes; ++idx) { - tableNode* node = &headerTable->_nodes[idx]; + SQTable::_HashNode* node = &headerTable->_nodes[idx]; if (node->key._Type == OT_STRING && node->val._Type == OT_ARRAY) { @@ -497,7 +497,7 @@ template SQRESULT SQ_InternalMakeHttpRequest(HSquirrelVM SQTable* queryTable = sqvm->_stackOfCurrentFunction[4]._VAL.asTable; for (int idx = 0; idx < queryTable->_numOfNodes; ++idx) { - tableNode* node = &queryTable->_nodes[idx]; + SQTable::_HashNode* node = &queryTable->_nodes[idx]; if (node->key._Type == OT_STRING && node->val._Type == OT_ARRAY) { @@ -527,14 +527,14 @@ template SQRESULT SQ_InternalMakeHttpRequest(HSquirrelVM } // bool NSIsHttpEnabled() -template SQRESULT SQ_IsHttpEnabled(HSquirrelVM* sqvm) +template SQRESULT SQ_IsHttpEnabled(HSQUIRRELVM sqvm) { g_pSquirrel->pushbool(sqvm, !IsHttpDisabled()); return SQRESULT_NOTNULL; } // bool NSIsLocalHttpAllowed() -template SQRESULT SQ_IsLocalHttpAllowed(HSquirrelVM* sqvm) +template SQRESULT SQ_IsLocalHttpAllowed(HSQUIRRELVM sqvm) { g_pSquirrel->pushbool(sqvm, IsLocalHttpAllowed()); return SQRESULT_NOTNULL; diff --git a/primedev/scripts/scriptjson.cpp b/primedev/scripts/scriptjson.cpp index 8959bf471..91553ae3d 100644 --- a/primedev/scripts/scriptjson.cpp +++ b/primedev/scripts/scriptjson.cpp @@ -9,8 +9,8 @@ #undef GetObject // fuck microsoft developers #endif -template void -DecodeJsonArray(HSquirrelVM* sqvm, rapidjson::GenericValue, rapidjson::MemoryPoolAllocator>* arr) +template +void DecodeJsonArray(HSQUIRRELVM sqvm, rapidjson::GenericValue, rapidjson::MemoryPoolAllocator>* arr) { g_pSquirrel->newarray(sqvm, 0); @@ -48,8 +48,8 @@ DecodeJsonArray(HSquirrelVM* sqvm, rapidjson::GenericValue } } -template void -DecodeJsonTable(HSquirrelVM* sqvm, rapidjson::GenericValue, rapidjson::MemoryPoolAllocator>* obj) +template +void DecodeJsonTable(HSQUIRRELVM sqvm, rapidjson::GenericValue, rapidjson::MemoryPoolAllocator>* obj) { g_pSquirrel->newtable(sqvm); @@ -107,7 +107,7 @@ template void EncodeJSONTable( { for (int i = 0; i < table->_numOfNodes; i++) { - tableNode* node = &table->_nodes[i]; + SQTable::_HashNode* node = &table->_nodes[i]; if (node->key._Type == OT_STRING) { rapidjson::GenericValue, rapidjson::MemoryPoolAllocator> newObj(rapidjson::kObjectType); @@ -240,7 +240,7 @@ ADD_SQFUNC( doc.SetObject(); // temp until this is just the func parameter type - HSquirrelVM* vm = (HSquirrelVM*)sqvm; + HSQUIRRELVM vm = (HSQUIRRELVM)sqvm; SQTable* table = vm->_stackOfCurrentFunction[1]._VAL.asTable; EncodeJSONTable(table, &doc, doc.GetAllocator()); diff --git a/primedev/scripts/scriptjson.h b/primedev/scripts/scriptjson.h index b747106b2..f766e3f00 100644 --- a/primedev/scripts/scriptjson.h +++ b/primedev/scripts/scriptjson.h @@ -10,4 +10,4 @@ template void EncodeJSONTable( rapidjson::MemoryPoolAllocator& allocator); template void -DecodeJsonTable(HSquirrelVM* sqvm, rapidjson::GenericValue, rapidjson::MemoryPoolAllocator>* obj); +DecodeJsonTable(HSQUIRRELVM sqvm, rapidjson::GenericValue, rapidjson::MemoryPoolAllocator>* obj); diff --git a/primedev/squirrel/squirrel.cpp b/primedev/squirrel/squirrel.cpp index 29540ccea..4141d04df 100644 --- a/primedev/squirrel/squirrel.cpp +++ b/primedev/squirrel/squirrel.cpp @@ -11,6 +11,8 @@ #include "ns_version.h" #include "core/vanilla.h" +#include "vscript/vscript.h" + #include AUTOHOOK_INIT() @@ -253,8 +255,8 @@ template void SquirrelManager::ExecuteCode(cons spdlog::info("Executing {} script code {} ", GetContextName(context), pCode); - std::string strCode(pCode); - CompileBufferState bufferState = CompileBufferState(strCode); + // NOTE: SQBufferState doesn't strdup pCode! + SQBufferState bufferState = SQBufferState(pCode); SQRESULT compileResult = compilebuffer(&bufferState, "console"); spdlog::info("sq_compilebuffer returned {}", PrintSQRESULT.at(compileResult)); @@ -309,14 +311,14 @@ template void SquirrelManager::AddFuncOverride( } // hooks -bool IsUIVM(ScriptContext context, HSquirrelVM* pSqvm) +bool IsUIVM(ScriptContext context, HSQUIRRELVM pSqvm) { NOTE_UNUSED(context); return ScriptContext(pSqvm->sharedState->cSquirrelVM->vmContext) == ScriptContext::UI; } -template void* (*sq_compiler_create)(HSquirrelVM* sqvm, void* a2, void* a3, SQBool bShouldThrowError); -template void* __fastcall sq_compiler_createHook(HSquirrelVM* sqvm, void* a2, void* a3, SQBool bShouldThrowError) +template void* (*sq_compiler_create)(HSQUIRRELVM sqvm, void* a2, void* a3, SQBool bShouldThrowError); +template void* __fastcall sq_compiler_createHook(HSQUIRRELVM sqvm, void* a2, void* a3, SQBool bShouldThrowError) { // store whether errors generated from this compile should be fatal if (IsUIVM(context, sqvm)) @@ -327,8 +329,8 @@ template void* __fastcall sq_compiler_createHook(HSquirr return sq_compiler_create(sqvm, a2, a3, bShouldThrowError); } -template SQInteger (*SQPrint)(HSquirrelVM* sqvm, const char* fmt); -template SQInteger SQPrintHook(HSquirrelVM* sqvm, const char* fmt, ...) +template SQInteger (*SQPrint)(HSQUIRRELVM sqvm, const char* fmt); +template SQInteger SQPrintHook(HSQUIRRELVM sqvm, const char* fmt, ...) { NOTE_UNUSED(sqvm); @@ -398,9 +400,9 @@ template void __fastcall DestroyVMHook(void* a1, CSquirr spdlog::info("DestroyVM {} {}", GetContextName(realContext), (void*)sqvm); } -template void (*SQCompileError)(HSquirrelVM* sqvm, const char* error, const char* file, int line, int column); +template void (*SQCompileError)(HSQUIRRELVM sqvm, const char* error, const char* file, int line, int column); template -void __fastcall ScriptCompileErrorHook(HSquirrelVM* sqvm, const char* error, const char* file, int line, int column) +void __fastcall ScriptCompileErrorHook(HSQUIRRELVM sqvm, const char* error, const char* file, int line, int column) { bool bIsFatalError = g_pSquirrel->m_bFatalCompilationErrors; ScriptContext realContext = context; // ui and client use the same function so we use this for prints @@ -544,7 +546,7 @@ template void ConCommand_script(const CCommand& args) g_pSquirrel->ExecuteCode(args.ArgS()); } -template SQRESULT SQ_StubbedFunc(HSquirrelVM* sqvm) +template SQRESULT SQ_StubbedFunc(HSQUIRRELVM sqvm) { SQStackInfos si; g_pSquirrel->sq_stackinfos(sqvm, 0, si); diff --git a/primedev/squirrel/squirrel.h b/primedev/squirrel/squirrel.h index 086ab9c67..ae6e80c93 100644 --- a/primedev/squirrel/squirrel.h +++ b/primedev/squirrel/squirrel.h @@ -129,72 +129,72 @@ class SquirrelManagerBase inline void defconst(CSquirrelVM* sqvm, const SQChar* pName, int nValue) { __sq_defconst(sqvm, pName, nValue); } inline SQRESULT - compilebuffer(CompileBufferState* bufferState, const SQChar* bufferName = "unnamedbuffer", const SQBool bShouldThrowError = false) + compilebuffer(SQBufferState* bufferState, const SQChar* bufferName = "unnamedbuffer", const SQBool bShouldThrowError = false) { return __sq_compilebuffer(m_pSQVM->sqvm, bufferState, bufferName, -1, bShouldThrowError); } - inline SQRESULT _call(HSquirrelVM* sqvm, const SQInteger args) { return __sq_call(sqvm, args + 1, false, true); } + inline SQRESULT _call(HSQUIRRELVM sqvm, const SQInteger args) { return __sq_call(sqvm, args + 1, false, true); } - inline SQInteger raiseerror(HSquirrelVM* sqvm, const SQChar* sError) { return __sq_raiseerror(sqvm, sError); } + inline SQInteger raiseerror(HSQUIRRELVM sqvm, const SQChar* sError) { return __sq_raiseerror(sqvm, sError); } inline bool compilefile(CSquirrelVM* sqvm, const char* path, const char* name, int a4) { return __sq_compilefile(sqvm, path, name, a4); } - inline void newarray(HSquirrelVM* sqvm, const SQInteger stackpos = 0) { __sq_newarray(sqvm, stackpos); } + inline void newarray(HSQUIRRELVM sqvm, const SQInteger stackpos = 0) { __sq_newarray(sqvm, stackpos); } - inline SQRESULT arrayappend(HSquirrelVM* sqvm, const SQInteger stackpos) { return __sq_arrayappend(sqvm, stackpos); } + inline SQRESULT arrayappend(HSQUIRRELVM sqvm, const SQInteger stackpos) { return __sq_arrayappend(sqvm, stackpos); } - inline SQRESULT newtable(HSquirrelVM* sqvm) { return __sq_newtable(sqvm); } + inline SQRESULT newtable(HSQUIRRELVM sqvm) { return __sq_newtable(sqvm); } - inline SQRESULT newslot(HSquirrelVM* sqvm, SQInteger idx, SQBool bStatic) { return __sq_newslot(sqvm, idx, bStatic); } + inline SQRESULT newslot(HSQUIRRELVM sqvm, SQInteger idx, SQBool bStatic) { return __sq_newslot(sqvm, idx, bStatic); } - inline void pushroottable(HSquirrelVM* sqvm) { __sq_pushroottable(sqvm); } + inline void pushroottable(HSQUIRRELVM sqvm) { __sq_pushroottable(sqvm); } - inline void pushstring(HSquirrelVM* sqvm, const SQChar* sVal, int length = -1) { __sq_pushstring(sqvm, sVal, length); } + inline void pushstring(HSQUIRRELVM sqvm, const SQChar* sVal, int length = -1) { __sq_pushstring(sqvm, sVal, length); } - inline void pushinteger(HSquirrelVM* sqvm, const SQInteger iVal) { __sq_pushinteger(sqvm, iVal); } + inline void pushinteger(HSQUIRRELVM sqvm, const SQInteger iVal) { __sq_pushinteger(sqvm, iVal); } - inline void pushfloat(HSquirrelVM* sqvm, const SQFloat flVal) { __sq_pushfloat(sqvm, flVal); } + inline void pushfloat(HSQUIRRELVM sqvm, const SQFloat flVal) { __sq_pushfloat(sqvm, flVal); } - inline void pushbool(HSquirrelVM* sqvm, const SQBool bVal) { __sq_pushbool(sqvm, bVal); } + inline void pushbool(HSQUIRRELVM sqvm, const SQBool bVal) { __sq_pushbool(sqvm, bVal); } - inline void pushasset(HSquirrelVM* sqvm, const SQChar* sVal, int length = -1) { __sq_pushasset(sqvm, sVal, length); } + inline void pushasset(HSQUIRRELVM sqvm, const SQChar* sVal, int length = -1) { __sq_pushasset(sqvm, sVal, length); } - inline void pushvector(HSquirrelVM* sqvm, const Vector3 pVal) { __sq_pushvector(sqvm, (float*)&pVal); } + inline void pushvector(HSQUIRRELVM sqvm, const Vector3 pVal) { __sq_pushvector(sqvm, (float*)&pVal); } - inline void pushobject(HSquirrelVM* sqvm, SQObject* obj) { __sq_pushobject(sqvm, obj); } + inline void pushobject(HSQUIRRELVM sqvm, SQObject* obj) { __sq_pushobject(sqvm, obj); } - inline const SQChar* getstring(HSquirrelVM* sqvm, const SQInteger stackpos) { return __sq_getstring(sqvm, stackpos); } + inline const SQChar* getstring(HSQUIRRELVM sqvm, const SQInteger stackpos) { return __sq_getstring(sqvm, stackpos); } - inline SQInteger getinteger(HSquirrelVM* sqvm, const SQInteger stackpos) { return __sq_getinteger(sqvm, stackpos); } + inline SQInteger getinteger(HSQUIRRELVM sqvm, const SQInteger stackpos) { return __sq_getinteger(sqvm, stackpos); } - inline SQFloat getfloat(HSquirrelVM* sqvm, const SQInteger stackpos) { return __sq_getfloat(sqvm, stackpos); } + inline SQFloat getfloat(HSQUIRRELVM sqvm, const SQInteger stackpos) { return __sq_getfloat(sqvm, stackpos); } - inline SQBool getbool(HSquirrelVM* sqvm, const SQInteger stackpos) { return __sq_getbool(sqvm, stackpos); } + inline SQBool getbool(HSQUIRRELVM sqvm, const SQInteger stackpos) { return __sq_getbool(sqvm, stackpos); } - inline SQRESULT get(HSquirrelVM* sqvm, const SQInteger stackpos) { return __sq_get(sqvm, stackpos); } + inline SQRESULT get(HSQUIRRELVM sqvm, const SQInteger stackpos) { return __sq_get(sqvm, stackpos); } - inline Vector3 getvector(HSquirrelVM* sqvm, const SQInteger stackpos) { return *(Vector3*)__sq_getvector(sqvm, stackpos); } + inline Vector3 getvector(HSQUIRRELVM sqvm, const SQInteger stackpos) { return *(Vector3*)__sq_getvector(sqvm, stackpos); } - inline int sq_getfunction(HSquirrelVM* sqvm, const char* name, SQObject* returnObj, const char* signature) + inline int sq_getfunction(HSQUIRRELVM sqvm, const char* name, SQObject* returnObj, const char* signature) { return __sq_getfunction(sqvm, name, returnObj, signature); } - inline SQRESULT getasset(HSquirrelVM* sqvm, const SQInteger stackpos, const char** result) + inline SQRESULT getasset(HSQUIRRELVM sqvm, const SQInteger stackpos, const char** result) { return __sq_getasset(sqvm, stackpos, result); } - inline long long sq_stackinfos(HSquirrelVM* sqvm, int level, SQStackInfos& out) + inline long long sq_stackinfos(HSQUIRRELVM sqvm, int level, SQStackInfos& out) { return __sq_stackinfos(sqvm, level, &out, sqvm->_callstacksize); } - inline Mod* getcallingmod(HSquirrelVM* sqvm, int depth = 0) + inline Mod* getcallingmod(HSQUIRRELVM sqvm, int depth = 0) { SQStackInfos stackInfo {}; if (1 + depth >= sqvm->_callstacksize) @@ -211,26 +211,26 @@ class SquirrelManagerBase } return nullptr; } - template inline SQRESULT getuserdata(HSquirrelVM* sqvm, const SQInteger stackpos, T* data, uint64_t* typeId) + template inline SQRESULT getuserdata(HSQUIRRELVM sqvm, const SQInteger stackpos, T* data, uint64_t* typeId) { return __sq_getuserdata(sqvm, stackpos, (void**)data, typeId); // this sometimes crashes idk } - template inline T* createuserdata(HSquirrelVM* sqvm, SQInteger size) + template inline T* createuserdata(HSQUIRRELVM sqvm, SQInteger size) { void* ret = __sq_createuserdata(sqvm, size); memset(ret, 0, size); return (T*)ret; } - inline SQRESULT setuserdatatypeid(HSquirrelVM* sqvm, const SQInteger stackpos, uint64_t typeId) + inline SQRESULT setuserdatatypeid(HSQUIRRELVM sqvm, const SQInteger stackpos, uint64_t typeId) { return __sq_setuserdatatypeid(sqvm, stackpos, typeId); } - template inline SQBool getthisentity(HSquirrelVM* sqvm, T* ppEntity) { return __sq_getthisentity(sqvm, (void**)ppEntity); } + template inline SQBool getthisentity(HSQUIRRELVM sqvm, T* ppEntity) { return __sq_getthisentity(sqvm, (void**)ppEntity); } - template inline T* getentity(HSquirrelVM* sqvm, SQInteger iStackPos) + template inline T* getentity(HSQUIRRELVM sqvm, SQInteger iStackPos) { SQObject obj; __sq_getobject(sqvm, iStackPos, &obj); @@ -239,9 +239,9 @@ class SquirrelManagerBase return (T*)__sq_getentityfrominstance(m_pSQVM, &obj, __sq_GetEntityConstant_CBaseEntity()); } - inline SQRESULT pushnewstructinstance(HSquirrelVM* sqvm, const int fieldCount) { return __sq_pushnewstructinstance(sqvm, fieldCount); } + inline SQRESULT pushnewstructinstance(HSQUIRRELVM sqvm, const int fieldCount) { return __sq_pushnewstructinstance(sqvm, fieldCount); } - inline SQRESULT sealstructslot(HSquirrelVM* sqvm, const int fieldIndex) { return __sq_sealstructslot(sqvm, fieldIndex); } + inline SQRESULT sealstructslot(HSQUIRRELVM sqvm, const int fieldIndex) { return __sq_sealstructslot(sqvm, fieldIndex); } #pragma endregion }; diff --git a/primedev/squirrel/squirrelautobind.h b/primedev/squirrel/squirrelautobind.h index 0fc599f3d..cb1d21087 100644 --- a/primedev/squirrel/squirrelautobind.h +++ b/primedev/squirrel/squirrelautobind.h @@ -15,7 +15,7 @@ extern SquirrelAutoBindContainer* g_pSqAutoBindContainer; class __squirrelautobind; #define ADD_SQFUNC(returnType, funcName, argTypes, helpText, runOnContext) \ - template SQRESULT CONCAT2(Script_, funcName)(HSquirrelVM * sqvm); \ + template SQRESULT CONCAT2(Script_, funcName)(HSQUIRRELVM sqvm); \ namespace \ { \ __squirrelautobind CONCAT2(__squirrelautobind, __LINE__)( \ @@ -35,10 +35,10 @@ class __squirrelautobind; returnType, __STR(funcName), argTypes, helpText, CONCAT2(Script_, funcName) < ScriptContext::SERVER >); \ }); \ } \ - template SQRESULT CONCAT2(Script_, funcName)(HSquirrelVM * sqvm) + template SQRESULT CONCAT2(Script_, funcName)(HSQUIRRELVM sqvm) #define REPLACE_SQFUNC(funcName, runOnContext) \ - template SQRESULT CONCAT2(Script_, funcName)(HSquirrelVM * sqvm); \ + template SQRESULT CONCAT2(Script_, funcName)(HSQUIRRELVM sqvm); \ namespace \ { \ __squirrelautobind CONCAT2(__squirrelautobind, __LINE__)( \ @@ -57,7 +57,7 @@ class __squirrelautobind; __STR(funcName), CONCAT2(Script_, funcName) < ScriptContext::SERVER >); \ }); \ } \ - template SQRESULT CONCAT2(Script_, funcName)(HSquirrelVM * sqvm) + template SQRESULT CONCAT2(Script_, funcName)(HSQUIRRELVM sqvm) class __squirrelautobind { diff --git a/primedev/squirrel/squirrelclasstypes.h b/primedev/squirrel/squirrelclasstypes.h index 55897b698..f53f6d183 100644 --- a/primedev/squirrel/squirrelclasstypes.h +++ b/primedev/squirrel/squirrelclasstypes.h @@ -1,83 +1,14 @@ #pragma once -#include "squirreldatatypes.h" -#include - -enum SQRESULT : SQInteger -{ - SQRESULT_ERROR = -1, - SQRESULT_NULL = 0, - SQRESULT_NOTNULL = 1, -}; - -typedef SQRESULT (*SQFunction)(HSquirrelVM* sqvm); +#include "vscript/vscript.h" -enum class eSQReturnType -{ - Float = 0x1, - Vector = 0x3, - Integer = 0x5, - Boolean = 0x6, - Entity = 0xD, - String = 0x21, - Default = 0x20, - Arrays = 0x25, - Asset = 0x28, - Table = 0x26, -}; +#include const std::map PrintSQRESULT = { {SQRESULT::SQRESULT_ERROR, "SQRESULT_ERROR"}, {SQRESULT::SQRESULT_NULL, "SQRESULT_NULL"}, {SQRESULT::SQRESULT_NOTNULL, "SQRESULT_NOTNULL"}}; -struct CompileBufferState -{ - const SQChar* buffer; - const SQChar* bufferPlusLength; - const SQChar* bufferAgain; - - CompileBufferState(const std::string& code) - { - buffer = code.c_str(); - bufferPlusLength = code.c_str() + code.size(); - bufferAgain = code.c_str(); - } -}; - -struct SQFuncRegistration -{ - const char* squirrelFuncName; - const char* cppFuncName; - const char* helpText; - const char* returnTypeString; - const char* argTypes; - uint32_t unknown1; - uint32_t devLevel; - const char* shortNameMaybe; - uint32_t unknown2; - eSQReturnType returnType; - uint32_t* externalBufferPointer; - uint64_t externalBufferSize; - uint64_t unknown3; - uint64_t unknown4; - SQFunction funcPtr; - - SQFuncRegistration() - { - memset(this, 0, sizeof(SQFuncRegistration)); - this->returnType = eSQReturnType::Default; - } -}; - -enum class ScriptContext : int -{ - INVALID = -1, - SERVER, - CLIENT, - UI, -}; - typedef std::vector> FunctionVector; typedef std::function VoidFunction; @@ -185,56 +116,56 @@ typedef int64_t (*RegisterSquirrelFuncType)(CSquirrelVM* sqvm, SQFuncRegistratio typedef void (*sq_defconstType)(CSquirrelVM* sqvm, const SQChar* name, int value); typedef SQRESULT (*sq_compilebufferType)( - HSquirrelVM* sqvm, CompileBufferState* compileBuffer, const char* file, int a1, SQBool bShouldThrowError); -typedef SQRESULT (*sq_callType)(HSquirrelVM* sqvm, SQInteger iArgs, SQBool bShouldReturn, SQBool bThrowError); -typedef SQInteger (*sq_raiseerrorType)(HSquirrelVM* sqvm, const SQChar* pError); + HSQUIRRELVM sqvm, SQBufferState* compileBuffer, const char* file, int a1, SQBool bShouldThrowError); +typedef SQRESULT (*sq_callType)(HSQUIRRELVM sqvm, SQInteger iArgs, SQBool bShouldReturn, SQBool bThrowError); +typedef SQInteger (*sq_raiseerrorType)(HSQUIRRELVM sqvm, const SQChar* pError); typedef bool (*sq_compilefileType)(CSquirrelVM* sqvm, const char* path, const char* name, int a4); // sq stack array funcs -typedef void (*sq_newarrayType)(HSquirrelVM* sqvm, SQInteger iStackpos); -typedef SQRESULT (*sq_arrayappendType)(HSquirrelVM* sqvm, SQInteger iStackpos); +typedef void (*sq_newarrayType)(HSQUIRRELVM sqvm, SQInteger iStackpos); +typedef SQRESULT (*sq_arrayappendType)(HSQUIRRELVM sqvm, SQInteger iStackpos); // sq table funcs -typedef SQRESULT (*sq_newtableType)(HSquirrelVM* sqvm); -typedef SQRESULT (*sq_newslotType)(HSquirrelVM* sqvm, SQInteger idx, SQBool bStatic); +typedef SQRESULT (*sq_newtableType)(HSQUIRRELVM sqvm); +typedef SQRESULT (*sq_newslotType)(HSQUIRRELVM sqvm, SQInteger idx, SQBool bStatic); // sq stack push funcs -typedef void (*sq_pushroottableType)(HSquirrelVM* sqvm); -typedef void (*sq_pushstringType)(HSquirrelVM* sqvm, const SQChar* pStr, SQInteger iLength); -typedef void (*sq_pushintegerType)(HSquirrelVM* sqvm, SQInteger i); -typedef void (*sq_pushfloatType)(HSquirrelVM* sqvm, SQFloat f); -typedef void (*sq_pushboolType)(HSquirrelVM* sqvm, SQBool b); -typedef void (*sq_pushassetType)(HSquirrelVM* sqvm, const SQChar* str, SQInteger iLength); -typedef void (*sq_pushvectorType)(HSquirrelVM* sqvm, const SQFloat* pVec); -typedef void (*sq_pushobjectType)(HSquirrelVM* sqvm, SQObject* pVec); +typedef void (*sq_pushroottableType)(HSQUIRRELVM sqvm); +typedef void (*sq_pushstringType)(HSQUIRRELVM sqvm, const SQChar* pStr, SQInteger iLength); +typedef void (*sq_pushintegerType)(HSQUIRRELVM sqvm, SQInteger i); +typedef void (*sq_pushfloatType)(HSQUIRRELVM sqvm, SQFloat f); +typedef void (*sq_pushboolType)(HSQUIRRELVM sqvm, SQBool b); +typedef void (*sq_pushassetType)(HSQUIRRELVM sqvm, const SQChar* str, SQInteger iLength); +typedef void (*sq_pushvectorType)(HSQUIRRELVM sqvm, const SQFloat* pVec); +typedef void (*sq_pushobjectType)(HSQUIRRELVM sqvm, SQObject* pVec); // sq stack get funcs -typedef const SQChar* (*sq_getstringType)(HSquirrelVM* sqvm, SQInteger iStackpos); -typedef SQInteger (*sq_getintegerType)(HSquirrelVM* sqvm, SQInteger iStackpos); -typedef SQFloat (*sq_getfloatType)(HSquirrelVM*, SQInteger iStackpos); -typedef SQBool (*sq_getboolType)(HSquirrelVM*, SQInteger iStackpos); -typedef SQRESULT (*sq_getType)(HSquirrelVM* sqvm, SQInteger iStackpos); -typedef SQRESULT (*sq_getassetType)(HSquirrelVM* sqvm, SQInteger iStackpos, const char** pResult); -typedef SQRESULT (*sq_getuserdataType)(HSquirrelVM* sqvm, SQInteger iStackpos, void** pData, uint64_t* pTypeId); -typedef SQFloat* (*sq_getvectorType)(HSquirrelVM* sqvm, SQInteger iStackpos); -typedef SQBool (*sq_getthisentityType)(HSquirrelVM*, void** ppEntity); -typedef void (*sq_getobjectType)(HSquirrelVM*, SQInteger iStackPos, SQObject* pOutObj); - -typedef long long (*sq_stackinfosType)(HSquirrelVM* sqvm, int iLevel, SQStackInfos* pOutObj, int iCallStackSize); +typedef const SQChar* (*sq_getstringType)(HSQUIRRELVM sqvm, SQInteger iStackpos); +typedef SQInteger (*sq_getintegerType)(HSQUIRRELVM sqvm, SQInteger iStackpos); +typedef SQFloat (*sq_getfloatType)(HSQUIRRELVM, SQInteger iStackpos); +typedef SQBool (*sq_getboolType)(HSQUIRRELVM, SQInteger iStackpos); +typedef SQRESULT (*sq_getType)(HSQUIRRELVM sqvm, SQInteger iStackpos); +typedef SQRESULT (*sq_getassetType)(HSQUIRRELVM sqvm, SQInteger iStackpos, const char** pResult); +typedef SQRESULT (*sq_getuserdataType)(HSQUIRRELVM sqvm, SQInteger iStackpos, void** pData, uint64_t* pTypeId); +typedef SQFloat* (*sq_getvectorType)(HSQUIRRELVM sqvm, SQInteger iStackpos); +typedef SQBool (*sq_getthisentityType)(HSQUIRRELVM, void** ppEntity); +typedef void (*sq_getobjectType)(HSQUIRRELVM, SQInteger iStackPos, SQObject* pOutObj); + +typedef long long (*sq_stackinfosType)(HSQUIRRELVM sqvm, int iLevel, SQStackInfos* pOutObj, int iCallStackSize); // sq stack userpointer funcs -typedef void* (*sq_createuserdataType)(HSquirrelVM* sqvm, SQInteger iSize); -typedef SQRESULT (*sq_setuserdatatypeidType)(HSquirrelVM* sqvm, SQInteger iStackpos, uint64_t iTypeId); +typedef void* (*sq_createuserdataType)(HSQUIRRELVM sqvm, SQInteger iSize); +typedef SQRESULT (*sq_setuserdatatypeidType)(HSQUIRRELVM sqvm, SQInteger iStackpos, uint64_t iTypeId); // sq misc entity funcs typedef void* (*sq_getentityfrominstanceType)(CSquirrelVM* sqvm, SQObject* pInstance, char** ppEntityConstant); typedef SQObject* (*sq_createscriptinstanceType)(void* ent); typedef char** (*sq_GetEntityConstantType)(); -typedef int (*sq_getfunctionType)(HSquirrelVM* sqvm, const char* name, SQObject* returnObj, const char* signature); +typedef int (*sq_getfunctionType)(HSQUIRRELVM sqvm, const char* name, SQObject* returnObj, const char* signature); // structs -typedef SQRESULT (*sq_pushnewstructinstanceType)(HSquirrelVM* sqvm, int fieldCount); -typedef SQRESULT (*sq_sealstructslotType)(HSquirrelVM* sqvm, int slotIndex); +typedef SQRESULT (*sq_pushnewstructinstanceType)(HSQUIRRELVM sqvm, int fieldCount); +typedef SQRESULT (*sq_sealstructslotType)(HSQUIRRELVM sqvm, int slotIndex); #pragma endregion diff --git a/primedev/squirrel/squirreldatatypes.h b/primedev/squirrel/squirreldatatypes.h deleted file mode 100644 index 84ab15ecc..000000000 --- a/primedev/squirrel/squirreldatatypes.h +++ /dev/null @@ -1,501 +0,0 @@ -#pragma once -/* - This file has been generated by IDA. - It contains local type definitions from - the type library 'server.dll' -*/ - -struct HSquirrelVM; -struct CallInfo; -struct SQTable; -struct SQString; -struct SQFunctionProto; -struct SQClosure; -struct SQSharedState; -struct StringTable; -struct SQStructInstance; -struct SQStructDef; -struct SQNativeClosure; -struct SQArray; -struct tableNode; -struct SQUserData; -struct CSquirrelVM; - -typedef void (*releasehookType)(void* val, int size); - -// stolen from ttf2sdk: sqvm types -typedef float SQFloat; -typedef long SQInteger; -typedef unsigned long SQUnsignedInteger; -typedef char SQChar; -typedef SQUnsignedInteger SQBool; - -/* 127 */ -enum SQObjectType : int -{ - _RT_NULL = 0x1, - _RT_INTEGER = 0x2, - _RT_FLOAT = 0x4, - _RT_BOOL = 0x8, - _RT_STRING = 0x10, - _RT_TABLE = 0x20, - _RT_ARRAY = 0x40, - _RT_USERDATA = 0x80, - _RT_CLOSURE = 0x100, - _RT_NATIVECLOSURE = 0x200, - _RT_GENERATOR = 0x400, - OT_USERPOINTER = 0x800, - _RT_USERPOINTER = 0x800, - _RT_THREAD = 0x1000, - _RT_FUNCPROTO = 0x2000, - _RT_CLASS = 0x4000, - _RT_INSTANCE = 0x8000, - _RT_WEAKREF = 0x10000, - OT_VECTOR = 0x40000, - SQOBJECT_CANBEFALSE = 0x1000000, - OT_NULL = 0x1000001, - OT_BOOL = 0x1000008, - SQOBJECT_DELEGABLE = 0x2000000, - SQOBJECT_NUMERIC = 0x4000000, - OT_INTEGER = 0x5000002, - OT_FLOAT = 0x5000004, - SQOBJECT_REF_COUNTED = 0x8000000, - OT_STRING = 0x8000010, - OT_ARRAY = 0x8000040, - OT_CLOSURE = 0x8000100, - OT_NATIVECLOSURE = 0x8000200, - OT_ASSET = 0x8000400, - OT_THREAD = 0x8001000, - OT_FUNCPROTO = 0x8002000, - OT_CLAAS = 0x8004000, - OT_STRUCT = 0x8200000, - OT_WEAKREF = 0x8010000, - OT_TABLE = 0xA000020, - OT_USERDATA = 0xA000080, - OT_INSTANCE = 0xA008000, - OT_ENTITY = 0xA400000, -}; - -/* 156 */ -union SQObjectValue -{ - SQString* asString; - SQTable* asTable; - SQClosure* asClosure; - SQFunctionProto* asFuncProto; - SQStructDef* asStructDef; - long long as64Integer; - SQNativeClosure* asNativeClosure; - SQArray* asArray; - HSquirrelVM* asThread; - float asFloat; - int asInteger; - SQUserData* asUserdata; - SQStructInstance* asStructInstance; -}; - -/* 160 */ -struct SQVector -{ - SQObjectType _Type; - float x; - float y; - float z; -}; - -/* 128 */ -struct SQObject -{ - SQObjectType _Type; - int structNumber; - SQObjectValue _VAL; -}; - -/* 138 */ -struct alignas(8) SQString -{ - void* vftable; - int uiRef; - int padding; - SQString* _next_maybe; - SQSharedState* sharedState; - int length; - unsigned char gap_24[4]; - char _hash[8]; - char _val[1]; -}; - -/* 137 */ -struct alignas(8) SQTable -{ - void* vftable; - unsigned char gap_08[4]; - int uiRef; - unsigned char gap_10[8]; - void* pointer_18; - void* pointer_20; - void* _sharedState; - long long field_30; - tableNode* _nodes; - int _numOfNodes; - int size; - int field_48; - int _usedNodes; - unsigned char _gap_50[20]; - int field_64; - unsigned char _gap_68[80]; -}; - -/* 140 */ -struct alignas(8) SQClosure -{ - void* vftable; - unsigned char gap_08[4]; - int uiRef; - void* pointer_10; - void* pointer_18; - void* pointer_20; - void* sharedState; - SQObject obj_30; - SQObject _function; - SQObject* _outervalues; - unsigned char gap_58[8]; - unsigned char gap_60[96]; - SQObject* objectPointer_C0; - unsigned char gap_C8[16]; -}; - -/* 139 */ -struct alignas(8) SQFunctionProto -{ - void* vftable; - unsigned char gap_08[4]; - int uiRef; - unsigned char gap_10[8]; - void* pointer_18; - void* pointer_20; - void* sharedState; - void* pointer_30; - SQObjectType _fileNameType; - SQString* _fileName; - SQObjectType _funcNameType; - SQString* _funcName; - SQObject obj_58; - unsigned char gap_68[12]; - int _stacksize; - unsigned char gap_78[48]; - int nParameters; - unsigned char gap_AC[60]; - int nDefaultParams; - unsigned char gap_EC[200]; -}; - -/* 152 */ -struct SQStructDef -{ - void* vtable; - int uiRef; - unsigned char padding_C[4]; - unsigned char unknown[24]; - SQSharedState* sharedState; - SQObjectType _nameType; - SQString* _name; - unsigned char gap_38[16]; - SQObjectType _variableNamesType; - SQTable* _variableNames; - unsigned char gap_[32]; -}; - -/* 157 */ -struct alignas(8) SQNativeClosure -{ - void* vftable; - int uiRef; - unsigned char gap_C[4]; - long long value_10; - long long value_18; - long long value_20; - SQSharedState* sharedState; - char unknown_30; - unsigned char padding_34[7]; - long long value_38; - long long value_40; - long long value_48; - long long value_50; - long long value_58; - SQObjectType _nameType; - SQString* _name; - long long value_70; - long long value_78; - unsigned char justInCaseGap_80[300]; -}; - -/* 162 */ -struct SQArray -{ - void* vftable; - int uiRef; - unsigned char gap_24[36]; - SQObject* _values; - int _usedSlots; - int _allocated; -}; - -/* 129 */ -struct alignas(8) HSquirrelVM -{ - void* vftable; - int uiRef; - unsigned char gap_8[12]; - void* _toString; - void* _roottable_pointer; - void* pointer_28; - CallInfo* ci; - CallInfo* _callstack; - int _callstacksize; - int _stackbase; - SQObject* _stackOfCurrentFunction; - SQSharedState* sharedState; - void* pointer_58; - void* pointer_60; - int _top; - SQObject* _stack; - unsigned char gap_78[8]; - SQObject* _vargvstack; - unsigned char gap_88[8]; - SQObject temp_reg; - unsigned char gapA0[8]; - void* pointer_A8; - unsigned char gap_B0[8]; - SQObject _roottable_object; - SQObject _lasterror; - SQObject _errorHandler; - long long field_E8; - int traps; - unsigned char gap_F4[12]; - int _nnativecalls; - int _suspended; - int _suspended_root; - int _unk; - int _suspended_target; - int trapAmount; - int _suspend_varargs; - int unknown_field_11C; - SQObject object_120; -}; - -/* 150 */ -struct SQStructInstance -{ - void* vftable; - __int32 uiRef; - BYTE gap_C[4]; - __int64 unknown_10; - void* pointer_18; - __int64 unknown_20; - SQSharedState* _sharedState; - unsigned int size; - BYTE gap_34[4]; - SQObject data[1]; // This struct is dynamically sized, so this size is unknown -}; - -/* 148 */ -struct SQSharedState -{ - unsigned char gap_0[72]; - void* unknown; - unsigned char gap_50[16344]; - SQObjectType _unknownTableType00; - long long _unknownTableValue00; - unsigned char gap_4038[16]; - StringTable* _stringTable; - unsigned char gap_4050[32]; - SQObjectType _unknownTableType0; - long long _unknownTableValue0; - SQObjectType _unknownObjectType1; - long long _unknownObjectValue1; - unsigned char gap_4090[8]; - SQObjectType _unknownArrayType2; - long long _unknownArrayValue2; - SQObjectType _gobalsArrayType; - SQStructInstance* _globalsArray; - unsigned char gap_40B8[16]; - SQObjectType _nativeClosuresType; - SQTable* _nativeClosures; - SQObjectType _typedConstantsType; - SQTable* _typedConstants; - SQObjectType _untypedConstantsType; - SQTable* _untypedConstants; - SQObjectType _globalsMaybeType; - SQTable* _globals; - SQObjectType _functionsType; - SQTable* _functions; - SQObjectType _structsType; - SQTable* _structs; - SQObjectType _typeDefsType; - SQTable* _typeDefs; - SQObjectType unknownTableType; - SQTable* unknownTable; - SQObjectType _squirrelFilesType; - SQTable* _squirrelFiles; - unsigned char gap_4158[80]; - SQObjectType _nativeClosures2Type; - SQTable* _nativeClosures2; - SQObjectType _entityTypesMaybeType; - SQTable* _entityTypesMaybe; - SQObjectType unknownTable2Type; - SQTable* unknownTable2; - unsigned char gap_41D8[72]; - SQObjectType _compilerKeywordsType; - SQTable* _compilerKeywords; - HSquirrelVM* _currentThreadMaybe; - unsigned char gap_4238[8]; - SQObjectType unknownTable3Type; - SQTable* unknownTable3; - unsigned char gap_4250[16]; - SQObjectType unknownThreadType; - SQTable* unknownThread; - SQObjectType _tableNativeFunctionsType; - SQTable* _tableNativeFunctions; - SQObjectType _unknownTableType4; - long long _unknownObjectValue4; - SQObjectType _unknownObjectType5; - long long _unknownObjectValue5; - SQObjectType _unknownObjectType6; - long long _unknownObjectValue6; - SQObjectType _unknownObjectType7; - long long _unknownObjectValue7; - SQObjectType _unknownObjectType8; - long long _unknownObjectValue8; - SQObjectType _unknownObjectType9; - long long _unknownObjectValue9; - SQObjectType _unknownObjectType10; - long long _unknownObjectValue10; - SQObjectType _unknownObjectType11; - long long _unknownObjectValue11; - SQObjectType _unknownObjectType12; - long long _unknownObjectValue12; - SQObjectType _unknownObjectType13; - long long _unknownObjectValue13; - SQObjectType _unknownObjectType14; - long long _unknownObjectValue14; - SQObjectType _unknownObjectType15; - long long _unknownObjectValue15; - unsigned char gap_4340[16]; - void* printFunction; - unsigned char gap_4358[16]; - void* logEntityFunction; - unsigned char gap_4370[40]; - SQObjectType _waitStringType; - SQString* _waitStringValue; - SQObjectType _SpinOffAndWaitForStringType; - SQString* _SpinOffAndWaitForStringValue; - SQObjectType _SpinOffAndWaitForSoloStringType; - SQString* _SpinOffAndWaitForSoloStringValue; - SQObjectType _SpinOffStringType; - SQString* _SpinOffStringValue; - SQObjectType _SpinOffDelayedStringType; - SQString* _SpinOffDelayedStringValue; - CSquirrelVM* cSquirrelVM; - bool enableDebugInfo; // functionality stripped - unsigned char gap_43F1[23]; -}; - -/* 165 */ -struct tableNode -{ - SQObject val; - SQObject key; - tableNode* next; -}; - -/* 136 */ -struct alignas(8) CallInfo -{ - long long ip; - SQObject* _literals; - SQObject obj10; - SQObject closure; - int _etraps[4]; - int _root; - short _vargs_size; - short _vargs_base; - unsigned char gap[16]; -}; - -/* 149 */ -struct StringTable -{ - unsigned char gap_0[12]; - int _numofslots; - unsigned char gap_10[200]; -}; - -/* 141 */ -struct alignas(8) SQStackInfos -{ - char* _name; - char* _sourceName; - int _line; -}; - -/* 151 */ -struct alignas(4) SQInstruction -{ - int op; - int arg1; - int output; - short arg2; - short arg3; -}; - -/* 154 */ -struct SQLexer -{ - unsigned char gap_0[112]; -}; - -/* 153 */ -struct SQCompiler -{ - unsigned char gap_0[4]; - int _token; - unsigned char gap_8[8]; - SQObject object_10; - SQLexer lexer; - unsigned char gap_90[752]; - HSquirrelVM* sqvm; - unsigned char gap_288[8]; -}; - -/* 155 */ -struct CSquirrelVM -{ - BYTE gap_0[8]; - HSquirrelVM* sqvm; - BYTE gap_10[8]; - SQObject unknownObject_18; - __int64 unknown_28; - BYTE gap_30[12]; - __int32 vmContext; - BYTE gap_40[648]; - char* (*formatString)(__int64 a1, const char* format, ...); - BYTE gap_2D0[24]; -}; - -struct SQUserData -{ - void* vftable; - int uiRef; - char gap_12[4]; - long long unknown_10; - long long unknown_18; - long long unknown_20; - long long sharedState; - long long unknown_30; - int size; - char padding1[4]; - releasehookType releaseHook; - long long typeId; - char data[1]; -}; diff --git a/primedev/vscript/languages/squirrel_re/include/squirrel.h b/primedev/vscript/languages/squirrel_re/include/squirrel.h new file mode 100644 index 000000000..b068ff06b --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/include/squirrel.h @@ -0,0 +1,95 @@ +#pragma once + +class Mod; +struct SQBufferState; +class CBaseEntity; + +struct SQVM; +struct SQObject; +struct SQTable; +struct SQArray; +struct SQString; +struct SQClosure; +struct SQFunctionProto; +struct SQStructDef; +struct SQNativeClosure; +struct SQStructInstance; +struct SQUserData; +struct SQSharedState; + +typedef float SQFloat; +typedef long SQInteger; +typedef unsigned long SQUnsignedInteger; +typedef char SQChar; +typedef SQUnsignedInteger SQBool; + +typedef SQVM* HSQUIRRELVM; + +enum SQRESULT : SQInteger +{ + SQRESULT_ERROR = -1, + SQRESULT_NULL = 0, + SQRESULT_NOTNULL = 1, +}; + +enum class eSQReturnType +{ + Float = 0x1, + Vector = 0x3, + Integer = 0x5, + Boolean = 0x6, + Entity = 0xD, + String = 0x21, + Default = 0x20, + Arrays = 0x25, + Asset = 0x28, + Table = 0x26, +}; + +struct SQBufferState +{ + const SQChar* buffer; + const SQChar* bufferPlusLength; + const SQChar* bufferAgain; + + SQBufferState(const SQChar* pszCode) + { + buffer = pszCode; + bufferPlusLength = pszCode + strlen(pszCode); + bufferAgain = pszCode; + } +}; + +typedef SQRESULT (*SQFunction)(HSQUIRRELVM sqvm); + +struct SQFuncRegistration +{ + const char* squirrelFuncName; + const char* cppFuncName; + const char* helpText; + const char* returnTypeString; + const char* argTypes; + uint32_t unknown1; + uint32_t devLevel; + const char* shortNameMaybe; + uint32_t unknown2; + eSQReturnType returnType; + uint32_t* externalBufferPointer; + uint64_t externalBufferSize; + uint64_t unknown3; + uint64_t unknown4; + SQFunction funcPtr; + + SQFuncRegistration() + { + memset(this, 0, sizeof(SQFuncRegistration)); + this->returnType = eSQReturnType::Default; + } +}; + +struct alignas(8) SQStackInfos +{ + char* _name; + char* _sourceName; + int _line; +}; diff --git a/primedev/vscript/languages/squirrel_re/squirrel/sqarray.h b/primedev/vscript/languages/squirrel_re/squirrel/sqarray.h new file mode 100644 index 000000000..3214dc81d --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/squirrel/sqarray.h @@ -0,0 +1,12 @@ +#pragma once + +#include "vscript/languages/squirrel_re/include/squirrel.h" +#include "vscript/languages/squirrel_re/squirrel/sqobject.h" + +struct SQArray : public SQCollectable +{ + SQObject* _values; + int _usedSlots; + int _allocated; +}; +static_assert(sizeof(SQArray) == 0x40); diff --git a/primedev/vscript/languages/squirrel_re/squirrel/sqclosure.h b/primedev/vscript/languages/squirrel_re/squirrel/sqclosure.h new file mode 100644 index 000000000..85c3adef0 --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/squirrel/sqclosure.h @@ -0,0 +1,29 @@ +#pragma once + +#include "vscript/languages/squirrel_re/include/squirrel.h" +#include "vscript/languages/squirrel_re/squirrel/sqobject.h" + +struct alignas(8) SQClosure : public SQCollectable +{ + SQObject obj_30; + SQObject _function; + SQObject* _outervalues; + unsigned char gap_58[8]; +}; +static_assert(sizeof(SQClosure) == 96); + +struct alignas(8) SQNativeClosure : public SQCollectable +{ + char unknown_30; + unsigned char padding_34[7]; + long long value_38; + long long value_40; + long long value_48; + long long value_50; + long long value_58; + SQObjectType _nameType; + SQString* _name; + long long value_70; + long long value_78; +}; +static_assert(sizeof(SQNativeClosure) == 128); diff --git a/primedev/vscript/languages/squirrel_re/squirrel/sqcompiler.h b/primedev/vscript/languages/squirrel_re/squirrel/sqcompiler.h new file mode 100644 index 000000000..5a54751ca --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/squirrel/sqcompiler.h @@ -0,0 +1,26 @@ +#pragma once + +#include "vscript/languages/squirrel_re/include/squirrel.h" +#include "vscript/languages/squirrel_re/squirrel/sqlexer.h" + +struct SQCompiler +{ + BYTE gap0[4]; + int _token; + BYTE gap_8[8]; + SQObject object_10; + SQLexer lexer; + int64_t qword90; + int64_t qword98; + BYTE gapA0[280]; + bool bFatalError; + BYTE gap1B9[143]; + int64_t qword248; + int64_t qword250; + int64_t qword258; + int64_t qword260; + BYTE gap268[280]; + HSQUIRRELVM pSQVM; + unsigned char gap_288[8]; +}; +static_assert(sizeof(SQCompiler) == 0x390); diff --git a/primedev/vscript/languages/squirrel_re/squirrel/sqfunctionproto.h b/primedev/vscript/languages/squirrel_re/squirrel/sqfunctionproto.h new file mode 100644 index 000000000..77bec7ebe --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/squirrel/sqfunctionproto.h @@ -0,0 +1,24 @@ +#pragma once + +#include "vscript/languages/squirrel_re/include/squirrel.h" +#include "vscript/languages/squirrel_re/squirrel/sqobject.h" + +// NOTE [Fifty]: Variable sized struct +struct alignas(8) SQFunctionProto : public SQCollectable +{ + void* pointer_30; + SQObjectType _fileNameType; + SQString* _fileName; + SQObjectType _funcNameType; + SQString* _funcName; + SQObject obj_58; + unsigned char gap_68[12]; + int _stacksize; + unsigned char gap_78[48]; + int nParameters; + unsigned char gap_AC[60]; + int nDefaultParams; + unsigned char gap_EC[200]; +}; +// TODO [Fifty]: Find out the size of the base struct +static_assert(offsetof(SQFunctionProto, _fileName) == 0x40); // Sanity this check for now diff --git a/primedev/vscript/languages/squirrel_re/squirrel/sqlexer.h b/primedev/vscript/languages/squirrel_re/squirrel/sqlexer.h new file mode 100644 index 000000000..dc19bea8f --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/squirrel/sqlexer.h @@ -0,0 +1,9 @@ +#pragma once + +#include "vscript/languages/squirrel_re/include/squirrel.h" + +// TODO [Fifty]: Verify size +struct SQLexer +{ + unsigned char gap_0[112]; +}; diff --git a/primedev/vscript/languages/squirrel_re/squirrel/sqobject.h b/primedev/vscript/languages/squirrel_re/squirrel/sqobject.h new file mode 100644 index 000000000..ea5c0da96 --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/squirrel/sqobject.h @@ -0,0 +1,93 @@ +#pragma once + +#include "vscript/languages/squirrel_re/include/squirrel.h" + +struct SQTable; + +struct SQRefCounted +{ + void* vftable; + SQInteger uiRef; + void* weakRef; // Probably +}; + +struct SQCollectable : public SQRefCounted +{ + SQCollectable* _next; + SQCollectable* _prev; + SQSharedState* _sharedstate; +}; + +struct SQDelegable : public SQCollectable +{ + SQTable* _delegate; +}; + +enum SQObjectType : int +{ + _RT_NULL = 0x1, + _RT_INTEGER = 0x2, + _RT_FLOAT = 0x4, + _RT_BOOL = 0x8, + _RT_STRING = 0x10, + _RT_TABLE = 0x20, + _RT_ARRAY = 0x40, + _RT_USERDATA = 0x80, + _RT_CLOSURE = 0x100, + _RT_NATIVECLOSURE = 0x200, + _RT_GENERATOR = 0x400, + OT_USERPOINTER = 0x800, + _RT_USERPOINTER = 0x800, + _RT_THREAD = 0x1000, + _RT_FUNCPROTO = 0x2000, + _RT_CLASS = 0x4000, + _RT_INSTANCE = 0x8000, + _RT_WEAKREF = 0x10000, + OT_VECTOR = 0x40000, + SQOBJECT_CANBEFALSE = 0x1000000, + OT_NULL = 0x1000001, + OT_BOOL = 0x1000008, + SQOBJECT_DELEGABLE = 0x2000000, + SQOBJECT_NUMERIC = 0x4000000, + OT_INTEGER = 0x5000002, + OT_FLOAT = 0x5000004, + SQOBJECT_REF_COUNTED = 0x8000000, + OT_STRING = 0x8000010, + OT_ARRAY = 0x8000040, + OT_CLOSURE = 0x8000100, + OT_NATIVECLOSURE = 0x8000200, + OT_ASSET = 0x8000400, + OT_THREAD = 0x8001000, + OT_FUNCPROTO = 0x8002000, + OT_CLAAS = 0x8004000, + OT_STRUCT = 0x8200000, + OT_WEAKREF = 0x8010000, + OT_TABLE = 0xA000020, + OT_USERDATA = 0xA000080, + OT_INSTANCE = 0xA008000, + OT_ENTITY = 0xA400000, +}; + +union SQObjectValue +{ + SQString* asString; + SQTable* asTable; + SQClosure* asClosure; + SQFunctionProto* asFuncProto; + SQStructDef* asStructDef; + long long as64Integer; + SQNativeClosure* asNativeClosure; + SQArray* asArray; + HSQUIRRELVM asThread; + float asFloat; + int asInteger; + SQUserData* asUserdata; + SQStructInstance* asStructInstance; +}; + +struct SQObject +{ + SQObjectType _Type; + int structNumber; + SQObjectValue _VAL; +}; diff --git a/primedev/vscript/languages/squirrel_re/squirrel/sqopcodes.h b/primedev/vscript/languages/squirrel_re/squirrel/sqopcodes.h new file mode 100644 index 000000000..be0756c1d --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/squirrel/sqopcodes.h @@ -0,0 +1,13 @@ +#pragma once + +#include "vscript/languages/squirrel_re/include/squirrel.h" + +// TODO [Fifty]: Verify size +struct alignas(4) SQInstruction +{ + int op; + int arg1; + int output; + short arg2; + short arg3; +}; diff --git a/primedev/vscript/languages/squirrel_re/squirrel/sqstate.h b/primedev/vscript/languages/squirrel_re/squirrel/sqstate.h new file mode 100644 index 000000000..d5282ac7f --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/squirrel/sqstate.h @@ -0,0 +1,120 @@ +#pragma once + +#include "vscript/languages/squirrel_re/include/squirrel.h" + +class CSquirrelVM; +struct SQCompiler; + +// TODO [Fifty]: Verify size +struct StringTable +{ + unsigned char gap_0[12]; + int _numofslots; + unsigned char gap_10[200]; +}; + +struct SQSharedState +{ + unsigned char gap_0[72]; + void* unknown; + unsigned char gap_50[16344]; + SQObjectType _unknownTableType00; + long long _unknownTableValue00; + unsigned char gap_4038[16]; + StringTable* _stringTable; + unsigned char gap_4050[32]; + SQObjectType _unknownTableType0; + long long _unknownTableValue0; + SQObjectType _unknownObjectType1; + long long _unknownObjectValue1; + unsigned char gap_4090[8]; + SQObjectType _unknownArrayType2; + long long _unknownArrayValue2; + SQObjectType _gobalsArrayType; + SQStructInstance* _globalsArray; + unsigned char gap_40B8[16]; + SQObjectType _nativeClosuresType; + SQTable* _nativeClosures; + SQObjectType _typedConstantsType; + SQTable* _typedConstants; + SQObjectType _untypedConstantsType; + SQTable* _untypedConstants; + SQObjectType _globalsMaybeType; + SQTable* _globals; + SQObjectType _functionsType; + SQTable* _functions; + SQObjectType _structsType; + SQTable* _structs; + SQObjectType _typeDefsType; + SQTable* _typeDefs; + SQObjectType unknownTableType; + SQTable* unknownTable; + SQObjectType _squirrelFilesType; + SQTable* _squirrelFiles; + unsigned char gap_4158[80]; + SQObjectType _nativeClosures2Type; + SQTable* _nativeClosures2; + SQObjectType _entityTypesMaybeType; + SQTable* _entityTypesMaybe; + SQObjectType unknownTable2Type; + SQTable* unknownTable2; + unsigned char gap_41D8[64]; + SQCompiler* pCompiler; + SQObjectType _compilerKeywordsType; + SQTable* _compilerKeywords; + HSQUIRRELVM _currentThreadMaybe; + unsigned char gap_4238[8]; + SQObjectType unknownTable3Type; + SQTable* unknownTable3; + unsigned char gap_4250[16]; + SQObjectType unknownThreadType; + SQTable* unknownThread; + SQObjectType _tableNativeFunctionsType; + SQTable* _tableNativeFunctions; + SQObjectType _unknownTableType4; + long long _unknownObjectValue4; + SQObjectType _unknownObjectType5; + long long _unknownObjectValue5; + SQObjectType _unknownObjectType6; + long long _unknownObjectValue6; + SQObjectType _unknownObjectType7; + long long _unknownObjectValue7; + SQObjectType _unknownObjectType8; + long long _unknownObjectValue8; + SQObjectType _unknownObjectType9; + long long _unknownObjectValue9; + SQObjectType _unknownObjectType10; + long long _unknownObjectValue10; + SQObjectType _unknownObjectType11; + long long _unknownObjectValue11; + SQObjectType _unknownObjectType12; + long long _unknownObjectValue12; + SQObjectType _unknownObjectType13; + long long _unknownObjectValue13; + SQObjectType _unknownObjectType14; + long long _unknownObjectValue14; + SQObjectType _unknownObjectType15; + long long _unknownObjectValue15; + unsigned __int8 gap_4340[8]; + void* fnFatalErrorCallback; + void* fnPrintCallback; + unsigned __int8 gap_4358[16]; + void* logEntityFunction; + unsigned char gap_4370[1]; + SQChar szContextName[8]; + unsigned char gap[31]; + SQObjectType _waitStringType; + SQString* _waitStringValue; + SQObjectType _SpinOffAndWaitForStringType; + SQString* _SpinOffAndWaitForStringValue; + SQObjectType _SpinOffAndWaitForSoloStringType; + SQString* _SpinOffAndWaitForSoloStringValue; + SQObjectType _SpinOffStringType; + SQString* _SpinOffStringValue; + SQObjectType _SpinOffDelayedStringType; + SQString* _SpinOffDelayedStringValue; + CSquirrelVM* cSquirrelVM; + bool enableDebugInfo; // functionality stripped + unsigned char gap_43F1[23]; +}; +static_assert(sizeof(SQSharedState) == 17416); diff --git a/primedev/vscript/languages/squirrel_re/squirrel/sqstring.h b/primedev/vscript/languages/squirrel_re/squirrel/sqstring.h new file mode 100644 index 000000000..5b17f489c --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/squirrel/sqstring.h @@ -0,0 +1,15 @@ +#pragma once + +#include "vscript/languages/squirrel_re/include/squirrel.h" +#include "vscript/languages/squirrel_re/squirrel/sqobject.h" + +// NOTE [Fifty]: Variable sized struct +struct alignas(8) SQString : public SQRefCounted +{ + SQSharedState* sharedState; + int length; + unsigned char gap_24[4]; + char _hash[8]; + char _val[1]; +}; +static_assert(sizeof(SQString) == 56); // [Fifty]: Game allocates 56 + strlen diff --git a/primedev/vscript/languages/squirrel_re/squirrel/sqstruct.h b/primedev/vscript/languages/squirrel_re/squirrel/sqstruct.h new file mode 100644 index 000000000..1e357df8a --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/squirrel/sqstruct.h @@ -0,0 +1,24 @@ +#pragma once + +#include "vscript/languages/squirrel_re/include/squirrel.h" +#include "vscript/languages/squirrel_re/squirrel/sqobject.h" + +struct SQStructDef : public SQCollectable +{ + SQObjectType _nameType; + SQString* _name; + unsigned char gap_38[16]; + SQObjectType _variableNamesType; + SQTable* _variableNames; + unsigned char gap_[32]; +}; +static_assert(sizeof(SQStructDef) == 128); + +// NOTE [Fifty]: Variable sized struct +struct SQStructInstance : public SQCollectable +{ + unsigned int size; + BYTE gap_34[4]; + SQObject data[1]; +}; +static_assert(sizeof(SQStructInstance) == 72); diff --git a/primedev/vscript/languages/squirrel_re/squirrel/sqtable.h b/primedev/vscript/languages/squirrel_re/squirrel/sqtable.h new file mode 100644 index 000000000..e0ced4362 --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/squirrel/sqtable.h @@ -0,0 +1,21 @@ +#pragma once + +#include "vscript/languages/squirrel_re/include/squirrel.h" +#include "vscript/languages/squirrel_re/squirrel/sqobject.h" + +struct alignas(8) SQTable : public SQDelegable +{ + struct _HashNode + { + SQObject val; + SQObject key; + _HashNode* next; + }; + + _HashNode* _nodes; + int _numOfNodes; + int size; + int field_48; + int _usedNodes; +}; +static_assert(sizeof(SQTable) == 80); diff --git a/primedev/vscript/languages/squirrel_re/squirrel/squserdata.h b/primedev/vscript/languages/squirrel_re/squirrel/squserdata.h new file mode 100644 index 000000000..98ede8878 --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/squirrel/squserdata.h @@ -0,0 +1,15 @@ +#pragma once + +#include "vscript/languages/squirrel_re/include/squirrel.h" +#include "vscript/languages/squirrel_re/squirrel/sqobject.h" + +// NOTE [Fifty]: Variable sized struct +struct SQUserData : public SQDelegable +{ + int size; + char padding1[4]; + void* (*releasehook)(void* val, int size); + long long typeId; + char data[1]; +}; +static_assert(sizeof(SQUserData) == 88); // [Fifty]: Game allocates 87 + size (passed to the function) diff --git a/primedev/vscript/languages/squirrel_re/squirrel/sqvector.h b/primedev/vscript/languages/squirrel_re/squirrel/sqvector.h new file mode 100644 index 000000000..63984e909 --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/squirrel/sqvector.h @@ -0,0 +1,12 @@ +#pragma once + +#include "vscript/languages/squirrel_re/include/squirrel.h" + +// TODO [Fifty]: Verify size +struct SQVector +{ + SQObjectType _Type; + float x; + float y; + float z; +}; diff --git a/primedev/vscript/languages/squirrel_re/squirrel/sqvm.h b/primedev/vscript/languages/squirrel_re/squirrel/sqvm.h new file mode 100644 index 000000000..d16092e7b --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/squirrel/sqvm.h @@ -0,0 +1,69 @@ +#pragma once + +#include "vscript/languages/squirrel_re/include/squirrel.h" +#include "vscript/languages/squirrel_re/squirrel/sqstring.h" + +struct SQVM; + +enum class ScriptContext : int +{ + INVALID = -1, + SERVER, + CLIENT, + UI, +}; + +struct alignas(8) SQVM +{ + struct alignas(8) CallInfo + { + long long ip; + SQObject* _literals; + SQObject obj10; + SQObject closure; + int _etraps[4]; + int _root; + short _vargs_size; + short _vargs_base; + unsigned char gap[16]; + }; + + void* vftable; + int uiRef; + unsigned char gap_8[12]; + void* _toString; + void* _roottable_pointer; + void* pointer_28; + CallInfo* ci; + CallInfo* _callstack; + int _callstacksize; + int _stackbase; + SQObject* _stackOfCurrentFunction; + SQSharedState* sharedState; + void* pointer_58; + void* pointer_60; + int _top; + SQObject* _stack; + unsigned char gap_78[8]; + SQObject* _vargvstack; + unsigned char gap_88[8]; + SQObject temp_reg; + unsigned char gapA0[8]; + void* pointer_A8; + unsigned char gap_B0[8]; + SQObject _roottable_object; + SQObject _lasterror; + SQObject _errorHandler; + long long field_E8; + int traps; + unsigned char gap_F4[12]; + int _nnativecalls; + int _suspended; + int _suspended_root; + int _unk; + int _suspended_target; + int trapAmount; + int _suspend_varargs; + int unknown_field_11C; + SQObject object_120; +}; diff --git a/primedev/vscript/languages/squirrel_re/vsquirrel.h b/primedev/vscript/languages/squirrel_re/vsquirrel.h new file mode 100644 index 000000000..43be685ee --- /dev/null +++ b/primedev/vscript/languages/squirrel_re/vsquirrel.h @@ -0,0 +1,16 @@ +#pragma once + +struct CSquirrelVM +{ + BYTE gap_0[8]; + HSQUIRRELVM sqvm; + BYTE gap_10[8]; + SQObject unknownObject_18; + __int64 unknown_28; + BYTE gap_30[12]; + __int32 vmContext; + BYTE gap_40[648]; + char* (*formatString)(__int64 a1, const char* format, ...); + BYTE gap_2D0[24]; +}; +static_assert(sizeof(CSquirrelVM) == 744); diff --git a/primedev/vscript/vscript.h b/primedev/vscript/vscript.h new file mode 100644 index 000000000..4c9f072a9 --- /dev/null +++ b/primedev/vscript/vscript.h @@ -0,0 +1,20 @@ +#pragma once + +#include "vscript/languages/squirrel_re/include/squirrel.h" + +#include "vscript/languages/squirrel_re/squirrel/sqarray.h" +#include "vscript/languages/squirrel_re/squirrel/sqclosure.h" +#include "vscript/languages/squirrel_re/squirrel/sqcompiler.h" +#include "vscript/languages/squirrel_re/squirrel/sqfunctionproto.h" +#include "vscript/languages/squirrel_re/squirrel/sqlexer.h" +#include "vscript/languages/squirrel_re/squirrel/sqobject.h" +#include "vscript/languages/squirrel_re/squirrel/sqopcodes.h" +#include "vscript/languages/squirrel_re/squirrel/sqstate.h" +#include "vscript/languages/squirrel_re/squirrel/sqstring.h" +#include "vscript/languages/squirrel_re/squirrel/sqstruct.h" +#include "vscript/languages/squirrel_re/squirrel/sqtable.h" +#include "vscript/languages/squirrel_re/squirrel/squserdata.h" +#include "vscript/languages/squirrel_re/squirrel/sqvector.h" +#include "vscript/languages/squirrel_re/squirrel/sqvm.h" + +#include "vscript/languages/squirrel_re/vsquirrel.h" From 261fcdaec4467dd4fdde4907cf7863f308ec344d Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Mon, 2 Sep 2024 18:47:38 +0100 Subject: [PATCH 10/13] engine: Remove uses of Autohook from `host.cpp` (#802) Removes the AUTOHOOK macro from `host.cpp` and replaces it with HookAttach. --- primedev/engine/host.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/primedev/engine/host.cpp b/primedev/engine/host.cpp index dacb8fc1c..e414908b2 100644 --- a/primedev/engine/host.cpp +++ b/primedev/engine/host.cpp @@ -6,15 +6,11 @@ #include "r2engine.h" #include "core/tier0.h" -AUTOHOOK_INIT() - -// clang-format off -AUTOHOOK(Host_Init, engine.dll + 0x155EA0, -void, __fastcall, (bool bDedicated)) -// clang-format on +static void(__fastcall* o_pHost_Init)(bool bDedicated) = nullptr; +static void __fastcall h_Host_Init(bool bDedicated) { spdlog::info("Host_Init()"); - Host_Init(bDedicated); + o_pHost_Init(bDedicated); FixupCvarFlags(); // need to initialise these after host_init since they do stuff to preexisting concommands/convars without being client/server specific InitialiseCommandPrint(); @@ -29,5 +25,6 @@ void, __fastcall, (bool bDedicated)) ON_DLL_LOAD("engine.dll", Host_Init, (CModule module)) { - AUTOHOOK_DISPATCH() + o_pHost_Init = module.Offset(0x155EA0).RCast(); + HookAttach(&(PVOID&)o_pHost_Init, (PVOID)h_Host_Init); } From f9cb7d12c1036dda00b22d517f1466b6721ba4e0 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Tue, 3 Sep 2024 15:49:28 +0200 Subject: [PATCH 11/13] Update build instructions and CI for `build` subfolder (#808) Update build instructions for compiling from command line or both Windows and Linux Update CI to build into CI subfolder to match suggested build instructions Update gitignore in regards to build directory Co-authored-by: F1F7Y <64418963+F1F7Y@users.noreply.github.com> --- .github/workflows/ci.yml | 6 +++--- .github/workflows/release.yml | 14 +++++++------- .gitignore | 2 +- BUILD.md | 12 ++++++------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e562dc3bf..821a8d1c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - name: Setup msvc uses: ilammy/msvc-dev-cmd@v1 - name: Configure cmake - run: cmake -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="${{ env.BUILD_PROFILE }}" + run: cmake -G "Ninja" -B build -DCMAKE_BUILD_TYPE:STRING="${{ env.BUILD_PROFILE }}" - name: Setup resource file version shell: bash run: | @@ -33,7 +33,7 @@ jobs: FILEVERSION=$(echo ${{ env.NORTHSTAR_VERSION }} | tr '.' ',' | sed -E 's/-rc[0-9]+//' | tr -d '[:alpha:]') sed -i "s/0,0,0,1/${FILEVERSION}/g" primedev/ns_version.h - name: Build - run: cmake --build . + run: cmake --build build/ - name: Extract Short Commit Hash id: extract shell: bash @@ -43,7 +43,7 @@ jobs: with: name: NorthstarLauncher-${{ matrix.config.name }}-${{ steps.extract.outputs.commit }} path: | - game/ + build/game/ format-check: runs-on: ubuntu-latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e6dd8cc38..a440aea33 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,7 @@ jobs: - name: Setup msvc uses: ilammy/msvc-dev-cmd@v1 - name: Configure cmake - run: cmake -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="Release" + run: cmake -G "Ninja" -B build -DCMAKE_BUILD_TYPE:STRING="Release" - name: Setup resource file version shell: bash run: | @@ -30,22 +30,22 @@ jobs: FILEVERSION=$(echo ${{ env.NORTHSTAR_VERSION }} | tr '.' ',' | sed -E 's/-rc[0-9]+//' | tr -d '[:alpha:]') sed -i "s/0,0,0,1/${FILEVERSION}/g" primedev/ns_version.h - name: Build - run: cmake --build . + run: cmake --build build/ - name: Upload launcher build as artifact uses: actions/upload-artifact@v3 with: name: northstar-launcher path: | - game/*.exe - game/*.dll - game/bin/x64_retail/*.dll + build/game/*.exe + build/game/*.dll + build/game/bin/x64_retail/*.dll - name: Upload debug build artifact uses: actions/upload-artifact@v3 with: name: launcher-debug-files path: | - game/*.pdb - game/bin/x64_retail/*.pdb + build/game/*.pdb + build/game/bin/x64_retail/*.pdb upload-launcher-to-release: if: startsWith(github.ref, 'refs/tags/v') diff --git a/.gitignore b/.gitignore index c3c50a405..5e881b2d1 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ mono_crash.* # CMake output out/ -game/ +build/game/ build/ CMakeFiles/ cmake_install.cmake diff --git a/BUILD.md b/BUILD.md index f0ed5e722..76f20eb6b 100644 --- a/BUILD.md +++ b/BUILD.md @@ -37,9 +37,9 @@ Developers who can work a command line may be interested in using [Visual Studio - Follow the same steps as above for Visual Studio Build Tools, but instead of opening in Visual Studio, run the Command Prompt for VS 2022 and navigate to the NorthstarLauncher. -- Run `cmake . -G "Ninja"` to generate build files. +- Run `cmake . -G "Ninja" -B build` to generate build files. -- Run `cmake --build .` to build the project. +- Run `cmake --build build/` to build the project. ## Linux ### Steps @@ -47,8 +47,8 @@ Developers who can work a command line may be interested in using [Visual Studio 2. Use `cd` to navigate to the cloned repo's directory 3. Then, run the following commands in order: * `docker build --rm -t northstar-build-fedora .` -* `docker run --rm -it -e CC=cl -e CXX=cl --mount type=bind,source="$(pwd)",destination=/build northstar-build-fedora cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_NAME=Windows -G "Ninja"` -* `docker run --rm -it -e CC=cl -e CXX=cl --mount type=bind,source="$(pwd)",destination=/build northstar-build-fedora cmake --build .` +* `docker run --rm -it -e CC=cl -e CXX=cl --mount type=bind,source="$(pwd)",destination=/build northstar-build-fedora cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_NAME=Windows -G "Ninja" -B build` +* `docker run --rm -it -e CC=cl -e CXX=cl --mount type=bind,source="$(pwd)",destination=/build northstar-build-fedora cmake --build build/` #### Podman @@ -57,5 +57,5 @@ When using [`podman`](https://podman.io/) instead of Docker on an SELinux enable As such the corresponding commands are * `podman build --rm -t northstar-build-fedora .` -* `podman run --rm -it -e CC=cl -e CXX=cl --mount type=bind,source="$(pwd)",destination=/build,z northstar-build-fedora cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_NAME=Windows -G "Ninja"` -* `podman run --rm -it -e CC=cl -e CXX=cl --mount type=bind,source="$(pwd)",destination=/build,z northstar-build-fedora cmake --build .` +* `podman run --rm -it -e CC=cl -e CXX=cl --mount type=bind,source="$(pwd)",destination=/build,z northstar-build-fedora cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_NAME=Windows -G "Ninja" -B build` +* `podman run --rm -it -e CC=cl -e CXX=cl --mount type=bind,source="$(pwd)",destination=/build,z northstar-build-fedora cmake --build build/` From 8f6f81caa54ad5122c6f8be26e59795161676d00 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Tue, 3 Sep 2024 23:53:31 +0200 Subject: [PATCH 12/13] Ensure whitespace indentation is consistent in Dockerfile (#809) --- Dockerfile | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 261d649fa..af1bf3414 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,18 @@ FROM registry.fedoraproject.org/fedora-toolbox:38 RUN dnf update -y && \ dnf install -y \ - git \ - wine \ - wine-mono \ - python3 \ - msitools \ - python3-simplejson \ - python3-six \ - cmake \ - ninja-build \ - make \ - samba \ - libunwind && \ + git \ + wine \ + wine-mono \ + python3 \ + msitools \ + python3-simplejson \ + python3-six \ + cmake \ + ninja-build \ + make \ + samba \ + libunwind && \ dnf clean all && \ mkdir /opt/msvc/ /build From b75daf36ade1d8858adbbb98e1517cef8bd11ad0 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Wed, 4 Sep 2024 22:05:23 +0200 Subject: [PATCH 13/13] Bump clang-format-lint-action to v0.18.2 (#813) which is the newest upstream version currently --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 821a8d1c1..5f647faa0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,7 +49,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: DoozyX/clang-format-lint-action@v0.16.2 + - uses: DoozyX/clang-format-lint-action@v0.18.2 with: source: 'primedev' exclude: 'primedev/include primedev/thirdparty primedev/wsockproxy'