Skip to content

Commit

Permalink
EEex_FloatToLong() shouldn't occasionally cause crash
Browse files Browse the repository at this point in the history
- EEex_GameObjectBeingDeleted() shouldn't throw error if object has already been deleted
  • Loading branch information
Bubb13 committed Feb 21, 2020
1 parent 5813d89 commit dbbeb82
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 28 deletions.
10 changes: 7 additions & 3 deletions EEex/copy/EEex_Cre.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -74,7 +74,6 @@ function EEex_GameObjectAdded(object)
end
end

local objectID = EEex_ReadDword(object + 0x34)
EEex_ObjectData[objectID] = {
["volatileFields"] = volatileStorage,
}
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions EEex/copy/EEex_Mac.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
95 changes: 70 additions & 25 deletions EEex/copy/M__EEex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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", {[[
Expand All @@ -5080,6 +5124,7 @@ end
!call >_lua_pushnumber
!add_esp_byte 0C
!mov_eax #1
!pop_state
!ret
Expand Down

0 comments on commit dbbeb82

Please sign in to comment.