Please login or register.

Login with username, password and session length
Pages: [1]
Undead Knight
Heisho [Posts: 110]
  • View Profile
  • share
  • [August 12, 2018, 11:35:10 PM]
Help coding new stealing/breaking routine
« on: August 12, 2018, 11:35:10 PM »
Hello there!

I've been trying to develop a routine that allow you to either break or steal all equipment of the target, however I've hit a wall and do not know how to complete it.
At first it was a rutine that will jump if an item wasn't present and the formula that calls the routine had multihit but the game crashed after stealing the helmet (the first item to remove in the routine). Now with this new one I attempt to break/steal on one single hit by creating a loop, although I don't know if trying to send a routine to go back to the beginning using a jump is valid.

Can someone shed some light on this?

This is the code so far:

Thanks in advance to anyone that can help.

Regards.

    • Modding version: PSX
  • Gnarw, hiss, grrr and some other zombie noises...
    French Maid
    Xifanie (Webmistress) [Posts: 4400]
    • View Profile
    • Final Fantasy Hacktics
    • http://steamcommunity.com/id/Xifanie
    • share
    • [August 13, 2018, 12:39:19 AM]
    Re: Help coding new stealing/breaking routine
    « Reply #1 on: August 13, 2018, 12:39:19 AM »
    I'm not sure I can help (I'm ASM dyslexic, making me really bad at helping people with it), but your code looks really messy.

    You can just use r1 for lui... just once:
    Code: [Select]
    lui r1,0x8019   
    lw r2,0x2d98(r1)   Load Defender's Stats
    lw r4,0x2d90(r1)   Load Current Action Data Pointer
    lbu r3,0x001a(r2)   Load Defender's Headgear
    j 0x0000025c           Jump to store item
    nop   
    lw r2,0x2d98(r1)   Load Defender's Stats
    nop   
    lbu r3,0x001b(r2)   Load Defender's Armor

    But you should also just free up some registers by temporarily moving them in the stack instead of reloading again.

    Is the multi-hit necessary though? That sounds like it could cause problems

    • Modding version: PSX
  • <R999> My target market is not FFT mod players
    <Raijinili> remember that? it was awful
    Undead Knight
    Heisho [Posts: 110]
    • View Profile
    • share
    • [August 13, 2018, 07:35:49 PM]
    Re: Help coding new stealing/breaking routine
    « Reply #2 on: August 13, 2018, 07:35:49 PM »
    Thanks for help, I'll take your advice and see if freeing registers might do the trick.

    The reason for multihit goes way back. I tested a random steal formula from one of the hackers here but added a multihit routine (5 hits) and a 100% chance to steal in order to get all equipment. To my surprise the random element allowed to steal 3 or 4 of the hits but the fifth was very rare. Curiously enough it always was the same type of equipment that survived the steal barrage. Then I tried to make something by editing the original steal/break routine with a 5 hit formula. It worked on the first item (Helmet) but on the second attempt the game crashed. Later I made a test againt a target without a helmet and it also crashed, so i believe that something must be done on the routine. The version I'm posting is the vanilla routine with some edits from my part (that haven't worked so far). The multihit would be necessary only it a one hit steal/break all is not possible to make.

    However I believe it can be done but maybe I need to understand more about ASM, for starters (and please forgive my ignorance) how can you move registers to the stack? and also (forgive me again) what exactly is the stack? Maybe I already know the answers but don't know the lexicon.

    Anyway I'll give a try once I got a chance and will let you guys if I found something.

    Thanks once again.

    • Modding version: PSX
  • Gnarw, hiss, grrr and some other zombie noises...
    Glain [Posts: 487]
    • View Profile
    • share
    • [August 14, 2018, 07:05:55 PM]
    Re: Help coding new stealing/breaking routine
    « Reply #3 on: August 14, 2018, 07:05:55 PM »
    The main conceptual issue I see with this is that the game might not support it as-is because the action data can only have one item ID for stolen/broken item.  That being said, I took a look at this... a few things stand out.  You need to either use labels or have some idea of what address in RAM this code is going to be stored at.  This line is pretty much guaranteed to crash the game:

    Code: [Select]
    j 0x00000000

    Jumps to literally the beginning of RAM.  Jumping to 0x25c or what have you will also crash the game.  You need to be jumping to the address in RAM where your code is.  Labels can help a ton with this, as you'll see in my code example below.  There's also a ton of inefficiency, as Xifanie touched on, but since your register values aren't even being overwritten, you don't even need to save anything to the stack.  You're reloading values just to reload them...

    I simplified the logic down to this, which I believe should largely do what was intended (though is completely untested).  It fills out the action's 0x19 flags with the items to break/steal by using a loop.  Since you were basically doing the same thing for each item type, I just made that logic part of the loop.  This routine doesn't do the normal checks like evasion, Maintenance, etc., but those could possibly be checked in another routine if this is to be an inner routine... otherwise those checks would need to be added here.

    Code: [Select]
        lui     at, 0x8019   
        lw      t1, 0x2d98(at)          #   Load Defender's Stats
        lw      t0, 0x2d90(at)          #   Current Action Data Pointer
        lbu     t2, 6(t1)               #   Load Defender's 0x06 flags
        nop   
        andi    t2, t2, 0x20   
        bne     t2, zero, end           #   Branch to end if Defender is a Monster
        nop   

        li      t4, 0x1a
        li      t5, 0x80
        li      t6, 0

    loop_top:   
        addu    t2, t1, t4
        lbu     t3, 0(t2)
        li      t2, 0xff
        beq     t3, t2, loop_bottom
        nop
        or      t6, t6, t5
       
    loop_bottom:
        addiu   t4, t4, 1
        sltiu   t2, t4, 0x21
        bne     t2, zero, loop_top
        srl     t5, t5, 1
       
        sb      t6, 0x19(t0)
        lhu     t3, 0x38d6(at)          #   Load ability used
        li      t2, 0x73
        bne     t3, t2, break_item      #   Branch if not Great Heist (Thief)
        li      t2, 0x10                #   Special flag -Steal-
        sh      t2, 0x10(t0)            #   Store as steal item

    break_item:
        li      t2, 4                   #   Special flag -Break-     
        sh      t2, 0x10(t0)            #   Store as break item   

    end:
        jr      ra   
        nop

    Undead Knight
    Heisho [Posts: 110]
    • View Profile
    • share
    • [August 27, 2018, 04:53:24 AM]
    Re: Help coding new stealing/breaking routine
    « Reply #4 on: August 27, 2018, 04:53:24 AM »
    Hello everyone! Sorry for taking so long but I just finished testing this.

    First of all,  Glain thanks for the code man, I appreciate the help. The thing missing from my original idea was a jump after stealing which I added in order to steal.

    Regarding the results of the test I have good news and bad news.

    Good news: It work as expect, it stole and broke every single piece of equipment, I even equip it after stealing and the items worked as they should. Tested the stolen items in the formation screen after the battle and they worked fine.

    Bad news: After the ability finished it gave a message text: "" Destroyed / Got "". So it seems that i would not load every item name which might be a little problem aesthetically. Also due to my limited knowledge I don't if this can generate bugs later. I even added the text from another skill (Invite) to see if the message could be hidden and it plays the sound and it shows proper text (XXX joined) but after that the Got "" showed.

    So pretty much it kinda work, I don't know if not displaying the name of stolen/broken items might create bugs later. Maybe I can make a multi hit version that steal one item at a time so it can display every item name. I tested this before with the random steal formula that I got from another member and it gave good results, however the random factor didn't allow to steal all items on one single try (which is the purpose)

    One more thing. For some reason the last jump wasn't working and I replaced it with a jump and return. Could that be a problem?

    It looks like this:

    [0x0000005c] ori r10,r0,0x0073
    [0x00000060] bne r11,r10,0x00000074
    [0x00000064] ori r10,r0,0x0010
    [0x00000068] sh r10,0x0010(r8)
    [0x0000006c] jr r31
    [0x00000070] nop
    [0x00000074] ori r10,r0,0x0004
    [0x00000078] sh r10,0x0010(r8)
    [0x0000007c] jr r31
    [0x00000080] nop

    So anyways thanks for helping, I'll see if editing this formula for a multihit can be better. In the meantime feel free to leave comments or feedback on this strange quest.

    Regards.


    • Modding version: PSX
  • Gnarw, hiss, grrr and some other zombie noises...
    May I kill him?
    Pride [Posts: 839]
    • View Profile
    • share
    • [August 27, 2018, 07:18:46 AM]
    Re: Help coding new stealing/breaking routine
    « Reply #5 on: August 27, 2018, 07:18:46 AM »
    What does the rest of the routine look like?

    • Modding version: PSX
  • Check out my ASM thread. Who doesn't like hax?
    Glain [Posts: 487]
    • View Profile
    • share
    • [August 27, 2018, 12:58:46 PM]
    Re: Help coding new stealing/breaking routine
    « Reply #6 on: August 27, 2018, 12:58:46 PM »
    Oh right, there should have been a jump there.  That way will work but it's good form (although not required) to have one jr r31 per routine.  The way it should be is:

    li      t2, 0x10                #   Special flag -Steal-
    j      end
    sh    t2, 0x10(t0)           #   Store as steal item
    Undead Knight
    Heisho [Posts: 110]
    • View Profile
    • share
    • [August 27, 2018, 04:08:39 PM]
    Re: Help coding new stealing/breaking routine
    « Reply #7 on: August 27, 2018, 04:08:39 PM »
    @Glain: Yeah I though the same, some routine I have and formulas have only one jr r31, I just though of this a drastic measure to allow testing.
    I'll add later what you recommended, I just got out of bed, rough night.

    @Pride:
    The routine goes like this

    [0x00000000] lui r1,0x8019
    [0x00000004] lw r9,0x2d98(r1)
    [0x00000008] lw r8,0x2d90(r1)
    [0x0000000c] lbu r10,0x0006(r9)
    [0x00000010] nop
    [0x00000014] andi r10,r10,0x0020
    [0x00000018] bne r10,r0,0x0000007c
    [0x0000001c] nop
    [0x00000020] ori r12,r0,0x001a
    [0x00000024] ori r13,r0,0x0080
    [0x00000028] ori r14,r0,0x0000
    [0x0000002c] addu r10,r9,r12
    [0x00000030] lbu r11,0x0000(r10)
    [0x00000034] ori r10,r0,0x00ff
    [0x00000038] beq r11,r10,0x00000044
    [0x0000003c] nop
    [0x00000040] or r14,r14,r13
    [0x00000044] addiu r12,r12,0x0001
    [0x00000048] sltiu r10,r12,0x0021
    [0x0000004c] bne r10,r0,0x0000002c
    [0x00000050] srl r13,r13,0x01
    [0x00000054] sb r14,0x0019(r8)
    [0x00000058] lhu r11,0x38d6(r1)
    [0x0000005c] ori r10,r0,0x0073
    [0x00000060] bne r11,r10,0x00000074
    [0x00000064] ori r10,r0,0x0010
    [0x00000068] sh r10,0x0010(r8)
    [0x0000006c] jr r31
    [0x00000070] nop
    [0x00000074] ori r10,r0,0x0004
    [0x00000078] sh r10,0x0010(r8)
    [0x0000007c] jr r31
    [0x00000080] nop

    This is a subroutine, so it lacks Maintenance checks, and all that.

    • Modding version: PSX
  • Gnarw, hiss, grrr and some other zombie noises...
    Pages: [1]