Maps in widened views: TAB overlay in place, M map across the full width
- hud: shift SetViewport/Clear with moved windows (TAB overview map) - megamap: view constants patched to the render width (clip, scroll limit, edge scrolling, centre, dark band, zoomed view and its markers); frame stretched to the screen edges, zoom controls and their click area centred - hud: Anchor::Screen windows are drawn and clicked unshifted but still own the event scope - autotest waits for log markers instead of fixed delays (~18 s per run) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
a7f8496b2b
commit
c6c5530709
9 files changed
+327
-18
No files matched your search
+55
-7
@@ -45,13 +45,14 @@ thread_local int g_offsetX = 0;
|
||||
thread_local bool g_eventShifted = false;
|
||||
|
||||
|
||||
enum class Anchor { Center, Right };
|
||||
// Screen: laid out across the whole render width by its mod (drawn unshifted).
|
||||
enum class Anchor { Center, Right, Screen };
|
||||
|
||||
int OffsetFor(Anchor anchor) {
|
||||
static const bool enabled = re::ConfigInt("hud", "Enabled", 1) != 0;
|
||||
const int width = mods::widescreen::RenderWidth();
|
||||
if (!enabled || width <= kLayoutWidth || mods::widescreen::IsClassicFrame() ||
|
||||
mods::widescreen::MenuIsShowing()) {
|
||||
mods::widescreen::MenuIsShowing() || anchor == Anchor::Screen) {
|
||||
return 0;
|
||||
}
|
||||
return anchor == Anchor::Center ? (width - kLayoutWidth) / 2 : width - kLayoutWidth;
|
||||
@@ -283,11 +284,12 @@ int MouseEventXOffsets(void* event, int (&offsets)[2]) {
|
||||
}
|
||||
}
|
||||
|
||||
// RAII: shift the mouse position by -dx for the scope (outermost window only).
|
||||
// RAII: shift the mouse position by -dx for the scope (outermost window only;
|
||||
// one with dx 0, e.g. Anchor::Screen, still keeps its children from shifting).
|
||||
class EventOffset {
|
||||
public:
|
||||
EventOffset(void* event, int dx) : cursor_(dx) {
|
||||
if (dx == 0 || g_eventShifted) {
|
||||
EventOffset(void* event, int dx) : outermost_(!g_eventShifted), cursor_(outermost_ ? dx : 0) {
|
||||
if (!outermost_) {
|
||||
return;
|
||||
}
|
||||
int offsets[2];
|
||||
@@ -309,6 +311,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
bool outermost_;
|
||||
int count_ = 0;
|
||||
int32_t* x_[2] = {};
|
||||
int32_t original_[2] = {};
|
||||
@@ -387,6 +390,45 @@ HRESULT __stdcall DrawIndexedPrimitiveShifted(void* device, DWORD type, DWORD fv
|
||||
indexCount, flags);
|
||||
}
|
||||
|
||||
// Viewports and cleared rectangles in screen space (the overview map, TAB,
|
||||
// sets a viewport at its frame, 162,120 700x525, and draws the map inside with
|
||||
// its own projection): moved like the vertices while a window draws.
|
||||
struct Viewport7 {
|
||||
DWORD x, y, width, height;
|
||||
float minZ, maxZ;
|
||||
};
|
||||
struct Rect7 {
|
||||
LONG x1, y1, x2, y2;
|
||||
};
|
||||
using SetViewportFn = HRESULT(__stdcall*)(void* device, Viewport7* viewport);
|
||||
using ClearFn = HRESULT(__stdcall*)(void* device, DWORD count, Rect7* rects, DWORD flags, DWORD color, float z,
|
||||
DWORD stencil);
|
||||
SetViewportFn g_setViewport = nullptr;
|
||||
ClearFn g_clear = nullptr;
|
||||
|
||||
HRESULT __stdcall SetViewportShifted(void* device, Viewport7* viewport) {
|
||||
if (g_offsetX == 0 || !viewport) {
|
||||
return g_setViewport(device, viewport);
|
||||
}
|
||||
Viewport7 shifted = *viewport;
|
||||
shifted.x = static_cast<DWORD>(static_cast<int>(shifted.x) + g_offsetX);
|
||||
return g_setViewport(device, &shifted);
|
||||
}
|
||||
|
||||
HRESULT __stdcall ClearShifted(void* device, DWORD count, Rect7* rects, DWORD flags, DWORD color, float z,
|
||||
DWORD stencil) {
|
||||
if (g_offsetX == 0 || count == 0 || !rects) {
|
||||
return g_clear(device, count, rects, flags, color, z, stencil);
|
||||
}
|
||||
thread_local std::vector<Rect7> shifted;
|
||||
shifted.assign(rects, rects + count);
|
||||
for (Rect7& r : shifted) {
|
||||
r.x1 += g_offsetX;
|
||||
r.x2 += g_offsetX;
|
||||
}
|
||||
return g_clear(device, count, shifted.data(), flags, color, z, stencil);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int CursorOffsetX() {
|
||||
@@ -414,6 +456,12 @@ void OnDevice(void* device) {
|
||||
g_drawIndexedPrimitive = reinterpret_cast<DrawIndexedPrimitiveFn>(vtable[26]);
|
||||
re::AttachRuntimeHook("D3D7 DrawIndexedPrimitive", reinterpret_cast<void**>(&g_drawIndexedPrimitive),
|
||||
reinterpret_cast<void*>(&DrawIndexedPrimitiveShifted));
|
||||
// Clear 10, SetViewport 13.
|
||||
g_clear = reinterpret_cast<ClearFn>(vtable[10]);
|
||||
re::AttachRuntimeHook("D3D7 Clear", reinterpret_cast<void**>(&g_clear), reinterpret_cast<void*>(&ClearShifted));
|
||||
g_setViewport = reinterpret_cast<SetViewportFn>(vtable[13]);
|
||||
re::AttachRuntimeHook("D3D7 SetViewport", reinterpret_cast<void**>(&g_setViewport),
|
||||
reinterpret_cast<void*>(&SetViewportShifted));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -545,8 +593,8 @@ HUD_EVENT(0x006c5f40, UiInventory_HandleEvent, Anchor::Center)
|
||||
HUD_RENDER(0x006c6140, UiInventory_Render, Anchor::Center)
|
||||
HUD_EVENT(0x006c70e0, UiOverviewMap_HandleEvent, Anchor::Center)
|
||||
HUD_RENDER(0x006c69d0, UiOverviewMap_Render, Anchor::Center)
|
||||
HUD_EVENT(0x006c7ec0, UiMegamap_HandleEvent, Anchor::Center)
|
||||
HUD_RENDER(0x006c9ce0, UiMegamap_Render, Anchor::Center)
|
||||
HUD_EVENT(0x006c7ec0, UiMegamap_HandleEvent, Anchor::Screen)
|
||||
HUD_RENDER(0x006c9ce0, UiMegamap_Render, Anchor::Screen) // laid out by mods/megamap.cpp
|
||||
HUD_EVENT(0x006d1080, UiMaster_HandleEvent, Anchor::Center)
|
||||
HUD_RENDER(0x006d0f00, UiMaster_Render, Anchor::Center)
|
||||
HUD_EVENT(0x006d2450, UiMasterCombo_HandleEvent, Anchor::Center)
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
// The large map (M, cUI_Megamap) spans the whole render width.
|
||||
//
|
||||
// The game lays the map out for a 1024x768 screen: a scrollable view of the
|
||||
// 2048x2816 world map (256 px tiles, scroll position at +0xc016c / +0xc0170),
|
||||
// clipped and edge-scrolled at x 1024, centred at x 512, under a dark band
|
||||
// (inner edge 70 px) and a frame of child statics (corners, 32 px edge tiles).
|
||||
// Moving it as a centred window left the world visible at the sides; instead
|
||||
// the view constants are set to the render width, the frame's right side moves
|
||||
// to the right screen edge and its top and bottom tiles stretch across, and
|
||||
// the zoom buttons at the bottom stay centred. The window is drawn and clicked
|
||||
// unshifted (mods/hud.cpp, Anchor::Screen). See docs/hud.md.
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "game/addresses.h"
|
||||
#include "mods/megamap.h"
|
||||
#include "mods/widescreen.h"
|
||||
#include "re/hook.h"
|
||||
#include "re/log.h"
|
||||
#include "re/patch.h"
|
||||
|
||||
namespace mods::megamap {
|
||||
namespace {
|
||||
|
||||
constexpr int kLayoutWidth = 1024;
|
||||
|
||||
// cmp reg, 3FFh: cursor at the right edge (edge scrolling, cursor shape).
|
||||
constexpr uint32_t kRightEdgeCompares[] = {0x006c7625, 0x006c764c, 0x006c768c, 0x006c76d9, 0x006c76fe,
|
||||
0x006c773a, 0x006c9dce, 0x006c9df4, 0x006c9e32};
|
||||
// cmp reg, 400h: tiles right of the view are skipped (0x6c9aa3); a label that
|
||||
// would end right of it is placed left of its point (0x6ca2c6, 0x6ca2e5).
|
||||
constexpr uint32_t kWidthCompares[] = {0x006c9aa3, 0x006ca2c6, 0x006ca2e5};
|
||||
// add eax, -400h: the largest scroll x is the map width minus the view.
|
||||
constexpr uint32_t kScrollLimit = 0x006c9edd;
|
||||
// The view centre 200h: the zoom-in frame (0x6ca53f) and the image centred
|
||||
// on it (0x6ca637, 0x6ca645).
|
||||
constexpr uint32_t kCentreImmediates[] = {0x006ca53f, 0x006ca637, 0x006ca645};
|
||||
// fsub/fld/fadd [512.0]: centring the scroll on the hero (opening the map
|
||||
// 0x6c7bfe, 0x6cb27a), the zoomed view (0x6ccb7f) and its quest markers
|
||||
// (0x6cf782).
|
||||
constexpr uint32_t kCentreFloatUses[] = {0x006c7bfe, 0x006cb27a, 0x006ccb7f, 0x006cf782};
|
||||
// fld [768.0] as an x: markers in the zoomed view at 768 - d (0x6ce156), the
|
||||
// centre plus 256.
|
||||
constexpr uint32_t kZoomMarkerX = 0x006ce156;
|
||||
constexpr float kZoomMarkerFromCentre = 256.0f;
|
||||
// The dark band around the view (10 vertices, mov [esp+..], imm32): its right
|
||||
// outer edge x 1024 and inner edge x 954.
|
||||
constexpr uint32_t kBandRightOuter[] = {0x006ca774, 0x006ca808};
|
||||
constexpr uint32_t kBandRightInner[] = {0x006ca7bc, 0x006ca84c};
|
||||
constexpr int kBandWidth = 70;
|
||||
|
||||
float g_halfWidth = 512.0f;
|
||||
float g_zoomMarkerX = 768.0f;
|
||||
|
||||
uint32_t FloatBits(float value) {
|
||||
uint32_t bits;
|
||||
std::memcpy(&bits, &value, sizeof(bits));
|
||||
return bits;
|
||||
}
|
||||
|
||||
// UI control layout (relative to the parent at +0x50, if any).
|
||||
// Rectangles: x, y (int32), width, height (int16); a control's at +0x24.
|
||||
constexpr size_t kControlRect = 0x24;
|
||||
// cUI_Window2: child controls, a vector of pointers.
|
||||
constexpr size_t kChildrenBegin = 0x78;
|
||||
constexpr size_t kChildrenEnd = 0x7c;
|
||||
// The frame: left side x < 48, right side from x 976, top tiles above y 48,
|
||||
// bottom tiles from y 720 (measured).
|
||||
constexpr int kFrameLeft = 48;
|
||||
constexpr int kFrameRight = 976;
|
||||
constexpr int kFrameTop = 48;
|
||||
constexpr int kFrameBottom = 720;
|
||||
// Controls the map holds itself (absolute positions, drawn by its render):
|
||||
// two statics and two buttons, the zoom controls at the bottom centre.
|
||||
constexpr size_t kOwnControls[] = {0xc0440, 0xc04bc, 0xc0544, 0xc0600};
|
||||
// Rectangle around them: the map passes only clicks inside it to the buttons
|
||||
// (its event handler, 0x6c7f32).
|
||||
constexpr size_t kZoomControlsRect = 0xc0538;
|
||||
|
||||
int& RectX(uint8_t* rect) {
|
||||
return *reinterpret_cast<int*>(rect);
|
||||
}
|
||||
int RectY(uint8_t* rect) {
|
||||
return *reinterpret_cast<int*>(rect + 4);
|
||||
}
|
||||
int16_t& RectWidth(uint8_t* rect) {
|
||||
return *reinterpret_cast<int16_t*>(rect + 8);
|
||||
}
|
||||
|
||||
// The game lays the controls out once, when it creates the map; they are
|
||||
// placed for the render width once, too (the map is opened many times).
|
||||
struct Placement {
|
||||
int x;
|
||||
int16_t width;
|
||||
};
|
||||
std::unordered_map<const void*, Placement> g_placed;
|
||||
|
||||
void Place(uint8_t* rect, int x, int width) {
|
||||
RectX(rect) = x;
|
||||
RectWidth(rect) = static_cast<int16_t>(width);
|
||||
g_placed[rect] = {x, static_cast<int16_t>(width)};
|
||||
}
|
||||
|
||||
bool AlreadyPlaced(uint8_t* rect) {
|
||||
const auto it = g_placed.find(rect);
|
||||
return it != g_placed.end() && it->second.x == RectX(rect) && it->second.width == RectWidth(rect);
|
||||
}
|
||||
|
||||
// Frame pieces: the right side moves by `extra`, the top and bottom tiles
|
||||
// between the corners stretch over the wider span; anything else stays
|
||||
// centred.
|
||||
void PlaceFramePiece(uint8_t* rect, int extra) {
|
||||
const int x = RectX(rect);
|
||||
const int width = RectWidth(rect);
|
||||
const int y = RectY(rect);
|
||||
if (x + width <= kFrameLeft) {
|
||||
return;
|
||||
}
|
||||
if (x >= kFrameRight) {
|
||||
Place(rect, x + extra, width);
|
||||
return;
|
||||
}
|
||||
if (y < kFrameTop || y >= kFrameBottom) {
|
||||
const double scale = static_cast<double>(kFrameRight - kFrameLeft + extra) / (kFrameRight - kFrameLeft);
|
||||
const int left = kFrameLeft + static_cast<int>((x - kFrameLeft) * scale + 0.5);
|
||||
const int right = kFrameLeft + static_cast<int>((x + width - kFrameLeft) * scale + 0.5);
|
||||
Place(rect, left, right - left);
|
||||
return;
|
||||
}
|
||||
Place(rect, x + extra / 2, width);
|
||||
}
|
||||
|
||||
void PlaceCentred(uint8_t* rect, int extra) {
|
||||
if (!AlreadyPlaced(rect)) {
|
||||
Place(rect, RectX(rect) + extra / 2, RectWidth(rect));
|
||||
}
|
||||
}
|
||||
|
||||
void Layout(uint8_t* megamap) {
|
||||
const int extra = mods::widescreen::RenderWidth() - kLayoutWidth;
|
||||
if (extra <= 0) {
|
||||
return;
|
||||
}
|
||||
auto** child = *reinterpret_cast<uint8_t***>(megamap + kChildrenBegin);
|
||||
auto** end = *reinterpret_cast<uint8_t***>(megamap + kChildrenEnd);
|
||||
for (; child && child != end; ++child) {
|
||||
if (*child && !AlreadyPlaced(*child + kControlRect)) {
|
||||
PlaceFramePiece(*child + kControlRect, extra);
|
||||
}
|
||||
}
|
||||
for (size_t offset : kOwnControls) {
|
||||
PlaceCentred(megamap + offset + kControlRect, extra);
|
||||
}
|
||||
PlaceCentred(megamap + kZoomControlsRect, extra);
|
||||
uint8_t* window = megamap + kControlRect;
|
||||
if (!AlreadyPlaced(window) && RectX(window) == 0 && RectWidth(window) == kLayoutWidth) {
|
||||
Place(window, 0, kLayoutWidth + extra);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void PatchLayout(int width) {
|
||||
g_halfWidth = width / 2.0f;
|
||||
int failed = re::PatchAll(kRightEdgeCompares, 0x3ff, static_cast<uint32_t>(width - 1));
|
||||
failed += re::PatchAll(kWidthCompares, 0x400, static_cast<uint32_t>(width));
|
||||
failed += !re::PatchInstructionDword(kScrollLimit, static_cast<uint32_t>(-kLayoutWidth),
|
||||
static_cast<uint32_t>(-width));
|
||||
failed += re::PatchAll(kCentreImmediates, 0x200, static_cast<uint32_t>(width / 2));
|
||||
for (uint32_t instruction : kCentreFloatUses) {
|
||||
failed += !re::RedirectOperand(instruction, game::addr::kScreenHalfWidthF, &g_halfWidth);
|
||||
}
|
||||
g_zoomMarkerX = g_halfWidth + kZoomMarkerFromCentre;
|
||||
failed += !re::RedirectOperand(kZoomMarkerX, game::addr::kScreenHeightF, &g_zoomMarkerX);
|
||||
failed += re::PatchAll(kBandRightOuter, FloatBits(1024.0f), FloatBits(static_cast<float>(width)));
|
||||
failed += re::PatchAll(kBandRightInner, FloatBits(1024.0f - kBandWidth),
|
||||
FloatBits(static_cast<float>(width - kBandWidth)));
|
||||
re::Log("megamap: view width %d%s", width, failed ? " (some patches FAILED)" : "");
|
||||
}
|
||||
|
||||
} // namespace mods::megamap
|
||||
|
||||
namespace game {
|
||||
|
||||
// cUI_Megamap::Show (vf24 0x6c7930, the argument: show / hide).
|
||||
void __fastcall UiMegamap_Show(void* self, void* edx, int show);
|
||||
RE_HOOK(0x006c7930, UiMegamap_Show);
|
||||
void __fastcall UiMegamap_Show(void* self, void* edx, int show) {
|
||||
if (self && (show & 0xff)) {
|
||||
mods::megamap::Layout(static_cast<uint8_t*>(self));
|
||||
}
|
||||
UiMegamap_Show_original(self, edx, show);
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
namespace mods::megamap {
|
||||
|
||||
// Sets the large map's view constants to the render width (once, when the
|
||||
// render size is applied).
|
||||
void PatchLayout(int width);
|
||||
|
||||
} // namespace mods::megamap
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "mods/widescreen.h"
|
||||
|
||||
#include "mods/hud.h"
|
||||
#include "mods/megamap.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
@@ -318,6 +319,7 @@ void ApplyRenderSize(game::DxDisplayMode& mode, HWND window) {
|
||||
PatchGrannyOrthoPushes(width, height);
|
||||
PatchLabelArea(width, height);
|
||||
PatchLetterbox(width);
|
||||
mods::megamap::PatchLayout(width);
|
||||
}
|
||||
const double scaleX = width / kOriginalWidth;
|
||||
const double scaleY = height / kOriginalHeight;
|
||||
|
||||
Reference in new issue
Block a user