Skip to content

Commit de5bcdf

Browse files
committed
Increased the width of default ammo bar to 2px
1 parent ca3df33 commit de5bcdf

2 files changed

Lines changed: 62 additions & 17 deletions

File tree

sfall/HRP/InterfaceBar.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ void IFaceBar::init() {
496496
// intface_end_buttons_enable_, intface_end_buttons_disable_
497497
sf::HookCalls(combat_buttons_trans_buf_to_buf, {0x45FC72, 0x45FD06});
498498

499-
// display_init_ hacks
499+
// display_init_ hacks
500500
sf::MakeCall(0x43166F, display_init_hack);
501501
sf::HookCall(0x431704, display_init_hook_buf_to_buf);
502502
sf::SafeWrite32(0x43172A, display_width);
@@ -528,12 +528,12 @@ void IFaceBar::init() {
528528
0x460FA0, 0x460FDD, 0x461010, 0x461060, 0x461085, 0x4610AB, 0x4610EC
529529
});
530530

531-
if (ALTERNATE_AMMO_METRE == 0) {
532-
// intface_draw_ammo_lights_ hacks
533-
sf::MakeCall(0x460AA6, intface_draw_ammo_lights_hack);
534-
sf::SafeWriteBatch<DWORD>(IFACE_BAR_WIDTH, {0x460AC8, 0x460AD8, 0x460AE3});
535-
sf::SafeWrite32(0x460AB4, 26 * IFACE_BAR_WIDTH); // y position
536-
}
531+
//if (ALTERNATE_AMMO_METRE == 0) {
532+
// // intface_draw_ammo_lights_ hacks
533+
// sf::MakeCall(0x460AA6, intface_draw_ammo_lights_hack);
534+
// sf::SafeWriteBatch<DWORD>(IFACE_BAR_WIDTH, {0x460AC8, 0x460AD8, 0x460AE3});
535+
// sf::SafeWrite32(0x460AB4, 26 * IFACE_BAR_WIDTH); // y position
536+
//}
537537
} else {
538538
IFACE_BAR_WIDTH = 640;
539539
}

sfall/Modules/Interface.cpp

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,8 @@ static void __fastcall wmDetectHotspotHover(long wmMouseX, long wmMouseY) {
771771
}
772772
// redraw rectangle on worldmap interface
773773
RECT rect;
774-
rect.top = y;
775774
rect.left = x_offset;
775+
rect.top = y;
776776
rect.right = x + TerrainHoverImage::width;
777777
rect.bottom = y + TerrainHoverImage::height;
778778
fo::func::win_draw_rect(fo::var::wmBkWin, &rect);
@@ -1043,16 +1043,62 @@ static __declspec(naked) void gmouse_bk_process_hook() {
10431043
}
10441044
}
10451045

1046-
static long ammoBarXPos = 463; // default position
1047-
10481046
static __declspec(naked) void intface_update_ammo_lights_hack() {
10491047
__asm {
10501048
mov eax, 70; // 70 - full ammo bar
10511049
cmp edx, eax;
10521050
cmovg edx, eax;
10531051
cmp edx, ebx; // ebx = 0 (empty ammo bar)
10541052
cmovl edx, ebx;
1055-
mov eax, ammoBarXPos; // overwritten engine code
1053+
mov eax, 463; // overwritten engine code
1054+
retn;
1055+
}
1056+
}
1057+
1058+
// Implementation from HRP by Mash
1059+
static void __fastcall DrawAmmoBar(long barX, long barFillHeight) {
1060+
fo::Window* win = fo::func::GNW_find(fo::var::interfaceWindow);
1061+
if (win == nullptr) return;
1062+
1063+
barX += win->width - 640;
1064+
1065+
long barFillHeightMax = 70;
1066+
1067+
if (barFillHeight & 1) barFillHeight--;
1068+
BYTE* buff = win->surface;
1069+
buff += (26 * win->width) + barX;
1070+
1071+
while (barFillHeightMax > barFillHeight) {
1072+
buff[0] = 14;
1073+
buff[1] = 14;
1074+
buff += win->width;
1075+
barFillHeightMax--;
1076+
}
1077+
1078+
while (barFillHeight > 0) {
1079+
buff[0] = 196;
1080+
buff[1] = 196;
1081+
buff += win->width;
1082+
buff[0] = 14;
1083+
buff[1] = 14;
1084+
buff += win->width;
1085+
barFillHeight -= 2;
1086+
}
1087+
1088+
RECT rect;
1089+
rect.left = barX;
1090+
rect.top = 26;
1091+
rect.right = barX + 2;
1092+
rect.bottom = 26 + 70;
1093+
fo::func::win_draw_rect(fo::var::interfaceWindow, &rect);
1094+
}
1095+
1096+
static __declspec(naked) void intface_update_ammo_lights_hook() {
1097+
__asm {
1098+
push ecx;
1099+
mov ecx, eax;
1100+
call DrawAmmoBar;
1101+
pop ecx;
10561102
retn;
10571103
}
10581104
}
@@ -1475,12 +1521,11 @@ void Interface::init() {
14751521

14761522
// Fix crash when the player equips a weapon overloaded with ammo (ammo bar overflow)
14771523
MakeCall(0x45F94F, intface_update_ammo_lights_hack);
1478-
// Tweak for ammo bar position with HRP by Mash
1479-
if (HRP::Setting::ExternalEnabled()) {
1480-
//ammoBarXPos = 467;
1481-
if (!IniReader::GetInt("IFACE", "ALTERNATE_AMMO_METRE", 0, ".\\f2_res.ini")) {
1482-
ammoBarXPos += 4;
1483-
}
1524+
// Ammo bar graphics patch (when not using ALTERNATE_AMMO_METRE from HRP)
1525+
if ((HRP::Setting::ExternalEnabled() && IniReader::GetInt("IFACE", "ALTERNATE_AMMO_METRE", 0, ".\\f2_res.ini") == 0) ||
1526+
(!HRP::Setting::ExternalEnabled() && HRP::IFaceBar::ALTERNATE_AMMO_METRE == 0))
1527+
{
1528+
HookCall(0x45F954, intface_update_ammo_lights_hook); // replace intface_draw_ammo_lights_
14841529
}
14851530

14861531
// Add missing sounds to the 'Done' and 'Cancel' buttons in the 'Custom' disposition of the combat control panel

0 commit comments

Comments
 (0)