From b7980567be21c2f6fb97ccb93f62f1e0b3135805 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 24 Dec 2015 12:53:11 +0100 Subject: [PATCH] Better menu deallocation. --- iw4/Components/Menus.cpp | 39 ++++++++++++++++++++++++++++++--------- iw4/Components/Menus.hpp | 1 - iw4/Game/Functions.cpp | 10 ++++++++++ iw4/Game/Functions.hpp | 1 + 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/iw4/Components/Menus.cpp b/iw4/Components/Menus.cpp index 6abd5bc4..1f30d238 100644 --- a/iw4/Components/Menus.cpp +++ b/iw4/Components/Menus.cpp @@ -272,18 +272,13 @@ namespace Components return newList; } - void Menus::FreeMenuScript(Game::script_t* script) - { - Game::FreeMemory(script); - } - void Menus::FreeMenuSource(int handle) { if (!Menus::IsValidSourceHandle(handle)) return; Game::script_t *script; -// Game::token_t *token; -// Game::define_t *define; + Game::token_t *token; + Game::define_t *define; Game::indent_t *indent; Game::source_t *source = Game::sourceFiles[handle]; @@ -291,7 +286,21 @@ namespace Components { script = source->scriptstack; source->scriptstack = source->scriptstack->next; - Menus::FreeMenuScript(script); + Game::FreeMemory(script); + } + + while (source->tokens) + { + token = source->tokens; + source->tokens = source->tokens->next; + Game::FreeMemory(token); + } + + while (source->defines) + { + define = source->defines; + source->defines = source->defines->next; + Game::FreeMemory(define); } while (source->indentstack) @@ -310,7 +319,19 @@ namespace Components void Menus::FreeMenu(Game::menuDef_t* menudef) { - if (menudef->items) free(menudef->items); + // Do i need to free expressions and strings? + // Or does the game take care of it? + + if (menudef->items) + { + for (int i = 0; i < menudef->itemCount; i++) + { + Game::Menu_FreeItemMemory(menudef->items[i]); + } + + free(menudef->items); + } + free(menudef); } diff --git a/iw4/Components/Menus.hpp b/iw4/Components/Menus.hpp index 2bd50ce6..1d22072b 100644 --- a/iw4/Components/Menus.hpp +++ b/iw4/Components/Menus.hpp @@ -27,7 +27,6 @@ namespace Components static Game::menuDef_t* ParseMenu(int handle); - static void FreeMenuScript(Game::script_t* script); static void FreeMenuSource(int handle); static void FreeMenuList(Game::MenuList* menuList); diff --git a/iw4/Game/Functions.cpp b/iw4/Game/Functions.cpp index 326bc38b..6b6226f3 100644 --- a/iw4/Game/Functions.cpp +++ b/iw4/Game/Functions.cpp @@ -69,4 +69,14 @@ namespace Game g_poolSize[type] = newSize; return poolEntry; } + + void Menu_FreeItemMemory(Game::itemDef_t* item) + { + __asm + { + mov edi, item + mov eax, 63D880h + call eax + } + } } \ No newline at end of file diff --git a/iw4/Game/Functions.hpp b/iw4/Game/Functions.hpp index 02807af7..de6de0d6 100644 --- a/iw4/Game/Functions.hpp +++ b/iw4/Game/Functions.hpp @@ -113,4 +113,5 @@ namespace Game extern keywordHash_t **menuParseKeywordHash; void* ReallocateAssetPool(XAssetType type, unsigned int newSize); + void Menu_FreeItemMemory(Game::itemDef_t* item); }