aboutsummaryrefslogtreecommitdiff
path: root/LauncherInjector/memalloc.cpp
diff options
context:
space:
mode:
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;