VS Points Based on Finish Time Difference With 1st [CLF78]
#1
This code gives each player points based on how much time they took to get to the finish line after the leader. The time multiplier and max points can be modified by changing the values in the code. The code works both offline and online (all players must be running it for it to work).

NTSC-U
C252A0F0 00000011
48000034 7C67182E
81030040 A0680008
89280006 1D2903E8
7C691A14 A1280004
39000000 6108EA60
7D2941D6 7C691A14
4E800020 3CE0809C
80E78F70 80670018
88630000 5463103A
80E7000C 4BFFFFB9
7C6C1B78 7E639B78
4BFFFFAD 7C6A1B78
2C0A0000 4182001C
7D4C5050 3920XXXX
7D4A4BD6 392000YY
7C6A4851 41A10008
38600000 00000000

PAL
C252EC38 00000011
48000034 7C67182E
81030040 A0680008
89280006 1D2903E8
7C691A14 A1280004
39000000 6108EA60
7D2941D6 7C691A14
4E800020 3CE0809C
80E7D730 80670018
88630000 5463103A
80E7000C 4BFFFFB9
7C6C1B78 7E639B78
4BFFFFAD 7C6A1B78
2C0A0000 4182001C
7D4C5050 3920XXXX
7D4A4BD6 392000YY
7C6A4851 41A10008
38600000 00000000

NTSC-J
C252E5B8 00000011
48000034 7C67182E
81030040 A0680008
89280006 1D2903E8
7C691A14 A1280004
39000000 6108EA60
7D2941D6 7C691A14
4E800020 3CE0809C
80E7C790 80670018
88630000 5463103A
80E7000C 4BFFFFB9
7C6C1B78 7E639B78
4BFFFFAD 7C6A1B78
2C0A0000 4182001C
7D4C5050 3920XXXX
7D4A4BD6 392000YY
7C6A4851 41A10008
38600000 00000000

NTSC-K
C251CC90 00000011
48000034 7C67182E
81030040 A0680008
89280006 1D2903E8
7C691A14 A1280004
39000000 6108EA60
7D2941D6 7C691A14
4E800020 3CE0809B
80E7BD70 80670018
88630000 5463103A
80E7000C 4BFFFFB9
7C6C1B78 7E639B78
4BFFFFAD 7C6A1B78
2C0A0000 4182001C
7D4C5050 3920XXXX
7D4A4BD6 392000YY
7C6A4851 41A10008
38600000 00000000

XXXX = Multiplier (the game will subtract one point every XXXX milliseconds)
YY = Max Points (first place will always receive this amount)

Source:
Code:
# Hook Addresses: 0x8052EC38 PAL, 0x8052A0F0 NTSC-U, 0x8052E5B8 NTSC-J, 0x8051CC90 NTSC-K

# Change these to suit your needs
.set REGION, ''
.set MULTIPLIER, XXXXX

.set MAXPOINTS, YYY

# Address ports
.if (REGION == 'P' || REGION == 'p')
.set Raceinfo, 0x809BD730
.elseif (REGION == 'U' || REGION == 'u' || REGION == 'E' || REGION == 'e')
.set Raceinfo, 0x809B8F70
.elseif (REGION == 'J' || REGION == 'j')
.set Raceinfo, 0x809BC790
.elseif (REGION == 'K' || REGION == 'k')
    .set Raceinfo, 0x809ABD70
.else
    .err
.endif

# Free registers = r0, r7, r8, r9, r10, r12
# Dest register = r3
# Other registers = r22 (number of players), r19 (current player * 4)

########
# Jump #
########

# Jump to function start
b startFunc

###################################
# Get Player Time Helper Function #
###################################

# Get RaceinfoPlayer
getFinishTime:
lwzx r3, r7, r3

# Get finish time class
lwz r8, 0x40(r3)

# Get milliseconds
lhz r3, 0x8(r8)

# Get seconds and multiply by 1000
lbz r9, 0x6(r8)
mulli r9, r9, 1000
add r3, r9, r3

# Get minutes and multiply by 60000
lhz r9, 0x4(r8)
li r8, 0
ori r8, r8, 60000
mullw r9, r9, r8
add r3, r9, r3

# Return
blr

#################
# Main Function #
#################

# Load Raceinfo in r7
startFunc:
lis r7, Raceinfo@ha
lwz r7, Raceinfo@l(r7)

# Get player id in 1st
lwz r3, 0x18(r7)
lbz r3, 0(r3)
slwi r3, r3, 2

# Setup the array
lwz r7, 0xC(r7)

# Get the finish time and move it to r12
bl getFinishTime
mr r12, r3

# Get the current player's finish time and move it to r10
mr r3, r19
bl getFinishTime
mr r10, r3

# If the time is 0, give 0 (this usually happens if the player has DC'd)
cmpwi r10, 0
beq noPoints

# Subtract the first time to the player's time
sub r10, r10, r12

# Divide by the multiplier to get points to be subtracted
li r9, MULTIPLIER
divw r10, r10, r9

# Get max points
li r9, MAXPOINTS

# Subtract the point difference from max points
sub. r3, r9, r10

# If the value is less than 0, give 0 points
bgt+ end

# No points for you!
noPoints:
li r3, 0

# Return
end:

Code created by: CLF78
Reply


Messages In This Thread
VS Points Based on Finish Time Difference With 1st [CLF78] - by CLF78 - 04-09-2021, 01:35 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)