Critical Failures Tables - Fallout2.exe

Discussion in 'Fallout General Modding' started by lisac2k, Apr 2, 2009.

  1. lisac2k

    lisac2k Vault Senior Citizen
    Modder

    Oct 26, 2004
    I'm interested in the way the critical failures work in Fallout 2, and since it hasn't been documented anywhere so far, this could be a chance to crack the nut.

    As it is already known, there are Critical Hit Tables in Fallout2.exe and those can be found here (pretty nice documented):
    http://falloutmods.wikia.com/wiki/Critical_hit_tables
    When you visit that page, take a look at this table (I'll name it 1st Table):
    Code:
    0x01000000 - knockout
    0x02000000 - knockdown
    0x04000000 - crippled left leg
    0x08000000 - crippled right leg
    0x10000000 - crippled left arm
    0x20000000 - crippled right arm
    0x40000000 - blinded
    0x80000000 - death
    0x00040000 - on fire - triggers the 'flamedance' animation, but not if the hit is fatal (probably a bug)
    0x00080000 - bypass armor
    0x00400000 - dropped weapon (doesn't work)
    0x00800000 - lose next turn
    0x00002000 - random
    Now, I have discovered a part of the exe which might contain similar data for the critical failures. It starts at 0x1074594 (or somewhere around this address) and contains the same flag bit fields that can be found in the "1st Table" (and which, btw, control what effects the critical failures causes). Some of those are:
    Code:
    0x01000000 - knockout
    0x00800000 - lose next turn
    0x00400000 - dropped weapon
    etc...
    The problem is, I've got problems understanding the critical table. The values are somewhat inconsistent and there could be (???) even some still unknown effects (flag bit fields), which can be found in the COMBAT.MSG file:
    Code:
    {300}{}{knocked out}
    {301}{}{knocked down}
    {302}{}{crippled his left leg}
    {303}{}{crippled his right leg}
    {304}{}{crippled his left arm}
    {305}{}{crippled his right arm}
    {306}{}{blinded}
    {307}{}{was killed}
    {308}{}{hit}
    {309}{}{critical}
    {310}{}{on fire}
    {311}{}{had his armor bypassed}
    {312}{}{his weapon exploded}
    {313}{}{his weapon destroyed}
    {314}{}{his weapon dropped}
    {315}{}{lost his next turn}
    {316}{}{hit himself}
    {317}{}{lost the rest of his ammo}
    {318}{}{fired a dud shot}
    {319}{}{hurt himself}
    {320}{}{hit randomly}
    {321}{}{crippled a random limb}
    {322}{}{peppered with fragments}
    I.e. the line #315 is shown when the unlucky person makes a critical miss (critical failure) and loses his/her next turn. However, this unlucky event is not defined in the first table, so we can only assume which value it takes in the flag bit fields. Also, it's impossible to find the numbers of the lines used for critical failures (300 to 322).

    I need help from someone more experienced when it comes to rummaging the executable. Anyone?
     
  2. Kanhef

    Kanhef Vault Dweller

    Sep 2, 2007
    I tried to find the failure data myself when extracting the critical hit tables, and didn't find it then. Looking at combat.msg, there are four sets of the same 23 messages, for male player, female player, male critters, and female critters. The table will probably contain offsets from the start of those groups, so the same table can be used for everyone.

    Also, I might have figured out how it decides which critical failures can occur with a given weapon. In the .pro files (http://falloutmods.wikia.com/wiki/PRO_File_Format#Weapons), I think the 'crit fail' field is mislabeled, and is the type of failures, not the chance. Its value is 0 for unarmed-class weapons, 1 for melee weapons, 2 for guns (large and small), 3 for energy weapons, and 4 for grenades. There are a few exceptions, though (some have an unexpected value, 5 and 6 are also used a few times), which troubles me. Might have to play a Jinxed game to test their behavior.
     
  3. lisac2k

    lisac2k Vault Senior Citizen
    Modder

    Oct 26, 2004
    Thanks for the reply.

    I've been playing around with Jinxed as well, simply because seeing a critical failure without that perk is almost impossible. You are right about the types of failures for each weapon. I.e. during my tests an unarmed attacking NPC managed to reproduce "lose his/her next turn" only. This is what I have seen so far:
    Code:
    Unarmed:
    {315}{}{lost his next turn}
    Code:
    Melee:
    {314}{}{his weapon dropped}
    {315}{}{lost his next turn}
    Code:
    Pistol (10mm Pistol):
    {313}{}{his weapon destroyed}
    {314}{}{his weapon dropped}
    {317}{}{lost the rest of his ammo} 
    {320}{}{hit randomly}
    Interesting, when I was testing the 10mm Pistol, the four critical failures were occurring almost exactly at 25% each. From 100 failures there was this ratio 18:29:26:27, where 18 is "weapon destroyed" and 27 is "hit randomly." Although it's not enough to draw the final conclusion, still it provides some info about the failures frequencies.
     
  4. lisac2k

    lisac2k Vault Senior Citizen
    Modder

    Oct 26, 2004
    OK, I think I got it!

    I was testing melee weapons and the side effects they produce when critical failure occurs. One of the side effects was:
    Code:
    Slaver critically missed and his weapon dropped.
    After comparing it to the COMBAT.MSG file, I found out that this message is combination of two strings which can be find in that file:
    Code:
    {514}{}{%s critically missed}
    {214}{}{your weapon dropped}
    So, I tried to find it as long unsigned bytes (little-endian, 0202 0000 D600 0000) and found it at the 0x00106D80. Also, there seem to be more side effects next to that one, and it looks like a critical failure table. I was using male player messages as the base (messages 200+ in the COMBAT.MSG file).

    I can provide list of side effects for all weapons (6 effects groups), so the exact size and look of the table can be determined.

    Kanhef?
     
  5. Kanhef

    Kanhef Vault Dweller

    Sep 2, 2007
    If it's not too much trouble, that list would be great. The bigger guns are more fun – I once had a flamer explode and set me on fire, with the 'flamedance' animation.

    I ran the Mac version through a disassembler, which gave promising results. It separated the 5% of the program file that is data from the rest of the executable code, which will make searching easier. Let me know if you want a copy. It also contains all the function names, which means there's a chance of figuring out how it works. Won't be easy, though; there are 3877 functions, and PowerPC assembly has about as much in common with x86 assembly as C does with Visual Basic.
     
  6. Lexx

    Lexx Background Radiant
    Moderator

    Apr 24, 2005
    Haha, nice. :lol: I didn't know that it is possible to burn yourself, but now it just seems logical.
     
  7. lisac2k

    lisac2k Vault Senior Citizen
    Modder

    Oct 26, 2004
    OK, here comes somewhat longer (but hopefully very informative) post about the messages used when a critical failure occurs.

    IMPORTANT:

    When putting the strings together, Fallout engine checks is there is more than 2 strings. If this is true, the engine separates the 1st and the 2nd string with space and comma (" ,"), and this "space+comma" can't be found in COMBAT.MSG - it is just added automatically.

    Also, there are combinations of strings where different ones are used for the same effect. This was done in order to avoid grammatical errors (i.e. singular/plural strings etc.) or to describe the same effect, but with variety of objects (i.e. crippled your left/right arm/leg.)

    On other note, some effects are heavy depending on LUCK stat. If this stat is set to certain value(s), some of the effects will not occur at all. For now, I have tested this for UNARMED and MELEE WEAPONS only.

    Whoever makes a critical failure, his name (string) is used to start the failure message. This is "You" ($506 in COMBAT.MSG) for Player or the name of the critter taken from the PRO_CRIT.MSG for NPCs/critters.

    I didn't manage to see these two messages:
    {221}{}{crippled a random limb}
    {222}{}{peppered with fragments}
    This doesn't mean they're not available. There could be something that triggers these messages, I just didn't stumbled upon it I guess. I was always linking these to robots, so they could be added to the player messages for the sake of consistency or something like that.

    Now, onto the message combos:

    Code:
    UNARMED (0)
    
    	A) critically missed and crippled your left/right arm/leg [ $514 + $108 + ($202 or $203 or $204 or $205) ]
    	B) critically missed and lost your next turn [ $514 + $108 + $215 ]
    	C) critically missed and took %d points, knocked down and hurt yourself [ ($533 or $534) + " ," + $201 + $108 + $219 ]
    	
    	All effects depend on Luck (LK):
    	A if LK 1-5
    	B if LK 1-10 (always)
    	C if LK 1-9
    Code:
    MELEE WEAPONS (1)
    
    	A) critically missed and your weapon dropped [ $514 + $108 + $214 ]
    	B) critically missed and lost your next turn [ $514 + $108 + $215 ]
    	C) critically missed and took %d hit points and hit yourself [ ($533 or $534) + $108 + $216 ]
    	D) critically missed and hit randomly [ $514 + $108 + $220 ]
    	
    	All effects depend on Luck (LK):
    	A if LK 1-10 (always)
    	B if LK 1-10 (always)
    	C if LK 1-5
    	D if LK 1-9
    Code:
    GUNS (2)
    	A) critically missed and your weapon dropped [ $514 + $108 + $214 ]
    	B) critically missed and lost the rest of your ammo [ $514 + $108 + $217 ]
    	C) critically missed and your weapon destroyed [ $514 + $108 + $213 ]
    	D) critically missed and hit randomly [ $514 + $108 + $220 ]
    Code:
    ENERGY WEAPONS (3)
    	A) critically missed, your weapon dropped and lost your next turn [ $514 + " ," + $214 + $108 + $215 ]
    	B) critically missed, lost your next turn and lost the rest of your ammo [ $514 + " ,"  + $215 + $108 + $217 ]
    	C) critically missed, your weapon exploded and lost your next turn [ $514 + " ," + $212 + $108 + $215 ]
    	D) critically missed and hit randomly [ $514 + $108 + $220 ]
    Code:
    GRENADES (4)
    	A) critically missed and your weapon dropped [ $514 + $108 + $214 ]
    	B) critically missed and took %d hit points, your weapon dropped and hurt yourself [ ($533 or $534) + " ,"  + $214 + $108 + $219 ]
    	C) critically missed and your weapon exploded [ $514 + $108 + $212 ]
    	D) critically missed and hit randomly [ $514 + $108 + $220 ]
    Code:
    FLAMERS (5)
    	A) critically missed and your weapon destroyed  [ $514 + $108 +$213 ]
    	B) critically missed and lost your next turn [ $514 + $108 + $215 ]
    	C) critically missed, on fire, your weapon exploded and lost your next turn [ $514 + " ," + $210 + " ," + $212 + $108 + $215 ]
    	D) critically missed and hit randomly [ $514 + $108 + $220 ]
    Code:
    ROCKET LAUNCHER (6)
    	A) critically missed and your weapon destroyed  [ $514 + $108 +$213 ]
    	B) critically missed and fired a dud shot [ $514 + $108 + $218 ]
    	C) critically missed, knocked down, your weapon exploded and lost your next turn [ $514 + " ," + $201 + " ," + $212 + $108 + $215 ]
    	D) critically missed and hit randomly [ $514 + $108 + $220 ]
     
  8. Kanhef

    Kanhef Vault Dweller

    Sep 2, 2007
    'Peppered with fragments' is used when you fire a rocket (and maybe grenades/anything with a blast radius) at short range and get caught in the blast. I usually see it with rocketbots; other critters seem smart enough to back off before using explosives.

    I'm not sure about 'crippled a random limb'. It resembles a critical hit effect used for robots' regulators (http://falloutmods.wikia.com/wiki/Critical_hit_tables#Robots), but that displays the names of the limb(s) affected. Maybe it was used at first, before they wrote the code to show the specific limb, or used for debugging.

    Some progress, I found the algorithms for choosing criticals. I confirmed the critical hit formula: random number in the range [1,100] + critical hit table modifier, with effects in the ranges (<21), (21-45), (46-70), (71-90), (91-100), and (>100).

    The critical failure formula is: random[1-100] - 5 * (luck - 5), and the effect ranges are (<21), (21-50), (51-75), (76-95), and (>95). A character with the average luck of 5 will have an unmodified roll. With 10 luck, the modified range is [-24,75], so you'll never get the two worst effects. With only 1 luck, the range is [21,120], and you can't get the least-bad result.

    So, there are five critical failures for each type of weapon. A character with 3 or 4 luck has a decent chance of seeing all of them, but it might be easier to go through twice with high- and low-luck characters. I can't say with certainty, but it looks like luck doesn't affect how often critical failures occur.
     
  9. lisac2k

    lisac2k Vault Senior Citizen
    Modder

    Oct 26, 2004
    Excellent! :drummer:

    This is indeed good news! I'll try nailing those missing effects down today and let you know about the progress.

    The funny thing, I thought I saw "the 5th effect" once during my testing sessions, but then I just continued thinking it will occur again... I'll keep watching for those.

    Oh, and thanks for the help about this issue. Fallout Wiki could be updated with this info soon, I guess.

    EDIT: About this part:
    For example, the "least-bad" effect for unarmed is
    The problem is that I get it always, even if LK=1. This could be explained with the fact that this effect for unarmed attacks was (most probably) used twice. Also, this assumption justifies the frequency of the effects, which is approx. (1*A : 2*B : 1*C) if LK=5.

    EDIT2: Now, testing the knife (melee weapons effects group [1]), and this is what I got:
    Code:
    Female Slaver NPC with Knife
      attacks
    Jinxed Player
    (Chance-To-Hit) CTH=25%
    
    *Attacker's Luck=10 (200 Misses):
    143 Misses
    57 Critical misses (28*A + 29*B + 0*C + 0*D)
    
    *Attacker's Luck=5 (200 Misses):
    124 Misses
    76 Critical misses (23*A + 33*B + 4*C + 19*D)
    
    *Attacker's Luck=1 (200 Misses):
    105 Misses
    95 Critical misses (21*A + 37*B + 24*C + 23*D)
    The worst two effects (C, D) are not occurring when LK=10, and that is OK - just like it's supposed to be. But the problem is that all of the effects can be seen when LK=1 :?

    The only possible explanation for this would be that some effects were used more than once (again, just like "unarmed"). Can you confirm this?

    By the way, I didn't manage to reproduce "the 5th failure effect" in any of the unarmed or melee weapons tests. Again, my hunch tells me some effects were used more than once...
     
  10. Kanhef

    Kanhef Vault Dweller

    Sep 2, 2007
    More than one of the failures having the same effect is certainly possible; it's been done with the critical hits. They'll probably all be distinct when using guns, which have more ways of failing.

    It looks like luck does affect the chance of critical failures; I really don't understand that part of the code yet.
     
  11. lisac2k

    lisac2k Vault Senior Citizen
    Modder

    Oct 26, 2004
    Yes, it's quite puzzling for me too.

    I tried digging through the code with hex editor, which is far less effective then your methods... Yet, didn't find anything useful. Some people are helping me determine the approximate formula for "upgrading" a miss to critical one (although I hope we'll test Jinxed trait too). The good people are on their way to develop a testing method to test thousands of shots in a relative short time. We'll see what's there to find.

    I did some testing with Jinxed and chance-to-hit 25% and the formula was something like (50-LK*2)%, ranging from 30% to 48% chance to upgrade a normal miss to critical one. The problem is, this formula doesn't seem to work for other chance-to-hit values (i.e. 50%). Would it be helpful to you to have more info about that?
     
  12. Kanhef

    Kanhef Vault Dweller

    Sep 2, 2007
    If a formula becomes apparent, it might be useful, but I wouldn't count on it. While the multi-way branches aren't too hard to spot, most of the code resists analysis. Without variable names it's very hard to tell what bits of data are used for.
     
  13. lisac2k

    lisac2k Vault Senior Citizen
    Modder

    Oct 26, 2004
    Thanks to Atom and Zabujca, two fine Poles, and Ghosthack, a marvelous Swede, who altogether managed to crack the mystery of critical misses/failures located in Fallout2.exe.

    Here's the link to the PDF version of the document covering this issue:

    http://fonlinedocs.netii.net/fo2calg.pdf

    It's not finished yet. There are still some unknown features regarding combat which need to be found.

    I hope someone will find this useful.

    EDIT: Forgot the question for Kanhef... Could you investigate the Unarmed Attack Armor Piercing effect, how it works and what is it depending on? If you find something in the Mac code, we could use it to track down the PC routines.
     
  14. Glovz

    Glovz Vault Dweller
    Modder

    Sep 16, 2005
    This effect/function:
    Would probably be what is responsible for hitting dead bodies. Many have mentioned previously they'd like to see the hitting of dead bodies removed or at least changed such that only living targets can be mistakenly hit.
     
  15. Kanhef

    Kanhef Vault Dweller

    Sep 2, 2007
    Nice work. The unarmed attacks might be tricky; I don't immediately see where it even decides which attack you use. I'll play around with a bit and see what I can find out.

    The hitting dead bodies is its own bug, I think. I don't understand this section very much yet – there are complicated things like objects representing the straight path from one tile to another – so I'm making some conjectures as to how it works.

    The function compute_attack is in charge of most of the process. Early on it makes a call to compute_spray; treating a single shot as a burst of 1 simplifies the code.

    compute_spray calls check_ranged_miss to determine what happens to bullets that miss their target outright. check_ranged_miss includes a call to critter_is_dead, so it doesn't hit dead bodies (or at least doesn't show any messages about it).

    If you don't miss completely, compute_spray later calls shoot_along_path so bullets can hit critters in the way, no matter how skilled you are. shoot_along_path does not check for critters being dead, which causes the bug. Somehow patching a check into there should fix it.

    The bug where all but one shot of a burst hits dead bodies is harder to find, but I think it depends on the other one and won't need a separate fix.


    Also, these might be useful.
    A list of all 3877 functions: F2_function_list.txt.
    And the functions again, with every call they make to other functions: F2_function_structure.txt.
    The order of functions is compiler-dependent, but the game structure will be similar.
     
  16. Josan12

    Josan12 Vault Senior Citizen

    Oct 15, 2007
    Please please please please please please fix this. I HATE 'accidentally' hitting dead bodies. Its a really stoopid bug that desperately needs to be fixed.
     
  17. Kanhef

    Kanhef Vault Dweller

    Sep 2, 2007
    I did some in-game testing, and it looks like the armor-piercing unarmed attacks ignore the target's damage threshold (DT), whereas armor-bypassing criticals ignore damage resistance. With the critical chance bonus from these attacks, it's not hard to get both at once.
     
  18. lisac2k

    lisac2k Vault Senior Citizen
    Modder

    Oct 26, 2004
    Erhm... Could you provide more details how this works? How often occurs armor-piercing-hit and armor-bypassing, respectively? What are they depending on (except the critical chance)?
     
  19. Kanhef

    Kanhef Vault Dweller

    Sep 2, 2007
    These unarmed attacks are always armor-piercing. Mentioning the armor-bypassing effect was probably confusing; that comes from critical hits, and there is no connection between them.
     
  20. Timeslip

    Timeslip Water Chip? Been There, Done That
    Modder

    Aug 15, 2007
    Looking at the code, that critter_is_dead check doesn't actually preclude hitting the dead critter, it just reduces the chances. (Fallout calculates the chance to hit normally, then checks if the critter is dead and replaces the chance with 5% if it is.) Also, either I have my function arguments backward for several of the other combat functions, or it's checking if the attacker is dead instead of the target... (Edit: and on closer inspection, it's all of my argument lables that are wrong. Guess I lose)

    In any case, now that I've found that bit of code I think I have enough information to fix it and to add an extra check to shoot_along_path. I just need to set up a save file with a minigun and a large pile of corpses. :twisted:

    Edit: Done. Starting from 1.43b, there's now a corpses-don't-block-line-of-fire option in sfall.

    The order of the functions may be different, but the order of function calls within each function is not, so that structure is sufficient to confidently name the majority of the functions in the windows version. That's incredibly useful. Thanks. :clap: