forked from JoselleAstrid/ram-watch-cheat-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbfbb.lua
428 lines (335 loc) · 13.6 KB
/
bfbb.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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
package.loaded.utils = nil
local utils = require 'utils'
local subclass = utils.subclass
package.loaded.dolphin = nil
local dolphin = require 'dolphin'
package.loaded.valuetypes = nil
local valuetypes = require 'valuetypes'
local V = valuetypes.V
local MV = valuetypes.MV
local Block = valuetypes.Block
local Value = valuetypes.Value
local MemoryValue = valuetypes.MemoryValue
local FloatType = valuetypes.FloatTypeBE
local UIntType = valuetypes.IntTypeBE
local UShortType = valuetypes.ShortTypeBE
local UByteType = valuetypes.ByteType
local SIntType = valuetypes.SignedIntTypeBE
local SShortType = valuetypes.SignedShortTypeBE
local SByteType = valuetypes.SignedByteType
local BinaryType = valuetypes.BinaryType
package.loaded.layouts = nil
local layoutsModule = require 'layouts'
local BFBB = subclass(dolphin.DolphinGame)
BFBB.supportedGameVersions = {
na = 'GQPE78',
}
BFBB.layoutModuleNames = {'bfbb_layouts'}
BFBB.framerate = 60
BFBB.labelPadding = 0
function BFBB:init(options)
dolphin.DolphinGame.init(self, options)
local start = self:getGameStartAddress()
self.start = start
local addrs = {}
self.addrs = addrs
addrs["globals"] = start + 0x3C0558
addrs["globals.camera.yaw_cur"] = addrs["globals"] + 0x1D4
addrs["globals.pad0"] = addrs["globals"] + 0x31C
addrs["globals.player"] = addrs["globals"] + 0x6E0
addrs["globals.player.ent"] = addrs["globals.player"] + 0
addrs["globals.player.ent.model"] = addrs["globals.player.ent"] + 0x24
addrs["globals.player.ent.frame"] = addrs["globals.player.ent"] + 0x48
addrs["globals.player.Health"] = addrs["globals.player"] + 0xFD0
addrs["globals.player.bbowlInitVel"] = addrs["globals.player"] + 0x1308
addrs["globals.player.IsBubbleBowling"] = addrs["globals.player"] + 0x140C
addrs["globals.player.Inv_Shiny"] = addrs["globals.player"] + 0x1420
addrs["globals.player.Inv_Spatula"] = addrs["globals.player"] + 0x1424
addrs["globals.player.Inv_PatsSock_Total"] = addrs["globals.player"] + 0x14E4
addrs["sBubbleBowlTimer"] = start + 0x3CB6CC
addrs["gGameOstrich"] = start + 0x3CB8AC
addrs["jumpPower"] = start + 0x3BF6E8
addrs["oob_state::shared::flags"] = start + 0x297E48
addrs["sPadData"] = start + 0x292620
--
-- sPadData addresses have been replaced by globals.pad0 to fix stick twitching
--
-- for a version where only analog sticks use globals.pad0
-- checkout 1ea2ed0907c4ce99caf258faa7caab4f9509918c
-- for a version where both analog sticks and buttons use sPadData
-- checkout ea8008ca4652c586f02325fbf113bdbe36d5580d
--
-- addrs["sPadData[0].button"] = addrs["sPadData"] + 0
-- addrs["sPadData[0].button 2"] = addrs["sPadData"] + 1
-- addrs["sPadData[0].stickX"] = addrs["sPadData"] + 2
-- addrs["sPadData[0].stickY"] = addrs["sPadData"] + 3
-- addrs["sPadData[0].substickX"] = addrs["sPadData"] + 4
-- addrs["sPadData[0].substickY"] = addrs["sPadData"] + 5
addrs["sPadData[0].triggerLeft"] = addrs["sPadData"] + 6
addrs["sPadData[0].triggerRight"] = addrs["sPadData"] + 7
end
function BFBB:toCEAddress(dolphinAddr)
return dolphinAddr - 0x80000000 + self.start
end
function BFBB:updateAddresses()
self.addrs["globals.pad0->pressed"] = nil
self.addrs["globals.pad0->released"] = nil
self.addrs["globals.pad0->analog1.x"] = nil
self.addrs["globals.pad0->analog1.y"] = nil
self.addrs["globals.pad0->analog2.x"] = nil
self.addrs["globals.pad0->analog2.y"] = nil
self.addrs["globals.player.ent.model->Mat"] = nil
self.addrs["globals.player.ent.model->Mat->pos.x"] = nil
self.addrs["globals.player.ent.model->Mat->pos.y"] = nil
self.addrs["globals.player.ent.model->Mat->pos.z"] = nil
self.addrs["globals.player.ent.frame->vel.x"] = nil
self.addrs["globals.player.ent.frame->vel.y"] = nil
self.addrs["globals.player.ent.frame->vel.z"] = nil
self.addrs["globals.player.ent.frame->rot.angle"] = nil
local pad0 = utils.readIntBE(self.addrs["globals.pad0"])
if pad0 ~= 0 then
pad0 = self:toCEAddress(pad0)
self.addrs["globals.pad0->pressed"] = pad0 + 0x30
self.addrs["globals.pad0->released"] = pad0 + 0x34
self.addrs["globals.pad0->analog1.x"] = pad0 + 0x38
self.addrs["globals.pad0->analog1.y"] = pad0 + 0x39
self.addrs["globals.pad0->analog2.x"] = pad0 + 0x3A
self.addrs["globals.pad0->analog2.y"] = pad0 + 0x3B
end
local model = utils.readIntBE(self.addrs["globals.player.ent.model"])
if model ~= 0 then
model = self:toCEAddress(model)
self.addrs["globals.player.ent.model->Mat"] = model + 0x4C
local mat = utils.readIntBE(self.addrs["globals.player.ent.model->Mat"])
if mat ~= 0 then
mat = self:toCEAddress(mat)
self.addrs["globals.player.ent.model->Mat->pos.x"] = mat + 0x30
self.addrs["globals.player.ent.model->Mat->pos.y"] = mat + 0x34
self.addrs["globals.player.ent.model->Mat->pos.z"] = mat + 0x38
end
end
local frame = utils.readIntBE(self.addrs["globals.player.ent.frame"])
if frame ~= 0 then
frame = self:toCEAddress(frame)
self.addrs["globals.player.ent.frame->vel.x"] = frame + 0xD4
self.addrs["globals.player.ent.frame->vel.y"] = frame + 0xD8
self.addrs["globals.player.ent.frame->vel.z"] = frame + 0xDC
self.addrs["globals.player.ent.frame->rot.angle"] = frame + 0xB8
end
end
function BFBB:setLabelPadding(padding)
BFBB.labelPadding = padding
end
function BFBB:padLabel(label)
return string.format("%-" .. BFBB.labelPadding .. "s", label)
end
local BFBBValue = subclass(MemoryValue)
BFBB.BFBBValue = BFBBValue
function BFBBValue:init(label, name, extraArgs)
MemoryValue.init(self, label, 0)
self.name = name
if extraArgs ~= nil and extraArgs.safeToRead ~= nil then
self.safeToRead = extraArgs.safeToRead
end
end
function BFBBValue:isAddressValid(addr)
return (addr ~= nil and
addr >= self.game.start and
addr < self.game.start + 0x20000000)
end
function BFBBValue:getAddress()
return self.game.addrs[self.name]
end
function BFBBValue:isValid()
return self:isAddressValid(self:getAddress()) and
(self.safeToRead == nil or self:safeToRead())
end
function BFBBValue:getLabel()
return self.game:padLabel(self.label)
end
local SimpleValue = subclass(Value)
BFBB.SimpleValue = SimpleValue
function SimpleValue:getLabel()
return self.game:padLabel(self.label)
end
-------------------------------------
----------- custom values -----------
-------- subclass(BFBBValue) --------
-------------------------------------
local StickXValue = subclass(BFBBValue)
BFBB.StickXValue = StickXValue
function StickXValue:get()
return 128 + BFBBValue.get(self)
end
local StickYValue = subclass(BFBBValue)
BFBB.StickYValue = StickYValue
function StickYValue:get()
return 128 - BFBBValue.get(self)
end
-------------------------------------
----------- simple values -----------
------- subclass(SimpleValue) -------
-------------------------------------
local ButtonValue = subclass(SimpleValue)
BFBB.ButtonValue = ButtonValue
function ButtonValue:init()
SimpleValue.init(self)
self.current = 0
end
function ButtonValue:updateValue()
-- mask in pressed buttons
self.current = self.current | self.game.buttonPressed:get()
-- mask out released buttons
self.current = self.current & ~self.game.buttonReleased:get()
self.value = self.current
end
local RotatedVelXValue = subclass(SimpleValue)
BFBB.RotatedVelXValue = RotatedVelXValue
function RotatedVelXValue:updateValue()
local angle = self.game.camAngle:get()
local s = math.sin(angle)
local c = math.cos(angle)
self.value = -self.game.xvel:get() * c + self.game.zvel:get() * s
end
local RotatedVelZValue = subclass(SimpleValue)
BFBB.RotatedVelZValue = RotatedVelZValue
function RotatedVelZValue:updateValue()
local angle = self.game.camAngle:get()
local s = math.sin(angle)
local c = math.cos(angle)
self.value = self.game.xvel:get() * s + self.game.zvel:get() * c
end
function centerString(s, n)
local l = string.len(s)
if l >= n then return s end
local d = n - l
local r = d // 2
local l = d - r
for i=1,l do
s = " " .. s
end
for i=1,r do
s = s .. " "
end
return s
end
local HVelLengthValue = subclass(SimpleValue)
BFBB.HVelLengthValue = HVelLengthValue
function HVelLengthValue:updateValue()
local angle = self.game.camAngle:get()
local x = self.game.xvel:get()
local z = self.game.zvel:get()
self.value = math.sqrt(math.pow(x, 2) + math.pow(z, 2))
end
function HVelLengthValue:displayValue(options)
s = SimpleValue.displayValue(self, options)
return centerString(s, 10)
end
local VVelLengthValue = subclass(SimpleValue)
BFBB.VVelLengthValue = VVelLengthValue
function VVelLengthValue:updateValue()
self.value = self.game.yvel:get()
end
function VVelLengthValue:displayValue(options)
s = SimpleValue.displayValue(self, options)
return centerString(s, 10)
end
local ZeroValue = subclass(SimpleValue)
BFBB.ZeroValue = ZeroValue
function ZeroValue:updateValue()
self.value = 0
end
local HansStateStrValue = subclass(SimpleValue)
BFBB.HansStateStrValue = HansStateStrValue
function HansStateStrValue:updateValue()
v = self.game.hansState:get()
s = tostring(v)
if v == 3 then
s = "Enabled"
-- s = "Enabled (" .. s .. ")"
elseif v == 7 then
s = "Disabled"
-- s = "Disabled (" .. s .. ")"
end
self.value = s
end
-- override to prevent unnecessary string conversion
function HansStateStrValue:displayValue(options)
return self.value
end
-------------------------------------
---------- value functions ----------
-------------------------------------
function value(label, offset, typeMixinClass, safeToRead, extraArgs)
if extraArgs == nil then
extraArgs = {}
end
extraArgs.safeToRead = safeToRead
return MV(label, offset, BFBBValue, typeMixinClass, extraArgs)
end
function customvalue(label, offset, valueClass, typeMixinClass, safeToRead, extraArgs)
if extraArgs == nil then
extraArgs = {}
end
extraArgs.safeToRead = safeToRead
return MV(label, offset, valueClass, typeMixinClass, extraArgs)
end
function simplevalue(label, valueClass)
v = V(valueClass)
v.label = label
return v
end
function playerEntSafeToRead(value)
return utils.readIntBE(value.game.addrs["gGameOstrich"]) == 2
end
local GV = BFBB.blockValues
GV.health = value("Health", "globals.player.Health", UIntType)
GV.bowlingState = value("Bowl State", "globals.player.IsBubbleBowling", SIntType)
GV.bowlingSpeed = value("Bowl Speed", "globals.player.bbowlInitVel", FloatType)
GV.bowlingDamp = value("Bowl Dampen", "sBubbleBowlTimer", FloatType)
GV.shinyObjects = value("Shiny Objects", "globals.player.Inv_Shiny", UIntType)
GV.spatulas = value("Spatulas", "globals.player.Inv_Spatula", UIntType)
GV.socks = value("Socks", "globals.player.Inv_PatsSock_Total", UIntType)
GV.xpos = value("X Position", "globals.player.ent.model->Mat->pos.x", FloatType, playerEntSafeToRead)
GV.ypos = value("Y Position", "globals.player.ent.model->Mat->pos.y", FloatType, playerEntSafeToRead)
GV.zpos = value("Z Position", "globals.player.ent.model->Mat->pos.z", FloatType, playerEntSafeToRead)
GV.xvel = value("X Momentum", "globals.player.ent.frame->vel.x", FloatType, playerEntSafeToRead)
GV.yvel = value("Y Momentum", "globals.player.ent.frame->vel.y", FloatType, playerEntSafeToRead)
GV.zvel = value("Z Momentum", "globals.player.ent.frame->vel.z", FloatType, playerEntSafeToRead)
GV.facingAngle = value("Facing Angle", "globals.player.ent.frame->rot.angle", FloatType, playerEntSafeToRead)
GV.camAngle = value("Camera angle", "globals.camera.yaw_cur", FloatType)
GV.hansState = value("Hans State", "oob_state::shared::flags", SIntType)
GV.jumpPower = value("Jump Power", "jumpPower", FloatType)
GV.hansStateStr = simplevalue("Hans State", HansStateStrValue)
GV.buttonPressed = value("Pressed", "globals.pad0->pressed", UIntType)
GV.buttonReleased = value("Released", "globals.pad0->released", UIntType)
GV.buttonBits = simplevalue("", ButtonValue)
GV.stickX = customvalue("X Stick", "globals.pad0->analog1.x", StickXValue, SByteType)
GV.stickY = customvalue("Y Stick", "globals.pad0->analog1.y", StickYValue, SByteType)
GV.xCStick = customvalue("X C-Stick", "globals.pad0->analog2.x", StickXValue, SByteType)
GV.yCStick = customvalue("Y C-Stick", "globals.pad0->analog2.y", StickYValue, SByteType)
GV.lShoulder = value("L Shoulder", "sPadData[0].triggerLeft", UByteType)
GV.rShoulder = value("R Shoulder", "sPadData[0].triggerRight", UByteType)
GV.xvelRot = simplevalue("", RotatedVelXValue)
GV.zvelRot = simplevalue("", RotatedVelZValue)
GV.hvelLength = simplevalue("Horizontal", HVelLengthValue)
GV.vvelLength = simplevalue("Vertical", VVelLengthValue)
GV.zero = simplevalue("", ZeroValue)
local HVelocityImage = subclass(layoutsModule.StickInputImage)
BFBB.HVelocityImage = HVelocityImage
function HVelocityImage:init(window, game, options)
options = options or {}
options.max = options.max or 15
options.square = options.square or false
layoutsModule.StickInputImage.init(self, window, game.xvelRot, game.zvelRot, options)
end
local VVelocityImage = subclass(layoutsModule.StickInputImage)
BFBB.VVelocityImage = VVelocityImage
function VVelocityImage:init(window, game, options)
options = options or {}
options.max = options.max or 15
options.square = options.square or true
options.sizex = options.sizex or 20
layoutsModule.StickInputImage.init(self, window, game.zero, game.yvel, options)
end
return BFBB