From e7add0d1b40a7a24402d94ab4b65bac8c09b23ca Mon Sep 17 00:00:00 2001 From: NovaRain Date: Fri, 12 Nov 2021 00:48:06 +0800 Subject: [PATCH] Added inventory code --- sfall/FalloutEngine/Structs.h | 40 +++++++------ sfall/FalloutEngine/VariableOffsets.h | 3 + sfall/FalloutEngine/Variables_def.h | 1 + sfall/HRP/Dialog.cpp | 7 +++ sfall/HRP/Init.cpp | 2 + sfall/HRP/Inventory.cpp | 82 +++++++++++++++++++++++++++ sfall/HRP/Inventory.h | 17 ++++++ sfall/ddraw.vcxproj | 2 + sfall/ddraw.vcxproj.filters | 6 ++ 9 files changed, 144 insertions(+), 16 deletions(-) create mode 100644 sfall/HRP/Inventory.cpp create mode 100644 sfall/HRP/Inventory.h diff --git a/sfall/FalloutEngine/Structs.h b/sfall/FalloutEngine/Structs.h index 53a7be99..2d7a292e 100644 --- a/sfall/FalloutEngine/Structs.h +++ b/sfall/FalloutEngine/Structs.h @@ -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 . + */ #pragma once @@ -109,6 +109,14 @@ struct AnimationSad { static_assert(sizeof(AnimationSad) == 3240, "Incorrect AnimationSad definition."); +struct InventScrData { + long artIndex; + long width; + long height; + long x; + long y; +}; + struct SquareRect { long y; long x; diff --git a/sfall/FalloutEngine/VariableOffsets.h b/sfall/FalloutEngine/VariableOffsets.h index eff0cb97..cdc69fd6 100644 --- a/sfall/FalloutEngine/VariableOffsets.h +++ b/sfall/FalloutEngine/VariableOffsets.h @@ -144,6 +144,8 @@ #define FO_VAR_i_lhand 0x59E958 #define FO_VAR_i_rhand 0x59E968 #define FO_VAR_i_wid 0x59E964 +#define FO_VAR_i_wid_max_x 0x59E974 +#define FO_VAR_i_wid_max_y 0x59E970 #define FO_VAR_i_worn 0x59E954 #define FO_VAR_idle_func 0x51E234 #define FO_VAR_In_WorldMap 0x672E1C @@ -156,6 +158,7 @@ #define FO_VAR_inven_scroll_dn_bid 0x5190E8 #define FO_VAR_inven_scroll_up_bid 0x5190E4 #define FO_VAR_inventry_message_file 0x59E814 +#define FO_VAR_iscr_data 0x519068 #define FO_VAR_itemButtonItems 0x5970F8 #define FO_VAR_itemCurrentItem 0x518F78 #define FO_VAR_kb_lock_flags 0x51E2EA diff --git a/sfall/FalloutEngine/Variables_def.h b/sfall/FalloutEngine/Variables_def.h index c4c331aa..ec13cab0 100644 --- a/sfall/FalloutEngine/Variables_def.h +++ b/sfall/FalloutEngine/Variables_def.h @@ -102,6 +102,7 @@ VAR_(inven_pid, DWORD) VAR_(inven_scroll_dn_bid, DWORD) VAR_(inven_scroll_up_bid, DWORD) VAR_(inventry_message_file, fo::MessageList) +VARA(iscr_data, fo::InventScrData, 6) VARA(itemButtonItems, fo::ItemButtonItem, 2) // 0 - left, 1 - right VAR_(itemCurrentItem, long) // 0 - left, 1 - right VAR_(kb_lock_flags, DWORD) diff --git a/sfall/HRP/Dialog.cpp b/sfall/HRP/Dialog.cpp index 2dd9ef12..e52669dc 100644 --- a/sfall/HRP/Dialog.cpp +++ b/sfall/HRP/Dialog.cpp @@ -44,6 +44,13 @@ static long __fastcall CreateWinDialog(long height, long yPos, long xPos, long c xPosition = xPos; yPosition = yPos; + // item move window + fo::var::iscr_data[4].x = xPos + 185; + fo::var::iscr_data[4].y = yPos + 115; + // about window + fo::var::iscr_data[3].x = xPos + 80; + fo::var::iscr_data[3].y = yPos + 290; + return fo::func::win_add(xPos, yPos, width, height, color, flags); } diff --git a/sfall/HRP/Init.cpp b/sfall/HRP/Init.cpp index b9147739..00156138 100644 --- a/sfall/HRP/Init.cpp +++ b/sfall/HRP/Init.cpp @@ -16,6 +16,7 @@ #include "MainMenu.h" #include "InterfaceBar.h" #include "Dialog.h" +#include "Inventory.h" #include "Init.h" @@ -146,6 +147,7 @@ void HRP::init() { ViewMap::init(); IFaceBar::init(); Dialog::init(); + Inventory::init(); } } diff --git a/sfall/HRP/Inventory.cpp b/sfall/HRP/Inventory.cpp new file mode 100644 index 00000000..595483b0 --- /dev/null +++ b/sfall/HRP/Inventory.cpp @@ -0,0 +1,82 @@ +/* + * sfall + * Copyright (C) 2008-2021 The sfall team + * + */ + +#include "..\main.h" +#include "..\FalloutEngine\Fallout2.h" + +#include "Init.h" + +#include "Inventory.h" + +namespace sfall +{ + +static bool setPosition[3]; +static long xPosition; +static long yPosition; + +static long __fastcall CreateWin(long height, long yPos, long xPos, long width, long mode, long color, long flags) { + if (!setPosition[mode]) { + setPosition[mode] = true; + long x = (HRP::ScreenWidth() - width) / 2; + long y = (fo::var::getInt(FO_VAR_buf_length_2) - height) / 2; + fo::var::iscr_data[mode].x = x; + fo::var::iscr_data[mode].y = y; + } + // item move window + fo::var::iscr_data[4].x = fo::var::iscr_data[mode].x + 60; + fo::var::iscr_data[4].y = fo::var::iscr_data[mode].y + 80; + + xPos -= 80; + xPos += fo::var::iscr_data[mode].x; + yPos += fo::var::iscr_data[mode].y; + xPosition = xPos - 80; + yPosition = yPos; + + fo::var::setInt(FO_VAR_i_wid_max_x) = xPos + width; + fo::var::setInt(FO_VAR_i_wid_max_y) = yPos + height; + + return fo::func::win_add(xPos, yPos, width, height, color, flags); +} + +static void __declspec(naked) setup_inventory_hook_win_add() { + __asm { + pop ebp; // ret addr + push edi; // mode + push ebx; // width + push eax; // xPos + push ebp; + jmp CreateWin; + } +} + +static void __declspec(naked) inventory_hook_mouse_click_in() { + __asm { + add eax, xPosition; // left + add ebx, xPosition; // right + add edx, yPosition; // top + add ecx, yPosition; // bottom + jmp fo::funcoffs::mouse_click_in_; + } +} + +void Inventory::init() { + // set timer window position to center screen + fo::var::iscr_data[5].x = (HRP::ScreenWidth() - fo::var::iscr_data[5].width) / 2; + fo::var::iscr_data[5].y = (HRP::ScreenHeight() - fo::var::iscr_data[5].height) / 2; + + HookCall(0x46ED0E, setup_inventory_hook_win_add); + HookCalls(inventory_hook_mouse_click_in, { + 0x471145, 0x471270, 0x471301, 0x47138B, // inven_pickup_ + 0x474959, 0x474A23 // move_inventory_ + }); + + // setup_inventory_ + SafeMemSet(0x46ED23, CodeType::Nop, 6); + SafeMemSet(0x46ED31, CodeType::Nop, 6); +} + +} diff --git a/sfall/HRP/Inventory.h b/sfall/HRP/Inventory.h new file mode 100644 index 00000000..eace2542 --- /dev/null +++ b/sfall/HRP/Inventory.h @@ -0,0 +1,17 @@ +/* + * sfall + * Copyright (C) 2008-2021 The sfall team + * + */ + +#pragma once + +namespace sfall +{ + +class Inventory { +public: + static void init(); +}; + +} diff --git a/sfall/ddraw.vcxproj b/sfall/ddraw.vcxproj index f20d5cac..99498f6e 100644 --- a/sfall/ddraw.vcxproj +++ b/sfall/ddraw.vcxproj @@ -313,6 +313,7 @@ + @@ -440,6 +441,7 @@ + diff --git a/sfall/ddraw.vcxproj.filters b/sfall/ddraw.vcxproj.filters index 9bad3053..53a5a033 100644 --- a/sfall/ddraw.vcxproj.filters +++ b/sfall/ddraw.vcxproj.filters @@ -404,6 +404,9 @@ HRP + + HRP + @@ -743,6 +746,9 @@ HRP + + HRP +