From bb2132a78f3250835eea47f91addf5adcc2de215 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sat, 14 Nov 2015 08:57:37 -0800 Subject: [PATCH] save scene & pos feature; serialize stored values --- Lua/addrs/M/common.lua | 1 + Lua/cheat menu.lua | 57 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Lua/addrs/M/common.lua b/Lua/addrs/M/common.lua index 136a00b..7695d5f 100755 --- a/Lua/addrs/M/common.lua +++ b/Lua/addrs/M/common.lua @@ -377,6 +377,7 @@ return { warp_begin = AG(0x18875, 1), screen_dim = AG(0x18877, 1), warp_destination = AG(0x1887A, 2), + fade_type = AG(0x1887F, 1), entrance_entered = AG(0x18B48, 1), link_actor = setmetatable({ diff --git a/Lua/cheat menu.lua b/Lua/cheat menu.lua index 6e849f3..be760a7 100755 --- a/Lua/cheat menu.lua +++ b/Lua/cheat menu.lua @@ -10,6 +10,12 @@ require "flag manager" dummy = Callbacks() +local fn = 'cheat menu.save.lua' +local saved = deserialize('cheat menu.save.lua') or {} +local function save() + serialize(fn, saved) +end + function Setter(t) local cb = Callbacks() function cb:on() @@ -75,23 +81,27 @@ local soft_reset = Callbacks() function soft_reset:on() addrs.warp_begin(0x14) addrs.warp_destination(0x1C00) - AL(0x3F48, 2)(0xFFFA) -- doesn't quite work + --AL(0x3F48, 2)(0xFFFA) -- doesn't really do anything? end -local pos = {} local save_pos = Callbacks() function save_pos:on() local la = addrs.link_actor + saved.pos = {} + local pos = saved.pos pos.x = la.x() pos.y = la.y() pos.z = la.z() pos.a = la.angle() -- also save ISG for glitch testers ;) pos.isg = la.sword_active() + save() end local load_pos = Callbacks() function load_pos:on() local la = addrs.link_actor + local pos = saved.pos + if pos == nil then return end la.x(pos.x) la.y(pos.y) la.z(pos.z) @@ -110,16 +120,47 @@ function reload_scene:on() addrs.warp_destination(ev) end -local saved_scene = nil local save_scene = Callbacks() function save_scene:on() - saved_scene = addrs.exit_value() + saved.scene = addrs.exit_value() + save() end local load_scene = Callbacks() function load_scene:on() - if saved_scene == nil then return end + if saved.scene == nil then return end addrs.warp_begin(0x14) - addrs.warp_destination(saved_scene) + addrs.warp_destination(saved.scene) +end + +local save_scene_pos = Callbacks() +function save_scene_pos:on() + saved.scenepos = {} + local sp = saved.scenepos + sp.scene = addrs.exit_value() + local la = addrs.link_actor + sp.x = la.x() + sp.y = la.y() + sp.z = la.z() + sp.a = la.angle() + --sp.room = la.room_number() + save() +end +local load_scene_pos = Callbacks() +function load_scene_pos:on() + local sp = saved.scenepos + if sp == nil then return end + addrs.warp_begin(0x14) + addrs.warp_destination(sp.scene) + addrs.fade_type(0x0B) -- this transition is basically instantaneous + -- TODO: add these to address list + -- probably the same struct for both MM and OoT + AL(0x3CB0, 4)(-4) -- void out type: reload area + AL(0x3CB4, 'f')(sp.x) + AL(0x3CB8, 'f')(sp.y) + AL(0x3CBC, 'f')(sp.z) + AL(0x3CC0, 2)(sp.a) + AL(0x3CC2, 2)(0x0BFF) -- puts camera behind link instead of at entrance + --AL(0x3CC6, 2)(sp.room) end local time_menu = Menu{ @@ -183,7 +224,9 @@ local main_menu = Menu{ Oneshot("Reload Scene", reload_scene), Oneshot("Store Scene", save_scene), Oneshot("Restore Scene", load_scene), - -- TODO: can probably save/load position+scene using void out mechanics + Text(""), + Oneshot("Store Scene & Position", save_scene_pos), + Oneshot("Restore Scene & Position", load_scene_pos), Text(""), Oneshot("Soft Reset (Warp to Title)", soft_reset), Text(""),