From 1b891ff2f166a5d00270c1cd00d2606d8cfd114d Mon Sep 17 00:00:00 2001 From: BobTheBob9 Date: Sat, 3 Sep 2022 01:08:39 +0100 Subject: various formatting changes and fixes --- NorthstarDLL/NorthstarDLL.vcxproj | 1349 ++++++++++++++--------------- NorthstarDLL/NorthstarDLL.vcxproj.filters | 3 - NorthstarDLL/dedicatedmaterialsystem.cpp | 1 - NorthstarDLL/exploitfixes.cpp | 30 +- NorthstarDLL/hoststate.cpp | 2 +- NorthstarDLL/logging.cpp | 12 +- NorthstarDLL/scriptdatatables.cpp | 23 +- NorthstarDLL/sigscanning.cpp | 41 - NorthstarDLL/squirrel.cpp | 2 +- NorthstarDLL/vector.h | 10 +- 10 files changed, 718 insertions(+), 755 deletions(-) delete mode 100644 NorthstarDLL/sigscanning.cpp (limited to 'NorthstarDLL') diff --git a/NorthstarDLL/NorthstarDLL.vcxproj b/NorthstarDLL/NorthstarDLL.vcxproj index ac1b3991..7b2ece51 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj +++ b/NorthstarDLL/NorthstarDLL.vcxproj @@ -1,676 +1,675 @@ - - - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {cfad2623-064f-453c-8196-79ee10292e32} - NorthstarDedicatedTest - 10.0 - NorthstarDLL - - - - DynamicLibrary - true - v143 - Unicode - - - DynamicLibrary - false - v143 - true - Unicode - - - - - - - - - - - - - - - - true - Northstar - - - false - Northstar - - - - Level3 - true - _DEBUG;NORTHSTARDEDICATEDTEST_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);CURL_STATICLIB - true - Use - pch.h - stdcpp20 - $(ProjectDir)include;%(AdditionalIncludeDirectories) - - - Windows - true - false - $(ProjectDir)include\MinHook.x64.lib;$(ProjectDir)include\libcurl\lib\libcurl_a.lib;dbghelp.lib;Wldap32.lib;Normaliz.lib;version.lib;%(AdditionalDependencies) - - - %(AdditionalLibraryDirectories) - - - - - - - copy /Y "$(TargetPath)" "$(SolutionDir)..\..\" - - - - - Level3 - true - true - true - NDEBUG;NORTHSTARDEDICATEDTEST_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);CURL_STATICLIB - true - Use - pch.h - stdcpp20 - $(ProjectDir)include;%(AdditionalIncludeDirectories) - MultiThreadedDLL - - - Windows - true - true - true - false - $(ProjectDir)include\MinHook.x64.lib;$(ProjectDir)include\libcurl\lib\libcurl_a.lib;dbghelp.lib;Wldap32.lib;Normaliz.lib;version.lib;%(AdditionalDependencies) - - - %(AdditionalLibraryDirectories) - - - - - - - copy /Y "$(TargetPath)" "$(SolutionDir)..\..\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Create - Create - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {cfad2623-064f-453c-8196-79ee10292e32} + NorthstarDedicatedTest + 10.0 + NorthstarDLL + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + true + Northstar + + + false + Northstar + + + + Level3 + true + _DEBUG;NORTHSTARDEDICATEDTEST_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);CURL_STATICLIB + true + Use + pch.h + stdcpp20 + $(ProjectDir)include;%(AdditionalIncludeDirectories) + + + Windows + true + false + $(ProjectDir)include\MinHook.x64.lib;$(ProjectDir)include\libcurl\lib\libcurl_a.lib;dbghelp.lib;Wldap32.lib;Normaliz.lib;version.lib;%(AdditionalDependencies) + + + %(AdditionalLibraryDirectories) + + + + + + + copy /Y "$(TargetPath)" "$(SolutionDir)..\..\" + + + + + Level3 + true + true + true + NDEBUG;NORTHSTARDEDICATEDTEST_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);CURL_STATICLIB + true + Use + pch.h + stdcpp20 + $(ProjectDir)include;%(AdditionalIncludeDirectories) + MultiThreadedDLL + + + Windows + true + true + true + false + $(ProjectDir)include\MinHook.x64.lib;$(ProjectDir)include\libcurl\lib\libcurl_a.lib;dbghelp.lib;Wldap32.lib;Normaliz.lib;version.lib;%(AdditionalDependencies) + + + %(AdditionalLibraryDirectories) + + + + + + + copy /Y "$(TargetPath)" "$(SolutionDir)..\..\" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NorthstarDLL/NorthstarDLL.vcxproj.filters b/NorthstarDLL/NorthstarDLL.vcxproj.filters index 293543f7..66fe25ca 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj.filters +++ b/NorthstarDLL/NorthstarDLL.vcxproj.filters @@ -1652,9 +1652,6 @@ Source Files\Hooks - - Source Files\Hooks - Source Files\Math diff --git a/NorthstarDLL/dedicatedmaterialsystem.cpp b/NorthstarDLL/dedicatedmaterialsystem.cpp index 18bf6a57..5dfa19ec 100644 --- a/NorthstarDLL/dedicatedmaterialsystem.cpp +++ b/NorthstarDLL/dedicatedmaterialsystem.cpp @@ -1,4 +1,3 @@ -#pragma once #include "pch.h" #include "dedicated.h" #include "tier0.h" diff --git a/NorthstarDLL/exploitfixes.cpp b/NorthstarDLL/exploitfixes.cpp index dbe065cc..419fc448 100644 --- a/NorthstarDLL/exploitfixes.cpp +++ b/NorthstarDLL/exploitfixes.cpp @@ -5,6 +5,7 @@ #include "tier0.h" #include "r2engine.h" #include "r2client.h" +#include "vector.h" AUTOHOOK_INIT() @@ -26,23 +27,6 @@ ConVar* Cvar_sv_cheats; return false; \ }()) -// Make sure 3 or less floats are valid -bool ValidateFloats(float a, float b = 0, float c = 0) -{ - return !isnan(a) && !isnan(b) && !isnan(c); -} - -struct Float3 -{ - float vals[3]; - - void MakeValid() - { - for (auto& val : vals) - if (isnan(val)) - val = 0; - } -}; // block bad netmessages // Servers can literally request a screenshot from any client, yeah no AUTOHOOK(CLC_Screenshot_WriteToBuffer, engine.dll + 0x22AF20, @@ -209,11 +193,11 @@ void, __fastcall, (void* buf, void* pCmd_move, void* pCmd_from)) // 4C 89 44 24 DWORD command_number; DWORD tick_count; float command_time; - Float3 worldViewAngles; + Vector3 worldViewAngles; BYTE gap18[4]; - Float3 localViewAngles; - Float3 attackangles; - Float3 move; + Vector3 localViewAngles; + Vector3 attackangles; + Vector3 move; DWORD buttons; BYTE impulse; short weaponselect; @@ -221,8 +205,8 @@ void, __fastcall, (void* buf, void* pCmd_move, void* pCmd_from)) // 4C 89 44 24 BYTE gap4C[24]; char headoffset; BYTE gap65[11]; - Float3 cameraPos; - Float3 cameraAngles; + Vector3 cameraPos; + Vector3 cameraAngles; BYTE gap88[4]; int tickSomething; DWORD dword90; diff --git a/NorthstarDLL/hoststate.cpp b/NorthstarDLL/hoststate.cpp index 6008a0f2..875d671d 100644 --- a/NorthstarDLL/hoststate.cpp +++ b/NorthstarDLL/hoststate.cpp @@ -72,7 +72,7 @@ void,, (CHostState* self)) g_pServerPresence->SetMap(g_pHostState->m_levelName); } -AUTOHOOK(CHostState__State_GameShutdown, engine.dll + 0x16E520, +AUTOHOOK(CHostState__State_GameShutdown, engine.dll + 0x16E640, void,, (CHostState* self)) { spdlog::info("HostState: GameShutdown"); diff --git a/NorthstarDLL/logging.cpp b/NorthstarDLL/logging.cpp index e82c2131..5bd5ae40 100644 --- a/NorthstarDLL/logging.cpp +++ b/NorthstarDLL/logging.cpp @@ -4,6 +4,7 @@ #include "concommand.h" #include "nsprefix.h" #include "bitbuf.h" +#include "tier0.h" #include "spdlog/sinks/basic_file_sink.h" #include @@ -225,11 +226,12 @@ void InitialiseLogging() AllocConsole(); // Bind stdout to receive console output. - FILE* fp; - freopen_s(&fp, "CONOUT$", "w", stdout); - //_dup2(_fileno(stdout), _fileno(stderr)); - - spdlog::default_logger()->set_pattern("[%H:%M:%S] [%l] %v"); + // these two lines are responsible for stuff to not show up in the console sometimes, from talking about it on discord + // apparently they were meant to make logging work when using -northstar, however from testing it seems that it doesnt + // work regardless of these two lines + // freopen("CONOUT$", "w", stdout); + // freopen("CONOUT$", "w", stderr); + spdlog::default_logger()->set_pattern("[%H:%M:%S] [%^%l%$] %v"); } ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", EngineSpewFuncHooks, ConVar, (CModule module)) diff --git a/NorthstarDLL/scriptdatatables.cpp b/NorthstarDLL/scriptdatatables.cpp index cd8a6b2a..2861b964 100644 --- a/NorthstarDLL/scriptdatatables.cpp +++ b/NorthstarDLL/scriptdatatables.cpp @@ -46,7 +46,6 @@ struct Datatable ConVar* Cvar_ns_prefer_datatable_from_disk; template Datatable* (*SQ_GetDatatableInternal)(HSquirrelVM* sqvm); -std::string DataTableToString(Datatable* datatable); struct CSVData { @@ -97,6 +96,7 @@ Vector3 StringToVector(char* pString) return vRet; } +// var function GetDataTable( asset path ) template SQRESULT SQ_GetDatatable(HSquirrelVM* sqvm) { const char* pAssetName; @@ -271,6 +271,7 @@ template SQRESULT SQ_GetDatatable(HSquirrelVM* sqvm) } } +// int function GetDataTableRowCount( var datatable, string columnName ) template SQRESULT SQ_GetDataTableColumnByName(HSquirrelVM* sqvm) { CSVData** pData; @@ -297,6 +298,7 @@ template SQRESULT SQ_GetDataTableColumnByName(HSquirrelV return SQRESULT_NOTNULL; } +// int function GetDataTableRowCount( var datatable ) template SQRESULT SQ_GetDataTableRowCount(HSquirrelVM* sqvm) { CSVData** pData; @@ -307,12 +309,11 @@ template SQRESULT SQ_GetDataTableRowCount(HSquirrelVM* s return g_pSquirrel->m_funcOriginals["GetDatatableRowCount"](sqvm); CSVData* csv = *pData; - const char* pColumnName = g_pSquirrel->getstring(sqvm, 2); - g_pSquirrel->pushinteger(sqvm, csv->dataPointers.size()); return SQRESULT_NOTNULL; } +// string function GetDataTableString( var datatable, int row, int col ) template SQRESULT SQ_GetDataTableString(HSquirrelVM* sqvm) { CSVData** pData; @@ -339,6 +340,7 @@ template SQRESULT SQ_GetDataTableString(HSquirrelVM* sqv return SQRESULT_NOTNULL; } +// asset function GetDataTableAsset( var datatable, int row, int col ) template SQRESULT SQ_GetDataTableAsset(HSquirrelVM* sqvm) { CSVData** pData; @@ -365,6 +367,7 @@ template SQRESULT SQ_GetDataTableAsset(HSquirrelVM* sqvm return SQRESULT_NOTNULL; } +// int function GetDataTableInt( var datatable, int row, int col ) template SQRESULT SQ_GetDataTableInt(HSquirrelVM* sqvm) { CSVData** pData; @@ -391,6 +394,7 @@ template SQRESULT SQ_GetDataTableInt(HSquirrelVM* sqvm) return SQRESULT_NOTNULL; } +// float function GetDataTableFloat( var datatable, int row, int col ) template SQRESULT SQ_GetDataTableFloat(HSquirrelVM* sqvm) { CSVData** pData; @@ -417,6 +421,7 @@ template SQRESULT SQ_GetDataTableFloat(HSquirrelVM* sqvm return SQRESULT_NOTNULL; } +// bool function GetDataTableBool( var datatable, int row, int col ) template SQRESULT SQ_GetDataTableBool(HSquirrelVM* sqvm) { CSVData** pData; @@ -443,6 +448,7 @@ template SQRESULT SQ_GetDataTableBool(HSquirrelVM* sqvm) return SQRESULT_NOTNULL; } +// vector function GetDataTableVector( var datatable, int row, int col ) template SQRESULT SQ_GetDataTableVector(HSquirrelVM* sqvm) { CSVData** pData; @@ -466,6 +472,7 @@ template SQRESULT SQ_GetDataTableVector(HSquirrelVM* sqv return SQRESULT_NOTNULL; } +// int function GetDataTableRowMatchingStringValue( var datatable, int col, string value ) template SQRESULT SQ_GetDataTableRowMatchingStringValue(HSquirrelVM* sqvm) { CSVData** pData; @@ -491,6 +498,7 @@ template SQRESULT SQ_GetDataTableRowMatchingStringValue( return SQRESULT_NOTNULL; } +// int function GetDataTableRowMatchingAssetValue( var datatable, int col, asset value ) template SQRESULT SQ_GetDataTableRowMatchingAssetValue(HSquirrelVM* sqvm) { CSVData** pData; @@ -517,6 +525,7 @@ template SQRESULT SQ_GetDataTableRowMatchingAssetValue(H return SQRESULT_NOTNULL; } +// int function GetDataTableRowMatchingFloatValue( var datatable, int col, float value ) template SQRESULT SQ_GetDataTableRowMatchingFloatValue(HSquirrelVM* sqvm) { CSVData** pData; @@ -542,6 +551,7 @@ template SQRESULT SQ_GetDataTableRowMatchingFloatValue(H return SQRESULT_NOTNULL; } +// int function GetDataTableRowMatchingIntValue( var datatable, int col, int value ) template SQRESULT SQ_GetDataTableRowMatchingIntValue(HSquirrelVM* sqvm) { CSVData** pData; @@ -567,6 +577,7 @@ template SQRESULT SQ_GetDataTableRowMatchingIntValue(HSq return SQRESULT_NOTNULL; } +// int function GetDataTableRowMatchingVectorValue( var datatable, int col, vector value ) template SQRESULT SQ_GetDataTableRowMatchingVectorValue(HSquirrelVM* sqvm) { CSVData** pData; @@ -593,6 +604,7 @@ template SQRESULT SQ_GetDataTableRowMatchingVectorValue( return SQRESULT_NOTNULL; } +// int function GetDataTableRowGreaterThanOrEqualToIntValue( var datatable, int col, int value ) template SQRESULT SQ_GetDataTableRowGreaterThanOrEqualToIntValue(HSquirrelVM* sqvm) { CSVData** pData; @@ -619,6 +631,7 @@ template SQRESULT SQ_GetDataTableRowGreaterThanOrEqualTo return SQRESULT_NOTNULL; } +// int function GetDataTableRowLessThanOrEqualToIntValue( var datatable, int col, int value ) template SQRESULT SQ_GetDataTableRowLessThanOrEqualToIntValue(HSquirrelVM* sqvm) { CSVData** pData; @@ -644,6 +657,7 @@ template SQRESULT SQ_GetDataTableRowLessThanOrEqualToInt return SQRESULT_NOTNULL; } +// int function GetDataTableRowGreaterThanOrEqualToFloatValue( var datatable, int col, float value ) template SQRESULT SQ_GetDataTableRowGreaterThanOrEqualToFloatValue(HSquirrelVM* sqvm) { CSVData** pData; @@ -669,6 +683,7 @@ template SQRESULT SQ_GetDataTableRowGreaterThanOrEqualTo return SQRESULT_NOTNULL; } +// int function GetDataTableRowLessThanOrEqualToFloatValue( var datatable, int col, float value ) template SQRESULT SQ_GetDataTableRowLessThanOrEqualToFloatValue(HSquirrelVM* sqvm) { CSVData** pData; @@ -919,4 +934,4 @@ ON_DLL_LOAD_RELIESON("engine.dll", SharedScriptDataTables, ConVar, (CModule modu RegisterConCommand("dump_datatables", ConCommand_dump_datatables, "dumps all datatables from a hardcoded list", FCVAR_NONE); RegisterConCommand("dump_datatable", ConCommand_dump_datatable, "dump a datatable", FCVAR_NONE); -} \ No newline at end of file +} diff --git a/NorthstarDLL/sigscanning.cpp b/NorthstarDLL/sigscanning.cpp deleted file mode 100644 index 618645e0..00000000 --- a/NorthstarDLL/sigscanning.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "pch.h" -#include "sigscanning.h" -#include - -// note: sigscanning is only really intended to be used for resolving stuff like shared function definitions -// we mostly use raw function addresses for stuff - -size_t GetModuleLength(HMODULE moduleHandle) -{ - // based on sigscan code from ttf2sdk, which is in turn based on CSigScan from https://wiki.alliedmods.net/Signature_Scanning - MEMORY_BASIC_INFORMATION mem; - VirtualQuery(moduleHandle, &mem, sizeof(mem)); - - IMAGE_DOS_HEADER* dos = (IMAGE_DOS_HEADER*)mem.AllocationBase; - IMAGE_NT_HEADERS* pe = (IMAGE_NT_HEADERS*)((unsigned char*)dos + dos->e_lfanew); - - return pe->OptionalHeader.SizeOfImage; -} - -void* FindSignature(std::string dllName, const char* sig, const char* mask) -{ - HMODULE module = GetModuleHandleA(dllName.c_str()); - - unsigned char* dllAddress = (unsigned char*)module; - unsigned char* dllEnd = dllAddress + GetModuleLength(module); - - size_t sigLength = strlen(mask); - - for (auto i = dllAddress; i < dllEnd - sigLength + 1; i++) - { - int j = 0; - for (; j < sigLength; j++) - if (mask[j] != '?' && sig[j] != i[j]) - break; - - if (j == sigLength) // loop finished of its own accord - return i; - } - - return nullptr; -} diff --git a/NorthstarDLL/squirrel.cpp b/NorthstarDLL/squirrel.cpp index 4bd4bca8..cf5cb49e 100644 --- a/NorthstarDLL/squirrel.cpp +++ b/NorthstarDLL/squirrel.cpp @@ -135,7 +135,7 @@ template void SquirrelManager::VMDestroyed() template void SquirrelManager::ExecuteCode(const char* pCode) { - if (!m_pSQVM) + if (!m_pSQVM || !m_pSQVM->sqvm) { spdlog::error("Cannot execute code, {} squirrel vm is not initialised", GetContextName(context)); return; diff --git a/NorthstarDLL/vector.h b/NorthstarDLL/vector.h index a5d68003..122fd211 100644 --- a/NorthstarDLL/vector.h +++ b/NorthstarDLL/vector.h @@ -12,11 +12,19 @@ union Vector3 float raw[3]; Vector3() : x(0), y(0), z(0) {} + Vector3(float x, float y, float z) : x(x), y(y), z(z) {} Vector3(float* pRawFloats) // assumes float[3] => vector { memcpy(raw, pRawFloats, sizeof(this)); } + void MakeValid() + { + for (auto& fl : raw) + if (isnan(fl)) + fl = 0; + } + // todo: more operators maybe bool operator==(const Vector3& other) { @@ -41,4 +49,4 @@ union QAngle { return x == other.x && y == other.y && z == other.z && w == other.w; } -}; \ No newline at end of file +}; -- cgit v1.2.3