Skip to content

Commit

Permalink
New gameplay behaviors are now disabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubb13 committed Jan 19, 2019
1 parent 4c83533 commit 6aa29e2
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 13 deletions.
11 changes: 11 additions & 0 deletions EEex/copy/B3_Books.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

function B3Books_InstallBookChanges()

EEex_DisableCodeProtection()

EEex_WriteAssembly(0x6870F6, {"!jmp_byte"}) -- force bookMode to true
EEex_WriteAssembly(0x709287, {"!jmp_byte"}) -- force hasMageBook to true

EEex_EnableCodeProtection()
end
B3Books_InstallBookChanges()
107 changes: 107 additions & 0 deletions EEex/copy/B3_Hotke.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@

B3Hotkey_PrintKeys = false
function B3Hotkey_TogglePrintKeys()
if not B3Hotkey_PrintKeys then
B3Hotkey_PrintKeys = true
Infinity_DisplayString("[EEex] Enabled Key-Pressed Output")
else
B3Hotkey_PrintKeys = false
Infinity_DisplayString("[EEex] Disabled Key-Pressed Output")
end
end

B3Hotkey_Hotkeys = {
{B3Hotkey_TogglePrintKeys, 3, 0x60}, -- Key-Pressed Output Toggle
--{"SPWI112", 3, 0x61, 0x73, 0x64}, -- Example keybinding...
}

function B3Hotkey_AttemptToCastViaHotkey(resref)
local actorID = EEex_GetActorIDSelected()
if actorID ~= 0x0 then
local useCGameButtonList = function(m_CGameSprite, m_CGameButtonList)
local found = false
EEex_IterateCPtrList(m_CGameButtonList, function(m_CButtonData)
-- m_CButtonData.m_abilityId.m_res
local m_res = EEex_ReadLString(m_CButtonData + 0x1C + 0x6, 0x8)
if m_res == resref then
-- Unlike most other functions, CGameSprite::ReadySpell() expects the CButtonData
-- arg to be passed by VALUE, not by reference. EEex's call() function isn't designed
-- to do that, so the hacky hilarity that follows is required...
local stackArgs = {}
table.insert(stackArgs, 0x0)
for i = 0x30, 0x0, -0x4 do
table.insert(stackArgs, EEex_ReadDword(m_CButtonData + i))
end
EEex_Call(EEex_Label("CGameSprite::ReadySpell"), stackArgs, m_CGameSprite, 0x0)
found = true
return true -- breaks out of EEex_IterateCPtrList()
end
end)
EEex_FreeCPtrList(m_CGameButtonList)
return found
end
local m_CGameSprite = EEex_GetActorShare(actorID)
local spellButtonDataList = EEex_Call(EEex_Label("CGameSprite::GetQuickButtons"), {0, 2}, m_CGameSprite, 0x0)
if useCGameButtonList(m_CGameSprite, spellButtonDataList) then return end
local innateButtonDataList = EEex_Call(EEex_Label("CGameSprite::GetQuickButtons"), {0, 4}, m_CGameSprite, 0x0)
useCGameButtonList(m_CGameSprite, innateButtonDataList)
end
end

B3Hotkey_LastSuccessfulHotkey = nil

function B3Hotkey_KeyPressedListener(key)
if worldScreen == e:GetActiveEngine() then
if B3Hotkey_PrintKeys then
Infinity_DisplayString("[EEex] Pressed: "..EEex_ToHex(key))
end
local completedMatch = false
for _, hotkeyDef in ipairs(B3Hotkey_Hotkeys) do
local stage = hotkeyDef[2]
if stage ~= 0 then
if hotkeyDef[stage] == key then
if stage ~= #hotkeyDef then
hotkeyDef[2] = stage + 1 -- Advance
else
-- Success
hotkeyDef[2] = 0 -- Stop Processing
B3Hotkey_LastSuccessfulHotkey = hotkeyDef
completedMatch = true
end

else
-- Fail
hotkeyDef[2] = 0 -- Stop Processing
end
end
end
if not completedMatch then
B3Hotkey_LastSuccessfulHotkey = nil
end
end
end
EEex_AddKeyPressedListener(B3Hotkey_KeyPressedListener)

function B3Hotkey_KeyReleasedListener(key)
if B3Hotkey_LastSuccessfulHotkey ~= nil then
local hotkeyValue = B3Hotkey_LastSuccessfulHotkey[1]
local hotkeyValueType = type(hotkeyValue)
if hotkeyValueType == "string" then
B3Hotkey_AttemptToCastViaHotkey(hotkeyValue)
elseif hotkeyValueType == "function" then
hotkeyValue()
end
end
B3Hotkey_LastSuccessfulHotkey = nil
for _, hotkeyDef in ipairs(B3Hotkey_Hotkeys) do
hotkeyDef[2] = 3
end
end
EEex_AddKeyReleasedListener(B3Hotkey_KeyReleasedListener)

function B3Hotkey_ResetListener()
EEex_AddKeyPressedListener(B3Hotkey_KeyPressedListener)
EEex_AddKeyReleasedListener(B3Hotkey_KeyReleasedListener)
EEex_AddResetListener(B3Hotkey_ResetListener)
end
EEex_AddResetListener(B3Hotkey_ResetListener)
94 changes: 94 additions & 0 deletions EEex/copy/B3_Invis.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

B3Invis_RenderAsInvisible = false

function B3Invis_InstallOpcode193Changes()

EEex_DisableCodeProtection()

local canSeeInvisAddress = EEex_WriteAssemblyAuto({[[
!build_stack_frame
!sub_esp_byte 04
!push_registers
!mov_eax_[dword] *g_pBaldurChitin
!mov_eax_[eax+dword] #D14
!mov_esi_[eax+dword] #3E54
!test_esi_esi
!je_dword >fail
!xor_ebx_ebx
@loop
!lea_ecx_[ebp+byte] FC
!push_ecx
!push_[esi+byte] 08
!call >CGameObjectArray::GetShare
!mov_ecx_[ebp+byte] FC
!cmp_[ecx+dword]_byte #C08 00
!jne_dword >found
!mov_esi_[esi]
!test_esi_esi
!jne_dword >loop
@fail
!mov_ebx #01
@found
!mov_eax_ebx
!restore_stack_frame
!ret
]]})

local invisCheckHook1 = EEex_WriteAssemblyAuto({[[
!push_complete_state
!cmp_[esi+dword]_byte #2D07 00
!je_dword >ret
!call ]], {canSeeInvisAddress, 4, 4}, [[
!cmp_eax_byte 00
@ret
!pop_complete_state
!ret
]]})

local invisCheckHook2 = EEex_WriteAssemblyAuto({[[
!push_complete_state
!cmp_[ebx+dword]_byte #2D07 00
!je_dword >ret
!call ]], {canSeeInvisAddress, 4, 4}, [[
!cmp_eax_byte 00
@ret
!pop_complete_state
!ret
]]})

local forceCircleHook = EEex_WriteAssemblyAuto({[[
!push_complete_state
!cmp_[eax+dword]_byte #9B 00
!jne_dword >ret
!cmp_[ebx+dword]_byte #2D07 00
!je_dword >ret
!call ]], {canSeeInvisAddress, 4, 4}, [[
!cmp_eax_byte 01
@ret
!pop_complete_state
!ret
]]})

EEex_WriteAssembly(0x6EE5F1, {"!call", {invisCheckHook1, 4, 4}, "!nop !nop"})
EEex_WriteAssembly(0x6FC1C2, {"!call", {invisCheckHook2, 4, 4}, "!nop !nop"})
EEex_WriteAssembly(0x6FC237, {"!call", {forceCircleHook, 4, 4}, "!nop !nop"})

if B3Invis_RenderAsInvisible then

local invisCheckHook3 = EEex_WriteAssemblyAuto({[[
!push_complete_state
!cmp_[ebx+dword]_byte #2D07 00
!je_dword >ret
!call ]], {canSeeInvisAddress, 4, 4}, [[
!cmp_eax_byte 01
@ret
!pop_complete_state
!ret
]]})

EEex_WriteAssembly(0x6F9170, {"!call", {invisCheckHook2, 4, 4}, "!nop !nop"})
EEex_WriteAssembly(0x6F9970, {"!call", {invisCheckHook3, 4, 4}, "!nop !nop"})
end
EEex_EnableCodeProtection()
end
B3Invis_InstallOpcode193Changes()
7 changes: 4 additions & 3 deletions EEex/copy/EEex_AHo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ function EEex_SetActionPointY(actionData, newY)
end

function EEex_HookAction(actionData)
for _, func in ipairs(EEex_HookActionFunctions) do
func(actionData)
end
local hooksCopy = EEex_HookActionFunctions
EEex_HookActionFunctions = {}
for _, hook in ipairs(hooksCopy) do
hook(actionData)
end
end

function EEex_InstallActionHook()
Expand Down
6 changes: 6 additions & 0 deletions EEex/copy/EEex_INI.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

EEex_Modules = {
["B3_Books"] = false,
["B3_Hotke"] = false,
["B3_Invis"] = false,
}
14 changes: 14 additions & 0 deletions EEex/copy/EEex_Mac.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ for _, macroEntry in ipairs({
{"cmove_eax_ebx", "0F 44 C3"},
{"cmovne_eax_ebx", "0F 45 C3"},
{"cmovne_eax_edi", "0F 45 C7"},
{"cmp_[eax+dword]_byte", "80 B8"},
{"cmp_[ebp+byte]_byte", "83 7D"},
{"cmp_[ebp+byte]_ebx", "39 5D"},
{"cmp_[ebx+dword]_byte", "80 BB"},
{"cmp_[ecx+byte]_byte", "83 79"},
{"cmp_[ecx+byte]_esi", "39 71"},
{"cmp_[ecx+dword]_byte", "80 B9"},
{"cmp_[esi+dword]_byte", "80 BE"},
{"cmp_eax_byte", "83 F8"},
{"cmp_eax_dword", "3D"},
{"cmp_eax_ebx", "3B C3"},
Expand Down Expand Up @@ -114,7 +118,9 @@ for _, macroEntry in ipairs({
{"mov_eax_[esi+byte]", "8B 46"},
{"mov_eax_[esi+dword]", "8B 86"},
{"mov_eax_[esi]", "8B 46 00"},
{"mov_eax_ebx", "8B C3"},
{"mov_eax_edx", "8B C2"},
{"mov_ebx", "BB"},
{"mov_ebx_eax", "8B D8"},
{"mov_ebx_esp", "8B DC"},
{"mov_ecx_[ebp+byte]", "8B 4D"},
Expand All @@ -128,6 +134,7 @@ for _, macroEntry in ipairs({
{"mov_edi_eax", "8B F8"},
{"mov_edi_esp", "8B FC"},
{"mov_edx", "BA"},
{"mov_edx_[eax+dword]", "8B 90"},
{"mov_edx_[ebx+byte]", "8B 53"},
{"mov_edx_[ebx+dword]", "8B 93"},
{"mov_edx_[ebx]", "8B 53 00"},
Expand All @@ -139,6 +146,8 @@ for _, macroEntry in ipairs({
{"mov_edx_[edx]", "8B 52 00"},
{"mov_edx_eax", "8B D0"},
{"mov_esi", "BE"},
{"mov_esi_[eax+dword]", "8B B0"},
{"mov_esi_[esi]", "8B 36"},
{"mov_esi_eax", "8B F0"},
{"mov_esp_[ebp+byte]", "8B 65"},
{"mov_esp_[ebp+dword]", "8B A5"},
Expand All @@ -147,12 +156,15 @@ for _, macroEntry in ipairs({
{"nop", "90"},
{"pop_eax", "58"},
{"pop_ecx", "59"},
{"pop_complete_state", "5F 5E 5A 59 5B 58 5D"},
{"pop_state", "5F 5E 5A 59 5B 5D"},
{"push_[dword]", "FF 35"},
{"push_[ebp+byte]", "FF 75"},
{"push_[ebp+dword]", "FF B5"},
{"push_[ebp]", "FF 75 00"},
{"push_[edi+byte]", "FF 77"},
{"push_[edx+byte]", "FF 72"},
{"push_[esi+byte]", "FF 76"},
{"push_byte", "6A"},
{"push_dword", "68"},
{"push_eax", "50"},
Expand All @@ -161,6 +173,7 @@ for _, macroEntry in ipairs({
{"push_edx", "52"},
{"push_esi", "56"},
{"push_registers", "53 51 52 56 57"},
{"push_complete_state", "55 8B EC 50 53 51 52 56 57"},
{"push_state", "55 8B EC 53 51 52 56 57"},
{"restore_stack_frame", "5F 5E 5A 59 5B 8B E5 5D"},
{"ret", "C3"},
Expand All @@ -178,6 +191,7 @@ for _, macroEntry in ipairs({
{"test_eax_eax", "85 C0"},
{"test_edi_edi", "85 FF"},
{"test_edx_edx", "85 D2"},
{"test_esi_esi", "85 F6"},
{"xor_eax_eax", "33 C0"},
{"xor_ebx_ebx", "33 DB"},
--[[
Expand Down
17 changes: 9 additions & 8 deletions EEex/copy/EEex_Opc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ function EEex_InstallOpcodeChanges()
EEex_WriteAssembly(0x5903AA, {"!nop !nop"})
EEex_WriteAssembly(0x5903DC, {"!nop !nop !nop !nop !nop !nop"})

EEex_WriteAssembly(0x6870F6, {"!jmp_byte"}) -- force bookMode to true
EEex_WriteAssembly(0x709287, {"!jmp_byte"}) -- force hasMageBook to true
-- Set strref of opcode #324 to Special
EEex_WriteAssembly(0x57F805, {"8B 7E 44 90 90"})

-- 0x617DBA - Render's spell icon

EEex_WriteAssembly(0x57F805, {"8B 7E 44 90 90"}) -- Set strref of opcode #324 to Special
--EEex_WriteAssembly(0x52CBE8, {"!nop !nop !nop"}) -- Remove Opcode #262 hard limit
--EEex_WriteAssembly(0x60C7B3, {"90 90 90"}) -- Remove Opcode #262 hard limit
--EEex_WriteAssembly(0x60C7B9, {"90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90"}) -- Remove Opcode #262 hard limit
-- (Opcode #262) Not ready yet...
--[[
EEex_WriteAssembly(0x52CBE8, {"!nop !nop !nop"})
EEex_WriteAssembly(0x60C7B3, {"90 90 90"})
EEex_WriteAssembly(0x60C7B9, {"90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90"})
--]]

EEex_EnableCodeProtection()

end
EEex_InstallOpcodeChanges()
Loading

0 comments on commit 6aa29e2

Please sign in to comment.