forked from gaithern/KH-1FM-AP-LUA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1fmAPSaveAnywhere.lua
137 lines (121 loc) · 4.16 KB
/
1fmAPSaveAnywhere.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
LUAGUI_NAME = "1fmAPSaveAnywhere"
LUAGUI_AUTH = "denhonator with slight edits from Gicu"
LUAGUI_DESC = "Read readme for button combinations. Modified for AP by Gicu"
local extraSafety = false
local offset = 0x3A0606
local addgummi = 0
local lastInput = 0
local prevHUD = 0
local revertCode = false
local removeWhite = 0
local lastDeathPointer = 0
local soraHUD = 0x280EB1C - offset
local soraHP = 0x2D592CC - offset
local stateFlag = 0x2863958 - offset
local deathCheck = 0x2978E0 - offset
local safetyMeasure = 0x297746 - offset
local whiteFade = 0x233C49C - offset
local blackFade = 0x4D93B8 - offset
local closeMenu = 0x2E90820 - offset
local deathPointer = 0x23944B8 - offset
local closeMenu = 0x2E90820 - offset
local warpTrigger = 0x22E86DC - offset
local warpType1 = 0x233C240 - offset
local warpType2 = 0x22E86E0 - offset
local title = 0x233CAB8 - offset
local continue = 0x2DFC5D0 - offset
local config = 0x2DFBDD0 - offset
local cam = 0x503A18 - offset
local state = 0x2863958 - offset
local canExecute = false
local lastsavemenuopen = 0
function _OnInit()
if GAME_ID == 0xAF71841E and ENGINE_TYPE == "BACKEND" then
if ReadShort(deathCheck) == 0x2E74 then
ConsolePrint("Global version detected")
elseif ReadShort(deathCheck-0x1C0) == 0x2E74 then
deathCheck = deathCheck-0x1C0
safetyMeasure = safetyMeasure-0x1C0
extraSafety = false
ConsolePrint("JP detected")
end
canExecute = true
else
ConsolePrint("KH1 not detected, not running script")
end
lastDeathPointer = ReadLong(deathPointer)
end
function InstantContinue()
if ReadByte(warpTrigger) == 0 then
ConsolePrint("Instant continue trigger")
WriteByte(warpType1, 5)
WriteByte(warpType2, 12)
WriteByte(warpTrigger, 2)
end
end
function SoftReset()
ConsolePrint("Soft reset")
WriteByte(warpType1, 3)
WriteByte(warpType2, 1)
if ReadByte(title) == 0 then
WriteByte(title, 1)
end
WriteByte(warpTrigger, 2)
end
function _OnFrame()
if not canExecute then
goto done
end
local input = ReadInt(0x233D034-offset)
local savemenuopen = ReadByte(0x232A604-offset)
if ReadByte(state) ~= 0x01 then
if input == 1793 and lastInput ~= 1793 and savemenuopen~=4 and ReadByte(0x2350CD4-offset) == 0 then
WriteByte(0x2350CD4-offset, 0x1)
addgummi = 5
elseif input == 1793 and lastInput ~= 1793 then
WriteLong(closeMenu, 0)
end
if input == 3968 and lastInput ~= 3968 and ReadLong(closeMenu) == 0 then
InstantContinue()
end
if input == 3872 and lastInput ~= 3872 and ReadLong(closeMenu) == 0 then
local f = io.open("autosave.dat", "rb")
if f ~= nil then
WriteString(continue, f:read("*a"))
f:close()
ConsolePrint("Loaded autosave")
WriteByte(closeMenu, 1)
InstantContinue()
WriteFloat(cam, -1.0 + ReadByte(config+0x14)*2)
WriteFloat(cam+4, 1.0 - ReadByte(config+0x18)*2)
end
end
if input == 3848 and lastInput ~= 3848 then
SoftReset()
end
end
if savemenuopen == 4 and lastsavemenuopen ~= 4 then
addgummi = 5
end
if savemenuopen == 4 and addgummi==1 then
WriteByte(0x2E1CC28-offset, 3) --Unlock gummi
WriteByte(0x2E1CB9C-offset, 5) --Set 5 buttons to save menu
WriteByte(0x2E8F450-offset, 5) --Set 5 buttons to save menu
WriteByte(0x2E8F452-offset, 5) --Set 5 buttons to save menu
for i=0,4 do
WriteByte(0x2E1CBA0+i*4-offset, i) --Set button types
end
end
addgummi = addgummi > 0 and addgummi-1 or addgummi
lastInput = input
lastsavemenuopen = savemenuopen
lastDeathPointer = ReadLong(deathPointer)
if ReadFloat(soraHUD) == 1 and prevHUD < 1 then
local f = io.open("autosave.dat", "wb")
f:write(ReadString(continue, 0x16C00))
f:close()
--ConsolePrint("Wrote autosave")
end
prevHUD = ReadFloat(soraHUD)
::done::
end