From 98bac520be62431dd1307d155c49f778c060362f Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:01:48 -0400 Subject: [PATCH 01/17] feat(entry): hook helpers for leaf and mid-function detours PreservingThunk.h, for the split-screen hooks that follow: - PreservingThunk / PreservedEntry: the detour of a small leaf function whose callers keep values in volatile registers across the call (Halo 3 keeps the screen height in r10 across its title-safe box function, Halo 4 an xmm register across its ultrawide helpers). The thunk saves every volatile register but rax and xmm0 around a C++ detour, which also gets the caller's return address. - MidFunctionThunk: the detour of a point inside a function, called with the function's stack pointer there (its locals), resuming through the hook's trampoline. EntrySet::on_remove runs a callback as a module's hooks are removed, for state that points into the module (a byte a hook patched, say). check_gates.py counts a PreservedEntry's target as gated, like the other Entry macros'. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/entry/PreservingThunk.h | 131 +++++++++++++++++++++++++ src/mcc/module/entry/entry.cpp | 6 ++ src/mcc/module/entry/entry.h | 5 + tools/offsets/check_gates.py | 3 +- 4 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 src/mcc/module/entry/PreservingThunk.h diff --git a/src/mcc/module/entry/PreservingThunk.h b/src/mcc/module/entry/PreservingThunk.h new file mode 100644 index 00000000..f91a13fd --- /dev/null +++ b/src/mcc/module/entry/PreservingThunk.h @@ -0,0 +1,131 @@ +#pragma once + +#include + +#include +#include +#include + +// Executable code made of `pieces` (bytes, size) laid end to end, or null. +inline void* EmitCode(std::initializer_list> pieces) { + size_t size = 0; + for (auto& piece : pieces) size += piece.second; + auto code = (unsigned char*)VirtualAlloc(nullptr, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); + if (code == nullptr) return nullptr; + auto at = code; + for (auto& piece : pieces) { + if (piece.second != 0) memcpy(at, piece.first, piece.second); + at += piece.second; + } + FlushInstructionCache(GetCurrentProcess(), code, size); + return code; +} + +// The detour of a small leaf function whose callers count on it leaving registers alone. +// Compilers keep values in volatile registers across calls to leaves they can see into (Halo 3 keeps the +// screen height in r10 across its title-safe box function, Halo 4 an xmm register across its ultrawide +// helpers), which a C++ detour would clobber. The detour takes the four register arguments and the caller's +// return address: (void* rcx, void* rdx, void* r8, void* r9, __int64 return_address), and returns in rax or +// xmm0 as the leaf does. +using PreservedDetour = __int64 (*)(void* rcx, void* rdx, void* r8, void* r9, __int64 return_address); + +// Code to hook in the detour's place: it saves every volatile register but rax and xmm0, calls `detour`, +// restores them and returns what the detour returned. +inline void* PreservingThunk(const void* detour) { + static const unsigned char kBefore[] = { + 0x51, // push rcx + 0x52, // push rdx + 0x41, 0x50, // push r8 + 0x41, 0x51, // push r9 + 0x41, 0x52, // push r10 + 0x41, 0x53, // push r11 + 0x48, 0x81, 0xEC, 0x88, 0, 0, 0, // sub rsp, 0x88 (shadow space, 5th argument, xmm1-5) + 0xF3, 0x0F, 0x7F, 0x4C, 0x24, 0x30, // movdqu [rsp+0x30], xmm1 + 0xF3, 0x0F, 0x7F, 0x54, 0x24, 0x40, // movdqu [rsp+0x40], xmm2 + 0xF3, 0x0F, 0x7F, 0x5C, 0x24, 0x50, // movdqu [rsp+0x50], xmm3 + 0xF3, 0x0F, 0x7F, 0x64, 0x24, 0x60, // movdqu [rsp+0x60], xmm4 + 0xF3, 0x0F, 0x7F, 0x6C, 0x24, 0x70, // movdqu [rsp+0x70], xmm5 + 0x48, 0x8B, 0x84, 0x24, 0xB8, 0, 0, 0, // mov rax, [rsp+0xB8] (the return address) ... + 0x48, 0x89, 0x44, 0x24, 0x20, // mov [rsp+0x20], rax ... as the 5th argument + 0x48, 0xB8, // mov rax, detour + }; + static const unsigned char kAfter[] = { + 0xFF, 0xD0, // call rax + 0xF3, 0x0F, 0x6F, 0x4C, 0x24, 0x30, // movdqu xmm1, [rsp+0x30] + 0xF3, 0x0F, 0x6F, 0x54, 0x24, 0x40, // movdqu xmm2, [rsp+0x40] + 0xF3, 0x0F, 0x6F, 0x5C, 0x24, 0x50, // movdqu xmm3, [rsp+0x50] + 0xF3, 0x0F, 0x6F, 0x64, 0x24, 0x60, // movdqu xmm4, [rsp+0x60] + 0xF3, 0x0F, 0x6F, 0x6C, 0x24, 0x70, // movdqu xmm5, [rsp+0x70] + 0x48, 0x81, 0xC4, 0x88, 0, 0, 0, // add rsp, 0x88 + 0x41, 0x5B, // pop r11 + 0x41, 0x5A, // pop r10 + 0x41, 0x59, // pop r9 + 0x41, 0x58, // pop r8 + 0x5A, // pop rdx + 0x59, // pop rcx + 0xC3, // ret + }; + return EmitCode({{kBefore, sizeof(kBefore)}, {&detour, sizeof(void*)}, {kAfter, sizeof(kAfter)}}); +} + +// The detour of a point inside a function: code to hook there that saves every volatile register, calls +// `detour` with the function's stack pointer at that point (its locals), restores them, runs `resume_code` +// (e.g. reloading a register from a local the detour rewrote) and continues at *resume - +// the hook's trampoline (Entry::m_pOriginal), which runs the instructions the hook displaced. +inline void* MidFunctionThunk(void (*detour)(char* locals), void* const* resume, const unsigned char* resume_code, + size_t resume_size) { + static const unsigned char kBefore[] = { + 0x50, // push rax + 0x51, // push rcx + 0x52, // push rdx + 0x41, 0x50, // push r8 + 0x41, 0x51, // push r9 + 0x41, 0x52, // push r10 + 0x41, 0x53, // push r11 + 0x48, 0x81, 0xEC, 0x88, 0, 0, 0, // sub rsp, 0x88 (shadow space, xmm0-5) + 0xF3, 0x0F, 0x7F, 0x44, 0x24, 0x20, // movdqu [rsp+0x20], xmm0 + 0xF3, 0x0F, 0x7F, 0x4C, 0x24, 0x30, // movdqu [rsp+0x30], xmm1 + 0xF3, 0x0F, 0x7F, 0x54, 0x24, 0x40, // movdqu [rsp+0x40], xmm2 + 0xF3, 0x0F, 0x7F, 0x5C, 0x24, 0x50, // movdqu [rsp+0x50], xmm3 + 0xF3, 0x0F, 0x7F, 0x64, 0x24, 0x60, // movdqu [rsp+0x60], xmm4 + 0xF3, 0x0F, 0x7F, 0x6C, 0x24, 0x70, // movdqu [rsp+0x70], xmm5 + 0x48, 0x8D, 0x8C, 0x24, 0xC0, 0, 0, 0, // lea rcx, [rsp+0xC0] (the stack pointer at the hook) + 0x48, 0xB8, // mov rax, detour + }; + static const unsigned char kAfter[] = { + 0xFF, 0xD0, // call rax + 0xF3, 0x0F, 0x6F, 0x44, 0x24, 0x20, // movdqu xmm0, [rsp+0x20] + 0xF3, 0x0F, 0x6F, 0x4C, 0x24, 0x30, // movdqu xmm1, [rsp+0x30] + 0xF3, 0x0F, 0x6F, 0x54, 0x24, 0x40, // movdqu xmm2, [rsp+0x40] + 0xF3, 0x0F, 0x6F, 0x5C, 0x24, 0x50, // movdqu xmm3, [rsp+0x50] + 0xF3, 0x0F, 0x6F, 0x64, 0x24, 0x60, // movdqu xmm4, [rsp+0x60] + 0xF3, 0x0F, 0x6F, 0x6C, 0x24, 0x70, // movdqu xmm5, [rsp+0x70] + 0x48, 0x81, 0xC4, 0x88, 0, 0, 0, // add rsp, 0x88 + 0x41, 0x5B, // pop r11 + 0x41, 0x5A, // pop r10 + 0x41, 0x59, // pop r9 + 0x41, 0x58, // pop r8 + 0x5A, // pop rdx + 0x59, // pop rcx + 0x58, // pop rax + }; + static const unsigned char kJump[] = { + 0x50, // push rax + 0x48, 0xB8, // mov rax, resume + }; + static const unsigned char kJumpAfter[] = { + 0x48, 0x8B, 0x00, // mov rax, [rax] + 0x48, 0x87, 0x04, 0x24, // xchg [rsp], rax + 0xC3, // ret (to *resume, with rax and rsp as they were) + }; + return EmitCode({{kBefore, sizeof(kBefore)}, {&detour, sizeof(void*)}, {kAfter, sizeof(kAfter)}, + {resume_code, resume_size}, {kJump, sizeof(kJump)}, {&resume, sizeof(void*)}, + {kJumpAfter, sizeof(kJumpAfter)}}); +} + +// Like the games' Entry macros, for a detour hooked through PreservingThunk: its parameters are +// PreservedDetour's (the register arguments, then the caller's return address). +#define PreservedEntry(name, set, offset, pDetour, ...) \ + __int64 pDetour(__VA_ARGS__); \ + ::Entry name(set, offset, PreservingThunk((const void*)&pDetour), entry_feature); \ + __int64 pDetour(__VA_ARGS__) diff --git a/src/mcc/module/entry/entry.cpp b/src/mcc/module/entry/entry.cpp index b22758a4..bd387d1b 100644 --- a/src/mcc/module/entry/entry.cpp +++ b/src/mcc/module/entry/entry.cpp @@ -68,4 +68,10 @@ bool EntrySet::update(__int64 hModule) { void EntrySet::remove() { for (int i = 0; i < entryCount; ++i) entryArray[i]->remove(); + for (int i = 0; i < callbackCount; ++i) callbackArray[i](); +} + +void EntrySet::on_remove(void (*callback)()) { + assert(callbackCount < MAX_CALLBACK); + callbackArray[callbackCount++] = callback; } diff --git a/src/mcc/module/entry/entry.h b/src/mcc/module/entry/entry.h index 3582b7eb..913f5e09 100644 --- a/src/mcc/module/entry/entry.h +++ b/src/mcc/module/entry/entry.h @@ -31,6 +31,8 @@ class EntrySet { // reloads them at new addresses, so a hook left behind would later be "restored" into // whatever DLL occupies its old address. void remove(); + // Called as the set is removed, for state that points into the module (up to MAX_CALLBACK). + void on_remove(void (*callback)()); private: // Halo Reach reached the old limit of 20 with the FOV baseline seam (5 @@ -39,6 +41,9 @@ class EntrySet { inline static const int MAX_ENTRY = 32; int entryCount; Entry* entryArray[MAX_ENTRY]; + inline static const int MAX_CALLBACK = 4; + int callbackCount; + void (*callbackArray[MAX_CALLBACK])(); }; diff --git a/tools/offsets/check_gates.py b/tools/offsets/check_gates.py index acd85204..f6632e32 100644 --- a/tools/offsets/check_gates.py +++ b/tools/offsets/check_gates.py @@ -4,7 +4,7 @@ On a build the offsets weren't written for, an offset that isn't found reads as 0 (src/offsets/Offsets.h), so what uses it has to be gated on it. Every OFFSET_ a source file uses must be gated there in one of these ways: - - a hook's own target (Halo1Entry(name, OFFSET_X, ...), ::Entry name(Set(), OFFSET_X, ...)); + - a hook's own target (Halo1Entry(name, OFFSET_X, ...), PreservedEntry, ::Entry name(Set(), OFFSET_X, ...)); - listed in an EntryFeature(...) or a Feature name(...) / {...}; - checked with Found({...}) or OFFSET_X.found(); - a {Steam, Windows Store} pair handed to Hook::Detour / Hook::Offset, which skip a missing one; @@ -30,6 +30,7 @@ HOOK_TARGETS = [ r"\w+Entry\(\s*\w+\s*,\s*(OFFSET_\w+)", # Halo1Entry(name, OFFSET_X + r"PreservedEntry\(\s*\w+\s*,\s*[\w:]+\(\)\s*,\s*(OFFSET_\w+)", # PreservedEntry(name, Set(), OFFSET_X r"::Entry\s+\w+\(\s*\w+\(\)\s*,\s*(OFFSET_\w+)", # ::Entry name(Set(), OFFSET_X ] GATED_LISTS = [ From ff145cc067d57489d2105573e96677360132f021 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:01:55 -0400 Subject: [PATCH 02/17] feat(offsets): split-screen addresses for Halo CE, 2, 3, ODST and 4 The addresses the next commits use, as DefOffsets with their byte patterns (gen_patterns.py; values and patterns as in the kirklandsig fork, same 1.3528 build): - Halo CE's and Halo 2's view grid, windows and dividers, and whether Classic graphics are on screen; - the Gen3 games' screen size, player count, divider painter and render-target pool, and Halo 3 / ODST's HUD layout records; - each view's title-safe box (Halo 3, ODST, Halo 4); - Halo 4's HUD layout picker, its ultrawide UI helpers and the first-person camera's aspect divide; - where Halo CE and Halo 2 take a mission's game options. COVER pins down the whole divss the Halo 4 gun fix patches; COVER_BEFORE starts the Halo CE scope hook's pattern 0x45 bytes earlier, over the locals its detour rewrites. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- lib/game/inc/1.3528.0.0/offset_halo1.h | 12 ++++ lib/game/inc/1.3528.0.0/offset_halo2.h | 10 +++ lib/game/inc/1.3528.0.0/offset_halo3.h | 14 ++++ lib/game/inc/1.3528.0.0/offset_halo3odst.h | 14 ++++ lib/game/inc/1.3528.0.0/offset_halo4.h | 28 ++++++++ lib/game/inc/1.3528.0.0/patterns_halo1.inc | 27 ++++++++ lib/game/inc/1.3528.0.0/patterns_halo2.inc | 24 +++++++ lib/game/inc/1.3528.0.0/patterns_halo3.inc | 35 ++++++++++ .../inc/1.3528.0.0/patterns_halo3odst.inc | 35 ++++++++++ lib/game/inc/1.3528.0.0/patterns_halo4.inc | 69 +++++++++++++++++++ tools/offsets/gen_patterns.py | 8 ++- 11 files changed, 274 insertions(+), 2 deletions(-) diff --git a/lib/game/inc/1.3528.0.0/offset_halo1.h b/lib/game/inc/1.3528.0.0/offset_halo1.h index a87da910..09114586 100644 --- a/lib/game/inc/1.3528.0.0/offset_halo1.h +++ b/lib/game/inc/1.3528.0.0/offset_halo1.h @@ -3,9 +3,21 @@ #include "Offset.h" DefOffset(OFFSET_HALO1_PF_RENDER, 0x1F05B0) +DefOffset(OFFSET_HALO1_PF_GAME_START, 0x939D0) // engine game_start(self, manager, game_options) DefOffset(OFFSET_HALO1_PF_4PLAYERS, 0x67492) DefOffset(OFFSET_HALO1_PF_PAUSE, 0x427978) DefOffset(OFFSET_HALO1_PF_IDK, 0x85428) DefOffset(OFFSET_HALO1_PV_PLAYER_COUNT, 0x1B7B910) + +// Left/Right split screen (mcc/splitscreen/LeftRight) +DefOffset(OFFSET_HALO1_PF_SPLIT_GRID, 0xAC4108) // void (int views, int* columns, int* rows) - the window grid, rows first +DefOffset(OFFSET_HALO1_PF_SPLIT_WINDOW, 0xAC4154) // void (int view, int views, short rect[4], short copy[4]) - a view's window +DefOffset(OFFSET_HALO1_PF_SPLIT_DIVIDERS, 0xB32238) // void () - paints the black bands between the views +DefOffset(OFFSET_HALO1_PF_SPLIT_VIEWS, 0xB321FC) // int () - views on screen +DefOffset(OFFSET_HALO1_PV_WINDOW_BOUNDS, 0x29E05B4) // int16 top, left, bottom, right of the window being drawn +DefOffset(OFFSET_HALO1_PV_SCREEN_BOUNDS, 0x1B7D3DC) // int16 top, left, bottom, right the windows are laid out on +DefOffset(OFFSET_HALO1_SCOPE_GRID_SET, 0xAC73DC) // in the scope effects' texture transforms: the view's grid place is set +DefOffset(OFFSET_HALO1_PF_FILL_RECT, 0xAC63F4) // void (short rect[4] {top, left, bottom, right}, unsigned argb) +DefOffset(OFFSET_HALO1_PV_ANNIVERSARY_SHOWN, 0x1B7AA84) // int, nonzero while Anniversary graphics are on screen (Back switches it; 0x745B0 is bool () "Classic") diff --git a/lib/game/inc/1.3528.0.0/offset_halo2.h b/lib/game/inc/1.3528.0.0/offset_halo2.h index 8c15df2a..93082ae2 100644 --- a/lib/game/inc/1.3528.0.0/offset_halo2.h +++ b/lib/game/inc/1.3528.0.0/offset_halo2.h @@ -4,6 +4,7 @@ DefOffset(OFFSET_HALO2_PF_LOAD, 0x4F980) DefOffset(OFFSET_HALO2_PF_GAME, 0x67A220) +DefOffset(OFFSET_HALO2_PF_COPY_GAME_OPTIONS, 0x39CE0) // copy_game_options(game_options) DefOffset(OFFSET_HALO2_PF_ADD_LOCAL_PLAYER, 0x69D2C0)//0x69D290 @@ -28,3 +29,12 @@ DefOffset(OFFSET_HALO2_PF_PLAYERS_UPDATE, 0x6A3910) DefOffset(OFFSET_HALO2_PF_COOP_CAMPAIGN, 0x6A6320) // bool () - a co-op campaign: session [0xE80A78] mode +8 == 1, byte +0x2C8 DefOffset(OFFSET_HALO2_PF_COOP_RESPAWN_ALLOWED, 0x6A5D40) // bool () - not with the Iron skull (11), not on Legendary DefOffset(OFFSET_HALO2_PV_SCENARIO, 0xE6F768) // the loaded scenario*: int starting locations +0x100 + +// Left/Right split screen (mcc/splitscreen/LeftRight) +DefOffset(OFFSET_HALO2_PF_SPLIT_GRID, 0x7E09D0) // void (int views, int mode, short grid[2] columns, rows) - mode 1 stacks, others side by side +DefOffset(OFFSET_HALO2_PF_SPLIT_CELL, 0x7E0BD0) // void (int view, int views, int mode, short grid[2], short cell[2], short span[2]) +DefOffset(OFFSET_HALO2_PF_SPLIT_DIVIDERS, 0x831D90) // void () - paints the black bands between the views, by the frame's mode +DefOffset(OFFSET_HALO2_PV_SPLIT_MODE, 0x165C168) // int - the frame's grid mode, which only the dividers read +DefOffset(OFFSET_HALO2_PV_SPLIT_VIEWS, 0x165C16C) // int - the frame's views +DefOffset(OFFSET_HALO2_PV_ANNIVERSARY, 0xE21280) // int, nonzero while the Anniversary renderer is up +DefOffset(OFFSET_HALO2_PV_CLASSIC_SHOWN, 0x1E8CE73) // bool, the player switched to Classic graphics diff --git a/lib/game/inc/1.3528.0.0/offset_halo3.h b/lib/game/inc/1.3528.0.0/offset_halo3.h index ee683684..10156bf2 100644 --- a/lib/game/inc/1.3528.0.0/offset_halo3.h +++ b/lib/game/inc/1.3528.0.0/offset_halo3.h @@ -42,6 +42,20 @@ DefOffset(OFFSET_HALO3_PF_OBJECT_POST_CREATE, 0x1EA04) // (int object) - called // c_splitscreen_config::m_config_table; the black-bar patches rewrite entries 8, 9 and 12 (0x8AE150, 0x8AE164, 0x8AE1A0) DefOffset(OFFSET_HALO3_PV_SPLITSCREEN_TABLE, 0x8AE0B0)//0x8AD0C0 +// Left/Right split screen and each view's title-safe box (mcc/splitscreen/LeftRight) +DefOffset(OFFSET_HALO3_PV_SCREEN_SIZE, 0x8AC3E8) // int width, height the views are laid out on +DefOffset(OFFSET_HALO3_PF_SPLITSCREEN_PLAYER_COUNT, 0x2E0928) // int () +DefOffset(OFFSET_HALO3_PF_DRAW_SPLITSCREEN_BARS, 0x2D8174) // void () - black bars and dividers +DefOffset(OFFSET_HALO3_PF_FILL_RECT, 0x1890C4) // void (short rect[4] {top, left, bottom, right}, unsigned argb) +DefOffset(OFFSET_HALO3_PF_RT_CREATE, 0x2757C8) // (target*, int sizes[], descriptor*, int variant) - one pool render target +DefOffset(OFFSET_HALO3_PF_RT_POOL_RELEASE, 0x27613C) // void () - the resize path's teardown ... +DefOffset(OFFSET_HALO3_PF_RT_POOL_INIT, 0x275BBC) // void () - ... and rebuild +DefOffset(OFFSET_HALO3_PF_HUD_RESOLUTION, 0x2F1E38) // int (int user) - HUD layout of a view: 0 full, 1 half, 4 quarter (2, 5, 6 on 4:3) +DefOffset(OFFSET_HALO3_PF_HUD_LAYOUT, 0x2ECF38) // record* (int user, int resolution) - +0x10 int canvas width, height; 0x64 bytes +DefOffset(OFFSET_HALO3_PF_VIEW_SETUP, 0x282EC4) // void (view*, int slot, int players, int, int, void*) - a split-screen view's rect, title-safe box, projection +DefOffset(OFFSET_HALO3_PF_TITLE_SAFE, 0x272010) // void (short rect[4] {top, left, bottom, right}) - the screen's title-safe box, 5% in from each edge +DefOffset(OFFSET_HALO3_VIEW_SETUP_TITLE_SAFE_RETURN, 0x282F10) // where the view setup's call to it returns + struct halo3_teb_data_definition { void* zero; void* actor; diff --git a/lib/game/inc/1.3528.0.0/offset_halo3odst.h b/lib/game/inc/1.3528.0.0/offset_halo3odst.h index 88a2d352..aef32efd 100644 --- a/lib/game/inc/1.3528.0.0/offset_halo3odst.h +++ b/lib/game/inc/1.3528.0.0/offset_halo3odst.h @@ -18,3 +18,17 @@ DefOffset(OFFSET_HALO3ODST_PF_ADD_LOCAL_PLAYER, 0xFBFE4)//0xFBEE4 // c_splitscreen_config::m_config_table; the black-bar patches rewrite entries 8, 9 and 12 (0x8F1FB0, 0x8F1FC4, 0x8F2000) DefOffset(OFFSET_HALO3ODST_PV_SPLITSCREEN_TABLE, 0x8F1F10)//0x8F1F20 + +// Left/Right split screen and each view's title-safe box (mcc/splitscreen/LeftRight); see offset_halo3.h for the signatures +DefOffset(OFFSET_HALO3ODST_PV_SCREEN_SIZE, 0x8F0278) +DefOffset(OFFSET_HALO3ODST_PF_SPLITSCREEN_PLAYER_COUNT, 0x313AF0) +DefOffset(OFFSET_HALO3ODST_PF_DRAW_SPLITSCREEN_BARS, 0x303C54) +DefOffset(OFFSET_HALO3ODST_PF_FILL_RECT, 0x1BA498) +DefOffset(OFFSET_HALO3ODST_PF_RT_CREATE, 0x2A2C64) // (target*, int sizes[], descriptor*, int variant, int) +DefOffset(OFFSET_HALO3ODST_PF_RT_POOL_RELEASE, 0x2A3400) +DefOffset(OFFSET_HALO3ODST_PF_RT_POOL_INIT, 0x2A30F0) +DefOffset(OFFSET_HALO3ODST_PF_HUD_RESOLUTION, 0x32DD0C) +DefOffset(OFFSET_HALO3ODST_PF_HUD_LAYOUT, 0x3284B4) // record* - +0x94 int canvas width, height; 0x110 bytes +DefOffset(OFFSET_HALO3ODST_PF_VIEW_SETUP, 0x2ABAC8) // void (view*, int slot, int players, int, int, void*) - as Halo 3's +DefOffset(OFFSET_HALO3ODST_PF_TITLE_SAFE, 0x29F634) // void (short rect[4]) - the screen's title-safe box, 5% in from each edge +DefOffset(OFFSET_HALO3ODST_VIEW_SETUP_TITLE_SAFE_RETURN, 0x2ABB14) // where the view setup's call to it returns diff --git a/lib/game/inc/1.3528.0.0/offset_halo4.h b/lib/game/inc/1.3528.0.0/offset_halo4.h index c4801348..36a979ec 100644 --- a/lib/game/inc/1.3528.0.0/offset_halo4.h +++ b/lib/game/inc/1.3528.0.0/offset_halo4.h @@ -18,3 +18,31 @@ DefOffset(OFFSET_HALO4_PF_ADD_LOCAL_PLAYER, 0x7D948) // c_splitscreen_config::m_config_table; the black-bar patches rewrite entries 8, 9 and 12 (0xE84E50, 0xE84E64, 0xE84EA0) DefOffset(OFFSET_HALO4_PV_SPLITSCREEN_TABLE, 0xE84DB0)//0xE84DA0 + +// Left/Right split screen and each view's title-safe box (mcc/splitscreen/LeftRight); see offset_halo3.h for the signatures +DefOffset(OFFSET_HALO4_PV_SCREEN_SIZE, 0xE84608) +DefOffset(OFFSET_HALO4_PF_SPLITSCREEN_PLAYER_COUNT, 0x122188) +DefOffset(OFFSET_HALO4_PF_DRAW_SPLITSCREEN_BARS, 0x3C66D4) +DefOffset(OFFSET_HALO4_PF_FILL_RECT, 0x12D694) +DefOffset(OFFSET_HALO4_PF_RENDER_SETUP_1, 0x34D224) // (int, int) - the bar painter calls it with (0, 1) ... +DefOffset(OFFSET_HALO4_PF_RENDER_SETUP_2, 0x34D14C) // (int) - ... and this with 0, before drawing +DefOffset(OFFSET_HALO4_PF_RT_VARIANT_SIZE, 0x37E8B4) // (descriptor*, int* w, int* h, int* w2, int* h2, int* face, int index) +DefOffset(OFFSET_HALO4_PF_RT_POOL_RELEASE, 0x37F610) +DefOffset(OFFSET_HALO4_PF_RT_POOL_INIT, 0x37F3A8) +DefOffset(OFFSET_HALO4_PF_HUD_LAYOUT, 0x3BD78C) // int (int user) - the HUD layout by the view's table variant: 0x80076 full, 0x80077 half, 0x80078 quarter +DefOffset(OFFSET_HALO4_PF_COMPUTE_VIEWPORT_RECT, 0x38EE74) // (int slot, int players, short view[4], short box[4]) - a view and its title-safe box, as Reach's +DefOffset(OFFSET_HALO4_VIEWMODEL_ASPECT_DIVIDE, 0x34ED96) // divss xmm5, xmm0 - the first-person camera's field of view, times the screen's aspect, over the view's (in 0x34EC44) + +// Halo 4's HUD in a Left/Right half (module/entry/halo4/hud_fit.cpp) +DefOffset(OFFSET_HALO4_PF_HUD_UPDATE, 0x3BCF88) // (hud*, int user) - updates a user's HUD screens +DefOffset(OFFSET_HALO4_PF_HUD_RENDER, 0x3F7A7C) // (?, int user, ?, ?) - draws a user's HUD +DefOffset(OFFSET_HALO4_PF_UI_WIDE, 0x3DBB8C) // bool () - the screen is wider than 16:9 +DefOffset(OFFSET_HALO4_PF_UI_ASPECT, 0x3DBBEC) // float (bool inverse) - the screen's aspect over 16:9's (or its inverse) +DefOffset(OFFSET_HALO4_PF_UI_EXTRA_WIDTH, 0x3DBC40) // float () - UI units either side of a 1280-wide layout on a wider screen +DefOffset(OFFSET_HALO4_PF_UI_EXTRA_HEIGHT, 0x3DBC98) // float () - ... either side of a 720-high layout on a narrower one +DefOffset(OFFSET_HALO4_PF_UI_ANCHOR, 0x3FD3E8) // (element*, context*) - places an element anchored to the screen's edges +DefOffset(OFFSET_HALO4_PF_UI_FIT_RANGE, 0x4224F0) // (widget*, context*) - fits a widget's extent to the screen's shape +DefOffset(OFFSET_HALO4_PF_UI_USER_INDEX, 0x3A7BDC) // int (int user id) - the local user index of a UI context's user (+0x28) +DefOffset(OFFSET_HALO4_PF_UI_SCREEN_RENDER, 0x3D6184) // (screen*, context*) - draws a UI screen, translated by the extra width/height +DefOffset(OFFSET_HALO4_VT_HUD_RETICLE_GROUP, 0xD6C2D0) // the vtable of the widget group holding the crosshair +DefOffset(OFFSET_HALO4_VT_UI_GROUP, 0xD7DE70) // the vtable of a UI screen's top-level widget groups diff --git a/lib/game/inc/1.3528.0.0/patterns_halo1.inc b/lib/game/inc/1.3528.0.0/patterns_halo1.inc index 2bf89e46..d5e437e5 100644 --- a/lib/game/inc/1.3528.0.0/patterns_halo1.inc +++ b/lib/game/inc/1.3528.0.0/patterns_halo1.inc @@ -5,6 +5,8 @@ constexpr ModuleBuild kHalo1Build{0x68a0e4cf, 0x3d82000}; const OffsetPatterns kHalo1Patterns[] = { {&OFFSET_HALO1_PF_RENDER, 0x1f05b0, Code, { At("40 57 48 83 EC 40 48 C7 44 24 20 FE FF FF FF 48 89 5C 24 50 48 89 6C 24 60 48 89 74 24 68 8B F2", 0x0)}}, + {&OFFSET_HALO1_PF_GAME_START, 0x939d0, Code, { + At("40 53 56 57 48 81 EC 50 02 00 00 48 8B 05 ?? ?? ?? ?? 48 33 C4", 0x0)}}, {&OFFSET_HALO1_PF_4PLAYERS, 0x67492, Code, { At("85 C0 75 11 C7 05 ?? ?? ?? ?? 04 00 00 00 48 89 35 ?? ?? ?? ?? C6 05 ?? ?? ?? ?? 01", 0x2)}}, {&OFFSET_HALO1_PF_PAUSE, 0x427978, Code, { @@ -14,4 +16,29 @@ const OffsetPatterns kHalo1Patterns[] = { {&OFFSET_HALO1_PV_PLAYER_COUNT, 0x1b7b910, Data, { Rel("0F BF 15 ?? ?? ?? ?? 45 33 FF 48 63 F8 45 8D 77 01 41 2B D6", 0x3, 0x7, 0x0), Rel("0F B7 05 ?? ?? ?? ?? 66 89 81 24 01 00 00 0F B7 8A 58 01 00 00", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PF_SPLIT_GRID, 0xac4108, Code, { + At("48 89 5C 24 08 BB 01 00 00 00 4D 8B D8 44 8B CB", 0x0), + Rel("E8 ?? ?? ?? ?? 44 8B 5C 24 58 41 8B C3 0F AF 44 24 50 3B C3", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_SPLIT_WINDOW, 0xac4154, Code, { + At("4C 8B DC 49 89 5B 18 49 89 6B 20 56 57 41 54 41 55 41 57", 0x0), + Rel("E8 ?? ?? ?? ?? 83 C8 FF 40 88 6B 02 33 D2 66 89 03 48 8B CB", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_SPLIT_DIVIDERS, 0xb32238, Code, { + At("48 89 5C 24 10 48 89 74 24 18 55 57 41 54 41 56 41 57 48 8B EC 48 83 EC 20", 0x0)}}, + {&OFFSET_HALO1_PF_SPLIT_VIEWS, 0xb321fc, Code, { + At("48 83 EC 28 E8 ?? ?? ?? ?? 84 C0 75 ?? 48 8B 05 ?? ?? ?? ?? 80 78 0A 00 75 ?? E8", 0x0), + Rel("E8 ?? ?? ?? ?? 45 8D 45 01 8B F8 66 41 3B C0 7D ?? 41 0F B7 F8", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PV_WINDOW_BOUNDS, 0x29e05b4, Data, { + Rel("0F BF 05 ?? ?? ?? ?? F3 0F 11 45 E7 41 8D 56 07 66 0F 6E C1", 0x3, 0x7, 0x0), + Rel("44 0F BF 3D ?? ?? ?? ?? F3 0F 5E F0 66 0F 6E D0 8B C6 41 2B C7", 0x4, 0x8, 0x0)}}, + {&OFFSET_HALO1_PV_SCREEN_BOUNDS, 0x1b7d3dc, Data, { + Rel("48 8B 05 ?? ?? ?? ?? 45 33 C0 48 89 44 24 38 41 8B D7 48 8B 05", 0x3, 0x7, 0x0), + Rel("0F BF 0D ?? ?? ?? ?? 2B C1 40 0F B6 CD 66 41 03 CD 99 F7 7C 24 50", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_SCOPE_GRID_SET, 0xac73dc, Code, { + At("F3 44 0F 11 7C 24 48 EB ?? F3 44 0F 11 44 24 48 66 41 3B F8 7E ?? F3 44 0F 11 4C 24 44 EB ?? F3 0F 11 74 24 44 66 3B F9 7D ?? 66 85 F6 7F ?? 66 3B F9 75 ?? 66 41 3B F0 7F ?? 45 0F 57 FF F3 44 0F 11 7C 24 64 44 88 44 24 20 E9 ?? ??", 0x45)}}, + {&OFFSET_HALO1_PF_FILL_RECT, 0xac63f4, Code, { + At("48 89 5C 24 08 48 89 74 24 10 48 89 7C 24 18 55 48 8D 6C 24 80", 0x0), + Rel("BA 00 00 FF 80 48 8D 4C 24 40 E8 ?? ?? ?? ?? 48 83 C4 38 C3", 0xb, 0xf, 0x0)}}, + {&OFFSET_HALO1_PV_ANNIVERSARY_SHOWN, 0x1b7aa84, Data, { + Rel("83 3D ?? ?? ?? ?? 00 0F 94 40 D8 C7 40 DC 01 00 00 00 48 8D 0D", 0x2, 0x7, 0x0), + Rel("83 3D ?? ?? ?? ?? 00 74 ?? 48 85 C9 74 ?? 83 B9 28 02 00 00 00 75", 0x2, 0x7, 0x0)}}, }; diff --git a/lib/game/inc/1.3528.0.0/patterns_halo2.inc b/lib/game/inc/1.3528.0.0/patterns_halo2.inc index da008854..534fdd03 100644 --- a/lib/game/inc/1.3528.0.0/patterns_halo2.inc +++ b/lib/game/inc/1.3528.0.0/patterns_halo2.inc @@ -9,6 +9,9 @@ const OffsetPatterns kHalo2Patterns[] = { {&OFFSET_HALO2_PF_GAME, 0x67a220, Code, { At("40 53 55 56 57 41 54 41 56 41 57 48 83 EC 60 48 C7 44 24 20 FE FF FF FF 0F 29 74 24 50", 0x0), Rel("75 ?? E8 ?? ?? ?? ?? 8B 05 ?? ?? ?? ?? 83 F8 09 75 ?? 48 8D 8D 98 00 00 00 E8", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PF_COPY_GAME_OPTIONS, 0x39ce0, Code, { + At("40 53 48 81 EC 30 03 00 00 48 8B D1 48 8D 1D ?? ?? ?? ?? 48 8B CB", 0x0), + Rel("48 8B CF E8 ?? ?? ?? ?? 8B 4F 10 E8 ?? ?? ?? ?? B9 10 00 00 00 48 89 05", 0x4, 0x8, 0x0)}}, {&OFFSET_HALO2_PF_ADD_LOCAL_PLAYER, 0x69d2c0, Code, { At("48 89 5C 24 08 57 48 83 EC 20 48 8B FA 8B D1 48 8B 0D", 0x0), Rel("E8 ?? ?? ?? ?? FF C3 48 81 C7 D4 00 00 00 83 FB 10 7C ?? E8 ?? ?? ?? ?? E8", 0x1, 0x5, 0x0)}}, @@ -41,4 +44,25 @@ const OffsetPatterns kHalo2Patterns[] = { {&OFFSET_HALO2_PV_SCENARIO, 0xe6f768, Data, { Rel("48 8B 05 ?? ?? ?? ?? 8B DE 48 89 7C 24 68 39 98 10 02 00 00", 0x3, 0x7, 0x0), Rel("48 8B 05 ?? ?? ?? ?? 33 D2 4C 63 80 6C 01 00 00 41 83 F8 FF", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PF_SPLIT_GRID, 0x7e09d0, Code, { + At("48 89 5C 24 08 BB 01 00 00 00 44 8B D2 44 8B D9", 0x0), + Rel("E8 ?? ?? ?? ?? 44 8B 84 24 E0 00 00 00 48 8D 84 24 C8 00 00 00", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO2_PF_SPLIT_CELL, 0x7e0bd0, Code, { + At("48 89 5C 24 08 48 89 7C 24 10 4C 8B 54 24 30 49 8B F9", 0x0), + Rel("E8 ?? ?? ?? ?? 48 8D 87 B8 00 00 00 4C 8D 8F B0 00 00 00 48 89 44 24 20", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO2_PF_SPLIT_DIVIDERS, 0x831d90, Code, { + At("40 55 48 8B EC 48 83 EC 20 48 8B 05 ?? ?? ?? ?? 48 85 C0 74", 0x0), + Rel("E8 ?? ?? ?? ?? BA 04 00 00 00 4C 8D 05 ?? ?? ?? ?? 8D 4A FB 48 83 C4 28", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO2_PV_SPLIT_MODE, 0x165c168, Data, { + Rel("83 3D ?? ?? ?? ?? 01 0F 85 ?? ?? ?? ?? 4C 8D 45 18 48 8D 55 10 E8 ?? ?? ?? ?? 8B 45 18", 0x2, 0x7, 0x0), + Rel("89 3D ?? ?? ?? ?? E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 80 3D ?? ?? ?? ?? 00 74 ?? 48 8B 0D ?? ?? ?? ?? 41 B0 01 48 C7 C2 FF FF FF FF E8 ?? ?? ?? ?? F3 0F 10 15 ?? ?? ?? ?? 45 33 C9 BA FF FF FF FF 41 8D 49 01 E8 ?? ?? ?? ?? 48 8B 0D", 0x2, 0x6, 0x0)}}, + {&OFFSET_HALO2_PV_SPLIT_VIEWS, 0x165c16c, Data, { + Rel("B9 01 00 00 00 0F B6 C3 39 0D ?? ?? ?? ?? 0F 4E C1 48 83 C4 20", 0xa, 0xe, 0x0), + Rel("8B 05 ?? ?? ?? ?? 83 F8 02 7E ?? 83 F8 03 8B 45 10 99 75 ?? 2B C2", 0x2, 0x6, 0x0)}}, + {&OFFSET_HALO2_PV_ANNIVERSARY, 0xe21280, Data, { + Rel("48 89 44 24 48 83 3D ?? ?? ?? ?? 00 0F 94 84 24 A0 00 00 00", 0x7, 0xc, 0x0), + Rel("66 C7 83 80 00 00 00 00 00 83 3D ?? ?? ?? ?? 00 74 ?? 80 3D ?? ?? ?? ?? 00", 0xb, 0x10, 0x0)}}, + {&OFFSET_HALO2_PV_CLASSIC_SHOWN, 0x1e8ce73, Data, { + Rel("0F B6 0D ?? ?? ?? ?? 44 38 87 81 00 00 00 75 ?? 85 D2 74 ?? 84 C9", 0x3, 0x7, 0x0), + Rel("C6 05 ?? ?? ?? ?? 01 49 8B 5B 10 49 8B 6B 18 49 8B 73 20 49 8B 7B 28", 0x2, 0x7, 0x0)}}, }; diff --git a/lib/game/inc/1.3528.0.0/patterns_halo3.inc b/lib/game/inc/1.3528.0.0/patterns_halo3.inc index 0d4ddd71..4028b749 100644 --- a/lib/game/inc/1.3528.0.0/patterns_halo3.inc +++ b/lib/game/inc/1.3528.0.0/patterns_halo3.inc @@ -80,4 +80,39 @@ const OffsetPatterns kHalo3Patterns[] = { Rel("E8 ?? ?? ?? ?? 8B FB 4C 8D 9C 24 E0 01 00 00 8B C7 49 8B 5B 30", 0x1, 0x5, 0x0)}}, {&OFFSET_HALO3_PV_SPLITSCREEN_TABLE, 0x8ae0b0, Data, { Rel("48 8D 0D ?? ?? ?? ?? F3 0F 10 44 91 08 F3 0F 5C 04 91 0F 2F 05", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO3_PV_SCREEN_SIZE, 0x8ac3e8, Data, { + Rel("0F BF 05 ?? ?? ?? ?? 66 44 0F 6E D0 45 0F 5B D2 F3 44 0F 5E 15", 0x3, 0x7, 0x0), + Rel("8B 1D ?? ?? ?? ?? 66 41 0F 6E C7 0F 5B C0 66 0F 6E FB 0F 5B FF", 0x2, 0x6, 0x0)}}, + {&OFFSET_HALO3_PF_SPLITSCREEN_PLAYER_COUNT, 0x2e0928, Code, { + At("48 83 EC 28 E8 ?? ?? ?? ?? 84 C0 74 ?? E8 ?? ?? ?? ?? 84 C0 75 ?? 65 48 8B 04 25 58 00 00 00", 0x0), + Rel("E8 ?? ?? ?? ?? 83 F8 01 8B EF B9 00 01 00 00 40 0F 9F C5 E8", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3_PF_DRAW_SPLITSCREEN_BARS, 0x2d8174, Code, { + At("48 8B C4 48 89 58 10 48 89 70 18 48 89 78 20 55 41 54 41 55 41 56 41 57 48 8B EC", 0x0), + Rel("44 38 25 ?? ?? ?? ?? 74 ?? 44 38 25 ?? ?? ?? ?? 74 ?? E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 8D 4D D0", 0x18, 0x1c, 0x0)}}, + {&OFFSET_HALO3_PF_FILL_RECT, 0x1890c4, Code, { + At("4C 8B DC 48 83 EC 48 0F B7 41 06 44 0F B7 49 02", 0x0), + Rel("48 8D 4C 24 48 E8 ?? ?? ?? ?? 48 8B 5C 24 40 48 8B 6C 24 50", 0x6, 0xa, 0x0)}}, + {&OFFSET_HALO3_PF_RT_CREATE, 0x2757c8, Code, { + At("48 89 5C 24 20 4C 89 44 24 18 55 56 57 41 54 41 55 41 56 41 57 48 83 EC 70", 0x0), + Rel("48 03 4E 50 E8 ?? ?? ?? ?? 8B 4D 4F 0B C8 89 4D 4F 45 33 DB", 0x5, 0x9, 0x0)}}, + {&OFFSET_HALO3_PF_RT_POOL_RELEASE, 0x27613c, Code, { + At("48 8B C4 57 41 54 41 55 41 56 41 57 48 83 EC 30 48 C7 40 C8 FE FF FF FF 48 89 58 10 48 89 68 18 48 89 70 20 E8 ?? ?? ?? ?? 33 D2", 0x0), + Rel("E8 ?? ?? ?? ?? 41 0F B6 EC 45 33 F6 85 C0 41 0F 48 EE 48 8D 1D", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3_PF_RT_POOL_INIT, 0x275bbc, Code, { + At("48 8B C4 55 53 56 57 41 54 41 55 41 56 41 57 48 8D 68 88", 0x0), + Rel("E8 ?? ?? ?? ?? 45 0F B6 F4 45 33 FF 85 C0 45 0F 48 F7 E8 ?? ?? ?? ?? 44 22 F0", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3_PF_HUD_RESOLUTION, 0x2f1e38, Code, { + At("48 89 5C 24 08 57 48 83 EC 20 44 8B C9 E8 ?? ?? ?? ?? 41 8B C9", 0x0), + Rel("E8 ?? ?? ?? ?? 8B C8 8B C3 D3 E0 66 09 86 0E 04 00 00 39 7D 28", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3_PF_HUD_LAYOUT, 0x2ecf38, Code, { + At("48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 48 83 EC 20 48 8B 05 ?? ?? ?? ?? 33 DB 48 8B 35", 0x0), + Rel("E8 ?? ?? ?? ?? 8B 48 60 83 C1 03 66 44 0F 6E E9 45 0F 5B ED", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3_PF_VIEW_SETUP, 0x282ec4, Code, { + At("48 89 5C 24 10 48 89 6C 24 18 48 89 74 24 20 57 41 54 41 55 41 56 41 57 48 81 EC C0 00 00 00", 0x0), + Rel("E8 ?? ?? ?? ?? FF C6 49 81 C7 20 28 00 00 41 3B F4 7C ?? 8B 9D 90 03 00 00", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3_PF_TITLE_SAFE, 0x272010, Code, { + At("33 C0 89 01 0F B7 05 ?? ?? ?? ?? 66 89 41 06 0F B7 05 ?? ?? ?? ?? 66 89 41 04", 0x0), + Rel("E8 ?? ?? ?? ?? 66 83 85 10 09 00 00 50 BA 04 00 00 00 48 8D 4D 70", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3_VIEW_SETUP_TITLE_SAFE_RETURN, 0x282f10, Code, { + At("E8 ?? ?? ?? ?? 48 8D 15 ?? ?? ?? ?? 49 8B EF 49 8D 47 FC 4A 8D 04 B0 48 8D 0C 80", 0x5)}}, }; diff --git a/lib/game/inc/1.3528.0.0/patterns_halo3odst.inc b/lib/game/inc/1.3528.0.0/patterns_halo3odst.inc index c28ed987..a69482f9 100644 --- a/lib/game/inc/1.3528.0.0/patterns_halo3odst.inc +++ b/lib/game/inc/1.3528.0.0/patterns_halo3odst.inc @@ -20,4 +20,39 @@ const OffsetPatterns kHalo3odstPatterns[] = { Rel("44 8A 47 21 48 8D 55 97 41 8B CE E8 ?? ?? ?? ?? 3B C6 74 ?? EB", 0xc, 0x10, 0x0)}}, {&OFFSET_HALO3ODST_PV_SPLITSCREEN_TABLE, 0x8f1f10, Data, { Rel("48 8D 0D ?? ?? ?? ?? F3 0F 10 44 91 08 F3 0F 5C 04 91 0F 2F 05", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO3ODST_PV_SCREEN_SIZE, 0x8f0278, Data, { + Rel("8B 15 ?? ?? ?? ?? 41 8A C1 66 41 0F 6E 8E A0 01 00 00 F6 D8", 0x2, 0x6, 0x0), + Rel("0F BF 05 ?? ?? ?? ?? 4C 8B C1 45 33 DB 66 0F 6E C0 0F BF 05", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO3ODST_PF_SPLITSCREEN_PLAYER_COUNT, 0x313af0, Code, { + At("48 83 EC 28 E8 ?? ?? ?? ?? 84 C0 74 ?? E8 ?? ?? ?? ?? 84 C0 75 ?? 65 48 8B 04 25 58 00 00 00", 0x0), + Rel("E8 ?? ?? ?? ?? 8B D8 45 33 C0 41 8D 68 01 3B C5 41 0F 9F C0", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3ODST_PF_DRAW_SPLITSCREEN_BARS, 0x303c54, Code, { + At("48 8B C4 48 89 58 10 48 89 70 18 48 89 78 20 55 41 54 41 55 41 56 41 57 48 8B EC", 0x0), + Rel("E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 44 38 3D ?? ?? ?? ?? 0F 95 C2 48 63 0D ?? ?? ?? ?? 8D 41 01 89 05", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3ODST_PF_FILL_RECT, 0x1ba498, Code, { + At("4C 8B DC 48 83 EC 48 0F B7 41 06 44 0F B7 49 02", 0x0), + Rel("E8 ?? ?? ?? ?? B8 A8 00 00 00 49 8B CE 48 89 8D 58 0A 00 00", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3ODST_PF_RT_CREATE, 0x2a2c64, Code, { + At("48 89 5C 24 20 4C 89 44 24 18 55 56 57 41 54 41 55 41 56 41 57 48 81 EC 80 00 00 00", 0x0), + Rel("E8 ?? ?? ?? ?? 8B 4D 4F 44 8B 6D 8B 0B C8 8B 45 AF 44 8B 7C 24 38", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3ODST_PF_RT_POOL_RELEASE, 0x2a3400, Code, { + At("48 8B C4 57 41 54 41 55 41 56 41 57 48 83 EC 30 48 C7 40 C8 FE FF FF FF 48 89 58 10", 0x0), + Rel("E8 ?? ?? ?? ?? 41 0F B6 EC 45 33 F6 85 C0 41 0F 48 EE 48 8D 1D", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3ODST_PF_RT_POOL_INIT, 0x2a30f0, Code, { + At("40 55 53 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 E1 48 81 EC E8 00 00 00", 0x0), + Rel("E8 ?? ?? ?? ?? 45 33 ED 45 0F B6 F4 85 C0 45 0F 48 F5 E8 ?? ?? ?? ?? 44 22 F0", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3ODST_PF_HUD_RESOLUTION, 0x32dd0c, Code, { + At("48 89 5C 24 08 57 48 83 EC 20 44 8B C9 E8 ?? ?? ?? ?? 41 8B C9", 0x0), + Rel("E8 ?? ?? ?? ?? 4C 8D 9C 24 18 02 00 00 41 89 84 3E 68 15 00 00", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3ODST_PF_HUD_LAYOUT, 0x3284b4, Code, { + At("48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 48 83 EC 20 48 8B 05 ?? ?? ?? ?? 33 DB 48 8B 35", 0x0), + Rel("E8 ?? ?? ?? ?? 8B 88 04 01 00 00 83 C1 03 66 44 0F 6E E9 45 0F 5B ED", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3ODST_PF_VIEW_SETUP, 0x2abac8, Code, { + At("48 89 5C 24 10 48 89 6C 24 18 48 89 74 24 20 57 41 54 41 55 41 56 41 57 48 81 EC C0 00 00 00", 0x0), + Rel("E8 ?? ?? ?? ?? FF C6 49 81 C7 10 28 00 00 41 3B F4 7C ?? 8B 9D 38 03 00 00", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3ODST_PF_TITLE_SAFE, 0x29f634, Code, { + At("33 C0 89 01 0F B7 05 ?? ?? ?? ?? 66 89 41 06 0F B7 05 ?? ?? ?? ?? 66 89 41 04", 0x0), + Rel("E8 ?? ?? ?? ?? 66 83 85 10 09 00 00 50 BA 04 00 00 00 48 8D 4D 70", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3ODST_VIEW_SETUP_TITLE_SAFE_RETURN, 0x2abb14, Code, { + At("E8 ?? ?? ?? ?? 48 8D 15 ?? ?? ?? ?? 49 8B EF 49 8D 47 FC 4A 8D 04 B0 48 8D 0C 80", 0x5)}}, }; diff --git a/lib/game/inc/1.3528.0.0/patterns_halo4.inc b/lib/game/inc/1.3528.0.0/patterns_halo4.inc index 1c655c88..e1e77179 100644 --- a/lib/game/inc/1.3528.0.0/patterns_halo4.inc +++ b/lib/game/inc/1.3528.0.0/patterns_halo4.inc @@ -25,4 +25,73 @@ const OffsetPatterns kHalo4Patterns[] = { {&OFFSET_HALO4_PV_SPLITSCREEN_TABLE, 0xe84db0, Data, { Rel("48 8D 0D ?? ?? ?? ?? 66 0F 6E E0 0F 5B E4 0F 28 C3 0F 28 CB", 0x3, 0x7, 0x0), Rel("48 8D 0D ?? ?? ?? ?? 8B 0C 91 85 C9 74 ?? 83 E9 01 74 ?? 83 E9 01", 0x3, 0x7, -0x10)}}, + {&OFFSET_HALO4_PV_SCREEN_SIZE, 0xe84608, Data, { + Rel("0F BF 05 ?? ?? ?? ?? 8B DA 66 0F 6E D0 0F BF 41 02 0F 5B D2", 0x3, 0x7, 0x0), + Rel("8B 3D ?? ?? ?? ?? 0F 57 C0 F3 0F 2A 86 54 01 00 00 45 0F 57 C0", 0x2, 0x6, 0x0)}}, + {&OFFSET_HALO4_PF_SPLITSCREEN_PLAYER_COUNT, 0x122188, Code, { + At("48 83 EC 28 E8 ?? ?? ?? ?? 84 C0 74 ?? E8 ?? ?? ?? ?? 84 C0 75 ?? E8 ?? ?? ?? ?? 84 C0 75", 0x0), + Rel("E8 ?? ?? ?? ?? 45 33 FF 89 44 24 28 44 8B C0 44 89 7C 24 24", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO4_PF_DRAW_SPLITSCREEN_BARS, 0x3c66d4, Code, { + At("48 8B C4 48 89 58 18 55 56 57 41 54 41 55 41 56 41 57 48 8B EC", 0x0), + Rel("41 8A C4 75 ?? 41 8A C5 84 C0 74 ?? E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 8D 0D", 0x12, 0x16, 0x0)}}, + {&OFFSET_HALO4_PF_FILL_RECT, 0x12d694, Code, { + At("40 53 48 83 EC 30 0F BF 05 ?? ?? ?? ?? 8B DA 66 0F 6E D0 0F BF 41 02", 0x0), + Rel("E8 ?? ?? ?? ?? 41 8B CE 66 89 5D 48 D1 F9 41 8B D7 0F B7 C1", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO4_PF_RENDER_SETUP_1, 0x34d224, Code, { + At("48 89 5C 24 08 48 63 C2 48 8D 1D ?? ?? ?? ?? 4C 6B D0 70 4C 63 D9", 0x0), + Rel("33 D2 33 C9 E8 ?? ?? ?? ?? 48 8B 5C 24 60 48 83 C4 40 5F C3", 0x5, 0x9, 0x0)}}, + {&OFFSET_HALO4_PF_RENDER_SETUP_2, 0x34d14c, Code, { + At("48 89 5C 24 08 44 8B 15 ?? ?? ?? ?? 48 8D 1D ?? ?? ?? ?? 44 8B 1D ?? ?? ?? ?? 33 D2", 0x0), + Rel("E8 ?? ?? ?? ?? 48 8D 44 24 78 C7 44 24 28 02 00 00 00 4C 8D 4D 20", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO4_PF_RT_VARIANT_SIZE, 0x37e8b4, Code, { + At("48 8B C4 48 89 58 08 48 89 68 10 48 89 70 18 57 41 56 41 57 48 83 EC 60 44 8B 51 10", 0x0), + Rel("E8 ?? ?? ?? ?? 33 D2 F6 43 10 08 74 ?? 8B 4D 67 85 C9 74 ?? 83 F9 01", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO4_PF_RT_POOL_RELEASE, 0x37f610, Code, { + At("48 8B C4 57 41 54 41 55 41 56 41 57 48 83 EC 30 48 C7 40 C8 FE FF FF FF 48 89 58 10 48 89 68 18 48 89 70 20 45 33 E4", 0x0), + Rel("E8 ?? ?? ?? ?? F7 D8 40 1A ED 40 80 E5 01 48 8D 1D ?? ?? ?? ?? 45 33 F6", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO4_PF_RT_POOL_INIT, 0x37f3a8, Code, { + At("48 89 5C 24 20 55 56 57 48 83 EC 30 33 D2 48 8D 0D", 0x0), + Rel("E8 ?? ?? ?? ?? 41 0F B6 F4 45 33 FF 85 C0 41 0F 48 F7 41 8D 4C 24 0F", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO4_PF_HUD_LAYOUT, 0x3bd78c, Code, { + At("40 53 48 83 EC 20 48 63 D9 E8 ?? ?? ?? ?? 41 B8 76 00 08 00", 0x0), + Rel("E8 ?? ?? ?? ?? 44 8B 57 08 44 8B C8 8B 17 44 8B C3 48 8B 0D", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO4_PF_COMPUTE_VIEWPORT_RECT, 0x38ee74, Code, { + At("48 89 5C 24 08 48 89 74 24 10 48 89 7C 24 18 0F BF 05", 0x0), + Rel("E8 ?? ?? ?? ?? 0F 57 DB 33 D2 48 8B CB 4C 8B C5 E8 ?? ?? ?? ?? 48 8B 5C 24 30", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO4_VIEWMODEL_ASPECT_DIVIDE, 0x34ed96, Code, { + At("F3 0F 5E E8 83 FF FF 74 ?? 8B 0D ?? ?? ?? ?? 65 48 8B 04 25 58 00 00 00", 0x0)}}, + {&OFFSET_HALO4_PF_HUD_UPDATE, 0x3bcf88, Code, { + At("48 8B C4 48 89 58 18 55 56 57 41 54 41 55 41 56 41 57 48 8D A8 58 F7 FF FF", 0x0), + Rel("E8 ?? ?? ?? ?? 40 84 F6 74 ?? 42 8B 04 2B B9 04 00 00 00 89 04 1F", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO4_PF_HUD_RENDER, 0x3f7a7c, Code, { + At("48 89 5C 24 18 55 56 57 41 54 41 55 41 56 41 57 48 8D AC 24 80 D6 FF FF", 0x0), + Rel("E8 ?? ?? ?? ?? 48 85 FF 74 ?? 48 8B 07 49 89 44 EE 04 48 8B 5C 24 50", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO4_PF_UI_WIDE, 0x3dbb8c, Code, { + At("0F BF 05 ?? ?? ?? ?? 0F 57 DB 0F 57 C0 F3 0F 2A D8 0F BF 05", 0x0), + Rel("F3 0F 11 8B AC 00 00 00 E8 ?? ?? ?? ?? 84 C0 0F 84 ?? ?? ?? ?? 48 8D 0D", 0x9, 0xd, 0x0)}}, + {&OFFSET_HALO4_PF_UI_ASPECT, 0x3dbbec, Code, { + At("0F BF 05 ?? ?? ?? ?? 84 C9 75 ?? 66 0F 6E C0 0F BF 05 ?? ?? ?? ?? 0F 5B C0", 0x0), + Rel("E8 ?? ?? ?? ?? 0F 28 D6 F3 0F 5E D0 F3 0F 5C F2 F3 0F 59 35", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO4_PF_UI_EXTRA_WIDTH, 0x3dbc40, Code, { + At("48 83 EC 28 0F BF 05 ?? ?? ?? ?? 66 0F 6E C8 0F BF 05 ?? ?? ?? ?? 0F 5B C9", 0x0), + Rel("E8 ?? ?? ?? ?? 66 0F 6E 93 DC 01 00 00 0F 5B D2 F3 0F 59 C2", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO4_PF_UI_EXTRA_HEIGHT, 0x3dbc98, Code, { + At("48 83 EC 28 0F BF 05 ?? ?? ?? ?? F3 0F 10 0D ?? ?? ?? ?? 66 0F 6E D0 0F BF 05", 0x0), + Rel("E8 ?? ?? ?? ?? F3 0F 10 9B C0 00 00 00 F3 0F 58 9B BC 00 00 00", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO4_PF_UI_ANCHOR, 0x3fd3e8, Code, { + At("48 89 5C 24 10 48 89 6C 24 18 48 89 7C 24 20 41 56 48 83 EC 20 48 8B FA", 0x0), + Rel("48 8B D9 E8 ?? ?? ?? ?? 48 8D 8B E8 01 00 00 48 83 C4 20 5B", 0x4, 0x8, 0x0)}}, + {&OFFSET_HALO4_PF_UI_FIT_RANGE, 0x4224f0, Code, { + At("48 89 5C 24 10 48 89 6C 24 18 48 89 74 24 20 57 48 83 EC 30 80 79 28 02", 0x0)}}, + {&OFFSET_HALO4_PF_UI_USER_INDEX, 0x3a7bdc, Code, { + At("49 83 CA FF 41 8B D2 41 3B CA 74 ?? 33 D2 45 33 C0", 0x0), + Rel("E8 ?? ?? ?? ?? 48 8D 7B 08 48 63 E8 48 8B 17 48 8B CF FF 12", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO4_PF_UI_SCREEN_RENDER, 0x3d6184, Code, { + At("48 89 5C 24 18 55 56 57 48 8D AC 24 50 FE FF FF", 0x0)}}, + {&OFFSET_HALO4_VT_HUD_RETICLE_GROUP, 0xd6c2d0, Data, { + Rel("48 8D 05 ?? ?? ?? ?? 48 89 03 83 8B E8 01 00 00 FF C6 83 EC 01 00 00 00", 0x3, 0x7, 0x0), + Rel("48 8D 05 ?? ?? ?? ?? 48 89 03 8B 87 E8 01 00 00 89 83 E8 01 00 00 8A 87 EC 01 00 00", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO4_VT_UI_GROUP, 0xd7de70, Data, { + Rel("48 8D 05 ?? ?? ?? ?? 48 89 03 83 C8 FF 89 83 E8 01 00 00 89 83 EC 01 00 00 EB", 0x3, 0x7, 0x0), + Rel("48 8D 05 ?? ?? ?? ?? 48 89 03 8B 87 E8 01 00 00 89 83 E8 01 00 00 8B 87 EC 01 00 00 89 83 EC 01 00 00 EB", 0x3, 0x7, 0x0)}}, }; diff --git a/tools/offsets/gen_patterns.py b/tools/offsets/gen_patterns.py index bef71e0c..32b981e5 100644 --- a/tools/offsets/gen_patterns.py +++ b/tools/offsets/gen_patterns.py @@ -50,14 +50,18 @@ "OFFSET_HALO2_PF_QUIT_TO_LOBBY_TEST": 9, "OFFSET_HALO4_PF_COOP_PLAYER_LIMIT": 6, "OFFSET_HALO4_PF_COOP_REJOIN": 2, + "OFFSET_HALO4_VIEWMODEL_ASPECT_DIVIDE": 4, "OFFSET_GROUNDHOG_PF_REJOIN": 2, "OFFSET_HALOREACH_PF_COOP_REJOIN": 2, "OFFSET_HALOREACH_PF_RENDER_THROTTLE_COUNT_CALL": 5, } # Mid-function hooks whose detours rewrite what the code before them set up: the pattern starts at least this many -# bytes earlier (none yet). An offset right after a call - a return address - always takes the call as well. -COVER_BEFORE = {} +# bytes earlier (halo1/splitscreen.cpp ScopeGrid: rsp+0x40..0x48 and 0x64/xmm15). An offset right after a call - a +# return address - always takes the call as well. +COVER_BEFORE = { + "OFFSET_HALO1_SCOPE_GRID_SET": 0x45, +} # Offsets with no binary here to pattern from. SKIP = { From be926cc6dcbc3490dd38c02448c8f5b7d3c4fd0a Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:03:23 -0400 Subject: [PATCH 03/17] feat(splitscreen): one Left/Right choice for every game src/mcc/splitscreen/LeftRight takes XiaoDanny's saved layout choice (SplitscreenConfigStore's TwoPlayerLayout) to the other games. It does what his Reach port showed the layout takes - the table's regions, the black bars, the half-screen render target and the HUD's shape - for the Gen3 games, which share Reach's table and render-target pool (each says where those live in a LeftRight::Gen3), and keeps the choice for Halo CE and Halo 2, which take it as a mission starts. Reach keeps its own implementation. - Active() is the choice with 2 or 3 players on screen. Reach's own gate (LeftRightAvailable: every Reach hook that draws it) stays on Reach's paths, so it doesn't hold the other games back. - Choose() saves the choice and puts it on screen in whichever game is running, re-applying Reach's enabled patches over the stock entries on Top / Bottom. - The store makes LayoutEntry public and gives each slot's Left/Right region (LeftRightRegion). Load() now runs as any game module loads: the render targets are built for the saved choice. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/CModule.cpp | 5 +- .../module/patch/SplitscreenConfigStore.cpp | 12 +- src/mcc/module/patch/SplitscreenConfigStore.h | 13 ++ src/mcc/splitscreen/LeftRight.cpp | 191 ++++++++++++++++++ src/mcc/splitscreen/LeftRight.h | 101 +++++++++ 5 files changed, 314 insertions(+), 8 deletions(-) create mode 100644 src/mcc/splitscreen/LeftRight.cpp create mode 100644 src/mcc/splitscreen/LeftRight.h diff --git a/src/mcc/module/CModule.cpp b/src/mcc/module/CModule.cpp index 286a9d6b..cc9f6c10 100644 --- a/src/mcc/module/CModule.cpp +++ b/src/mcc/module/CModule.cpp @@ -28,6 +28,10 @@ void CModule::load_module(const module_info_t *p_info) { m_info = *p_info; + // The split-screen layout choice has to be known before the game builds its render targets + // (mcc/splitscreen/LeftRight), in every game, not only Reach. + AlphaRing::SplitscreenConfigStore::Load(); + m_patches.update(m_info.hModule, known_build); if (!known_build) { @@ -67,7 +71,6 @@ void CModule::load_module(const module_info_t *p_info) { // drawn. HaloReach::Entry::Render re-asserts them per frame; this is the // "already correct before the first frame" half. if (m_info.title == MCC::Module::MODULE_HALOREACH) { - AlphaRing::SplitscreenConfigStore::Load(); if (AlphaRing::SplitscreenConfigStore::GetTwoPlayerLayout() == AlphaRing::SplitscreenConfigStore::TwoPlayerLayout::LeftRight && !AlphaRing::SplitscreenConfigStore::LeftRightAvailable()) diff --git a/src/mcc/module/patch/SplitscreenConfigStore.cpp b/src/mcc/module/patch/SplitscreenConfigStore.cpp index 4cc7663d..1698cd0e 100644 --- a/src/mcc/module/patch/SplitscreenConfigStore.cpp +++ b/src/mcc/module/patch/SplitscreenConfigStore.cpp @@ -56,13 +56,7 @@ namespace { ~WritesLock() { ReleaseSRWLockExclusive(&g_writesLock); } }; - struct LayoutEntry { - float x0; - float y0; - float x1; - float y1; - __int32 resolution; - }; + using AlphaRing::SplitscreenConfigStore::LayoutEntry; static_assert(sizeof(LayoutEntry) == AlphaRing::SplitscreenConfigStore::ENTRY_SIZE); constexpr LayoutEntry kTopBottom[2] = { @@ -322,6 +316,10 @@ namespace AlphaRing::SplitscreenConfigStore { return entry.resolution == 3; } + const LayoutEntry& LeftRightRegion(int playerCount, int slot) { + return playerCount == 2 ? kLeftRight[slot] : kLeftRight3P[slot]; + } + void SetTwoPlayerLayout(TwoPlayerLayout layout, __int64 hModule) { g_states[MakeKey(-1, "two_player_layout")] = (float)layout; g_states.erase(MakeKey(-1, "vertical_split")); diff --git a/src/mcc/module/patch/SplitscreenConfigStore.h b/src/mcc/module/patch/SplitscreenConfigStore.h index 99286759..a41ccbb0 100644 --- a/src/mcc/module/patch/SplitscreenConfigStore.h +++ b/src/mcc/module/patch/SplitscreenConfigStore.h @@ -68,6 +68,19 @@ namespace AlphaRing::SplitscreenConfigStore { // CUI (half -> quarter variant) corrections both key on it. bool UsesFullHeightLeftRightSlot(int playerCount, int slot); + // One m_config_table entry. Halo 3, ODST and Halo 4 share Reach's table layout, so the + // Left/Right regions serve them too (mcc/splitscreen/LeftRight). + struct LayoutEntry { + float x0; + float y0; + float x1; + float y1; + __int32 resolution; + }; + + // The Left/Right region of a slot with 2 or 3 players. + const LayoutEntry& LeftRightRegion(int playerCount, int slot); + // Incremented only when the published TwoPlayerLayout actually changes, // after the new geometry is in the table. Both layouts share res=3, so the // render-target pool cannot tell them apart by variant; this generation is diff --git a/src/mcc/splitscreen/LeftRight.cpp b/src/mcc/splitscreen/LeftRight.cpp new file mode 100644 index 00000000..95386489 --- /dev/null +++ b/src/mcc/splitscreen/LeftRight.cpp @@ -0,0 +1,191 @@ +#include "LeftRight.h" + +#include "common.h" + +#include "mcc/CGameGlobal.h" +#include "mcc/module/CModule.h" + +#include +#include +#include +#include +#include + +namespace MCC::Splitscreen::LeftRight { + namespace Store = AlphaRing::SplitscreenConfigStore; + + namespace { + // The table entries the layout owns: 2-player slots 0-1 and 3-player slots 0-2. + struct Slot { int players, slot; }; + constexpr Slot kSlots[] = {{2, 0}, {2, 1}, {3, 0}, {3, 1}, {3, 2}}; + static_assert(std::size(kSlots) == sizeof(State::saved) / sizeof(State::saved[0])); + + // The render-target variant (the table's "resolution") the full-height halves draw into. The stock + // two-player layout uses it too, so no other view shares its surface. + constexpr int kHalfSurface = 3; + + std::atomic s_classic_side_by_side{-1}; // the Halo CE / Halo 2 game whose mission started side by side + + bool ClassicGame(int game) { return game == CGameGlobal::Halo1 || game == CGameGlobal::Halo2; } + + Store::LayoutEntry* Entry(const Gen3& game, __int64 module, const Slot& s) { + return (Store::LayoutEntry*)(module + game.table) + s.players * Store::SLOT_COUNT + s.slot; + } + + const int* Screen(const Gen3& game, __int64 module) { return (const int*)(module + game.screen); } + + // A descriptor size in pixels, as the pool computes it: flag bit 0 makes the value a divisor of the + // screen size, rounded half up; otherwise it is the size itself. + int Pixels(const Gen3& game, float value, int screen, unsigned flags) { + if (!(flags & 1)) return (int)value; + float divided = (float)screen / (std::max)(value, 1.0f); + return game.double_rounding ? (int)std::floor((double)divided + 0.5) : (int)std::floor(divided + 0.5f); + } + } + + int Players(const Gen3& game, __int64 module) { return ((int (*)())(module + game.player_count))(); } + + bool Chosen() { + return Store::GetTwoPlayerLayout() == Store::TwoPlayerLayout::LeftRight; + } + + bool Active(int player_count) { + return Chosen() && (player_count == 2 || player_count == 3); + } + + bool Supports(int game, int player_count) { + switch (game) { + case CGameGlobal::Halo1: case CGameGlobal::Halo2: case CGameGlobal::Halo3: case CGameGlobal::Halo4: + case CGameGlobal::Halo3ODST: case CGameGlobal::HaloReach: + return player_count == 2 || player_count == 3; + default: + return false; + } + } + + bool OnScreen(int game, int player_count) { + return Supports(game, player_count) && + (ClassicGame(game) ? s_classic_side_by_side == game : Chosen()) && + (game != CGameGlobal::HaloReach || Store::LeftRightAvailable()); + } + + void StartClassicMission(int game, bool side_by_side) { s_classic_side_by_side = side_by_side ? game : -1; } + + void Choose(bool left_right) { + auto reach = MCC::Module::GetSubModule(MCC::Module::MODULE_HALOREACH); + Store::SetTwoPlayerLayout(left_right ? Store::TwoPlayerLayout::LeftRight : Store::TwoPlayerLayout::TopBottom, + reach->info().hModule); + // Reach's store writes the stock entries back over any black-bar patch the player turned on. + if (!left_right) reach->patches()->apply(); + } + + void Frame(const Gen3& game, __int64 module, State& state) { + if (state.module != module) { + state.module = module; + state.table_left_right = false; + } + + if (Chosen()) { + for (size_t i = 0; i < std::size(kSlots); ++i) { + auto entry = Entry(game, module, kSlots[i]); + if (!state.table_left_right) state.saved[i] = *entry; + auto& want = Store::LeftRightRegion(kSlots[i].players, kSlots[i].slot); + if (memcmp(entry, &want, sizeof(want)) != 0) CPatch::apply(entry, &want, sizeof(want)); + } + state.table_left_right = true; + } else if (state.table_left_right) { + for (size_t i = 0; i < std::size(kSlots); ++i) + CPatch::apply(Entry(game, module, kSlots[i]), &state.saved[i], sizeof(state.saved[i])); + state.table_left_right = false; + } + + // The pool sizes its surfaces once, so a switch rebuilds it: the same release/init pair the + // engine's own resize path runs right before this render call, minus the swap-chain resize. + unsigned generation = Store::GetLayoutGeneration(); + if (state.built != generation) { + ((void (*)())(module + game.pool_release))(); + ((void (*)())(module + game.pool_init))(); + state.built = generation; + } + } + + bool PaintDividers(const Gen3& game, __int64 module) { + if (!Chosen()) return false; + int players = Players(game, module); + if (!Active(players)) return false; + + // the stock dividers are 2px bands at the screen's middle + if (game.before_painting) game.before_painting(module); + auto screen = Screen(game, module); + PaintBands({0, 0, (short)screen[1], (short)screen[0]}, 1, players, + (void (*)(Rect*, unsigned))(module + game.fill_rect)); + return true; + } + + void PaintBands(const Rect& screen, short half_width, int players, void (*fill)(Rect*, unsigned argb)) { + short middle_x = (short)((screen.left + screen.right) / 2), middle_y = (short)((screen.top + screen.bottom) / 2); + Rect down{screen.top, (short)(middle_x - half_width), screen.bottom, (short)(middle_x + half_width)}; + fill(&down, 0xFF000000); + if (players == 3) { + Rect across{(short)(middle_y - half_width), middle_x, (short)(middle_y + half_width), screen.right}; + fill(&across, 0xFF000000); + } + } + + int HudResolution(const Gen3& game, __int64 module, State& state, int user, int resolution) { + bool half = resolution == 1 || resolution == 5; + bool tall = half && Chosen() && Active(Players(game, module)); + if (user >= 0 && user < 4) state.tall_hud[user] = tall; + if (tall) resolution = resolution == 1 ? 4 : 6; + // a quarter has the screen's own shape, so the full-screen layout (0, or 2 on 4:3) fits it whole + if (game.whole_quarter_hud) resolution = resolution == 4 ? 0 : resolution == 6 ? 2 : resolution; + return resolution; + } + + const void* HudLayout(const Gen3& game, __int64 module, State& state, int user, const void* layout) { + if (layout == nullptr || user < 0 || user >= 4 || !state.tall_hud[user]) return layout; + auto copy = state.hud_layouts[user]; + memcpy(copy, layout, (std::min)(game.hud_layout_size, kMaxHudLayoutSize)); + auto screen = Screen(game, module); + auto canvas = (int*)(copy + game.hud_canvas); + if (screen[0] > 1) canvas[1] = (int)((float)canvas[0] * screen[1] / (screen[0] / 2) + 0.5f); + return copy; + } + + bool ResizesHalfSurface(State& state, int variant) { + state.built = Store::GetLayoutGeneration(); + return Chosen() && (variant & 3) == kHalfSurface; + } + + void SizeSurface(const Gen3& game, __int64 module, State& state, int* sizes, const unsigned char* desc, + int variant) { + if (!ResizesHalfSurface(state, variant) || !sizes || !desc) return; + + unsigned flags = *(const unsigned*)desc; + if (!(flags & 0x20)) return; // not sized per view variant + + auto screen = Screen(game, module); + auto field = [&](int offset) { return *(const float*)(desc + offset); }; + int w1 = Pixels(game, field(0x08), screen[0], flags), h1 = Pixels(game, field(0x0C), screen[1], flags); + int w2 = Pixels(game, field(0x20), screen[0], flags), h2 = Pixels(game, field(0x24), screen[1], flags); + bool same = (flags & 6) == 2; // the second pair copies the first + + int* pair1 = sizes + 6; + int* pair2 = sizes + 1; + if (pair1[0] != w1 * 3 / 4 || pair1[1] != h1 / 2 || + (!same && (pair2[0] != w2 * 3 / 4 || pair2[1] != h2 / 2))) { + static bool logged; + if (!logged) { + logged = true; + LOG_WARNING("Left/Right split: render target {}x{} does not match its descriptor, left stock", + pair1[0], pair1[1]); + } + return; + } + + pair1[0] = w1 / 2; + pair1[1] = h1; + pair2[0] = same ? pair1[0] : w2 / 2; + pair2[1] = same ? pair1[1] : h2; + } +} diff --git a/src/mcc/splitscreen/LeftRight.h b/src/mcc/splitscreen/LeftRight.h new file mode 100644 index 00000000..f4f37387 --- /dev/null +++ b/src/mcc/splitscreen/LeftRight.h @@ -0,0 +1,101 @@ +#pragma once + +#include "Offset.h" +#include "mcc/module/patch/SplitscreenConfigStore.h" + +// The Left/Right split screen in every game. One saved choice (the store's TwoPlayerLayout) drives them all. +// XiaoDanny's Reach port (mcc/module/patch/SplitscreenConfigStore, module/entry/haloreach) showed what the +// layout takes: the split-screen table's regions, the black-bar painter, the render target the half-screen +// views draw into and the HUD's shape. Halo 3, ODST and Halo 4 share Reach's table and render-target pool +// design, so each says where those live in a Gen3 below; Halo 2 and CE lay their views out on a grid +// (module/entry/halo2, halo1). Reach keeps its own implementation (module/entry/haloreach). +namespace MCC::Splitscreen::LeftRight { + // A screen rectangle in the engines' order. + struct Rect { short top, left, bottom, right; }; + + // Left/Right is the saved choice. + bool Chosen(); + + // Left/Right is what `player_count` local players see: it is chosen and 2 or 3 players are on screen. + // (Reach's own paths also need every Reach hook that draws it, SplitscreenConfigStore::LeftRightAvailable.) + bool Active(int player_count); + + // `game` (CGameGlobal::eGame) has the layout for `player_count` players. + bool Supports(int game, int player_count); + + // Left/Right is what `player_count` players of `game` see. Halo CE and Halo 2 are side by side only in + // Classic graphics, which a mission starts in (Splitscreen::ClassicGraphicsScope): for them this is whether + // the mission running now started side by side, and their hooks also ask the game whether Classic graphics + // are still on screen (Back switches to Anniversary's stacked views in the middle of a mission). + bool OnScreen(int game, int player_count); + + // A Halo CE or Halo 2 mission starts, side by side or not; the choice takes effect there at the next one. + void StartClassicMission(int game, bool side_by_side); + + // Saves the choice and puts it on screen in whichever game is running. + void Choose(bool left_right); + + // Where a Gen3 engine keeps what the layout touches (module-relative addresses). + struct Gen3 { + const AlphaRing::Offset& table; // c_splitscreen_config::m_config_table, {x0, y0, x1, y1, variant}[players * 4 + slot] + const AlphaRing::Offset& screen; // int width, height the views are laid out on + const AlphaRing::Offset& player_count; // int () - local players on screen + const AlphaRing::Offset& fill_rect; // void (short rect[4] {top, left, bottom, right}, unsigned argb) + const AlphaRing::Offset& pool_release; // the render-target pool teardown and rebuild the engine's resize path runs + const AlphaRing::Offset& pool_init; + void (*before_painting)(__int64 module) = nullptr; // render state the painter sets up itself (Halo 4) + bool double_rounding = false; // render-target sizes are rounded in double precision (Halo 3), not float + int hud_layout_size = 0; // bytes in a HUD layout record (chud globals) ... + int hud_canvas = 0; // ... where it keeps its int canvas width, height (Halo 3, ODST) + bool whole_quarter_hud = false; // quarters use the full-screen HUD layout (ODST: its quarter ones lack most elements) + }; + + constexpr int kMaxHudLayoutSize = 0x110; + + // Local players on screen (the game's player_count). + int Players(const Gen3& game, __int64 module); + + // Per-game runtime state, one per game module. + struct State { + __int64 module = 0; + bool table_left_right = false; // the table holds the Left/Right regions + AlphaRing::SplitscreenConfigStore::LayoutEntry saved[5]{}; // the entries they replaced (kSlots) + unsigned built = 0; // layout generation the render targets were made for + bool tall_hud[4]{}; // the user's HUD was switched to a full-height half's + unsigned char hud_layouts[4][kMaxHudLayoutSize]{}; // ... layout, and its layout record, reshaped + }; + + // Before each frame is drawn: keeps the table on the chosen layout (restoring the game's own regions, + // black-bar patches included, when Left/Right is turned off) and rebuilds the render targets when the + // choice changed since they were made. + void Frame(const Gen3& game, __int64 module, State& state); + + // In place of the black-bar painter: draws the Left/Right dividers and returns true while the layout + // is on screen; returns false to let the game paint its own bars. + bool PaintDividers(const Gen3& game, __int64 module); + + // The Left/Right dividers on `screen`, bands `half_width` either side of its middle: one down it, and for + // three players one across the right half, where players 2 and 3 share it. + void PaintBands(const Rect& screen, short half_width, int players, void (*fill)(Rect*, unsigned argb)); + + // The HUD of a full-height half. The engine picks a player's HUD layout by the shape of their view + // (resolution 1 for a two-player half, 4 for a quarter; 5 and 6 on 4:3 screens) and each layout has a + // virtual canvas, stretched over the view. No layout is taller than 4:3, so a Left/Right half takes a + // quarter's layout - made for a view half the screen wide - and its canvas is made as tall as the + // view, which keeps the HUD at a quarter's size without stretching it and puts the elements the + // layout anchors at the bottom (the motion tracker) at the bottom of the half. + int HudResolution(const Gen3& game, __int64 module, State& state, int user, int resolution); + const void* HudLayout(const Gen3& game, __int64 module, State& state, int user, const void* layout); + + // From a render-target sizing hook: records that the pool is being built for the current choice, and + // returns true when a target of this variant is the full-height halves' surface while Left/Right is + // chosen - the caller then makes it half the screen's width and its full height. + bool ResizesHalfSurface(State& state, int variant); + + // ResizesHalfSurface for the pool's creation hook (Halo 3, ODST): `sizes` holds the target's two {w, h} + // pairs (at + 0x18 and + 0x04), already shrunk to the stock variant's three quarters by half. The + // unshrunk sizes are recomputed from the descriptor and only used when they reproduce the pool's own + // result, so a misread descriptor keeps the stock size. + void SizeSurface(const Gen3& game, __int64 module, State& state, int* sizes, const unsigned char* desc, + int variant); +} From ba6da91679375d0b0442c067ba272679266661fc Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:03:27 -0400 Subject: [PATCH 04/17] feat(halo3): side by side Halo 3's Left/Right split screen (LeftRight::Gen3): - before each frame the table's 2- and 3-player entries are kept on the Left/Right regions; going back to Top / Bottom puts the entries they replaced back, black-bar patches included; - the divider painter draws a band down the middle (and one across the right half for 3 players) instead of the black bars; - the variant-3 render target, the full-height halves' surface, is made half the screen wide and full height, from the pool's descriptor and only when that reproduces the pool's own size; a live switch rebuilds the pool with the engine's own release/init pair; - a full-height half's HUD takes the quarter layout with its canvas as tall as the view, so the motion tracker sits at the bottom. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/entry/halo3/splitscreen.cpp | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/mcc/module/entry/halo3/splitscreen.cpp diff --git a/src/mcc/module/entry/halo3/splitscreen.cpp b/src/mcc/module/entry/halo3/splitscreen.cpp new file mode 100644 index 00000000..582a9ed3 --- /dev/null +++ b/src/mcc/module/entry/halo3/splitscreen.cpp @@ -0,0 +1,47 @@ +// Left/Right split screen for Halo 3 (mcc/splitscreen/LeftRight), after XiaoDanny's Reach port. +#include "halo3.h" + +#include "mcc/splitscreen/LeftRight.h" + +namespace Halo3::Entry::Splitscreen { + namespace LeftRight = MCC::Splitscreen::LeftRight; + + constexpr LeftRight::Gen3 kGame { + OFFSET_HALO3_PV_SPLITSCREEN_TABLE, OFFSET_HALO3_PV_SCREEN_SIZE, OFFSET_HALO3_PF_SPLITSCREEN_PLAYER_COUNT, + OFFSET_HALO3_PF_FILL_RECT, OFFSET_HALO3_PF_RT_POOL_RELEASE, OFFSET_HALO3_PF_RT_POOL_INIT, + nullptr, true, 0x64, 0x10, + }; + LeftRight::State s_state; + + EntryFeature("Halo 3 Left/Right split screen", OFFSET_HALO3_PV_SPLITSCREEN_TABLE, OFFSET_HALO3_PV_SCREEN_SIZE, + OFFSET_HALO3_PF_SPLITSCREEN_PLAYER_COUNT, OFFSET_HALO3_PF_FILL_RECT, OFFSET_HALO3_PF_RT_POOL_RELEASE, + OFFSET_HALO3_PF_RT_POOL_INIT); + + Halo3Entry(entry_render, OFFSET_HALO3_PF_RENDER, void, render) { + LeftRight::Frame(kGame, entry_render.m_target - entry_render.m_offset, s_state); + ((render_t)entry_render.m_pOriginal)(); + } + + Halo3Entry(entry_bars, OFFSET_HALO3_PF_DRAW_SPLITSCREEN_BARS, void, draw_bars) { + if (!LeftRight::PaintDividers(kGame, entry_bars.m_target - entry_bars.m_offset)) + ((draw_bars_t)entry_bars.m_pOriginal)(); + } + + Halo3Entry(entry_hud_resolution, OFFSET_HALO3_PF_HUD_RESOLUTION, int, hud_resolution, int user) { + int resolution = ((hud_resolution_t)entry_hud_resolution.m_pOriginal)(user); + return LeftRight::HudResolution(kGame, entry_hud_resolution.m_target - entry_hud_resolution.m_offset, + s_state, user, resolution); + } + + Halo3Entry(entry_hud_layout, OFFSET_HALO3_PF_HUD_LAYOUT, const void*, hud_layout, int user, int resolution) { + auto layout = ((hud_layout_t)entry_hud_layout.m_pOriginal)(user, resolution); + return LeftRight::HudLayout(kGame, entry_hud_layout.m_target - entry_hud_layout.m_offset, s_state, user, + layout); + } + + Halo3Entry(entry_rt, OFFSET_HALO3_PF_RT_CREATE, __int64, create_target, void* target, int* sizes, + const unsigned char* desc, int variant) { + LeftRight::SizeSurface(kGame, entry_rt.m_target - entry_rt.m_offset, s_state, sizes, desc, variant); + return ((create_target_t)entry_rt.m_pOriginal)(target, sizes, desc, variant); + } +} From 757c30295c97bb85deef7f41b9ce69d9e2bbdfd2 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:05:03 -0400 Subject: [PATCH 05/17] feat(odst): side by side, and the whole HUD with 3-4 players ODST's Left/Right split screen, as Halo 3's (LeftRight::Gen3). ODST never shipped four-player split screen: its quarter HUD layouts carry only the ammo panel - no compass, health or grenades. Quarters and full-height halves use the full-screen layouts instead (Gen3::whole_quarter_hud), in both layouts: with Top / Bottom too, for 3-4 players. CModule now installs ODST's hooks. render.cpp's render hook did nothing, and its target is the split-screen render hook's, so it goes. This also installs ODST's existing engine and world hooks (native info, task queue), as Halo 3's are. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/CModule.cpp | 2 +- src/mcc/module/entry/halo3odst/render.cpp | 29 ----------- .../module/entry/halo3odst/splitscreen.cpp | 50 +++++++++++++++++++ 3 files changed, 51 insertions(+), 30 deletions(-) delete mode 100644 src/mcc/module/entry/halo3odst/render.cpp create mode 100644 src/mcc/module/entry/halo3odst/splitscreen.cpp diff --git a/src/mcc/module/CModule.cpp b/src/mcc/module/CModule.cpp index cc9f6c10..69c3020e 100644 --- a/src/mcc/module/CModule.cpp +++ b/src/mcc/module/CModule.cpp @@ -209,7 +209,7 @@ static struct { {"Remove Black Bar1", "remove black bar", OFFSET_GROUNDHOG_PV_SPLITSCREEN_TABLE, kBlackBar1, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x3F\x00\x00\x00\x3F\x01\x00\x00\x00", false}, {"Remove Black Bar2", "remove black bar", OFFSET_GROUNDHOG_PV_SPLITSCREEN_TABLE, kBlackBar2, "\x00\x00\x00\x00\x00\x00\x00\x3F\x00\x00\x80\x3F\x00\x00\x80\x3F\x01\x00\x00\x00", false}, {"Remove Black Bar3", "remove black bar", OFFSET_GROUNDHOG_PV_SPLITSCREEN_TABLE, kBlackBar3, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x3F\x00\x00\x00\x3F\x01\x00\x00\x00", false}, -}}, {nullptr, { +}}, {Halo3ODSTEntrySet(), { {"splitscreen_patch1", "", OFFSET_HALO3ODST_PF_COOP_JOIN, "\x31\xC0\xC3\x90", true}, {"Remove Black Bar1", "remove black bar", OFFSET_HALO3ODST_PV_SPLITSCREEN_TABLE, kBlackBar1, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x3F\x00\x00\x00\x3F\x01\x00\x00\x00", false}, {"Remove Black Bar2", "remove black bar", OFFSET_HALO3ODST_PV_SPLITSCREEN_TABLE, kBlackBar2, "\x00\x00\x00\x00\x00\x00\x00\x3F\x00\x00\x80\x3F\x00\x00\x80\x3F\x01\x00\x00\x00", false}, diff --git a/src/mcc/module/entry/halo3odst/render.cpp b/src/mcc/module/entry/halo3odst/render.cpp deleted file mode 100644 index 0e5ff39e..00000000 --- a/src/mcc/module/entry/halo3odst/render.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "halo3odst.h" - -#include - -namespace Halo3ODST::Entry::World {void AddTask(const std::function& func);} - -namespace Halo3ODST::Entry::Render { - void Prologue() { - - } - - void Epilogue() { -// if (MainRenderer()->ShowContext() && MainRenderer()->NewFrame()) { -// ImGui::Begin("Halo3 ODST"); -// if (ImGui::Button("Add Player")) { -// Halo3ODST::Entry::World::AddTask([]() { -// NativeHalo3ODST()->NativeFunc()->local_player_add(L"UWU", L"UWU"); -// }); -// } -// ImGui::End(); -// } - } - - Halo3ODSTEntry(entry, OFFSET_HALO3ODST_PF_RENDER, void, detour) { - Prologue(); - ((detour_t)entry.m_pOriginal)(); - Epilogue(); - } -} diff --git a/src/mcc/module/entry/halo3odst/splitscreen.cpp b/src/mcc/module/entry/halo3odst/splitscreen.cpp new file mode 100644 index 00000000..5a5192bb --- /dev/null +++ b/src/mcc/module/entry/halo3odst/splitscreen.cpp @@ -0,0 +1,50 @@ +// Left/Right split screen for ODST (mcc/splitscreen/LeftRight), after XiaoDanny's Reach port. +#include "halo3odst.h" + +#include "mcc/splitscreen/LeftRight.h" + +namespace Halo3ODST::Entry::Splitscreen { + namespace LeftRight = MCC::Splitscreen::LeftRight; + + constexpr LeftRight::Gen3 kGame { + OFFSET_HALO3ODST_PV_SPLITSCREEN_TABLE, OFFSET_HALO3ODST_PV_SCREEN_SIZE, + OFFSET_HALO3ODST_PF_SPLITSCREEN_PLAYER_COUNT, OFFSET_HALO3ODST_PF_FILL_RECT, + OFFSET_HALO3ODST_PF_RT_POOL_RELEASE, OFFSET_HALO3ODST_PF_RT_POOL_INIT, + nullptr, false, 0x110, 0x94, + true, // ODST never shipped four-player split screen: its quarter HUD layouts carry only the ammo panel + }; + LeftRight::State s_state; + + EntryFeature("ODST Left/Right split screen", OFFSET_HALO3ODST_PV_SPLITSCREEN_TABLE, OFFSET_HALO3ODST_PV_SCREEN_SIZE, + OFFSET_HALO3ODST_PF_SPLITSCREEN_PLAYER_COUNT, OFFSET_HALO3ODST_PF_FILL_RECT, + OFFSET_HALO3ODST_PF_RT_POOL_RELEASE, OFFSET_HALO3ODST_PF_RT_POOL_INIT); + + Halo3ODSTEntry(entry_render, OFFSET_HALO3ODST_PF_RENDER, void, render) { + LeftRight::Frame(kGame, entry_render.m_target - entry_render.m_offset, s_state); + ((render_t)entry_render.m_pOriginal)(); + } + + Halo3ODSTEntry(entry_bars, OFFSET_HALO3ODST_PF_DRAW_SPLITSCREEN_BARS, void, draw_bars) { + if (!LeftRight::PaintDividers(kGame, entry_bars.m_target - entry_bars.m_offset)) + ((draw_bars_t)entry_bars.m_pOriginal)(); + } + + Halo3ODSTEntry(entry_hud_resolution, OFFSET_HALO3ODST_PF_HUD_RESOLUTION, int, hud_resolution, int user) { + int resolution = ((hud_resolution_t)entry_hud_resolution.m_pOriginal)(user); + return LeftRight::HudResolution(kGame, entry_hud_resolution.m_target - entry_hud_resolution.m_offset, + s_state, user, resolution); + } + + Halo3ODSTEntry(entry_hud_layout, OFFSET_HALO3ODST_PF_HUD_LAYOUT, const void*, hud_layout, int user, + int resolution) { + auto layout = ((hud_layout_t)entry_hud_layout.m_pOriginal)(user, resolution); + return LeftRight::HudLayout(kGame, entry_hud_layout.m_target - entry_hud_layout.m_offset, s_state, user, + layout); + } + + Halo3ODSTEntry(entry_rt, OFFSET_HALO3ODST_PF_RT_CREATE, __int64, create_target, void* target, int* sizes, + const unsigned char* desc, int variant, int flags) { + LeftRight::SizeSurface(kGame, entry_rt.m_target - entry_rt.m_offset, s_state, sizes, desc, variant); + return ((create_target_t)entry_rt.m_pOriginal)(target, sizes, desc, variant, flags); + } +} From 9e5c1c07a343ecab08ac75a150b9ad356db900ea Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:07:05 -0400 Subject: [PATCH 06/17] feat(halo4): side by side Halo 4's Left/Right split screen, as Halo 3's (LeftRight::Gen3), through Halo 4's own places: its bar painter sets up the render state before drawing, and it sizes a pool target's view variant in a helper, which is asked again for the unshrunk size of the halves' surface. Halo 4 lays each view's HUD out from the view's table variant, the full-height halves (3) taking the two-player layout, as wide as a top/bottom half: in a Left/Right half the weapon panel ran off the right edge. The halves take the quarter layout, exactly their width. The split-screen hooks get an entry set of their own (Halo4SplitscreenEntrySet), which CModule installs; the old Halo 4 hooks (engine, render, world) stay off. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/CModule.cpp | 2 +- src/mcc/module/entry/halo4/halo4.cpp | 3 +- src/mcc/module/entry/halo4/halo4.h | 16 ++++++ src/mcc/module/entry/halo4/splitscreen.cpp | 61 ++++++++++++++++++++++ 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 src/mcc/module/entry/halo4/splitscreen.cpp diff --git a/src/mcc/module/CModule.cpp b/src/mcc/module/CModule.cpp index 69c3020e..59775522 100644 --- a/src/mcc/module/CModule.cpp +++ b/src/mcc/module/CModule.cpp @@ -196,7 +196,7 @@ static struct { {"Remove Black Bar1", "remove black bar", OFFSET_HALO3_PV_SPLITSCREEN_TABLE, kBlackBar1, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x3F\x00\x00\x00\x3F\x01\x00\x00\x00", false}, {"Remove Black Bar2", "remove black bar", OFFSET_HALO3_PV_SPLITSCREEN_TABLE, kBlackBar2, "\x00\x00\x00\x00\x00\x00\x00\x3F\x00\x00\x80\x3F\x00\x00\x80\x3F\x01\x00\x00\x00", false}, {"Remove Black Bar3", "remove black bar", OFFSET_HALO3_PV_SPLITSCREEN_TABLE, kBlackBar3, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x3F\x00\x00\x00\x3F\x01\x00\x00\x00", false}, -}}, {nullptr, { +}}, {Halo4SplitscreenEntrySet(), { {"splitscreen_patch1", "", OFFSET_HALO4_PF_COOP_JOIN, "\x31\xC0\xC3\x90", true}, {"splitscreen_patch2", "", OFFSET_HALO4_PF_COOP_REJOIN, "\xEB", true}, {"splitscreen_patch3", "", OFFSET_HALO4_PF_COOP_PLAYER_LIMIT, "\x90\x90\x90\x90\x90\x90", true}, diff --git a/src/mcc/module/entry/halo4/halo4.cpp b/src/mcc/module/entry/halo4/halo4.cpp index 14bb7ba7..edd8ed2f 100644 --- a/src/mcc/module/entry/halo4/halo4.cpp +++ b/src/mcc/module/entry/halo4/halo4.cpp @@ -1,3 +1,4 @@ #include "halo4.h" -EntrySet g_pHalo4EntrySet; \ No newline at end of file +EntrySet g_pHalo4EntrySet; +EntrySet g_Halo4SplitscreenEntrySet; \ No newline at end of file diff --git a/src/mcc/module/entry/halo4/halo4.h b/src/mcc/module/entry/halo4/halo4.h index 741801c8..67fbc24a 100644 --- a/src/mcc/module/entry/halo4/halo4.h +++ b/src/mcc/module/entry/halo4/halo4.h @@ -6,6 +6,22 @@ extern EntrySet g_pHalo4EntrySet; inline EntrySet* Halo4EntrySet() {return &g_pHalo4EntrySet;}; +// The hooks CModule installs for Halo 4. The ones above (engine, render, world) were never switched on +// and their offsets are unchecked, so the split-screen hooks have a set of their own. +extern EntrySet g_Halo4SplitscreenEntrySet; +inline EntrySet* Halo4SplitscreenEntrySet() {return &g_Halo4SplitscreenEntrySet;}; + +#define Halo4SplitscreenEntry(name, offset, returnType, pDetour, ...) \ + returnType pDetour(__VA_ARGS__); \ + typedef returnType (*pDetour##_t)(__VA_ARGS__); \ + ::Entry name(Halo4SplitscreenEntrySet(), offset, pDetour, entry_feature); \ + returnType pDetour(__VA_ARGS__) + +namespace Halo4::Entry { + // HUD layouts (OFFSET_HALO4_PF_HUD_LAYOUT): full screen 1280x720, two-player 960x360, quarter 640x360 + constexpr int kFullHudLayout = 0x80076, kHalfHudLayout = 0x80077, kQuarterHudLayout = 0x80078; +} + #define Halo4Entry(name, offset, returnType, pDetour, ...) \ returnType pDetour(__VA_ARGS__); \ typedef returnType (*pDetour##_t)(...); \ diff --git a/src/mcc/module/entry/halo4/splitscreen.cpp b/src/mcc/module/entry/halo4/splitscreen.cpp new file mode 100644 index 00000000..f56af2af --- /dev/null +++ b/src/mcc/module/entry/halo4/splitscreen.cpp @@ -0,0 +1,61 @@ +// Left/Right split screen for Halo 4 (mcc/splitscreen/LeftRight), after XiaoDanny's Reach port. +#include "halo4.h" + +#include "mcc/splitscreen/LeftRight.h" + +namespace Halo4::Entry::Splitscreen { + namespace LeftRight = MCC::Splitscreen::LeftRight; + + EntryFeature("Halo 4 Left/Right split screen", OFFSET_HALO4_PV_SPLITSCREEN_TABLE, OFFSET_HALO4_PV_SCREEN_SIZE, + OFFSET_HALO4_PF_SPLITSCREEN_PLAYER_COUNT, OFFSET_HALO4_PF_FILL_RECT, OFFSET_HALO4_PF_RT_POOL_RELEASE, + OFFSET_HALO4_PF_RT_POOL_INIT, OFFSET_HALO4_PF_RENDER_SETUP_1, OFFSET_HALO4_PF_RENDER_SETUP_2); + + // The bar painter sets the render state up itself before drawing (as Reach's does, blackbars.cpp). + void BeforePainting(__int64 module) { + ((void (*)(int, int))(module + OFFSET_HALO4_PF_RENDER_SETUP_1))(0, 1); + ((void (*)(int))(module + OFFSET_HALO4_PF_RENDER_SETUP_2))(0); + } + + constexpr LeftRight::Gen3 kGame { + OFFSET_HALO4_PV_SPLITSCREEN_TABLE, OFFSET_HALO4_PV_SCREEN_SIZE, OFFSET_HALO4_PF_SPLITSCREEN_PLAYER_COUNT, + OFFSET_HALO4_PF_FILL_RECT, OFFSET_HALO4_PF_RT_POOL_RELEASE, OFFSET_HALO4_PF_RT_POOL_INIT, + BeforePainting, + }; + LeftRight::State s_state; + + // Halo 4 lays each view's HUD out from the view's table variant, the full-height halves' (3) taking the + // two-player layout, which is as wide as a top/bottom half: in a Left/Right half it ran off the right edge. + // The quarter layout is exactly a half's width. + Halo4SplitscreenEntry(entry_hud_layout, OFFSET_HALO4_PF_HUD_LAYOUT, int, hud_layout, int user) { + int layout = ((hud_layout_t)entry_hud_layout.m_pOriginal)(user); + if (layout != kHalfHudLayout || !LeftRight::Chosen()) return layout; + __int64 module = entry_hud_layout.m_target - entry_hud_layout.m_offset; + return LeftRight::Active(LeftRight::Players(kGame, module)) ? kQuarterHudLayout : layout; + } + + Halo4SplitscreenEntry(entry_render, OFFSET_HALO4_PF_RENDER, void, render) { + LeftRight::Frame(kGame, entry_render.m_target - entry_render.m_offset, s_state); + ((render_t)entry_render.m_pOriginal)(); + } + + Halo4SplitscreenEntry(entry_bars, OFFSET_HALO4_PF_DRAW_SPLITSCREEN_BARS, void, draw_bars) { + if (!LeftRight::PaintDividers(kGame, entry_bars.m_target - entry_bars.m_offset)) + ((draw_bars_t)entry_bars.m_pOriginal)(); + } + + // Halo 4 sizes a pool target's view variant in a helper of its own: the descriptor's size, then for + // variant 3 three quarters of the width by half the height, both pairs alike. For Left/Right's half + // surface the helper is asked for the unshrunk size (variant 0 of the same target) and that is halved + // in width, the way the pool halves for its other variants. + Halo4SplitscreenEntry(entry_rt_size, OFFSET_HALO4_PF_RT_VARIANT_SIZE, void, variant_size, + const unsigned char* desc, int* w, int* h, int* w2, int* h2, int* face, int index) { + ((variant_size_t)entry_rt_size.m_pOriginal)(desc, w, h, w2, h2, face, index); + if (!LeftRight::ResizesHalfSurface(s_state, index) || !(*(const unsigned*)(desc + 0x10) & 0x20)) return; + + int full_w, full_h, full_w2, full_h2, full_face = 0; + ((variant_size_t)entry_rt_size.m_pOriginal)(desc, &full_w, &full_h, &full_w2, &full_h2, &full_face, + index & ~3); + *w = *w2 = full_w / 2; + *h = *h2 = full_h; + } +} From a818bdd7a0372d490e86efdd302009d5b84e4770 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:08:46 -0400 Subject: [PATCH 07/17] feat(halo4): fit the HUD to a Left/Right half A full-height half is 960x1080 for the quarter layout's 640x360 HUD units, and the layout sits in the view's corner, so the HUD kept to the top half of the view with the motion tracker at mid-height. Halo 4 already fits its 1280x720 layout to screens of another shape (ultrawide) through four helpers - wider or not, the aspect over 16:9's, the extra width or height either side. While a half's HUD is updated or drawn they now answer for that view and its layout (leaves whose callers keep values in registers: PreservingThunk), the half's edge-anchored elements follow its edges, and the crosshair group is moved back to the view's centre. Every other view (Top / Bottom, quarters) gets the game's own answers, as before. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/entry/halo4/halo4.h | 4 + src/mcc/module/entry/halo4/hud_fit.cpp | 186 +++++++++++++++++++++ src/mcc/module/entry/halo4/splitscreen.cpp | 4 +- 3 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 src/mcc/module/entry/halo4/hud_fit.cpp diff --git a/src/mcc/module/entry/halo4/halo4.h b/src/mcc/module/entry/halo4/halo4.h index 67fbc24a..88992b66 100644 --- a/src/mcc/module/entry/halo4/halo4.h +++ b/src/mcc/module/entry/halo4/halo4.h @@ -20,6 +20,10 @@ inline EntrySet* Halo4SplitscreenEntrySet() {return &g_Halo4SplitscreenEntrySet; namespace Halo4::Entry { // HUD layouts (OFFSET_HALO4_PF_HUD_LAYOUT): full screen 1280x720, two-player 960x360, quarter 640x360 constexpr int kFullHudLayout = 0x80076, kHalfHudLayout = 0x80077, kQuarterHudLayout = 0x80078; + + namespace HudFit { + void Refresh(__int64 module); // each user's fit, once a frame (hud_fit.cpp) + } } #define Halo4Entry(name, offset, returnType, pDetour, ...) \ diff --git a/src/mcc/module/entry/halo4/hud_fit.cpp b/src/mcc/module/entry/halo4/hud_fit.cpp new file mode 100644 index 00000000..e25d286c --- /dev/null +++ b/src/mcc/module/entry/halo4/hud_fit.cpp @@ -0,0 +1,186 @@ +// Halo 4's HUD in a Left/Right half. A half is 960x1080 for the quarter layout's 640x360 units (HUD units: +// pixels over min(width / 1280, height / 720) of the screen), and the layout sits in the view's corner, so the +// HUD kept to the top half of the view, the motion tracker at mid-height. +// +// Halo 4 already fits its 1280x720 layout to screens of another shape (ultrawide): four helpers give the +// screen's shape against 16:9 - wider or not, the aspect over 16:9's, the extra width or height either side +// - and the UI uses them to centre each screen, keep edge-anchored elements at the screen's edges and place +// what it projects from the world (nametags, waypoints). While a half's HUD is updated or drawn, the helpers +// answer for that view and its layout instead (the other split views keep the game's own answers). The +// crosshair sits at the view's centre already, so the screen's centring would move it: its group is moved back. +#include "halo4.h" + +#include "mcc/module/entry/PreservingThunk.h" +#include "mcc/module/patch/SplitscreenConfigStore.h" +#include "mcc/splitscreen/LeftRight.h" + +#include +#include + +namespace Halo4::Entry::HudFit { + namespace LeftRight = MCC::Splitscreen::LeftRight; + namespace Store = AlphaRing::SplitscreenConfigStore; + + EntryFeature("Halo 4 split-screen HUD fit", OFFSET_HALO4_PV_SPLITSCREEN_TABLE, OFFSET_HALO4_PV_SCREEN_SIZE, + OFFSET_HALO4_PF_HUD_LAYOUT, OFFSET_HALO4_PF_SPLITSCREEN_PLAYER_COUNT, OFFSET_HALO4_PF_UI_USER_INDEX, + OFFSET_HALO4_VT_UI_GROUP, OFFSET_HALO4_VT_HUD_RETICLE_GROUP); + + struct Fit { + bool on = false; + float aspect = 1.0f; // the view's aspect over its layout's (wide when above 1) + float extra_x = 0.0f, extra_y = 0.0f; // HUD units either side of the layout + }; + + thread_local int t_user = -1; // the user whose HUD is being updated or drawn + Fit s_fits[4]; // each user's, as of this frame (Refresh) + bool s_any_fit = false; // this frame + bool s_ever_fit = false; // since the module loaded: crosshair groups may carry our offset + + Fit Compute(__int64 module, int players, int user) { + Fit fit; + if (players < 2 || players > 4 || user >= players) return fit; + // a Left/Right half (both two-player views, the three-player left one) + if (!LeftRight::Active(players) || Store::LeftRightRegion(players, user).resolution != 3) return fit; + auto& view = ((const Store::LayoutEntry*)(module + OFFSET_HALO4_PV_SPLITSCREEN_TABLE)) + [players * Store::SLOT_COUNT + user]; + auto screen = (const int*)(module + OFFSET_HALO4_PV_SCREEN_SIZE); + float width = (float)screen[0], height = (float)screen[1]; + if (width < 1 || height < 1) return fit; + float scale = (std::min)(width / 1280.0f, height / 720.0f); + float view_w = width * (view.x1 - view.x0) / scale, view_h = height * (view.y1 - view.y0) / scale; + int layout = ((int (*)(int))(module + OFFSET_HALO4_PF_HUD_LAYOUT))(user); + float layout_w = layout == kHalfHudLayout ? 960.0f : layout == kQuarterHudLayout ? 640.0f : 1280.0f; + float layout_h = layout == kFullHudLayout ? 720.0f : 360.0f; + if (view_h < 1 || (std::abs(view_w - layout_w) < 1 && std::abs(view_h - layout_h) < 1)) return fit; + fit.on = true; + fit.aspect = (view_w / view_h) / (layout_w / layout_h); + if (fit.aspect > 1.0f) fit.extra_x = (view_w - layout_w) * 0.5f; + else fit.extra_y = (view_h - layout_h) * 0.5f; + return fit; + } + + void Refresh(__int64 module) { + s_any_fit = false; + if (!entry_feature->Available()) return; // from splitscreen.cpp's render hook: only with the hooks below + int players = ((int (*)())(module + OFFSET_HALO4_PF_SPLITSCREEN_PLAYER_COUNT))(); + for (int user = 0; user < 4; ++user) { + s_fits[user] = Compute(module, players, user); + s_any_fit |= s_fits[user].on; + } + s_ever_fit |= s_any_fit; + } + const bool s_reset = (Halo4SplitscreenEntrySet()->on_remove([] { s_ever_fit = false; }), true); + + // The fit of the user whose HUD is being worked on, when it's on. + const Fit* Current() { + return s_any_fit && t_user >= 0 && t_user < 4 && s_fits[t_user].on ? &s_fits[t_user] : nullptr; + } + + struct UserScope { + int outer = t_user; + explicit UserScope(int user) { t_user = user; } + ~UserScope() { t_user = outer; } + }; + + // whose HUD + Halo4SplitscreenEntry(entry_update, OFFSET_HALO4_PF_HUD_UPDATE, __int64, hud_update, void* hud, __int64 user, + void* r8, void* r9) { + UserScope scope((int)user); + return ((hud_update_t)entry_update.m_pOriginal)(hud, user, r8, r9); + } + + Halo4SplitscreenEntry(entry_render, OFFSET_HALO4_PF_HUD_RENDER, __int64, hud_render, void* rcx, __int64 user, + void* r8, void* r9) { + UserScope scope((int)user); + return ((hud_render_t)entry_render.m_pOriginal)(rcx, user, r8, r9); + } + + // the helpers: leaves, whose callers keep values in volatile registers across them + extern ::Entry entry_wide, entry_aspect, entry_extra_width, entry_extra_height; + + __int64 Wide(void*, void*, void*, void*, __int64) { + if (const Fit* fit = Current()) return fit->aspect > 1.0f; + return ((bool (*)())entry_wide.m_pOriginal)(); + } + + float Aspect(void* inverse, void*, void*, void*, __int64) { + if (const Fit* fit = Current()) return (unsigned char)(__int64)inverse ? 1.0f / fit->aspect : fit->aspect; + return ((float (*)(void*))entry_aspect.m_pOriginal)(inverse); + } + + float ExtraWidth(void*, void*, void*, void*, __int64) { + if (const Fit* fit = Current()) return fit->extra_x; + return ((float (*)())entry_extra_width.m_pOriginal)(); + } + + float ExtraHeight(void*, void*, void*, void*, __int64) { + if (const Fit* fit = Current()) return fit->extra_y; + return ((float (*)())entry_extra_height.m_pOriginal)(); + } + + ::Entry entry_wide(Halo4SplitscreenEntrySet(), OFFSET_HALO4_PF_UI_WIDE, PreservingThunk((const void*)&Wide), + entry_feature); + ::Entry entry_aspect(Halo4SplitscreenEntrySet(), OFFSET_HALO4_PF_UI_ASPECT, PreservingThunk((const void*)&Aspect), + entry_feature); + ::Entry entry_extra_width(Halo4SplitscreenEntrySet(), OFFSET_HALO4_PF_UI_EXTRA_WIDTH, + PreservingThunk((const void*)&ExtraWidth), entry_feature); + ::Entry entry_extra_height(Halo4SplitscreenEntrySet(), OFFSET_HALO4_PF_UI_EXTRA_HEIGHT, + PreservingThunk((const void*)&ExtraHeight), entry_feature); + + // The UI places some widgets outside the HUD update and draw, in a context naming its user (+0x28). + int ContextUser(__int64 module, const char* context) { + if (t_user >= 0 || !s_any_fit) return t_user; + return ((int (*)(int))(module + OFFSET_HALO4_PF_UI_USER_INDEX))(*(const int*)(context + 0x28)); + } + + // An element anchored to the screen's edges keeps its x there only where the user's HUD settings let the + // ultrawide layout move it; a split view's edge elements always follow its edges. + Halo4SplitscreenEntry(entry_anchor, OFFSET_HALO4_PF_UI_ANCHOR, void, anchor, char* element, char* context) { + UserScope user(ContextUser(entry_anchor.m_target - entry_anchor.m_offset, context)); + ((anchor_t)entry_anchor.m_pOriginal)(element, context); + const Fit* fit = Current(); + if (fit == nullptr || *(int*)(element + 0x1D4) != 2) return; // x anchoring set up: base +0x1D8, side +0x1DC + *(float*)(element + 0xBC) = *(float*)(element + 0x1D8) + fit->extra_x * (float)*(int*)(element + 0x1DC); + *(float*)(element + 0xC0) = 0.0f; + } + + Halo4SplitscreenEntry(entry_fit_range, OFFSET_HALO4_PF_UI_FIT_RANGE, void, fit_range, char* widget, char* context) { + UserScope user(ContextUser(entry_fit_range.m_target - entry_fit_range.m_offset, context)); + ((fit_range_t)entry_fit_range.m_pOriginal)(widget, context); + } + + // The widget tree: a node's first child from its vtable (+0x28), siblings at +0x40; widgets have bit 1 of + // their type's flags (+8 -> +0xC). + char* FirstChild(char* node) { return ((char* (*)(char*))(*(void***)node)[0x28 / 8])(node); } + char* Next(char* node) { return *(char**)(node + 0x40); } + bool IsWidget(char* node, __int64 vtable) { + char* type = *(char**)(node + 8); + return type != nullptr && (*(unsigned char*)(type + 0xC) & 2) && *(__int64*)node == vtable; + } + + // Each weapon's HUD screen holds its crosshair in a group under one of the screen's top-level groups: the + // group with a widget at the layout's centre, 640, 360 in HUD units. + char* ReticleGroup(__int64 module, char* screen) { + for (char* top = FirstChild(screen); top != nullptr; top = Next(top)) { + if (!IsWidget(top, module + OFFSET_HALO4_VT_UI_GROUP)) continue; + for (char* group = FirstChild(top); group != nullptr; group = Next(group)) { + if (!IsWidget(group, module + OFFSET_HALO4_VT_HUD_RETICLE_GROUP)) continue; + for (char* widget = FirstChild(group); widget != nullptr; widget = Next(widget)) + if (*(float*)(widget + 0xBC) == 640.0f && *(float*)(widget + 0xC4) == 360.0f) return group; + } + } + return nullptr; + } + + Halo4SplitscreenEntry(entry_screen_render, OFFSET_HALO4_PF_UI_SCREEN_RENDER, void, screen_render, char* screen, + void* context) { + if (t_user >= 0 && s_ever_fit) { + if (char* group = ReticleGroup(entry_screen_render.m_target - entry_screen_render.m_offset, screen)) { + const Fit* fit = Current(); // back to 0 when the view fits + *(float*)(group + 0xC0) = fit != nullptr ? -fit->extra_x : 0.0f; + *(float*)(group + 0xC8) = fit != nullptr ? -fit->extra_y : 0.0f; + } + } + ((screen_render_t)entry_screen_render.m_pOriginal)(screen, context); + } +} diff --git a/src/mcc/module/entry/halo4/splitscreen.cpp b/src/mcc/module/entry/halo4/splitscreen.cpp index f56af2af..3794f839 100644 --- a/src/mcc/module/entry/halo4/splitscreen.cpp +++ b/src/mcc/module/entry/halo4/splitscreen.cpp @@ -34,7 +34,9 @@ namespace Halo4::Entry::Splitscreen { } Halo4SplitscreenEntry(entry_render, OFFSET_HALO4_PF_RENDER, void, render) { - LeftRight::Frame(kGame, entry_render.m_target - entry_render.m_offset, s_state); + __int64 module = entry_render.m_target - entry_render.m_offset; + LeftRight::Frame(kGame, module, s_state); + HudFit::Refresh(module); ((render_t)entry_render.m_pOriginal)(); } From 2fb81fbd0f9e421c7d1c723f70f6bb58c0323058 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:10:17 -0400 Subject: [PATCH 08/17] fix(halo4): frame the side-by-side gun like the world 0x34EC44 builds the first-person camera from the view's: its field of view times the screen's aspect over the view's (mulss / divss at 0x34ED92 / 0x34ED96). Stock split-screen views are wider than tall, and that keeps the gun's framing; a 960x1080 Left/Right half doubled it, so both arms and the whole gun came into frame, drawn big. While Left/Right is on screen the divide's register byte is switched (divss xmm5, xmm0 -> xmm1, the screen's aspect: E8 -> E9 at 0x34ED99), so the gun is framed like the world, as Halo 3 and Reach draw it. It is switched in the render hook before each frame, on the thread that draws it, put back otherwise, and put back as the module unloads (EntrySet::on_remove). CPatch::apply now flushes the instruction cache after a write, since the bytes may be code. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/entry/halo4/splitscreen.cpp | 29 ++++++++++++++++++++++ src/mcc/module/patch/CPatch.cpp | 1 + src/mcc/module/patch/CPatch.h | 1 + 3 files changed, 31 insertions(+) diff --git a/src/mcc/module/entry/halo4/splitscreen.cpp b/src/mcc/module/entry/halo4/splitscreen.cpp index 3794f839..b4c9b00b 100644 --- a/src/mcc/module/entry/halo4/splitscreen.cpp +++ b/src/mcc/module/entry/halo4/splitscreen.cpp @@ -1,8 +1,11 @@ // Left/Right split screen for Halo 4 (mcc/splitscreen/LeftRight), after XiaoDanny's Reach port. #include "halo4.h" +#include "mcc/module/patch/CPatch.h" #include "mcc/splitscreen/LeftRight.h" +#include + namespace Halo4::Entry::Splitscreen { namespace LeftRight = MCC::Splitscreen::LeftRight; @@ -33,10 +36,36 @@ namespace Halo4::Entry::Splitscreen { return LeftRight::Active(LeftRight::Players(kGame, module)) ? kQuarterHudLayout : layout; } + // Halo 4 scales the first-person camera's field of view by the screen's aspect over the view's (0x34EC44, times + // the screen's, then this divide by the view's). That keeps the gun's framing in its own split-screen views, + // all wider than tall, but a full-height Left/Right half doubled it: both arms and the whole gun came into frame, + // drawn big. While Left/Right is on screen the divisor is the screen's aspect too (divss xmm5, xmm0 -> xmm1), so + // the gun is framed like the world, as Halo 3 and Reach draw it. Switched before a frame is drawn, on the thread + // drawing it. + unsigned char* s_viewmodel_divide = nullptr; // the divide's register byte, while it's switched + + void RestoreViewmodelAspect() { + unsigned char view = 0xE8; // xmm0 + if (s_viewmodel_divide != nullptr) CPatch::apply(s_viewmodel_divide, &view, 1); + s_viewmodel_divide = nullptr; + } + const bool s_restore = (Halo4SplitscreenEntrySet()->on_remove(&RestoreViewmodelAspect), true); + + void ViewmodelAspect(__int64 module, bool left_right) { + if (left_right == (s_viewmodel_divide != nullptr)) return; + if (!left_right) return RestoreViewmodelAspect(); + auto divide = (unsigned char*)(module + OFFSET_HALO4_VIEWMODEL_ASPECT_DIVIDE); + unsigned char screen = 0xE9; // xmm1 + if (OFFSET_HALO4_VIEWMODEL_ASPECT_DIVIDE.found() && memcmp(divide, "\xF3\x0F\x5E\xE8", 4) == 0 && + CPatch::apply(divide + 3, &screen, 1)) + s_viewmodel_divide = divide + 3; + } + Halo4SplitscreenEntry(entry_render, OFFSET_HALO4_PF_RENDER, void, render) { __int64 module = entry_render.m_target - entry_render.m_offset; LeftRight::Frame(kGame, module, s_state); HudFit::Refresh(module); + ViewmodelAspect(module, LeftRight::Active(LeftRight::Players(kGame, module))); ((render_t)entry_render.m_pOriginal)(); } diff --git a/src/mcc/module/patch/CPatch.cpp b/src/mcc/module/patch/CPatch.cpp index 18c420fc..5aed01f9 100644 --- a/src/mcc/module/patch/CPatch.cpp +++ b/src/mcc/module/patch/CPatch.cpp @@ -16,6 +16,7 @@ bool CPatch::apply(void *dst, const void *src, size_t size) { result = true; } VirtualProtect(dst, size, oldprotect, &oldprotect); + if (result) FlushInstructionCache(GetCurrentProcess(), dst, size); // the bytes may be code return result; } diff --git a/src/mcc/module/patch/CPatch.h b/src/mcc/module/patch/CPatch.h index ad60ba56..122db679 100644 --- a/src/mcc/module/patch/CPatch.h +++ b/src/mcc/module/patch/CPatch.h @@ -44,6 +44,7 @@ class CPatch { inline bool have_desc() const {return !m_desc.empty();} inline bool enabled() {return m_enabled;} + // Writes code or read-only data (and flushes the instruction cache). static bool apply(void *dst, const void *src, size_t size); private: From 31f672d3afc60415e06dbfe43ff28dfd5924ee9b Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:10:20 -0400 Subject: [PATCH 09/17] fix(halo4): start 3-4 player missions with two players A Halo 4 campaign mission that starts with players 3-4 stays black in every view, but the engine brings late joiners in beside a teammate, like a controller signing in mid-game. get_xbox_user_id now reports two local players in Halo 4 until 3 s after the game state goes Running, then all of them. The clock is cleared at the end of each session (game_restart, which MCC runs after the exit states): dropping players while the engine shuts down can hang it, and the next session asks for its players before its own loading state. The log says "Splitscreen: exposing N local players" whenever the count changes. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/CGameManager.cpp | 2 ++ src/mcc/CGameManager.h | 6 ++++ src/mcc/CGameManagerSplitscreen.cpp | 55 ++++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/mcc/CGameManager.cpp b/src/mcc/CGameManager.cpp index cd4df89e..139172e6 100644 --- a/src/mcc/CGameManager.cpp +++ b/src/mcc/CGameManager.cpp @@ -131,6 +131,7 @@ void CGameManager::set_state(CGameManager *self, eState state) { static std::atomic s_last_state{-1}; if (s_last_state.exchange((int)state) != (int)state) MATCH_LOG("set_state {} (caller {})", (int)state, AlphaRing::MatchLog::Describe(_ReturnAddress())); + track_state(state); return ppOriginal.set_state(self, state); } @@ -237,6 +238,7 @@ static bool ShouldThrottleApply() { } void *CGameManager::game_restart(CGameManager *self, int type, const char *reason) { + end_session(); AlphaRing::MatchLog::NewMatch(); MATCH_LOG("game_restart enter: type={} reason=\"{}\" (caller {})", type, reason ? reason : "", AlphaRing::MatchLog::Describe(_ReturnAddress())); diff --git a/src/mcc/CGameManager.h b/src/mcc/CGameManager.h index 6e01f79c..43406596 100644 --- a/src/mcc/CGameManager.h +++ b/src/mcc/CGameManager.h @@ -24,6 +24,7 @@ }; enum eState { + Running = 1, Exit = 5, Exiting = 10, }; @@ -35,8 +36,13 @@ static Profile_t* get_profile(int index); static CInputDevice* get_controller(int index); static void apply_profiles(); + // Local players in the game right now (see CGameManagerSplitscreen.cpp: Halo 4 starts with two). + static int active_player_count(); private: + static void track_state(eState state); + static void end_session(); + static void __fastcall set_vibration(CGameManager* self, DWORD dwUserIndex, XINPUT_VIBRATION *pVibration); static CUserProfile* __fastcall get_player_profile(CGameManager* self, __int64 xid); static bool __fastcall get_xbox_user_id(CGameManager* self, __int64* pId, wchar_t *pName, int size, int index); diff --git a/src/mcc/CGameManagerSplitscreen.cpp b/src/mcc/CGameManagerSplitscreen.cpp index 28489068..cd9cbbf3 100644 --- a/src/mcc/CGameManagerSplitscreen.cpp +++ b/src/mcc/CGameManagerSplitscreen.cpp @@ -11,6 +11,8 @@ using AlphaRing::MatchLog::Describe; using AlphaRing::MatchLog::FirstThisMatch; +#include + void CGameManager::set_vibration(CGameManager *self, DWORD dwUserIndex, XINPUT_VIBRATION *pVibration) { CInputDevice* p_device; auto p_setting = AlphaRing::Global::MCC::Splitscreen(); @@ -29,6 +31,57 @@ void CGameManager::set_vibration(CGameManager *self, DWORD dwUserIndex, XINPUT_V AlphaRing::Input::SetState(p_device->input_user, pVibration); } +// Halo 4 campaigns fail when a mission *starts* with players 3-4 (every view stays black), +// yet the engine spawns late joiners next to a teammate, like a controller signing in +// mid-game on the original console. So Halo 4 starts with two players and the rest are +// revealed once the game has been running for a moment. (Halo CE and Halo 2 never pick up +// late joiners, so they - like the other games - start with everyone.) +static constexpr int kDeferredJoinStartPlayers = 2; +static constexpr ULONGLONG kDeferredJoinDelayMs = 3000; +static std::atomic s_running_since; // 0 until the current session first runs + +void CGameManager::track_state(eState state) { + if (state == Running && !s_running_since) // also re-sent after level transitions + s_running_since = GetTickCount64(); +} + +// MCC ends every session with a restart after the exit states. The clock is cleared there, +// not on the exit states: dropping players while the engine is still shutting down can hang +// it, and the next session queries its players before its own loading state. +void CGameManager::end_session() { + s_running_since = 0; +} + +static int deferred_player_count(int count) { + if (count <= kDeferredJoinStartPlayers) return count; + + auto p_global = GameGlobal(); + if (p_global == nullptr) return count; + + if (p_global->current_game != CGameGlobal::Halo4) + return count; + + ULONGLONG since = s_running_since; + if (since && GetTickCount64() - since >= kDeferredJoinDelayMs) + return count; + + return kDeferredJoinStartPlayers; +} + +int CGameManager::active_player_count() { + static std::atomic s_last_logged = -1; + int active = deferred_player_count(AlphaRing::Global::MCC::Splitscreen()->player_count); + + if (active != s_last_logged) { + s_last_logged = active; + auto p_global = GameGlobal(); + LOG_INFO("Splitscreen: exposing {} local players (game {}, in game {})", + active, p_global ? (int)p_global->current_game : -1, MCC::IsInGame()); + } + + return active; +} + static bool get_xbox_user_id_inner(CGameManager *self, __int64 *pId, wchar_t *pName, int size, int index, const char** path) { auto p_setting = AlphaRing::Global::MCC::Splitscreen(); @@ -39,7 +92,7 @@ static bool get_xbox_user_id_inner(CGameManager *self, __int64 *pId, wchar_t *pN return CGameManager::ppOriginal.get_xbox_user_id(self, pId, pName, size, index); } - if (index >= p_setting->player_count) { + if (index >= CGameManager::active_player_count()) { *path = "beyond player_count"; return false; } From e80b5ab180b32c8a3896de95dc19cd37c6f57943 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:11:29 -0400 Subject: [PATCH 10/17] feat(splitscreen): Classic graphics for Halo CE and 2 with 3-4 players or side by side Halo CE's and Halo 2's Anniversary renderers only ever draw two views, stacked: with 3-4 players the others were missing, and side by side is a Classic layout. Bit 0 of the first game-options byte selects Anniversary visuals in both engines. As a mission starts (Halo CE's game_start, Halo 2's copy_game_options) ClassicGraphicsScope clears it while the engine copies the options, so MCC's own setting is left alone, and tells LeftRight whether the mission runs side by side - which Halo CE and Halo 2 take only there. Back still switches to Anniversary graphics in the middle of a mission. CModule now installs Halo CE's hooks; its render hook did nothing, so it goes. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/CModule.cpp | 2 +- src/mcc/module/entry/halo1/graphics.cpp | 11 +++++++++++ src/mcc/module/entry/halo1/render.cpp | 19 ------------------- src/mcc/module/entry/halo2/graphics.cpp | 11 +++++++++++ src/mcc/splitscreen/Splitscreen.cpp | 23 +++++++++++++++++++++++ src/mcc/splitscreen/Splitscreen.h | 19 ++++++++++++++++++- 6 files changed, 64 insertions(+), 21 deletions(-) create mode 100644 src/mcc/module/entry/halo1/graphics.cpp delete mode 100644 src/mcc/module/entry/halo1/render.cpp create mode 100644 src/mcc/module/entry/halo2/graphics.cpp diff --git a/src/mcc/module/CModule.cpp b/src/mcc/module/CModule.cpp index 59775522..2624c195 100644 --- a/src/mcc/module/CModule.cpp +++ b/src/mcc/module/CModule.cpp @@ -177,7 +177,7 @@ static struct { CModule halo3odst; CModule haloreach; } modules { - {nullptr, { + {Halo1EntrySet(), { {"splitscreen_patch1", "", OFFSET_HALO1_PF_4PLAYERS, "\xEB\x18", true}, {"splitscreen_patch2", "", OFFSET_HALO1_PF_PAUSE, "\xEB", true}, {"splitscreen_patch3", "", OFFSET_HALO1_PF_IDK, "\x90\x90\x90\x90\x90\x90", true}, // fix [issue](https://github.com/WinterSquire/AlphaRing/issues/19) diff --git a/src/mcc/module/entry/halo1/graphics.cpp b/src/mcc/module/entry/halo1/graphics.cpp new file mode 100644 index 00000000..ae0eab3d --- /dev/null +++ b/src/mcc/module/entry/halo1/graphics.cpp @@ -0,0 +1,11 @@ +#include "halo1.h" + +#include "mcc/CGameGlobal.h" +#include "mcc/splitscreen/Splitscreen.h" + +namespace Halo1::Entry::Graphics { + Halo1Entry(entry, OFFSET_HALO1_PF_GAME_START, __int64, detour, void* self, void* manager, unsigned char* game_options, void* a4) { + MCC::Splitscreen::ClassicGraphicsScope classic(game_options, CGameGlobal::Halo1); + return ((detour_t)entry.m_pOriginal)(self, manager, game_options, a4); + } +} diff --git a/src/mcc/module/entry/halo1/render.cpp b/src/mcc/module/entry/halo1/render.cpp deleted file mode 100644 index 75675a3d..00000000 --- a/src/mcc/module/entry/halo1/render.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "halo1.h" - -#include - -namespace Halo1::Entry::Render { - void Prologue() { -// NativeHalo1()->NativeInfo()->update((__int64) GetModuleHandleA("halo1.dll")); - } - - void Epilogue() { - - } - - Halo1Entry(entry, OFFSET_HALO1_PF_RENDER, void, detour, void* a1, int a2) { - Prologue(); - ((detour_t)entry.m_pOriginal)(a1, a2); - Epilogue(); - } -} diff --git a/src/mcc/module/entry/halo2/graphics.cpp b/src/mcc/module/entry/halo2/graphics.cpp new file mode 100644 index 00000000..f668ab85 --- /dev/null +++ b/src/mcc/module/entry/halo2/graphics.cpp @@ -0,0 +1,11 @@ +#include "halo2.h" + +#include "mcc/CGameGlobal.h" +#include "mcc/splitscreen/Splitscreen.h" + +namespace Halo2::Entry::Graphics { + Halo2Entry(entry, OFFSET_HALO2_PF_COPY_GAME_OPTIONS, __int64, detour, unsigned char* game_options, void* a2, void* a3, void* a4) { + MCC::Splitscreen::ClassicGraphicsScope classic(game_options, CGameGlobal::Halo2); + return ((detour_t)entry.m_pOriginal)(game_options, a2, a3, a4); + } +} diff --git a/src/mcc/splitscreen/Splitscreen.cpp b/src/mcc/splitscreen/Splitscreen.cpp index 186d1555..4050792b 100644 --- a/src/mcc/splitscreen/Splitscreen.cpp +++ b/src/mcc/splitscreen/Splitscreen.cpp @@ -8,6 +8,7 @@ #include "../CGameManager.h" #include "log/MatchLog.h" +#include "LeftRight.h" namespace MCC::Splitscreen { DefDetourFunction(__int64, __fastcall, get_index_by_xuid, void* a1, __int64 xuid) { @@ -38,6 +39,28 @@ namespace MCC::Splitscreen { return true; } + + ClassicGraphicsScope::ClassicGraphicsScope(unsigned char* game_options, int game) { + auto p_setting = AlphaRing::Global::MCC::Splitscreen(); + + bool left_right = p_setting->b_override && game_options != nullptr && LeftRight::Chosen() && + LeftRight::Supports(game, p_setting->player_count); + LeftRight::StartClassicMission(game, left_right); + if (!p_setting->b_override || game_options == nullptr) return; + if (p_setting->player_count <= 2 && !left_right) return; + bool anniversary = game_options[0] & 1; + if (!anniversary) return; + + LOG_INFO("Splitscreen: {} players{}, starting in Classic graphics", p_setting->player_count, + left_right ? " side by side" : ""); + m_options = game_options; + m_saved = game_options[0]; + game_options[0] &= ~1; + } + + ClassicGraphicsScope::~ClassicGraphicsScope() { + if (m_options) m_options[0] = m_saved; + } } #include "imgui.h" diff --git a/src/mcc/splitscreen/Splitscreen.h b/src/mcc/splitscreen/Splitscreen.h index 9f3a155e..3a776f28 100644 --- a/src/mcc/splitscreen/Splitscreen.h +++ b/src/mcc/splitscreen/Splitscreen.h @@ -3,4 +3,21 @@ namespace MCC::Splitscreen { bool Initialize(); void ImGuiContext(); -} \ No newline at end of file +} + +namespace MCC::Splitscreen { + // Halo CE and Halo 2's Anniversary renderer only ever drew two views, stacked, so missions with + // three or four players, or side by side (LeftRight.h, which takes the layout choice here), start in + // Classic: bit 0 of the first game-options byte selects Anniversary visuals in both engines, and it + // is cleared only while the engine copies the options, leaving MCC's own setting untouched. + class ClassicGraphicsScope { + public: + // `game`: CGameGlobal::Halo1 or Halo2 + ClassicGraphicsScope(unsigned char* game_options, int game); + ~ClassicGraphicsScope(); + + private: + unsigned char* m_options = nullptr; + unsigned char m_saved = 0; + }; +} From a5d23822d3571d3856fbad31c2661774e3199d73 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:12:30 -0400 Subject: [PATCH 11/17] feat(halo1): side by side Halo CE lays its views out on a grid that always grows by rows first: two players get it turned into two columns; with three, player 1's window is built as a two-player half and players 2 and 3's as the right quarters of the four-player grid. The divider painter draws a band down the middle (and one across the right half for 3) instead of across the screen. A zoomed view's scope effect (pistol, sniper) re-samples the view's part of the screen with factors MCC works out for the stock grid - how many views the screen is wide and tall, and the view's place in them - which put a side-by-side player's zoomed view in the wrong part of the screen, squeezed. A mid-function hook (MidFunctionThunk) sets the same factors from the view's own window; for the stock layouts they come out as MCC's. Side by side is Classic's layout: while Anniversary graphics are on screen (Back) the game's own layout is used. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/entry/halo1/splitscreen.cpp | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/mcc/module/entry/halo1/splitscreen.cpp diff --git a/src/mcc/module/entry/halo1/splitscreen.cpp b/src/mcc/module/entry/halo1/splitscreen.cpp new file mode 100644 index 00000000..ce239a60 --- /dev/null +++ b/src/mcc/module/entry/halo1/splitscreen.cpp @@ -0,0 +1,74 @@ +// Left/Right split screen for Halo CE (mcc/splitscreen/LeftRight): CE lays its views out on a grid that +// always grows by rows first; two players get it turned into two columns, and three players the windows of +// both: player 1 a two-player half, players 2 and 3 the right quarters of a four-player grid. +#include "halo1.h" + +#include "mcc/CGameGlobal.h" + +#include "mcc/module/entry/PreservingThunk.h" +#include "mcc/splitscreen/LeftRight.h" + +namespace Halo1::Entry::Splitscreen { + using MCC::Splitscreen::LeftRight::Rect; + + EntryFeature("Halo CE Left/Right split screen", OFFSET_HALO1_PF_SPLIT_VIEWS, OFFSET_HALO1_PV_WINDOW_BOUNDS, + OFFSET_HALO1_PV_SCREEN_BOUNDS, OFFSET_HALO1_PF_FILL_RECT, OFFSET_HALO1_PV_ANNIVERSARY_SHOWN); + + // Side by side is Classic's layout (Back switches to Anniversary's stacked views in the middle of a mission). + bool OnScreen(__int64 module, int views) { + return *(int*)(module + OFFSET_HALO1_PV_ANNIVERSARY_SHOWN) == 0 && + MCC::Splitscreen::LeftRight::OnScreen(CGameGlobal::Halo1, views); + } + + int Views(__int64 module) { return ((int (*)())(module + OFFSET_HALO1_PF_SPLIT_VIEWS))(); } + + Halo1Entry(entry_grid, OFFSET_HALO1_PF_SPLIT_GRID, void, split_grid, int views, int* columns, int* rows) { + ((split_grid_t)entry_grid.m_pOriginal)(views, columns, rows); + if (views == 2 && OnScreen(entry_grid.m_target - entry_grid.m_offset, 2)) { + *columns = 2; + *rows = 1; + } + } + + Halo1Entry(entry_window, OFFSET_HALO1_PF_SPLIT_WINDOW, void, split_window, int view, int views, short* rect, + short* copy) { + if (views == 3 && view >= 0 && view < 3 && OnScreen(entry_window.m_target - entry_window.m_offset, 3)) { + views = view == 0 ? 2 : 4; + if (view == 2) view = 3; + } + ((split_window_t)entry_window.m_pOriginal)(view, views, rect, copy); + } + + // The stock dividers are 4px bands across the screen's middle (and one down it for 3-4 players). + Halo1Entry(entry_dividers, OFFSET_HALO1_PF_SPLIT_DIVIDERS, void, split_dividers) { + __int64 module = entry_dividers.m_target - entry_dividers.m_offset; + int views = Views(module); + if (!OnScreen(module, views)) return ((split_dividers_t)entry_dividers.m_pOriginal)(); + // the dividers' window is the screen + MCC::Splitscreen::LeftRight::PaintBands(*(const Rect*)(module + OFFSET_HALO1_PV_WINDOW_BOUNDS), 2, views, + (void (*)(Rect*, unsigned))(module + OFFSET_HALO1_PF_FILL_RECT)); + } + + // A zoomed view's scope effects (pistol, sniper) blur the screen image under the scope mask. MCC re-samples + // each view's part of it with factors it works out for the stock grid - how many views the screen is wide + // and tall, and the view's place in them - which side by side put a player's zoomed view in the wrong part + // of the screen, squeezed and stretched. These are the same factors, from the view's own window; for the + // stock layouts they come out as MCC's. + extern ::Entry entry_scope_grid; + void ScopeGrid(char* locals) { + __int64 module = entry_scope_grid.m_target - entry_scope_grid.m_offset; + if (!OnScreen(module, Views(module))) return; + auto view = *(const Rect*)(module + OFFSET_HALO1_PV_WINDOW_BOUNDS); + auto screen = *(const Rect*)(module + OFFSET_HALO1_PV_SCREEN_BOUNDS); + float width = (float)(view.right - view.left), height = (float)(view.bottom - view.top); + if (width <= 0 || height <= 0) return; + *(float*)(locals + 0x40) = (screen.right - screen.left) / width; // screen width in views + *(float*)(locals + 0x44) = (screen.bottom - screen.top) / height; // screen height in views + *(float*)(locals + 0x48) = (screen.left - view.left) / width; // minus the view's column + *(float*)(locals + 0x64) = (screen.top - view.top) / height; // minus the view's row + } + constexpr unsigned char kReloadRow[] = {0xF3, 0x44, 0x0F, 0x10, 0x7C, 0x24, 0x64}; // movss xmm15, [rsp+0x64] + ::Entry entry_scope_grid(Halo1EntrySet(), OFFSET_HALO1_SCOPE_GRID_SET, + MidFunctionThunk(&ScopeGrid, &entry_scope_grid.m_pOriginal, kReloadRow, sizeof(kReloadRow)), + entry_feature); +} From a2f2765bc30f5187d6f3be460386509270a9b52a Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:12:35 -0400 Subject: [PATCH 12/17] feat(halo2): side by side Halo 2 lays its views out on a grid it grows by rows or by columns, by a mode MCC's build always passes as 1 (rows: Top / Bottom); any other mode grows columns first, and with three players gives player 1 the full-height left half. While side by side is on screen the grid and cell calls get mode 2, and so does the divider painter, which reads the frame's mode from a global and already has a side-by-side branch. Side by side is Classic's layout: while Anniversary graphics are on screen (Back) the game's own layout is used. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/entry/halo2/splitscreen.cpp | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/mcc/module/entry/halo2/splitscreen.cpp diff --git a/src/mcc/module/entry/halo2/splitscreen.cpp b/src/mcc/module/entry/halo2/splitscreen.cpp new file mode 100644 index 00000000..c5ca2465 --- /dev/null +++ b/src/mcc/module/entry/halo2/splitscreen.cpp @@ -0,0 +1,44 @@ +// Left/Right split screen for Halo 2 (mcc/splitscreen/LeftRight). Halo 2 lays its views out on a grid it +// grows by rows or by columns, by a mode MCC's build always passes as 1 (rows: Top/Bottom); any other mode +// grows columns first, and with three players gives player 1 the full-height left half. +#include "halo2.h" + +#include "mcc/CGameGlobal.h" +#include "mcc/splitscreen/LeftRight.h" + +namespace Halo2::Entry::Splitscreen { + namespace LeftRight = MCC::Splitscreen::LeftRight; + + EntryFeature("Halo 2 Left/Right split screen", OFFSET_HALO2_PV_SPLIT_MODE, OFFSET_HALO2_PV_SPLIT_VIEWS, + OFFSET_HALO2_PV_ANNIVERSARY, OFFSET_HALO2_PV_CLASSIC_SHOWN); + + // Side by side is Classic's layout (Back switches to Anniversary's stacked views in the middle of a mission). + bool ClassicShown(__int64 module) { + return *(int*)(module + OFFSET_HALO2_PV_ANNIVERSARY) == 0 || *(bool*)(module + OFFSET_HALO2_PV_CLASSIC_SHOWN); + } + + int Mode(__int64 module, int views, int mode) { + return ClassicShown(module) && LeftRight::OnScreen(CGameGlobal::Halo2, views) ? 2 : mode; + } + + Halo2Entry(entry_grid, OFFSET_HALO2_PF_SPLIT_GRID, void, split_grid, int views, int mode, short* grid) { + ((split_grid_t)entry_grid.m_pOriginal)(views, Mode(entry_grid.m_target - entry_grid.m_offset, views, mode), grid); + } + + Halo2Entry(entry_cell, OFFSET_HALO2_PF_SPLIT_CELL, void, split_cell, int view, int views, int mode, + const short* grid, short* cell, short* span) { + ((split_cell_t)entry_cell.m_pOriginal)(view, views, Mode(entry_cell.m_target - entry_cell.m_offset, views, mode), + grid, cell, span); + } + + // The dividers take the frame's mode from a global the frame's render entry sets: side by side, a band + // down the middle (and across the right half for three players) instead of across the screen. + Halo2Entry(entry_dividers, OFFSET_HALO2_PF_SPLIT_DIVIDERS, void, split_dividers) { + __int64 module = entry_dividers.m_target - entry_dividers.m_offset; + auto& mode = *(int*)(module + OFFSET_HALO2_PV_SPLIT_MODE); + int stock = mode; + mode = Mode(module, *(const int*)(module + OFFSET_HALO2_PV_SPLIT_VIEWS), stock); + ((split_dividers_t)entry_dividers.m_pOriginal)(); + mode = stock; + } +} From cc80d852bee636e25fb3fed8228888ce09cc89d2 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:22:13 -0400 Subject: [PATCH 13/17] fix(splitscreen): each view's own title-safe box, and its HUD in it Halo 3, ODST, Halo 4 and Reach clip every split-screen view by the whole screen's title-safe box (5% in from each edge). A view's HUD is laid out in that box and its crosshair and aim sit at its centre, so they were pulled toward the middle of the screen: 48 px in a 1080p quarter, and onto the seam of a screen spanning two monitors. Each view now gets its own box, the same size, 5% in from its own edges (LeftRight::ViewSafeBox), with 2-4 players in both layouts; a lone view keeps the game's box. - Halo 3 / ODST: the view setup asks a leaf for the screen's box and clips the view by it. The leaf answers the view setup's call (by its return address, inside a ViewSetup scope) with the view's own box. The view setup keeps the screen height in r10 across that call, hence PreservedEntry. - Halo 4 / Reach: a leaf works a view and its box out together (LeftRight::ViewportRect); the box is replaced after it. Reach's is haloreach/view_safe.cpp, beside XiaoDanny's hooks. - Halo 3 / ODST also clamp each HUD frame to a share of the whole screen (the HUD layout record's safe frame), which trimmed a quarter on its outer sides only and sat its HUD ~34 px toward the middle. Split views get a copy of the record with it zeroed, which the game skips. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/entry/halo3/splitscreen.cpp | 21 +++++++- .../module/entry/halo3odst/splitscreen.cpp | 21 +++++++- src/mcc/module/entry/halo4/splitscreen.cpp | 7 +++ src/mcc/module/entry/haloreach/view_safe.cpp | 14 ++++++ src/mcc/splitscreen/LeftRight.cpp | 49 +++++++++++++++++-- src/mcc/splitscreen/LeftRight.h | 29 ++++++++++- 6 files changed, 132 insertions(+), 9 deletions(-) create mode 100644 src/mcc/module/entry/haloreach/view_safe.cpp diff --git a/src/mcc/module/entry/halo3/splitscreen.cpp b/src/mcc/module/entry/halo3/splitscreen.cpp index 582a9ed3..5805d7aa 100644 --- a/src/mcc/module/entry/halo3/splitscreen.cpp +++ b/src/mcc/module/entry/halo3/splitscreen.cpp @@ -1,6 +1,7 @@ // Left/Right split screen for Halo 3 (mcc/splitscreen/LeftRight), after XiaoDanny's Reach port. #include "halo3.h" +#include "mcc/module/entry/PreservingThunk.h" #include "mcc/splitscreen/LeftRight.h" namespace Halo3::Entry::Splitscreen { @@ -9,13 +10,13 @@ namespace Halo3::Entry::Splitscreen { constexpr LeftRight::Gen3 kGame { OFFSET_HALO3_PV_SPLITSCREEN_TABLE, OFFSET_HALO3_PV_SCREEN_SIZE, OFFSET_HALO3_PF_SPLITSCREEN_PLAYER_COUNT, OFFSET_HALO3_PF_FILL_RECT, OFFSET_HALO3_PF_RT_POOL_RELEASE, OFFSET_HALO3_PF_RT_POOL_INIT, - nullptr, true, 0x64, 0x10, + nullptr, true, 0x64, 0x10, 0x28, &OFFSET_HALO3_VIEW_SETUP_TITLE_SAFE_RETURN, }; LeftRight::State s_state; EntryFeature("Halo 3 Left/Right split screen", OFFSET_HALO3_PV_SPLITSCREEN_TABLE, OFFSET_HALO3_PV_SCREEN_SIZE, OFFSET_HALO3_PF_SPLITSCREEN_PLAYER_COUNT, OFFSET_HALO3_PF_FILL_RECT, OFFSET_HALO3_PF_RT_POOL_RELEASE, - OFFSET_HALO3_PF_RT_POOL_INIT); + OFFSET_HALO3_PF_RT_POOL_INIT, OFFSET_HALO3_VIEW_SETUP_TITLE_SAFE_RETURN); Halo3Entry(entry_render, OFFSET_HALO3_PF_RENDER, void, render) { LeftRight::Frame(kGame, entry_render.m_target - entry_render.m_offset, s_state); @@ -27,6 +28,22 @@ namespace Halo3::Entry::Splitscreen { ((draw_bars_t)entry_bars.m_pOriginal)(); } + // Each view's own title-safe box (LeftRight::ViewSafeBox, TitleSafe). + Halo3Entry(entry_view_setup, OFFSET_HALO3_PF_VIEW_SETUP, void, view_setup, void* view, int slot, int players, + int a4, int a5, void* a6) { + LeftRight::ViewSetup setup(slot, players); + ((view_setup_t)entry_view_setup.m_pOriginal)(view, slot, players, a4, a5, a6); + } + + // The view setup keeps the screen height in r10 across this call, hence the preserving thunk. + PreservedEntry(entry_title_safe, Halo3EntrySet(), OFFSET_HALO3_PF_TITLE_SAFE, title_safe, void* box, void*, + void*, void*, __int64 return_address) { + if (LeftRight::TitleSafe(kGame, entry_title_safe.m_target - entry_title_safe.m_offset, return_address, + (short*)box)) + return ((short*)box)[2]; // as the game's leaves eax + return ((__int64 (*)(void*))entry_title_safe.m_pOriginal)(box); + } + Halo3Entry(entry_hud_resolution, OFFSET_HALO3_PF_HUD_RESOLUTION, int, hud_resolution, int user) { int resolution = ((hud_resolution_t)entry_hud_resolution.m_pOriginal)(user); return LeftRight::HudResolution(kGame, entry_hud_resolution.m_target - entry_hud_resolution.m_offset, diff --git a/src/mcc/module/entry/halo3odst/splitscreen.cpp b/src/mcc/module/entry/halo3odst/splitscreen.cpp index 5a5192bb..0e3e089c 100644 --- a/src/mcc/module/entry/halo3odst/splitscreen.cpp +++ b/src/mcc/module/entry/halo3odst/splitscreen.cpp @@ -1,6 +1,7 @@ // Left/Right split screen for ODST (mcc/splitscreen/LeftRight), after XiaoDanny's Reach port. #include "halo3odst.h" +#include "mcc/module/entry/PreservingThunk.h" #include "mcc/splitscreen/LeftRight.h" namespace Halo3ODST::Entry::Splitscreen { @@ -10,14 +11,15 @@ namespace Halo3ODST::Entry::Splitscreen { OFFSET_HALO3ODST_PV_SPLITSCREEN_TABLE, OFFSET_HALO3ODST_PV_SCREEN_SIZE, OFFSET_HALO3ODST_PF_SPLITSCREEN_PLAYER_COUNT, OFFSET_HALO3ODST_PF_FILL_RECT, OFFSET_HALO3ODST_PF_RT_POOL_RELEASE, OFFSET_HALO3ODST_PF_RT_POOL_INIT, - nullptr, false, 0x110, 0x94, + nullptr, false, 0x110, 0x94, 0xAC, &OFFSET_HALO3ODST_VIEW_SETUP_TITLE_SAFE_RETURN, true, // ODST never shipped four-player split screen: its quarter HUD layouts carry only the ammo panel }; LeftRight::State s_state; EntryFeature("ODST Left/Right split screen", OFFSET_HALO3ODST_PV_SPLITSCREEN_TABLE, OFFSET_HALO3ODST_PV_SCREEN_SIZE, OFFSET_HALO3ODST_PF_SPLITSCREEN_PLAYER_COUNT, OFFSET_HALO3ODST_PF_FILL_RECT, - OFFSET_HALO3ODST_PF_RT_POOL_RELEASE, OFFSET_HALO3ODST_PF_RT_POOL_INIT); + OFFSET_HALO3ODST_PF_RT_POOL_RELEASE, OFFSET_HALO3ODST_PF_RT_POOL_INIT, + OFFSET_HALO3ODST_VIEW_SETUP_TITLE_SAFE_RETURN); Halo3ODSTEntry(entry_render, OFFSET_HALO3ODST_PF_RENDER, void, render) { LeftRight::Frame(kGame, entry_render.m_target - entry_render.m_offset, s_state); @@ -29,6 +31,21 @@ namespace Halo3ODST::Entry::Splitscreen { ((draw_bars_t)entry_bars.m_pOriginal)(); } + // Each view's own title-safe box, as in Halo 3 (module/entry/halo3/splitscreen.cpp). + Halo3ODSTEntry(entry_view_setup, OFFSET_HALO3ODST_PF_VIEW_SETUP, void, view_setup, void* view, int slot, + int players, int a4, int a5, void* a6) { + LeftRight::ViewSetup setup(slot, players); + ((view_setup_t)entry_view_setup.m_pOriginal)(view, slot, players, a4, a5, a6); + } + + PreservedEntry(entry_title_safe, Halo3ODSTEntrySet(), OFFSET_HALO3ODST_PF_TITLE_SAFE, title_safe, void* box, + void*, void*, void*, __int64 return_address) { + if (LeftRight::TitleSafe(kGame, entry_title_safe.m_target - entry_title_safe.m_offset, return_address, + (short*)box)) + return ((short*)box)[2]; // as the game's leaves eax + return ((__int64 (*)(void*))entry_title_safe.m_pOriginal)(box); + } + Halo3ODSTEntry(entry_hud_resolution, OFFSET_HALO3ODST_PF_HUD_RESOLUTION, int, hud_resolution, int user) { int resolution = ((hud_resolution_t)entry_hud_resolution.m_pOriginal)(user); return LeftRight::HudResolution(kGame, entry_hud_resolution.m_target - entry_hud_resolution.m_offset, diff --git a/src/mcc/module/entry/halo4/splitscreen.cpp b/src/mcc/module/entry/halo4/splitscreen.cpp index b4c9b00b..ab6baa8f 100644 --- a/src/mcc/module/entry/halo4/splitscreen.cpp +++ b/src/mcc/module/entry/halo4/splitscreen.cpp @@ -1,6 +1,7 @@ // Left/Right split screen for Halo 4 (mcc/splitscreen/LeftRight), after XiaoDanny's Reach port. #include "halo4.h" +#include "mcc/module/entry/PreservingThunk.h" #include "mcc/module/patch/CPatch.h" #include "mcc/splitscreen/LeftRight.h" @@ -19,6 +20,12 @@ namespace Halo4::Entry::Splitscreen { ((void (*)(int))(module + OFFSET_HALO4_PF_RENDER_SETUP_2))(0); } + // Each view's own title-safe box (LeftRight::ViewSafeBox, ViewportRect); a leaf, hence the preserving thunk. + PreservedEntry(entry_viewport_rect, Halo4SplitscreenEntrySet(), OFFSET_HALO4_PF_COMPUTE_VIEWPORT_RECT, + viewport_rect, void* slot, void* players, void* view, void* box, __int64) { + return LeftRight::ViewportRect(entry_viewport_rect.m_pOriginal, slot, players, view, box); + } + constexpr LeftRight::Gen3 kGame { OFFSET_HALO4_PV_SPLITSCREEN_TABLE, OFFSET_HALO4_PV_SCREEN_SIZE, OFFSET_HALO4_PF_SPLITSCREEN_PLAYER_COUNT, OFFSET_HALO4_PF_FILL_RECT, OFFSET_HALO4_PF_RT_POOL_RELEASE, OFFSET_HALO4_PF_RT_POOL_INIT, diff --git a/src/mcc/module/entry/haloreach/view_safe.cpp b/src/mcc/module/entry/haloreach/view_safe.cpp new file mode 100644 index 00000000..5ac12354 --- /dev/null +++ b/src/mcc/module/entry/haloreach/view_safe.cpp @@ -0,0 +1,14 @@ +// Each split-screen view's own title-safe box, which its crosshair and aim centre on +// (MCC::Splitscreen::LeftRight::ViewSafeBox): Reach works a view's rect and its box out together. +#include "haloreach.h" + +#include "mcc/module/entry/PreservingThunk.h" +#include "mcc/splitscreen/LeftRight.h" + +namespace HaloReach::Entry::ViewSafe { + // a leaf, hence the preserving thunk + PreservedEntry(entry_viewport_rect, HaloReachEntrySet(), OFFSET_HALOREACH_PF_COMPUTE_VIEWPORT_RECT, + viewport_rect, void* slot, void* players, void* view, void* box, __int64) { + return MCC::Splitscreen::LeftRight::ViewportRect(entry_viewport_rect.m_pOriginal, slot, players, view, box); + } +} diff --git a/src/mcc/splitscreen/LeftRight.cpp b/src/mcc/splitscreen/LeftRight.cpp index 95386489..c0032818 100644 --- a/src/mcc/splitscreen/LeftRight.cpp +++ b/src/mcc/splitscreen/LeftRight.cpp @@ -79,6 +79,39 @@ namespace MCC::Splitscreen::LeftRight { if (!left_right) reach->patches()->apply(); } + Rect ViewSafeBox(const Rect& v) { + short dy = (short)((v.bottom - v.top) * 0.05f), dx = (short)((v.right - v.left) * 0.05f); + return {(short)(v.top + dy), (short)(v.left + dx), (short)(v.bottom - dy), (short)(v.right - dx)}; + } + + namespace { + thread_local int t_view_players = 0, t_view_slot = 0; // the view being set up (ViewSetup) + } + + ViewSetup::ViewSetup(int slot, int players) { t_view_players = players, t_view_slot = slot; } + ViewSetup::~ViewSetup() { t_view_players = 0; } + + bool TitleSafe(const Gen3& game, __int64 module, __int64 return_address, short box[4]) { + int players = t_view_players, slot = t_view_slot; + if (game.title_safe_return == nullptr || return_address - module != *game.title_safe_return || players < 2 || + players > 4 || slot >= players) + return false; + auto& entry = *Entry(game, module, {players, slot}); + auto screen = Screen(game, module); + // the view, as the engine rounds it + Rect view = {(short)(screen[1] * entry.y0), (short)(screen[0] * entry.x0), + (short)(screen[1] * entry.y1), (short)(screen[0] * entry.x1)}; + if (view.right <= view.left || view.bottom <= view.top) return false; + *(Rect*)box = ViewSafeBox(view); + return true; + } + + __int64 ViewportRect(void* original, void* slot, void* players, void* view, void* box) { + auto result = ((__int64 (*)(void*, void*, void*, void*))original)(slot, players, view, box); + if ((int)(__int64)players > 1) *(Rect*)box = ViewSafeBox(*(const Rect*)view); + return result; + } + void Frame(const Gen3& game, __int64 module, State& state) { if (state.module != module) { state.module = module; @@ -143,12 +176,20 @@ namespace MCC::Splitscreen::LeftRight { } const void* HudLayout(const Gen3& game, __int64 module, State& state, int user, const void* layout) { - if (layout == nullptr || user < 0 || user >= 4 || !state.tall_hud[user]) return layout; + if (layout == nullptr || user < 0 || user >= 4) return layout; + bool tall = state.tall_hud[user], split = game.hud_safe_frame && Players(game, module) > 1; + if (!tall && !split) return layout; auto copy = state.hud_layouts[user]; memcpy(copy, layout, (std::min)(game.hud_layout_size, kMaxHudLayoutSize)); - auto screen = Screen(game, module); - auto canvas = (int*)(copy + game.hud_canvas); - if (screen[0] > 1) canvas[1] = (int)((float)canvas[0] * screen[1] / (screen[0] / 2) + 0.5f); + if (tall) { + auto screen = Screen(game, module); + auto canvas = (int*)(copy + game.hud_canvas); + if (screen[0] > 1) canvas[1] = (int)((float)canvas[0] * screen[1] / (screen[0] / 2) + 0.5f); + } + if (split) { // zero: the game skips the clamp + auto frame = (float*)(copy + game.hud_safe_frame); + frame[0] = frame[1] = 0.0f; + } return copy; } diff --git a/src/mcc/splitscreen/LeftRight.h b/src/mcc/splitscreen/LeftRight.h index f4f37387..b2df9772 100644 --- a/src/mcc/splitscreen/LeftRight.h +++ b/src/mcc/splitscreen/LeftRight.h @@ -46,7 +46,9 @@ namespace MCC::Splitscreen::LeftRight { void (*before_painting)(__int64 module) = nullptr; // render state the painter sets up itself (Halo 4) bool double_rounding = false; // render-target sizes are rounded in double precision (Halo 3), not float int hud_layout_size = 0; // bytes in a HUD layout record (chud globals) ... - int hud_canvas = 0; // ... where it keeps its int canvas width, height (Halo 3, ODST) + int hud_canvas = 0; // ... where it keeps its int canvas width, height ... + int hud_safe_frame = 0; // ... and the share of the screen a HUD is clamped to, float H, V (Halo 3, ODST) + const AlphaRing::Offset* title_safe_return = nullptr; // where the view setup's call for the title-safe box returns (Halo 3, ODST) bool whole_quarter_hud = false; // quarters use the full-screen HUD layout (ODST: its quarter ones lack most elements) }; @@ -78,6 +80,11 @@ namespace MCC::Splitscreen::LeftRight { // three players one across the right half, where players 2 and 3 share it. void PaintBands(const Rect& screen, short half_width, int players, void (*fill)(Rect*, unsigned argb)); + // HudLayout also leaves off, for every split view, the share of the whole screen Halo 3 and ODST clamp + // each view's HUD frame to (hud_safe_frame): it trimmed a view on its outer sides only, which sat a + // quarter's HUD ~34 px toward the middle of the screen, and each view's frame now comes from its own + // safe box (ViewSafeBox). + // // The HUD of a full-height half. The engine picks a player's HUD layout by the shape of their view // (resolution 1 for a two-player half, 4 for a quarter; 5 and 6 on 4:3 screens) and each layout has a // virtual canvas, stretched over the view. No layout is taller than 4:3, so a Left/Right half takes a @@ -87,6 +94,26 @@ namespace MCC::Splitscreen::LeftRight { int HudResolution(const Gen3& game, __int64 module, State& state, int user, int resolution); const void* HudLayout(const Gen3& game, __int64 module, State& state, int user, const void* layout); + // A split-screen view's title-safe box: the box its HUD is laid out in, whose centre its crosshair and + // aim sit on. The engines clip each view by the whole screen's box (5% in from each edge), which pulls + // every view's box toward the middle of the screen - a 1080p quarter's crosshair sits 48 px off its + // centre, and on a screen spanning two monitors the HUD crowds the seam. This is the view's own box + // instead: the same size, 5% in from the view's edges; a lone view keeps the game's box. + Rect ViewSafeBox(const Rect& view); + + // Halo 3 and ODST: the view setup asks for the screen's box, then clips the view by it. Their hooks + // put a ViewSetup around the view setup, and in the title-safe function answer the view setup's call + // with TitleSafe (true: `box` is the view's own). + struct ViewSetup { + ViewSetup(int slot, int players); + ~ViewSetup(); + }; + bool TitleSafe(const Gen3& game, __int64 module, __int64 return_address, short box[4]); + + // Halo 4 and Reach work a view and its box out together in one function, (int slot, int players, + // short view[4], short box[4]). From its hook: calls the game's and makes the box the view's own. + __int64 ViewportRect(void* original, void* slot, void* players, void* view, void* box); + // From a render-target sizing hook: records that the pool is being built for the current choice, and // returns true when a target of this variant is the full-height halves' surface while Left/Right is // chosen - the caller then makes it half the screen's width and its full height. From 9fad2275666f7788c5e196912888dc3dc64e5e4f Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:24:12 -0400 Subject: [PATCH 14/17] feat(module): one split-screen layout combo for every game Dev Tools' "Two-player layout" combo sat in Reach's tab and set Reach's table only. It moves above the game tabs as "Split-screen layout" and goes through LeftRight::Choose: saved as before, switched at once in Halo 3, ODST, Halo 4 and Reach, and at the next mission start in Halo CE and Halo 2. Going back to Top / Bottom still re-applies Reach's enabled black-bar patches over the stock entries. Halo 3, ODST and Halo 4's black-bar checkboxes are disabled while Left / Right is chosen, as Reach's are: Left / Right owns the same table entries and puts back the ones it found when Top / Bottom returns, so a patch toggled meanwhile would be undone. docs/REVERSE_ENGINEERING.md names the combo's new place, and LeftRight::Active as the other games' active-layout check. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- docs/REVERSE_ENGINEERING.md | 4 +-- src/mcc/module/Module.cpp | 60 ++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/docs/REVERSE_ENGINEERING.md b/docs/REVERSE_ENGINEERING.md index c1cfeb51..71bcebe4 100644 --- a/docs/REVERSE_ENGINEERING.md +++ b/docs/REVERSE_ENGINEERING.md @@ -87,8 +87,8 @@ Observed resolution variants at 1920×1080: - Halo Reach's two-player bar painter assumes horizontal slots. With a left/right layout, slot 0's computed right bar covers player 2, so bypassing that painter is mandatory for the experiment. - Vertical configuration and black-bar removal touch the same table entries by different routes. Byte patches apply at load; the persistent store applies later. - The per-player HUD resolution semantic at `haloreach.dll + 0xD1F710` does not track the live splitscreen table — it is refreshed every HUD update from an unrelated per-player HUD-state field, not copied from the table (see "Resolved: Left/Right HUD fixes" below). -- The `Two-player layout` combo in `Module.cpp` is the supported control; a prior unused `g_verticalSplitToggle` flag that gated nothing was removed 2026-09-17. -- **`ResolveActiveLayout(playerCount)` always returns Native for 1P and 4P**, regardless of the saved Left/Right preference — the preference persists across player counts, but every Left/Right-keyed behavior (bar suppression, HUD semantic override, render-target sizing) must gate on the *active* layout, not the saved one. An earlier version gated on the saved preference alone and forced the 2P pillarbox HUD record onto a full-screen solo slot; fixed by adding this scope check. Any new Left/Right-conditional code must use `ResolveActiveLayout`/`UsesFullHeightLeftRightSlot`, never the raw preference. +- The `Split-screen layout` combo in `Module.cpp` (Dev Tools, above the game tabs; formerly Reach's `Two-player layout`) is the supported control, and sets the layout for every game (`mcc/splitscreen/LeftRight`); a prior unused `g_verticalSplitToggle` flag that gated nothing was removed 2026-09-17. +- **`ResolveActiveLayout(playerCount)` always returns Native for 1P and 4P**, regardless of the saved Left/Right preference — the preference persists across player counts, but every Left/Right-keyed behavior (bar suppression, HUD semantic override, render-target sizing) must gate on the *active* layout, not the saved one. An earlier version gated on the saved preference alone and forced the 2P pillarbox HUD record onto a full-screen solo slot; fixed by adding this scope check. Any new Left/Right-conditional code must use `ResolveActiveLayout`/`UsesFullHeightLeftRightSlot`, never the raw preference. The other games' equivalent is `LeftRight::Active`, which leaves out Reach's hook gate (`LeftRightAvailable`). - **Known — current behavior, validated:** the bars-removed/bars-on preference is independent of layout selection and survives Top/Bottom↔Left/Right switching (both directions) and a full MCC restart. Cause of an earlier regression (layout selection silently erasing the user's bar choice) and its fix are covered under `CPatch` below — the same root cause also explains a "toggle inert until a layout round-trip" symptom. ## Vertical-splitscreen investigation diff --git a/src/mcc/module/Module.cpp b/src/mcc/module/Module.cpp index 0ee8ca93..cc5a1c4d 100644 --- a/src/mcc/module/Module.cpp +++ b/src/mcc/module/Module.cpp @@ -11,6 +11,7 @@ #include "mcc/CGameManager.h" #include "mcc/module/patch/PatchConfig.h" #include "mcc/module/patch/SplitscreenConfigStore.h" +#include "mcc/splitscreen/LeftRight.h" #include "global/Global.h" #include "log/DebugFlags.h" @@ -232,8 +233,22 @@ namespace MCC::Module { ImGui::EndMenuBar(); } + // Everyone's split-screen layout, in every game (mcc/splitscreen/LeftRight). It was Reach's + // "Two-player layout" combo; Choose() also re-applies Reach's enabled black-bar patches over + // the stock entries when going back to Top / Bottom. + int layout_index = MCC::Splitscreen::LeftRight::Chosen() ? 1 : 0; + const char* layout_names[] = { "Top / Bottom", "Left / Right" }; + ImGui::SetNextItemWidth(180.0f); + if (ImGui::Combo("Split-screen layout", &layout_index, layout_names, 2)) + MCC::Splitscreen::LeftRight::Choose(layout_index == 1); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("Everyone's layout, in every game. Left / Right: 2 players get equal full-height halves; 3 players put player 1 on the full left half and players 2/3 on the right half. 1 and 4 players always use the game's own layout. Halo 3, ODST, Halo 4 and Reach switch at once; Halo CE and Halo 2 at the next mission start, in Classic graphics."); + if (!ImGui::BeginTabBar("patch")) return; + // under each game's black-bar controls, disabled while Left / Right is chosen + static constexpr const char* kBarsKept = "Black-bar settings are kept and return with Top / Bottom."; + counter = 0; for (int i = MODULE_HALO1; i < MODULE_MCC; ++i) { @@ -267,38 +282,14 @@ namespace MCC::Module { // while Left/Right is selected SplitscreenConfigStore::Apply // rewrites every field of those entries each frame, so an // enabled patch's bytes never show, and the painter bypass - // is derived in blackbars.cpp. Selecting Top/Bottom writes - // the stock entries, then re-applies each enabled patch so - // the user's saved bar choice comes back exactly as it was. + // is derived in blackbars.cpp. Selecting Top/Bottom (the + // layout combo above the tabs) writes the stock entries, + // then re-applies each enabled patch so the user's saved + // bar choice comes back exactly as it was. // (The old exclusion rationale - D1F710 as a stale table // cache - was disproved: D1F710 is not table-derived.) - auto layout = AlphaRing::SplitscreenConfigStore::GetTwoPlayerLayout(); - int layout_index = (int)layout; - const char* layout_names[] = { "Top / Bottom", "Left / Right" }; - - ImGui::PushID(counter++); - ImGui::SetNextItemWidth(180.0f); - if (ImGui::Combo("Two-player layout", &layout_index, layout_names, 2)) { - layout = (AlphaRing::SplitscreenConfigStore::TwoPlayerLayout)layout_index; - - auto h = GetSubModule((eModule)i)->info().hModule; - AlphaRing::SplitscreenConfigStore::SetTwoPlayerLayout(layout, h); - - if (layout == AlphaRing::SplitscreenConfigStore::TwoPlayerLayout::TopBottom) { - CPatch* bars[3] = { p_bar1, p_bar2, p_bar3 }; - for (auto p_bar : bars) - if (p_bar != nullptr && p_bar->enabled()) - p_bar->apply(); - } - } - ImGui::PopID(); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Selects the 2- and 3-player rectangles explicitly. Left / Right: 2 players get equal full-height halves; 3 players put player 1 on the full left half (as in 2 players) and players 2/3 on the right half. 1 and 4 players always use Reach's own layout."); - - const bool left_right = - layout == AlphaRing::SplitscreenConfigStore::TwoPlayerLayout::LeftRight; - if (left_right) - ImGui::TextDisabled("Black-bar settings are kept and return with Top / Bottom."); + const bool left_right = MCC::Splitscreen::LeftRight::Chosen(); + if (left_right) ImGui::TextDisabled(kBarsKept); if (left_right) ImGui::BeginDisabled(); @@ -623,6 +614,13 @@ namespace MCC::Module { bool player1_on = (p_bar1 == nullptr || p_bar3 == nullptr) ? true : (p_bar1->enabled() && p_bar3->enabled()); + // Left / Right owns the same table entries and puts back the ones it + // found when the player returns to Top / Bottom, so the bars hold still + // meanwhile (as in Reach). + const bool left_right = i != MODULE_GROUNDHOG && MCC::Splitscreen::LeftRight::Chosen(); + if (left_right) ImGui::TextDisabled(kBarsKept); + ImGui::BeginDisabled(left_right); + if (p_bar1 != nullptr && p_bar3 != nullptr) { bool top = player1_on; ImGui::PushID(counter++); @@ -663,6 +661,8 @@ namespace MCC::Module { : "Enable Player 1's black-bar removal first. On this game, Player 2's toggle only takes effect when Player 1's is also on - same shared-painter bug Reach had before its dedicated fix."); } + ImGui::EndDisabled(); + ImGui::Separator(); } } From 2d01db3212d4095e7778797d305df59c96504ee1 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 15:34:46 -0400 Subject: [PATCH 15/17] fix(halo4): Left/Right only with the HUD fit's hooks Halo 4's Left/Right hooks and its HUD fit (hud_fit.cpp) were separate features: on an MCC update where one of the fit's offsets is missing, the table, targets and quarter HUD layout still went to Left/Right while the HUD kept to the top half of each view, the motion tracker at mid-height. A feature can now require another (Feature::Requires, Offset.h): Halo 4's Left/Right feature requires the HUD fit's, so without it none of its hooks go in and Halo 4 keeps its stock split. No change on 1.3528. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- lib/game/inc/Offset.h | 6 ++++++ src/mcc/module/entry/halo4/halo4.h | 1 + src/mcc/module/entry/halo4/hud_fit.cpp | 1 + src/mcc/module/entry/halo4/splitscreen.cpp | 3 +++ 4 files changed, 11 insertions(+) diff --git a/lib/game/inc/Offset.h b/lib/game/inc/Offset.h index 228ac864..ddeeee0f 100644 --- a/lib/game/inc/Offset.h +++ b/lib/game/inc/Offset.h @@ -39,12 +39,17 @@ namespace AlphaRing { void Add(const Offset& offset) { m_offsets.push_back(&offset); } + // A feature that only works together with this one: when one of its offsets is missing, so is this. + void Requires(const Feature& other) { m_requires.push_back(&other); } + const char* Name() const { return m_name; } // The first of its offsets this build lacks, or nullptr when it's all there. const Offset* Missing() const { for (auto offset : m_offsets) if (!offset->found()) return offset; + for (auto feature : m_requires) + if (auto missing = feature->Missing()) return missing; return nullptr; } @@ -53,6 +58,7 @@ namespace AlphaRing { private: const char* m_name; std::vector m_offsets; + std::vector m_requires; }; } diff --git a/src/mcc/module/entry/halo4/halo4.h b/src/mcc/module/entry/halo4/halo4.h index 88992b66..446a3ded 100644 --- a/src/mcc/module/entry/halo4/halo4.h +++ b/src/mcc/module/entry/halo4/halo4.h @@ -23,6 +23,7 @@ namespace Halo4::Entry { namespace HudFit { void Refresh(__int64 module); // each user's fit, once a frame (hud_fit.cpp) + const ::AlphaRing::Feature& Hooks(); // its hooks and offsets, which Left/Right requires } } diff --git a/src/mcc/module/entry/halo4/hud_fit.cpp b/src/mcc/module/entry/halo4/hud_fit.cpp index e25d286c..3dd24ff2 100644 --- a/src/mcc/module/entry/halo4/hud_fit.cpp +++ b/src/mcc/module/entry/halo4/hud_fit.cpp @@ -24,6 +24,7 @@ namespace Halo4::Entry::HudFit { EntryFeature("Halo 4 split-screen HUD fit", OFFSET_HALO4_PV_SPLITSCREEN_TABLE, OFFSET_HALO4_PV_SCREEN_SIZE, OFFSET_HALO4_PF_HUD_LAYOUT, OFFSET_HALO4_PF_SPLITSCREEN_PLAYER_COUNT, OFFSET_HALO4_PF_UI_USER_INDEX, OFFSET_HALO4_VT_UI_GROUP, OFFSET_HALO4_VT_HUD_RETICLE_GROUP); + const ::AlphaRing::Feature& Hooks() { return *entry_feature; } struct Fit { bool on = false; diff --git a/src/mcc/module/entry/halo4/splitscreen.cpp b/src/mcc/module/entry/halo4/splitscreen.cpp index ab6baa8f..dc04f856 100644 --- a/src/mcc/module/entry/halo4/splitscreen.cpp +++ b/src/mcc/module/entry/halo4/splitscreen.cpp @@ -13,6 +13,9 @@ namespace Halo4::Entry::Splitscreen { EntryFeature("Halo 4 Left/Right split screen", OFFSET_HALO4_PV_SPLITSCREEN_TABLE, OFFSET_HALO4_PV_SCREEN_SIZE, OFFSET_HALO4_PF_SPLITSCREEN_PLAYER_COUNT, OFFSET_HALO4_PF_FILL_RECT, OFFSET_HALO4_PF_RT_POOL_RELEASE, OFFSET_HALO4_PF_RT_POOL_INIT, OFFSET_HALO4_PF_RENDER_SETUP_1, OFFSET_HALO4_PF_RENDER_SETUP_2); + // A half's HUD only fits it with hud_fit.cpp's hooks (without them it keeps to the half's top half): on a build + // without one of them, none of these go in either and Halo 4 keeps its stock split. + const bool s_requires_hud_fit = (entry_feature->Requires(HudFit::Hooks()), true); // The bar painter sets the render state up itself before drawing (as Reach's does, blackbars.cpp). void BeforePainting(__int64 module) { From a84a8feedcd496aad1195350d567196f8a753923 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 15:51:52 -0400 Subject: [PATCH 16/17] fix(halo4): the HUD fit's extras, each axis on its own Compute gave a Left/Right half either extra width or extra height, by which side of the layout's aspect the half was on. Halo 4's UI root translation adds both (ExtraWidth at 0x3D61EB, ExtraHeight at 0x3D61FF, independently), and a half of a screen wider than 16:9 has room either side of its layout as well as above and below it: at 32:9 a half is 1280x720 HUD units for the quarter layout's 640x360, which wants 320 each side and 180 above and below, not 180 alone. Each extra is now its own axis's. On 16:9 the half is exactly the layout's width, so nothing changes there; not tried on an ultrawide screen. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/entry/halo4/hud_fit.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mcc/module/entry/halo4/hud_fit.cpp b/src/mcc/module/entry/halo4/hud_fit.cpp index 3dd24ff2..ddbcad4c 100644 --- a/src/mcc/module/entry/halo4/hud_fit.cpp +++ b/src/mcc/module/entry/halo4/hud_fit.cpp @@ -55,8 +55,10 @@ namespace Halo4::Entry::HudFit { if (view_h < 1 || (std::abs(view_w - layout_w) < 1 && std::abs(view_h - layout_h) < 1)) return fit; fit.on = true; fit.aspect = (view_w / view_h) / (layout_w / layout_h); - if (fit.aspect > 1.0f) fit.extra_x = (view_w - layout_w) * 0.5f; - else fit.extra_y = (view_h - layout_h) * 0.5f; + // each axis on its own: the root translation adds both (0x3D61EB, 0x3D61FF), and a half of a screen wider + // than 16:9 has room either side of its layout as well as above and below it + fit.extra_x = (view_w - layout_w) * 0.5f; + fit.extra_y = (view_h - layout_h) * 0.5f; return fit; } From 55e86345af9d93c287266f1e8ea1028cdf91bf74 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 16:31:55 -0400 Subject: [PATCH 17/17] revert(halo4): the HUD fit's extras back to one axis Giving a Left/Right half both extras centres its HUD on a screen wider than 16:9 through the UI's root translation, which adds both (0x3D61EB, 0x3D61FF) - but the world-marker projection (0x3F2783-0x3F27C5) cancels only the extra that Wide() picks, so nametags and waypoints would land 320 HUD units off at 32:9 (and 160 with the bars removed at 4:3). Back to one extra until that path cancels the other axis too: on screens wider than 16:9 a half's HUD stays uncentred horizontally, as before. Nothing changes at 16:9 either way. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/entry/halo4/hud_fit.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/mcc/module/entry/halo4/hud_fit.cpp b/src/mcc/module/entry/halo4/hud_fit.cpp index ddbcad4c..3dd24ff2 100644 --- a/src/mcc/module/entry/halo4/hud_fit.cpp +++ b/src/mcc/module/entry/halo4/hud_fit.cpp @@ -55,10 +55,8 @@ namespace Halo4::Entry::HudFit { if (view_h < 1 || (std::abs(view_w - layout_w) < 1 && std::abs(view_h - layout_h) < 1)) return fit; fit.on = true; fit.aspect = (view_w / view_h) / (layout_w / layout_h); - // each axis on its own: the root translation adds both (0x3D61EB, 0x3D61FF), and a half of a screen wider - // than 16:9 has room either side of its layout as well as above and below it - fit.extra_x = (view_w - layout_w) * 0.5f; - fit.extra_y = (view_h - layout_h) * 0.5f; + if (fit.aspect > 1.0f) fit.extra_x = (view_w - layout_w) * 0.5f; + else fit.extra_y = (view_h - layout_h) * 0.5f; return fit; }