From dbbeb827b2b4b29a8660cc71c13f4063f7276bac Mon Sep 17 00:00:00 2001 From: Bubb13 <36863623+Bubb13@users.noreply.github.com> Date: Fri, 21 Feb 2020 12:35:19 -0800 Subject: [PATCH] EEex_FloatToLong() shouldn't occasionally cause crash - EEex_GameObjectBeingDeleted() shouldn't throw error if object has already been deleted --- EEex/copy/EEex_Cre.lua | 10 +++-- EEex/copy/EEex_Mac.lua | 2 + EEex/copy/M__EEex.lua | 95 +++++++++++++++++++++++++++++++----------- 3 files changed, 79 insertions(+), 28 deletions(-) diff --git a/EEex/copy/EEex_Cre.lua b/EEex/copy/EEex_Cre.lua index 3ec6509..05c31c5 100644 --- a/EEex/copy/EEex_Cre.lua +++ b/EEex/copy/EEex_Cre.lua @@ -62,7 +62,7 @@ function EEex_HookLoadAreaInformation(cre, actorStruct) if areaScriptResref ~= "" then EEex_SetActorScriptInternal(cre, areaScriptResref, 1) end end -function EEex_GameObjectAdded(object) +function EEex_GameObjectAdded(objectID) local volatileStorage = EEex_Malloc(EEex_VolatileStorageSpace) @@ -74,7 +74,6 @@ function EEex_GameObjectAdded(object) end end - local objectID = EEex_ReadDword(object + 0x34) EEex_ObjectData[objectID] = { ["volatileFields"] = volatileStorage, } @@ -86,6 +85,11 @@ function EEex_GameObjectBeingDeleted(objectID) if objectID == -1 then return end local objectData = EEex_ObjectData[objectID] + -- Object was already deleted by something else, like CInfGame being destroyed. + if not objectData then + return + end + local volatileStorage = objectData["volatileFields"] for _, volatileDef in pairs(EEex_VolatileStorageDefinitions) do @@ -494,7 +498,7 @@ function EEex_InstallCreatureHooks() !call >_lua_getglobal !add_esp_byte 08 - !push_edi + !push_[ebx] !fild_[esp] !sub_esp_byte 04 !fstp_qword:[esp] diff --git a/EEex/copy/EEex_Mac.lua b/EEex/copy/EEex_Mac.lua index 5a37881..c3d9ac9 100644 --- a/EEex/copy/EEex_Mac.lua +++ b/EEex/copy/EEex_Mac.lua @@ -333,9 +333,11 @@ for _, macroEntry in ipairs({ {"push_registers", "53 51 52 56 57"}, {"push_state", "55 8B EC 53 51 52 56 57"}, {"push_[dword]", "FF 35"}, + {"push_[eax]", "FF 30"}, {"push_[ebp+byte]", "FF 75"}, {"push_[ebp+dword]", "FF B5"}, {"push_[ebp]", "FF 75 00"}, + {"push_[ebx]", "FF 33"}, {"push_[ecx+byte]", "FF 71"}, {"push_[ecx]", "FF 31"}, {"push_[edi+byte]", "FF 77"}, diff --git a/EEex/copy/M__EEex.lua b/EEex/copy/M__EEex.lua index eea5d10..91c5781 100644 --- a/EEex/copy/M__EEex.lua +++ b/EEex/copy/M__EEex.lua @@ -5032,31 +5032,75 @@ end -- SIGNATURE: -- number result = EEex_ReadDword(number address) - EEex_WriteAssemblyFunction("EEex_ReadDword", { - "55 8B EC 53 51 52 56 57 6A 00 6A 01 FF 75 08 \z - !call >_lua_tonumberx \z - 83 C4 0C \z - !call >__ftol2_sse \z - FF 30 \z - 50 \z - 68", {debugHookAddress, 4}, - "FF 75 08 \z - !call >_lua_getglobal \z - 83 C4 08 \z - DB 04 24 83 EC 04 DD 1C 24 FF 75 08 \z - !call >_lua_pushnumber \z - 83 C4 0C \z - FF 34 24 \z - DB 04 24 83 EC 04 DD 1C 24 FF 75 08 \z - !call >_lua_pushnumber \z - 83 C4 0C \z - 6A 00 6A 00 6A 00 6A 00 6A 02 FF 75 08 \z - !call >_lua_pcallk \z - 83 C4 18 \z - DB 04 24 83 EC 04 DD 1C 24 FF 75 08 \z - !call >_lua_pushnumber \z - 83 C4 0C B8 01 00 00 00 5F 5E 5A 59 5B 5D C3" - }) + EEex_WriteAssemblyFunction("EEex_ReadDword", {[[ + + !push_ebp + !mov_ebp_esp + !push_ebx + !push_ecx + !push_edx + !push_esi + !push_edi + + !push_byte 00 + !push_byte 01 + !push_[ebp+byte] 08 + !call >_lua_tonumberx + !add_esp_byte 0C + + !call >__ftol2_sse ; Put address from _lua_tonumberx in eax ; + !push_[eax] ; Store read value on stack ; + !push_eax ; Store address on stack ; + + !push_dword ]], {debugHookAddress, 4}, [[ + !push_[ebp+byte] 08 + !call >_lua_getglobal + !add_esp_byte 08 + + ; Push address ; + !fild_[esp] + !sub_esp_byte 04 + !fstp_qword:[esp] + !push_[ebp+byte] 08 + !call >_lua_pushnumber + !add_esp_byte 0C + + ; Push copy of read value ; + !push_[esp] + !fild_[esp] + !sub_esp_byte 04 + !fstp_qword:[esp] + !push_[ebp+byte] 08 + !call >_lua_pushnumber + !add_esp_byte 0C + + ; Call EEex_ReadDwordDebug ; + !push_byte 00 + !push_byte 00 + !push_byte 00 + !push_byte 00 + !push_byte 02 + !push_[ebp+byte] 08 + !call >_lua_pcallk + !add_esp_byte 18 + + ; Return read value ; + !fild_[esp] + !sub_esp_byte 04 + !fstp_qword:[esp] + !push_[ebp+byte] 08 + !call >_lua_pushnumber + !add_esp_byte 0C + + !mov_eax #1 + !pop_edi + !pop_esi + !pop_edx + !pop_ecx + !pop_ebx + !pop_ebp + !ret + ]]}) EEex_WriteAssemblyFunction("EEex_FloatToLong", {[[ @@ -5080,6 +5124,7 @@ end !call >_lua_pushnumber !add_esp_byte 0C + !mov_eax #1 !pop_state !ret