RidersPyTools 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,354 @@
1
+ """
2
+ CLASS SCHEMA FOR PLAYER
3
+ """
4
+
5
+ from enum import IntEnum, IntFlag
6
+
7
+ import dolphin_memory_engine as DME
8
+ from .include.Controller import Controller
9
+ from .include.GenericData import GenericData
10
+ from .include.GearStats import GearStats
11
+ from .include.Constants import *
12
+ from .GameState import GAME_VERSION
13
+
14
+ INIT_STATE = True
15
+
16
+ # Rename to TypeSkill for clarity? Unsure.
17
+ class Type(IntFlag):
18
+ noType = 0,
19
+ Speed = 1 << 0,
20
+ Fly = 1 << 1,
21
+ Power = 1 << 2,
22
+ All = Speed | Fly | Power
23
+
24
+ class TrickRanks(IntEnum):
25
+ CRank = 0,
26
+ BRank = 1,
27
+ ARank = 2,
28
+ APlusRank = 3,
29
+ SRank = 4,
30
+ SPlusRank = 5,
31
+ XRank = 6,
32
+ TenPlus = 7
33
+
34
+ class MovementFlags(IntFlag):
35
+ none = 0,
36
+ drifting = 1 << 14,
37
+ boosting = 1 << 10,
38
+ jumpCharge = 1 << 12,
39
+ railLink = 1 << 16,
40
+ braking = 1 << 8,
41
+ TurbulenceLRExit = 1 << 18,
42
+ noBoostChain = 1 << 13
43
+
44
+ class PlayerState(IntEnum):
45
+ QTE = 0x0,
46
+ StartLine = 0x1,
47
+ Unknown = 0x2,
48
+ Death = 0x3,
49
+ Retire = 0x4,
50
+ Cruise = 0x5,
51
+ Jump = 0x6,
52
+ Fall = 0x7,
53
+ FrontflipRamp = 0x8,
54
+ BackflipRamp = 0x9,
55
+ UnknownTrick = 0xA,
56
+ HalfPipeTrick = 0xB,
57
+ ManualRamp = 0xC,
58
+ TurbulenceTrick = 0xD,
59
+ TurbulenceTrick2 = 0xE,
60
+ PlayerCollide = 0xF,
61
+ TurbulenceRide = 0x10,
62
+ QTE2 = 0x11,
63
+ RailGrind = 0x12,
64
+ Fly = 0x13,
65
+ AttackingPlayer = 0x15,
66
+ AttackedByPlayer = 0x16,
67
+ Stun = 0x17,
68
+ Unk1 = 0x18,
69
+ Run = 0x19,
70
+ StartLineShock = 0x1A,
71
+ Unknown2 = 0x1B,
72
+
73
+ class Player:
74
+ def __getattr__(self, name):
75
+ global INIT_STATE
76
+
77
+ if INIT_STATE:
78
+ return None
79
+
80
+ # This gets our types and offsets (users cannot get these, they are protected from frontend).
81
+ type_to_read = vars(self.__getattribute__(name))["_datatype"]
82
+ offset_to_read = vars(self.__getattribute__(name))["_offset"]
83
+
84
+ # Check our types, read from game, return value if found
85
+ if 'READ_FROM_DME' in name:
86
+ try:
87
+ value_read = None
88
+ if type_to_read == u8 or type_to_read == s8 or type_to_read == Bool:
89
+ value_read = DME.read_byte(offset_to_read)
90
+ if type_to_read == u16 or type_to_read == s16:
91
+ value_read = DME.read_byte(offset_to_read)
92
+ if type_to_read == u32 or type_to_read == s32 or type_to_read == vu32:
93
+ value_read = DME.read_word(offset_to_read)
94
+ if type_to_read == f32:
95
+ value_read = DME.read_float(offset_to_read)
96
+ if value_read is None:
97
+ # No types were valid, read bytes instead
98
+ value_read = DME.read_bytes(offset_to_read, type_to_read)
99
+ return value_read
100
+ except RuntimeError as e:
101
+ print("RuntimeError: DME is " + str(e) + ". Failed to return value.")
102
+ return vars(self.__getattribute__(name))
103
+ def __setattr__(self, name, value):
104
+ global INIT_STATE
105
+
106
+ # On startup, this allows everything to be assigned to the player object.
107
+ # We NEED this for init ONLY.
108
+ # Once every struct variable is done, SET INIT_STATE = False.
109
+ # Once that is done, this will retrieve data from DME instead of setting the attribute's value.
110
+ if INIT_STATE:
111
+ super().__setattr__(name, value)
112
+ return
113
+ # Use this function for GenericData value assignment that isn't setting equal to a new object instance (that's handled in their own classes)
114
+
115
+ # This gets our types and offsets (users cannot get these, they are protected from frontend).
116
+ # check_DME_value = vars(self.__getattribute__(name))
117
+ type_to_write = vars(self.__getattribute__(name))["_datatype"]
118
+ offset_to_write = vars(self.__getattribute__(name))["_offset"]
119
+
120
+ # Check our types, read from game, return value if found
121
+ try:
122
+ if type_to_write == u8 or type_to_write == s8 or type_to_write == Bool:
123
+ DME.write_byte(offset_to_write, value)
124
+ if type_to_write == u16 or type_to_write == s16:
125
+ DME.write_byte(offset_to_write, value)
126
+ if type_to_write == u32 or type_to_write == s32 or type_to_write == vu32:
127
+ DME.write_word(offset_to_write, value)
128
+ if type_to_write == f32:
129
+ DME.write_float(offset_to_write, value)
130
+ except RuntimeError as e:
131
+ print("RuntimeError: DME is " + str(e) + ". Failed to write new value.")
132
+ return
133
+ def __init__(self, playerNum, playerPtr=None):
134
+ global INIT_STATE
135
+ INIT_STATE = True
136
+ # TODO: If TE, use the map file instead of this for ptr
137
+ # If a player pointer is passed in, use that instead and skip the match.
138
+ # This is especially helpful for when TE builds change pointers and the ptr hasn't been updated in the constants yet.
139
+ if playerPtr:
140
+ self.playerPtr = playerPtr + (0x1080 * playerNum)
141
+ else:
142
+ match GAME_VERSION:
143
+ # Vanilla based IDs for vanilla, DX, FT
144
+ case GameIDs.SONIC_RIDERS_ID:
145
+ self.playerPtr = VANILLA_PLAYER_PTR + (0x1080 * playerNum)
146
+ case GameIDs.SONIC_RIDERS_DX_ID:
147
+ self.playerPtr = VANILLA_PLAYER_PTR + (0x1080 * playerNum)
148
+ case GameIDs.SONIC_RIDERS_FT_ID:
149
+ self.playerPtr = VANILLA_PLAYER_PTR + (0x1080 * playerNum)
150
+
151
+ # TE is special, as the game is a shiftable dol.
152
+ # I'd suggest using the map file to figure out what this is supposed to be,
153
+ # Or having a user enter it manually if no map is passed in.
154
+ case GameIDs.SONIC_RIDERS_TE_ID:
155
+ self.playerPtr = TE_PLAYER_PTR + (0x1080 * playerNum)
156
+
157
+ # ZG has dynamic player ptrs, this is not very reliable as of now.
158
+ case GameIDs.SONIC_RIDERS_ZG_ID:
159
+ self.playerPtr = ZG_PLAYER_PTR + (0x1120 * playerNum)
160
+ case _:
161
+ pass
162
+ pass
163
+ # Inputs are always defined on game load, at least for P1.
164
+ # The input ptr is always at the start of the playerPtr struct, so just read word from here and pass the struct ID
165
+ ptr_start_addr = self.playerPtr
166
+
167
+ # Go to pointer for controls, starts at offset 0
168
+ self.input = Controller(DME.follow_pointers(ptr_start_addr, [0]), ptr)
169
+ self.tornadoInvulnerabilityTimer = GenericData(ptr_start_addr + 0x4, u8)
170
+ self.ignoreTurbulence = GenericData(ptr_start_addr + 0x8, Bool)
171
+
172
+ self.character = GenericData(ptr_start_addr + 0xBA, u8)
173
+ self.extremeGear = GenericData(ptr_start_addr + 0xBB, u8)
174
+ self.aiControl = GenericData(ptr_start_addr + 0xBC, Bool)
175
+ self.playerType = GenericData(ptr_start_addr + 0xBD, Bool)
176
+ self.gearType = GenericData(ptr_start_addr + 0xBE, u8)
177
+ self.attributes = GenericData(ptr_start_addr + 0xBF, u8)
178
+ self.current_itemID = GenericData(ptr_start_addr + 0xF4, u32)
179
+ self.tornadoIgnore_invincibilityTimer = GenericData(ptr_start_addr + 0xF8, u8)
180
+ self.characterVoiceID = GenericData(ptr_start_addr + 0xFA, u16)
181
+ # self.currentCollision = GenericData(DME.follow_pointers(ptr_start_addr, [0]), ptr) // Needs collision class.
182
+ self.gearSpecificFlags = GenericData(ptr_start_addr + 0x100, u32) # Bitset for level 4.
183
+ self.maxJump = GenericData(ptr_start_addr + 0x104, u8)
184
+ self.midJump = GenericData(ptr_start_addr + 0x105, u8)
185
+ self.badJump = GenericData(ptr_start_addr + 0x106, u8)
186
+ self.absoluteMaxJump = GenericData(ptr_start_addr + 0x107, u8)
187
+ self.last_itemID_lap = GenericData(ptr_start_addr + 0x108, u8)
188
+ self.trickCount = GenericData(ptr_start_addr + 0x109, u8)
189
+ self.last_itemID = GenericData(ptr_start_addr + 0x10C, u32)
190
+ self.last_itemBox_random = GenericData(ptr_start_addr + 0x110, Bool)
191
+ self.last_level4 = GenericData(ptr_start_addr + 0x111, Bool)
192
+ self.rainbowTrailState = GenericData(ptr_start_addr + 0x112, Bool)
193
+ self.dreamTrail_timer = GenericData(ptr_start_addr + 0x113, u8)
194
+ self.exhaustTrailColor = GenericData(ptr_start_addr + 0x114, u32) # Uses RGBA class
195
+ self.berserkerCooldown = GenericData(ptr_start_addr + 0x118, u8) # Uses RGBA class
196
+
197
+ # State unions (same addresses, different names)
198
+ self.coverF_archetype = GenericData(ptr_start_addr + 0x11A, u8)
199
+ self.superFormState = GenericData(ptr_start_addr + 0x11A, u8)
200
+ self.coverP_weightState = GenericData(ptr_start_addr + 0x11A, u8)
201
+
202
+ self.slipstream = GenericData(ptr_start_addr + 0x11B, Bool)
203
+ self.magneticImpulse_timer = GenericData(ptr_start_addr + 0x11C, f32)
204
+ self.turningSpeedLoss = GenericData(ptr_start_addr + 0x120, f32)
205
+ self.x = GenericData(ptr_start_addr + 0x1E4, f32)
206
+ self.y = GenericData(ptr_start_addr + 0x1E8, f32)
207
+ self.z = GenericData(ptr_start_addr + 0x1EC, f32)
208
+ self.verticalRotation = GenericData(ptr_start_addr + 0x1F0, f32)
209
+ self.horizontalRotation = GenericData(ptr_start_addr + 0x1F4, f32)
210
+ self.rotationRoll = GenericData(ptr_start_addr + 0x1F8, f32)
211
+
212
+ self.xDifferenceFromNextPlayer = GenericData(ptr_start_addr + 0x340, f32)
213
+ self.yDifferenceFromNextPlayer = GenericData(ptr_start_addr + 0x344, f32)
214
+ self.zDifferenceFromNextPlayer = GenericData(ptr_start_addr + 0x348, f32)
215
+
216
+ # Uses Vector3F (X float, y float, z float)
217
+ # Replace with class instance later rather than array.
218
+ self.forward = [GenericData(ptr_start_addr + 0x358, f32), GenericData(ptr_start_addr + 0x35C, f32), GenericData(ptr_start_addr + 0x360, f32)]
219
+
220
+ self.currPathFindingPoint = GenericData(ptr_start_addr + 0x5E6, u16)
221
+ self.prevPathFindingPoint = GenericData(ptr_start_addr + 0x5E8, u16)
222
+
223
+ self.railState = GenericData(ptr_start_addr + 0x624, u16)
224
+ self.railPart = GenericData(ptr_start_addr + 0x626, u16)
225
+ self.railID = GenericData(ptr_start_addr + 0x628, u16)
226
+ self.collisionProperties = GenericData(ptr_start_addr + 0x6C0, u16) # Has IDs. Add later.
227
+ self.railID = GenericData(ptr_start_addr + 0x6C4, u16)
228
+ self.turbulenceState = GenericData(ptr_start_addr + 0x6C8, u16)
229
+
230
+ self.lastAnimationID = GenericData(ptr_start_addr + 0x764, u32)
231
+ self.currentAnimationID = GenericData(ptr_start_addr + 0x764, u32)
232
+ self.animationFlags = GenericData(ptr_start_addr + 0x764, u32) # Has its own flag class, add later.
233
+ self.currentAnimationFrame = GenericData(ptr_start_addr + 0x770, f32)
234
+ self.animationSpeed = GenericData(ptr_start_addr + 0x784, f32)
235
+
236
+ # Timer union
237
+ self.fastest_timer = GenericData(ptr_start_addr + 0x87C, u32)
238
+ self.superTails_transformCooldown = GenericData(ptr_start_addr + 0x87C, u32)
239
+ self.hyperSonic_totalLinkTimer = GenericData(ptr_start_addr + 0x87C, u32)
240
+ self.SuperMetalFrameCounter = GenericData(ptr_start_addr + 0x87C, u32)
241
+
242
+ self.boostDuration = GenericData(ptr_start_addr + 0x8AC, s32)
243
+ self.lightBoard_flag = GenericData(ptr_start_addr + 0x8C0, u32)
244
+
245
+ # GearStats[3] -> index per level
246
+ self.gearStats = [GearStats(ptr_start_addr + 0x8DC, u32), GearStats(ptr_start_addr + 0x914, u32), GearStats(ptr_start_addr + 0x94C, u32)]
247
+ self.currentAir = GenericData(ptr_start_addr + 0x984, u32)
248
+ self.changeInAir_gain = GenericData(ptr_start_addr + 0x988, u32)
249
+ self.changeInAir_loss = GenericData(ptr_start_addr + 0x98C, u32)
250
+ self.weight = GenericData(ptr_start_addr + 0x994, f32)
251
+ self.requiredDriftDashFrames = GenericData(ptr_start_addr + 0x9C4, s32)
252
+ self.trickAirGainMultiplier = GenericData(ptr_start_addr + 0x9C8, f32)
253
+ self.shortcutAirGainMultiplier = GenericData(ptr_start_addr + 0x9CC, f32)
254
+ self.QTEAirGainMultiplier = GenericData(ptr_start_addr + 0x9D0, f32)
255
+ self.specialFlags = GenericData(ptr_start_addr + 0x9D4, u32) # Uses SpecialFlags enum
256
+ self.trickSpeed = GenericData(ptr_start_addr + 0x9E0, u32)
257
+ self.trickDirection = GenericData(ptr_start_addr + 0x9E8, u32)
258
+ self.jumpCharge = GenericData(ptr_start_addr + 0x9F4, u16)
259
+ self.startingTrick = GenericData(ptr_start_addr + 0x9F8, u8)
260
+ self.rampType = GenericData(ptr_start_addr + 0x9F9, u8)
261
+ self.trickTrajectory = GenericData(ptr_start_addr + 0x9FE, u8)
262
+ self.trickRank = GenericData(ptr_start_addr + 0x9FF, u8) # Uses trick rank enum
263
+ self.trickFail = GenericData(ptr_start_addr + 0xA03, u8)
264
+
265
+ self.movementFlags = GenericData(ptr_start_addr + 0xA28, u32) # Uses movement flags enum
266
+ self.last_movementFlags = GenericData(ptr_start_addr + 0xA2C, u32)
267
+
268
+ self.characterptr = GenericData(ptr_start_addr + 0xA40, u32) # Uses character ptr class
269
+ self.gearptr = GenericData(ptr_start_addr + 0xA44, u32) # Uses gear ptr class
270
+
271
+ self.verticalSpeed = GenericData(ptr_start_addr + 0xAA4, f32)
272
+ self.generalSpeedLoss = GenericData(ptr_start_addr + 0xAA8, f32)
273
+ self.speed = GenericData(ptr_start_addr + 0xAAC, f32)
274
+ self.maxSpeedPercentage = GenericData(ptr_start_addr + 0xAB0, f32)
275
+ self.speedCap = GenericData(ptr_start_addr + 0xAB4, f32)
276
+ self.minSpeedCap = GenericData(ptr_start_addr + 0xAB8, f32)
277
+
278
+ # Float distance from other players, 8 entries total.
279
+ self.otherPlayerDistance = [GenericData(ptr_start_addr + x, f32) for x in range (0xAD4, 0xAF0, 0x4)]
280
+
281
+ self.speedAsInt = GenericData(ptr_start_addr + 0xABC, u32)
282
+
283
+ self.driftDirection = GenericData(ptr_start_addr + 0xB4C, f32)
284
+ self.driftDashFrames = GenericData(ptr_start_addr + 0xB54, s32)
285
+ self.boostingAnimationID = GenericData(ptr_start_addr + 0xB7C, u32)
286
+
287
+ # List of laps and their times in centiseconds, up to 99 laps
288
+ self.lapTimeList = [GenericData(ptr_start_addr + x, u32) for x in range(0xBF4, 0xD7C, 0x4)]
289
+
290
+ self.rings = GenericData(ptr_start_addr + 0xB98, u32)
291
+
292
+ # Add flags for this class
293
+ self.playerDisplayFlags = GenericData(ptr_start_addr + 0xBA8, u32)
294
+
295
+ self.statusEffectFlags = GenericData(ptr_start_addr + 0xBA8, u32)
296
+
297
+ self.stageProgress = GenericData(ptr_start_addr + 0xBC4, f32)
298
+
299
+ # Uses type enum
300
+ self.typeAttributes = GenericData(ptr_start_addr + 0xBD3, u8)
301
+
302
+ # Last recorded lap as an int, in centiseconds.
303
+ self.lastSplitLapTime = GenericData(ptr_start_addr + 0xD80, u32)
304
+
305
+ self.closestTurbulenceIndex = GenericData(ptr_start_addr + 0xE90, u32)
306
+
307
+ # Ptrs to attacking/who's attacked.
308
+ # Needs their own structs.
309
+ # self.attackedPlayer = GenericData(ptr_start_addr + 0xF38, u32)
310
+ # self.attackingPlayer = GenericData(ptr_start_addr + 0xF3C, u32)
311
+ # self.attackProperties = GenericData(ptr_start_addr + 0xF40, u32)
312
+
313
+ # This is an array of bytes:
314
+ # 1st byte = ms, 2nd byte = sec, 3rd byte = min
315
+ self.raceFinishTime = [GenericData(ptr_start_addr + 0xFF4, u8), GenericData(ptr_start_addr + 0xFF5, u8), GenericData(ptr_start_addr + 0xFF6, u8)]
316
+ # Note: on lap being completed, this resets to zero in-game.
317
+ self.lapElapsedTime = [GenericData(ptr_start_addr + 0xFF8, u8), GenericData(ptr_start_addr + 0xFF9, u8), GenericData(ptr_start_addr + 0xFFA, u8)]
318
+
319
+ self.reciproExtendTimer = GenericData(ptr_start_addr + 0x101A, u16)
320
+ self.death_spawnPoint = GenericData(ptr_start_addr + 0x101E, u16)
321
+ self.currentLap = GenericData(ptr_start_addr + 0x102A, u8)
322
+ self.previousLap = GenericData(ptr_start_addr + 0x102B, u8)
323
+ self.placement_counter = GenericData(ptr_start_addr + 0x102C, u8)
324
+ self.placement = GenericData(ptr_start_addr + 0x102D, u8)
325
+ self.level = GenericData(ptr_start_addr + 0x102E, u8)
326
+ self.subState = GenericData(ptr_start_addr + 0x102F, u8)
327
+ self.state = GenericData(ptr_start_addr + 0x1034, u8)
328
+ self.previousState = GenericData(ptr_start_addr + 0x1035, u8)
329
+ self.turbulenceTrickType = GenericData(ptr_start_addr + 0x1042, u8) # Uses trick enum
330
+ self.qteState = GenericData(ptr_start_addr + 0x1043, u8)
331
+ self.unk1044 = GenericData(ptr_start_addr + 0x1044, u8)
332
+ self.stage_subState = GenericData(ptr_start_addr + 0x1048, u8)
333
+ self.greenCave_subState = GenericData(ptr_start_addr + 0x105C, u8)
334
+ self.y_toggle = GenericData(ptr_start_addr + 0x1068, u8)
335
+ self.grindRailDash = GenericData(ptr_start_addr + 0x106A, u8)
336
+ self.flyHoopDash = GenericData(ptr_start_addr + 0x106B, u8)
337
+ self.splashCanyonFlyRoute = GenericData(ptr_start_addr + 0x106C, Bool)
338
+ self.airBroomParticles = GenericData(ptr_start_addr + 0x106D, Bool)
339
+ self.specialReciproExtend = GenericData(ptr_start_addr + 0x106E, Bool)
340
+ self.magneticImpulse_soundStatus = GenericData(ptr_start_addr + 0x1079, u8)
341
+
342
+ # TE SPECIFIC, all other builds check "archetype" with character checks instead
343
+ self.characterArchetype = GenericData(ptr_start_addr + 0x107C, u8)
344
+
345
+ # Extra union
346
+ self.fastest_superCruise = GenericData(ptr_start_addr + 0x107E, Bool)
347
+ self.stardustspeederII_1frameboost = GenericData(ptr_start_addr + 0x107E, Bool)
348
+
349
+ # TE SPECIFIC
350
+ self.canBeAttacked = GenericData(ptr_start_addr + 0x107F, Bool)
351
+
352
+
353
+ # DO NOT TOUCH, REQUIRED FOR INIT/RUNTIME TO WORK
354
+ INIT_STATE = False
@@ -0,0 +1,125 @@
1
+ """
2
+ Contains all memory addresses from map/vanilla addresses fallback
3
+ """
4
+
5
+ import dolphin_memory_engine as DME
6
+ from .include.GenericData import GenericData
7
+ from .include.GearStats import GearStats
8
+ from .include.Constants import *
9
+ from .GameState import GAME_VERSION, RACESTATE_ID_TO_NAME, ALL_RACESTATES, RaceState
10
+ from .Player import Player
11
+
12
+ INIT_STATE = True
13
+
14
+ # Note: these are vanilla addresses as default
15
+ default_general_addresses = {
16
+ "gameID": 0x80000000,
17
+ "CurrentGameMode": 0x806129A0,
18
+ "geGame_ModeDetail": 0x806129A4,
19
+ "CurrentStage": 0x806129A8,
20
+ "ExitMethod": 0x806129C0,
21
+ "StageTimer": 0x80612B40,
22
+ "playerPtrStartAddr": VANILLA_PLAYER_PTR
23
+ }
24
+
25
+ class RidersObject:
26
+ def __getattr__(self, name):
27
+ global INIT_STATE
28
+
29
+ if INIT_STATE:
30
+ return None
31
+
32
+ # This gets our types and offsets (users cannot get these, they are protected from frontend).
33
+ type_to_read = vars(self.__getattribute__(name))["_datatype"]
34
+ offset_to_read = vars(self.__getattribute__(name))["_offset"]
35
+
36
+ # Check our types, read from game, return value if found
37
+ if 'READ_FROM_DME' in name:
38
+ try:
39
+ value_read = None
40
+ if type_to_read == u8 or type_to_read == s8 or type_to_read == Bool:
41
+ value_read = DME.read_byte(offset_to_read)
42
+ if type_to_read == u16 or type_to_read == s16:
43
+ value_read = DME.read_byte(offset_to_read)
44
+ if type_to_read == u32 or type_to_read == s32 or type_to_read == vu32:
45
+ value_read = DME.read_word(offset_to_read)
46
+ if type_to_read == f32:
47
+ value_read = DME.read_float(offset_to_read)
48
+ if value_read is None:
49
+ # No types were valid, read bytes instead
50
+ value_read = DME.read_bytes(offset_to_read, type_to_read)
51
+ return value_read
52
+ except RuntimeError as e:
53
+ print("RuntimeError: DME is " + str(e) + ". Failed to return value.")
54
+ return vars(self.__getattribute__(name))
55
+ def __setattr__(self, name, value):
56
+ global INIT_STATE
57
+
58
+ # On startup, this allows everything to be assigned to the player object.
59
+ # We NEED this for init ONLY.
60
+ # Once every struct variable is done, SET INIT_STATE = False.
61
+ # Once that is done, this will retrieve data from DME instead of setting the attribute's value.
62
+ if INIT_STATE:
63
+ super().__setattr__(name, value)
64
+ return
65
+ # Use this function for GenericData value assignment that isn't setting equal to a new object instance (that's handled in their own classes)
66
+
67
+ # This gets our types and offsets (users cannot get these, they are protected from frontend).
68
+ # check_DME_value = vars(self.__getattribute__(name))
69
+ type_to_write = vars(self.__getattribute__(name))["_datatype"]
70
+ offset_to_write = vars(self.__getattribute__(name))["_offset"]
71
+
72
+ # Check our types, read from game, return value if found
73
+ try:
74
+ if type_to_write == u8 or type_to_write == s8 or type_to_write == Bool:
75
+ DME.write_byte(offset_to_write, value)
76
+ if type_to_write == u16 or type_to_write == s16:
77
+ DME.write_byte(offset_to_write, value)
78
+ if type_to_write == u32 or type_to_write == s32 or type_to_write == vu32:
79
+ DME.write_word(offset_to_write, value)
80
+ if type_to_write == f32:
81
+ DME.write_float(offset_to_write, value)
82
+ except RuntimeError as e:
83
+ print("RuntimeError: DME is " + str(e) + ". Failed to write new value.")
84
+ return
85
+ def __init__(self, replacement_values: dict = None):
86
+ global INIT_STATE
87
+ INIT_STATE = True
88
+ # Find a way to define literally EVERY SYMBOL here.
89
+ # Not easy, but most are defined. Some are custom with pointers and structs. Good luck.
90
+
91
+ # This is a hack that allows me to change where the addresses are.
92
+ # This makes it easier to find while we're testing TE.
93
+ # If no address found, use vanilla.
94
+ # If you want this for TE, send in stageTimerAddr 0x8053C480
95
+ # TE 2.4.6.1 currentStageAddr 0x8053C2E8
96
+
97
+ addresses_to_use = default_general_addresses | replacement_values
98
+
99
+ # This is 6 bytes long.
100
+ self.gameID = GenericData(addresses_to_use["gameID"], 0x6)
101
+
102
+ self.currentMode = GenericData(addresses_to_use["CurrentGameMode"], vu32)
103
+ self.gameModeDetail = GenericData(addresses_to_use["geGame_ModeDetail"], vu32)
104
+ self.currentStage = GenericData(addresses_to_use["CurrentStage"], vu32)
105
+ self.exitMethod = GenericData(addresses_to_use["ExitMethod"], u32)
106
+ self.stageTimer = [GenericData(addresses_to_use["StageTimer"], u8),
107
+ GenericData(addresses_to_use["StageTimer"] + 0x1, u8),
108
+ GenericData(addresses_to_use["StageTimer"] + 0x2, u8)]
109
+
110
+ # List of all players 1-4
111
+ self.players = [Player(0 + idx) for idx in range(0,3)]
112
+
113
+ INIT_STATE = False
114
+ pass
115
+
116
+ def get_race_state(self, return_text=False):
117
+ if return_text:
118
+ return RACESTATE_ID_TO_NAME[RaceState(self.gameModeDetail - self.currentMode)]
119
+ return RaceState(self.gameModeDetail - self.currentMode)
120
+
121
+ def get_current_race_time(self):
122
+ minutes = (self.stageTimer[2])
123
+ seconds = (self.stageTimer[1])
124
+ milliseconds = (self.stageTimer[0])
125
+ return "{:02d}:{:02d}:{:02d}".format(minutes, seconds, milliseconds)
@@ -0,0 +1,38 @@
1
+ STAGE_METAL_CITY = 1
2
+ STAGE_SPLASH_CANYON = 2
3
+ STAGE_EGG_FACTORY = 3
4
+ STAGE_GREEN_CAVE = 4
5
+ STAGE_SAND_RUINS = 5
6
+ STAGE_BABYLON_GARDEN = 6
7
+ STAGE_DIGITAL_DIMENSION = 7
8
+ STAGE_SEGA_CARNIVAL = 8
9
+ STAGE_NIGHT_CHASE = 9
10
+ STAGE_RED_CANYON = 10
11
+ STAGE_ICE_FACTORY = 11
12
+ STAGE_WHITE_CAVE = 12
13
+ STAGE_DARK_DESERT = 13
14
+ STAGE_SKY_ROAD = 14
15
+ STAGE_BABYLON_GUARDIAN = 15
16
+ STAGE_SEGA_ILLUSION = 16
17
+
18
+ STAGE_ID_TO_NAME = {
19
+ STAGE_METAL_CITY: "Metal City",
20
+ STAGE_SPLASH_CANYON: "Splash Canyon",
21
+ STAGE_EGG_FACTORY: "Egg Factory",
22
+ STAGE_GREEN_CAVE: "Green Cave",
23
+ STAGE_SAND_RUINS: "Sand Ruins",
24
+ STAGE_BABYLON_GARDEN: "Babylon Garden",
25
+ STAGE_DIGITAL_DIMENSION: "Digital Dimension",
26
+ STAGE_SEGA_CARNIVAL: "SEGA CARNIVAL",
27
+ STAGE_NIGHT_CHASE: "Night Chase",
28
+ STAGE_RED_CANYON: "Red Canyon",
29
+ STAGE_ICE_FACTORY: "Ice Factory",
30
+ STAGE_WHITE_CAVE: "White Cave",
31
+ STAGE_DARK_DESERT: "Dark Desert",
32
+ STAGE_SKY_ROAD: "Sky Road",
33
+ STAGE_BABYLON_GUARDIAN: "Babylon Guardian",
34
+ STAGE_SEGA_ILLUSION: "SEGA ILLUSION"
35
+ }
36
+ ALL_STAGES = list(STAGE_ID_TO_NAME.keys())
37
+ BASE_STAGES = [x for x in ALL_STAGES if x <= STAGE_SEGA_CARNIVAL]
38
+ ALT_STAGES = [x for x in ALL_STAGES if x > STAGE_SEGA_CARNIVAL]
@@ -0,0 +1 @@
1
+ # from . import config
@@ -0,0 +1,35 @@
1
+ # In this file, we hold the settings for whatever the user does.
2
+ # This is particularly important in order to keep a possible main.map as a global variable for reference
3
+
4
+ import MapParser
5
+
6
+ MAIN_MAP_FILE = None # If there is a main.map set before the script, set to true.
7
+ SYMBOL_ACCESS_LEVEL = 0 # levels change, but assume 0 means player ptrs only, while higher values are more elevated access.
8
+
9
+
10
+ """
11
+ If the user sets this, we can set this value to the MainMapFile given.
12
+ Else, just use vanilla ptrs, since only TE as of now changes the mem locs. DX-based builds only allocate more.
13
+ """
14
+ def SetMainMap(pathToMapFile):
15
+ # Run the map parser here so we can store the symbols needed for later in a dictionary.
16
+ MapParser.read_for_files(pathToMapFile)
17
+ # Store symbols in the object listing, somehow.
18
+ global MAIN_MAP_FILE
19
+ MAIN_MAP_FILE = pathToMapFile
20
+ pass
21
+
22
+ """
23
+ The user will not need to set this value unless they're a power user
24
+ 0 = player pointers only. No other values can be modified, only read.
25
+ 1 = player ptrs + player related values. No other values can be modified, only read.
26
+ 2 = Unlimited access. Read/Write has zero restrictions. Users with this active better take care not to do anything crazy.
27
+ """
28
+ def SetSymbolAccessLevel(levelToSet):
29
+ if levelToSet < 0 or levelToSet > 2:
30
+ print("Symbol access level invalid. Please set a number 0-2")
31
+ return
32
+ global SYMBOL_ACCESS_LEVEL
33
+ SYMBOL_ACCESS_LEVEL = levelToSet
34
+ pass
35
+
@@ -0,0 +1,105 @@
1
+ from enum import Enum
2
+ # ID
3
+
4
+ SPEED_DIVISOR = 216.0
5
+ def pSpeed(speed_num: float):
6
+ return speed_num / SPEED_DIVISOR
7
+
8
+ BASE_ID: int = 8770000
9
+
10
+ VANILLA_PLAYER_PTR: int = 0x80609440
11
+
12
+ # NOTE: init player ptr for TE if detected using map file/map file passed in
13
+ TE_PLAYER_PTR: int = 0x80532d80 # change to match the current ptr at time of release. Read main.map using map parser and change in config.py.
14
+ # 2.4.6 fix 1 0x80532d80
15
+
16
+ ZG_PLAYER_PTR: int = 0x804970CC # Player 1, other players may not be sequential. Do more research for this.
17
+
18
+ class GameIDs(Enum):
19
+ SONIC_RIDERS_ID = b'GXEE8P' # Vanilla Game ID
20
+ SONIC_RIDERS_TE_ID = b'GXSRTE' # Tournament Edition ID
21
+ SONIC_RIDERS_DX_ID = b'GXSRDX' # DX ID
22
+ SONIC_RIDERS_ZG_ID = b'SRZE8P' # Zero Gravity ID
23
+ SONIC_RIDERS_FT_ID = b'FUTURE' # Future ID (follow the naming convention guys, c'mon...)
24
+ SONIC_RIDERS_PLUS_ID = b'GXEX8P'
25
+
26
+ GAME_ID_TO_NAME = {
27
+ GameIDs.SONIC_RIDERS_ID: "Sonic Riders",
28
+ GameIDs.SONIC_RIDERS_TE_ID: "Sonic Riders: Tournament Edition",
29
+ GameIDs.SONIC_RIDERS_DX_ID: "Sonic Riders: Director's Cut",
30
+ GameIDs.SONIC_RIDERS_ZG_ID: "Sonic Riders: Zero Gravity",
31
+ GameIDs.SONIC_RIDERS_FT_ID: "Sonic Riders: Future",
32
+ GameIDs.SONIC_RIDERS_PLUS_ID: "Sonic Riders: Plus"
33
+ }
34
+ ALL_GAMES = list(GAME_ID_TO_NAME.keys())
35
+
36
+ # class Sizes(enum):
37
+ # Signed
38
+ type s8 = 1
39
+ type s16 = 2
40
+ type s32 = 4
41
+ type s64 = 8
42
+
43
+ # Unsigned
44
+ type u8 = 1
45
+ type u16 = 2
46
+ type u32 = 4
47
+ type u64 = 8
48
+
49
+ type Bool = 1
50
+
51
+ # Floats
52
+ type f32 = 4
53
+ type f64 = 8
54
+
55
+ # Volatiles (uncommon, some symbols may use this)
56
+ type vs8 = 1
57
+ type vs16 = 2
58
+ type vs32 = 4
59
+
60
+ type vu8 = 1
61
+ type vu16 = 2
62
+ type vu32 = 4
63
+
64
+ type vf32 = 4
65
+ type vf64 = 8
66
+
67
+ # TASK is a void(*)(), so length 4
68
+ type Task = 4
69
+
70
+ # Ptr is... well a pointer, so length 4.
71
+ type ptr = 4
72
+
73
+ # Flag template handler
74
+ # TODO: Add more cases
75
+ # Note: group these? Readability would be so bad...
76
+ def Flag(f_type):
77
+ match f_type:
78
+ case "Buttons":
79
+ # Controller button data
80
+ return u32
81
+ case "Type":
82
+ # Shortcut type
83
+ return u8
84
+ case "SpecialFlags":
85
+ # Bitfield of gearSpecialFlags
86
+ return u32
87
+ case "MovementFlags":
88
+ # Player movement flags during the race, i.e. boosting.
89
+ return u32
90
+ case "PlayerFlags" | "PlayerStatus":
91
+ return u32
92
+ case "AnimationFlags":
93
+ return u32
94
+ case "ObjectVisibility":
95
+ return u32
96
+ case "ParticleCtrl":
97
+ # Particle things
98
+ return u16
99
+ case _:
100
+ return ptr
101
+ pass
102
+
103
+ # fillerData handler
104
+ def fillerData(size):
105
+ return size