Determine Item Rank Position By Distance To First [Gearworks]
#1
I made this experimental code to see how MKW plays with MK8's distance based item rank calculation.

I have noticed that there are some courses with alternate checkpoint paths with item boxes in them that cause the game to think you're further away from first than where you should be, so keep that in mind. (Rainbow Road, Bowser's Castle)

Although this code is primarily meant for offline play, this should work fine online.

NTSC-U is currently the only tested version as I do not have playable access to the other regions.

NTSC-U
Code:
047AC54C 3800000C
047ACA0C 38000000
C27AE924 00000018
7D2802A6 3CE0809C
80E78F70 81070018
89080000 7C081800
4082000C 38600001
48000090 48000031
44BB8000 457A0000
45CB2000 46147000
46435000 4680E800
46A02800 46C35000
46E67800 4706C400
47185800 7CC802A6
3C80809C 80848F28
80840020 C0A40010
80A7000C 5500103A
7C85002E C084000C
EC840172 5460103A
7C85002E C064000C
EC630172 EC441828
38600000 5460103A
38630001 7C26042E
FC020800 4180000C
2C03000C 4180FFE8
7D2803A6 4E800020
60000000 00000000

PAL
Code:
047BAFAC 3800000C
047BB46C 38000000
C27BD384 00000018
7D2802A6 3CE0809C
80E7D730 81070018
89080000 7C081800
4082000C 38600001
48000090 48000031
44BB8000 457A0000
45CB2000 46147000
46435000 4680E800
46A02800 46C35000
46E67800 4706C400
47185800 7CC802A6
3C80809C 8084D6E8
80840020 C0A40010
80A7000C 5500103A
7C85002E C084000C
EC840172 5460103A
7C85002E C064000C
EC630172 EC441828
38600000 5460103A
38630001 7C26042E
FC020800 4180000C
2C03000C 4180FFE8
7D2803A6 4E800020
60000000 00000000

NTSC-J
Code:
047BA618 3800000C
047BAAD8 38000000
C27BC9F0 00000018
7D2802A6 3CE0809C
80E7C790 81070018
89080000 7C081800
4082000C 38600001
48000090 48000031
44BB8000 457A0000
45CB2000 46147000
46435000 4680E800
46A02800 46C35000
46E67800 4706C400
47185800 7CC802A6
3C80809C 8084C748
80840020 C0A40010
80A7000C 5500103A
7C85002E C084000C
EC840172 5460103A
7C85002E C064000C
EC630172 EC441828
38600000 5460103A
38630001 7C26042E
FC020800 4180000C
2C03000C 4180FFE8
7D2803A6 4E800020
60000000 00000000

NTSC-K
Code:
047A936C 3800000C
047A982C 38000000
C27AB744 00000018
7D2802A6 3CE0809B
80E7BD70 81070018
89080000 7C081800
4082000C 38600001
48000090 48000031
44BB8000 457A0000
45CB2000 46147000
46435000 4680E800
46A02800 46C35000
46E67800 4706C400
47185800 7CC802A6
3C80809B 8084BD28
80840020 C0A40010
80A7000C 5500103A
7C85002E C084000C
EC840172 5460103A
7C85002E C064000C
EC630172 EC441828
38600000 5460103A
38630001 7C26042E
FC020800 4180000C
2C03000C 4180FFE8
7D2803A6 4E800020
60000000 00000000

Source
Code:
// Mario Kart Wii Determine Item Rank Position By Distance To First
// Created by Gearworks on 10/11/2023

// Always load and use 12 player item slot table

// NTSC-U
047AC54C 3800000C
047ACA0C 38000000

// PAL
047BAFAC 3800000C
047BB46C 38000000

// NTSC-J
047BA618 3800000C
047BAAD8 38000000

// NTSC-K
047A936C 3800000C
047A982C 38000000

// Main code

Hook Address: 807AE924 NTSC-U
              807BD384 PAL
              807BC9F0 NTSC-J
              807AB744 NTSC-K

.set region, ''

.if (region == 'E' || region == 'e')

.set raceDirector, 0x809B8F70
.set kmpInfo, 0x809B8F28

.elseif (region == 'P' || region == 'p')

.set raceDirector, 0x809BD730
.set kmpInfo, 0x809BD6E8

.elseif (region == 'J' || region == 'j')

.set raceDirector, 0x809BC790
.set kmpInfo, 0x809BC748

.elseif (region == 'K' || region == 'k')

.set raceDirector, 0x809ABD70
.set kmpInfo, 0x809ABD28

.else

.error "invalid region selected"

.endif

mflr r9 # back up lr

lis r7, raceDirector@ha
lwz r7, raceDirector@l(r7)
lwz r8, 0x18(r7)
lbz r8, 0(r8) # player id of the player in 1st place

cmpw r8, r3
bne check_distance

li r3, 1 # the player is already in first, don't bother checking distance
b end

check_distance:
bl distances # distances are processed as "below <distance in units> for <rank position>"
.float 1500.0
.float 4000.0
.float 6500.0
.float 9500.0
.float 12500.0
.float 16500.0
.float 20500.0
.float 25000.0
.float 29500.0
.float 34500.0
.float 39000.0
distances:
mflr r6

lis r4, kmpInfo@ha
lwz r4, kmpInfo@l(r4)
lwz r4, 0x20(r4)
lfs f5, 0x10(r4) # course length

lwz r5, 0xC(r7)

slwi r0, r8, 2
lwzx r4, r5, r0
lfs f4, 0xC(r4) # get race progress for the player in 1st
fmuls f4, f4, f5

slwi r0, r3, 2
lwzx r4, r5, r0
lfs f3, 0xC(r4) # get race progress for the player who hit the itembox
fmuls f3, f3, f5

fsubs f2, f4, f3

li r3, 0
check_distance_loop:
slwi r0, r3, 2
addi r3, r3, 1

lfsx f1, r6, r0
fcmpu cr0, f2, f1
blt end

cmpwi r3, 0xC
blt check_distance_loop

end:
mtlr r9 # restore lr
blr # skip the rest of the function and return
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)