forked from gaithern/KH-1FM-AP-LUA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1fmAPEotWDoor.lua
134 lines (118 loc) · 4.03 KB
/
1fmAPEotWDoor.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
-----------------------------------
------ Kingdom Hearts 1 FM AP -----
------ by Gicu -----
-----------------------------------
LUAGUI_NAME = "kh1fmAP"
LUAGUI_AUTH = "Gicu and Sonicshadowsilver2"
LUAGUI_DESC = "Kingdom Hearts 1FM AP Integration"
canExecute = false
required_reports_door = 14
door_goal = "reports"
frame_count = 0
if os.getenv('LOCALAPPDATA') ~= nil then
client_communication_path = os.getenv('LOCALAPPDATA') .. "\\KH1FM\\"
else
client_communication_path = os.getenv('HOME') .. "/KH1FM/"
ok, err, code = os.rename(client_communication_path, client_communication_path)
if not ok and code ~= 13 then
os.execute("mkdir " .. path)
end
end
function file_exists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
function read_required_reports()
if file_exists(client_communication_path .. "required_reports.cfg") then
file = io.open(client_communication_path .. "required_reports.cfg", "r")
io.input(file)
required_reports_door = tonumber(io.read())
io.close(file)
end
if file_exists(client_communication_path .. "required_reports_door.cfg") then
file = io.open(client_communication_path .. "required_reports_door.cfg", "r")
io.input(file)
required_reports_door = tonumber(io.read())
io.close(file)
end
end
function read_door_goal()
if file_exists(client_communication_path .. "door.cfg") then
file = io.open(client_communication_path .. "door.cfg", "r")
io.input(file)
door_goal = io.read()
io.close(file)
end
end
function all_postcards_mailed()
postcards_mailed_address = 0x2DEBBD0 - 0x231
postcards_mailed = ReadByte(postcards_mailed_address)
return postcards_mailed >= 10
end
function all_puppies_returned()
all_puppies_returned_address = 0x2DEAB25
all_puppies_returned_byte = ReadByte(all_puppies_returned_address)
return all_puppies_returned_byte > 0
end
function all_super_bosses_defeated()
sephiroth_address = 0x2DEAC4A
unknown_and_kurt_zisa_address = 0x2DEB6A1
phantom_address = 0x2DEB1ED
sephiroth_complete = ReadByte(sephiroth_address) > 0
unknown_complete = (ReadByte(unknown_and_kurt_zisa_address) % 16) >= 8
kurt_zisa_complete = (ReadByte(unknown_and_kurt_zisa_address) % 64) >= 32
phantom_complete = ReadByte(phantom_address) >= 0x96
return sephiroth_complete and unknown_complete and kurt_zisa_complete and phantom_complete
end
function read_report_qty()
inventory_address = 0x2DEA179
reports_1 = ReadArray(inventory_address + 149, 3)
reports_2 = ReadArray(inventory_address + 168, 10)
reports_acquired = 0
for k,v in pairs(reports_1) do
if v > 0 then
reports_acquired = reports_acquired + 1
end
end
for k,v in pairs(reports_2) do
if v > 0 then
reports_acquired = reports_acquired + 1
end
end
return reports_acquired
end
function write_ansem_door(ansem_door_on)
final_rest = 0x2DEBE2C
if ansem_door_on then
WriteByte(final_rest, 0)
else
WriteByte(final_rest, 1)
end
end
function main()
read_door_goal()
if door_goal == "reports" then
read_required_reports()
write_ansem_door(read_report_qty() >= required_reports_door)
elseif door_goal == "puppies" then
write_ansem_door(all_puppies_returned())
elseif door_goal == "postcards" then
write_ansem_door(all_postcards_mailed())
elseif door_goal == "superbosses" then
write_ansem_door(all_super_bosses_defeated())
end
end
function _OnInit()
if GAME_ID == 0xAF71841E and ENGINE_TYPE == "BACKEND" then
canExecute = true
ConsolePrint("KH1 detected, running script")
else
ConsolePrint("KH1 not detected, not running script")
end
end
function _OnFrame()
if frame_count == 0 and canExecute then
main()
end
frame_count = (frame_count + 1) % 30
end