200cc (CTGP Replica)
#21
To my surprise, saving/loading brake drifting ghosts was already working. So I started working on CTGP compatibility.

For unknown reasons, braking input sequences are delayed by one frame in the stock game. And since brake drifting was implemented the same way as braking, it way delayed too. But CTGP doesn't do that and handles brake drifting like other inputs. I updated the code above to align with CTGP (only patch 5 had to be changed).

Another difference is that CTGP not only multiplies speed, but also boost acceleration, and standard acceleration, but not drift acceleration (they are separate vehicle/character stats). It also caps max boost speed differently than 150cc. I made a code that reproduces this behavior.

NTSC-U:
048b13b8 40900000
04575600 60000000
c25745fc 00000006
807d0000 80630004
80630004 54630739
40820014 3c603fc0
907d0030 c01d0030
ec200072 d03d0030
60000000 00000000

PAL:
048b5c78 40900000
0457be64 60000000
c257ae60 00000006
807d0000 80630004
80630004 54630739
40820014 3c603fc0
907d0030 c01d0030
ec200072 d03d0030
60000000 00000000

Patch 1: set the boost acceleration to 4.5 (instead of 3.0)
# replace at 808b13b8 (NTSC-U)
# replace at 808b5c78 (PAL)
40900000

Patch 2: remove a branch to always use the same (smaller) speed cap while boosting
# replace at 80575600 (NTSC-U)
# replace at 8057be64 (PAL)
nop

Patch 3: multiply the non-boost acceleration by 1.5 if the player is not drifting
# inject at 805745fc (NTSC-U)
# inject at 8057ae60 (PAL)
lwz r3, 0x0 (r29)
lwz r3, 0x4 (r3)
lwz r3, 0x4 (r3)
rlwinm. r3, r3, 0, 28, 28
bne end
lis r3, 0x3fc0
stw r3, 0x30 (r29)
lfs f0, 0x30 (r29)
fmuls f1, f0, f1
end:
stfs f1, 0x30 (r29)

With this, it is now possible to replay CTGP 200cc ghosts on some tracks like rGV2 and rMC3 with at least millisecond accuracy, but other tracks like TF and rWS are more problematic, even when seemingly not using fast falling. In particular there is a value separate from acceleration that's added to the speed the next few frames after landing, and of course it's sometimes different on CTGP.
#22
(11-04-2020, 01:55 PM)Vega Wrote:
(11-04-2020, 11:50 AM)stebler Wrote: Yes, I'm a computer science student.

Then you will learn really fast here. The majority of ASM codes here on the site use very rudimentary ASM w/o any sort of use of actual static analysis. Do you want join our Discord Server?

I will join, but I probably won't be a very active member (not a fan of Discord).
#23
I've sent you an invite link via personal message.
#24
(10-30-2020, 04:41 PM)stebler Wrote: Brake drifting v0.2

NTSC-U:
c251bea0 00000006
55040739 41820020
a09c0090 548406b5
41820014 a09c0090
548405ad 41820008
61080010 b11d0004
60000000 00000000
c251b1ec 00000005
54c40739 41820018
54640673 41820010
546405ad 41820008
60c60010 5464073b
60000000 00000000
c258e1cc 00000003
540307fe 5400e7fe
68000001 7c001839
60000000 00000000
045776e8 60000000
c2574620 00000002
2c000001 41820008
548307ff 00000000

PAL:
c2520314 00000006
55040739 41820020
a09c0090 548406b5
41820014 a09c0090
548405ad 41820008
61080010 b11d0004
60000000 00000000
c251f660 00000005
54c40739 41820018
54640673 41820010
546405ad 41820008
60c60010 5464073b
60000000 00000000
c25949f0 00000003
540307fe 5400e7fe
68000001 7c001839
60000000 00000000
0457df4c 60000000
c257ae84 00000002
2c000001 41820008
548307ff 00000000

ASM patch 1: set the brake drifting bit when both B and R are pressed and the player is drifting (GCN controller)
# inject at 8051bea0 (NTSC-U)
# inject at 80520314 (PAL)
rlwinm. r4, r8, 0, 28, 28
beq end
lhz r4, 0x90 (r28)
rlwinm. r4, r4, 0, 26, 26
beq end
lhz r4, 0x90 (r28)
rlwinm. r4, r4, 0, 22, 22
beq end
ori r8, r8, 0x10
end:
sth r8, 0x4 (r29)

ASM patch 2: set the brake drifting bit when both B and R are pressed and the player is drifting (classic controller)
# inject at 8051b1ec (NTSC-U)
# inject at 8051f660 (PAL)
rlwinm. r4, r6, 0, 28, 28
beq end
rlwinm. r4, r3, 0, 25, 25
beq end
rlwinm. r4, r3, 0, 22, 22
beq end
ori r6, r6, 0x10
end:
rlwinm. r4, r3, 0, 28, 29

ASM patch 3: do not accelerate when the brake drifting bit is set
# inject at 8058e1cc (NTSC-U)
# inject at 805949f0 (PAL)
rlwinm r3, r0, 0, 31, 31
rlwinm r0, r0, 28, 31, 31
xori r0, r0, 1
and. r0, r0, r3

ASM patch 4: do not cancel the drifting when the player is no longer accelerating
# replace at 805776e8 (NTSC-U)
# replace at 8057df4c (PAL)
nop

ASM patch 5: allow breaking while drifting
# inject at 80574620 (NTSC-U)
# inject at 8057ae84 (PAL)
cmpwi r0, 1
beq end
rlwinm. r3, r4, 0, 31, 31
end:

Note: just like CTGP, this code uses bit 4 of the button input variable for brake drifting (0 = accelerate, 1 = brake or drift, 2 = use item, 3 = drift, 5 = look backwards).

TODO:
* nunchuk
* wii wheel
* NTSC-J, NTSC-K
* test on real Wii
* check that it works online
* work on perfect CTGP compatibility (using ghost replay)

This is my first time working on a code for MKW, so any feedback is welcome!

If you'd like, I'd be more than happy to help you port this to NTSC-J and NTSC-K once you've done the other two controllers. Also, I've tested the PAL version of this code on Wii, and I'm happy to say it works perfectly so good job!
#25
I updated the brake drifting code with nunchuk and wii wheel support. I used the same buttons as CTGP, but this can easily be changed if needed.

There are also NTSC-J and NTSC-K versions now. Thanks to Brawlbox for helping me on that!
#26
(11-19-2020, 10:31 PM)stebler Wrote: I updated the brake drifting code with nunchuk and wii wheel support. I used the same buttons as CTGP, but this can easily be changed if needed.

There are also NTSC-J and NTSC-K versions now. Thanks to Brawlbox for helping me on that!

Any chance you can post all the codes you have made as individual thread in the Codes forum? It would make nice additions to the site. I gave you Coder/Dev role, so you can bypass the thread approval process.



THREAD UPDATE (12/28/2020)
Thread has been closed since Stebler has posted the official 200cc Code.


Forum Jump:


Users browsing this thread: 4 Guest(s)