Difference between revisions of "Conditional Out of Bounds"

From Custom Mario Kart
Jump to navigation Jump to search
Line 1: Line 1:
 +
[[File:lecode-ver-36x160.png|right]]
 
Currently, there are two different codes available:
 
Currently, there are two different codes available:
 
* [[Conditional Out of Bounds (kHacker35000vr)]]
 
* [[Conditional Out of Bounds (kHacker35000vr)]]
Line 134: Line 135:
  
 
This makes the distribution compatible with tracks created for either version of the out-of-bounds patch, and track authors can then freely choose which one to use.  
 
This makes the distribution compatible with tracks created for either version of the out-of-bounds patch, and track authors can then freely choose which one to use.  
 
 
  
 
{{disambig}}
 
{{disambig}}
 +
[[category:LE-CODE]]

Revision as of 09:19, 10 October 2020

Currently, there are two different codes available:

Both of these cheat codes are using AREA type 10, and use its parameters in an incompatible way. kHacker35000vr's patch is only active if the "Route" setting of the AREA is not 0, but Riidefi's patch is always active. In order to support both of these codes in a custom track distribution, the patches need to be modified.

Given that track(s) using kHacker35000vr's version are using a route value of 1 (CTR N. Gin Labs v1.4k2), and track(s) using Riidefi's version are using a route value of 0xff (CTR N. Gin Labs v1.4r, WP Wii Tanks, and Block Plaza (Race)), the easiest way to do that is to patch kHacker35000vr's version to only run for AREA route 1, and to patch Riidefi's version to only run for AREA route 0xff.

In the LE-CODE, which will implement both cheat codes as of version b26, this is done using the following code:

/* conditional_oob.S
 *  by Leseratte
 *  code by Riidefi and kHacker35000vr
 *
 *  Allows you to use a conditional Out-of-Bounds.

 *  Uses "Conditional OOB v2.0" by Riidefi and
 *  "Conditional OoB v1.1" by kHacker35000vr
 *
 *  See http://wiki.tockdom.com/wiki/Conditional_Out_of_Bounds
 */
 
.section .text
.globl __asm_conditional_oob_riidefi_patch
__asm_conditional_oob_riidefi_patch:

    extsh. r3, r3
    blt whatever

    lis r6, kmpData@ha;
    lwz r5, 4(r31);
    lwz r5, 0(r5); 
    lwz r4, kmpData@l(r6);

    lis r6, raceData2@ha; 
    lwz r6, raceData2@l(r6);
    rlwinm r0, r3, 2, 0, 29;
    lwz r4, 44(r4);

    lbz r5, 16(r5);
    lwz r4, 0(r4);
    lwz r6, 12(r6);
    rlwinm r5, r5, 2, 0, 29;
    lwzx r4, r4, r0;
    lwzx r5, r6, r5;
    lwz r4, 4(r4);      

    lbz r7, 0x2c(r4);       // Read route setting
    cmpwi cr7, r7, 0xff;    // If it's NOT 0xFF (-1), which is the default value, return.
    bne cr7, whatever

    lhz r7, 10(r5);
    lhz r8, 0x28(r4);     // AREA setting 1
    lhz r9, 0x2a(r4);     // AREA setting 2
    subf r10, r8, r9;
    srawi r4, r10, 31;
    xor r0, r4, r10;
    subf r6, r4, r0;
    subfc r5, r8, r9;
    subfe r4, r9, r9;
    cntlzw r0, r10;
    and r5, r5, r4
    add r5, r8, r5
    rlwinm r4, r10, 1, 31, 31
    subf r5, r5, r7
    rlwinm r0, r0, 27, 5, 31;
    subfc r5, r6, r5;
    subfe r5, r5, r5;
    neg r5, r5;
    xor r4, r5, r4;
    or r4, r4, r0
    addi r0, r4, -1
    or. r3, r0, r3;

whatever:
    b conditional_oob_patch_riidefi + 4;


.globl __asm_conditional_oob_kevin_patch
__asm_conditional_oob_kevin_patch:

    cmpwi r3, 0
    bltlr;

    lis r10, kmpData@h;
    rlwinm r9, r3, 2, 0, 29;
    ori r10, r10, kmpData@l;
    lwz r10, 0(r10)
    lwz r10, 44(r10)
    lwz r10, 0(r10);
    lwzx r9, r10, r9;
    lwz r10, 4(r9);
    lbz r9, 1(r10);             // read AREA type
    cmpwi cr7, r9, 10;
    bnelr cr7;

    lbz r9, 0x2c(r10);          // read route setting of the AREA. If it's NOT 1 (which is what tracks for kevin's version use), return.
    cmpwi cr7, r9, 1
    bnelr cr7;

    lis r8, raceData2@h
    lhz r9, 0x28(r10);          // read AREA setting 1
    ori r8, r8, raceData2@l
    lwz r7, 0(r8);
    cmpwi cr7, r9, 0;
    addi r8, r31, 4;
    lwz r8, 0(r8)
    lwz r8, 0(r8)
    lbz r8, 16(r8);
    lwz r7, 12(r7);
    rlwinm r8, r8, 2, 0, 29
    lwzx r8, r7, r8;
    bne cr7, area_setting_not_null
    lbz r9, 39(r8);
    lhz r10, 42(r10);
    cmpw cr7, r9, r10;
    beqlr cr7;

error:
    li r3, -1
    blr;

area_setting_not_null:
    cmplwi cr7, r9, 1
    bne error
    lbz r9, 39(r8)
    lhz r10, 42(r10);
    cmpw cr7, r9, r10
    bnelr+ cr7
    b error

This makes the distribution compatible with tracks created for either version of the out-of-bounds patch, and track authors can then freely choose which one to use.