-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.lua
executable file
·55 lines (49 loc) · 1.4 KB
/
utils.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
-- Auxiliary module for IO/Logging functions
local u = {}
function u.log(message)
print("--> asm.lua: " .. message)
end
function u.syntaxCheck(script)
local err, message = autoAssembleCheck(script)
if not err then
u.log("Syntax error found in autoassembler script.\n" .. message)
return ""
end
return script
end
-- Open Cheat Engine's auto assemble(.asm) scripts and return contents as a string
function u.open(path)
local file = io.open(path, "r")
if file == nil then
u.log("Couldn't find file!")
return
end
local script = file:read("*all")
file:close()
return u.syntaxCheck(script)
end
-- Parse a .asm file, return only the section
-- [enable] if enable otherwise returns [disable] section
function u.extractSection(path, enable)
local key = {start = nil, stop = nil}
if enable then
key.start = "[ENABLE]"
key.stop = "[DISABLE]"
else
key.start = "[DISABLE]"
key.stop = "[ENABLE]"
end
local script = ""
local appendFlag = false
for line in io.lines(path) do
if line == key.start then
appendFlag = true
elseif line == key.stop then
appendFlag = false
elseif appendFlag then
script = script .. line .. "\n"
end
end
return u.syntaxCheck(script)
end
return u