fork/training-mode-ce

git clone https://git.julia.blue/fork/training-mode-ce

AitchMerge pull request #88 from NickCondron/remove-asm2c08d3a

nix
8.2 KiB366 linesraw
1    # To be inserted at 8016e510
2    .include "../Globals.s"
3
4    .set MatchInfo, 31
5    .set SpawnTable, 30
6    .set REG_PlayerSlot, 28
7
8    backup
9
10    # Don't run in singleplayer
11    branchl r12, 0x8016b41c
12    cmpwi r3, 0
13    bne Exit
14    # Don't run for players 5 and 6
15    cmpwi REG_PlayerSlot, 5
16    bge Exit
17
18    # Check if teams
19    lbz r3, 0x24D0(MatchInfo)
20    cmpwi r3, 1
21    beq isTeams
22
23isSingles:
24    # Get this players spawn order
25    .set LoopCount, 26
26    .set SpawnOrder, 25
27    li SpawnOrder, 0
28    li LoopCount, 0
29
30isSingles_Loop:
31    # Load slot type
32    mr r3, LoopCount
33    branchl r12, PlayerBlock_LoadSlotType
34    cmpwi r3, 0x3
35    beq isSingles_IncLoop                           # If =3, no player present
36    # Player is present, check if this is the one were looking for
37    cmpw REG_PlayerSlot, LoopCount
38    beq isSingles_Exit
39    # Increment offset
40    addi SpawnOrder, SpawnOrder, 1
41
42isSingles_IncLoop:
43    addi LoopCount, LoopCount, 1
44    cmpwi LoopCount, 4
45    ble isSingles_Loop
46
47isSingles_Exit:
48    mr r3, REG_PlayerSlot
49    mr r4, SpawnOrder
50    lbz r5, 0x24D0(MatchInfo)
51    bl SetSpawn
52    b Exit
53
54isTeams:
55
56CheckIf2v2:
57    .set REG_TeamID, 26
58    li REG_TeamID, 0
59
60CheckIf2v2_Loop:
61
62# Check how many players are on this team
63GetTeamCount:
64    .set REG_Count, 25
65    .set REG_TeamMembers, 24
66    li REG_TeamMembers, 0
67    li REG_Count, 0
68
69GetTeamCount_Loop:
70    # Load slot type
71    mr r3, REG_Count
72    branchl r12, PlayerBlock_LoadSlotType
73    cmpwi r3, 0x3
74    beq GetTeamCount_IncLoop                        # If =3, no player present
75    # Get Team
76    mr r3, REG_Count
77    branchl r12, 0x80033370
78    cmpw r3, REG_TeamID
79    bne GetTeamCount_IncLoop
80    # Increment team members
81    addi REG_TeamMembers, REG_TeamMembers, 1
82
83GetTeamCount_IncLoop:
84    addi REG_Count, REG_Count, 1
85    cmpwi REG_Count, 4
86    blt GetTeamCount_Loop
87    # If =1 or >2, exit
88    cmpwi REG_TeamMembers, 1
89    beq Exit
90    cmpwi REG_TeamMembers, 2
91    bgt Exit
92
93CheckIf2v2_IncLoop:
94    addi REG_TeamID, REG_TeamID, 1
95    cmpwi REG_TeamID, 3
96    blt CheckIf2v2_Loop
97
98# Create an array
99CreateTeamArray:
100    .set REG_TeamID, 25
101    .set REG_TeamArray, 26
102    .set REG_ArraySize, 24
103    li REG_TeamID, 0
104    addi REG_TeamArray, sp, 0x80
105    li REG_ArraySize, 0
106
107CreateTeamArray_Loop:
108
109# Check how many players are on this team
110CheckTeam:
111    .set REG_Count, 23
112    .set REG_TeamMembers, 22
113    li REG_TeamMembers, 0
114    li REG_Count, 0
115
116CheckTeam_Loop:
117    # Load slot type
118    mr r3, REG_Count
119    branchl r12, PlayerBlock_LoadSlotType
120    cmpwi r3, 0x3
121    beq CheckTeam_IncLoop                           # If =3, no player present
122    # Get Team
123    mr r3, REG_Count
124    branchl r12, 0x80033370
125    cmpw r3, REG_TeamID
126    bne CheckTeam_IncLoop
127    # Add to array
128    stbx REG_Count, REG_ArraySize, REG_TeamArray
129    addi REG_ArraySize, REG_ArraySize, 1
130
131CheckTeam_IncLoop:
132    addi REG_Count, REG_Count, 1
133    cmpwi REG_Count, 4
134    blt CheckTeam_Loop
135
136CreateTeamArray_IncLoop:
137    addi REG_TeamID, REG_TeamID, 1
138    cmpwi REG_TeamID, 3
139    blt CreateTeamArray_Loop
140
141# Now search for this players ID
142SearchForPlayerID:
143    .set REG_Count, 25
144    li REG_Count, 0
145
146SearchForPlayerID_Loop:
147    lbzx r3, REG_Count, REG_TeamArray
148    cmpw r3, REG_PlayerSlot
149    beq SearchForPlayerID_Exit
150
151SearchForPlayerID_IncLoop:
152    addi REG_Count, REG_Count, 1
153    cmpwi REG_Count, 4
154    blt SearchForPlayerID_Loop
155
156SearchForPlayerID_Exit:
157    mr r3, REG_PlayerSlot
158    mr r4, REG_Count
159    lbz r5, 0x24D0(MatchInfo)
160    bl SetSpawn
161    b Exit
162
163SetSpawn:
164    .set REG_PlayerSlot, 31
165    .set REG_SpawnID, 30
166    .set REG_IsTeams, 29
167    .set REG_SpawnTable, 28
168
169    # Init
170    backup
171    mr REG_PlayerSlot, r3
172    mr REG_SpawnID, r4
173    mr REG_IsTeams, r5
174
175    # Get Neutral Spawn Table
176    bl NeutralSpawnTable
177    mflr REG_SpawnTable
178
179    # Get stage ID
180    lwz r6, -0x6CB8(r13)
181    li r5, 0
182
183# Get stage's spawn info
184SetSpawn_StageSearchLoop:
185    lwz r3, StageID(REG_SpawnTable)                 # get stage ID
186    cmpwi r3, -1                                    # check for end of table
187    beq SetSpawn_NotFound
188    cmpw r3, r6                                     # check for matching stage ID
189    beq SetSpawn_FoundStage
190    addi REG_SpawnTable, REG_SpawnTable, EntryLength
191    b SetSpawn_StageSearchLoop
192
193SetSpawn_FoundStage:
194    # Get Players Spawn Point and Facing Direction Pointer
195    addi REG_SpawnTable, REG_SpawnTable, SpawnData  # Skip past stage ID
196    mulli r3, REG_IsTeams, SpawnDataLength
197    add REG_SpawnTable, REG_SpawnTable, r3          # Get to teams/singles data
198    mulli r3, REG_SpawnID, SpawnDataLengthPerPlayer # Get to this players data
199    add REG_SpawnTable, REG_SpawnTable, r3
200
201    # Set players new spawn coordinates
202    addi r4, sp, 0x80
203    lfs f1, SpawnX(REG_SpawnTable)
204    stfs f1, 0x0(r4)
205    lfs f1, SpawnY(REG_SpawnTable)
206    stfs f1, 0x4(r4)
207    li r3, 0
208    stw r3, 0x8(r4)
209    mr r3, REG_PlayerSlot
210    branchl r12, 0x80032768
211    b SetSpawn_UpdateFacingDirection
212
213SetSpawn_NotFound:
214    # If singles, use spawn order
215    cmpwi REG_IsTeams, 1
216    beq SetSpawn_NotFound_Teams
217    mr r3, REG_SpawnID
218    b SetSpawn_NotFound_UpdatePosition
219
220SetSpawn_NotFound_Teams:
221    bl NeutralSpawnTable_NotFound
222    mflr r3
223    lbzx r3, r3, REG_SpawnID
224    b SetSpawn_NotFound_UpdatePosition
225
226SetSpawn_NotFound_UpdatePosition:
227    # Get XYZ from spawn ID
228    addi r4, sp, 0x80
229    branchl r12, 0x80224e64
230    # Set new XYZ spawn
231    mr r3, REG_PlayerSlot
232    addi r4, sp, 0x80
233    branchl r12, 0x80032768
234    b SetSpawn_UpdateFacingDirection
235
236SetSpawn_UpdateFacingDirection:
237    # Load X Position
238    mr r3, REG_PlayerSlot
239    addi r4, sp, 0x80
240    branchl r12, 0x800326cc
241    lfs f1, 0x80(sp)
242    # Compare to 0
243    lfs f0, -0x5718(rtoc)
244    fcmpo cr0, f1, f0
245    ble SetSpawn_UpdateFacingDirection_FacingRight
246
247SetSpawn_UpdateFacingDirection_FacingLeft:
248    lfs f1, -0x5708(rtoc)
249    b SetSpawn_UpdateFacingDirection_Store
250
251SetSpawn_UpdateFacingDirection_FacingRight:
252    lfs f1, -0x5734(rtoc)
253
254SetSpawn_UpdateFacingDirection_Store:
255    # Update Facing Direction
256    mr r3, REG_PlayerSlot
257    branchl r12, 0x80033094
258
259SetSpawn_AdjustEntryFrames:
260    mr r3, REG_PlayerSlot
261    mulli r4, REG_SpawnID, 5
262    branchl r12, 0x80035fdc
263
264SetSpawn_Exit:
265    restore
266    blr
267
268######################
269NeutralSpawnTable:
270    blrl
271    .set EntryLength, 0x4 + SpawnDataLength * 2
272    .set SpawnDataLength, 0x8 *4
273    .set SpawnDataLengthPerPlayer, 0x8
274
275    .set StageID, 0x0
276    .set SpawnData, 0x4
277    .set SpawnX, 0x0
278    .set SpawnY, 0x4
279
280    # FD
281    .long 0x20                                      # Stage ID
282    # Singles Data
283    .float -60, 10
284    .float 60, 10
285    .float -20, 10
286    .float 20, 10
287    # Teams Data
288    .float -20, 10
289    .float -60, 10
290    .float 20, 10
291    .float 60, 10
292    # Battlefield
293    .long 0x1F                                      # Stage ID
294    # Singles Data
295    .float -38.8, 35.2
296    .float 38.8, 35.2
297    .float 0, 8
298    .float 0, 62.4
299    # Teams Data
300    .float -38.8, 35.2
301    .float -38.8, 5
302    .float 38.8, 35.2
303    .float 38.8, 5
304    # Yoshi's Story
305    .long 0x08                                      # Stage ID
306    # Singles Data
307    .float -42, 26.6
308    .float 42, 28
309    .float 0, 46.9
310    .float 0, 4.9
311    # Teams Data
312    .float -42, 26.6
313    .float -42, 5
314    .float 42, 28
315    .float 42, 5
316    # Dream Land
317    .long 0x1C                                      # Stage ID
318    # Singles Data
319    .float -46.6, 37.2
320    .float 47.4, 37.3
321    .float 0, 7
322    .float 0, 58.5
323    # Teams Data
324    .float -46.6, 37.2
325    .float -46.6, 5
326    .float 47.4, 37.3
327    .float 47.4, 5
328    # FoD
329    .long 0x02                                      # Stage ID
330    # Singles Data
331    .float -41.25, 21
332    .float 41.25, 27
333    .float 0, 5.25
334    .float 0, 48
335    # Teams Data
336    .float -41.25, 21
337    .float -41.25, 5
338    .float 41.25, 27
339    .float 41.25, 5
340    # Pokemon Stadium
341    .long 0x03                                      # Stage ID
342    # Singles Data
343    .float -40, 32
344    .float 40, 32
345    .float 70, 7
346    .float -70, 7
347    # Teams Data
348    .float -40, 32
349    .float -40, 5
350    .float 40, 32
351    .float 40, 5
352    # Terminator
353    .long -1
354    .align 2
355
356NeutralSpawnTable_NotFound:
357    blrl
358    # Doubles
359    .long 0x00030102
360    .align 2
361
362######################
363
364Exit:
365    restore
366    lbz r0, 0x24D0(r31)