From ece76ee726352ede8a2d4629404f188ba1a9f53a Mon Sep 17 00:00:00 2001 From: NovaRain Date: Mon, 27 Apr 2020 14:24:47 +0800 Subject: [PATCH] Changed the fix for AI target selection in commit f731de7 * NPCs will reload the weapon in the same turn (and attack if have enough AP left) if weapon is empty while selecting targets. Misc code edits. --- artifacts/ddraw.ini | 2 +- sfall/FalloutEngine/Enums.h | 21 ++++++++++++------ sfall/FalloutEngine/Functions_def.h | 3 +++ sfall/Modules/AI.cpp | 22 +++++++++++-------- sfall/Modules/BugFixes.cpp | 4 ++-- sfall/Modules/Elevators.cpp | 4 ++-- sfall/Modules/MiscPatches.cpp | 32 ++++++++++++++-------------- sfall/Modules/MiscPatches.h | 33 +++++++++++++++-------------- sfall/Modules/PlayerModel.cpp | 32 ++++++++++++++-------------- sfall/Modules/PlayerModel.h | 33 +++++++++++++++-------------- sfall/Modules/Worldmap.cpp | 12 +++++------ 11 files changed, 108 insertions(+), 90 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 331109a1..d36e0faa 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -411,7 +411,7 @@ CorpseDeleteTime=6 ;Set a number of milliseconds to idle each input loop ;Set to -1 to disable ;Set to 0 to idle only if other processes are waiting for processor time (WinXP/2000: if processes have equal priority) -;Set to 1 (or some higher number if needed, the maximum is 127) to prevent 100% CPU use +;Set to 1 (or some higher number if needed) to prevent 100% CPU use. The maximum is 127 ProcessorIdle=-1 ;Set to 1 if using the hero appearance mod diff --git a/sfall/FalloutEngine/Enums.h b/sfall/FalloutEngine/Enums.h index 84937792..6517b89a 100644 --- a/sfall/FalloutEngine/Enums.h +++ b/sfall/FalloutEngine/Enums.h @@ -90,6 +90,15 @@ enum Animation : long ANIM_called_shot_pic = 64, }; +enum AnimCommand : long +{ + RB_UNRESERVED = 0x1, + RB_RESERVED = 0x2, + RB_DONTSTAND = 0x4, + RB_UNKNOWN = 0x100, + RB_END_ANIM = 0x200 +}; + enum CritterFlags : long { Sneak = 0x01, // Can sneak ? @@ -244,7 +253,7 @@ enum ArtType : char // Some FO2 PIDs possibly used by engine enum ProtoId : long { - PID_ROCK = 19, +// PID_ROCK = 19, PID_SMALL_ENERGY_CELL = 38, PID_MICRO_FUSION_CELL = 39, PID_STIMPAK = 40, @@ -256,8 +265,8 @@ enum ProtoId : long PID_GEIGER_COUNTER = 52, PID_MENTATS = 53, PID_STEALTH_BOY = 54, - PID_WATER_CHIP = 55, - PID_HOLODISK = 58, +// PID_WATER_CHIP = 55, +// PID_HOLODISK = 58, PID_MOTION_SENSOR = 59, PID_MUTATED_FRUIT = 71, PID_BIG_BOOK_OF_SCIENCE = 73, @@ -268,7 +277,7 @@ enum ProtoId : long PID_SCOUT_HANDBOOK = 86, PID_BUFFOUT = 87, PID_DOCTORS_BAG = 91, - PID_PUMP_PARTS = 98, +// PID_PUMP_PARTS = 98, PID_GUNS_AND_BULLETS = 102, PID_NUKA_COLA = 106, PID_RAD_X = 109, @@ -287,7 +296,7 @@ enum ProtoId : long PID_JET = 259, PID_JET_ANTIDOTE = 260, PID_DECK_OF_TRAGIC_CARDS = 306, - PID_GECK = 366, +// PID_GECK = 366, PID_SOLAR_SCORCHER = 390, PID_CAR_TRUNK = 455, PID_JESSE_CONTAINER = 467, @@ -560,7 +569,7 @@ namespace Scripts { } #define STAT_max_derived STAT_poison_resist -#define STAT_max_stat STAT_current_hp +#define STAT_max_stat STAT_current_hp // Script data types #define VAR_TYPE_INT (0xC001) diff --git a/sfall/FalloutEngine/Functions_def.h b/sfall/FalloutEngine/Functions_def.h index 79fb0763..d018ab56 100644 --- a/sfall/FalloutEngine/Functions_def.h +++ b/sfall/FalloutEngine/Functions_def.h @@ -19,6 +19,7 @@ WRAP_WATCOM_FFUNC4(long, _word_wrap, const char*, text, int, maxWidth, DWORD*, buf, BYTE*, count) WRAP_WATCOM_FFUNC3(void, correctFidForRemovedItem, GameObject*, critter, GameObject*, item, long, slotFlag) WRAP_WATCOM_FFUNC7(long, createWindow, const char*, winName, DWORD, x, DWORD, y, DWORD, width, DWORD, height, long, color, long, flags) +WRAP_WATCOM_FFUNC4(long, determine_to_hit, GameObject*, source, GameObject*, target, long, bodyPart, long, hitMode) WRAP_WATCOM_FFUNC3(void, display_inventory, long, inventoryOffset, long, visibleOffset, long, mode) WRAP_WATCOM_FFUNC4(void, display_target_inventory, long, inventoryOffset, long, visibleOffset, DWORD*, targetInventory, long, mode) WRAP_WATCOM_FFUNC3(FrmFrameData*, frame_ptr, FrmHeaderData*, frm, long, frame, long, direction) @@ -98,6 +99,7 @@ WRAP_WATCOM_FUNC1(long, item_w_dam_div, GameObject*, item) WRAP_WATCOM_FUNC1(long, item_w_dam_mult, GameObject*, item) WRAP_WATCOM_FUNC1(long, item_w_dr_adjust, GameObject*, item) WRAP_WATCOM_FUNC1(long, item_w_max_ammo, GameObject*, item) +WRAP_WATCOM_FUNC2(long, item_w_range, GameObject*, critter, long, hitMode) WRAP_WATCOM_FUNC2(long, item_w_reload, GameObject*, weapon, GameObject*, ammo) WRAP_WATCOM_FUNC1(long, item_w_rounds, GameObject*, item) WRAP_WATCOM_FUNC1(long, item_weight, GameObject*, item) @@ -114,6 +116,7 @@ WRAP_WATCOM_FUNC0(long, new_obj_id) // calculates bounding box (rectangle) for a given object WRAP_WATCOM_FUNC2(void, obj_bound, GameObject*, object, BoundRect*, boundRect) WRAP_WATCOM_FUNC1(long, obj_destroy, GameObject*, object) +WRAP_WATCOM_FUNC2(long, obj_dist, GameObject*, source, GameObject*, target) WRAP_WATCOM_FUNC2(long, obj_erase_object, GameObject*, object, BoundRect*, boundRect) WRAP_WATCOM_FUNC0(GameObject*, obj_find_first) WRAP_WATCOM_FUNC0(GameObject*, obj_find_next) diff --git a/sfall/Modules/AI.cpp b/sfall/Modules/AI.cpp index ab72b09f..d5f00199 100644 --- a/sfall/Modules/AI.cpp +++ b/sfall/Modules/AI.cpp @@ -152,7 +152,7 @@ skip: } } -static DWORD RetryCombatMinAP; +static long RetryCombatMinAP; static void __declspec(naked) RetryCombatHook() { static DWORD RetryCombatLastAP = 0; @@ -238,7 +238,7 @@ static void __declspec(naked) ai_danger_source_hook() { je fix; retn; fix: // check result - cmp eax, 2; // exception: 2 - out of range, 1 - no ammo + cmp eax, 1; // exception: 1 - no ammo setg al; // set 0 for result OK retn; } @@ -286,6 +286,15 @@ void AI::init() { /////////////////////// Combat AI behavior fixes /////////////////////// + // Fix for duplicate critters being added to the list of potential targets for AI + MakeCall(0x428E75, ai_find_attackers_hack_target2, 2); + MakeCall(0x428EB5, ai_find_attackers_hack_target3); + MakeCall(0x428EE5, ai_find_attackers_hack_target4, 1); + + #ifndef NDEBUG + if (iniGetInt("Debugging", "AIBugFixes", 1, ::sfall::ddrawIni) == 0) return; + #endif + // Fix to allow fleeing NPC to use drugs MakeCall(0x42B1DC, combat_ai_hack); // Fix for AI not checking minimum hp properly for using stimpaks (prevents premature fleeing) @@ -297,13 +306,8 @@ void AI::init() { // Disable fleeing when NPC cannot move closer to target BlockCall(0x42ADF6); // ai_try_attack_ - // Fix for duplicate critters being added to the list of potential targets for AI - MakeCall(0x428E75, ai_find_attackers_hack_target2, 2); - MakeCall(0x428EB5, ai_find_attackers_hack_target3); - MakeCall(0x428EE5, ai_find_attackers_hack_target4, 1); - - // Fix AI target selection for combat_check_bad_shot_ function returning a no_ammo or out_of_range result - HookCall(0x42918A, ai_danger_source_hook); + // Fix AI target selection for combat_check_bad_shot_ function returning a no_ammo result + HookCalls(ai_danger_source_hook, {0x42903A, 0x42918A}); } fo::GameObject* __stdcall AI::AIGetLastAttacker(fo::GameObject* target) { diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index b26f3e9d..cade354a 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -2664,8 +2664,8 @@ checkTiles: void BugFixes::init() { #ifndef NDEBUG - LoadGameHook::OnBeforeGameClose() += PrintAddrList; - if (iniGetInt("Debugging", "BugFixes", 1, ::sfall::ddrawIni) == 0) return; + LoadGameHook::OnBeforeGameClose() += PrintAddrList; + if (iniGetInt("Debugging", "BugFixes", 1, ::sfall::ddrawIni) == 0) return; #endif // Missing game initialization diff --git a/sfall/Modules/Elevators.cpp b/sfall/Modules/Elevators.cpp index 16c3d0a1..599a2a33 100644 --- a/sfall/Modules/Elevators.cpp +++ b/sfall/Modules/Elevators.cpp @@ -97,7 +97,7 @@ static void __declspec(naked) GetNumButtonsHook3() { } } -void ResetElevators() { +static void ResetElevators() { //memset(&elevatorExits[vanillaElevatorCount], 0, sizeof(fo::ElevatorExit) * (elevatorCount - vanillaElevatorCount) * exitsPerElevator); //memset(&elevatorsFrms[vanillaElevatorCount], 0, sizeof(fo::ElevatorFrms) * (elevatorCount - vanillaElevatorCount)); //for (int i = vanillaElevatorCount; i < elevatorCount; i++) elevatorType[i] = 0; @@ -138,7 +138,7 @@ static void LoadElevators(const char* elevFile) { } } -void ElevatorsInit() { +static void ElevatorsInit() { HookCall(0x43EF83, GetMenuHook); HookCall(0x43F141, CheckHotKeysHook); //HookCall(0x43F2D2, UnknownHook2); // unused diff --git a/sfall/Modules/MiscPatches.cpp b/sfall/Modules/MiscPatches.cpp index 82d09813..d70d7c21 100644 --- a/sfall/Modules/MiscPatches.cpp +++ b/sfall/Modules/MiscPatches.cpp @@ -1,20 +1,20 @@ /* -* sfall -* Copyright (C) 2008-2016 The sfall team -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ + * sfall + * Copyright (C) 2008-2016 The sfall team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include "..\main.h" #include "..\FalloutEngine\Fallout2.h" diff --git a/sfall/Modules/MiscPatches.h b/sfall/Modules/MiscPatches.h index 43298074..c3a49799 100644 --- a/sfall/Modules/MiscPatches.h +++ b/sfall/Modules/MiscPatches.h @@ -1,20 +1,21 @@ /* -* sfall -* Copyright (C) 2008-2016 The sfall team -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ + * sfall + * Copyright (C) 2008-2016 The sfall team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #include "Module.h" diff --git a/sfall/Modules/PlayerModel.cpp b/sfall/Modules/PlayerModel.cpp index 858f430a..25b5e7c0 100644 --- a/sfall/Modules/PlayerModel.cpp +++ b/sfall/Modules/PlayerModel.cpp @@ -1,20 +1,20 @@ /* -* sfall -* Copyright (C) 2008-2017 The sfall team -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ + * sfall + * Copyright (C) 2008-2017 The sfall team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include "..\main.h" diff --git a/sfall/Modules/PlayerModel.h b/sfall/Modules/PlayerModel.h index b9b4580b..c90ecdbf 100644 --- a/sfall/Modules/PlayerModel.h +++ b/sfall/Modules/PlayerModel.h @@ -1,20 +1,21 @@ /* -* sfall -* Copyright (C) 2008-2017 The sfall team -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ + * sfall + * Copyright (C) 2008-2017 The sfall team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #include "Module.h" diff --git a/sfall/Modules/Worldmap.cpp b/sfall/Modules/Worldmap.cpp index 15703f5c..ec90ffff 100644 --- a/sfall/Modules/Worldmap.cpp +++ b/sfall/Modules/Worldmap.cpp @@ -345,7 +345,7 @@ static void RestRestore() { SafeWrite16(0x499E93, 0x0574); } -void WorldLimitsPatches() { +static void WorldLimitsPatches() { DWORD data = GetConfigInt("Misc", "LocalMapXLimit", 0); if (data) { dlog("Applying local map x limit patch.", DL_INIT); @@ -368,7 +368,7 @@ void WorldLimitsPatches() { //} } -void TimeLimitPatch() { +static void TimeLimitPatch() { int limit = GetConfigInt("Misc", "TimeLimit", 13); if (limit == -2 || limit == -3) { addYear = true; @@ -394,7 +394,7 @@ void TimeLimitPatch() { } } -void WorldmapFpsPatch() { +static void WorldmapFpsPatch() { bool fpsPatchOK = (*(DWORD*)0x4BFE5E == 0x8D16); if (GetConfigInt("Misc", "WorldMapFPSPatch", 0)) { dlog("Applying world map fps patch.", DL_INIT); @@ -429,7 +429,7 @@ void WorldmapFpsPatch() { } } -void PathfinderFixInit() { +static void PathfinderFixInit() { //if (GetConfigInt("Misc", "PathfinderFix", 0)) { dlog("Applying Pathfinder patch.", DL_INIT); SafeWrite16(0x4C1FF6, 0x9090); // wmPartyWalkingStep_ @@ -439,7 +439,7 @@ void PathfinderFixInit() { //} } -void StartingStatePatches() { +static void StartingStatePatches() { int date = GetConfigInt("Misc", "StartYear", -1); if (date >= 0) { dlog("Applying starting year patch.", DL_INIT); @@ -495,7 +495,7 @@ void StartingStatePatches() { if (ViewportX != -1 || ViewportY != -1) HookCall(0x4BCF07, ViewportHook); // game_reset_ } -void PipBoyAutomapsPatch() { +static void PipBoyAutomapsPatch() { dlog("Applying Pip-Boy automaps patch.", DL_INIT); MakeCall(0x4BF931, wmMapInit_hack, 2); SafeWrite32(0x41B8B7, (DWORD)AutomapPipboyList);