-
Notifications
You must be signed in to change notification settings - Fork 4
/
MarioKart64_Waypoints.lua
318 lines (224 loc) · 12 KB
/
MarioKart64_Waypoints.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
--This Lua script was developed by Drew Weatherton for the BizHawk emulator (requires v1.9.4 or later)----------------
--NOTE: Script must be stored in the same directory as EmuHawk.exe for some functions to work-------------------------
--Purpose: Establish waypoints to track distance to provide benchmarks for progress-----------------------------------
console.clear()
--User has clicked the "Save" button
function SaveWaypoint1Button()
if forms.ischecked(CheckboxWayline1) == true then
CheckboxWayline1State = "true"
else
CheckboxWayline1State = "false"
end
if forms.ischecked(CheckboxWaypoint2) == true then
CheckboxWaypoint2State = "true"
else
CheckboxWaypoint2State = "false"
end
if forms.ischecked(CheckboxWayline2) == true then
CheckboxWayline2State = "true"
else
CheckboxWayline2State = "false"
end
local handle = io.open(forms.gettext(WaypointFilename) .. ".wpt", "w+")
handle:write(
CheckboxWayline1State .. "\n" ..
CheckboxWaypoint2State .. "\n" ..
CheckboxWayline2State .. "\n" ..
forms.gettext(Waypoint1TitleTextBox) .. "\n" ..
forms.gettext(Waypoint1XTextBox) .. "\n" ..
forms.gettext(Waypoint1YTextBox) .. "\n" ..
forms.gettext(Waypoint1ZTextBox) .. "\n" ..
forms.gettext(Waypoint1X2TextBox) .. "\n" ..
forms.gettext(Waypoint1Y2TextBox) .. "\n" ..
forms.gettext(Waypoint1Z2TextBox) .. "\n" ..
forms.gettext(Waypoint2TitleTextBox) .. "\n" ..
forms.gettext(Waypoint2XTextBox) .. "\n" ..
forms.gettext(Waypoint2YTextBox) .. "\n" ..
forms.gettext(Waypoint2ZTextBox) .. "\n" ..
forms.gettext(Waypoint2X2TextBox) .. "\n" ..
forms.gettext(Waypoint2Y2TextBox) .. "\n" ..
forms.gettext(Waypoint2Z2TextBox))
handle:close()
console.log("Waypoint File Saved")
end
--User has clicked the "Open" button
function OpenWaypoint1Button()
SavedVariables = { }
SavedVariables[0] = CheckboxWayline1
SavedVariables[1] = CheckboxWaypoint2
SavedVariables[2] = CheckboxWayline2
SavedVariables[3] = Waypoint1TitleTextBox
SavedVariables[4] = Waypoint1XTextBox
SavedVariables[5] = Waypoint1YTextBox
SavedVariables[6] = Waypoint1ZTextBox
SavedVariables[7] = Waypoint1X2TextBox
SavedVariables[8] = Waypoint1Y2TextBox
SavedVariables[9] = Waypoint1Z2TextBox
SavedVariables[10] = Waypoint2TitleTextBox
SavedVariables[11] = Waypoint2XTextBox
SavedVariables[12] = Waypoint2YTextBox
SavedVariables[13] = Waypoint2ZTextBox
SavedVariables[14] = Waypoint2X2TextBox
SavedVariables[15] = Waypoint2Y2TextBox
SavedVariables[16] = Waypoint2Z2TextBox
WaypointDirectory = forms.openfile()
local i = 0
for line in io.lines(WaypointDirectory) do
console.log(line)
if i < 3 then
forms.setproperty(SavedVariables[i],"Checked",line)
else
forms.settext(SavedVariables[i], line)
end
i = i + 1
end
end
function SetWaypoint1Button()
forms.settext(Waypoint1XTextBox, PlayerX)
forms.settext(Waypoint1YTextBox, PlayerY)
forms.settext(Waypoint1ZTextBox, PlayerZ)
end
function SetWaypoint1Button2()
forms.settext(Waypoint1X2TextBox, PlayerX)
forms.settext(Waypoint1Y2TextBox, PlayerY)
forms.settext(Waypoint1Z2TextBox, PlayerZ)
end
function SetWaypoint2Button()
forms.settext(Waypoint2XTextBox, PlayerX)
forms.settext(Waypoint2YTextBox, PlayerY)
forms.settext(Waypoint2ZTextBox, PlayerZ)
end
function SetWaypoint2Button2()
forms.settext(Waypoint2X2TextBox, PlayerX)
forms.settext(Waypoint2Y2TextBox, PlayerY)
forms.settext(Waypoint2Z2TextBox, PlayerZ)
end
WaypointsWindow = forms.newform(482, 700, "Mario Kart 64 Waypoint Dashboard")
WaypointFilename = forms.textbox(WaypointsWindow, "Filename", 366, 18, "", 53, 3, true, true)
SaveWaypoint1Handle = forms.button(WaypointsWindow, "Save", SaveWaypoint1Button, 0, 0, 50, 23)
OpenWaypoint1Handle = forms.button(WaypointsWindow, "Open", OpenWaypoint1Button, 422, 0, 50, 23)
-- Waypoint 1------------------------------------------------------------------------------------------------------------
-- Waypoint 1, Point 1
forms.label(WaypointsWindow, "____________________________________________________________________________________", 0, 11, 477, 14)
forms.label(WaypointsWindow, "Waypoint 1:", 0, 30, 64, 18)
SetWaypoint1Handle = forms.button(WaypointsWindow, "Set from location", SetWaypoint1Button, 185, 110, 94, 23)
Waypoint1TitleTextBox = forms.textbox(WaypointsWindow, "Title", 408, 20, "", 64, 27, true, true)
Waypoint1XTextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 185, 50, false, true)
Waypoint1XLabel = forms.label(WaypointsWindow, "X:", 171, 55, 17, 15)
Waypoint1X = tonumber(forms.gettext(Waypoint1XTextBox))
Waypoint1YTextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 185, 70, false, true)
forms.label(WaypointsWindow, "Y:", 171, 75, 17, 15)
Waypoint1Y = tonumber(forms.gettext(Waypoint1YTextBox))
Waypoint1ZTextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 185, 90, false, true)
forms.label(WaypointsWindow, "Z:", 171, 95, 17, 15)
Waypoint1Z = tonumber(forms.gettext(Waypoint1ZTextBox))
-- Waypoint 1, Point 2
SetWaypoint1Handle2 = forms.button(WaypointsWindow, "Set from location", SetWaypoint1Button2, 378, 110, 94, 23)
-- Create checkbox for toggling this waypoint's visiblity
CheckboxWayline1 = forms.checkbox(WaypointsWindow, "Line segment", 295, 110)
-- This starts as invisible (size 0,0) but size is changed to cover all related inputs
Waypoint1Cover2 = forms.label(WaypointsWindow, "", 320, 50, 0, 0)
Waypoint1X2TextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 340, 50, false, true)
forms.label(WaypointsWindow, "X2:", 320, 55, 24, 15)
Waypoint1X2 = tonumber(forms.gettext(Waypoint1X2TextBox))
Waypoint1Y2TextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 340, 70, false, true)
forms.label(WaypointsWindow, "Y2:", 320, 75, 24, 15)
Waypoint1Y2 = tonumber(forms.gettext(Waypoint1Y2TextBox))
Waypoint1Z2TextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 340, 90, false, true)
forms.label(WaypointsWindow, "Z2:", 320, 95, 24, 15)
Waypoint1Z2 = tonumber(forms.gettext(Waypoint1Z2TextBox))
-- Distances
forms.label(WaypointsWindow, "Distances:", 10, 53, 60, 15)
Waypoint1XYTextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 33, 70, false, true)
forms.label(WaypointsWindow, "XY:", 10, 75, 25, 20)
Waypoint1XYZTextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 33, 90, false, true)
forms.label(WaypointsWindow, "XYZ:", 3, 95, 32, 20)
-- Waypoint 2------------------------------------------------------------------------------------------------------------
-- Waypoint 2, Point 1
forms.label(WaypointsWindow, "____________________________________________________________________________________", 0, 123, 477, 14)
Waypoint2TitleTextBox = forms.textbox(WaypointsWindow, "Title", 388, 20, "", 84, 139, true, true)
CheckboxWaypoint2 = forms.checkbox(WaypointsWindow, "Waypoint 2:", 3, 137)
SetWaypoint1Handle = forms.button(WaypointsWindow, "Set from location", SetWaypoint2Button, 185, 222, 94, 23)
Waypoint2XTextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 185, 162, false, true)
Waypoint2XLabel = forms.label(WaypointsWindow, "X:", 171, 167, 17, 15)
Waypoint2X = tonumber(forms.gettext(Waypoint1XTextBox))
Waypoint2YTextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 185, 182, false, true)
forms.label(WaypointsWindow, "Y:", 171, 187, 17, 15)
Waypoint2Y = tonumber(forms.gettext(Waypoint1YTextBox))
Waypoint2ZTextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 185, 202, false, true)
forms.label(WaypointsWindow, "Z:", 171, 207, 17, 15)
Waypoint2Z = tonumber(forms.gettext(Waypoint1ZTextBox))
-- Waypoint 1, Point 2
SetWaypoint2Handle2 = forms.button(WaypointsWindow, "Set from location", SetWaypoint2Button2, 378, 222, 94, 23)
-- Create checkbox for toggling this waypoint's visiblity
CheckboxWayline2 = forms.checkbox(WaypointsWindow, "Line segment", 295, 222)
-- This starts as invisible (size 0,0) but size is changed to cover all related inputs
Waypoint2Cover2 = forms.label(WaypointsWindow, "", 320, 162, 0, 0)
Waypoint2X2TextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 340, 162, false, true)
forms.label(WaypointsWindow, "X2:", 320, 167, 24, 15)
Waypoint2X2 = tonumber(forms.gettext(Waypoint1X2TextBox))
Waypoint2Y2TextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 340, 182, false, true)
forms.label(WaypointsWindow, "Y2:", 320, 187, 24, 15)
Waypoint2Y2 = tonumber(forms.gettext(Waypoint1Y2TextBox))
Waypoint2Z2TextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 340, 202, false, true)
forms.label(WaypointsWindow, "Z2:", 320, 207, 24, 15)
Waypoint2Z2 = tonumber(forms.gettext(Waypoint1Z2TextBox))
-- Distances
forms.label(WaypointsWindow, "Distances:", 10, 165, 60, 15)
Waypoint2XYTextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 33, 182, false, true)
forms.label(WaypointsWindow, "XY:", 10, 187, 25, 20)
Waypoint2XYZTextBox = forms.textbox(WaypointsWindow, "0", 132, 20, SIGNED, 33, 202, false, true)
forms.label(WaypointsWindow, "XYZ:", 3, 207, 32, 20)
while true do
Xaddr = 0x0F69A4
Yaddr = 0x0F69AC
Zaddr = 0xF69A8
-- Divide by 18 to convert to meters
PlayerX=(mainmemory.readfloat(Xaddr, true)/18)
PlayerY=(mainmemory.readfloat(Yaddr, true)/18)
PlayerZ=(mainmemory.readfloat(Zaddr, true)/18)
-- Waypoint 1 Logic
Waypoint1X = tonumber(forms.gettext(Waypoint1XTextBox))
Waypoint1Y = tonumber(forms.gettext(Waypoint1YTextBox))
Waypoint1Z = tonumber(forms.gettext(Waypoint1ZTextBox))
Waypoint1XY = math.sqrt ((Waypoint1X-PlayerX)^2+(Waypoint1Y-PlayerY)^2)
forms.settext(Waypoint1XYTextBox, Waypoint1XY)
Waypoint1XYZ = math.sqrt ((Waypoint1X-PlayerX)^2+(Waypoint1Y-PlayerY)^2+(Waypoint1Z-PlayerZ)^2)
forms.settext(Waypoint1XYZTextBox, Waypoint1XYZ)
if forms.ischecked(CheckboxWayline1) == false then
forms.setproperty(Waypoint1Cover2,"Visible",true)
forms.setproperty(SetWaypoint1Handle2,"Visible",false)
else
forms.setproperty(Waypoint1Cover2,"Visible",false)
forms.setproperty(SetWaypoint1Handle2,"Visible",true)
Waypoint1X2 = tonumber(forms.gettext(Waypoint1X2TextBox))
Waypoint1Y2 = tonumber(forms.gettext(Waypoint1Y2TextBox))
Waypoint1Z2 = tonumber(forms.gettext(Waypoint1Z2TextBox))
end
if forms.ischecked(CheckboxWaypoint2) == false then
forms.setsize(WaypointsWindow, 482, 182)
forms.setproperty(Waypoint2TitleTextBox,"Visible",false)
else
forms.setsize(WaypointsWindow, 482, 272)
forms.setproperty(Waypoint2TitleTextBox,"Visible",true)
-- Waypoint 2 Logic
Waypoint2X = tonumber(forms.gettext(Waypoint2XTextBox))
Waypoint2Y = tonumber(forms.gettext(Waypoint2YTextBox))
Waypoint2Z = tonumber(forms.gettext(Waypoint2ZTextBox))
Waypoint2XY = math.sqrt ((Waypoint2X-PlayerX)^2+(Waypoint2Y-PlayerY)^2)
forms.settext(Waypoint2XYTextBox, Waypoint2XY)
Waypoint2XYZ = math.sqrt ((Waypoint2X-PlayerX)^2+(Waypoint2Y-PlayerY)^2+(Waypoint2Z-PlayerZ)^2)
forms.settext(Waypoint2XYZTextBox, Waypoint2XYZ)
end
if forms.ischecked(CheckboxWayline2) == false then
forms.setproperty(Waypoint2Cover2,"Visible",true)
forms.setproperty(SetWaypoint2Handle2,"Visible",false)
else
forms.setproperty(Waypoint2Cover2,"Visible",false)
forms.setproperty(SetWaypoint2Handle2,"Visible",true)
Waypoint2X2 = tonumber(forms.gettext(Waypoint2X2TextBox))
Waypoint2Y2 = tonumber(forms.gettext(Waypoint2Y2TextBox))
Waypoint2Z2 = tonumber(forms.gettext(Waypoint2Z2TextBox))
end
emu.frameadvance()
end