diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..365883a20 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file + +version: 2 +updates: + +- package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" + target-branch: "develop" + labels: + - "dependencies" diff --git a/README.md b/README.md index df7ffca32..968e5c59c 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,5 @@ Original description: A set of engine modifications for the classic game Fallout --- #### Fallout Engine IDA Database -**[Download](https://www.dropbox.com/s/tm0nyx0lnk4yui0/Fallout_1_and_2_IDA68.rar "Download from Dropbox")** (comments are in Russian) +[Download for IDA Pro 6.8](https://www.dropbox.com/s/tm0nyx0lnk4yui0/Fallout_1_and_2_IDA68.rar?dl=1 "Download from Dropbox") + | [Download for IDA Pro 7.0](https://www.dropbox.com/s/61srq09pn8grfpu/Fallout_1_and_2_IDA70.rar?dl=1 "Download from Dropbox") (comments are in Russian) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index d5f1f47d3..780f6ca7a 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -1,9 +1,10 @@ ;sfall configuration settings -;v4.3.4 +;v4.3.5 [Main] ;Set to 1 to enable the built-in High Resolution Patch mode that is similar to the hi-res patch by Mash ;The required settings will be read from the f2_res.ini configuration file of the original hi-res patch +;This option is always read from the main ddraw.ini file HiResMode=1 ;Set to 1 if you want to use command line arguments to tell sfall to use another ini file @@ -57,6 +58,7 @@ SpeedMultiInitial=100 ;Set to 6 for DX9 fullscreen windowed (the resolution in f2_res.ini should be set to the same aspect ratio as your desktop resolution) ;A DX9 mode is required for any graphics related script extender functions to work (i.e. fullscreen shaders) ;Modes 1, 2 and 3 are no longer supported +;This option will always be read from the main ddraw.ini file when using the hi-res patch by Mash Mode=0 ;If using a DX9 mode, this changes the resolution @@ -588,15 +590,12 @@ SuperStimExploitFix=0 InventoryApCost=4 QuickPocketsApCostReduction=2 -;Set to 1 to enable the balanced bullet distribution formula for burst attacks -ComputeSprayMod=0 - -;These options modify the bullet distribution of burst attacks if ComputeSprayMod is 1 -;All the bullets are divided into three groups: central, left and right -;These three groups will then travel along three parallel tracks, trying to hit targets on the way -;CenterMult/Div set the ratio of how many bullets go to the central group, and remaining bullets are divided equally to left and right sides -;TargetMult/Div set the ratio of how many bullets in the central group will attack the primary target directly -;Multipliers are capped at divisor values +;These options modify the bullet distribution of burst attacks +;All the bullets are divided into three groups: center, left, and right +;These groups will then travel along three parallel tracks, trying to hit targets on the way +;CenterMult/Div set the ratio of how many bullets go to the center group, and the remaining are divided equally to the left and right sides +;TargetMult/Div set the ratio of how many bullets in the center group will attack the primary target directly +;Multiplier values are capped at divisor values ComputeSpray_CenterMult=1 ComputeSpray_CenterDiv=3 ComputeSpray_TargetMult=1 @@ -741,10 +740,6 @@ CreateObjectSidFix=0 ;Note that enabling this option will cause problems for existing grave scripts GraveContainersFix=0 -;Set to 1 to fix the issue with the division operator treating negative integers as unsigned -;Note: To perform the unsigned integer division, use the new 'div' operator -DivisionOperatorFix=1 - ;Set to 1 to fix the priority score calculation for choosing the best weapon for NPCs ;Note that enabling this option can affect the weapon of choice for some NPCs AIBestWeaponFix=1 @@ -828,7 +823,7 @@ GlobalScriptPaths=scripts\gl*.int,scripts\sfall\gl*.int ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX [Debugging] ;Extra sfall configuration settings that can be used by modders -;This section is not effected by the 'UseCommandLine' option. It will always be read from the main ini +;This section is not affected by the 'UseCommandLine' option. It will always be read from the main ddraw.ini file ;Set to 1 to enable sfall debugging mode Enable=0 diff --git a/artifacts/mods/gl_npcarmor.int b/artifacts/mods/gl_npcarmor.int index 7c89d055c..9f8c4ba23 100644 Binary files a/artifacts/mods/gl_npcarmor.int and b/artifacts/mods/gl_npcarmor.int differ diff --git a/artifacts/mods/gl_npcarmor.ssl b/artifacts/mods/gl_npcarmor.ssl index b4c0741dd..7719a7996 100644 --- a/artifacts/mods/gl_npcarmor.ssl +++ b/artifacts/mods/gl_npcarmor.ssl @@ -224,12 +224,13 @@ procedure update_armor_apperance begin end procedure canuseweapon_handler begin - variable critter, canWield; + variable critter, canUse; critter := get_sfall_arg; if (critter != dude_obj and get_sfall_arg_at(3)) then begin - canWield := check_weapon_change(critter, get_sfall_arg, true); - // override result - set_sfall_arg(3, canWield); - set_sfall_return(canWield); + canUse := check_weapon_change(critter, get_sfall_arg, true); + if (canUse == false) then begin + set_sfall_arg(3, 0); + set_sfall_return(0); // overrides the result of engine function. Any non-zero value allows using the weapon + end end end diff --git a/artifacts/mods/gl_partycontrol.int b/artifacts/mods/gl_partycontrol.int index 418f41f7b..2fbc6be8f 100644 Binary files a/artifacts/mods/gl_partycontrol.int and b/artifacts/mods/gl_partycontrol.int differ diff --git a/artifacts/mods/gl_partycontrol.ssl b/artifacts/mods/gl_partycontrol.ssl index 900fa068a..d56bd3b74 100644 --- a/artifacts/mods/gl_partycontrol.ssl +++ b/artifacts/mods/gl_partycontrol.ssl @@ -60,6 +60,7 @@ procedure CombatTurn_Handler begin if (status == 1) then begin set_dude_obj(critter); + intface_redraw; //display_msg("Take control of: " + obj_name(critter)); if (critter != real_dude_obj) then begin @@ -78,7 +79,6 @@ procedure CombatTurn_Handler begin level := has_trait(TRAIT_PERK, real_dude_obj, perkID); if (level) then critter_add_trait(critter, TRAIT_PERK, perkID, level); end - intface_redraw; obj_set_light_level(critter, 100, 4); inControl := true; diff --git a/artifacts/scripting/compiler/sslc_readme.md b/artifacts/scripting/compiler/sslc_readme.md index 5a81e1bfe..77aefa50a 100644 --- a/artifacts/scripting/compiler/sslc_readme.md +++ b/artifacts/scripting/compiler/sslc_readme.md @@ -11,7 +11,7 @@ When compiling global or hook scripts for sfall 3.4 or below, you _must_ include This version of compiler was designed primarily for new sfall functions, but it can safely (and is recommended) to be used with non-sfall scripts as well, as long as you don't use any of the arrays syntax and any sfall script functions. -The original unmodified sslc source is over here: [http://www.teamx.ru/site_arc/utils/index.html](http://www.teamx.ru/site_arc/utils/index.html) +The original unmodified sslc source is over here: [https://teamx.ru/site_arc/utils/index.html](https://teamx.ru/site_arc/utils/index.html) ### Command line options @@ -121,7 +121,7 @@ Syntax which requires sfall for compiled scripts to be interpreted is marked by ``` __NOTE:__ If your expression starts with a constant (eg. `2 + 2`), enclose it in parentheses, otherwise compiler will be confused and give you errors. -- Hexadecimal numerical constants: Simply prefix a number with `0x` to create a hexadecimal. The numbers 0 to 9 and A-F are allowed in the number. The number may not have a decimal point. +- Hexadecimal numerical constants: Simply prefix a number with `0x` to create a hexadecimal. The numbers 0 to 9 and letters A to F are allowed in the number. The number may not have a decimal point. - new: ``` a := 0x1000; diff --git a/artifacts/scripting/functions.yml b/artifacts/scripting/functions.yml index 887c2642a..8b4a9aad1 100644 --- a/artifacts/scripting/functions.yml +++ b/artifacts/scripting/functions.yml @@ -542,11 +542,13 @@ - name: Audio items: - name: eax_available - detail: int eax_available + detail: int eax_available() opcode: 0x81a3 + doc: Obsolete since sfall 2.1a. Always returns 0. - name: set_eax_environment detail: void set_eax_environment(int environment) opcode: 0x81a4 + doc: Obsolete since sfall 2.1a. Has no effect. - name: play_sfall_sound detail: int play_sfall_sound(string file, int mode) @@ -631,7 +633,7 @@ doc: Arctangent of x. Pass 1 as y (don't ask...). opcode: 0x81f1 - name: ceil - detail: int ceil(float) + detail: int ceil(float x) opcode: 0x8266 doc: Round x to the nearest integer that is not less than x. - name: ^ @@ -948,7 +950,7 @@ - name: nb_create_char detail: int nb_create_char() opcode: 0x81f6 - doc: "`nb_*` functions are reserved for the brotherhood tactical training mod, and should be avoided." + doc: "`nb_*` functions are reserved for the brotherhood tactical training mod, and should be avoided. Not implemented, always returns 0." - name: get_proto_data detail: int get_proto_data(int pid, int offset) @@ -983,7 +985,7 @@ detail: int gdialog_get_barter_mod opcode: 0x824c - name: set_inven_ap_cost - detail: void set_inven_ap_cost + detail: void set_inven_ap_cost(int cost) opcode: 0x824d - name: game_loaded detail: int game_loaded() diff --git a/artifacts/scripting/sfall opcode list.md b/artifacts/scripting/sfall opcode list.md index a18b34cce..a1c14a97a 100644 --- a/artifacts/scripting/sfall opcode list.md +++ b/artifacts/scripting/sfall opcode list.md @@ -325,7 +325,7 @@ _^ - These functions require AllowUnsafeScripting to be enabled in ddraw.ini_ 0x824b - `int tile_under_cursor()`\ 0x824c - `int gdialog_get_barter_mod()`\ -0x824d - `void set_inven_ap_cost()` +0x824d - `void set_inven_ap_cost(int cost)` 0x825c - `void reg_anim_combat_check(int enable)`\ 0x825a - `void reg_anim_destroy(object object)`\ diff --git a/artifacts/scripting/sfall opcode list.txt b/artifacts/scripting/sfall opcode list.txt index eda120549..f0d6656a7 100644 --- a/artifacts/scripting/sfall opcode list.txt +++ b/artifacts/scripting/sfall opcode list.txt @@ -325,7 +325,7 @@ 0x824b - int tile_under_cursor() 0x824c - int gdialog_get_barter_mod() -0x824d - void set_inven_ap_cost() +0x824d - void set_inven_ap_cost(int cost) 0x825c - void reg_anim_combat_check(int enable) 0x825a - void reg_anim_destroy(object object) diff --git a/artifacts/translations/german.ini b/artifacts/translations/german.ini index 695628993..b158536d8 100644 --- a/artifacts/translations/german.ini +++ b/artifacts/translations/german.ini @@ -16,6 +16,8 @@ PartyOrderAttackHuman=Ich k PartyOrderAttackCreature=::Grrrr:: PartyOrderAttackRobot=::Piep:: +HiResInfo=Diese Version von Sfall verfügt über einen integrierten High Resolution Patch-Modus, der mit den Einstellungen des Hi-Res-Patch von Mash kompatibel ist.\n\nWenn der Hi-Res Patch von Mash weiterhin verwenden soll, deaktiviere die 'HiResMode'-Option in der ddraw.ini.\nUm die Grafikverbesserungen von Sfall zu erhalten, muss der originale Hi-Res-Patch deaktiviert werden.\n\nSoll der Hi-Res-Patch von Mash deaktiviert werden? + [AppearanceMod] RaceText=Geschlecht StyleText=Stil diff --git a/docs/index.md b/docs/index.md index 44b207732..d987a7295 100644 --- a/docs/index.md +++ b/docs/index.md @@ -37,5 +37,5 @@ Pay special attention to the [best practices]({{ site.baseurl }}/best-practices/ Next, proceed to discover new functions. They are categorized, use the menu to find the one you need. If you can't, check [uncategorized functions]({{ site.baseurl }}/other/) list and [sfall macros]({{ site.baseurl }}/sfall-funcx-macros/). Also, there's search at the top of the page. ## Questions and problems -* Report bugs and suggest features on [Github](https://github.com/phobos2077/sfall/issues). -* Ask questions and discuss on the [forum](https://nma-fallout.com/threads/fo2-engine-tweaks-sfall.178390/). +* Report bugs and suggest features on [Github](https://github.com/sfall-team/sfall/issues). +* Ask questions and discuss on the [forum](https://www.nma-fallout.com/threads/fo2-engine-tweaks-sfall.178390/). diff --git a/docs/optimization.md b/docs/optimization.md index 87ced15ee..c51d1954e 100644 --- a/docs/optimization.md +++ b/docs/optimization.md @@ -16,41 +16,48 @@ The executation speed of scripts is not typically important in an unmodded game, ## sslc -O option -The sfall build of sslc supports a -O command line option to perform an optimization pass over the generated code. This isn't a magic make-my-code-go-faster bullet; most of what it does is very limited in scope. It's primary purpose was to strip out the procedures and variables which get automatically pulled into every script that includes define.h, whether you use them or not, and to do something about the additional variables that get created by foreach loops. +The sfall build of sslc supports a `-O` command line option to perform an optimization pass over the generated code. This isn't a magic make-my-code-go-faster bullet; most of what it does is very limited in scope. It's primary purpose was to strip out the procedures and variables which get automatically pulled into every script that includes **define.h**, whether you use them or not, and to do something about the additional variables that get created by `foreach` loops. -There are several levels of optimization available: +**There are several levels of optimization available:** - `-O1` - Basic, only removes unreferenced globals variables and procedures, code itself remains untouched. - `-O2` - Full, most code optimizations are on, but only those that were tested on complex scripts. - `-O3` - Experimental, provides most efficiency, but tend to break some complex code due to bugs. -The following optimizations are performed: +**The following optimizations are performed:** - constant expression folding: if an expression depends only on values which are known at compile time, then the expression is replaced by its result. - `a:=2+2;` -> `a:=4;` + ``` + a := 2 + 2; -> a := 4; + ``` + - constant variable initialization: All variables are initialised to some value, ('0', if you don't specify anything else,) so sslc attempts to make use of that fact to remove the first assignment to a variable if the first assignment is a constant expression. ``` - variable a; -> variable a:=4; - a:=4; -> + variable a; -> variable a := 4; + a := 4; -> ``` + - constant propagation: checks for values assigned to variables which can be computed at compile time, and replaces relevent references to the symbol by the constant. The original store is not removed by this optimization. Global variables are considered for this optimization only if they are not marked import or export, and are not assigned to anywhere in the script. ``` - a:=4 -> a:=4 + a := 4; -> a := 4; foo(a); -> foo(4); ``` + - dead code removal: Checks for and removes code which cannot be reached, either because it is hidden behind a return or because the argument to an if statement can be computed at compile time. ``` - if 1 then begin -> display_msg("foo"); + if (True) then begin -> display_msg("foo"); display_msg("foo"); -> end else begin -> display_msg("bar"); -> end -> ``` -- unreferenced variable elimination: Checks for variables which are never referenced, and removes them. Also applies to global variables, as long as they are not marked for export. + +- unreferenced variable elimination: Checks for variables which are never referenced, and removes them. Also applies to global variables, as long as they are not marked for export. ``` variable i, j, k; -> variable i; - i:=1; -> i:=1; + i := 1; -> i := 1; return; -> return; ``` + - unreferenced procedure elimination: Checks for any procedures which are never called, and removes them. ``` procedure foo begin return "foo"; end -> procedure foo begin return "foo"; end @@ -59,31 +66,36 @@ The following optimizations are performed: display_msg(foo); -> end end -> ``` -- dead store removal: Removes variable assignments if the result of the variable is unused, and if the expression used to compute the value of the variable is provably free of side effects. (See 'pure' keyword) + +- dead store removal: Removes variable assignments if the result of the variable is unused, and if the expression used to compute the value of the variable is provably free of side effects. (See `pure` keyword) ``` - a:="moo"; -> a:="foo"; - a:="foo"; -> display_msg(a); + a := "moo"; -> a := "foo"; + a := "foo"; -> display_msg(a); display_msg(a); -> - a:="bar"; -> + a := "bar"; -> ``` + - store combination: Where there are two stores in a row to the same variable, the two expressions are combined. ``` var1 := var2; -> var1 := var2 + var3; - var1 += var3; -> + var1 += var3; -> ``` -- variable combination: Where usage regions of variables do not overlap, combine the variables to provide additional candidates for unreferenced variable elimination. Very useful for scripts containing multiple foreach loops, which generate 2 or 3 hidden variables each. + +- variable combination: Where usage regions of variables do not overlap, combine the variables to provide additional candidates for unreferenced variable elimination. Very useful for scripts containing multiple `foreach` loops, which generate 2 or 3 hidden variables each. ``` - a:="foo"; -> a:="foo"; + a := "foo"; -> a := "foo"; display_msg(a); -> display_msg(a); - b:="bar"; -> a:="bar"; + b := "bar"; -> a := "bar"; display_msg(b); -> display_msg(a); ``` + - namelist compression: Fallout stores the names of all file scope variables and procedures in a namelist which is saved into the .int. Any of these that are unreferenced can be removed, and the names of global variables can be modified to make them shorter. ## Writing your own code - Don't have global scripts running any more often that you need them to. Not everything needs to be run every single frame. -- Never concat constant strings with the '+' operator, as it forces the operation to be done at runtime. The compiler can cope with constant strings being placed next to each other without the need for a +, which results in far more efficient code as the combination is done at lex time. + +- Never concat constant strings with the `+` operator, as it forces the operation to be done at runtime. The compiler can cope with constant strings being placed next to each other without the need for a `+`, which results in far more efficient code as the combination is done at lex time. ``` #define GLOB_PREFIX "ts__" -> #define GLOB_PREFIX "ts__" @@ -91,15 +103,17 @@ The following optimizations are performed: set_sfall_global(GLOB_PREFIX + "foo1", 0); -> set_sfall_global(GLOB_PREFIX "foo1", 0); end -> end ``` -- Avoid function calls in while loops. function calls are expensive in comparison to variable lookups, so it's more efficient to move the function call out of the loop and store the result in a variable + +- Avoid function calls in `while` loops. Function calls are expensive in comparison to variable lookups, so it's more efficient to move the function call out of the loop and store the result in a variable. ``` - while i < len_array(array) do begin -> tmp:= len_array(array); + while i < len_array(array) do begin -> tmp := len_array(array); ... -> while i < tmp do begin end -> ... -> end ``` -- Mark functions with pure or inline where relevent. - 'pure' is a hint to the optimizer that a procedure has no side effects. (i.e. there's no way to tell that it's been called aside from its return value.) Pure procedures cannot modify global variables, or call any other procedure that isn't itself pure. Functions marked with pure can only be used in expressions (i.e. you cannot use the `call ` syntax to call them.) If there are non-pure terms in an expression, it prevents that expression being considered for dead store removal. Where no such optimizations can be performed, or if optimization is disabled, marking a procedure with pure will have no effect on the compiled code. +- Mark functions with `pure` or `inline` where relevent. + + * `pure` is a hint to the optimizer that a procedure has no side effects. (i.e. there's no way to tell that it's been called aside from its return value.) Pure procedures cannot modify global variables, or call any other procedure that isn't itself pure. Functions marked with pure can only be used in expressions (i.e. you cannot use the `call ` syntax to call them.) If there are non-pure terms in an expression, it prevents that expression being considered for dead store removal. Where no such optimizations can be performed, or if optimization is disabled, marking a procedure with pure will have no effect on the compiled code. - 'inline' is an instruction to the compiler to replace calls to the marked procedure with a copy of the procedures code instead of having a seperate call. inlined procedures cannot use the 'return' command, cannot be predefined, and cannot be used as part of an expression. inlining if a procedure is only going to be called once is always a win, but if there are multiple calls to a procedure you will end up bloating the size of the generated code. + * `inline` is an instruction to the compiler to replace calls to the marked procedure with a copy of the procedures code instead of having a seperate call. Inlined procedures cannot use the `return` command, cannot be predefined, and cannot be used as part of an expression. Inlining if a procedure is only going to be called once is always a win, but if there are multiple calls to a procedure you will end up bloating the size of the generated code. diff --git a/docs/sslc.md b/docs/sslc.md index 84720667c..2bd1a479d 100644 --- a/docs/sslc.md +++ b/docs/sslc.md @@ -15,13 +15,13 @@ This is a modified copy of sslc, that has a few bugfixes from the original, that Unlike the original script compiler, this has not been compiled as a dos program. When using this in place of the original compile.exe but still using p.bat, you need to either get rid of the dos4gw.exe reference from p.bat or replace the original dos4gw.exe with the one in this archive. -If you use fallout script editor, you can extract `compile.exe` and `dos4gw.exe` to its `\binary` folder, or extract them somewhere else and change your preferences in FSE to point there. FSE doesn't seem to be able to tell when errors occur when using this compiler though, so I'd recommend either using sfall's script editor instead or compiling by hand if possible. +If you use Fallout Script Editor, you can extract `compile.exe` and `dos4gw.exe` to its `\binary` folder, or extract them somewhere else and change your preferences in FSE to point there. FSE doesn't seem to be able to tell when errors occur when using this compiler though, so I'd recommend either using sfall's script editor instead or compiling by hand if possible. -When compiling global or hook scripts for sfall 3.4 or below, you _must_ include the line `procedure start;` before any `#include`s that define procedures to avoid a few weird problems. (this is no longer required starting from 3.5) +When compiling global or hook scripts for sfall 3.4 or below, you _must_ include the line `procedure start;` before any `#include` files that define procedures to avoid a few weird problems. (this is no longer required starting from 3.5) This version of compiler was designed primarily for new sfall functions, but it can safely (and is recommended) to be used with non-sfall scripts as well, as long as you don't use any of the arrays syntax and any sfall script functions. -The original unmodified sslc source is over here: [http://www.teamx.ru/eng/files/srcs/index.shtml](http://www.teamx.ru/eng/files/srcs/index.shtml). +The original unmodified sslc source is over here: [https://teamx.ru/site_arc/utils/index.html](https://teamx.ru/site_arc/utils/index.html) ## Command line options @@ -31,7 +31,9 @@ The original unmodified sslc source is over here: [http://www.teamx.ru/eng/files -b backward compatibility mode -l no logo -p preprocess source --O optimize code (full, see optimization.txt) +-P preprocess only (don't generate .int) +-F write full file paths in "#line" directives +-O optimize code (full by default, see "Optimization" page) -O set specific level of optimization (0 - off, 1 - basic, 2 - full, 3 - experimental) -d print debug messages -D output an abstract syntax tree of the program @@ -45,7 +47,7 @@ The original command line option `-w` to turn on warnings no longer has an effec ## Additional supported syntax -Syntax which requires sfall for compiled scripts to be interpreted, is marked by asterix (*). +Syntax which requires sfall for compiled scripts to be interpreted is marked by asterisk (*). - Optional arguments in user-defined procedures. You can only use constants for default values. It basically puts those constants in place of omitted arguments. @@ -73,14 +75,14 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by If `obj` is `null`, the second condition will not be checked and your script won't fail with "obj is null" error in debug.log - This also has an effect that a value of last computed argument is returned as a result of whole expressions, instead of always 0 (`false`) or 1 (`true`): + This also has an effect that a value of last computed argument is returned as a result of whole expressions, instead of always `false` (0) or `true` (1): ``` obj := false; display_msg(obj orElse "something"); // will print "something" ``` You can also use the `-s` option to enable short-circuit evaluation for all the `AND`, `OR` operators in the script. - NOTE: Be aware that it may break some old scripts because operators behavior is changed slightly. + __NOTE:__ Be aware that it may break some old scripts because operators behavior is changed slightly. - Conditional expressions (Python-inspired), also known as ternary operator: - new: @@ -94,7 +96,8 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by else X := value2; ``` -- To assign values, you can use the alternative assignment operator from C/Java instead of Pascal syntax. + +- To assign values, you can use the alternative assignment operator from **C/Java** instead of **Pascal** syntax. - new: ``` x = 5; @@ -103,7 +106,8 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by ``` x := 5; ``` -- Multiple variable declaration: Multiple variables can be declared on one line, seperated by commas. This is an alterative to the ugly begin/end block, or the bulky single variable per line style. + +- Multiple variable declaration: Multiple variables can be declared on one line, seperated by commas. This is an alterative to the ugly begin/end block, or the bulky single variable per line style. - new: ``` variable a, b, c; @@ -112,6 +116,7 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by ``` variable begin a; b; c; end ``` + - Variable initialization with expressions: You can now initialize local variables with complex expressions instead of constants. - new: ``` @@ -122,9 +127,9 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by variable tile; tile := tile_num(dude_obj); ``` - NOTE: if your expression starts with a constant (eg. `2+2`), enclose it in parentheses, otherwise compiler will be confused and give you errors. + __NOTE:__ If your expression starts with a constant (eg. `2 + 2`), enclose it in parentheses, otherwise compiler will be confused and give you errors. -- Hexadecimal numerical constants: Simply prefix a number with `0x` to create a hexadecimal. The numbers `0` to `9` and `a-f` are allowed in the number. The number may not have a decimal point. +- Hexadecimal numerical constants: Simply prefix a number with `0x` to create a hexadecimal. The numbers 0 to 9 and letters A to F are allowed in the number. The number may not have a decimal point. - new: ``` a := 0x1000; @@ -133,7 +138,8 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by ``` a := 4096; ``` -- Increment/decrement operators: `++` and `--` can be used as shorthand for `+=1` and `-=1` respectively. They are mearly a syntactic shorthand to improve readability, and so their use is only allowed where `+=1` would normally be allowed. + +- Increment/decrement operators: `++` and `--` can be used as shorthand for `+= 1` and `-= 1` respectively. They are mearly a syntactic shorthand to improve readability, and so their use is only allowed where `+= 1` would normally be allowed. - new: ``` a++; @@ -143,7 +149,7 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by a += 1; ``` -- `break` & `continue` statements: they work just like in most high-level languages. `break` jumps out of the loop. `continue` jumps right to the beginning of the next iteration (see `for` and `foreach` sections for additional details). +- `break` & `continue` statements: They work just like in most high-level languages. `break` jumps out of the loop. `continue` jumps right to the beginning of the next iteration (see `for` and `foreach` sections for additional details). - new: ``` while (i < N) begin @@ -187,18 +193,18 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by - new: ``` for (i := 0; i < 5; i++) begin - display_msg("i = "+i); + display_msg("i = " + i); end ``` - old: ``` i := 0; while (i < 5) do begin - display_msg("i = "+i); + display_msg("i = " + i); i++; end ``` - NOTE: `continue` statement in a `for` loop will recognize increment statement (third statement in parentheses) and will execute it before jumping back to the beginning of loop. This way you will not get an endless loop. + __NOTE:__ `continue` statement in a `for` loop will recognize increment statement (third statement in parentheses) and will execute it before jumping back to the beginning of loop. This way you will not get an endless loop. - `switch` statements: A shorthand way of writing big `if then else if...` blocks - new: @@ -222,7 +228,7 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by end ``` -- empty statements in blocks are allowed: This is just a convenience to save scripters a bit of memory. Some of the macros in the fallout headers include their own semicolons while others do not. With the original compiler you had to remember which was which, and if you got it wrong the script would not compile. Now it's always safe to include your own semicolon, even if the macro already had its own. For example, this would not compile with the original sslc, but will with the sfall edition: +- Empty statements in blocks are allowed: This is just a convenience to save scripters a bit of memory. Some of the macros in the Fallout headers include their own semicolons while others do not. With the original compiler you had to remember which was which, and if you got it wrong the script would not compile. Now it's always safe to include your own semicolon, even if the macro already had its own. For example, this would not compile with the original sslc, but will with the sfall edition: ``` #define my_macro diplay_msg("foo"); @@ -230,12 +236,9 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by my_macro; end ``` + __NOTE:__ **Does not work currently.** -- Procedure stringify operator `@`: designed to make callback-procedures a better option and allow for basic functional programming. Basically it replaces procedure names preceeded by `@` by a string constant. - Not many people know that since vanilla Fallout you can call procedures by "calling a variable" containing it's name as a string value. There was a couple of problems using this: - - optimizer wasn't aware that you are referencing a procedure, and could remove it, if you don't call it explicitly (can be solved by adding making procedure "critical") - - you couldn't see all references of a procedure from a Script Editor - - it was completely not obvious that you could do such a thing, it was a confusing syntax +- Procedure stringify operator `@`: Designed to make callback-procedures a better option and allow for basic functional programming. Basically it replaces procedure names preceeded by `@` by a string constant. - old: ``` callbackVar := "Node000"; @@ -246,7 +249,12 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by callbackVar := @Node000; callbackVar(); ``` -- *arrays: In vanilla fallout arrays had to be constructed by reserving a block of global/map variables. Since sfall 2.7, specific array targeted functions have been available, but they are fairly messy and long winded to use. The compiler provides additional syntactic shorthand for accessing and setting array variables, as well as for array creation. When declaring an array variable, put a constant integer in []'s to give the number of elements in the array. (before sfall 3.4 you had to specify size in bytes for array elements, now it's not required, see "arrays.txt" for more information) + Not many people know that since vanilla Fallout you can call procedures by "calling a variable" containing it's name as a string value. There was a couple of problems using this: + - optimizer wasn't aware that you are referencing a procedure, and could remove it, if you don't call it explicitly (can be solved by adding making procedure `critical`) + - you couldn't see all references of a procedure from a Script Editor + - it was completely not obvious that you could do such a thing, it was a confusing syntax + +- (*) **Arrays**: In vanilla Fallout, arrays had to be constructed by reserving a block of global/map variables. Since sfall 2.7, specific array targeted functions have been available, but they are fairly messy and long winded to use. The compiler provides additional syntactic shorthand for accessing and setting array variables, as well as for array creation. When declaring an array variable, put a constant integer in `[]`` to give the number of elements in the array. (before sfall 3.4 you had to specify size in bytes for array elements, now it's not required, see "Arrays" page for more information) - new: ``` procedure bingle begin @@ -267,7 +275,7 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by end ``` -- *array expressions: sometimes you need to construct an array of elements and you will probably want to do it in just one expression. This is now possible: +- (*) **Array expressions**: Sometimes you need to construct an array of elements and you will probably want to do it in just one expression. This is now possible: - new: ``` list := ["A", "B", "C", "D"]; @@ -280,14 +288,14 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by list[2] := "C"; list[3] := "D"; ``` - Syntax specific for associative arrays is also available. (see "arrays.txt" for full introduction to this type of arrays). + Syntax specific for associative arrays is also available. (see "Arrays" page for full introduction to this type of arrays). -- *map array expressions: +- (*) **Map array expressions**: ``` map := {5: "five", 10: "ten", 15: "fifteen", 20: "twelve"}; ``` -- * "dot" syntax to access elements of associative arrays. "dot" syntax allows to work with arrays like objects: +- (*) The dot `.` syntax to access elements of associative arrays and allow to work with arrays like objects: ``` trap.radius := 3; trap.tile := tile_num(dude_obj); @@ -296,16 +304,15 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by ``` collectionList[5].objectList[5].name += " foo"; ``` + __NOTE:__ When using incremental operators like `+=`, `*=`, `++`, `--` compiler will use additional temp variable to get an array at penultimate level in order to avoid making the same chain of `get_array` calls twice. - NOTE: when using incremental operators like `+=`, `*=`, `++`, `--` compiler will use additional temp variable to get an array at penultimate level in order to avoid making the same chain of "get_array" calls twice. - -- * `foreach` loops: A shorthand method of looping over all elements in an array. Syntax is `foreach ( in )`. +- (*) `foreach` loops: A shorthand method of looping over all elements in an array. Syntax is `foreach ( in )`. - new: ``` procedure bingle begin variable critter; foreach (critter in list_as_array(LIST_CRITTERS)) begin - display_msg(""+critter); + display_msg("" + critter); end end ``` @@ -322,6 +329,7 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by end end ``` + If you want an index array element (or key for "maps") at each iteration, use syntax: `foreach (: in )` ``` foreach (pid: price in itemPriceMap) begin @@ -329,15 +337,13 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by itemPrice := price; end ``` - If you want to add additional condition for continuing the loop, use syntax: `foreach ( in while )`. In this case loop will iterate over elements of an array until last element or until "while" expression is true (whatever comes first). - - NOTE: just like `for` loop, "continue" statement will respect increments of a hidden counter variable, so you can safely use it inside `foreach`. -## int2ssl note + If you want to add additional condition for continuing the loop, use syntax: `foreach ( in while )`. In this case loop will iterate over elements of an array until last element or until "while" expression is true (whatever comes first). -int2ssl by Anchorite (TeamX) is included in sfall modderspack package. It was updated to support all additional opcodes of sfall, along with some syntax features. You can use it to decompile any sfall or non-sfall script. + __NOTE:__ Just like `for` loop, `continue` statement will respect increments of a hidden counter variable, so you can safely use it inside `foreach`. ## Fixes + - `playmoviealpharect` was using the token for `playmoviealpha`, breaking both functions in the process. - `addbuttonflag` had an entry in the token table, and could be parsed, but was missing an entry in the emit list. This resulted in the compiler accepting it as a valid function, but not outputting any code for it into the compiled script. - The function `tokenize` was missing an entry in the token table, and so would not be recognised by the compiler. @@ -350,3 +356,7 @@ There are several changes in this version of sslc which may result in problems f - Missing a semicolon after a variable declaration is now a hard error. (Originally sslc would check for the semicolon, but would not complain if it was missing.) - The function `addbuttonflag` used to be recognised by the compiler, but would not emit any code into the int file. - The function `playmoviealpharect` compiled as `playmoviealpha`. + +## int2ssl note + +**int2ssl** by Anchorite (TeamX) is included in sfall modderspack package. It was updated to support all additional opcodes of sfall, along with some syntax features. You can use it to decompile any sfall or non-sfall script. diff --git a/sfall/FalloutEngine/EngineUtils.cpp b/sfall/FalloutEngine/EngineUtils.cpp index 64c151e71..0057a1300 100644 --- a/sfall/FalloutEngine/EngineUtils.cpp +++ b/sfall/FalloutEngine/EngineUtils.cpp @@ -214,6 +214,21 @@ fo::AttackSubType GetWeaponType(DWORD weaponFlag) { return (type < 9) ? weapon_types[type] : fo::AttackSubType::NONE; } +// Returns the distance a critter can move in combat based on current APs +long __fastcall GetCombatMoveDistance(fo::GameObject* critter, long freeMove) { + freeMove += critter->critter.movePoints; + long flags = critter->critter.damageFlags & (fo::DamageFlag::DAM_CRIP_LEG_LEFT | fo::DamageFlag::DAM_CRIP_LEG_RIGHT); + + // both legs crippled (8 AP per hex) + if (flags == (fo::DamageFlag::DAM_CRIP_LEG_LEFT | fo::DamageFlag::DAM_CRIP_LEG_RIGHT)) return (freeMove / 8); + + // not crippled + if (flags == 0) return freeMove; + + // one leg crippled (4 AP per hex) + return (freeMove / 4); +} + long ObjIsOpenable(fo::GameObject* object) { long result = 0; if (fo::func::obj_is_openable(object)) { diff --git a/sfall/FalloutEngine/EngineUtils.h b/sfall/FalloutEngine/EngineUtils.h index 72e23fb04..042cb377a 100644 --- a/sfall/FalloutEngine/EngineUtils.h +++ b/sfall/FalloutEngine/EngineUtils.h @@ -101,6 +101,9 @@ long GetCurrentAttackMode(); fo::AttackSubType GetWeaponType(DWORD weaponFlag); +// Returns the distance a critter can move in combat based on current APs +long __fastcall GetCombatMoveDistance(fo::GameObject* critter, long freeMove); + long ObjIsOpenable(fo::GameObject* object); bool HeroIsFemale(); diff --git a/sfall/FalloutEngine/FunctionOffsets_def.h b/sfall/FalloutEngine/FunctionOffsets_def.h index ab011c34b..d4eb43db8 100644 --- a/sfall/FalloutEngine/FunctionOffsets_def.h +++ b/sfall/FalloutEngine/FunctionOffsets_def.h @@ -1562,6 +1562,8 @@ FUNC(gsound_init_, 0x44FC70) FUNC(gsound_internal_background_callback_, 0x451AB0) FUNC(gsound_internal_effect_callback_, 0x451AD0) FUNC(gsound_internal_speech_callback_, 0x451A90) +FUNC(gsound_lrg_butt_press_, 0x451998) +FUNC(gsound_lrg_butt_release_, 0x4519A0) FUNC(gsound_load_sound_, 0x4510DC) FUNC(gsound_load_sound_volume_, 0x45145C) FUNC(gsound_med_butt_press_, 0x451988) @@ -4088,4 +4090,3 @@ FUNC(zcfree_, 0x4E3B84) FUNC(zero_vid_mem_, 0x4CADFC) FUNC(zlibVersion_, 0x4E3B50) FUNC(zupstr_, 0x4EEFF4) - diff --git a/sfall/FalloutEngine/Functions_def.h b/sfall/FalloutEngine/Functions_def.h index 8b844476f..3d2451fd3 100644 --- a/sfall/FalloutEngine/Functions_def.h +++ b/sfall/FalloutEngine/Functions_def.h @@ -191,6 +191,7 @@ WRAP_WATCOM_FUNC0(long, new_obj_id) WRAP_WATCOM_FUNC2(void, obj_bound, fo::GameObject*, object, fo::BoundRect*, boundRect) // Calculates bounding box (rectangle) for a given object WRAP_WATCOM_FUNC1(long, obj_destroy, fo::GameObject*, object) WRAP_WATCOM_FUNC2(long, obj_dist, fo::GameObject*, obj_src, fo::GameObject*, obj_trg) +WRAP_WATCOM_FUNC2(void, obj_drop, fo::GameObject*, source, fo::GameObject*, objectToDrop) WRAP_WATCOM_FUNC2(long, obj_erase_object, fo::GameObject*, object, fo::BoundRect*, boundRect) WRAP_WATCOM_FUNC0(fo::GameObject*, obj_find_first) WRAP_WATCOM_FUNC0(fo::GameObject*, obj_find_next) diff --git a/sfall/Game/items.cpp b/sfall/Game/items.cpp index 53f2a05a0..dc0754ea1 100644 --- a/sfall/Game/items.cpp +++ b/sfall/Game/items.cpp @@ -232,7 +232,7 @@ long __fastcall Items::item_w_mp_cost(fo::GameObject* source, fo::AttackType hit ); } -static void __declspec(naked) item_w_mp_cost_hack() { +static void __declspec(naked) item_w_mp_cost_replacement() { using namespace fo; __asm { push ebx; // isCalled @@ -248,7 +248,7 @@ void Items::init() { sf::HookCall(0x429A08, ai_search_inven_weap_hook); // Replace the item_w_mp_cost_ function with the sfall implementation - sf::MakeJump(fo::funcoffs::item_w_mp_cost_ + 1, item_w_mp_cost_hack); // 0x478B25 + sf::MakeJump(fo::funcoffs::item_w_mp_cost_ + 1, item_w_mp_cost_replacement); // 0x478B25 fastShotTweak = sf::IniReader::GetConfigInt("Misc", "FastShotFix", 0); } diff --git a/sfall/Game/tilemap.cpp b/sfall/Game/tilemap.cpp index 63ccc89be..620e1fefc 100644 --- a/sfall/Game/tilemap.cpp +++ b/sfall/Game/tilemap.cpp @@ -178,7 +178,7 @@ long __fastcall Tilemap::tile_num_beyond(long sourceTile, long targetTile, long } static void __declspec(naked) tile_num_beyond_replacement() { - __asm { //push ecx; + __asm { // push ecx; push ebx; mov ecx, eax; call Tilemap::tile_num_beyond; diff --git a/sfall/HRP/Init.cpp b/sfall/HRP/Init.cpp index 3e1a1dc79..cdc97f7b9 100644 --- a/sfall/HRP/Init.cpp +++ b/sfall/HRP/Init.cpp @@ -185,7 +185,7 @@ void Setting::init(const char* exeFileName, std::string &cmdline) { if (cmdline.find(" -restart") != std::string::npos) { GetBackupFileName(exeFileName, true); // delete after restart } - if (hiResMode == false) return; + if (!hiResMode) return; if (Setting::ExternalEnabled()) { char infoMsg[512]; @@ -252,7 +252,7 @@ void Setting::init(const char* exeFileName, std::string &cmdline) { MainMenuScreen::MAIN_MENU_SIZE = sf::IniReader::GetInt("MAINMENU", "MAIN_MENU_SIZE", 1, f2ResIni); SplashScreen::SPLASH_SCRN_SIZE = sf::IniReader::GetInt("STATIC_SCREENS", "SPLASH_SCRN_SIZE", 1, f2ResIni); - HelpScreen::HELP_SCRN_SIZE = sf::IniReader::GetInt("STATIC_SCREENS", "HELP_SCRN_SIZE", 0, f2ResIni); + HelpScreen::HELP_SCRN_SIZE = sf::IniReader::GetInt("STATIC_SCREENS", "HELP_SCRN_SIZE", 1, f2ResIni); DeathScreen::DEATH_SCRN_SIZE = sf::IniReader::GetInt("STATIC_SCREENS", "DEATH_SCRN_SIZE", 1, f2ResIni); SlidesScreen::END_SLIDE_SIZE = sf::IniReader::GetInt("STATIC_SCREENS", "END_SLIDE_SIZE", 1, f2ResIni); MoviesScreen::MOVIE_SIZE = sf::IniReader::GetInt("MOVIES", "MOVIE_SIZE", 1, f2ResIni); @@ -267,7 +267,7 @@ void Setting::init(const char* exeFileName, std::string &cmdline) { ViewMap::EDGE_CLIPPING_ON = (sf::IniReader::GetInt("MAPS", "EDGE_CLIPPING_ON", 1, f2ResIni) != 0); IFaceBar::IFACE_BAR_MODE = sf::IniReader::GetInt("IFACE", "IFACE_BAR_MODE", 0, f2ResIni); - IFaceBar::IFACE_BAR_SIDE_ART = sf::IniReader::GetInt("IFACE", "IFACE_BAR_SIDE_ART", 2, f2ResIni); + IFaceBar::IFACE_BAR_SIDE_ART = sf::IniReader::GetInt("IFACE", "IFACE_BAR_SIDE_ART", 1, f2ResIni); IFaceBar::IFACE_BAR_WIDTH = sf::IniReader::GetInt("IFACE", "IFACE_BAR_WIDTH", (!sf::versionCHI && SCR_WIDTH >= 800) ? 800 : 640, f2ResIni); IFaceBar::IFACE_BAR_SIDES_ORI = (sf::IniReader::GetInt("IFACE", "IFACE_BAR_SIDES_ORI", 0, f2ResIni) != 0); @@ -282,6 +282,10 @@ void Setting::init(const char* exeFileName, std::string &cmdline) { sf::WindowRender::EnableRecalculateFadeSteps(); } + int splashTime = sf::IniReader::GetInt("OTHER_SETTINGS", "SPLASH_SCRN_TIME", 0, f2ResIni); + if (splashTime > 10) splashTime = 10; + SplashScreen::SPLASH_SCRN_TIME = splashTime; + int nodes = sf::IniReader::GetInt("MAPS", "NumPathNodes", 1, f2ResIni); if (nodes > 1) game::Tilemap::SetPathMaxNodes((nodes < 20) ? nodes * 2000 : 40000); diff --git a/sfall/HRP/MainMenu.cpp b/sfall/HRP/MainMenu.cpp index 5b75140c7..68cfbefea 100644 --- a/sfall/HRP/MainMenu.cpp +++ b/sfall/HRP/MainMenu.cpp @@ -136,7 +136,7 @@ static long __fastcall main_menu_create_hook_add_win(long h, long y, long color, scaleHeight = (h / 480.0f); // is not scaled if USE_HIRES_IMAGES is used and the SCALE_BUTTONS_AND_TEXT_MENU option is disabled - if (MainMenuScreen::USE_HIRES_IMAGES == false || (MainMenuScreen::USE_HIRES_IMAGES && MainMenuScreen::SCALE_BUTTONS_AND_TEXT_MENU)) { + if (!sf::versionCHI && (!MainMenuScreen::USE_HIRES_IMAGES || (MainMenuScreen::USE_HIRES_IMAGES && MainMenuScreen::SCALE_BUTTONS_AND_TEXT_MENU))) { scaleFactor = scaleHeight; } else { if (w != 640) { diff --git a/sfall/HRP/MoviesScreen.cpp b/sfall/HRP/MoviesScreen.cpp index 57cc65c2e..e3261447c 100644 --- a/sfall/HRP/MoviesScreen.cpp +++ b/sfall/HRP/MoviesScreen.cpp @@ -41,6 +41,10 @@ static void __fastcall SetMovieSize() { long aspectH = sHeight; long x = 0; long y = 0; + + float movieAspect = (float)bW / (float)bH; + float marginHeight = (sHeight - (sWidth / movieAspect)) / 2; + if (marginHeight < subtitleHeight) aspectH -= subtitleHeight; // reserve space Image::GetAspectSize(bW, bH, &x, &y, aspectW, aspectH); movieToSize.left = x; diff --git a/sfall/HRP/SplashScreen.cpp b/sfall/HRP/SplashScreen.cpp index 5d3199fc9..536ea3c96 100644 --- a/sfall/HRP/SplashScreen.cpp +++ b/sfall/HRP/SplashScreen.cpp @@ -23,15 +23,20 @@ namespace sf = sfall; // 2 - image will stretch to fill the screen long SplashScreen::SPLASH_SCRN_SIZE; +long SplashScreen::SPLASH_SCRN_TIME; + static WORD rixWidth; static WORD rixHeight; static BYTE* rixBuffer; +static DWORD splashStartTime; static void __cdecl game_splash_screen_hack_scr_blit(BYTE* srcPixels, long srcWidth, long srcHeight, long srcX, long srcY, long width, long height, long x, long y) { RECT rect; long w = Setting::ScreenWidth(); long h = Setting::ScreenHeight(); + splashStartTime = GetTickCount(); + // TODO: Load an alternative 32-bit BMP image or DirectX texture // stretch texture for DirectX @@ -114,9 +119,26 @@ static void __declspec(naked) game_splash_screen_hook() { } } +static void SplashScreenTime() { + if (SplashScreen::SPLASH_SCRN_TIME >= 1) { + DWORD time = 1000 * SplashScreen::SPLASH_SCRN_TIME; + for (DWORD ticks = GetTickCount() - splashStartTime; ticks < time; ticks = GetTickCount() - splashStartTime) { + Sleep(500); + } + } +} + +static void __declspec(naked) game_init_hook_init_options_menu() { + __asm { + call SplashScreenTime; + jmp fo::funcoffs::init_options_menu_; + } +} + void SplashScreen::init() { sf::HookCall(0x4444FC, game_splash_screen_hook); sf::MakeCall(0x44451E, game_splash_screen_hack_scr_blit, 1); + sf::HookCall(0x442B0B, game_init_hook_init_options_menu); } } diff --git a/sfall/HRP/SplashScreen.h b/sfall/HRP/SplashScreen.h index 783d9d074..e96e5cfb4 100644 --- a/sfall/HRP/SplashScreen.h +++ b/sfall/HRP/SplashScreen.h @@ -14,6 +14,7 @@ class SplashScreen { static void init(); static long SPLASH_SCRN_SIZE; + static long SPLASH_SCRN_TIME; }; } diff --git a/sfall/IniReader.cpp b/sfall/IniReader.cpp index 7d8d69576..d46d22d02 100644 --- a/sfall/IniReader.cpp +++ b/sfall/IniReader.cpp @@ -50,6 +50,12 @@ static std::vector getList(const char* section, const char* setting return list; } +static int setInt(const char* section, const char* setting, int value, const char* iniFile) { + char buf[33]; + _itoa_s(value, buf, 33, 10); + return WritePrivateProfileStringA(section, setting, buf, iniFile); +} + const char* IniReader::GetConfigFile() { return ini; } @@ -107,9 +113,11 @@ std::vector IniReader::GetList(const char* section, const char* set } int IniReader::SetConfigInt(const char* section, const char* setting, int value) { - char buf[33]; - _itoa_s(value, buf, 33, 10); - return WritePrivateProfileStringA(section, setting, buf, ini); + return setInt(section, setting, value, ini); +} + +int IniReader::SetDefaultConfigInt(const char* section, const char* setting, int value) { + return setInt(section, setting, value, ddrawIni); } int IniReader::SetDefaultConfigString(const char* section, const char* setting, const char* value) { diff --git a/sfall/IniReader.h b/sfall/IniReader.h index eb3b0f896..563240417 100644 --- a/sfall/IniReader.h +++ b/sfall/IniReader.h @@ -65,6 +65,8 @@ class IniReader { static int SetConfigInt(const char* section, const char* setting, int value); + static int SetDefaultConfigInt(const char* section, const char* setting, int value); + static int SetDefaultConfigString(const char* section, const char* setting, const char* value); }; diff --git a/sfall/Modules/Animations.cpp b/sfall/Modules/Animations.cpp index 4b60f1b0e..447b53315 100644 --- a/sfall/Modules/Animations.cpp +++ b/sfall/Modules/Animations.cpp @@ -567,7 +567,7 @@ static void ApplyAnimationsAtOncePatches(signed char aniMax) { } void Animations::init() { - animationLimit = IniReader::GetConfigInt("Misc", "AnimationsAtOnceLimit", 32); + animationLimit = IniReader::GetConfigInt("Misc", "AnimationsAtOnceLimit", sfall::animationLimit); if (animationLimit < 32) animationLimit = 32; if (animationLimit > 32) { if (animationLimit > 127) animationLimit = 127; diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index d2577aef7..700393c74 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -3144,29 +3144,41 @@ static void __declspec(naked) op_create_object_sid_hack() { } } -// returns 0 (biped) if the critter has the "barter" flag set -static long __fastcall BarterOverrideBodyType(fo::GameObject* critter) { - return (fo::util::GetProto(critter->protoId)->critter.critterFlags & fo::CritterFlags::Barter) - ? fo::BodyType::Biped - : fo::BodyType::Quadruped; +// returns 0 (allows adding) if the critter has the "barter" flag set or its body type is "biped" +static long __fastcall CheckBarterAndBodyType(fo::GameObject* critter) { + fo::Proto* proto; + return (fo::util::GetProto(critter->protoId, &proto) && + !(proto->critter.critterFlags & fo::CritterFlags::Barter) && proto->critter.bodyType); } -static void __declspec(naked) item_add_mult_hook_body_type() { +static void __declspec(naked) item_add_mult_hook() { __asm { - call fo::funcoffs::critter_body_type_; - test eax, eax; - jnz notBiped; - retn; -notBiped: push edx; push ecx; - call BarterOverrideBodyType; // ecx - critter + call CheckBarterAndBodyType; // ecx - critter pop ecx; pop edx; retn; } } +// similar to critter_is_active_ function, with additional check for being knocked down in combat +static long __fastcall TargetIsActiveForPush(fo::GameObject* source, fo::GameObject* target) { + if (target->critter.IsNotActive()) return 0; + if (target->critter.damageFlags & fo::DamageFlag::DAM_KNOCKED_DOWN && fo::var::combat_state & fo::CombatStateFlag::InCombat) return 0; + return (target->critter.IsDead()) ? 0 : 1; +} + +static void __declspec(naked) action_can_be_pushed_hook() { + __asm { + push ecx; + call TargetIsActiveForPush; // ecx - source, edx - target + pop ecx; + mov edx, ebx; // restore target + retn; + } +} + void BugFixes::init() { #ifndef NDEBUG @@ -3195,11 +3207,11 @@ void BugFixes::init() SafeWrite16(0x46A4E7, 0x04DB); // Fix for vanilla division operator treating negative integers as unsigned - if (IniReader::GetConfigInt("Misc", "DivisionOperatorFix", 1)) { + //if (IniReader::GetConfigInt("Misc", "DivisionOperatorFix", 1)) { dlog("Applying division operator fix.", DL_FIX); SafeWrite32(0x46A51D, 0xFBF79990); // xor edx, edx; div ebx > cdq; idiv ebx dlogr(" Done", DL_FIX); - } + //} //if (IniReader::GetConfigInt("Misc", "SpecialUnarmedAttacksFix", 1)) { dlog("Applying Special Unarmed Attacks fix.", DL_FIX); @@ -3986,7 +3998,10 @@ void BugFixes::init() SafeWrite8(0x4B039F, 20); // text_object_create_ (was 19) // Fix for being unable to plant items on non-biped critters with the "Barter" flag set (e.g. Skynet and Goris) - HookCall(0x477183, item_add_mult_hook_body_type); + HookCall(0x477183, item_add_mult_hook); + + // Fix for being able to use the "Push" action on members of the player's team in combat when they are knocked down + HookCall(0x413718, action_can_be_pushed_hook); } } diff --git a/sfall/Modules/BurstMods.cpp b/sfall/Modules/BurstMods.cpp index 7d4f7262e..efd0e3077 100644 --- a/sfall/Modules/BurstMods.cpp +++ b/sfall/Modules/BurstMods.cpp @@ -17,7 +17,6 @@ */ #include "..\main.h" -#include "..\Logging.h" #include "BurstMods.h" @@ -67,8 +66,8 @@ static void __declspec(naked) compute_spray_rounds_distribution() { } void BurstMods::init() { - if (IniReader::GetConfigInt("Misc", "ComputeSprayMod", 0)) { - dlog("Applying ComputeSpray changes.", DL_INIT); + //if (IniReader::GetConfigInt("Misc", "ComputeSprayMod", 0)) { + dlog("Applying ComputeSpray settings to burst attacks.", DL_INIT); compute_spray_center_mult = IniReader::GetConfigInt("Misc", "ComputeSpray_CenterMult", 1); compute_spray_center_div = IniReader::GetConfigInt("Misc", "ComputeSpray_CenterDiv", 3); if (compute_spray_center_div < 1) { @@ -87,7 +86,7 @@ void BurstMods::init() { } MakeJump(0x4234F1, compute_spray_rounds_distribution); dlogr(" Done", DL_INIT); - } + //} } } diff --git a/sfall/Modules/Credits.cpp b/sfall/Modules/Credits.cpp index ee31efdec..d771ea244 100644 --- a/sfall/Modules/Credits.cpp +++ b/sfall/Modules/Credits.cpp @@ -40,6 +40,7 @@ static const char* ExtraLines[] = { "Timeslip", "", "@Contributors", + "@(in chronological order)", "ravachol", "Noid", "Glovz", diff --git a/sfall/Modules/Graphics.cpp b/sfall/Modules/Graphics.cpp index ecf421613..a9e000c09 100644 --- a/sfall/Modules/Graphics.cpp +++ b/sfall/Modules/Graphics.cpp @@ -1246,7 +1246,9 @@ static __declspec(naked) void dump_screen_hack_replacement() { } void Graphics::init() { - int gMode = IniReader::GetConfigInt("Graphics", "Mode", 0); + int gMode = (HRP::Setting::ExternalEnabled()) // avoid mode mismatch between ddraw.ini and another ini file + ? IniReader::GetIntDefaultConfig("Graphics", "Mode", 0) + : IniReader::GetConfigInt("Graphics", "Mode", 0); if (gMode >= 4) Graphics::mode = gMode; if (Graphics::mode < 0 || Graphics::mode > 6) { @@ -1270,7 +1272,7 @@ void Graphics::init() { SafeWrite8(0x50FB6B, '2'); // Set call DirectDrawCreate2 HookCall(0x44260C, game_init_hook); - MakeJump(fo::funcoffs::GNW95_SetPaletteEntries_ + 1, GNW95_SetPaletteEntries_replacement); // 0x4CB311 + MakeJump(fo::funcoffs::GNW95_SetPaletteEntries_ + 1, GNW95_SetPaletteEntries_replacement); // 0x4CB310 MakeJump(fo::funcoffs::GNW95_SetPalette_, GNW95_SetPalette_replacement); // 0x4CB568 // Replace the screenshot saving implementation for sfall DirectX 9 diff --git a/sfall/Modules/Interface.cpp b/sfall/Modules/Interface.cpp index 20fd21ee9..f561b62c1 100644 --- a/sfall/Modules/Interface.cpp +++ b/sfall/Modules/Interface.cpp @@ -800,6 +800,37 @@ static void __declspec(naked) wmInterfaceInit_hook() { } } +static void __declspec(naked) wmWorldMap_hook() { + __asm { + push eax; + mov eax, 0x503E14; // 'ib1p1xx1' + call fo::funcoffs::gsound_play_sfx_file_; + pop eax; + jmp fo::funcoffs::wmPartyInitWalking_; + } +} + +static void __declspec(naked) wmDrawCursorStopped_hack_hotspot() { + __asm { + mov eax, 0x503E34; // 'ib2p1xx1' + call fo::funcoffs::gsound_play_sfx_file_; + mov eax, dword ptr ds:[0x672E90]; // hotspot2_pic + retn; + } +} + +static void __declspec(naked) wmTownMapInit_hack() { + __asm { + mov dword ptr ds:[edi + 0x672DD8], eax; // _wmTownMapButtonId + push eax; + mov edx, fo::funcoffs::gsound_med_butt_press_; + xor ebx, ebx; // no button release sfx + call fo::funcoffs::win_register_button_sound_func_; + pop eax; + retn; + } +} + static void WorldMapInterfacePatch() { if (IniReader::GetConfigInt("Misc", "WorldMapFontPatch", 0)) { dlog("Applying world map font patch.", DL_INIT); @@ -814,6 +845,9 @@ static void WorldMapInterfacePatch() { 0x4C2D4C, // up 0x4C2D8A // down }); + HookCall(0x4C02DA, wmWorldMap_hook); // destination marker + MakeCall(0x4C4257, wmDrawCursorStopped_hack_hotspot); // triangle markers on the world map + MakeCall(0x4C4B94, wmTownMapInit_hack, 1); // triangle markers on the town map // Fix images for up/down buttons SafeWrite32(0x4C2C0A, 199); // index of UPARWOFF.FRM @@ -965,6 +999,16 @@ static void __declspec(naked) gmouse_bk_process_hook() { } } +static void __declspec(naked) intface_update_ammo_lights_hack() { + __asm { + mov eax, 70; // 70 - full ammo bar + cmp edx, eax; + cmovg edx, eax; + mov eax, 463; // overwritten engine code + retn; + } +} + static void __declspec(naked) display_body_hook() { __asm { mov ebx, [esp + 0x60 - 0x28 + 8]; @@ -1069,6 +1113,9 @@ void Interface::init() { HookCall(0x44B737, gmouse_bk_process_hook); HookCall(0x44C018, gmouse_handle_event_hook); // replaces hack function from HRP by Mash if (HRP::Setting::VersionIsValid) HRP::IFaceBar::IFACE_BAR_MODE = (GetIntHRPValue(HRP_VAR_IFACE_BAR_MODE) != 0); + + // Fix crash when the player equips a weapon overloaded with ammo (ammo bar overflow) + MakeCall(0x45F94F, intface_update_ammo_lights_hack); } void Interface::exit() { diff --git a/sfall/Modules/Inventory.cpp b/sfall/Modules/Inventory.cpp index d378c5438..ed1c7344b 100644 --- a/sfall/Modules/Inventory.cpp +++ b/sfall/Modules/Inventory.cpp @@ -48,7 +48,7 @@ void InventoryKeyPressedHook(DWORD dxKey, bool pressed) { if (fo::func::item_get_type(item) == fo::ItemType::item_type_weapon) { long maxAmmo = fo::func::item_w_max_ammo(item); long curAmmo = fo::func::item_w_curr_ammo(item); - if (maxAmmo != curAmmo) { + if (curAmmo < maxAmmo) { long ¤tMode = fo::util::GetActiveItemMode(); long previusMode = currentMode; currentMode = fo::HandSlotMode::Reload; diff --git a/sfall/Modules/Objects.cpp b/sfall/Modules/Objects.cpp index c462c775e..41b53d9b3 100644 --- a/sfall/Modules/Objects.cpp +++ b/sfall/Modules/Objects.cpp @@ -98,7 +98,7 @@ static void __declspec(naked) new_obj_id_hook() { } } -// Reassigns object IDs to all critters upon first loading a map and updates their max HP stat +// Reassigns object IDs to all critters upon first loading a map and updates their HP stats // TODO: for items? static void map_fix_critter_id() { long npcStartID = 4096; // 0x1000 diff --git a/sfall/Modules/Scripting/Handlers/Misc.cpp b/sfall/Modules/Scripting/Handlers/Misc.cpp index caab0781f..13ec9aed3 100644 --- a/sfall/Modules/Scripting/Handlers/Misc.cpp +++ b/sfall/Modules/Scripting/Handlers/Misc.cpp @@ -103,6 +103,15 @@ void __declspec(naked) op_eax_available() { } } +void __declspec(naked) op_set_eax_environment() { + __asm { + _GET_ARG_INT(end); + xor eax, eax; // EAX support has been removed since 2.1a +end: + retn; + } +} + static bool IsSpecialIni(const char* str, const char* end) { const char* pos = strfind(str, &IniReader::GetConfigFile()[2]); // TODO test if (pos && pos < end) return true; @@ -245,7 +254,10 @@ void op_set_palette(OpcodeContext& ctx) { //numbers subgame functions void __declspec(naked) op_nb_create_char() { - __asm retn; + __asm { + xor edx, edx; + _J_RET_VAL_TYPE(VAR_TYPE_INT); + } } void __declspec(naked) op_hero_select_win() { // for opening the appearance selection window diff --git a/sfall/Modules/Scripting/Handlers/Misc.h b/sfall/Modules/Scripting/Handlers/Misc.h index fb379476b..50b241027 100644 --- a/sfall/Modules/Scripting/Handlers/Misc.h +++ b/sfall/Modules/Scripting/Handlers/Misc.h @@ -47,6 +47,8 @@ void op_get_year(OpcodeContext&); void __declspec() op_eax_available(); +void __declspec() op_set_eax_environment(); + void op_get_ini_setting(OpcodeContext&); void op_get_ini_string(OpcodeContext&); diff --git a/sfall/Modules/Scripting/Opcodes.cpp b/sfall/Modules/Scripting/Opcodes.cpp index fca276783..d87da720e 100644 --- a/sfall/Modules/Scripting/Opcodes.cpp +++ b/sfall/Modules/Scripting/Opcodes.cpp @@ -211,6 +211,7 @@ static SfallOpcodeInfo opcodeInfoArray[] = { {0x267, "round", op_round, 1, true, 0, {ARG_NUMBER}}, // 0x268 RESERVED // 0x269 RESERVED + // 0x26a RESERVED {0x26b, "message_str_game", op_message_str_game, 2, true, 0, {ARG_INT, ARG_INT}}, {0x26c, "sneak_success", op_sneak_success, 0, true}, {0x26d, "tile_light", op_tile_light, 2, true, -1, {ARG_INT, ARG_INT}}, @@ -342,7 +343,7 @@ void Opcodes::InitNew() { opcodes[0x1a1] = op_set_hit_chance_max; opcodes[0x1a2] = op_set_skill_max; opcodes[0x1a3] = op_eax_available; - //opcodes[0x1a4] = op_set_eax_environment; + opcodes[0x1a4] = op_set_eax_environment; opcodes[0x1a6] = op_get_viewport_x; opcodes[0x1a7] = op_get_viewport_y; opcodes[0x1a8] = op_set_viewport_x; @@ -421,8 +422,6 @@ void Opcodes::InitNew() { opcodes[0x24c] = op_gdialog_get_barter_mod; opcodes[0x24d] = op_set_inven_ap_cost; - //opcodes[0x26a]=op_game_ui_redraw; - // configure default opcode handler for (int i = sfallOpcodeStart; i < opcodeCount; i++) { if (opcodes[i] == nullptr) { diff --git a/sfall/Modules/Stats.cpp b/sfall/Modules/Stats.cpp index 56482ebbe..76c47219e 100644 --- a/sfall/Modules/Stats.cpp +++ b/sfall/Modules/Stats.cpp @@ -188,26 +188,31 @@ static void __declspec(naked) stat_recalc_derived_hack() { } void Stats::UpdateHPStat(fo::GameObject* critter) { - if (engineDerivedStats) return; - fo::Proto* proto; if (fo::func::proto_ptr(critter->protoId, &proto) == -1) return; - auto getStatFunc = (derivedHPwBonus) ? fo::func::stat_level : fo::func::stat_get_base; + if (!engineDerivedStats) { + auto getStatFunc = (derivedHPwBonus) ? fo::func::stat_level : fo::func::stat_get_base; - double sum = 0; - for (int stat = fo::Stat::STAT_st; stat <= fo::Stat::STAT_lu; stat++) { - sum += (getStatFunc(critter, stat) + statFormulas[fo::Stat::STAT_max_hit_points].shift[stat]) * statFormulas[fo::Stat::STAT_max_hit_points].multi[stat]; - } - long calcStatValue = statFormulas[fo::Stat::STAT_max_hit_points].base + (int)floor(sum); - if (calcStatValue < statFormulas[fo::Stat::STAT_max_hit_points].min) calcStatValue = statFormulas[fo::Stat::STAT_max_hit_points].min; + double sum = 0; + for (int stat = fo::Stat::STAT_st; stat <= fo::Stat::STAT_lu; stat++) { + sum += (getStatFunc(critter, stat) + statFormulas[fo::Stat::STAT_max_hit_points].shift[stat]) * statFormulas[fo::Stat::STAT_max_hit_points].multi[stat]; + } + long calcStatValue = statFormulas[fo::Stat::STAT_max_hit_points].base + (int)floor(sum); + if (calcStatValue < statFormulas[fo::Stat::STAT_max_hit_points].min) calcStatValue = statFormulas[fo::Stat::STAT_max_hit_points].min; + + if (proto->critter.base.health != calcStatValue) { + fo::func::debug_printf("\nWarning: %s (PID: %d, ID: %d) has an incorrect base value of the max HP stat: %d, adjusted to %d.", + fo::func::critter_name(critter), critter->protoId, critter->id, proto->critter.base.health, calcStatValue); - if (proto->critter.base.health != calcStatValue) { - fo::func::debug_printf("\nWarning: critter PID: %d, ID: %d, has an incorrect base value of the max HP stat: %d (must be %d)", - critter->protoId, critter->id, proto->critter.base.health, calcStatValue); + proto->critter.base.health = calcStatValue; + } + } - proto->critter.base.health = calcStatValue; - critter->critter.health = calcStatValue + proto->critter.bonus.health; + // set the current HP to match the max HP stat for non-party member critters + // (prevent full healing for party members when entering random encounter maps) + if (!fo::util::IsPartyMember(critter) && critter->critter.health > 0) { + critter->critter.health = proto->critter.base.health + proto->critter.bonus.health; } } diff --git a/sfall/version.h b/sfall/version.h index 854984b9d..a693b4550 100644 --- a/sfall/version.h +++ b/sfall/version.h @@ -24,7 +24,7 @@ #define VERSION_MAJOR 4 #define VERSION_MINOR 3 -#define VERSION_BUILD 4 +#define VERSION_BUILD 5 #define VERSION_REV 0 -#define VERSION_STRING "4.3.4" +#define VERSION_STRING "4.3.5"