Skip to content

Commit

Permalink
Merged a couple of fixes and minor improvements for 4.0.x from the de…
Browse files Browse the repository at this point in the history
…velop branch:

* Fixed the game thinking you dropped an active explosive when the dropping is prevented with hs_inventorymove.
* Added "inventory_redraw" script function (from Mr.Stalin)
* NPC combat control mod now centers the screen on the controlled critter and has new options to display critter's name.
* Removed obsoleted WIN2K preprocessor defines.
Updated version number.
  • Loading branch information
NovaRain committed Jul 16, 2018
1 parent 1b3b5dc commit 41c8722
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 20 deletions.
14 changes: 14 additions & 0 deletions artifacts/config_files/sfall-mods.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,17 @@ MotionScanner=0
;If you want to control only specific critters, uncomment the PIDList line and set a comma delimited list of PIDs
Mode=0
;PIDList=62,89,97,107,160,161

;Displays the name of the controlled critter in a notification box above the interface bar. Must be between 5 and 9
;Set to 0 to disable
DisplayName=0

;Set the color of display name, available colors:
;0 - green
;1 - red
;2 - white
;3 - yellow
;4 - dark yellow
;5 - blue
;6 - purple
DisplayNameColor=0
2 changes: 1 addition & 1 deletion artifacts/ddraw.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;sfall configuration settings
;v4.0.6
;v4.0.7

[Main]
;Change to 1 if you want to use command line args to tell sfall to use another ini file.
Expand Down
Binary file modified artifacts/mods/gl_partycontrol.int
Binary file not shown.
30 changes: 27 additions & 3 deletions artifacts/mods/gl_partycontrol.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
*/

#include "..\headers\define.h"
#include "..\headers\command.h"
#include "main.h"

variable
configSection := "CombatControl",
controlMode,
pidList,
displayName,
displayNameColor,
inControl := false,
hasGeckoSkinning := false;


Expand All @@ -33,25 +37,45 @@ procedure combatturn_handler begin
if (status == 1
and (len_array(pidList) == 0 or scan_array(pidList, pid bwand 0xFFFFFF) != -1)
and (controlMode == 1 or party_member_obj(pid))) then begin
set_dude_obj(critter);
if hasGeckoSkinning then critter_add_trait(critter, TRAIT_PERK, PERK_gecko_skinning_perk, 1);
end else begin
if not(critter == real_dude_obj) then begin
set_dude_obj(critter);
if hasGeckoSkinning then critter_add_trait(critter, TRAIT_PERK, PERK_gecko_skinning_perk, 1);
inControl := true;
end
if inControl then begin
// center the screen on the controlled critter and remove roof tiles
move_to(dude_obj, dude_tile, dude_elevation);
if displayName then begin
set_iface_tag_text(displayName, obj_name(critter), displayNameColor);
show_iface_tag(displayName);
end
end
end else if inControl then begin
set_dude_obj(real_dude_obj);
if displayName then hide_iface_tag(displayName);
end
end

procedure gamemodechange_handler begin
if not(get_game_mode BWAND COMBAT) then inControl := false;
end

procedure start begin
if game_loaded and (sfall_ver_major >= 4) then begin
set_perk_ranks(PERK_gecko_skinning_perk, 1);
set_perk_level(PERK_gecko_skinning_perk, 999); // prevent it from appearing in the perk selection window
controlMode := GetConfig("CombatControl", "Mode", 0);
displayName := GetConfig("CombatControl", "DisplayName", 0);
displayNameColor := GetConfig("CombatControl", "DisplayNameColor", 0);
if (controlMode > 2) then controlMode := 0;
if (displayName < 5 or displayName > 9) then displayName := 0;
if (controlMode > 0) then begin
pidList := GetConfigListInt("CombatControl", "PIDList");
fix_array(pidList);
if has_trait(TRAIT_PERK, dude_obj, PERK_gecko_skinning_perk) then hasGeckoSkinning := true;

register_hook_proc(HOOK_COMBATTURN, combatturn_handler);
register_hook_proc(HOOK_GAMEMODECHANGE, gamemodechange_handler);
end
end
end
1 change: 1 addition & 0 deletions artifacts/scripting/headers/sfall.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
#define intface_is_hidden sfall_func0("intface_is_hidden")
#define intface_redraw sfall_func0("intface_redraw")
#define intface_show sfall_func0("intface_show")
#define inventory_redraw(invSide) sfall_func1("inventory_redraw", invSide)
#define item_weight(obj) sfall_func1("item_weight", obj)
#define lock_is_jammed(obj) sfall_func1("lock_is_jammed", obj)
#define outlined_object sfall_func0("outlined_object")
Expand Down
2 changes: 1 addition & 1 deletion artifacts/scripting/hookscripts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ int arg2 - event type: 1 - when the resting ends normally, -1 - when pressin
int arg3 - the hour part of the length of resting time
int arg4 - the minute part of the length of resting time

int ret1 - pass 1 to interrupt the resting
int ret1 - pass 1 to interrupt the resting, pass 0 to continue the rest if it was interrupted by pressing ESC key

-------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions artifacts/scripting/sfall function notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ Some utility/math functions are available:
- The text is limited to 19 characters
- available colors: 0 - green, 1 - red, 2 - white, 3 - yellow, 4 - dark yellow, 5 - blue, 6 - purple

> void sfall_func1("inventory_redraw", int invSide)
- redraws inventory list in the inventory/use inventory item on/loot/barter screens
- invSide specifies which side needs to be redrawn: 0 - the player, 1 - target (container/NPC in loot/barter screens)

------------------------
------ MORE INFO -------
------------------------
Expand Down
2 changes: 2 additions & 0 deletions sfall/FalloutEngine/Functions_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ WRAP_WATCOM_FUNC3(long, db_freadIntCount, DbFile*, file, DWORD*, dest, long, cou
WRAP_WATCOM_FUNC2(long, db_fwriteByte, DbFile*, file, long, value)
WRAP_WATCOM_FUNC2(long, db_fwriteInt, DbFile*, file, long, value)
WRAP_WATCOM_FUNC0(void, display_stats)
WRAP_WATCOM_FUNC3(void, display_inventory, long, inventoryOffset, long, visibleOffset, long, mode)
WRAP_WATCOM_FUNC4(void, display_target_inventory, long, inventoryOffset, long, visibleOffset, DWORD*, targetInventory, long, mode)
// perform combat turn for a given critter
WRAP_WATCOM_FUNC2(long, combat_turn, GameObject*, critter, long, isDudeTurn)
WRAP_WATCOM_FUNC1(long, critter_is_dead, GameObject*, critter)
Expand Down
1 change: 1 addition & 0 deletions sfall/FalloutEngine/VariableOffsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define FO_VAR_dialogue_switch_mode 0x518718
#define FO_VAR_dialog_target 0x518848
#define FO_VAR_dialog_target_is_party 0x51884C
#define FO_VAR_dropped_explosive 0x5190E0
#define FO_VAR_drugInfoList 0x5191CC
#define FO_VAR_edit_win 0x57060C
#define FO_VAR_Educated 0x57082C
Expand Down
1 change: 1 addition & 0 deletions sfall/FalloutEngine/Variables_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ VAR_(dialogue_state, DWORD)
VAR_(dialogue_switch_mode, DWORD)
VAR_(dialog_target, DWORD)
VAR_(dialog_target_is_party, DWORD)
VAR_(dropped_explosive, DWORD)
VAR_(drugInfoList, DWORD)
VAR_(edit_win, DWORD)
VAR_(Educated, DWORD)
Expand Down
4 changes: 0 additions & 4 deletions sfall/Modules/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,11 +983,7 @@ void Graphics::init() {
}
if (Graphics::mode == 4 || Graphics::mode == 5) {
dlog("Applying dx9 graphics patch.", DL_INIT);
#ifdef WIN2K
#define _DLL_NAME "d3dx9_42.dll"
#else
#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);
Expand Down
32 changes: 27 additions & 5 deletions sfall/Modules/HookScripts/InventoryHs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void __declspec(naked) MoveCostHook() {
__asm {
popad;
cmp cRet, 1;
cmovge eax, rets[0];
cmovge eax, dword ptr rets[0];
retn;
}
}
Expand Down Expand Up @@ -165,10 +165,11 @@ static void _declspec(naked) MoveInventoryHook() {
// - if 0 is returned while dropping caps, selected amount - 1 will still disappear from inventory (fixed)
static DWORD nextHookDropSkip = 0;
static int dropResult = -1;
static const DWORD InvenActionObjDropRet = 0x473874;
static void __declspec(naked) InvenActionCursorObjDropHook() {
if (nextHookDropSkip) {
nextHookDropSkip = 0;
dropResult = -1;
goto skipHook;
} else {
__asm {
pushad;
Expand All @@ -183,6 +184,7 @@ static void __declspec(naked) InvenActionCursorObjDropHook() {
}

if (dropResult == -1) {
skipHook:
_asm call fo::funcoffs::obj_drop_;
}
_asm retn;
Expand All @@ -192,10 +194,28 @@ static void __declspec(naked) InvenActionCursorObjDropHook() {
if (dropResult == -1) {
nextHookDropSkip = 1;
_asm call fo::funcoffs::item_remove_mult_;
} else {
_asm mov dword ptr [esp], 0x473874; // no caps drop
_asm retn;
}
_asm add esp, 4;
_asm jmp InvenActionObjDropRet; // no caps drop
}

static void __declspec(naked) InvenActionExplosiveDropHack() {
__asm {
pushad;
xor ecx, ecx; // no itemReplace
push 6; // event: item drop ground
call InventoryMoveHook_Script; // edx - item
cmp eax, -1; // ret value
popad;
jnz noDrop;
mov dword ptr ds:[FO_VAR_dropped_explosive], ebp; // overwritten engine code (ebp = 1)
mov nextHookDropSkip, ebp;
retn;
noDrop:
add esp, 4;
jmp InvenActionObjDropRet; // no drop
}
_asm retn;
}

static int __fastcall DropIntoContainer(DWORD ptrCont, DWORD item, DWORD addrCall) {
Expand Down Expand Up @@ -373,6 +393,8 @@ void InitInventoryHookScripts() {
0x473851, 0x47386F,
0x47379A // caps multi drop
});
MakeCall(0x473807, InvenActionExplosiveDropHack); // drop active explosives
SafeWrite8(0x47380C, 0x90);

LoadHookScript("hs_invenwield", HOOK_INVENWIELD);
HookCalls(InvenWieldFuncHook, { 0x47275E, 0x495FDF });
Expand Down
27 changes: 27 additions & 0 deletions sfall/Modules/Scripting/Handlers/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,5 +460,32 @@ void sf_set_iface_tag_text(OpcodeContext& ctx) {
}
}

void sf_inventory_redraw(OpcodeContext& ctx) {
int mode = -1;
DWORD loopFlag = GetLoopFlags();
if (loopFlag & INVENTORY) {
mode = 0;
} else if (loopFlag & INTFACEUSE) {
mode = 1;
} else if (loopFlag & INTFACELOOT) {
mode = 2;
} else if (loopFlag & BARTER) {
mode = 3;
} else {
return;
}

if (!ctx.arg(0).asBool()) {
int* stack_offset = (int*)FO_VAR_stack_offset;
stack_offset[fo::var::curr_stack * 4] = 0;
fo::func::display_inventory(0, -1, mode);
} else if (mode >= 2) {
int* target_stack_offset = (int*)FO_VAR_target_stack_offset;
target_stack_offset[fo::var::target_curr_stack * 4] = 0;
fo::func::display_target_inventory(0, -1, (DWORD*)fo::var::target_pud, mode);
fo::func::win_draw(fo::var::i_wid);
}
}

}
}
2 changes: 2 additions & 0 deletions sfall/Modules/Scripting/Handlers/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,7 @@ void sf_display_stats(OpcodeContext&);

void sf_set_iface_tag_text(OpcodeContext&);

void sf_inventory_redraw(OpcodeContext&);

}
}
1 change: 1 addition & 0 deletions sfall/Modules/Scripting/Handlers/Metarule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ static const SfallMetarule metarules[] = {
{"intface_is_hidden", sf_intface_is_hidden, 0, 0},
{"intface_redraw", sf_intface_redraw, 0, 0},
{"intface_show", sf_intface_show, 0, 0},
{"inventory_redraw", sf_inventory_redraw, 1, 1, {ARG_INT}},
{"item_weight", sf_item_weight, 1, 1, {ARG_OBJECT}},
{"lock_is_jammed", sf_lock_is_jammed, 1, 1, {ARG_OBJECT}},
{"outlined_object", sf_outlined_object, 0, 0},
Expand Down
8 changes: 2 additions & 6 deletions sfall/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,10 @@

#define VERSION_MAJOR 4
#define VERSION_MINOR 0
#define VERSION_BUILD 6
#define VERSION_BUILD 7
#define VERSION_REV 0

#ifdef WIN2K
#define VERSION_STRING "4.0.6 win2k"
#else
#define VERSION_STRING "4.0.6"
#endif
#define VERSION_STRING "4.0.7"

#define CHECK_VAL (4)

0 comments on commit 41c8722

Please sign in to comment.