forked from gaithern/KH-1FM-AP-LUA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1fmAPKeybladeLock.lua
121 lines (111 loc) · 4.1 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
111
112
113
114
115
116
117
118
119
120
121
-----------------------------------
------ Kingdom Hearts 1 FM AP -----
------ by Gicu -----
-----------------------------------
LUAGUI_NAME = "1fmAPKeybladeLock"
LUAGUI_AUTH = "KSX and Gicu"
LUAGUI_DESC = "Kingdom Hearts 1FM AP Integration"
game_version = 1 --1 for EGS 1.0.0.10, 2 for Steam 1.0.0.10
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 = {0x2DEA1F9, 0x2DE97F9} --changed for EGS 1.0.0.10
world_address = {0x2340E5C, 0x233FE84}
keyblade_offsets = {nil, nil, 94, 98, 86, 96, nil, 87, 90, 89, 93, 99, 88, nil, 91, 97}
current_world = ReadByte(world_address[game_version])
if keyblade_offsets[current_world] ~= nil then
keyblade_amt = ReadByte(stock_address[game_version] + keyblade_offsets[current_world])
if keyblade_amt > 0 then
return true
end
end
return false
end
function get_dg_count()
dg = 0
party_slot_1_address = {0x2DEA1EF, 0x2DE97EF} --changed for EGS 1.0.0.10
party_slot_2_address = {0x2DEA1F0, 0x2DE97F0} --changed for EGS 1.0.0.10
if ReadByte(party_slot_1_address[game_version]) == 1 or ReadByte(party_slot_1_address[game_version]) == 2 then
dg = dg + 1
end
if ReadByte(party_slot_2_address[game_version]) == 1 or ReadByte(party_slot_2_address[game_version]) == 2 then
dg = dg + 1
end
return dg
end
function _OnInit()
IsEpicGLVersion = 0x3A2B86
IsSteamGLVersion = 0x3A29A6
if GAME_ID == 0xAF71841E and ENGINE_TYPE == "BACKEND" then
if ReadByte(IsEpicGLVersion) == 0xF0 then
ConsolePrint("Epic Version Detected")
game_version = 1
end
if ReadByte(IsSteamGLVersion) == 0xF0 then
ConsolePrint("Steam Version Detected")
game_version = 2
end
canExecute = true
end
end
function _OnFrame()
if canExecute then
read_settings()
chests_address = {0x2B3904, 0x2B5AA4} --changed BOTH 1.0.0.10
chests = ReadByte(chests_address[game_version])
if (chestslocked and has_correct_keyblade() and chests == 0x72) or not chestslocked then
if interactinbattle then
WriteByte(chests_address[game_version], 0x73)
else
WriteByte(chests_address[game_version], 0x74)
end
elseif chestslocked and not has_correct_keyblade() and chests ~= 0x72 then
WriteByte(chests_address[game_version], 0x72)
end
if interactinbattle then
if not interactset then
Examine = {0x2929F9, 0x294B89} --changed BOTH 1.0.0.10
Talk = {0x292A39, 0x294BC9} --changed BOTH 1.0.0.10
WriteByte(Examine[game_version], 0x70)
WriteByte(Talk[game_version], 0x70)
interactset = true
end
Trinity = {0x1A2DAF, 0x1A4EFF} --changed BOTH 1.0.0.10
if get_dg_count() >= 2 then
WriteByte(Trinity[game_version], 0x71) -- Forced
else
WriteByte(Trinity[game_version], 0x75) -- Default
end
end
end
end