forked from JoselleAstrid/ram-watch-cheat-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.lua
83 lines (67 loc) · 2.26 KB
/
runner.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
package.loaded.utils = nil
local utils = require "utils"
local classInstantiate = utils.classInstantiate
local function createWindow(options)
-- Create Cheat Engine window
local window = createForm(true)
-- Window position {xpixels, ypixels}; if nil, put at center of screen
if options.windowPosition ~= nil then
window:setPosition(options.windowPosition[1], options.windowPosition[2])
else
window:centerScreen()
end
-- Window title
window:setCaption("RAM Display")
return window
end
local function start(options)
local gameModuleName =
options.gameModuleName or error("Must provide a gameModuleName.")
local layoutName =
options.layoutName or error("Must provide a layoutName.")
package.loaded[gameModuleName] = nil
local GameClass = require(gameModuleName)
local game = classInstantiate(GameClass, options)
local window = createWindow(options)
-- Modules where we'll look for layout definitions.
local layoutModuleNames = {
-- Layouts that aren't game specific
'generic_layouts',
-- User-defined layouts (not under version control)
'custom_layouts',
}
-- Game-specific layout modules
for _, name in pairs(game.layoutModuleNames) do
table.insert(layoutModuleNames, name)
end
-- Get the requested layout.
local layout = nil
for _, layoutModuleName in pairs(layoutModuleNames) do
-- Due to the way we're checking the existence of layout modules, we must
-- first ensure the module is not considered loaded OR preloaded.
package.preload[layoutModuleName] = nil
package.loaded[layoutModuleName] = nil
-- Check that the layout module exists. In particular we want to tolerate
-- non-existence of the custom module.
if utils.isModuleAvailable(layoutModuleName) then
local layoutModule = require(layoutModuleName)
for name, layoutCandidate in pairs(layoutModule.layouts) do
if name == layoutName then
layout = layoutCandidate
break
end
end
end
end
if layout == nil then
error("Couldn't find layout named: " .. layoutName)
end
local layoutOptions = options.layoutOptions or {}
layout.window = window
layout.game = game
layout:init(unpack(layoutOptions))
game:startUpdating(layout)
end
return {
start = start,
}