forked from gaithern/KH-1FM-AP-LUA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1fmAPKeybladeLock.lua
110 lines (101 loc) · 3.24 KB
/
1fmAPKeybladeLock.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
-----------------------------------
------ Kingdom Hearts 1 FM AP -----
------ by Gicu -----
-----------------------------------
LUAGUI_NAME = "kh1fmAP"
LUAGUI_AUTH = "KSX and Gicu"
LUAGUI_DESC = "Kingdom Hearts 1FM AP Integration"
chestslocked = true
interactinbattle = false
interactset = false
canExecute = false
settings_read = false
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_settings()
if not settings_read then
if file_exists(client_communication_path .. "chestslocked.cfg") then
chestslocked = true
settings_read = true
elseif file_exists(client_communication_path .. "chestsunlocked.cfg") then
chestslocked = false
settings_read = true
end
if file_exists(client_communication_path .. "interactinbattle.cfg") then
interactinbattle = true
end
end
end
function has_correct_keyblade()
stock_address = 0x2DEA179
world_address = 0x2340DDC
keyblade_offsets = {nil, nil, 94, 98, 86, 96, nil, 87, 90, 89, 93, 99, 88, nil, 91, 97}
current_world = ReadByte(world_address)
if keyblade_offsets[current_world] ~= nil then
keyblade_amt = ReadByte(stock_address + keyblade_offsets[current_world])
if keyblade_amt > 0 then
return true
end
end
return false
end
function get_dg_count()
dg = 0
if ReadByte(0x2DEA16F) == 1 or ReadByte(0x2DEA16F) == 2 then
dg = dg + 1
end
if ReadByte(0x2DEA170) == 1 or ReadByte(0x2DEA170) == 2 then
dg = dg + 1
end
return dg
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 canExecute then
read_settings()
chests_address = 0x2B35C4
chests = ReadByte(chests_address)
if (chestslocked and has_correct_keyblade() and chests == 0x72) or not chestslocked then
if interactinbattle then
WriteByte(chests_address, 0x73)
else
WriteByte(chests_address, 0x74)
end
elseif chestslocked and not has_correct_keyblade() and chests ~= 0x72 then
WriteByte(chests_address, 0x72)
end
if interactinbattle then
if not interactset then
Examine = 0x2926B9
Talk = 0x2926F9
WriteByte(Examine, 0x70)
WriteByte(Talk, 0x70)
interactset = true
end
Trinity = 0x1A2A6F
if get_dg_count() >= 2 then
WriteByte(Trinity, 0x71) -- Forced
else
WriteByte(Trinity, 0x75) -- Default
end
end
end
end