[Bug] Food item % chance to inflict a status

If you are stuck in the Dunan Unification Wars; or wish for more details on the gameplay systems, this is the place.
Post Reply
KFCrispy
Global Admin
Posts: 6174
Joined: Wed Jun 30, 2004 3:29 pm

[Bug] Food item % chance to inflict a status

Post by KFCrispy »

Buried in the Formulas thread, the coding-running community (namely psychedelist) found there is a bug in the game that fixes all food items to only have a 10% chance to inflict any status it is capable of inflicting. That nerfs several foods that can cause a useful status like Berserk, sadly!

Maybe Pyriel or someone can take a crack at fixing it? :)
User avatar
Pyriel
Webmaster
Posts: 1227
Joined: Wed Aug 18, 2004 1:20 pm

Re: [Bug] Food item % chance to inflict a status

Post by Pyriel »

Kind of going to need more information on what they were testing with. It looks to me like Fried Tacos work just fine at the point where it actually tries to roll chances. The way Konami does it is typical jank, though. If one thing or another isn't working, it wouldn't surprise me. I imagine the runners didn't give a rip about toasty, and there are 3-4 different paths that all do pretty much the same thing in slightly different ways. There's also always the possibility they were trying it in-battle, and the game wants to use yet another chunk of code there.
Z3R01337
Posts: 62
Joined: Sat Feb 06, 2016 6:06 am

Re: [Bug] Food item % chance to inflict a status

Post by Z3R01337 »

So this, and the other findings in recent topics were actually found by psychedelist from here as far as I know. It's from his reference doc posted here.
http://suikosource.com/phpBB3/viewtopic ... 90#p160083

As far as I could tell Fried Tacos always worked fine outside of battle. I assume it's in battle where the rate is 10%. It's not relevant in any current speedrun. I did a Freed & Gengen challenge run a while back where I tried to use a ton of berserk food items, and the percentage definitely felt more inline with 10%.
User avatar
Pyriel
Webmaster
Posts: 1227
Joined: Wed Aug 18, 2004 1:20 pm

Re: [Bug] Food item % chance to inflict a status

Post by Pyriel »

It's the battle code, and he ain't kidding about it being stupid.

Code: Select all

RAM:8004CCC0                 lbu     $v1, 0x36($s3)   # Load item flags (chances)
RAM:8004CCC4 nop
RAM:8004CCC8 andi $v0, $v1, 3
RAM:8004CCCC beqz $v0, loc_8004CCDC # If neither of the 2 least significant bits is set, go see which one is set??? WTF?
RAM:8004CCD0 move $s5, $a2
RAM:8004CCD4 j loc_8004CCF8
RAM:8004CCD8 li $s1, 0xA # Default to 10
RAM:8004CCDC # ---------------------------------------------------------------------------
RAM:8004CCDC
RAM:8004CCDC loc_8004CCDC: # CODE XREF: sub_8004CC98+34j
RAM:8004CCDC andi $v0, $v1, 1
RAM:8004CCE0 bnez $v0, loc_8004CCF8 # Bit one set, then 30
RAM:8004CCE4 li $s1, 0x1E
RAM:8004CCE8 andi $v0, $v1, 2
RAM:8004CCEC beqz $v0, loc_8004CCF8 # Bit 2 set then 60 else 100.
RAM:8004CCF0 li $s1, 0x64
RAM:8004CCF4 li $s1, 0x3C
They're pretty much saying "if value is zero, go see if value is 1 or 2, otherwise default to 10% chance". Out of battle appears to be correct. In-battle, you either have a 100% chance (if no chance flag is set on the item) or 10%.

There's not even a flag for 10% as far as I can tell. This code also has a default for 100% if neither chance flag is set, and that's what the out-of-battle code does more or less correctly with no code for a 10% chance. The chance is one of 30%, 60%, or 100% there. The way the battle code is written leads me to believe they couldn't figure out why it wasn't working, and just put a 10% chance up front as a default catch-all after getting stumped.
Julian
Posts: 73
Joined: Wed Jan 29, 2014 9:17 pm

Re: [Bug] Food item % chance to inflict a status

Post by Julian »

I just took a look at this on the PSP.

I couldn't find a way to write this that would fit, so I wrote a function to get the % and just hooked it in here.

Now, I don't have the PS1 elf loaded up on Ghidra so I can't see the code after what you pasted, but if it's the same as the PSP, there's two pointless instructions that do nothing:
li a1, 0x0
or a0, a1, a0 -- a0 or 0 is a0, the heck was the point of this?

The function call immediately after starts with lui a1, so that a1 of 0 is never used.

With two extra lines we're able to fit code that I think would work:

Code: Select all

RAM:8004CCC0 lbu $v1, 0x36($s3) # Load item flags (chances)
RAM:8004CCC4 andi $v0, $v1, 3
RAM:8004CCC8 li $v1, 1
RAM:8004CCCC bne $v0, $v1, loc_8004CCE0
RAM:8004CCD0 move $s5, $a2
RAM:8004CCD4 li $s1, 0x1e
RAM:8004CCD8 j loc_8004CCFF
RAM:8004CCDC nop
RAM:8004CCE0 li $v1, 0x2
RAM:8004CCE4 bne $v0, $v1 loc_8004CCF4
RAM:8004CCE8 li $s1, 0x3c
RAM:8004CCEC j loc_8004CCFF
RAM:8004CCF0 nop
RAM:8004CCF4 beq $v0, $zero, loc_8004CCFF
RAM:8004CCF8 li $s1, 0x64
RAM:8004CCFC li $s1, 0xA
I worked under the assumption that the last 2 bits:

Code: Select all

    ; 0 --> 0x64 (100%)
; 1 --> 0x1e (30%)
; 2 --> 0x3c (60%)
; 3 --> 0xa (10%) ??? I dont think its ever 3
User avatar
Pyriel
Webmaster
Posts: 1227
Joined: Wed Aug 18, 2004 1:20 pm

Re: [Bug] Food item % chance to inflict a status

Post by Pyriel »

To be honest, when I get around to it, I'm planning to just steamroll that 10% catch-all out of the code. I don't see any reason why it should work differently in-battle than out.

If I was going to leave it in, I'd probably just

Code: Select all


RAM:8004CCC0 lbu $v1, 0x36($s3) # Load item flags (chances)
RAM:8004CCC4 li $at, 3
RAM:8004CCC8 andi $v0, $v1, 3
RAM:8004CCCC bne $v0, $at, loc_8004CCDC # If one or none of the 2 least significant bits is set, go see what is set.
RAM:8004CCD0 move $s5, $a2
FYI, your code wouldn't be safe on the PSX. Loads won't cause register stalls on the R3000, so using a register the operation after you try to load it is verboten. There needs to be at least one slot of delay to ensure the operation that uses the value isn't getting a dirty read of sorts.

Edit: Now that I'm thinking about it, the two-line fix above is probably just fine. I also don't think both flags are set on any item, so it doesn't even matter. I'll just have to test a bit to make sure I'm not oversimplifying. IIRC this also hits the BP0_FST vs. BP0_SEC bullcrap. That is, it has to be changed in two places because the first round of battle uses a different module for some reason.
Julian
Posts: 73
Joined: Wed Jan 29, 2014 9:17 pm

Re: [Bug] Food item % chance to inflict a status

Post by Julian »

Huh... more you know. I haven't done much PS1 hacking but will try to keep that in mind.

I think your solution works.

Looking at the PSP version again, it's... slightly even more screwy.

The first part is the same so the end result is the same (10% if it's not 100%) -- but here, it's not even anding 0x2. lol (Not that it matters since due to the first check, it only gets to the bottom part if the two bits are 00.)

Code: Select all


        09e880c4 09 00 a3 90     lbu        v1,0x9(a1)
09e880c8 21 a0 80 00 move s4,a0
09e880cc 21 90 c0 00 move s2,a2
09e880d0 03 00 62 30 andi v0,v1,0x3
09e880d4 03 00 40 10 beq v0,zero,LAB_09e880e4
09e880d8 21 98 a0 00 _move s3,a1
09e880dc 09 00 00 10 b LAB_09e88104
09e880e0 0a 00 10 24 _li s0,0xa
LAB_09e880e4 XREF[1]: 09e880d4(j)
09e880e4 01 00 62 30 andi v0,v1,0x1
09e880e8 03 00 40 10 beq v0,zero,LAB_09e880f8
09e880ec 00 00 00 00 _nop
09e880f0 04 00 00 10 b LAB_09e88104
09e880f4 1e 00 10 24 _li s0,0x1e
LAB_09e880f8 XREF[1]: 09e880e8(j)
09e880f8 02 00 40 50 beql v0,zero,LAB_09e88104
09e880fc 64 00 10 24 _li s0,0x64
09e88100 3c 00 10 24 li s0,0x3c
User avatar
Pyriel
Webmaster
Posts: 1227
Joined: Wed Aug 18, 2004 1:20 pm

Re: [Bug] Food item % chance to inflict a status

Post by Pyriel »

Yeah...that reads like the people doing the PSP port saw "if (item->flag[0] & 3 != 0) { chance = 10; } else { switch(item->flag[0] & 3)... } " and thought they were removing unnecessary code by taking out "case 2:" or something. Instead of, you know, realizing the actual issue.
Julian
Posts: 73
Joined: Wed Jan 29, 2014 9:17 pm

Re: [Bug] Food item % chance to inflict a status

Post by Julian »

Yeah.. that's why your simple fix didn't come to mind, the code I've been staring at makes even less sense than the original. XD

Anyway, what you mentioned explains why the original code had a nop between the lbu and the andi. I was wondering about that, but that makes sense.
Rizen
Posts: 19
Joined: Fri Dec 06, 2019 1:50 am

Re: [Bug] Food item % chance to inflict a status

Post by Rizen »

i was talking with Z3ro about this on my stream, i think it was .. oh god... urmm...seshswan? sezchwan? goyza? .... yea that.... it says " causes Beserk" as in implies its 100%.... this was defo not the case. also while were on the subject of recipes ... i understand the recipe bugs, are caused by the code only allowing you to have one of each copy....this is strange to me. why go to all that trouble of programming this, when a player would just throw away any dupe copy? the elves wont drop a dupe recipe cause the game thinks you already have it? why is this even a thing. just have it drop at chance and have the player keep or throw it, like any other item?? and besides the game gives u multiple recipe 25s from greenhill rare finds. seems like the extra programming here was just a waste of time, trying to be too clever.
User avatar
Pyriel
Webmaster
Posts: 1227
Joined: Wed Aug 18, 2004 1:20 pm

Re: [Bug] Food item % chance to inflict a status

Post by Pyriel »

I mean one-time drops aren't exactly unique to this game. This method of doing it might have been a little unusual, even at the time, but none of this is all that uncommon. It would have worked fine, if they hadn't screwed it up.
Post Reply