From f33bab4fb3586fd06896a7730bce8913c2616b78 Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Thu, 2 Dec 2021 00:29:12 +0000 Subject: tier0 code cleanup and loadlibrary hook fix --- NorthstarDedicatedTest/tier0.cpp | 97 ---------------------------------------- 1 file changed, 97 deletions(-) delete mode 100644 NorthstarDedicatedTest/tier0.cpp (limited to 'NorthstarDedicatedTest/tier0.cpp') diff --git a/NorthstarDedicatedTest/tier0.cpp b/NorthstarDedicatedTest/tier0.cpp deleted file mode 100644 index 74ac02d3..00000000 --- a/NorthstarDedicatedTest/tier0.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include "pch.h" -#include "tier0.h" -#include -#include - -void* ResolveTier0Function(const char* name) -{ - HMODULE tier0 = GetModuleHandle(L"tier0.dll"); - - // todo: maybe cache resolved funcs? idk the performance hit of getprocaddress - //std::cout << "ResolveTier0Function " << name << " " << tier0 << "::" << GetProcAddress(tier0, name) << std::endl; - return GetProcAddress(tier0, name); -} - -// memory stuff -typedef IMemAlloc* (*Tier0CreateGlobalMemAlloc)(); -void* operator new(size_t n) -{ - // we should be trying to use tier0's g_pMemAllocSingleton, but atm i can't get it stable - // this actually seems relatively stable though, somehow??? - return malloc(n); - - //IMemAlloc** alloc = (IMemAlloc**)ResolveTier0Function("g_pMemAllocSingleton"); - //if (!alloc) - //{ - // Tier0CreateGlobalMemAlloc createAlloc = (Tier0CreateGlobalMemAlloc)ResolveTier0Function("CreateGlobalMemAlloc"); - // if (!createAlloc) - // return malloc(n); - // else - // (*alloc) = createAlloc(); - //} - // - //return (*alloc)->m_vtable->Alloc(*alloc, n); -} - -void operator delete(void* p) throw() -{ - // we should be trying to use tier0's g_pMemAllocSingleton, but atm i can't get it stable - // this actually seems relatively stable though, somehow??? - free(p); - - //IMemAlloc** alloc = (IMemAlloc**)ResolveTier0Function("g_pMemAllocSingleton"); - //if (!alloc) - //{ - // Tier0CreateGlobalMemAlloc createAlloc = (Tier0CreateGlobalMemAlloc)ResolveTier0Function("CreateGlobalMemAlloc"); - // if (!createAlloc) - // { - // free(p); - // return; - // } - // else - // (*alloc) = createAlloc(); - //} - // - //(*alloc)->m_vtable->Free(*alloc, p); -} - -// honestly this all really sucks and should be reworked - -typedef void(*Tier0Error)(const char* fmt, ...); -void Error(const char* fmt, ...) -{ - Tier0Error tier0Func = (Tier0Error)ResolveTier0Function("Error"); - - // reformat args because you can't pass varargs between funcs - char buf[1024]; - - va_list args; - va_start(args, fmt); - vsnprintf(buf, sizeof(buf), fmt, args); - va_end(args); - - // tier0 isn't loaded yet - //if (tier0Func) - // tier0Func(buf); - //else - std::cout << "FATAL ERROR " << buf << std::endl; -} - -typedef double(*Tier0FloatTime)(); -double Plat_FloatTime() -{ - Tier0FloatTime tier0Func = (Tier0FloatTime)ResolveTier0Function("Plat_FloatTime"); - - if (tier0Func) - return tier0Func(); - else - return 0.0f; -} - -typedef CCommandLine*(*Tier0CommandLine)(); -CCommandLine* CommandLine() -{ - Tier0CommandLine tier0Func = (Tier0CommandLine)ResolveTier0Function("CommandLine"); - - return tier0Func(); -} \ No newline at end of file -- cgit v1.2.3