[ASM Tweak] Better parallel lakitu patch
Users browsing this thread: 1 Guest(s)

I have made this tweak a very long time ago but I decided to finally share codes for it. What it does is basically fixing minor issues for parallel lakitu as well as adding better preciser controls for parallel lakitu.

Changelog from original parallel lakitu:
  • Camera is not stuck in c-up camera with lakitu, camera in cannons is not broken
  • All regular parallel lakitu controls are preserved (c-stick controls)
  • L button switches lakitu between parallel mode and regular cam mode in water/flying (useful for levels like WDW where water/flying cam is screwed sometimes)
  • In regular cam mode switching from mario->lakitu cam fixes parallel lakitu cam angle to closest 8-way aligned angle
  • D-pad left/right changes parallel lakitu angle precisely allowing for easier wallkicks out of 45 degree walls for example
  • D-pad up/down switches back to to closest 8-way aligned angle

I have made an ARMIPS ASM patch, use ARMIPS GUI to compile. This code overwrites unused lakitu cam presets so it can be used with any other non lakitu cam patch.
Spoiler: Code for camera
Code:
; [ARMIPS 0.9+] Better parallel cam patch

;is 0 when from mario cam, is not 0 if in lakitu
.defineLabel RAM_STATE, 0x41D20
.defineLabel RAM_STATE_HI, 0x8028
.defineLabel RAM_STATE_LO, 0x6D20

.defineLabel IS_PARALLEL, 0x41D24
.defineLabel IS_PARALLEL_HI, 0x8028
.defineLabel IS_PARALLEL_LO, 0x6D24

.defineLabel MARIO_FACE_HI, 0x8033
.defineLabel MARIO_FACE_LO, 0xDF60
.defineLabel MARIO_FACE_OF, 0x0012

.defineLabel LAKITU_ANGLE_HI, 0x8034
.defineLabel LAKITU_ANGLE_LO, 0xC778

.defineLabel INPUTS_HI, 0x8034
.defineLabel INPUTS_LO1, 0xAFA0 ; hold
.defineLabel INPUTS_LO2, 0xAFA0 ; press

;============Hook mario and lakitu cam functions==============
.orga 0x41BBC
.area 0x8
B mariocamhook   ; original: BEQ T5, R0, 0x41C54 -- selector between mario and lakitu cam
NOP
.endarea

.orga 0x41C7C
.area 0x8
B lakitucamhook  ; original: JR T9
NOP
.endarea
;=========================End Hooks===========================



;Set mario cam hook onto place where bad lakitu cams live
;restrict payload to fit before 41D20 which is RAM
.orga 0x41CD4
.area 0x4C
mariocamhook:
BEQ T5, R0, 0x41C54
NOP
;====================Mario hook code=====================
LUI AT, IS_PARALLEL_HI
LW T0, 0x6D24(AT)
BEQ T0, R0, mariocamhook_refixlakitu
NOP
B mariocamhook_endrefixlakitu
NOP

mariocamhook_refixlakitu:
LUI AT, RAM_STATE_HI
SW R0, 0x6D20(AT)
mariocamhook_endrefixlakitu:
;====================Mario hook end======================

B 0x41BC4
NOP
.endarea



;============Initilize RAM data with zeroes==================
.orga 0x41D20
.area 0x8
NOP
NOP
.endarea
;============================================================

;Set lakitu cam hook onto place where bad lakitu cam code live
.orga 0x3DC3C
.area 0x134
lakitucamhook:
;====================Lakitu hook code====================

;
;--------------------------------------------------------
; Remove all low lakitu cam codes
;--------------------------------------------------------
;
LUI T0, 0x8028
ADDI T0, T0, 0x6CB4
SUB T0, T9, T0
BLEZ T0, lakitucamhook_nofixoverflow
NOP

LUI T9, 0x8028
ADDI T9, T9, 0x6CC4
lakitucamhook_nofixoverflow:


;
;--------------------------------------------------------
; Check for L button press to switch modes
;--------------------------------------------------------
;
LUI AT, INPUTS_HI
LH T0, 0xAFA2(AT)

ANDI T0, T0, 0x0020
BEQ T0, R0, lakitucamhook_nolpress
NOP

LUI AT, IS_PARALLEL_HI
LW T0, 0x6D24(AT)
ADDI AT, R0, 0x0001
SUB T0, AT, T0
LUI AT, IS_PARALLEL_HI
SW T0, 0x6D24(AT)
lakitucamhook_nolpress:


;
;--------------------------------------------------------
;           Use parallel lakitu if L was pressed
;--------------------------------------------------------
;
LUI AT, IS_PARALLEL_HI
LW T0, 0x6D24(AT)
BEQ T0, R0, lakitucamhook_nobeparallel
NOP

;flying check
LUI T0, 0x8028
ADDI T0, T0, 0x6C84
SUB T0, T9, T0
BEQ T0, R0, lakitucamhook_beparallel
NOP

;water check
LUI T0, 0x8028
ADDI T0, T0, 0x6CA4
SUB T0, T9, T0
BEQ T0, R0, lakitucamhook_beparallel
NOP
B lakitucamhook_nobeparallel
NOP
lakitucamhook_beparallel:
LUI T9, 0x8028
ADDI T9, T9, 0x6CC4
lakitucamhook_nobeparallel:


;
;--------------------------------------------------------
; Rotate lakitu cam on dpad presses
;--------------------------------------------------------
;
LUI AT, INPUTS_HI
LH T0, 0xAFA0(AT)
LUI AT, LAKITU_ANGLE_HI
LH A0, 0xC778(AT)

ANDI AT, T0, 0x0200
BEQ AT, R0, lakitucamhook_noleft
NOP
ADDI A0, A0, 0xFFD0
B lakitucamhook_minirotateend

lakitucamhook_noleft:
ANDI AT, T0, 0x0100
BEQ AT, R0, lakitucamhook_noright
NOP
ADDI A0, A0, 0x0030
B lakitucamhook_minirotateend

lakitucamhook_noright:
LUI AT, INPUTS_HI
LH T0, 0xAFA2(AT) ;using press
ANDI AT, T0, 0x0C00
BEQ AT, R0, lakitucamhook_minirotateend
NOP
ADDI A0, A0, 0x1000
ANDI A0, A0, 0xE000

lakitucamhook_minirotateend:
LUI AT, LAKITU_ANGLE_HI
SH A0, 0xC778(AT)


;
;--------------------------------------------------------
; Get last state of lakitu cam and line it if needed
;--------------------------------------------------------
;
LUI AT, RAM_STATE_HI
LW T0, 0x6D20(AT)

BEQ T0, T9, lakitucamhook_fixangleend ;no fix required
NOP

LUI AT, MARIO_FACE_HI
LW T0, 0xDF60 (AT)
LH T0, 0x0012 (T0)

;Rotate camera to be behind mario and make it 8-way
ADDI T0, T0, 0x9000
ANDI T0, T0, 0xE000

LUI AT, LAKITU_ANGLE_HI
SH T0, 0xC778(AT)

;Store new mode of camera
LUI AT, RAM_STATE_HI
SW T9, 0x6D20 (AT)
lakitucamhook_fixangleend:
;====================Lakitu hook end=====================

JR T9
NOP
.endarea

Another way of applying patch to your ROM is using my patcher. Just drag'n'drop your ROM on exe inside archive to apply parallel lakitu patch.

[ASM Tweak] Better parallel lakitu patch
Users browsing this thread: 1 Guest(s)


  EN ・日本語