Qhimm.com Forums

Miscellaneous Forums => Scripting and Reverse Engineering => Topic started by: antd on 2011-07-26 09:17:50

Title: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: antd on 2011-07-26 09:17:50
It seems it is impossible to win all item drops from multiple enemies.

Example:
Fighting two soldiers (shinra HQ) will not allow you to win 2x grenade (1 is max)
Fighting three soldiers will not allow you to win 3x grenade (2 is max)
Fighting three sneaky steps will not allow you to win 3x m-tentacles (2 is max)

Am I wrong about this? Anything known about the mechanics?

I've never seen 100% item drops from multiple enemies. Although it could be that the full drop is quite rare...
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: NxK on 2011-07-26 09:49:49
It seems it is impossible to win all item drops from multiple enemies.

Example:
Fighting two soldiers (shinra HQ) will not allow you to win 2x grenade (1 is max)
Fighting three soldiers will not allow you to win 3x grenade (2 is max)
Fighting three sneaky steps will not allow you to win 3x m-tentacles (2 is max)

Am I wrong about this? Anything known about the mechanics?

I've never seen 100% item drops from multiple enemies. Although it could be that the full drop is quite rare...

What is known about the mechanics is that an enemy will never yield more than 1 item. This means that if one were to steal an item from an enemy, that enemy could not drop another item at the same time. So, did you actually steal while doing these drop rate tests?
Apart from that, I would suggest that you calculate the expected probability of all enemies dropping an item. As it probably will not be so low in the cases you are mentioning, you could easily do enough test runs to come across statistically significant deviations from your calculations in case it were in fact impossible for all enemies to drop an item.
What I also find remarkable is that you are referring exclusively to instances of multiple enemies of only one type. Perhaps the peculiarity concerning the drop rate you seem to be experiencing only applies to these cases as well.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: nfitc1 on 2011-07-26 15:19:09
The RNG table in the KERNEL.BIN comes into full force in this one. Those values determine what is capable of dropping. There are slots in RAM for a max of at least four items (might be more) being dropped at the end of a battle, but the RNG values usually don't allow that. The (pseudo)code to determine if an item drops or not is as follows:

Code: [Select]
ItemDrop ( EnemyData, isDrop, AllowRandom, ChanceMultiplier)
{
   WORD dropped_item = -1; //no item
   for ( int i = 0; i < 4; i++ ) //loop through the enemies' held item data
   {
      if ( ( EnemyData(136 + i) ) AND C0h ) == isDrop )  //if isDrop is a 0 then we're looking for drop items instead of steal items
      {
         DropChance = AllowRandom ? 256 : ChanceMultiplier * ( ( EnemyData(136 + i) ) AND 3Fh ) / 256; //special battles (like bosses or WEAPONS) have guaranteed drop rates, otherwise we'll use chance)
/*
 *  The multiplier is usually worked like this:
 *
 *  ( ( Thiefs_Level + 40 - Targets_Level ) << 9 ) / 100
 *
 * If Targets_Level = Thiefs_Level it turns out to be 204, but the multiplier won't go higher than 200%
 */
         if ( ( RandomRNGByte AND 63h ) <= DropChance )
         {
            dropped_item = EnemyData(140 + i * 2);
         }
      }
   }
   return dropped_item;
}

Basically, in a normal battle, if the random byte AND 63h is less or equal to the item's drop chance * multiplier (which is signed, so you need to be at no fewer than 39 levels below your target enemy to even have a chance) then the item drops. An Eagle Gun (lvl 46) will never drop an X-Potion (rate of 63) if killed by a character at level 7 or below, but a Master Tonberry (Lvl 77) will have a 1:6.452 chance of dropping a Megalixer (rate of 8) for a level 99 character. A few conditions to this:

The first item an enemy holds that drops, drops.
ex.
The Special Combatant enemy from Reactor 5 has two items to drop. He can drop an Antidote at a rate of 8 and a Grenade at a rate of 2. If the Antidote doesn't drop, the game goes for the Grenade. So there's a 0.8:8, or 1:10, chance that an Antidote will drop. If it doesn't, there is another .8:32, or 1:40, chance that the Grenade will drop. There doesn't seem to be anything else that influences drop rates. I don't see where the game doesn't allow all enemies to drop things.

Like NxK said, the enemy won't drop anything if it has been stolen from.

Back to the issue, this is handled as the enemy dies. So if they don't all die at once the RNG is going to keep moving around. Getting it to cooperate, let alone knowing where the pointer is, is nigh impossible in most cases, but this is relatively easy. Since it just requests a byte the Random Number Set isn't incremented. So you're looking for a certain pattern in the RNGLUT. You need to find a chain of them that all meet that criteria. I'm not certain there are any that do. The RNGLUT may have been constructed in such a way that situations like that are difficult.

Moral is: it CAN produce drops from all enemies (or you wouldn't get drops from single enemy battles like Adamantaimai), but you haven't hit the right string of numbers yet. It would take at least 256 attempts to try all the patterns in the RNGLUT.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: antd on 2011-12-28 17:16:10
Back to the issue, this is handled as the enemy dies. So if they don't all die at once the RNG is going to keep moving around. Getting it to cooperate, let alone knowing where the pointer is, is nigh impossible in most cases, but this is relatively easy. Since it just requests a byte the Random Number Set isn't incremented. So you're looking for a certain pattern in the RNGLUT. You need to find a chain of them that all meet that criteria. I'm not certain there are any that do. The RNGLUT may have been constructed in such a way that situations like that are difficult.

Moral is: it CAN produce drops from all enemies (or you wouldn't get drops from single enemy battles like Adamantaimai), but you haven't hit the right string of numbers yet. It would take at least 256 attempts to try all the patterns in the RNGLUT.
I think this is the point I was missing! I thought ending the battle by a different frame would yield the full range of results. But this is wrong; it is when individual enemies die.

In this case, I will throw a right arm at 3 enemies of the same type. This will ensure all enemies die at the same time, right?

I've set up my script to kill all enemies delaying +1 frame each time, so it should hit each all possible RNG values.

It's tried 1000 attempts already and it has never hit 3 * T/S bomb drops from 3 * Flapbeats.
The most it has dropped is 2 * T/S bomb.

If this runs for over 65536 attempts, will this show that getting all item drops from multiple of the same enemy is impossible?
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: nfitc1 on 2011-12-28 20:12:30

If this runs for over 65536 attempts, will this show that getting all item drops from multiple of the same enemy is impossible?

Statistically I'd say yes. 256 attempts would be enough given there are only 256 values in the RNGLUT. However, there are eight pointers to it at any given time and I don't know for certain what each of them are for and when the game cycles though them nor at what rate. So 2048 (256 * 8 ) would be enough if you knew where the pointer started and what value was next in the RNGLUT. I'm not convinced that the RNG is shuffled every frame like other RPG games do.
That would only work for consecutive values, however. If you knew what value made an item drop and got the RNGLUT pointer back to that value for every enemy then you could likely get all the items from enemy drops. There is room in the data for four unique items although the quantity is variable. This point is moot because an enemy will only drop one item (if any) and there can only be three enemy types in a battle.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: Vgr on 2011-12-28 22:43:46
A neat way to find out would be to find out which offsets points to the Random Number Generator Look-Up Table then try each value.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: antd on 2011-12-29 13:26:58
Quote
A neat way to find out would be to find out which offsets points to the Random Number Generator Look-Up Table then try each value.
Yep, a good idea. But beyond my skills at the moment. I may try this when I have enough spare time to find the relevant memory addresses!

Statistically I'd say yes. 256 attempts would be enough given there are only 256 values in the RNGLUT. However, there are eight pointers to it at any given time and I don't know for certain what each of them are for and when the game cycles though them nor at what rate. So 2048 (256 * 8 ) would be enough if you knew where the pointer started and what value was next in the RNGLUT. I'm not convinced that the RNG is shuffled every frame like other RPG games do.
That would only work for consecutive values, however. If you knew what value made an item drop and got the RNGLUT pointer back to that value for every enemy then you could likely get all the items from enemy drops. There is room in the data for four unique items although the quantity is variable. This point is moot because an enemy will only drop one item (if any) and there can only be three enemy types in a battle.
Interesting info!

Currently at 44,000 attempts and no maximum item drops. Only, 0, 1, and 2 drops. Not 3.
I'll let this script run until it crashes or until it reaches 1 million attempts. On average, it is currently testing 140,000 attempts per day. So should hit 1 million in just over 1 week.

Surely if it reaches 1 million consecutive attempts it would have tried pretty much all variations of RNG position?
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: Vgr on 2011-12-29 17:02:00
I can do it for you if you want, given you already do a lot of work to do. I'll do it through Cheat Engine and pSX, but I think you'd probably prefer through psxjin given that's what you use for your TAS. Shouldn't be too hard. I don't know how to manipulate it *in* the game though.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: antd on 2011-12-29 22:44:19
I can do it for you if you want, given you already do a lot of work to do. I'll do it through Cheat Engine and pSX, but I think you'd probably prefer through psxjin given that's what you use for your TAS. Shouldn't be too hard. I don't know how to manipulate it *in* the game though.
oh nice! you can get the relevant memory addresses?
i can write a lua script (psxjin) that automatically changes the values in game and reports the item drop


also: 58,000 consecutive attempts so far and no 3*T/S bomb drop from 3*Flapbeats!
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: Vgr on 2011-12-30 01:34:08
Wait, to automatically change might work, but will it work if someone uses the file to replicate the run? Because AFAIK if you want to post it on TASvideos you need replayability (I had read their rules...) so unless the lua script gets along with the emulator movie file, I think there has to be some way around.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: Livesey on 2011-12-30 16:36:57
Please correct me if I'm being dumb but could you not change the drop values of a certain enemy to 255% in ProudClod and then test an enemy formation to see if the can get a 3x grenade drop?
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: antd on 2011-12-31 15:18:04
Wait, to automatically change might work, but will it work if someone uses the file to replicate the run? Because AFAIK if you want to post it on TASvideos you need replayability (I had read their rules...) so unless the lua script gets along with the emulator movie file, I think there has to be some way around.
Well I'm just doing this for my own knowledge. This part of the run will not be submitted to TASvideos.
It's purely to find out if maximum item drops are possible on enemies of the same type.

So, I just need to know which memory addresses are related to item drops.

Btw, 100,000 attempts and no 3*T/S bomb drop + the emulator crashed :D
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: Erzfreund on 2012-01-01 16:30:37
I can guarantee that it is possible to get all items as long as there are multiple win slots. For example Garuda at Dao Chao (Far right hand is the best spot for that).
I’ve also won three Eye Drops from six Battery Caps.


Quote
[…]but a Master Tonberry (Lvl 77) will have a 1:6.452 chance of dropping a Megalixer (rate of 8) for a level 99 character[…]

Hard to believe. Megalixer drops are quite common.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: antd on 2012-01-01 16:55:14

I’ve also won three Eye Drops from six Battery Caps.
That's not actually what I'm suggesting. In your example, you will not win an item from all enemies.
I've only seen evidence of winning all items from a single enemy.
I'm suggesting that you cannot win 3 eye drops from 3 battery caps. That's unless 1 battery cap can drop more than 1 eye drop.

Quote
as long as there are multiple win slots
When does this change? Will there be 3 win slots when facing 3 enemies of the same type?

Anyone that can provide a screenshot or video of winning all items from all enemies of the same kind? I don't think it can be done without cheat codes.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: Erzfreund on 2012-01-01 18:57:13
Ah, no I meant, that it could be possible, that the maximum drop for items is two, which is not the case. I believe, that you are right about the general impossibility of winning all items.


Garuda:
(Full List) Win: [ 8] Ice Crystal, [ 8] Bolt Plume, [ 8] Light Curtain,
                 [ 8] Mute Mask

http://youtu.be/heWRsQG8Vv8
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: nfitc1 on 2012-01-02 13:51:54
Please correct me if I'm being dumb but could you not change the drop values of a certain enemy to 255% in ProudClod and then test an enemy formation to see if the can get a 3x grenade drop?

This should be done before any more in-game testing as a proof of concept at least. If it's impossible then this would show it (although it would need to be set to 63 as 255 is a guaranteed stealable).
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: Vgr on 2012-01-02 14:01:25
Heck, why did nobody thought of that before? I feel so dumb now :P
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: NxK on 2012-01-02 23:32:23
I have tried out the 3 Sneaky Steps battle and easily won 3 M-Tentacles after having adjusted the drop rate to 63.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: Erzfreund on 2012-01-03 11:43:39
Ah, that's nice, but not really surprising (regarding the Turk battle at Gongaga).

What happens if the drop rate is set to 62? Especially when fighting Battery Caps. I think five of six Eye Drops is the best one can get.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: NxK on 2012-01-03 16:34:49
Even at a drop rate of 62, I got 6 Eye Drops in the 6 Battery Caps battle on my first attempt.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: nfitc1 on 2012-01-03 18:10:02
Try getting three different items from a battle with three types of enemies. I think that's possible too.
...(regarding the Turk battle at Gongaga)...

I think bosses have some kind of 'always drop item' flag to ensure drop. I think even a rate of 63 is less than 100% or can somehow be prevented by certain attacks like Remove of whatever.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: Livesey on 2012-01-03 18:10:33
Isn't 62 over 100%?
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: NxK on 2012-01-03 19:29:08
Isn't 62 over 100%?

According to TFergusson the probability is (Chance + 1)/64, which means that 63 would be equivalent to 100% and 62 would definitely be less than 100%.

Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: Livesey on 2012-01-03 19:52:33
Ahh, alright I must have been getting confused with the 255 thing.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: Bosola on 2012-01-04 11:16:35
The scope of the variable is 6 bits rather than a whole byte. I don't know what those other two bits signify - maybe they're flags for 'always drop' and 'null'?
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: nfitc1 on 2012-01-04 21:08:22
The scope of the variable is 6 bits rather than a whole byte. I don't know what those other two bits signify - maybe they're flags for 'always drop' and 'null'?

The lower of the two doesn't appear to be used at all. The upper one signifies the item can be stolen and not won.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: antd on 2012-01-13 00:53:20
I have tried out the 3 Sneaky Steps battle and easily won 3 M-Tentacles after having adjusted the drop rate to 63.
Is this the same in the PSX version?

Changing the drop rate manually may not show if it is possible in a real game.
Anyone have the memory address for 'drop rate' or a way that i can easily find it?

Also, can someone explain why I have not seen 3*item drops after 400,000 (and counting) consecutive attempts? Possibly too low level to win all items?
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: Livesey on 2012-01-13 10:21:25
The 100% chance showed that it is possible in thoery and it wouldn't break the game.

Does anyone know if changing the drops in ProudClod enables 3 item drops?
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: Vgr on 2012-01-13 14:32:42
Oh damn right andt!

The probability might be too low since you are at low levels. I'm not sure. I assume, though, that finding an address would do no good if you can't replicate it without cheating. NxK showed that it is theoretically possible.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: nfitc1 on 2012-01-13 15:36:01
Also, can someone explain why I have not seen 3*item drops after 400,000 (and counting) consecutive attempts? Possibly too low level to win all items?

Level doesn't factor into Item Drops. In fact, item drops are not considered until after the battle is over. Once the battle ends it loops through each defeated enemy and totals the exp, ap, and gil won from each enemy and items are dropped in the process. They're calculated like stealing items, but without initial level considerations.

Basically, if (random number AND 63) <= [drop chance] then the item will drop. The random number is determined completely by the RNGLUT in the KERNEL.BIN. The set is never incremented so it just cruises in a straight line down the numbers checking if they meet the criteria for dropping an item. Take a look at the RNGLUT in WM. I just copied that whole thing and did a MOD 64 on each entry in Excel. It looks like there isn't a place that will let you get six items from six different enemies unless those enemies have a high drop chance. It doesn't look like it's possible to get more than three from a Battery Cap x6 battle.

In order to be able to win six items from six enemies, the drop chances needs to be pretty high for an item.

Code: [Select]
Drop rate:    RNGLUT pointer:
27+           31, 32, 33, 120
26+           32, 33, 120
25+           120

As you can see, there has to be freakishly high rates of dropping for this to occur. A drop rate of 8 is typical for "common" items. Some go as high as 32, but that's Vlakorados and King Behemoth which are singular enemies.
Since most drop rates are 8, then it's impossible to win more than three from any number of enemies in a given battle. There's a 10/256 chance that that will occur.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: Livesey on 2012-01-13 19:48:39
Level doesn't factor into Item Drops. In fact, item drops are not considered until after the battle is over. Once the battle ends it loops through each defeated enemy and totals the exp, ap, and gil won from each enemy and items are dropped in the process. They're calculated like stealing items, but without initial level considerations.

Basically, if (random number AND 63) <= [drop chance] then the item will drop. The random number is determined completely by the RNGLUT in the KERNEL.BIN. The set is never incremented so it just cruises in a straight line down the numbers checking if they meet the criteria for dropping an item. Take a look at the RNGLUT in WM. I just copied that whole thing and did a MOD 64 on each entry in Excel. It looks like there isn't a place that will let you get six items from six different enemies unless those enemies have a high drop chance. It doesn't look like it's possible to get more than three from a Battery Cap x6 battle.

In order to be able to win six items from six enemies, the drop chances needs to be pretty high for an item.

Code: [Select]
Drop rate:    RNGLUT pointer:
27+           31, 32, 33, 120
26+           32, 33, 120
25+           120

As you can see, there has to be freakishly high rates of dropping for this to occur. A drop rate of 8 is typical for "common" items. Some go as high as 32, but that's Vlakorados and King Behemoth which are singular enemies.
Since most drop rates are 8, then it's impossible to win more than three from any number of enemies in a given battle. There's a 10/256 chance that that will occur.

Master of the Kernels you are my friend.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: antd on 2012-01-15 00:49:59
Is there anything in the code that shows it loops after 65536 frames? Because that is what it does in practice.

In my results I keep seeing the same loop of item drops after 65536 frames. And none of those results have a 3*item drop. This means, in this particular instance, it is not possible to get 3*item drop.

Here is the savestate: http://www.multiupload.com/UDRDKFIBAC
Here is the emulator which can load it: http://code.google.com/p/pcsxrr/
Load it by moving to sstates directory and pressing F1 in the emulaor.

If 3*drop from 3*enemy is possible, then there must be another factor in order to account for my results?
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: nfitc1 on 2012-01-15 13:53:58
I can't tell at it loops based on frame at all. I'm not sure if it is incremented on it's own like that.

And you won't be getting 3 items from 3 enemies without hacking. The most you'll get is two.
Title: Re: (FF7 PSX) Impossible to win all item drops from multiple enemies?
Post by: antd on 2012-01-15 23:22:01
Ok great. Nice to know it is in the code then :D
Thanks