Added a tweak to center inventory windows when not using HRP

This commit is contained in:
NovaRain
2026-05-04 11:04:11 +08:00
parent f435c57c33
commit 3472ea2d84
5 changed files with 78 additions and 0 deletions
+27
View File
@@ -956,4 +956,31 @@ enum DialogOutFlags : long
DIALOGOUT_CLEAN = 0x20 // no buttons
};
enum InventoryWindowType : unsigned long
{
// Normal inventory window with quick character sheet.
INV_WIN_TYPE_NORMAL,
// Narrow inventory window with just an item scroller that's shown when
// a "Use item on" is selected from context menu.
INV_WIN_TYPE_USE_ITEM_ON,
// Looting/stealing interface.
INV_WIN_TYPE_LOOT,
// Barter interface.
INV_WIN_TYPE_TRADE,
// Supplementary "Move items" window. Used to set quantity of items when
// moving items between inventories.
INV_WIN_TYPE_MOVE_ITEMS,
// Supplementary "Set timer" window. Internally it's implemented as "Move
// items" window but with timer overlay and slightly different adjustment
// mechanics.
INV_WIN_TYPE_SET_TIMER,
INV_WIN_TYPE_COUNT,
};
}
+8
View File
@@ -113,6 +113,14 @@ struct AnimationSad {
static_assert(sizeof(AnimationSad) == 3240, "Incorrect AnimationSad definition.");
struct InventScrData {
long artIndex;
long width;
long height;
long x;
long y;
};
// Bounding rectangle, used by tile_refresh_rect and related functions.
struct BoundRect {
long x;
+1
View File
@@ -101,6 +101,7 @@ PTR_(inven_pid, DWORD)
PTR_(inven_scroll_dn_bid, DWORD)
PTR_(inven_scroll_up_bid, DWORD)
PTR_(inventry_message_file, fo::MessageList)
PTR_(iscr_data, fo::InventScrData) // array of 6 InventScrData
PTR_(itemButtonItems, fo::ItemButtonItem) // array of 2 ItemButtonItem, 0 - left, 1 - right
PTR_(itemCurrentItem, long) // 0 - left, 1 - right
PTR_(kb_lock_flags, DWORD)
+1
View File
@@ -161,6 +161,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
+41
View File
@@ -1088,6 +1088,31 @@ inPref:
}
}
// Player's inventory, "use item on", and loot windows
static __declspec(naked) void setup_inventory_hack0() {
__asm {
lea edx, [edi + edi * 4]; // edi - inventory mode
mov eax, ds:[FO_VAR_iscr_data + edx * 4 + 12]; // iscr_data[mode].x
mov ebp, eax; // add to i_wid_max_x later
// Set move items window position relative to the active inventory window
lea edx, [eax + 60];
mov ds:[FO_VAR_iscr_data + 20 * 4 + 12], edx; // iscr_data[TYPE_MOVE_ITEMS].x
mov dword ptr ds:[FO_VAR_iscr_data + 20 * 4 + 16], 80; // iscr_data[TYPE_MOVE_ITEMS].y
retn;
}
}
// barter/trade window
static __declspec(naked) void setup_inventory_hack1() {
__asm {
mov eax, 80; // overwritten engine code
// Set move items window position to the screen center
mov dword ptr ds:[FO_VAR_iscr_data + 20 * 4 + 12], 190; // iscr_data[TYPE_MOVE_ITEMS].x
mov dword ptr ds:[FO_VAR_iscr_data + 20 * 4 + 16], 115; // iscr_data[TYPE_MOVE_ITEMS].y
retn;
}
}
static __declspec(naked) void display_body_hook() {
__asm {
mov ebx, [esp + 0x60 - 0x28 + 8];
@@ -1225,6 +1250,22 @@ void Interface::init() {
MakeCalls(IncDecGamma_hack0, gammaValueGetAddr);
const DWORD gammaValueSetAddr[] = {0x492985, 0x492A65};
MakeCalls(IncDecGamma_hack1, gammaValueSetAddr);
// Center inventory windows horizontally when not using HRP (vanilla 640x480 screen)
if (!hrpIsEnabled) {
MakeCall(0x46ECF1, setup_inventory_hack0);
MakeCall(0x46EDB4, setup_inventory_hack1);
long idata = 0x90EA01;
SafeWriteBytes(0x46ED1E, (BYTE*)&idata, 3); // add edx, 80 > add edx, ebp (add to i_wid_max_x)
// Horizontal alignment (all were 80)
fo::ptr::iscr_data[fo::INV_WIN_TYPE_NORMAL].x = 70; // (640 - 499) / 2
fo::ptr::iscr_data[fo::INV_WIN_TYPE_USE_ITEM_ON].x = 174; // (640 - 292) / 2
fo::ptr::iscr_data[fo::INV_WIN_TYPE_LOOT].x = 51; // (640 - 537) / 2
// Set timer window position to the screen center
fo::ptr::iscr_data[fo::INV_WIN_TYPE_SET_TIMER].x = 190; // (640 - 259) / 2
fo::ptr::iscr_data[fo::INV_WIN_TYPE_SET_TIMER].y = 159; // (480 - 162) / 2
}
}
void Interface::exit() {