Engine reversing/exploration

Kanhef

Vault Dweller
Working my way through the code, I've found some information about how the special weapon perks work. Most of the functions are complicated, due to the number of factors involved, so I haven't figured out the details yet, but I can definitively say where they are used.

Weapon Long Range, Scope Range, Accurate, and Night Sight are used only in _determine_to_hit_func .

Penetrate and Knockback are used only in _compute_damage .

Fast Reload is used only in _item_w_mp_cost . This function appears to calculate the AP cost of all uses of a weapon (primary and secondary attacks, plus aimed versions, as well as reloading), so it's a bit of a nightmare. Having Fast Reload makes it promptly return 1.

Flameboy is used only in _pick_death , so it apparently affects just the death animation, and has no effect on damage or anything else.

Enhanced Knockout is used in _attack_crit_success , where it makes any critical hit knock out the victim, in addition to the regular critical effects. It is also used in _correctAttackForPerks, where it gives very strong characters a miniscule chance of causing knockout with a non-critical hit. Chance is 2% with ST 10, 1% with ST 9, none otherwise. However, there are no weapons that use this perk in the unmodded game.

_ai_best_weapon checks if a weapon has a perk, but doesn't care which one. I presume this makes the AI assign additional weight to weapons with perks.

The armor perks are only directly used by _adjust_ac ; it immediately hands them to _perk_add_effect (or _perk_remove_effect). Regular and Hardened PA have the Powered Armor perk. APA has Armor Advanced I, and APA mk2 has Armor Advanced II. Combat Armor (regular and mk2), Brotherhood Armor, and Tesla Armor all have the Combat Armor perk. I think these all give bonuses to radiation resistance, as well as the ST gain from the various PA.


I'll update this as I decipher more of the functions.
 
Just to mention this quick and hoping not to take this thread off topic.

The plate gloves I think was mentioned somewhere that they were intended to have the Enhanced Knockout perk.

Or maybe that's just my wish. :D
 
Wow! That's great!

Is there a known way to create new perks for weapons and use them?

And, what if I just add the Advanced Power Armor perk to the Leather Armor? Will it work without any problems?
 
Great work, Kanhef!

I agree with Glovz - we really need a weapon that uses the enhanced_knockout perk. It would be fun and really usefull to slavers trying to capture people alive (ravager69?)

It would be cool to put it on the plated gloves. It might even qualify for the RP as a function that was cut

Also - you've confirmed flameboy as useless. That's annoying - i really like the flamer and always hoped the MKII flamer was actually better. Is there anyway to edit it to give it a function? Any ideas on this?
 
Enhanced knockout + Slayer would make an interesting combination. Maybe good for a semi-pacifist game, so you can incapacitate people without killing them.

I seem to recall something about it and the plated gloves as well, but couldn't find a source for it – there's nothing in the Fallout Bible.

The weapon perks are hardcoded into the engine, so Timeslip's your man if you want new ones, or to make Flameboy more useful. As for armor, go ahead and see what happens.
 
Kanhef said:
Enhanced knockout + Slayer would make an interesting combination. Maybe good for a semi-pacifist game, so you can incapacitate people without killing them.

Yeah yeah yeah! Awesomeness! :D
 
Josan12 said:
Also - you've confirmed flameboy as useless.

Not if we can put it on the 10mm Pistol or the Spear and make people burst into flames after being shot or stabbed! Pyromaniac mod - every weapon has Flameboy.

Kanhef said:
Enhanced knockout + Slayer would make an interesting combination.

I was thinking it would be broken and maybe that's why they didn't include EK after all. Perhaps one could put it on the gloves used in the ring but not outside.
 
Per said:
Josan12 said:
Also - you've confirmed flameboy as useless.
Not if we can put it on the 10mm Pistol or the Spear and make people burst into flames after being shot or stabbed! Pyromaniac mod - every weapon has Flameboy.
Unfortunately, it doesn't change the damage type, so it has the same effect as the Bloody Mess trait. Might be good for making a weapon seem especially violent (e.g., the .44 Magnum).

Per said:
Kanhef said:
Enhanced knockout + Slayer would make an interesting combination.
I was thinking it would be broken and maybe that's why they didn't include EK after all. Perhaps one could put it on the gloves used in the ring but not outside.
Good point. That might be why there are two sets of boxing glove items (IDs 292, 293 and 496, 497).
 
Per said:
I was thinking it would be broken and maybe that's why they didn't include EK after all. Perhaps one could put it on the gloves used in the ring but not outside.

So is the enhanced_knockout function broken?? :( :cry: WHAAAA!!
*runs off to find Timeslip*
 
No, it works just fine. I think Per's objection is that instantly knocking out everything you hit isn't really how the game is supposed to play. A bit like how you win boxing matches in Jinxed games by waiting for the opponent to have a critical failure.
 
Kanhef said:
No, it works just fine. I think Per's objection is that instantly knocking out everything you hit isn't really how the game is supposed to play. A bit like how you win boxing matches in Jinxed games by waiting for the opponent to have a critical failure.

Ah ha. Ok i see. Yeah - it's definately vulnerable to being overpowered. Once you've got slayer it would be a bit ridiculous i guess. I wonder if there's a way to give the 'recipient' a chance to 'resist' the effect?? (AD&D styleeee)
 
Enhanced Knockout is used in _attack_crit_success , where it makes any critical hit knock out the victim, in addition to the regular critical effects. It is also used in _correctAttackForPerks, where it gives very strong characters a miniscule chance of causing knockout with a non-critical hit. Chance is 2% with ST 10, 1% with ST 9, none otherwise. However, there are no weapons that use this perk in the unmodded game.

Is it possible to make a weapon that would have this effect but only on a special map? Like with a script or something?
 
item_w_skill, which determines the skill used for an attack, mostly does what you'd expect, but the exact algorithm is worth mentioning. It first checks the attack mode: 'punch' and 'kick' use Unarmed, 'swing' and 'thrust' use Melee Weapons, and 'throw' uses Throwing. If the mode is 'fire single', 'fire burst', or 'flame', it next checks the damage type. A weapon dealing laser, plasma, or electrical damage uses the Energy Weapons skill. Otherwise it checks the 'big gun' flag; if set, Big Guns is used, and Small Guns if not. The order of operations is significant; cattle prods will be considered melee weapons even though they cause electrical damage.

So a taser (a good candidate for Enhanced Knockout) will be considered an energy weapon when fired. If you add a thrust attack (to simulate shocking someone by direct contact without firing), that will use the melee weapons skill.

I discovered that Fallout will run under gdb, which is awesome from a hacking perspective, but there's a slight problem: when a full-screen program hits a breakpoint, it can't be paused or hidden to get back to the debugger. It can be worked around by ssh'ing in from another computer and running it that way. Fallout plays on my main computer and gdb is accessible on the secondary.
 
Kanhef said:
item_w_skill, which determines the skill used for an attack, mostly does what you'd expect, but the exact algorithm is worth mentioning. It first checks the attack mode: 'punch' and 'kick' use Unarmed, 'swing' and 'thrust' use Melee Weapons, and 'throw' uses Throwing. If the mode is 'fire single', 'fire burst', or 'flame', it next checks the damage type. A weapon dealing laser, plasma, or electrical damage uses the Energy Weapons skill. Otherwise it checks the 'big gun' flag; if set, Big Guns is used, and Small Guns if not. The order of operations is significant; cattle prods will be considered melee weapons even though they cause electrical damage.

Right on. So, do you have any idea if it'd be possible to edit something to make melee weapons (that use swing or thrust) be able to cause other death animations? (for example the cattle prod cause the 'electrified' death)? Or do you think this info might help Timeslip change it in sfall??
 
I'm sure it's possible, but it hasn't been easy to figure out. I started by working on pick_death. It's a bit complicated (takes 6 arguments), but I have the gist of it. Which death animation is used primarily depends on one of the arguments, which I think is damage. If it's greater than or equal to 45, the more violent animation is used. In the range (15..44) the less bloody death is chosen. Otherwise the victim just falls down. This can then be affected by the violence level and Bloody Mess trait. The specific animation is then looked up based on the damage type.

Of course, there are special cases. If the target critter has a special death animation, it skips most of the logic and uses that. If the player is attacking, has the Pyromaniac perk, and is dealing fire damage, both cutoff values are set to 1, so the most violent animation available is used. If the weapon has Weapon Flameboy, it divides them by 3, irrespective of the damage type. (The compiler uses a clever trick: it actually multiplies by 0x55555556, treating it as a fixed-point decimal; more explanation here.) And if a Molotov Cocktail is used, it sets the cutoffs to 15 and 5, and changes the damage type to fire; it has to really be explosive to have a blast radius. Flameboy is applied after this, so the effect would be cumulative.

Interesting stuff, but not what we want. pick_death gets called by show_damage_to_object, which is a huge, 8-argument function. The call is a ways in, but I'll try to figure out what leads up to it. In the meantime, I've done some experimenting, and it seems that no melee weapons can cause death animations, but unarmed-class weapons can. <s>This suggests that there's a weapon type check somewhere that can be bypassed.</s> I've only tested a few combinations, but thrown weapons tend not to trigger death animations either. Plasma grenades don't, and frag grenades don't if causing fire damage, though they do blow people up normally.

Update: show_damage_to_object just passes args through, I can't learn anything there. It's used by the show_damage function. action_melee calls show_damage(x,y,0); action_ranged calls show_damage(x,y,z); action_explode calls show_damage(x,0,1). I'm guessing that the third argument indicates the damage type somehow, but that doesn't explain why unarmed attacks can trigger animations and thrown weapons don't.
 
Hmmm. Ok. So from your update, do you think there's no way to skip the 'weapon type check' or whatever is blocking melee weapons from causing death animations? Maybe if you can find approximately which offset is causing it Timeslip can put something in Sfall?? *looks hopeful* :D

Also - you say unarmed can potentially cause death animations ... any idea how the power fist could be set to cause the 'blow big hole in opponent' death animation? ;) :mrgreen:

Also2 - If you set a melee weapon to do explosive damage - it will work correctly, but not display the explsion graphic! Any idea why?
 
No, I meant that there didn't seem to be a simple check that can be easily skipped. However, taking another look at show_damage_to_target, I might have something. There's a sequence of three tests; if one passes (or fails, depending on the logic) it continues to the next, and if all three pass it makes the call to pick_death. If any of them fails, there's a call to check_death (which makes sure the animation is allowed by the violence setting and that the art for it exists), and then it branches past pick_death. So those tests are probably what prevents it from showing damage type based death animations.

I'll try to work on this more over the weekend. Meanwhile, I did some in-game experimenting and it looks like some of the code is awfully complicated:

Unarmed wepons can cause laser, fire, plasma, electrical, and explosive death animations. Making the power fist cause explosive damage would give you the 'big hole' effect and even tear people apart on high violence settings. Unfortunately, explosive weapons always have a blast radius, so it's rather suicidal unless you hack your character to be immune to explosions.

Only weapon that launch a projectile and cause explosive, plasma, or EMP damage (which determines the color) display an explosion and have a blast radius. This always works with explosive damage, but I can't consistently get it to work for the other two. Thrown weapons that cause any of the other damage type are not destroyed and appear on the ground; ammunition fired by another weapon is always destroyed, whatever the damage type.

Also, Living Anatomy is applied after the damage resistance calculations, so EMP grenades will do 5 damage to all non-robots. I haven't tested Bonus Ranged (or HtH) Damage, and how all of them affect burst attacks.
 
Well, I feel a bit foolish for not thinking of this earlier. Running F2 under gdb, I noticed it gave me names for the data in memory I was examining. Promptly dumped the symbol table - the disassembler had used function names, but not given me the table itself. You can get it here. I've stripped out the text (function) section, since I already have that in a more useful format (structure and plain list). I've broken it into blocks of more-or-less contiguous addresses, which essentially puts a gap at every large data structure.

The symbol table format is "<address> <section> <name>"; the sections are:
d - data (value stored in executable)
b - bss (dynamically allocated memory)
s - other symbol
u - unknown (mostly C library functions)
Upper/lower case relates to scope, not important here.

The contents of the data section are here. Its format is "<address> | <16 data bytes> <ascii equivalent>". The data is in four 4-byte big-endian words.

Update-
I've pulled apart the data blocks for skills, perks, and stats, found a few surprises. Several fields are always zero; I presume they're used in-game, but haven't looked at that yet.
Code:
Skill {
  0
  0
  0
  index
  base value
  multiplier
  stat1
  stat2 (-1 for none)
  1
  XP
  unknown (1 for Lockpick, Steal, Traps; 0 otherwise)
}
The starting value of a skill is 'base + multiplier * (stat1 + stat2)'. XP is the default experience for using the skill: 25 for Lockpick, Steal, Traps, and First Aid, 50 for Doctor, and 100 for Outdoorsman.
Code:
Stat {
  0
  0
  unknown
  min
  max
  default
}
The ranges of stats (inclusive):
Primary stats (1, 10); default 5
Max HP (0, 999)
Max APs (1, 99)
AC (0, 999)
Melee damage (0, 500)
Carry weight (0, 999)
Sequence (0, 60)
Healing rate (0, 30)
Critical chance (0, 100)
Critical roll modifier (-60, 100)
Damage threshold [all] (0, 100)
Damage resistance [EMP] (0, 100)
Damage resistance [others] (0, 90)
Radiation resistance (0, 95)
Poison resistance (0, 95)
Age (16, 101); default 25
Gender (0, 1) [0 = male, 1 = female]
Current HP, poison, radiation levels (0, 2000)
Skill points (0, maxint) [maxint = 2^31 - 1 = 2,147,483,647]
Level (1, 99)
Experience (0, maxint)
Reputation (-20, 20)
Karma (0, maxint)

Code:
Perk {
  0
  0
  unknown
  ranks
  min level
  stat (-1 for none)
  stat modifier
  skill1 (-1 for none)
  skill1 min
  operator
  skill2 (-1 for none)
  skill2 min
  ST
  PE
  EN
  CH
  IN
  AG
  LK
}
When gained, the perk increases stat by stat modifier, which may be negative. All other perk effects come from being specifically checked for by scripts or the engine. If a primary stat requirement is negative, that stat must be below the value specified (e.g., -7 indicates a stat must be less than 7). operator is only non-zero when there are two skill requirements. If set to 1, only one of those requirements must be met; if set to 2, both must be met.

Going through the perks, there were a few surprising differences with the manual. Master Trader requires 75 Barter, not 60; Heave Ho! has a maximum strength of 8; Pathfinder requires only 40 Outdoorsman, not 60; and Weapon Handling has a maximum strength of 6, not 9. The F1-only perks (Mental Block, Scrounger, etc.) are all there, but their minimum level is set to 310, so they're never available.
 
I did the same analysis on Fallout 1, and found some interesting differences, some of which may be significant for the F2->F1 conversion.

The perk structure doesn't include a second skill dependency. Bonus Rate of Fire requires 6 perception (the manual says 4). Rad Resistance increases the stat by 15, not 10! I confirmed this in-game on the Mac version, don't have the Windows version to test though.

If the base value of a skill depends on two primary stats, their sum is divided by two. This is not indicated in the data, and seems to be part of the engine.

Max HP, max AP, AC, melee damage, carry weight, sequence, and healing rate all have no upper bound. You'd never normally be able to reach the F2 limits, but it allows cheating with ridiculously high values instead of unusually high values. Age is capped at 35; I don't know what happens over time if you start that old. Poison and rad resistance can go up to 100%.

The last change has the greatest consequence for the total conversion. In F1, you can pop a couple of Rad-X at the Glow and not have to worry about radiation at all unless you read books or play chess. With the F2 engine, you'd still pick up some radiation. Using a geiger counter to monitor your rad count would be worthwhile, and you'd probably have to use at least one rad-away.
 
Great info, didn't know it too. But I am thinking about the age max 35 thing.. I mean, I never played a character that old, but wasn't it possible to get to at least 50 or so? I would test it now, but I am not at home...
 
Back
Top