Game Mechanics And Codes

If you are stuck in the Dunan Unification Wars; or wish for more details on the gameplay systems, this is the place.
User avatar
Pyriel
Webmaster
Posts: 959
Joined: Wed Aug 18, 2004 1:20 pm

Game Mechanics And Codes

Postby Pyriel » Sun Jun 21, 2009 11:38 pm

Best title I could come up with at the moment. Having cluttered up the Elemental Resistances & Bestiary thread quite enough, I thought I'd start another for this. I searched around the forum a bit, and couldn't find a topic that was a good fit.

Drop Chances
As long as you don't have a Hunter Rune equipped, the drop is recomputed every time an enemy dies*, until a drop occurs or you run out of enemies. Each enemy can have up to three drops, and the drops typically have descending probability from the first to the third. The probability is represented by a number that can be between 0 and 255, so 255 would be ~100%, 128 a fraction more than 50%, and 26 a fraction more than 10%, etc.

When an enemy is killed the game uses a seed--initially, I believe, from the system clock, but on subsequent passes, it's the last large integer generated--and some magic numbers** to generate a pseudo-random number. This number is then multiplied by the total of all drop percentages, adjusted a bit if it comes up negative, and then shifted and masked until the result is a relatively small number 255 or less. This number is compared to the stack of adjusted probabilities. The game adjusts the probabilities by adding the first to the second, and the first and the second to the third. That may seem mystifying, but it's a programming trick that eliminates the need for multiple passes. Let's say you have the following drops and probabilities (I'm using raw numbers rather than percentages):
  1. Medicine X 4 - 4
  2. Antitoxin X 4 - 1
  3. Mega Medicine X 4 1
The adjusted probabilities you end up with will be 4, 5 and 6 respectively. The drops are then checked in order from first to last, using the same number. So while it may look at a glance like they've just made Mega Medicine more likely to drop, they haven't. Think of it like The Price Is Right in reverse. The goal is simply to be the first one to be higher than the "price", which is the random number. So if the random number is 0-3, the Medicine is dropped (you may notice that's 4/256, as indicated by the chance number). In order for the Anti-Toxin to drop, the number must be 4 or higher, and less than 5, which means it has to be exactly 4 (1/256). Likewise the Mega Medicine requires the random number to be exactly 5 for it to drop.

(For fun, while 255 should be 100% there's no special coding for it. Since the comparisons done are random number less than adjusted drop chance number, there's still a 1/256 chance of no drop when an enemy has 255 as a drop number.)

Doing it this way has two benefits: For the programmers, it was simpler than doing multiple passes, and for the players, it means your chances are locked in as long as things were done properly, e.g., no assigning a drop chance of 127 to three drops for one enemy. I've seen some complaints about the chance of one drop making another virtually impossible. It's true in the sense that the higher probability item does have a greater chance of coming up (tautology). However, the way I've heard it stated is that it's like you get three rolls of the dice at maximum for prizes, and rolls two and three are only allowed if you fail to hit the magic number for the first prize. The way it's actually done is a bit more like a wheel game, where you spin and certain slots are for certain prizes while others get you nothing. In my example above, "rolling" a 5 will always get you a Mega Medicine. You don't have to not roll a 1-4, then not roll a 1, and then hit a 1 on the third to fit the drop number and get the Mega Medicine.

* This is how the game's code looks. I can't fully confirm yet, as I don't have a save in an area with mixed groups.
**1,103,515,245 (somebody's phone number?) and 12,345

Enough technical stuff.

Enemies Always Drop #?
D002E09A 1040
8002E152 1000
D002E09A 1040
8002E154 00??

96 - First Drop item
98 - Second
9A - Third

If the enemy doesn't have a drop in the position selected, you get nothing.

There's a second set of drop code that seems to be for an area drop. When I set it up to trigger always (in the area outside the fort at the beginning of the game) I keep getting unidentified vases/ornaments. I'm not sure what that's all about. I was messing with this to verify that I had computed drop chances correctly when ripping the data from the disc, and found that bit of code first. It was sort of annoying, since I was supposed to be getting Medicines and Technique runes like my listing said. Those vases could just be garbage data, and the code is actually for one-time drops, like the recipes and stuff. It just happens the area I was in has no one-time drops, and that code wasn't meant to execute. I haven't yet looked into it. Might be worth looking into for recipe #34 or something.

Since I'm crawling through the code anyway, I'll make some more cheats as the opportunities present themselves. While I'm at it, I'll also entertain any reasonable request for investigations into game mechanics, time permitting.
Last edited by Pyriel on Mon Jun 22, 2009 5:49 am, edited 1 time in total.

User avatar
BadPotato
Posts: 170
Joined: Mon Feb 09, 2009 10:07 am
Location: Canada - Québec

Re: Game Mechanics And Codes

Postby BadPotato » Mon Jun 22, 2009 1:21 am

Pyriel wrote:Enemies Always Drop #?
D002E09A 1040
8002E152 1000
D002E09A 1040
D002E154 00??

96 - First Drop item
98 - Second
9A - Third

hehe :D
Tested and it work very well on hollyboy in mercenry fortress aera at start(aera A)... I was able to change what slot # could be dropped, in my test I simply had to freeze 2E154 address to get it work.

If this might help you, I've made recently some address identification(I din't finish for every aera... but when it would be done, I'll post the whole list here) and as far as I can say, the unidentified item drop doesn't work like the "normal item", because the item digit seem to be stored in another address... anyway IMO this is an another case.

Pyriel wrote:When an enemy is killed the game uses a seed--initially, I believe, from the system clock, but on subsequent passes, it's the last large integer generated--and some magic numbers** to generate a pseudo-random number.


From my own test,(when I was unable to get some enemy drop even by reloading a previous savestate again and again), I feel like these "magic number" would be freezed for an undetermined amount of time with a very low or even null probability(to me it look like the drop are sometime overwrithed and you get nothing insthead of some item).

Pyriel wrote:**1,103,515,245 (somebody's phone number?) and 12,345

where you get these number?? is it for a specific memory address?

User avatar
Pyriel
Webmaster
Posts: 959
Joined: Wed Aug 18, 2004 1:20 pm

Re: Game Mechanics And Codes

Postby Pyriel » Mon Jun 22, 2009 6:22 am

BadPotato wrote:hehe :D
Tested and it work very well on hollyboy in mercenry fortress aera at start(aera A)... I was able to change what slot # could be dropped, in my test I simply had to freeze 2E154 address to get it work.

If this might help you, I've made recently some address identification(I din't finish for every aera... but when it would be done, I'll post the whole list here) and as far as I can say, the unidentified item drop doesn't work like the "normal item", because the item digit seem to be stored in another address... anyway IMO this is an another case.
I had a typo in the code (last line started with 'D' instead of '8').

That's sort of what I was getting at for the drop. This is "in-battle" or "after-kill" executable code that gets loaded as-needed into memory. Unlike the stuff in the area-specific files, it has to be generic enough to handle the needs of several different events and periods in the game's story. One of the things it does is load a byte-value that it tests for zero, and if it is, then it branches into the "Normal Drop" code. Possibly that's to see if any area/event drops are specified, but I don't really know. I had set it to always work as though the value was something other than zero, and wound up getting those antiques. I may try it again, and ID one of them. I suspect the item value was coming up as 0xCDCD or some other "uninitialized" garbage that happens to have the "item-unidentified" bit set. Getting it appraised will probably crash the game when it tries to retrieve the item name and description.

BadPotato wrote:From my own test,(when I was unable to get some enemy drop even by reloading a previous savestate again and again), I feel like these "magic number" would be freezed for an undetermined amount of time with a very low or even null probability(to me it look like the drop are sometime overwrithed and you get nothing insthead of some item).
Yeah, if you save-state, they certainly would be. Like I said in the description, the "seed" for every pass through the pseudo-rand generator after the first is the previously generated number. Unless you actually reset the system, and let it recreate that initial seed, the simple manipulations they do will have the same result every time. If you know what the current seed is, you could actually use a simple program/scipt/maybe even spreadsheet to predict what each subsequent "random" number will be. The only way it might fool you is if it calls the function from somewhere else you're unaware of, and gets ahead of you.

BadPotato wrote:where you get these number?? is it for a specific memory address?
Nah, it's hard-coded.

Code: Select all

RAM:800D4C2C Pseudo_rand:                             # DATA XREF: AK_Potch_Drop+24Co
RAM:800D4C2C                                          # AK_Potch_Drop+3D4o
RAM:800D4C2C                 lui     $v1, 0x41C6
RAM:800D4C30                 lw      $v0, 0x80109960
RAM:800D4C38                 li      $v1, 0x41C64E6D <---phone number
RAM:800D4C3C                 mult    $0, $v0, $v1
RAM:800D4C40                 mflo    $a0
RAM:800D4C44                 addiu   $v0, $a0, 0x3039 <--12345
RAM:800D4C48                 sw      $v0, 0x80109960
RAM:800D4C50                 srl     $v0, 16
RAM:800D4C54                 jr      $ra
RAM:800D4C58                 andi    $v0, 0x7FFF
Come to think of it, now that I've confirmed how the drops work, I might be able to mess up the random number generation so that it always creates numbers in ascending order from 0 to the adjusted drop chance of drop 3. An always drop, and cycle through drops code. I'll have to give it some thought.

User avatar
Pyriel
Webmaster
Posts: 959
Joined: Wed Aug 18, 2004 1:20 pm

Re: Game Mechanics And Codes

Postby Pyriel » Thu Jul 02, 2009 5:21 pm

Enemies Always Drop (Random)
D002E124 F809
8002E12C 0012
D002E124 F809
8002E12E 93A4
D002E124 F809
8002E130 0002
D002E124 F809
8002E132 1080
D002E124 F809
8002E134 0001
D002E124 F809
8002E136 2403
D002E124 F809
8002E138 1821
D002E124 F809
8002E13A 0004
D002E124 F809
8002E13C 001B
D002E124 F809
8002E13E 0043
D002E124 F809
8002E148 1810
D002E124 F809
8002E14A 0000

Enemies will always drop a random item from their drop table. The chances are still relative to the rarity of their individual drops. Using my hypothetical example above, you'd now have about a 16% chance of the antitoxin dropping, 16% for the Mega Medicine, and a 68% chance of getting the medicine.

I had partially written a code to enable you to change the drop number with button presses, but due to the limitations of most PS1 devices, it's just impractical to enter. Once I realized it was going to be about 60 lines long, I just stopped, and let it die.

I also wrote a code to change critical hit chances. The problem I've discovered is that the game has multiple logic paths for damage, and it seems like it follows a completely different one after the first round. Not sure what that's about yet.

User avatar
BadPotato
Posts: 170
Joined: Mon Feb 09, 2009 10:07 am
Location: Canada - Québec

Re: Game Mechanics And Codes

Postby BadPotato » Thu Jul 02, 2009 11:47 pm

Pyriel wrote:Enemies Always Drop (Random)
D002E124 F809
8002E12C 0012
D002E124 F809
8002E12E 93A4
D002E124 F809
8002E130 0002
D002E124 F809
8002E132 1080
D002E124 F809
8002E134 0001
D002E124 F809
8002E136 2403
D002E124 F809
8002E138 1821
D002E124 F809
8002E13A 0004
D002E124 F809
8002E13C 001B
D002E124 F809
8002E13E 0043
D002E124 F809
8002E148 1810
D002E124 F809
8002E14A 0000


since im using emulator with gameshark plugin I manage to make it work easily and it seem to work in any aera !!

can you explain how it work?

I feel like you success to modify an important "random number generator" because I'm getting some unexpected secondary effect.. like this. (in one turn jowy and riou getted knockdown by the woodpecker and millie about the third turn)

User avatar
Pyriel
Webmaster
Posts: 959
Joined: Wed Aug 18, 2004 1:20 pm

Re: Game Mechanics And Codes

Postby Pyriel » Fri Jul 03, 2009 9:22 am

You're just unlucky. I didn't do anything to the random number generator itself. It's used in too many places, and if they use it for things like drawing water effects, having it generate sequential or even predictable numbers is liable to make the game crash.

I just replaced the code in the drop logic that takes the random number the pseudo-rand function generates and fiddles it down to a number between 0 and 255. Now instead of doing that, the cheat transforms the random number into something between 0 and the highest drop number in the adjusted table. Using the hypothetical situation from my first post, the pseudo-rand function might return 0x1856AD34, and the game's original task would be to shift that around, add an arbitrary value to it, and then bitwise AND it with 0xFF to get a number from 0-255. With the code on, it will instead just load the highest adjusted drop-number which would be the 6 for the Mega Medicine, divide the 0x1856AD34 by that, and take the remainder as the result. So after killing an enemy with a drop table like this, the drop logic would always create a random number between 0 and 5.

For reference, the code changes this:

Code: Select all

RAM:8002E118                 la      $v0, Pseudo_rand      <--Load address of pseudo-rand function
RAM:8002E120                 lui     $v1, 0x8004      <--Tracing address
RAM:8002E124                 jalr    $v0         <--Call Pseudo-rand
RAM:8002E128                 sw      $v0, off_8003AEF0      <--Store address of pseudo rand for tracing?
RAM:8002E12C                 sll     $v1, $v0, 8      <--Shift result left 8 bits
RAM:8002E130                 subu    $v1, $v0         <--Subtract original result from shifted value
RAM:8002E134                 bgez    $v1, loc_8002E140      <--This and 8002E13C will add 0x7FFF...
RAM:8002E138                 nop
RAM:8002E13C                 addiu   $v1, 0x7FFF      <--...if the number is < 0
RAM:8002E140
RAM:8002E140 loc_8002E140:                            # CODE XREF: AK_Potch_Drop+3F0j
RAM:8002E140                 srl     $v1, 15         <--Shift the result right 15 bits
RAM:8002E144                 lbu     $v0, 0x40+var_30($sp)   <--Load the drop number for the first drop
RAM:8002E148                 andi    $v1, 0xFF         <--AND result with 0xFF.  Result is 0-255.


To:

Code: Select all

RAM:8002E118                 la      $v0, Pseudo_rand      <--Load address of pseudo-rand function
RAM:8002E120                 lui     $v1, 0x8004      <--Tracing address
RAM:8002E124                 jalr    $v0         <--Call Pseudo-rand
RAM:8002E128                 sw      $v0, off_8003AEF0      <--Store address of pseudo rand for tracing?
RAM:8002E12C££££Changes begin.
RAM:8002E12C                 lbu     $a0, 0x12($sp)      <--Load the third drop number
RAM:8002E130                 beqz    $a0, loc_8002E13C      <--If the third drop number is zero...
RAM:8002E134                 li      $v1, 1         <--...divisor = 1 and go to divide
RAM:8002E138                 mov     $v1, $a0         <--Otherwise, divisor = third drop number
RAM:8002E13C
RAM:8002E13C loc_8002E13C:
RAM:8002E13C                 divu    $v0, $v1         <--Divide random number by divisor
RAM:8002E140                 srl     $v1, 15         <--Moot operation.
RAM:8002E144                 lbu     $v0, 0x40+var_30($sp)   <--Load the drop number for the first drop
RAM:8002E148                 mfhi    $v1         <--Move the remainder of division to $v1

Hybridfurie
Posts: 25
Joined: Tue Jul 25, 2006 7:27 am

Re: Game Mechanics And Codes

Postby Hybridfurie » Sun Jul 12, 2009 1:59 am

I'm a bit interested here. This hacking's way above where I am now.

There were two codes I was interested for hacking for this game that I couldn't. One I think I may be able to do with some more knowledge of this, the other I'm still not sure why I can't already.

The first is linking a unit's War Battle strength with the unit leader's attack or defense respectively. Right now, I'm leaning towards adding the first byte of their level to it, if possible.

The second is enabling the fourth level spell of Riou's Bright Shield rune early. It seemed like something that I could find using a cheat engine, but I came up empty.

You're using PS2dis, right? From your notes I can discern a few of the commands and what they do. Is there a list somewhere I can use? Actually I can google that.

User avatar
Pyriel
Webmaster
Posts: 959
Joined: Wed Aug 18, 2004 1:20 pm

Re: Game Mechanics And Codes

Postby Pyriel » Sun Jul 12, 2009 9:08 am

I use IDA Pro, but PS2Dis is functional.

The war codes you might find tricky. As you've already noticed, the values move around a bit depending on the battle, and the executable code that handles wars is only loaded when it's necessary. The easiest thing to do would probably be to hook the "Display Unit Status" code, determine who the unit leader is, retrieve his level or whatever from the character status array, add that to the unit strength, and then store it back. You're probably talking about ten to twenty op codes.

Unlocking the Bright Shield Rune's fourth level spell would most likely be an event flag, or a flag in Riou's character data somewhere (possibly both). If you can give someone else the Bright Shield Rune, and it is locked or unlocked depending on the status of Riou's "copy", then it's almost certainly an event flag, unless they hard-coded the check to look at Riou's data. It could be as small as a single bit flag, which is a pain to find by difference searching. I'd probably take a peek through the game's code for a reference to the Bright Shield Rune's identifier number. It's fairly likely that there's a "LI blah, BSRuneID; beq/bne blah, vRunePos", or similar somewhere in it. That will tell you exactly how the game decides the fourth level spell has been unlocked. The extra benefit to this is that, if it's an event flag, it's possible the event flag has an effect on other things. If you can't change the event flag safely, you can generally modify game code that checks it for a specific purpose without side effects.

I don't know how easy it easy to find a complete listing of Emotion Engine op codes with Google, unless you know the right search terms. There are a lot of incomplete lists floating around, but I do keep a copy of Sony's full listings on my website: http://www.herrvillain.com/codebreaker/inst_0e.pdf

Hybridfurie
Posts: 25
Joined: Tue Jul 25, 2006 7:27 am

Re: Game Mechanics And Codes

Postby Hybridfurie » Sun Jul 12, 2009 1:31 pm

Excellent, thanks. As I recall, the 4th spell is blocked even on other people, so it's probably an event. It just puzzled me because I thought I should at least be able to find the switch for that flag, but I couldn't with the cheat engine.

Whew, IDA pro is pricey. I'll have to stick to what I have. That manual is fantastic. I had found a list of all the commands but it didn't really describe in detail what was going on. Mostly just equations, and I don't recognize all the symbols.

It will likely be a bit before I can actually do what I want here, but thanks. What you described for the War Unit idea is probably the most elegant solution, as it would only load when needed, and one code would work for every unit. I wonder if it uses that same routine for enemy units, though. That might be much more difficult than I thought.



Edit: Looking back at my notes, I do have the address line for the unit leader, at least. I wrote that the address directly after the war ability quantity codes held the unit leader value. I also wrote not to mess with it... can't remember why.. but since this just needs to call the value and not change it, it should be fine.

User avatar
BadPotato
Posts: 170
Joined: Mon Feb 09, 2009 10:07 am
Location: Canada - Québec

Re: Game Mechanics And Codes

Postby BadPotato » Wed Jul 15, 2009 1:41 pm

Pyriel wrote:I also wrote a code to change critical hit chances. The problem I've discovered is that the game has multiple logic paths for damage, and it seems like it follows a completely different one after the first round. Not sure what that's about yet.


maybe you should just try to find how to get an automatic knockdown.. if I remember correctly, you should deal critical dommage in same time than the knockdown status

brett
Posts: 7
Joined: Mon Feb 22, 2010 5:03 pm

Re: Game Mechanics And Codes

Postby brett » Tue Mar 02, 2010 8:41 pm

pyriel- i took ur codes and used them on my action replay they worked :) so they are pal compatible, im just atm trying to look at codes around it. there's a goodish one at 0000 for the last part of the code i get a drop off every enemy.

im trying to find codes where u can get enemies to drop the same item.

so u can have a different code per item. but im not having much luck as i dont understand it too well. ive tried changing the last 4 digits to your code to try and find them thinking they would all be in a row somewhere but to no avail.

D002E09A-1040
8002E152- 1000
D002E09A-1040
8002E152- ????
this code. i just changed the last 4 digits and fought a load of enemies to see what they dropped, it crashed a few times when i got something but i did find a lot of decent stuff. i was wondering if u could help find the codes.

User avatar
Pyriel
Webmaster
Posts: 959
Joined: Wed Aug 18, 2004 1:20 pm

Re: Game Mechanics And Codes

Postby Pyriel » Fri Apr 16, 2010 4:10 pm

Well, you're kind of working in the wrong direction trying to use those codes for that. I basically just modified the drop determination so that something always drops. The actual item being dropped isn't considered anywhere near that bit of the game's executable. It would certainly be possible fix it so that enemies always drop, and always drop a particular item, but you're not going to do it by just modifying values in those codes.

I don't think it would be terribly difficult to make an "always drop X" code, and you could possibly even cycle through the items. I can't make any promises, but if I have a spare moment and the initiative, I'll see what I can do.

brett
Posts: 7
Joined: Mon Feb 22, 2010 5:03 pm

Re: Game Mechanics And Codes

Postby brett » Fri Apr 16, 2010 5:05 pm

i have made a spread sheet so far with alot of stuff on it my most interesting find was a stone of magic x5 and i have found most of the armor but i haven been searching in a few weeks.

User avatar
Pyriel
Webmaster
Posts: 959
Joined: Wed Aug 18, 2004 1:20 pm

Re: Game Mechanics And Codes

Postby Pyriel » Tue Jun 28, 2011 3:25 pm

I did this in response to a request from suiko2fan2, and thought it was pretty cool.

Image
The Fire Rune has been upgraded a touch.

Image
Note that only the Hero is casting the spell.

The actual request was to edit the White Fang rune or some similar rune and turn into a Beast Rune. I'm still not sure if that's possible, but there are a bunch of skills with mangled names in the data. I think they'll all turn out to be effects mappings for the Alert Rune and such, but maybe not. The Champion Rune is pretty much just a flag that gets searched for in the encounter routines, and likewise for the Prosperity and Fortune Runes. Perhaps enough of them are of the hard-coded sort, and the Beast Rune skills will have enough availability to make this feasible.

User avatar
ninjaluc79
Posts: 848
Joined: Tue Sep 13, 2005 10:45 pm
Location: The Island Nations
Contact:

Re: Game Mechanics And Codes

Postby ninjaluc79 » Sun Jul 03, 2011 4:23 am

Is it possible to edit the stat growth rates of the characters?

This could help in simulating the non-Suikoden 2 characters such as Lazlo, The Prince of Falena and the Suikoden 5 characters, and Suikoden 3's Destroyers (please note that S3 Luc has slightly different stat growth rates than S2 Luc).

I can give some of the non-S2 characters' stat growths:

Lazlo (we can use *Black Sword with Forgiver Sign at level 4 to simulate *Punishment. Best suited with Killey.):

STR 05
TEC 05
MAG 05
SPD 05
PDF 04
MDF 03
LUC 02
HP 06

Frey (he doesn't have *Dawn here though, but you can use *Bright Shield to simulate it anyway. You can use Nanami to simulate him.):

STR 05
TEC 07
MAG 06
SPD 06
PDF 05
MDF 05
LUC 06
HP 05

Lyon (same as Frey, she doesn't have *Twilight here anymore. Just use any female swordsman to simulate her. About time to make some use off Hanna, don't you think?)

STR 06
TEC 05
MAG 05
SPD 07
PDF 04
MDF 04
LUC 04
HP 04

S4 Ted (hey, he's already dead! But you can simulate him just in case. I recommend Kinnison, but Ayda's also fine if you want Kinnison with Shiro.)

STR 03
TEC 06
MAG 08
SPD 05
PDF 01
MDF 07
LUC 03
HP 03

S4 Jeane (Yeah, right, you can't have her in your S2 party. But you can try if you want to. You can consider using Viki to simulate her, assuming rune affinities CAN be changed manually.)

STR 02
TEC 07
MAG 08
SPD 02
PDF 01
MDF 08
LUC 04
HP 02

Zerase (With all the rants about how broken she was in S5, now's the time to see if she's really a broken mage character. Eilie or Rina, it's your choice.)

STR 02
TEC 04
MAG 08
SPD 03
PDF 01
MDF 07
LUC 02
HP 03

Luca Blight (Huh? Really? But there's no Rage Sword Rune in S2! Use Viktor to simulate him.)

STR 08
TEC 05
MAG 04
SPD 04
PDF 06
MDF 02
LUC 02
HP 07

Yuber (Can't you think of other dummies asides Pesmerga?)

STR 08
TEC 06
MAG 06
SPD 04
PDF 07
MDF 05
LUC 02
HP 06

Sasarai (For comparison only. Replace Luc's *Wind with *Earth.)

STR 01
TEC 03
MAG 07
SPD 05
PDF 01
MDF 06
LUC 02
HP 03

S3 Luc (For comparison only with his S2 incarnation.)

STR 00
TEC 05
MAG 08
SPD 05
PDF 00
MDF 04
LUC 04
HP 04
It's not all about knowledge, but it helps.


Return to “Suikoden II”

Who is online

Users browsing this forum: Google [Bot] and 2 guests