aboutsummaryrefslogtreecommitdiff
path: root/LauncherInjector/memalloc.cpp
diff options
context:
space:
mode:
authorp0358 <p0358@users.noreply.github.com>2021-12-30 02:58:19 +0100
committerp0358 <p0358@users.noreply.github.com>2021-12-30 02:58:19 +0100
commitd2ee389192aa425ef9c81b2c3367ffb0de6976d0 (patch)
treef244033f6d85055ca272f8369942969848d053f5 /LauncherInjector/memalloc.cpp
parentc18b293ba739424bee6db39e2e5a3081b0010a13 (diff)
downloadNorthstarLauncher-d2ee389192aa425ef9c81b2c3367ffb0de6976d0.tar.gz
NorthstarLauncher-d2ee389192aa425ef9c81b2c3367ffb0de6976d0.zip
Refactor and fix of various issues, add run_northstar.txt support
Diffstat (limited to 'LauncherInjector/memalloc.cpp')
-rw-r--r--LauncherInjector/memalloc.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/LauncherInjector/memalloc.cpp b/LauncherInjector/memalloc.cpp
index 64bc7b76..1d0f13e6 100644
--- a/LauncherInjector/memalloc.cpp
+++ b/LauncherInjector/memalloc.cpp
@@ -1,13 +1,14 @@
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include "memalloc.h"
+#include <stdio.h>
-HMODULE hTier0Module;
+extern HMODULE hTier0Module;
IMemAlloc** g_ppMemAllocSingleton;
void LoadTier0Handle()
{
- hTier0Module = GetModuleHandleA("tier0.dll");
+ if (!hTier0Module) hTier0Module = GetModuleHandleA("tier0.dll");
if (!hTier0Module) return;
g_ppMemAllocSingleton = (IMemAlloc**)GetProcAddress(hTier0Module, "g_pMemAllocSingleton");
@@ -18,10 +19,11 @@ const int STATIC_ALLOC_SIZE = 16384;
size_t g_iStaticAllocated = 0;
char pStaticAllocBuf[STATIC_ALLOC_SIZE];
-// they should never be used here, except in LibraryLoadError
+// they should never be used here, except in LibraryLoadError // haha not true
void* malloc(size_t n)
{
+ //printf("NorthstarLauncher malloc: %llu\n", n);
// allocate into static buffer
if (g_iStaticAllocated + n <= STATIC_ALLOC_SIZE)
{
@@ -32,7 +34,7 @@ void* malloc(size_t n)
else
{
// try to fallback to g_pMemAllocSingleton
- if (!hTier0Module) LoadTier0Handle();
+ if (!hTier0Module || !g_ppMemAllocSingleton) LoadTier0Handle();
if (g_ppMemAllocSingleton && *g_ppMemAllocSingleton)
return (*g_ppMemAllocSingleton)->m_vtable->Alloc(*g_ppMemAllocSingleton, n);
else
@@ -42,6 +44,7 @@ void* malloc(size_t n)
void free(void* p)
{
+ //printf("NorthstarLauncher free: %p\n", p);
// if it was allocated into the static buffer, just do nothing, safest way to deal with it
if (p >= pStaticAllocBuf && p <= pStaticAllocBuf + STATIC_ALLOC_SIZE)
return;