forked from gaithern/KH-1FM-AP-LUA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1fmAPKeybladeStats.lua
110 lines (97 loc) · 3.04 KB
/
1fmAPKeybladeStats.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 = "1fmAPKeybladeStats"
LUAGUI_AUTH = "Gicu"
LUAGUI_DESC = "Kingdom Hearts 1FM AP Integration"
game_version = 1 --1 for ESG 1.0.0.9, 2 for Steam 1.0.0.9
local keyblade_stats_base_address = {0x2D2CBB8, 0x2D2C238}
local canExecute = false
local finished = false
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 split(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
function read_keyblade_stats()
if file_exists(client_communication_path .. "keyblade_stats.cfg") then
file = io.open(client_communication_path .. "keyblade_stats.cfg", "r")
io.input(file)
keyblade_stats = split(io.read(),",")
io.close(file)
return keyblade_stats
elseif file_exists(client_communication_path .. "Keyblade Stats.cfg") then
file = io.open(client_communication_path .. "Keyblade Stats.cfg", "r")
io.input(file)
keyblade_stats = split(io.read(),",")
io.close(file)
return keyblade_stats
else
return nil
end
end
function write_keyblade_stats(keyblade_stats)
i = 1
j = 0
while i <= #keyblade_stats do
str = tonumber(keyblade_stats[i])
mp = tonumber(keyblade_stats[i+1])
WriteByte(keyblade_stats_base_address[game_version] + (0x58 * j) + 0x30, str)
WriteByte(keyblade_stats_base_address[game_version] + (0x58 * j) + 0x38, mp)
i = i + 2
j = j + 1
end
end
function give_dream_weapons()
inventory_address = {0x2DEA179, 0x2DE97F9}
WriteArray(inventory_address[game_version] + 82, {1,1,1})
end
function main()
keyblade_stats = read_keyblade_stats()
if keyblade_stats ~= nil and not finished then
write_keyblade_stats(keyblade_stats)
finished = true
end
give_dream_weapons()
end
function _OnInit()
IsEpicGLVersion = 0x3A2B86
IsSteamGLVersion = 0x3A29A6
if GAME_ID == 0xAF71841E and ENGINE_TYPE == "BACKEND" then
if ReadByte(IsEpicGLVersion) == 0xFF then
ConsolePrint("Epic Version Detected")
game_version = 1
end
if ReadByte(IsSteamGLVersion) == 0xFF then
ConsolePrint("Steam Version Detected")
game_version = 2
end
canExecute = true
end
end
function _OnFrame()
if frame_count == 0 and canExecute then
main()
end
frame_count = (frame_count + 1) % 30
end