Skip to content

Commit

Permalink
Looks like *that* was deallocate all along lol
Browse files Browse the repository at this point in the history
  • Loading branch information
CelestialAmber committed Sep 26, 2024
1 parent 47e0434 commit 86ae98d
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 79 deletions.
2 changes: 1 addition & 1 deletion config/jp/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32639,7 +32639,7 @@ getRegionIndex2_2__Q23mtl10MemManagerFv = .text:0x804343A8; // type:function siz
deleteRegion__Q23mtl10MemManagerFi = .text:0x804343B0; // type:function size:0x7C scope:global align:4
func_8043442C__Q23mtl10MemManagerFiUlUl = .text:0x8043442C; // type:function size:0x24 scope:global align:4
func_80434450__Q23mtl10MemManagerFiUlUl = .text:0x80434450; // type:function size:0x88 scope:global align:4
func_804344D8__Q23mtl10MemManagerFPv = .text:0x804344D8; // type:function size:0x1C8 scope:global align:4
deallocate__Q23mtl10MemManagerFPv = .text:0x804344D8; // type:function size:0x1C8 scope:global align:4
func_804346A0__Q23mtl10MemManagerFi = .text:0x804346A0; // type:function size:0x1C scope:global align:4
func_804346BC__Q23mtl10MemManagerFi = .text:0x804346BC; // type:function size:0x48 scope:global align:4
func_80434704__Q23mtl6RegionFUlUlPUl = .text:0x80434704; // type:function size:0x6C scope:global align:4
Expand Down
49 changes: 1 addition & 48 deletions libs/monolib/include/monolib/MemManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace mtl{
static bool deleteRegion(int regionIndex);
static void* func_8043442C(int regionIndex, u32 r4, u32 r5);
static void func_80434450(int regionIndex, u32 r4, u32 r5);
static void func_804344D8(void* r3);
static void deallocate(void* r3);
static u32 func_804346A0(int regionIndex);
static void func_804346BC(int regionIndex);
static void func_80434770(int regionIndex);
Expand Down Expand Up @@ -222,53 +222,6 @@ namespace mtl{
return result;
}


static inline void deallocate(void* p){
if(p != nullptr){
if(regionIndex1 != -1){
MemBlock* entryToDelete = MemBlock::fromVoidPointer(p);
Region* region = MemManager::getRegion(entryToDelete->regionIndex);

//this doesn't seem right
if(entryToDelete->size - sizeof(MemBlock) - 1 > 0x7FFFFFF - sizeof(MemBlock) - 1){
log(true); //Since monolithsoft removed their log function, this calls the math log lol
return;
}

region->mFreeBytes += entryToDelete->size;

//Remove the entry from the linked list
if(entryToDelete->prev != nullptr){
entryToDelete->prev->next = entryToDelete->next;
}
if(entryToDelete->next != nullptr) {
entryToDelete->next->prev = entryToDelete->prev;
}

if (region->unk8 == entryToDelete) {
region->unk8 = entryToDelete->next;
}

if (region->unkC == entryToDelete) {
region->unkC = entryToDelete->prev;
}

MemBlock* entry = region->func_804339B8(entryToDelete);
entry = region->unkInline1(entry);

if (entry != nullptr) {
entry = region->unkInline1(entry);

if (entry != NULL) {
region->func_80433AA8(entry);
}
}

region->unk18--;
}
}
}

//TODO: is there a way to have this be a normal array without generating sinit stuff?
static u8 regionArray[MAX_REGIONS * sizeof(Region)];
static s32 lbl_80667E50;
Expand Down
6 changes: 3 additions & 3 deletions libs/monolib/src/CPackItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ CPackItem::CPackItem(const char* name, UNKWORD r5) : unk4(), pkbFilename() {

CPackItem::~CPackItem(){
if(mFileHandle != nullptr){
CDeviceFile::func_8044F118((CFileHandle*)mFileHandle);
CDeviceFile::func_8044F118(mFileHandle);
}

if(unk79 != 0){
mPackHeader = nullptr;
}

if(mPackHeader != nullptr){
mtl::MemManager::func_804344D8((void*)mPackHeader);
mtl::MemManager::deallocate((void*)mPackHeader);
mPackHeader = nullptr;
}

if(mAhxAdxDataPtr != nullptr){
mtl::MemManager::func_804344D8((void*)mAhxAdxDataPtr);
mtl::MemManager::deallocate((void*)mAhxAdxDataPtr);
mAhxAdxDataPtr = nullptr;
}
}
Expand Down
48 changes: 23 additions & 25 deletions libs/monolib/src/CPathUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace ml{
}

const char* CPathUtil::getFileExtensionFromPath(const char* str){
int endIndex = strlen(str) - 1;
int endIndex = std::strlen(str) - 1;

for(int i = endIndex; i >= 0; i--) {
char c = str[i];
Expand All @@ -49,32 +49,30 @@ namespace ml{
param_2 = getFilenameFromPath(param_2);

if (param_2 == nullptr) {
sVar2 = strlen(temp.string);
param_1->size = sVar2;
strcpy(param_1->string, temp.string);
param_1->length = std::strlen(temp.string);
std::strcpy(param_1->string, temp.string);
}else {
local_28 = strlen(param_2);
strcpy(temp.string, param_2);
local_28 = std::strlen(param_2);
std::strcpy(temp.string, param_2);

sVar2 = getFilenameLengthWithoutExtension(temp.string, local_28);

if (sVar2 + 1 < 2) {
sVar2 = strlen(temp.string);
param_1->size = sVar2;
strcpy(param_1->string,temp.string);
param_1->length = std::strlen(temp.string);
std::strcpy(param_1->string,temp.string);
} else {
param_1->string[0] = 0;
param_1->size = 0;
param_1->length = 0;

if (local_28 != 0) {
if (sVar2 == -1) {
sVar2 = local_28;
}

strncpy(param_1->string,temp.string,sVar2);
std::strncpy(param_1->string,temp.string,sVar2);
param_1->string[sVar2] = 0;
sVar2 = strlen(param_1->string);
param_1->size = sVar2;
sVar2 = std::strlen(param_1->string);
param_1->length = sVar2;
}
}
}
Expand All @@ -94,9 +92,9 @@ namespace ml{
char acStack_40 [16];
size_t local_30;

sVar3 = strlen("");
param_1->size = sVar3;
strcpy(param_1->string, "");
sVar3 = std::strlen("");
param_1->length = sVar3;
std::strcpy(param_1->string, "");

for (iVar6 = 0; iVar6 < param_3; iVar6++) {
iVar4 = 1;
Expand Down Expand Up @@ -130,16 +128,16 @@ namespace ml{
}

local_58[0] = (u16)(u8)((char)((param_2 % (iVar4 * 10))) + 0x30) << 8;
local_30 = strlen((char *)local_58);
strcpy(acStack_40,(char *)local_58);
local_44 = strlen(acStack_40);
strcpy(acStack_54,acStack_40);
sVar3 = strlen(param_1->string);
strcat(acStack_54,param_1->string);
local_30 = std::strlen((char *)local_58);
std::strcpy(acStack_40,(char *)local_58);
local_44 = std::strlen(acStack_40);
std::strcpy(acStack_54,acStack_40);
sVar3 = std::strlen(param_1->string);
std::strcat(acStack_54,param_1->string);
local_44 = local_44 + sVar3;
sVar3 = strlen(acStack_54);
param_1->size = sVar3;
strcpy(param_1->string,acStack_54);
sVar3 = std::strlen(acStack_54);
param_1->length = sVar3;
std::strcpy(param_1->string,acStack_54);
}
return;
}
Expand Down
47 changes: 45 additions & 2 deletions libs/monolib/src/MemManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,56 @@ namespace mtl{
return true;
}

void MemManager::func_8043442C(int regionIndex, u32 r4, u32 r5){
void* MemManager::func_8043442C(int regionIndex, u32 r4, u32 r5){
}

void MemManager::func_80434450(int regionIndex, u32 r4, u32 r5){
}

void MemManager::func_804344D8(void* r3){
void MemManager::deallocate(void* p){
if(p != nullptr){
if(regionIndex1 != -1){
MemBlock* entryToDelete = MemBlock::fromVoidPointer(p);
Region* region = MemManager::getRegion(entryToDelete->regionIndex);

//this doesn't seem right
if(entryToDelete->size - sizeof(MemBlock) - 1 > 0x7FFFFFF - sizeof(MemBlock) - 1){
log(true); //Since monolithsoft removed their log function, this calls the math log lol
return;
}

region->mFreeBytes += entryToDelete->size;

//Remove the entry from the linked list
if(entryToDelete->prev != nullptr){
entryToDelete->prev->next = entryToDelete->next;
}
if(entryToDelete->next != nullptr) {
entryToDelete->next->prev = entryToDelete->prev;
}

if (region->unk8 == entryToDelete) {
region->unk8 = entryToDelete->next;
}

if (region->unkC == entryToDelete) {
region->unkC = entryToDelete->prev;
}

MemBlock* entry = region->func_804339B8(entryToDelete);
entry = region->unkInline1(entry);

if (entry != nullptr) {
entry = region->unkInline1(entry);

if (entry != NULL) {
region->func_80433AA8(entry);
}
}

region->unk18--;
}
}
}

u32 MemManager::func_804346A0(int regionIndex){
Expand Down

0 comments on commit 86ae98d

Please sign in to comment.