aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LauncherInjector/memalloc.cpp25
-rw-r--r--LauncherInjector/memalloc.h15
-rw-r--r--NorthstarDedicatedTest/gameutils.h17
-rw-r--r--NorthstarDedicatedTest/memalloc.cpp24
-rw-r--r--loader_launcher_proxy/Memory.cpp24
-rw-r--r--loader_launcher_proxy/Memory.h15
6 files changed, 110 insertions, 10 deletions
diff --git a/LauncherInjector/memalloc.cpp b/LauncherInjector/memalloc.cpp
index 1d0f13e6..936523d7 100644
--- a/LauncherInjector/memalloc.cpp
+++ b/LauncherInjector/memalloc.cpp
@@ -17,6 +17,7 @@ void LoadTier0Handle()
const int STATIC_ALLOC_SIZE = 16384;
size_t g_iStaticAllocated = 0;
+void* g_pLastAllocated = nullptr;
char pStaticAllocBuf[STATIC_ALLOC_SIZE];
// they should never be used here, except in LibraryLoadError // haha not true
@@ -29,6 +30,7 @@ void* malloc(size_t n)
{
void* ret = pStaticAllocBuf + g_iStaticAllocated;
g_iStaticAllocated += n;
+ g_pLastAllocated = ret;
return ret;
}
else
@@ -53,6 +55,29 @@ void free(void* p)
(*g_ppMemAllocSingleton)->m_vtable->Free(*g_ppMemAllocSingleton, p);
}
+void* realloc(void* old_ptr, size_t size) {
+ // it was allocated into the static buffer
+ if (old_ptr >= pStaticAllocBuf && old_ptr <= pStaticAllocBuf + STATIC_ALLOC_SIZE)
+ {
+ if (g_pLastAllocated == old_ptr)
+ {
+ // nothing was allocated after this
+ size_t old_size = g_iStaticAllocated - ((size_t)g_pLastAllocated - (size_t)pStaticAllocBuf);
+ size_t diff = size - old_size;
+ if (diff > 0)
+ g_iStaticAllocated += diff;
+ return old_ptr;
+ }
+ else
+ {
+ return malloc(size);
+ }
+ }
+
+ if (g_ppMemAllocSingleton && *g_ppMemAllocSingleton)
+ return (*g_ppMemAllocSingleton)->m_vtable->Realloc(*g_ppMemAllocSingleton, old_ptr, size);
+}
+
void* operator new(size_t n)
{
return malloc(n);
diff --git a/LauncherInjector/memalloc.h b/LauncherInjector/memalloc.h
index 928e403c..c983966c 100644
--- a/LauncherInjector/memalloc.h
+++ b/LauncherInjector/memalloc.h
@@ -5,10 +5,19 @@ class IMemAlloc
public:
struct VTable
{
- void* unknown[1];
+ void* unknown[1]; // alloc debug
void* (*Alloc) (IMemAlloc* memAlloc, size_t nSize);
- void* unknown2[3];
- void(*Free) (IMemAlloc* memAlloc, void* pMem);
+ void* unknown2[1]; // realloc debug
+ void* (*Realloc)(IMemAlloc* memAlloc, void* pMem, size_t nSize);
+ void* unknown3[1]; // free #1
+ void (*Free) (IMemAlloc* memAlloc, void* pMem);
+ void* unknown4[2]; // nullsubs, maybe CrtSetDbgFlag
+ size_t(*GetSize) (IMemAlloc* memAlloc, void* pMem);
+ void* unknown5[9]; // they all do literally nothing
+ void (*DumpStats) (IMemAlloc* memAlloc);
+ void (*DumpStatsFileBase) (IMemAlloc* memAlloc, const char* pchFileBase);
+ void* unknown6[4];
+ int (*heapchk) (IMemAlloc* memAlloc);
};
VTable* m_vtable;
diff --git a/NorthstarDedicatedTest/gameutils.h b/NorthstarDedicatedTest/gameutils.h
index 8def57eb..43f387d1 100644
--- a/NorthstarDedicatedTest/gameutils.h
+++ b/NorthstarDedicatedTest/gameutils.h
@@ -7,10 +7,19 @@ class IMemAlloc
public:
struct VTable
{
- void* unknown[1];
- void* (*Alloc)(IMemAlloc* memAlloc, size_t nSize);
- void* unknown2[3];
- void (*Free)(IMemAlloc* memAlloc, void* pMem);
+ void* unknown[1]; // alloc debug
+ void* (*Alloc) (IMemAlloc* memAlloc, size_t nSize);
+ void* unknown2[1]; // realloc debug
+ void* (*Realloc)(IMemAlloc* memAlloc, void* pMem, size_t nSize);
+ void* unknown3[1]; // free #1
+ void (*Free) (IMemAlloc* memAlloc, void* pMem);
+ void* unknown4[2]; // nullsubs, maybe CrtSetDbgFlag
+ size_t(*GetSize) (IMemAlloc* memAlloc, void* pMem);
+ void* unknown5[9]; // they all do literally nothing
+ void (*DumpStats) (IMemAlloc* memAlloc);
+ void (*DumpStatsFileBase) (IMemAlloc* memAlloc, const char* pchFileBase);
+ void* unknown6[4];
+ int (*heapchk) (IMemAlloc* memAlloc);
};
VTable* m_vtable;
diff --git a/NorthstarDedicatedTest/memalloc.cpp b/NorthstarDedicatedTest/memalloc.cpp
index cff0ecac..d301f1fa 100644
--- a/NorthstarDedicatedTest/memalloc.cpp
+++ b/NorthstarDedicatedTest/memalloc.cpp
@@ -15,6 +15,7 @@
const int STATIC_ALLOC_SIZE = 100000; // alot more than we need, could reduce to 50k or even 25k later potentially
size_t g_iStaticAllocated = 0;
+void* g_pLastAllocated = nullptr;
char pStaticAllocBuf[STATIC_ALLOC_SIZE];
// TODO: rename to malloc and free after removing statically compiled .libs
@@ -53,6 +54,29 @@ void free_(void* p)
g_pMemAllocSingleton->m_vtable->Free(g_pMemAllocSingleton, p);
}
+void* realloc_(void* old_ptr, size_t size) {
+ // it was allocated into the static buffer
+ if (old_ptr >= pStaticAllocBuf && old_ptr <= pStaticAllocBuf + STATIC_ALLOC_SIZE)
+ {
+ if (g_pLastAllocated == old_ptr)
+ {
+ // nothing was allocated after this
+ size_t old_size = g_iStaticAllocated - ((size_t)g_pLastAllocated - (size_t)pStaticAllocBuf);
+ size_t diff = size - old_size;
+ if (diff > 0)
+ g_iStaticAllocated += diff;
+ return old_ptr;
+ }
+ else
+ {
+ return malloc_(size);
+ }
+ }
+
+ if (g_pMemAllocSingleton)
+ return g_pMemAllocSingleton->m_vtable->Realloc(g_pMemAllocSingleton, old_ptr, size);
+}
+
void* operator new(size_t n)
{
return malloc_(n);
diff --git a/loader_launcher_proxy/Memory.cpp b/loader_launcher_proxy/Memory.cpp
index 6c69d80f..bd19502a 100644
--- a/loader_launcher_proxy/Memory.cpp
+++ b/loader_launcher_proxy/Memory.cpp
@@ -14,6 +14,7 @@ void LoadTier0Handle()
const int STATIC_ALLOC_SIZE = 4096;
size_t g_iStaticAllocated = 0;
+void* g_pLastAllocated = nullptr;
char pStaticAllocBuf[STATIC_ALLOC_SIZE];
// they should never be used here, except in LibraryLoadError?
@@ -48,6 +49,29 @@ void free(void* p)
(*g_ppMemAllocSingleton)->m_vtable->Free(*g_ppMemAllocSingleton, p);
}
+void* realloc(void* old_ptr, size_t size) {
+ // it was allocated into the static buffer
+ if (old_ptr >= pStaticAllocBuf && old_ptr <= pStaticAllocBuf + STATIC_ALLOC_SIZE)
+ {
+ if (g_pLastAllocated == old_ptr)
+ {
+ // nothing was allocated after this
+ size_t old_size = g_iStaticAllocated - ((size_t)g_pLastAllocated - (size_t)pStaticAllocBuf);
+ size_t diff = size - old_size;
+ if (diff > 0)
+ g_iStaticAllocated += diff;
+ return old_ptr;
+ }
+ else
+ {
+ return malloc(size);
+ }
+ }
+
+ if (g_ppMemAllocSingleton && *g_ppMemAllocSingleton)
+ return (*g_ppMemAllocSingleton)->m_vtable->Realloc(*g_ppMemAllocSingleton, old_ptr, size);
+}
+
void* operator new(size_t n)
{
return malloc(n);
diff --git a/loader_launcher_proxy/Memory.h b/loader_launcher_proxy/Memory.h
index 928e403c..c983966c 100644
--- a/loader_launcher_proxy/Memory.h
+++ b/loader_launcher_proxy/Memory.h
@@ -5,10 +5,19 @@ class IMemAlloc
public:
struct VTable
{
- void* unknown[1];
+ void* unknown[1]; // alloc debug
void* (*Alloc) (IMemAlloc* memAlloc, size_t nSize);
- void* unknown2[3];
- void(*Free) (IMemAlloc* memAlloc, void* pMem);
+ void* unknown2[1]; // realloc debug
+ void* (*Realloc)(IMemAlloc* memAlloc, void* pMem, size_t nSize);
+ void* unknown3[1]; // free #1
+ void (*Free) (IMemAlloc* memAlloc, void* pMem);
+ void* unknown4[2]; // nullsubs, maybe CrtSetDbgFlag
+ size_t(*GetSize) (IMemAlloc* memAlloc, void* pMem);
+ void* unknown5[9]; // they all do literally nothing
+ void (*DumpStats) (IMemAlloc* memAlloc);
+ void (*DumpStatsFileBase) (IMemAlloc* memAlloc, const char* pchFileBase);
+ void* unknown6[4];
+ int (*heapchk) (IMemAlloc* memAlloc);
};
VTable* m_vtable;