-
Notifications
You must be signed in to change notification settings - Fork 1k
/
HeadlessWrapper.lua
205 lines (188 loc) · 4.9 KB
/
HeadlessWrapper.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#@
-- This wrapper allows the program to run headless on any OS (in theory)
-- It can be run using a standard lua interpreter, although LuaJIT is preferable
-- Callbacks
local callbackTable = { }
local mainObject
local function runCallback(name, ...)
if callbackTable[name] then
return callbackTable[name](...)
elseif mainObject and mainObject[name] then
return mainObject[name](mainObject, ...)
end
end
function SetCallback(name, func)
callbackTable[name] = func
end
function GetCallback(name)
return callbackTable[name]
end
function SetMainObject(obj)
mainObject = obj
end
-- Image Handles
local imageHandleClass = { }
imageHandleClass.__index = imageHandleClass
function NewImageHandle()
return setmetatable({ }, imageHandleClass)
end
function imageHandleClass:Load(fileName, ...)
self.valid = true
end
function imageHandleClass:Unload()
self.valid = false
end
function imageHandleClass:IsValid()
return self.valid
end
function imageHandleClass:SetLoadingPriority(pri) end
function imageHandleClass:ImageSize()
return 1, 1
end
-- Rendering
function RenderInit() end
function GetScreenSize()
return 1920, 1080
end
function SetClearColor(r, g, b, a) end
function SetDrawLayer(layer, subLayer) end
function SetViewport(x, y, width, height) end
function SetDrawColor(r, g, b, a) end
function DrawImage(imgHandle, left, top, width, height, tcLeft, tcTop, tcRight, tcBottom) end
function DrawImageQuad(imageHandle, x1, y1, x2, y2, x3, y3, x4, y4, s1, t1, s2, t2, s3, t3, s4, t4) end
function DrawString(left, top, align, height, font, text) end
function DrawStringWidth(height, font, text)
return 1
end
function DrawStringCursorIndex(height, font, text, cursorX, cursorY)
return 0
end
function StripEscapes(text)
return text:gsub("^%d",""):gsub("^x%x%x%x%x%x%x","")
end
function GetAsyncCount()
return 0
end
-- Search Handles
function NewFileSearch() end
-- General Functions
function SetWindowTitle(title) end
function GetCursorPos()
return 0, 0
end
function SetCursorPos(x, y) end
function ShowCursor(doShow) end
function IsKeyDown(keyName) end
function Copy(text) end
function Paste() end
function Deflate(data)
-- TODO: Might need this
return ""
end
function Inflate(data)
-- TODO: And this
return ""
end
function GetTime()
return 0
end
function GetScriptPath()
return ""
end
function GetRuntimePath()
return ""
end
function GetUserPath()
return ""
end
function MakeDir(path) end
function RemoveDir(path) end
function SetWorkDir(path) end
function GetWorkDir()
return ""
end
function LaunchSubScript(scriptText, funcList, subList, ...) end
function AbortSubScript(ssID) end
function IsSubScriptRunning(ssID) end
function LoadModule(fileName, ...)
if not fileName:match("%.lua") then
fileName = fileName .. ".lua"
end
local func, err = loadfile(fileName)
if func then
return func(...)
else
error("LoadModule() error loading '"..fileName.."': "..err)
end
end
function PLoadModule(fileName, ...)
if not fileName:match("%.lua") then
fileName = fileName .. ".lua"
end
local func, err = loadfile(fileName)
if func then
return PCall(func, ...)
else
error("PLoadModule() error loading '"..fileName.."': "..err)
end
end
function PCall(func, ...)
local ret = { pcall(func, ...) }
if ret[1] then
table.remove(ret, 1)
return nil, unpack(ret)
else
return ret[2]
end
end
function ConPrintf(fmt, ...)
-- Optional
--print(string.format(fmt, ...))
end
function ConPrintTable(tbl, noRecurse) end
function ConExecute(cmd) end
function ConClear() end
function SpawnProcess(cmdName, args) end
function OpenURL(url) end
function SetProfiling(isEnabled) end
function Restart() end
function Exit() end
local l_require = require
function require(name)
-- Hack to stop it looking for lcurl, which we don't really need
if name == "lcurl.safe" then
return
end
return l_require(name)
end
dofile("Launch.lua")
runCallback("OnInit")
runCallback("OnFrame") -- Need at least one frame for everything to initialise
if mainObject.promptMsg then
-- Something went wrong during startup
print(mainObject.promptMsg)
io.read("*l")
return
end
-- The build module; once a build is loaded, you can find all the good stuff in here
local build = mainObject.main.modes["BUILD"]
-- Here's some helpful helper functions to help you get started
local function newBuild()
mainObject.main:SetMode("BUILD", false, "Help, I'm stuck in Path of Building!")
runCallback("OnFrame")
end
local function loadBuildFromXML(xmlText)
mainObject.main:SetMode("BUILD", false, "", xmlText)
runCallback("OnFrame")
end
local function loadBuildFromJSON(getItemsJSON, getPassiveSkillsJSON)
mainObject.main:SetMode("BUILD", false, "")
runCallback("OnFrame")
local charData = build.importTab:ImportItemsAndSkills(getItemsJSON)
build.importTab:ImportPassiveTreeAndJewels(getPassiveSkillsJSON, charData)
-- You now have a build without a correct main skill selected, or any configuration options set
-- Good luck!
end
-- Now you can mess around!
-- Probably optional
runCallback("OnExit")