Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions res/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,1,0,0
PRODUCTVERSION 1,1,0,0
FILEVERSION 1,1,1,0
PRODUCTVERSION 1,1,1,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -79,12 +79,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Tosox"
VALUE "FileDescription", "Always displays the HP bars for vehicles"
VALUE "FileVersion", "1.1.0"
VALUE "FileVersion", "1.1.1"
VALUE "InternalName", "PersistentVehicleHPBars"
VALUE "LegalCopyright", "Copyright © 2026"
VALUE "OriginalFilename", "PersistentVehicleHPBars.dll"
VALUE "ProductName", "PersistentVehicleHPBars"
VALUE "ProductVersion", "1.1.0"
VALUE "ProductVersion", "1.1.1"
END
END
BLOCK "VarFileInfo"
Expand Down
32 changes: 24 additions & 8 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ namespace {
constexpr const char* kVehicleDecoratorUpdatePattern =
"55 8B EC 83 E4 F8 6A FF 68 ?? ?? ?? ?? 64 A1 00 00 00 00 50 64 89 25 00 00 00 00 "
"83 EC 24 53 55 56 57 8B E9 8B 85 80 00 00 00 85 C0 74 41 8B 48 54 85 C9 74 3A";
constexpr const char* kVehicleDecoratorVeterancyHidePattern =
"53 EB 08 8D 8D 88 00 00 00 6A 01 8B 01 8B 50 04 FF D2 89 5C 24 20 89 5C 24 24";

constexpr std::ptrdiff_t kVehicleHealthWidgetOffset = 0x88;
constexpr std::size_t kWidgetSetVisibleVTableIndex = 1;
constexpr unsigned char kVehicleDecoratorVeterancyHideOriginalBytes[] = { 0x53, 0xEB, 0x08 };
constexpr unsigned char kVehicleDecoratorVeterancyHidePatchedBytes[] = { 0x90, 0xEB, 0x0F };

using VehicleDecoratorUpdateFn = void(__thiscall*)(void*);
using WidgetSetVisibleFn = void(__thiscall*)(void*, int);
using WidgetSetVisibleFn = void(__thiscall*)(void*, bool);

VehicleDecoratorUpdateFn oFnVehicleDecoratorUpdate = nullptr;

Expand All @@ -26,7 +30,7 @@ namespace {
}

auto* const setVisible = reinterpret_cast<WidgetSetVisibleFn>(vtable[kWidgetSetVisibleVTableIndex]);
setVisible(widget, visible ? 1 : 0);
setVisible(widget, visible);
}

void __fastcall HookedVehicleDecoratorUpdate(void* _this, void* edx) {
Expand All @@ -37,23 +41,35 @@ namespace {
}

bool SetupHook() {
const auto tVehicleDecoratorVeterancyHideResult = ModSDK::Memory::FindPattern("WW2Mod.dll", kVehicleDecoratorVeterancyHidePattern);
if (!tVehicleDecoratorVeterancyHideResult.has_value()) {
ModSDK::Dialogs::ShowError("Failed to find VehicleDecorator::Update (veterancy hide site)");
return false;
}

auto* const tVehicleDecoratorVeterancyHide = reinterpret_cast<unsigned char*>(tVehicleDecoratorVeterancyHideResult.value());
ModSDK::Memory::PatchMemory(
tVehicleDecoratorVeterancyHide,
kVehicleDecoratorVeterancyHidePatchedBytes,
sizeof(kVehicleDecoratorVeterancyHidePatchedBytes));

const auto tVehicleDecoratorUpdateResult = ModSDK::Memory::FindPattern("WW2Mod.dll", kVehicleDecoratorUpdatePattern);
if (!tVehicleDecoratorUpdateResult.has_value()) {
ModSDK::Dialogs::ShowError("Failed to find VehicleDecorator::Update");
ModSDK::Dialogs::ShowError("Failed to find VehicleDecorator::Update");
return false;
}

const auto tVehicleDecoratorUpdate = reinterpret_cast<void*>(tVehicleDecoratorUpdateResult.value());
const auto tVehicleDecoratorUpdate = reinterpret_cast<void*>(tVehicleDecoratorUpdateResult.value());
if (!ModSDK::Hooks::CreateHook(
tVehicleDecoratorUpdate,
reinterpret_cast<void*>(&HookedVehicleDecoratorUpdate),
reinterpret_cast<void**>(&oFnVehicleDecoratorUpdate))) {
ModSDK::Dialogs::ShowError("Failed to create VehicleDecorator::Update hook");
ModSDK::Dialogs::ShowError("Failed to create VehicleDecorator::Update hook");
return false;
}

if (!ModSDK::Hooks::EnableHook(tVehicleDecoratorUpdate)) {
ModSDK::Dialogs::ShowError("Failed to enable VehicleDecorator::Update hook");
ModSDK::Dialogs::ShowError("Failed to enable VehicleDecorator::Update hook");
return false;
}

Expand All @@ -73,9 +89,9 @@ namespace {
const CoHModSDKModuleV1 kModule = {
.abiVersion = COHMODSDK_ABI_VERSION,
.size = sizeof(CoHModSDKModuleV1),
.modId = "de.tosox.vehiclehpbars",
.modId = "de.tosox.persistentvehiclehpbars",
.name = "Persistent Vehicle HP Bars",
.version = "1.1.0",
.version = "1.1.1",
.author = "Tosox",
.OnInitialize = &OnInitialize,
.OnModsLoaded = &OnModsLoaded,
Expand Down
Loading