Water boxes
#2
This seems like it might be the appropriate place to talk about water currents? This is more about water in general but I think people might look here for it.

The speed and direction of the water box's current will actually be derived from the floor triangles underneath it. The collision type for most triangles intended to be below water is "0D", however type "0E" will move Mario according to the speed and angle provided in the following bytes.

Code:
Offset     Type     Description
0x00     u16     collision_type
0x02     u8     flowing speed LUT value (0x00=metal cap water, 0x02=castle grounds water)
0x03     u8     flowing direction

The value at 0x02 functions as a Look Up Table byte, as such the force at which flow speed pushes Mario is not linear. These two bytes are normally 0, so changing the collision type of a floor collision triangle above which Mario is swimming from "0D" to "0E" will use the flow speed of 00 in the lookup table, which happens to be the force of the water in the Cavern of the Metal Cap, against which a casual player will not make headway (maybe perfect swimming can?).

Code:
Key     Value     Description
0x00     0x001C     metal cap water
0x02     0x0008     castle grounds water
0x27     0x0000     SSL gradual quicksand
0x18     0x1A14     SSL instant quicksand //traps mario
0xEE     0x0100     No in game use, very fast

Play around to find a value you like. Most values point to stuff surely unintended for water currents, so try stuff out. Check the current value by breaking at 0x8027056C and checking the T8 register.

The flow direction is a straight forward angle byte with 0x00 to X+, 0x40 to Z+, and so on counterclockwise.

When injecting your own code, the "Push Mario With Current" function at 0x80270500 is a good place to start to directly modify the current speed or current direction applied to mario. It even works in unconventional water like in the Cavern of the Metal Cap that do not follow normal waterbox rules. This code will let you flip the direction of all currents and water boxes by holding the L button:

Code:
.defineLabel func_waterCurrent_ROM_start, 0x7F0000
.defineLabel func_waterCurrent_RAM_start, 0x80370000

.defineLabel func_waterRotation_ROM_start, 0x7F0084
.defineLabel func_waterRotation_RAM_start, 0x80370084

.orga 0x2B538//0x80270538
J 0x80370000
LW T9, 0x0048(SP)

.orga func_waterCurrent_ROM_start
.area 0x0084
LW    T0, 0x0068 (T9)
LH    T1, 0x0002 (T0) //first current load

//if L is held, modify our boy
.f_testInput BUTTON_L, true, waterNoL1
AND T5, T1, T1
ADDIU T5, T5, 0x0080
ANDI T5, T5, 0x00FF
ANDI T1, T1, 0xFF00
OR T1, T1, T5

waterNoL1:
SLL    T2, T1, 8
SH    T2, 0x003E (SP)
LW    T3, 0x0048 (SP)
LUI    T8, 0x8033
LW    T4, 0x0068 (T3)
LH    T5, 0x0002 (T4) //second current load

//if L is held, modify our boy
.f_testInput BUTTON_L, true, waterNoL2
AND AT, T5, T5
ADDIU AT, AT, 0x0080
ANDI AT, AT, 0x00FF
ANDI T5, T5, 0xFF00
OR T5, T5, AT

waterNoL2:
AND A0, T6, T6
J 0x80270560
SRA    T6, T5, 8
.endarea

//Flip water rotation
.orga 0x8B5D0;802D05D0
J func_waterRotation_RAM_start;BNEZ    T5, 0x802D06EC
;NOP

.orga func_waterRotation_ROM_start
.f_testInput BUTTON_L, true, waterRotPostXOR

LI T8, 0x0001
XOR T5, T5, T8
waterRotPostXOR:
BNEZ T5, waterRotBranch
NOP
J 0x802D05D8
NOP
waterRotBranch:
J 0x802D06EC
NOP


// Call our custom function with DMACopy from the top-most levelscript.
.orga 0x108A18
.word 0x11080000, 0x8024B940

//************** DmaCopy function **************//
.orga 0x6940 ; Overwrite the unused function 0x8024B940
.area 0x64 ; Set data import limit to 0x64 bytes
addiu sp, sp, -0x18
sw ra, 0x14 (sp)
sw a0, 0x10 (sp) ; lvl cmd 0x11 safeguard

// These two are nessecary because of what we overwrote at 0x108A18.
.f_osViBlack FALSE ; Set screen blackout to false
sw r0, 0x8038BE24 ; Set level accumulator to 0

// Copies 0x100 bytes from ROM addr 0x7F0000 to RAM addr 0x80370000
.f_DmaCopy func_waterCurrent_RAM_start, func_waterCurrent_ROM_start, 0x7F00F4

lw v0, 0x10 (sp) ; lvl cmd 0x11 safeguard
lw ra, 0x14 (sp)
jr ra
addiu sp, sp, 0x18
.endarea
46artlu, and David liked this post
Reply


Messages In This Thread
Water boxes - by David - 03-09-2018, 10:45 PM
RE: Water boxes - by Deivore - 07-13-2018, 03:47 AM



Users browsing this thread: 2 Guest(s)