Updated documentation on hook scripts.

Minor edits to missing d3dx9 dll message.
This commit is contained in:
NovaRain
2017-03-16 22:03:33 +08:00
parent 158234438b
commit bf61051887
3 changed files with 57 additions and 39 deletions
@@ -224,5 +224,4 @@
#define WPN_ANIM_MINIGUN (0x09) // (L)
#define WPN_ANIM_ROCKET_LAUNCHER (0x0A) // (M)
#endif // DEFINE_EXTRA_H
+51 -32
View File
@@ -6,29 +6,48 @@ Hook scripts are specially named scripts that are run by sfall at specific point
In addition to the bit of code it overrides, the script will be run once when first loaded and again at each player reload to allow for setup. Hook scripts have access to a set of arguments supplied to sfall, but aren't required to use them all. They also return one or more values, but again they're optional, and you only need to return a value if you want to override the default.
As good practise to aid in mod compatibility, only use the hs_xxx .int script if you are setting return values. For any other scripts, use a normal global script combined with register_hook or register_hook_proc.
To aid in mods compatibility, avoid using hs_xxx .int scripts. Instead it is recommended to use a normal global script combined with register_hook_proc or register_hook.
There are script functions specific to hook scripts:
Example setup for a hook-script based mod:
int init_hook()
procedure tohit_hook_handler begin
display_msg("Modifying hit_hook " + get_sfall_arg);
set_hit_chance_max(100);
set_sfall_return(100);
end
procedure start begin
if game_loaded then begin
register_hook_proc(HOOK_TOHIT, tohit_hook_handler);
end
end
There are script functions available, specific to hook scripts:
> int init_hook()
The hook script equivilent of game_loaded; it returns 2 when the script is first loaded, 1 when the player reloads and 0 otherwise.
mixed get_sfall_arg()
> mixed get_sfall_arg()
Gets the next argument from sfall. Each time it's called it returns the next argument, or otherwise it returns 0 if there are no more arguments left.
int get_sfall_args()
> array get_sfall_args()
Returns all hook arguments as a new temp array.
void set_sfall_return(int value)
> void set_sfall_return(int value)
Used to return the new values from the script. Each time it's called it sets the next value, or if you've already set all return values it does nothing.
void set_sfall_arg(int argnum, int value)
> void set_sfall_arg(int argnum, int value)
Changes argument value. This is usefull if you have several hook scripts attached to one hook point (see below).
void register_hook(int hooktype)
> void register_hook(int hooktype)
Used from a normal global script if you want to run it at the same point a full hook script would normally run. In case of this function, "start" proc will be execuded in a current global script. You can use all above functions like normal.
void register_hook_proc(int hooktype, proc procedure)
> void register_hook_proc(int hooktype, proc procedure)
The same as register_hook, except that you specifically define which procedure in the current script should be called as a hook (instead of "start"). Pass procedure the same as how you use dialog option functions. This IS the recommended way to use hook scripts, as it gives both modularity (each mod logic in a separate global script, no conflicts if you don't use "hs_*.int" scripts) and flexibility (you can place all related hook scripts for specific mod in a single script!).
NOTE: you can hook several scripts to a single hook point, for example if it's different mods from different authors or just some different aspects of one larger mod. In this case scripts are executed in reverse order of how they were registered. When one of the scripts in a chain returns value with "set_sfall_return", the next script may override this value if calls "set_sfall_return" again. Sometimes you need to multiply certain value in a chain of hook scripts.
@@ -56,7 +75,7 @@ The defines to use for the hooktype are in sfall.h.
----------- HOOK SCRIPT TYPES -------------
-------------------------------------------
hs_tohit.int
HOOK_TOHIT (hs_tohit.int)
Runs when fallout is calculating the chances of an attack striking a target
Runs after the hit chance is fully calculated normally, including applying the 95% cap
@@ -70,7 +89,7 @@ int ret1 - the new hit chance
-------------------------------------------
hs_afterhitroll.int
HOOK_AFTERHITROLL (hs_afterhitroll.int)
Runs after fallout has decided if an attack will hit or miss
@@ -86,7 +105,7 @@ critter ret3 - Override the target of the attack
-------------------------------------------
hs_calcapcost.int
HOOK_CALCAPCOST (hs_calcapcost.int)
Runs whenever fallout is calculating the ap cost of using the weapon (or unarmed attack). Doesn't run for using other item types or moving.
Note that the first time a game is loaded, this script doesn't run before the initial interface is drawn, so if the script effects the ap cost of whatever is in the players hands at the time the wrong ap cost will be shown. It will be fixed the next time the interface is redrawn.
@@ -101,7 +120,7 @@ int ret1 - The new ap cost
-------------------------------------------
hs_deathanim1.int
HOOK_DEATHANIM1 (hs_deathanim1.int)
Runs before fallout tries to calculate the death animation. Lets you switch out which weapon fallout sees
@@ -114,7 +133,7 @@ int ret1 - The pid of an object to override the attacking weapon with
-------------------------------------------
hs_deathanim2.int
HOOK_DEATHANIM2 (hs_deathanim2.int)
Runs after fallout has calculated the death animation. Lets you set your own custom frame id, so more powerful than hs_deathanim1, but performs no validation.
When using critter_dmg function, this script will also run. In that case weapon pid will be -1 and target will point to an object with obj_art_fid == 0x20001F5.
@@ -129,7 +148,7 @@ int ret1 - The death anim id to override with
-------------------------------------------
hs_combatdamage.int
HOOK_COMBATDAMAGE (hs_combatdamage.int)
Runs when:
1) Game calculates how much damage each target will get. This includes primary target as well as all extras (explosions and bursts). This happens BEFORE the actual attack animation.
@@ -156,7 +175,7 @@ int ret5 - The amount of knockback to the target
-------------------------------------------
hs_ondeath.int
HOOK_ONDEATH (hs_ondeath.int)
Runs immediately after a critter dies for any reason. No return values; this is just a convinence for when you need to do something after death for a large number of different critters and don't want to have to script each and every one of them.
@@ -164,7 +183,7 @@ Critter arg1 - The critter that just died
-------------------------------------------
hs_findtarget.int
HOOK_FINDTARGET (hs_findtarget.int)
Runs when the ai is trying to pick a target in combat. Fallout first chooses a list of 4 likely suspects, then normally sorts them in order of weakness/distance/etc depending on the ai caps of the attacker. This hook replaces that sorting function, allowing you to sort the targets in some arbitrary way. Use sfall_return to give the 4 targets, in order of preference. All 4 must be given if you want to override normal sorting; if you want to specify less than 4 targets fill in the extra spaces with 0's. If you do not give 4 targets, the npcs normal sorting mechanism will be used.
@@ -183,7 +202,7 @@ critter ret4 - The fourth choice of target
-------------------------------------------
hs_useobjon.int
HOOK_USEOBJON (hs_useobjon.int)
Runs when:
1) a critter uses an object on another critter. (Or themselves)
@@ -201,7 +220,7 @@ int ret1 - overrides hard-coded handler and selects what should happen with
-------------------------------------------
hs_useobj.int
HOOK_USEOBJ (hs_useobj.int)
Runs when:
1) a critter uses an object from inventory which have "Use" action flag set or it's an active flare or dynamite.
@@ -217,7 +236,7 @@ int ret1 - overrides hard-coded handler and selects what should happen with
-------------------------------------------
hs_removeinvenobj.int
HOOK_REMOVEINVENOBJ (hs_removeinvenobj.int)
Runs when an object is removed from a critters inventory for any reason
@@ -228,7 +247,7 @@ int arg4 - The reason the object is being removed. (Actually, the site from
-------------------------------------------
hs_barterprice.int
HOOK_BARTERPRICE (hs_barterprice.int)
Runs whenever the value of goods being purchased is calculated
@@ -240,13 +259,13 @@ int arg5 - the amount of actual caps in the barter stack (as opposed to good
int arg6 - the value of all goods being traded before skill modifications
critter arg7 - table of offered goods (being sold to NPC)
int arg8 - the total cost of the goods offered by the player
int arg9 - set 1 if the "offers" button was pressed (not for a party member), otherwise 0
int arg9 - set 1 if the "offers" button was pressed(not for a party member), otherwise 0
int ret1 - the modified value of all of the goods
-------------------------------------------
hs_movecost.int
HOOK_MOVECOST (hs_movecost.int)
Runs when calculating the ap cost of movement
@@ -280,7 +299,7 @@ object* ret1 - 0 if the hex doesn't block, or any sort of object pointer if it d
-------------------------------------------
hs_itemdamage.int
HOOK_ITEMDAMAGE (hs_itemdamage.int)
Runs when retriving the damage rating of the players used weapon. (Which may be their fists.)
@@ -296,7 +315,7 @@ int ret2 - The new maximum damage
-------------------------------------------
hs_ammocost.int
HOOK_AMMOCOST (hs_ammocost.int)
Runs when calculating ammo cost for a weapon. Doesn't affect damage, only how much ammo is spent.
By default, weapon will shoot when at least 1 round is left, regardless of ammo cost calculations.
@@ -312,7 +331,7 @@ int ret1 - new ammo cost value (set to 0 for unlimited ammo)
-------------------------------------------
hs_keypress.int
HOOK_KEYPRESS (hs_keypress.int)
Runs once every time when any key was pressed or released.
DX codes: (see dik.h header)
@@ -324,7 +343,7 @@ int arg3 - key VK code (very similar to ASCII codes)
-------------------------------------------
hs_mouseclick.int
HOOK_MOUSECLICK (hs_mouseclick.int)
Runs once every time when a mouse button was pressed or release.
@@ -333,7 +352,7 @@ int arg2 - button number (0 - left, 1 - right, up to 7)
-------------------------------------------
hs_useskill.int
HOOK_USESKILL (hs_useskill.int)
Runs when using any skill on any object.
@@ -350,7 +369,7 @@ int ret1 - overrides hard-coded handler (-1 - use engine handler, any other
-------------------------------------------
hs_steal.int
HOOK_STEAL (hs_steal.int)
Runs when checking an attempt to steal or plant an item in other inventory using Steal skill.
@@ -366,7 +385,7 @@ int ret1 - overrides hard-coded handler (1 - force success, 0 - force fail,
-------------------------------------------
hs_withinperception.int
HOOK_WITHINPERCEPTION (hs_withinperception.int)
Runs when checking if one critter sees another critter. This is used in different situations like combat AI. You can override the result.
@@ -382,7 +401,7 @@ int ret1 - overrides the returned result of the function: 0 - not in range (
-------------------------------------------
hs_inventorymove.int
HOOK_INVENTORYMOVE (hs_inventorymove.int)
Runs before moving items between inventory slots in dude interface. You can override the action.
What you can NOT do with this hook:
@@ -401,7 +420,7 @@ int ret1 - Override setting (-1 - use engine handler, any other value - prev
-------------------------------------------
hs_invenwield.int
HOOK_INVENWIELD (hs_invenwield.int)
Runs before wielding or unwielding an armor or a weapon by a critter (except when using inventory by PC).
An example usage would be to change critter art depending on armor being used or to dynamically customize weapon animations.
+6 -6
View File
@@ -839,20 +839,20 @@ static void DllMain2() {
if (GraphicsMode == 4 || GraphicsMode == 5) {
dlog("Applying dx9 graphics patch.", DL_INIT);
#ifdef WIN2K
HMODULE h = LoadLibraryEx("d3dx9_42.dll", 0, LOAD_LIBRARY_AS_DATAFILE);
if (!h) {
MessageBoxA(0, "You have selected graphics mode 4 or 5, but d3dx9_42.dll is missing\nSwitch back to mode 0, or install an up to date version of DirectX", "Error", 0);
#define _DLL_NAME "d3dx9_42.dll"
#else
HMODULE h = LoadLibraryEx("d3dx9_43.dll", 0, LOAD_LIBRARY_AS_DATAFILE);
if (!h) {
MessageBoxA(0, "You have selected graphics mode 4 or 5, but d3dx9_43.dll is missing\nSwitch back to mode 0, or install an up to date version of DirectX", "Error", 0);
#define _DLL_NAME "d3dx9_43.dll"
#endif
HMODULE h = LoadLibraryEx(_DLL_NAME, 0, LOAD_LIBRARY_AS_DATAFILE);
if (!h) {
MessageBoxA(0, "You have selected graphics mode 4 or 5, but " _DLL_NAME " is missing\nSwitch back to mode 0, or install an up to date version of DirectX", "Error", 0);
ExitProcess(-1);
} else {
FreeLibrary(h);
}
SafeWrite8(0x0050FB6B, '2');
dlogr(" Done", DL_INIT);
#undef _DLL_NAME
}
tmp = GetPrivateProfileIntA("Graphics", "FadeMultiplier", 100, ini);
if (tmp != 100) {