From c8dc689bc66b489e4a82c4e371e0bcfa4df806b4 Mon Sep 17 00:00:00 2001 From: Torhan Bartel Date: Wed, 14 Oct 2026 00:20:26 +0200 Subject: [PATCH] Name all sacred.exe addresses in src/game/addresses.h Hooks now refer to addr::* instead of literal addresses; the header also lists the world view's users of the 1024.0/768.0 constants and the ortho projection extent pushes for the widescreen work. Co-Authored-By: Claude Opus 5.5 (1M context) --- src/game/addresses.h | 47 +++++++++++++++++++++++++++++++++++++ src/game/engine/cmdline.cpp | 3 ++- src/game/engine/log.cpp | 3 ++- src/mods/borderless.cpp | 9 +++---- 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 src/game/addresses.h diff --git a/src/game/addresses.h b/src/game/addresses.h new file mode 100644 index 0000000..f8a52bc --- /dev/null +++ b/src/game/addresses.h @@ -0,0 +1,47 @@ +#pragma once +// Every sacred.exe address we use, in one place (Sacred Gold 2.28, image base +// 0x400000, no ASLR). Hooks, patches and docs refer to these names; see +// docs/function-map.md and docs/widescreen.md for what each one does. + +#include + +namespace game::addr { + +// --- functions --------------------------------------------------------------- +constexpr uint32_t Log = 0x0066f1c0; +constexpr uint32_t CmdLineHasFlag = 0x00813140; +constexpr uint32_t GetMouseClientPos = 0x0066e500; +constexpr uint32_t MainWindowProc = 0x008122a0; +constexpr uint32_t DxDriver7_SetDisplayMode = 0x00645390; +constexpr uint32_t DxDriver7_Flip = 0x00645f70; +constexpr uint32_t WorldView0_SetupView = 0x00624ae0; +constexpr uint32_t WorldView0_SetZoom = 0x00628210; +constexpr uint32_t WorldView0_Render = 0x006322b0; +constexpr uint32_t WorldToScreen = 0x00623c40; + +// --- globals ----------------------------------------------------------------- +constexpr uint32_t g_dxDriver = 0x00cda99c; // DxDriver7* +constexpr uint32_t g_appFlags = 0x0182cdb8; // uint32_t, 0x20000 = inactive + +// --- read-only constants ----------------------------------------------------- +constexpr uint32_t kScreenWidthF = 0x0088e6f4; // float 1024.0 +constexpr uint32_t kScreenHeightF = 0x00890040; // float 768.0 + +// Instructions in the world view that read kScreenWidthF / kScreenHeightF as +// a memory operand (fmul/fcomp dword ptr [addr]). Redirecting their operand +// resizes the world view without touching the UI's uses of the same floats. +constexpr uint32_t kViewWidthUsers[] = { + 0x0061e5c2, 0x00623c82, 0x00624af2, 0x00628f65, 0x00629294, + 0x0062b43a, 0x0062dc32, 0x0062ea2b, 0x0062f30d, 0x00630656, 0x00630f3f, +}; +constexpr uint32_t kViewHeightUsers[] = { + 0x0061e5ec, 0x00623c9c, 0x00624b03, 0x00628f8f, 0x006292bc, + 0x0062ea5e, 0x0062f345, 0x0063068a, 0x00630f77, +}; + +// push sequences of the 3D models' ortho extents (-267, 267, -200, 200). +constexpr uint32_t kOrthoExtentPushes[] = { + 0x0060c1f7, 0x0060da54, 0x00625039, 0x006283b3, 0x0062858d, 0x00628d3b, +}; + +} // namespace game::addr diff --git a/src/game/engine/cmdline.cpp b/src/game/engine/cmdline.cpp index 3e55c72..4f49881 100644 --- a/src/game/engine/cmdline.cpp +++ b/src/game/engine/cmdline.cpp @@ -16,11 +16,12 @@ #include #include "game/engine/log.h" +#include "game/addresses.h" #include "re/hook.h" namespace game { -RE_HOOK(0x00813140, CmdLineHasFlag); +RE_HOOK(addr::CmdLineHasFlag, CmdLineHasFlag); bool __cdecl CmdLineHasFlag(const char* cmdline, const char* flag, bool quiet) { char needle[256]; diff --git a/src/game/engine/log.cpp b/src/game/engine/log.cpp index 69ad760..23192bc 100644 --- a/src/game/engine/log.cpp +++ b/src/game/engine/log.cpp @@ -16,12 +16,13 @@ #include #include +#include "game/addresses.h" #include "re/hook.h" #include "re/log.h" namespace game { -RE_HOOK(0x0066f1c0, Log); +RE_HOOK(addr::Log, Log); void __cdecl Log(const char* fmt, ...) { char message[1024]; diff --git a/src/mods/borderless.cpp b/src/mods/borderless.cpp index 931a9f7..3794c8c 100644 --- a/src/mods/borderless.cpp +++ b/src/mods/borderless.cpp @@ -33,6 +33,7 @@ #include "game/engine/input.h" #include "game/render/dx_driver7.h" #include "re/config.h" +#include "game/addresses.h" #include "re/hook.h" #include "re/log.h" @@ -138,10 +139,10 @@ bool IsMouseMessageWithClientCoords(UINT message) { namespace game { -RE_HOOK(0x00645390, DxDriver7_SetDisplayMode); -RE_HOOK(0x00645f70, DxDriver7_Flip); -RE_HOOK(0x0066e500, GetMouseClientPos); -RE_HOOK(0x008122a0, MainWindowProc); +RE_HOOK(addr::DxDriver7_SetDisplayMode, DxDriver7_SetDisplayMode); +RE_HOOK(addr::DxDriver7_Flip, DxDriver7_Flip); +RE_HOOK(addr::GetMouseClientPos, GetMouseClientPos); +RE_HOOK(addr::MainWindowProc, MainWindowProc); int __fastcall DxDriver7_SetDisplayMode(DxDriver7* self, void* edx, void* deviceCaps, const DxDisplayMode* mode, uint32_t unknown) {