Skip to content

Commit

Permalink
Adds keyblade locking lua to seed gen
Browse files Browse the repository at this point in the history
  • Loading branch information
zaktherobot committed Mar 27, 2024
1 parent 3f523b5 commit 35b4422
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Module/seedmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,22 @@ def write_battle_level_assets(self, modified_battle_level_binary: bytearray):

self.out_zip.writestr(source_name, modified_battle_level_binary)

def write_keyblade_locking_lua(self):
keyblade_lua_name = _relative_mod_file("keyblade_locking/keyblade.lua")
assets = [
{
"name": "scripts/keyblade.lua",
"method": "copy",
"source": [{"name": keyblade_lua_name}],
},
]
self.mod_yml.add_assets(assets)

self.out_zip.write(
resource_path("static/keyblade_locking/keyblade.lua"), keyblade_lua_name
)


def write_better_stt_assets(self, boss_enabled: bool):
"""Adds assets and files to the mod for 'Better STT'."""
trinity_bar_source_name = _relative_mod_file("better_stt/trinity_zz.bar")
Expand Down
3 changes: 3 additions & 0 deletions Module/zipper.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ def create_zip(self) -> SeedZipResult:
"Disabled",
]
mod.write_better_stt_assets(boss_enabled)

if settings.keyblades_unlock_chests:
mod.write_keyblade_locking_lua()

self.add_cmd_list_modifications(mod)

Expand Down
136 changes: 136 additions & 0 deletions static/keyblade_locking/keyblade.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
function _OnInit()
if (GAME_ID == 0xF266B00B or GAME_ID == 0xFAF99301) and ENGINE_TYPE == "ENGINE" then --PCSX2
if ENGINE_VERSION < 3.0 then
print('LuaEngine is Outdated. Things might not work properly.')
end
OnPC = false
Now = 0x032BAE0 --Current Location
Save = 0x032BB30 --Save File
Sys3Pointer = 0x1C61AF8 --03system.bin Pointer Address
elseif GAME_ID == 0x431219CC and ENGINE_TYPE == 'BACKEND' then --PC
if ENGINE_VERSION < 5.0 then
ConsolePrint('LuaBackend is Outdated. Things might not work properly.',2)
end
OnPC = true
Now = 0x0714DB8 - 0x56454E
Save = 0x09A7070 - 0x56450E
Sys3Pointer = 0x2AE3550 - 0x56454E
end
end

--table key is world id. table value is keyblade ID, keyblade save file inventory address
keyTable = {
[0] = {-1, -1},
[1] = {0x1F2, 0x368D}, --STT | Bond of Flame
[2] = {0x02A, 0x35A2}, --TT | Oathkeeper
[3] = {0x220, 0x3699}, --CoR | Winner's Proof
[4] = {0x1EE, 0x3689}, --HB | Sleeping Lion
[5] = {0x1EA, 0x3685}, --BC | Rumbling Rose
[6] = {0x1E4, 0x367F}, --OC | Hero's Crest
[7] = {0x1EC, 0x3687}, --AG | Wishing Lamp
[8] = {0x1E1, 0x367C}, --LoD | Hidden Dragon
[9] = {0x1EF, 0x368A}, --HAW | Sweet Memeories
[10] = {0x1E7, 0x3682}, --PL | Circle of Life
[11] = {-1, -1},
[12] = {0x1E5, 0x3680}, --DC | Monochrome
[13] = {0x1E5, 0x3680}, --TR | Monochrome
[14] = {0x1ED, 0x3688}, --HT | Decisive Pumpkin
[15] = {-1, -1},
[16] = {0x1E6, 0x3681}, --PR | Follow The Wind
[17] = {0x1E8, 0x3683}, --SP | Photon Debugger
[18] = {0x21F, 0x3698} --TWTNW | Two Become One
}

function CheckKeyblade(invAdd, keyValue)
--invAdd = keyblade inventory address in savefile to use
--keyValue = keyblade item ID
local Key = ReadShort(Save + 0x24F0)
local Valor = ReadShort(Save + 0x32F4)
local Master = ReadShort(Save + 0x339C)
local Final = ReadShort(Save + 0x33D4)
local SaveKey = ReadByte(Save + invAdd)

if (SaveKey > 0 or Key == keyValue or Valor == keyValue or Master == keyValue or Final == keyValue) then
return true
end

return false
end

function BAR(File,Subfile,Offset) --Get address within a BAR file
local Subpoint = File + 0x08 + 0x10*Subfile
local Address
--Detect errors
if ReadInt(File,OnPC) ~= 0x01524142 then --Header mismatch
return
elseif Subfile > ReadInt(File+4,OnPC) then --Subfile over count
return
elseif Offset >= ReadInt(Subpoint+4,OnPC) then --Offset exceed subfile length
return
end
--Get address
Address = File + (ReadInt(Subpoint,OnPC) - ReadInt(File+8,OnPC)) + Offset
return Address
end

function _OnFrame()
if true then --Define current values for common addresses
World = ReadByte(Now+0x00)
Room = ReadByte(Now+0x01)
Place = ReadShort(Now+0x00)
if Place == 0xFFFF or not MSN then
if not OnPC then
Sys3 = ReadInt(Sys3Pointer)
MSN = 0x04FA440
else
Sys3 = ReadLong(Sys3Pointer)
MSN = 0x0BF08C0 - 0x56450E
end
end
end
CanUnlock()
end

function CanUnlock()
--return if not a valid world
if (World <= 1 or World >= 19) then
return
end

--STT Tutorial Chest/GoA Chests (Always unlocked)
if Place == 0x2002 or Place == 0x1A04 then
WriteShort(BAR(Sys3,0x2,0x04BA),0x20,OnPC)
return
end

--get world value and set here to modify later if needed (STT/COR)
local curWorld = World

--STT Check
if World == 0x2 and ReadByte(Save+0x1CFF) == 13 then --STT/TT
curWorld = curWorld -1
end

--CoR Check
if World == 0x4 and Room >= 0x15 and Room <= 0x18 then
curWorld = curWorld -1
end

--get key values
local worldKeyInv = keyTable[curWorld][1]
local worldKeySav = keyTable[curWorld][2]

--return if somehow not a valid key
if worldKeyInv == -1 or worldKeySav == -1 then
return
end

--get and set unlock status
local Unlock = CheckKeyblade(worldKeySav, worldKeyInv)

if Unlock then
WriteShort(BAR(Sys3,0x2,0x04BA),0x20,OnPC)
else
WriteShort(BAR(Sys3,0x2,0x04BA),0x00,OnPC)
end
end

0 comments on commit 35b4422

Please sign in to comment.