-
Notifications
You must be signed in to change notification settings - Fork 0
/
WaluigiClient.lua
268 lines (217 loc) · 6.73 KB
/
WaluigiClient.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
--[[ Waluigi Client
Made By NameGoesThere
This is a lua script intended to be loaded with the BizHawk emulator, other emulators WILL NOT work with this script.
This script will only work with the popular NES title, Super Mario Bros. This script WILL NOT work with other games.
You can find the BizHawk emulator at https://tasvideos.org/Bizhawk
(note: I don't like lua, and i'm not good at it either, if I made a mistake, please make an issue or a pull request.)
]]--
--- Client data
TITLE = "Waluigi Client"
TITLE_FONT = "calibri"
WARN_FONT = "candara"
-- All the different cheats
hacks = {"Powerup State", "Player Size", "Invincibility", "Lives", "Enemy ESP", "Powerup ESP", "Star", "Flight"}
-- Customizable values for the cheats (some cheats may not need these, so the max and min are set to 0)
values = {0, 0, 0, 3, 0, 0, 0, 0}
maxValues = {2, 1, 0, 127, 0, 0, 0, 0}
minValues = {0, 0, 0, 1, 0, 0, 0, 0}
-- What cheats are enabled
enabled = {false, false, false, false, false, false, false, false}
-- What cheat is selected
selected = 0
-- Keys pressed
up = joypad.get()["P1 Up"]
down = joypad.get()["P1 Down"]
left = joypad.get()["P1 Left"]
right = joypad.get()["P1 Right"]
press = joypad.get()["P1 A"]
-- Previous keys pressed
prevUp = false
prevDown = false
prevLeft = false
prevRight = false
prevPress = false
-- Is user changing the values of the different cheats
isSettings = false
-- Memory addresses for certain values (DO NOT CHANGE)
PAUSED = 0x0776
POWERUP_STATE = 0x0756
PLAYER_SIZE = 0x0754
INVINCIBILITY = 0x079E
LIVES = 0x075A
STAR = 0x079F
ENEMY_X = 0x03AE
ENEMY_Y = 0x03B9
ENEMY_DRAWN = 0x000F
POWERUP_X = 0x03B3
POWERUP_Y = 0x03BE
POWERUP_DRAWN = 0x0014
PLAYER_SPEED_H = 0x0057
PLAYER_SPEED_V = 0x009F
PLAYER_GRAVITY = 0x070A
-- Gets the hash of the ROM
ROM_HASH = gameinfo.getromhash()
-- Expected hash (Japan / US)
CORRECT_HASH = "EA343F4E445A9050D4B4FBAC2C77D0693B1D0922"
-- Incorrect ROM
UNEXPECTED_ROM = false
if ROM_HASH ~= CORRECT_HASH then
console.writeline("WARN: Unexpected ROM hash encountered. Expected: "..CORRECT_HASH..". Got: "..ROM_HASH)
UNEXPECTED_ROM = true
end
-- Main loop
while true do
-- Is the user pausing the game?
local _paused = mainmemory.readbyte(PAUSED)
-- Changing the previously pressed keys
prevDown = down
prevUp = up
prevPress = press
prevLeft = left
prevRight = right
-- Checking for keyboard input
up = joypad.get()["P1 Up"]
down = joypad.get()["P1 Down"]
left = joypad.get()["P1 Left"]
right = joypad.get()["P1 Right"]
press = joypad.get()["P1 A"]
-- Should the cheat menu be showed?
if _paused ~= 0 then
-- Unexpected ROM warning
if UNEXPECTED_ROM then
gui.drawText(1, 210, "WARN: Unexpected ROM hash encountered.", 0xffffff00, 0xff000000, 11, WARN_FONT)
end
-- Enables a cheat if you are hovering over it and you click the A button
if (not isSettings) and press and not prevPress then
enabled[selected+1] = not enabled[selected+1]
end
-- Down button pressed
if down and not prevDown then
if not isSettings then
-- Changes the selected cheat
selected = selected + 1
else
-- Decreases the current value (if selected)
values[selected+1] = values[selected+1] - 1
if values[selected+1] < minValues[selected+1] then
values[selected+1] = minValues[selected+1]
end
end
end
-- Up button pressed
if up and not prevUp then
if not isSettings then
-- Changes the selected cheat
selected = selected - 1
else
-- Increases the current value (if selected)
values[selected+1] = values[selected+1] + 1
if values[selected+1] > maxValues[selected+1] then
values[selected+1] = maxValues[selected+1]
end
end
end
-- Makes sure you can't select out of bounds (prevents crashes)
if selected < 0 then
selected = #hacks - 1
elseif selected > #hacks - 1 then
selected = 0
end
-- Is changing values
if right and not prevRight then
isSettings = true
elseif left and not prevLeft then
isSettings = false
end
-- Cheat menu background
gui.drawBox( 20, 24, 240, 180, 0x33000000, 0x55000000)
-- Title
gui.drawText( 21, 25, TITLE, 0xAAAA60AA, 0x00FFFFFF, 17, TITLE_FONT)
gui.drawText( 20, 24, TITLE, 0xFFFFB0FF, 0x00FFFFFF, 17, TITLE_FONT)
-- Loops over the cheats and renders their names based off of if they are enabled or not.
for i, h in pairs(hacks) do
if enabled[i] == false then
-- Not enabled
gui.drawText( 21, 25+(i+1)*11, h, 0xFF880000, 0x00000000, 10)
gui.drawText( 20, 24+(i+1)*11, h, 0xFFFF0000, 0x00000000, 10)
else
-- Enabled
gui.drawText( 21, 25+(i+1)*11, h, 0xFF006600, 0x00000000, 10)
gui.drawText( 20, 24+(i+1)*11, h, 0xFF00FF00, 0x00000000, 10)
end
end
-- Draws the customizable values of the cheats
for i, h in pairs(values) do
gui.drawText( 20+100+1, (24+(i+1)*11)+1, h, 0x88303030, 0x00000000, 10)
gui.drawText( 20+100, 24+(i+1)*11, h, 0xFF909090, 0x00000000, 10)
end
-- Draws the cursor
if not isSettings then
-- Not changing values
gui.drawBox(18, 24+(selected+2)*11, 20, 24+(selected+2)*11+10, 0xAAFFFFFF, 0xAAFFFFFF)
else
-- Changing values
gui.drawBox(118, 24+(selected+2)*11, 120, 24+(selected+2)*11+10, 0xAAFFFFFF, 0xAAFFFFFF)
end
else
-- Not paused
selected = 0
gui.clearGraphics()
end
-- Powerup state cheat
if enabled[1] == true then
mainmemory.writebyte(POWERUP_STATE, values[1])
end
-- Player size cheat
if enabled[2] == true then
mainmemory.writebyte(PLAYER_SIZE, 1-values[2])
end
-- Invincibility cheat
if enabled[3] == true then
mainmemory.writebyte(INVINCIBILITY, 2)
end
-- Lives cheat
if enabled[4] == true then
mainmemory.writebyte(LIVES, values[4] - 1)
end
-- Enemy ESP
if enabled[5] == true then
if mainmemory.readbyte(ENEMY_DRAWN) == 1 then
local x = mainmemory.readbyte(ENEMY_X)
local y = mainmemory.readbyte(ENEMY_Y)
gui.drawBox(x, y, x+16, y+16, 0xFFFFB0FF, 0x40FFB0FF)
end
end
-- Powerup ESP
if enabled[6] == true then
if mainmemory.readbyte(POWERUP_DRAWN) == 1 then
local x = mainmemory.readbyte(POWERUP_X)
local y = mainmemory.readbyte(POWERUP_Y)
gui.drawBox(x, y, x+16, y+16, 0xFFFFB0FF, 0x40FFB0FF)
end
end
-- Star
if enabled[7] == true then
mainmemory.writebyte(STAR, 2)
end
-- Flight
if enabled[8] == true then
mainmemory.writebyte(PLAYER_GRAVITY, 0x00)
mainmemory.writebyte(PLAYER_SPEED_V, 0x00)
if up then
mainmemory.writebyte(PLAYER_SPEED_V, 0xFD)
end
if down then
mainmemory.writebyte(PLAYER_SPEED_V, 0x03)
end
mainmemory.writebyte(PLAYER_SPEED_H, 0x00)
if left then
mainmemory.writebyte(PLAYER_SPEED_H, 0xD6)
end
if right then
mainmemory.writebyte(PLAYER_SPEED_H, 0x30)
end
end
-- Update graphics
emu.frameadvance()
end