mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Backported the code of four hookscripts from 4.x.
* FINDTARGET, BARTERPRICE, WITHINPERCEPTION, and INVENTORYMOVE. For unifying the behavior of common hooks between 3.8 and 4.x. Added the example script of WITHINPERCEPTION from 4.x. Updated gl_highlighting_lite.
This commit is contained in:
Binary file not shown.
@@ -100,6 +100,11 @@ procedure KeyPressHandler begin
|
||||
end
|
||||
end
|
||||
|
||||
procedure InventoryMoveHandler begin
|
||||
// remove item outline when player picks up the item
|
||||
if (isHighlight and get_sfall_arg == 7) then set_outline(get_sfall_arg, 0);
|
||||
end
|
||||
|
||||
procedure start begin
|
||||
if game_loaded and (sfall_ver_major < 4) then begin
|
||||
call InitConfigs;
|
||||
@@ -116,5 +121,6 @@ procedure start begin
|
||||
highlightFailMsg2 := Translate("HighlightFail2", "Your motion sensor is out of charge.");
|
||||
|
||||
register_hook_proc(HOOK_KEYPRESS, KeyPressHandler);
|
||||
register_hook_proc(HOOK_INVENTORYMOVE, InventoryMoveHandler);
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,5 +17,5 @@ Also, you should disable the built-in function in ddraw.ini (ToggleItemHighlight
|
||||
|
||||
Note that due to the lack of newer game hooks in sfall 3.8.x, there are some minor visual glitches with the lite version:
|
||||
- items will be kept highlighted when entering combat while holding the highlight key.
|
||||
- when you pick up items while holding the highlight key, they will be kept highlighted if you drop them on the ground.
|
||||
- when you pick up items while holding the highlight key, they will be kept highlighted if you drop them on the ground (fixed for 3.8.18+).
|
||||
Both glitches can bo solved by pressing and releasing the highlight key again.
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Example implementation of the algorithm of how the game engine checks if one critter sees another critter.
|
||||
|
||||
NOTE: the AllowUnsafeScripting option must be enabled.
|
||||
*/
|
||||
|
||||
#include "..\headers\define.h"
|
||||
#include "..\headers\command.h"
|
||||
#include "..\headers\sfall\sfall.h"
|
||||
#include "..\headers\sfall\define_extra.h"
|
||||
|
||||
#define can_see_(source, target) call_offset_r2(0x412BEC, source, target)
|
||||
#define obj_dist_(target, source) call_offset_r2(0x48BBD4, target, source)
|
||||
|
||||
procedure start;
|
||||
|
||||
procedure start begin
|
||||
if game_loaded then begin
|
||||
register_hook(HOOK_WITHINPERCEPTION);
|
||||
end else begin
|
||||
variable
|
||||
source := get_sfall_arg,
|
||||
target := get_sfall_arg,
|
||||
original := get_sfall_arg,
|
||||
hookType := get_sfall_arg, /* new arg */
|
||||
result := 0,
|
||||
distance;
|
||||
|
||||
if target then begin
|
||||
distance := get_critter_stat(source, STAT_pe);
|
||||
|
||||
if can_see_(source, target) then begin
|
||||
distance *= 5;
|
||||
if (get_flags(target) bwand FLAG_TRANSGLASS) then distance /= 2;
|
||||
end else if combat_is_initialized then begin
|
||||
distance *= 2;
|
||||
end
|
||||
|
||||
if (target == dude_obj) then begin
|
||||
if sneak_success then begin
|
||||
distance /= 4;
|
||||
if has_skill(target, SKILL_SNEAK) > 120 then distance -= 1;
|
||||
end else if dude_is_sneaking then begin
|
||||
distance := distance * 2 / 3;
|
||||
end
|
||||
end
|
||||
|
||||
if obj_dist_(target, source) <= distance then result := 1;
|
||||
|
||||
// example
|
||||
if (result) then begin
|
||||
display_msg("hs_withinperception: " + obj_name(source) + " sees " + obj_name(target) + " [original: " + original + " script: " + result + "]");
|
||||
end else begin
|
||||
display_msg("hs_withinperception: " + obj_name(source) + " does not see " + obj_name(target) + " [original: " + original + " script: " + result + "]");
|
||||
end
|
||||
end
|
||||
|
||||
//set_sfall_return(result);
|
||||
end
|
||||
end
|
||||
@@ -189,7 +189,7 @@ Critter arg1 - The critter that just died
|
||||
|
||||
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.
|
||||
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. If you want to specify less than 4 targets, fill in the extra spaces with 0's. Pass -1 to skip the return value.
|
||||
|
||||
The return values can include critters that weren't in the list of possible targets, but the additional targets may still be discarded later on in the combat turn if they are out of the attackers perception or the chance of a successful hit is too low. The list of possible targets often includes duplicated entries.
|
||||
|
||||
@@ -266,7 +266,8 @@ 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 ret1 - the modified value of all of the goods
|
||||
int ret1 - the modified value of all of the goods (pass -1 if you just want to modify offered goods)
|
||||
int ret2 - the modified value of all offered goods
|
||||
|
||||
-------------------------------------------
|
||||
|
||||
@@ -404,6 +405,7 @@ This is fired after the default calculation is made.
|
||||
Critter arg1 - Watcher object
|
||||
Obj arg2 - Target object
|
||||
int arg3 - Result of vanilla function: 1 - within perception range, 0 - otherwise
|
||||
int arg4 - Type of hook: 1 - when being called from obj_can_see_obj script function, 2 when being called from obj_can_hear_obj script function (need to set ObjCanHearObjFix=1 in ddraw.ini), 0 for all other cases
|
||||
|
||||
int ret1 - overrides the returned result of the function: 0 - not in range (can't see), 1 - in range (will see if not blocked), 2 - forced detection (will see regardless, only used in obj_can_see_obj scripting function which is called by every critter in the game)
|
||||
|
||||
@@ -414,17 +416,16 @@ 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:
|
||||
- force moving items to inappropriate slots (like gun in armor slot)
|
||||
- block picking up items
|
||||
What you can do:
|
||||
- restrict player from using specific weapons or armors
|
||||
- add AP costs for all inventory movement including reloading
|
||||
- apply or remove some special scripted effects depending on PC's armor
|
||||
|
||||
int arg1 - Target slot (0 - main backpack, 1 - left hand, 2 - right hand, 3 - armor slot, 4 - weapon, when reloading it by dropping ammo)
|
||||
int arg1 - Target slot (0 - main backpack, 1 - left hand, 2 - right hand, 3 - armor slot, 4 - weapon, when reloading it by dropping ammo, 5 - container, like bag/backpack, 6 - dropping on the ground, 7 - picking up item, 8 - dropping item on the character portrait)
|
||||
Item arg2 - Item being moved
|
||||
Item arg3 - Item being replaced or weapon being reloaded (can be 0)
|
||||
Item arg3 - Item being replaced, weapon being reloaded, or container being filled (can be 0)
|
||||
|
||||
int ret1 - Override setting (-1 - use engine handler, any other value - prevent relocation of item/reloading weapon)
|
||||
int ret1 - Override setting (-1 - use engine handler, any other value - prevent relocation of item/reloading weapon/picking up item)
|
||||
|
||||
-------------------------------------------
|
||||
|
||||
@@ -436,7 +437,7 @@ NOTE: when replacing a previously wielded armor or weapon, the unwielding hook w
|
||||
If you need to rely on this, try checking if armor/weapon is already equipped when wielding hook is executed.
|
||||
|
||||
Critter arg1 - critter
|
||||
Obj arg2 - item being wielded or unwielded (weapon/armor), may be 0 when unwielding (object is valid only if the item is unwielded by move_obj_inven_to_obj() or rm_obj_from_inven())
|
||||
Obj arg2 - item being wielded or unwielded (weapon/armor)
|
||||
int arg3 - slot (INVEN_TYPE_*)
|
||||
int arg4 - 1 when wielding, 0 when unwielding
|
||||
|
||||
|
||||
+40
-1
@@ -334,6 +334,7 @@ const DWORD DOSCmdLineDestroy_ = 0x4E3D3C;
|
||||
const DWORD DrawCard_ = 0x43AAEC;
|
||||
const DWORD DrawFolder_ = 0x43410C;
|
||||
const DWORD DrawInfoWin_ = 0x4365AC;
|
||||
const DWORD drop_into_container_ = 0x476464;
|
||||
const DWORD dude_stand_ = 0x418378;
|
||||
const DWORD editor_design_ = 0x431DF8;
|
||||
const DWORD elapsed_time_ = 0x4C93E0;
|
||||
@@ -503,6 +504,7 @@ const DWORD obj_connect_ = 0x489EC4;
|
||||
const DWORD obj_destroy_ = 0x49B9A0;
|
||||
const DWORD obj_dist_ = 0x48BBD4;
|
||||
const DWORD obj_dist_with_tile_ = 0x48BC08;
|
||||
const DWORD obj_drop_ = 0x49B8B0;
|
||||
const DWORD obj_erase_object_ = 0x48B0FC;
|
||||
const DWORD obj_find_first_at_ = 0x48B48C;
|
||||
const DWORD obj_find_first_at_tile_ = 0x48B5A8;
|
||||
@@ -881,6 +883,22 @@ TGameObj* __stdcall InvenWorn(TGameObj* critter) {
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(noinline) TGameObj* __stdcall GetItemPtrSlot(TGameObj* critter, long slot) {
|
||||
TGameObj* itemPtr = nullptr;
|
||||
switch (slot) {
|
||||
case INVEN_TYPE_LEFT_HAND:
|
||||
itemPtr = InvenLeftHand(critter);
|
||||
break;
|
||||
case INVEN_TYPE_RIGHT_HAND:
|
||||
itemPtr = InvenRightHand(critter);
|
||||
break;
|
||||
case INVEN_TYPE_WORN:
|
||||
itemPtr = InvenWorn(critter);
|
||||
break;
|
||||
}
|
||||
return itemPtr;
|
||||
}
|
||||
|
||||
TGameObj* __stdcall InvenLeftHand(TGameObj* critter) {
|
||||
__asm {
|
||||
mov eax, critter;
|
||||
@@ -1012,7 +1030,6 @@ void __stdcall MapDirErase(const char* folder, const char* ext) {
|
||||
}
|
||||
}
|
||||
|
||||
// for the backported AmmoCostHook from 4.x
|
||||
long __stdcall ItemWAnimWeap(TGameObj* item, DWORD hitMode) {
|
||||
__asm {
|
||||
mov edx, hitMode;
|
||||
@@ -1042,3 +1059,25 @@ long __stdcall ItemWRounds(TGameObj* item) {
|
||||
call item_w_rounds_;
|
||||
}
|
||||
}
|
||||
|
||||
long __stdcall BarterComputeValue(TGameObj* source, TGameObj* target) {
|
||||
__asm {
|
||||
mov edx, target;
|
||||
mov eax, source;
|
||||
call barter_compute_value_;
|
||||
}
|
||||
}
|
||||
|
||||
long __stdcall ItemCapsTotal(TGameObj* object) {
|
||||
__asm {
|
||||
mov eax, object;
|
||||
call item_caps_total_;
|
||||
}
|
||||
}
|
||||
|
||||
long __stdcall ItemTotalCost(TGameObj* object) {
|
||||
__asm {
|
||||
mov eax, object;
|
||||
call item_total_cost_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
#define _dialogue_state 0x518714
|
||||
#define _dialogue_switch_mode 0x518718
|
||||
#define _displayMapList 0x41B560
|
||||
#define _dropped_explosive 0x5190E0
|
||||
#define _drugInfoList 0x5191CC
|
||||
#define _edit_win 0x57060C
|
||||
#define _Educated 0x57082C
|
||||
@@ -556,6 +557,7 @@ extern const DWORD DOSCmdLineDestroy_;
|
||||
extern const DWORD DrawCard_;
|
||||
extern const DWORD DrawFolder_;
|
||||
extern const DWORD DrawInfoWin_;
|
||||
extern const DWORD drop_into_container_;
|
||||
extern const DWORD dude_stand_;
|
||||
extern const DWORD editor_design_;
|
||||
extern const DWORD elapsed_time_;
|
||||
@@ -730,6 +732,7 @@ extern const DWORD obj_connect_;
|
||||
extern const DWORD obj_destroy_;
|
||||
extern const DWORD obj_dist_;
|
||||
extern const DWORD obj_dist_with_tile_;
|
||||
extern const DWORD obj_drop_;
|
||||
extern const DWORD obj_erase_object_;
|
||||
extern const DWORD obj_find_first_at_;
|
||||
extern const DWORD obj_find_first_at_tile_; // <eax>(int elevation<eax>, int tile<edx>)
|
||||
@@ -977,6 +980,8 @@ TGameObj* __stdcall InvenLeftHand(TGameObj* critter);
|
||||
// item in critter's right hand slot
|
||||
TGameObj* __stdcall InvenRightHand(TGameObj* critter);
|
||||
|
||||
__declspec(noinline) TGameObj* __stdcall GetItemPtrSlot(TGameObj* critter, long slot);
|
||||
|
||||
// pops value type from Data stack (must be followed by InterpretPopLong)
|
||||
DWORD __stdcall InterpretPopShort(TProgram* scriptPtr);
|
||||
|
||||
@@ -1034,3 +1039,8 @@ long __stdcall ItemWAnimWeap(TGameObj* item, DWORD hitMode);
|
||||
long __stdcall ItemWComputeAmmoCost(TGameObj* item, DWORD* rounds);
|
||||
long __stdcall ItemWCurrAmmo(TGameObj* item);
|
||||
long __stdcall ItemWRounds(TGameObj* item);
|
||||
|
||||
// for the backported BarterPriceHook from 4.x
|
||||
long __stdcall BarterComputeValue(TGameObj* source, TGameObj* target);
|
||||
long __stdcall ItemCapsTotal(TGameObj* object);
|
||||
long __stdcall ItemTotalCost(TGameObj* object);
|
||||
|
||||
+477
-263
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user