From b22b441f6e1c46c1648461ad4be4ab41504ef805 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 19:58:33 -0400 Subject: [PATCH 1/9] feat(offsets): per-player HUD addresses for Halo CE, 2, 3, ODST and Reach What the per-player HUD reads and hooks: the player whose HUD is being drawn in Halo CE, 2, 3 and ODST (Reach's is XiaoDanny's DAT_CURRENT_HUD_PLAYER), the HUD canvas in Halo 3 and ODST (Reach's is PV_HUD_CANVAS), Halo 2's HUD view bounds and offset unit scale, Halo CE's hud_calculate_point and the view it places points in, and where Reach's per-widget transform ask returns. Also Halo 2's "HUD anchor: Centered" global and the je that skips its centred 16:9 HUD frame, with a COVER entry: a patch there relies on the jump's distance. Each has byte patterns (gen_patterns.py): offset_test finds all 237 patterned offsets exactly, 13 of them new. 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 | 5 +++++ lib/game/inc/1.3528.0.0/offset_halo2.h | 8 ++++++++ lib/game/inc/1.3528.0.0/offset_halo3.h | 4 ++++ lib/game/inc/1.3528.0.0/offset_halo3odst.h | 4 ++++ lib/game/inc/1.3528.0.0/offset_haloreach.h | 6 ++++++ lib/game/inc/1.3528.0.0/patterns_halo1.inc | 9 +++++++++ lib/game/inc/1.3528.0.0/patterns_halo2.inc | 14 ++++++++++++++ lib/game/inc/1.3528.0.0/patterns_halo3.inc | 6 ++++++ lib/game/inc/1.3528.0.0/patterns_halo3odst.inc | 6 ++++++ lib/game/inc/1.3528.0.0/patterns_haloreach.inc | 2 ++ tools/offsets/gen_patterns.py | 1 + 11 files changed, 65 insertions(+) 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 09114586..64e4bcd1 100644 --- a/lib/game/inc/1.3528.0.0/offset_halo1.h +++ b/lib/game/inc/1.3528.0.0/offset_halo1.h @@ -21,3 +21,8 @@ DefOffset(OFFSET_HALO1_PV_SCREEN_BOUNDS, 0x1B7D3DC) // int16 top, left, bottom, 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") + +// Per-player HUD (mcc/hud, module/entry/halo1/hud.cpp) +DefOffset(OFFSET_HALO1_PF_HUD_CALCULATE_POINT, 0xB56A58) // (player, placement, header, -, bool, float, short2* out, int mcc element) +DefOffset(OFFSET_HALO1_PV_HUD_VIEWPORT_BOUNDS, 0x29AF2F0) // int16 top, left, bottom, right of the view being drawn +DefOffset(OFFSET_HALO1_PV_HUD_DRAWING_PLAYER, 0x29AF2B8) // int16 local player whose HUD is being drawn 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 93082ae2..893d7b76 100644 --- a/lib/game/inc/1.3528.0.0/offset_halo2.h +++ b/lib/game/inc/1.3528.0.0/offset_halo2.h @@ -38,3 +38,11 @@ DefOffset(OFFSET_HALO2_PV_SPLIT_MODE, 0x165C168) // int - the frame's grid mode, 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 + +// Per-player HUD (mcc/hud). With "HUD anchor: Centered" on a screen wider than 16:9, 0x954DD0 insets the whole-screen +// HUD frame to a centred 16:9 box, which 0x7E0A40 splits among the players. +DefOffset(OFFSET_HALO2_PF_HUD_ASPECT_LOCK, 0x954DF2) // je (74 3C) that skips the centred 16:9 HUD frame when the profile's aspect lock is off +DefOffset(OFFSET_HALO2_PV_HUD_ASPECT_LOCK, 0x197EE40) // bool: the profiles' LockMaxAspectRatio ("HUD anchor: Centered"), the last loaded wins +DefOffset(OFFSET_HALO2_PV_HUD_DRAWING_PLAYER, 0x165C398) // int local player whose HUD is being drawn +DefOffset(OFFSET_HALO2_PV_HUD_VIEW_BOUNDS, 0x165C298) // int16 top, left, bottom, right of that player's HUD (window bounds) +DefOffset(OFFSET_HALO2_PV_HUD_UNIT_SCALE, 0xE14F28) // float: pixels per HUD offset unit (times the element's scale) 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 10156bf2..09236337 100644 --- a/lib/game/inc/1.3528.0.0/offset_halo3.h +++ b/lib/game/inc/1.3528.0.0/offset_halo3.h @@ -56,6 +56,10 @@ DefOffset(OFFSET_HALO3_PF_VIEW_SETUP, 0x282EC4) // void (view*, int slot, int pl 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 +// Per-player HUD (mcc/hud) +DefOffset(OFFSET_HALO3_PV_HUD_DRAWING_PLAYER, 0xAD317C) // int user whose HUD is being drawn +DefOffset(OFFSET_HALO3_PV_HUD_CANVAS, 0xAD3148) // float width, height of that user's HUD virtual canvas + 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 aef32efd..01af1a48 100644 --- a/lib/game/inc/1.3528.0.0/offset_halo3odst.h +++ b/lib/game/inc/1.3528.0.0/offset_halo3odst.h @@ -32,3 +32,7 @@ DefOffset(OFFSET_HALO3ODST_PF_HUD_LAYOUT, 0x3284B4) // record* - +0x94 int canva 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 + +// Per-player HUD (mcc/hud); see offset_halo3.h +DefOffset(OFFSET_HALO3ODST_PV_HUD_DRAWING_PLAYER, 0xB1AA04) +DefOffset(OFFSET_HALO3ODST_PV_HUD_CANVAS, 0xB1A9D8) diff --git a/lib/game/inc/1.3528.0.0/offset_haloreach.h b/lib/game/inc/1.3528.0.0/offset_haloreach.h index c7428153..ef9789e1 100644 --- a/lib/game/inc/1.3528.0.0/offset_haloreach.h +++ b/lib/game/inc/1.3528.0.0/offset_haloreach.h @@ -139,6 +139,12 @@ DefOffset(OFFSET_HALOREACH_PV_HUD_CANVAS, 0xD1F6F0) // float width, height of th DefOffset(OFFSET_HALOREACH_DAT_HUD_BASIS, 0xD1F740) // float4[5], ending where the next begins DefOffset(OFFSET_HALOREACH_DAT_HUD_SCREEN_SCALE_AND_OFFSET, 0xD1F790) // chud_screen_scale_and_offset: float xInset, yInset, halfW, halfH +// Per-player HUD (mcc/hud; the player is DAT_CURRENT_HUD_PLAYER, the canvas PV_HUD_CANVAS). Where the per-widget +// get_hud_element_transform call (0x2D93A4, widget anchor -> element) returns. UpdatePlayerHudView already asks for the +// motion sensor (element 1) once per view and bakes the answer into the radar centre the dish and blips draw from, so a +// dish widget asking again here would get it twice. +DefOffset(OFFSET_HALOREACH_V_HUD_WIDGET_TRANSFORM_RETURN, 0x2D9443) + // Dev Tools' resolution/FOV table dump (mcc/module/Module.cpp) DefOffset(OFFSET_HALOREACH_PF_GET_SPLITSCREEN_SLOT_TOKEN, 0x53EC8) // unsigned (int slot) DefOffset(OFFSET_HALOREACH_PF_RESOLVE_HUD_PROFILE, 0x2C2F60) // int (unsigned token) 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 d5e437e5..e60cd327 100644 --- a/lib/game/inc/1.3528.0.0/patterns_halo1.inc +++ b/lib/game/inc/1.3528.0.0/patterns_halo1.inc @@ -41,4 +41,13 @@ const OffsetPatterns kHalo1Patterns[] = { {&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)}}, + {&OFFSET_HALO1_PF_HUD_CALCULATE_POINT, 0xb56a58, Code, { + At("48 8B C4 48 89 58 18 48 89 70 20 55 57 41 55 41 56", 0x0), + Rel("E8 ?? ?? ?? ?? 0F B7 45 E2 66 89 45 D2 0F B7 C3 66 03 45 4A", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PV_HUD_VIEWPORT_BOUNDS, 0x29af2f0, Data, { + Rel("0F BF 05 ?? ?? ?? ?? F3 0F 59 D7 0F 5B C0 66 0F 6E C8 0F 5B C9", 0x3, 0x7, 0x0), + Rel("44 0F B7 35 ?? ?? ?? ?? 41 0F B7 F4 8A 84 04 D8 00 00 00 FE C8", 0x4, 0x8, 0x0)}}, + {&OFFSET_HALO1_PV_HUD_DRAWING_PLAYER, 0x29af2b8, Data, { + Rel("0F B7 35 ?? ?? ?? ?? B8 03 00 00 00 66 B9 04 00 66 3B F8 75", 0x3, 0x7, 0x0), + Rel("0F BF 0D ?? ?? ?? ?? 89 4D 67 48 8B C8 48 C1 E9 10 48 89 45 6F", 0x3, 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 534fdd03..9ca3540c 100644 --- a/lib/game/inc/1.3528.0.0/patterns_halo2.inc +++ b/lib/game/inc/1.3528.0.0/patterns_halo2.inc @@ -65,4 +65,18 @@ const OffsetPatterns kHalo2Patterns[] = { {&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)}}, + {&OFFSET_HALO2_PF_HUD_ASPECT_LOCK, 0x954df2, Code, { + At("74 3C F3 0F 10 15 ?? ?? ?? ?? 66 0F 6E CF 66 0F 6E C3 0F 5B C9", 0x0)}}, + {&OFFSET_HALO2_PV_HUD_ASPECT_LOCK, 0x197ee40, Data, { + Rel("88 05 ?? ?? ?? ?? 48 8B 01 FF 50 60 8B 54 24 54 8B 4C 24 50", 0x2, 0x6, 0x0), + Rel("38 15 ?? ?? ?? ?? 44 0F B7 C2 74 ?? F3 0F 10 15 ?? ?? ?? ?? 66 0F 6E CF 66 0F 6E C3", 0x2, 0x6, 0x0)}}, + {&OFFSET_HALO2_PV_HUD_DRAWING_PLAYER, 0x165c398, Data, { + Rel("8B 0D ?? ?? ?? ?? F3 0F 59 C6 F3 0F 11 44 24 50 F2 0F 10 00", 0x2, 0x6, 0x0), + Rel("48 63 35 ?? ?? ?? ?? 8B CE 48 89 7C 24 60 0F 29 74 24 50 E8", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PV_HUD_VIEW_BOUNDS, 0x165c298, Data, { + Rel("66 41 F7 D8 48 8B 05 ?? ?? ?? ?? 66 F7 DA 48 89 44 24 50 E8", 0x7, 0xb, 0x0), + Rel("0F BF 15 ?? ?? ?? ?? 41 8B F0 45 8B E1 44 8B DA 41 8B FA 66 0F 6E C8", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PV_HUD_UNIT_SCALE, 0xe14f28, Data, { + Rel("F3 0F 11 0D ?? ?? ?? ?? 4C 8D 9C 24 A0 04 00 00 49 8B 73 18", 0x4, 0x8, 0x0), + Rel("0F 5B C0 F3 0F 59 05 ?? ?? ?? ?? F3 0F 2C C0 48 83 C4 28 C3", 0x7, 0xb, 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 4028b749..a498ea55 100644 --- a/lib/game/inc/1.3528.0.0/patterns_halo3.inc +++ b/lib/game/inc/1.3528.0.0/patterns_halo3.inc @@ -115,4 +115,10 @@ const OffsetPatterns kHalo3Patterns[] = { 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)}}, + {&OFFSET_HALO3_PV_HUD_DRAWING_PLAYER, 0xad317c, Data, { + Rel("8B 15 ?? ?? ?? ?? F3 0F 59 C1 F3 4C 0F 2C C8 F3 41 0F 10 00", 0x2, 0x6, 0x0), + Rel("48 63 05 ?? ?? ?? ?? 48 69 C8 C8 28 00 00 4A 8B 04 02 8B 94 08 60 14 00 00", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO3_PV_HUD_CANVAS, 0xad3148, Data, { + Rel("F3 0F 11 1D ?? ?? ?? ?? 66 0F 6E 43 14 0F 5B C0 F3 0F 11 35", 0x4, 0x8, 0x0), + Rel("F3 0F 10 05 ?? ?? ?? ?? F3 0F 11 44 24 30 F3 0F 11 4C 24 34", 0x4, 0x8, 0x0)}}, }; 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 a69482f9..0cab920a 100644 --- a/lib/game/inc/1.3528.0.0/patterns_halo3odst.inc +++ b/lib/game/inc/1.3528.0.0/patterns_halo3odst.inc @@ -55,4 +55,10 @@ const OffsetPatterns kHalo3odstPatterns[] = { 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)}}, + {&OFFSET_HALO3ODST_PV_HUD_DRAWING_PLAYER, 0xb1aa04, Data, { + Rel("44 89 3D ?? ?? ?? ?? E8 ?? ?? ?? ?? 89 05 ?? ?? ?? ?? 41 8B CF 8B 94 3E 68 15 00 00", 0x3, 0x7, 0x0), + Rel("8B 15 ?? ?? ?? ?? 0F 29 74 24 20 F3 0F 10 35 ?? ?? ?? ?? F3 0F 59 C6 F3 4C 0F 2C C8", 0x2, 0x6, 0x0)}}, + {&OFFSET_HALO3ODST_PV_HUD_CANVAS, 0xb1a9d8, Data, { + Rel("F3 0F 10 0D ?? ?? ?? ?? F3 0F 11 4D F8 66 0F 6E C0 0F 5B C0", 0x4, 0x8, 0x0), + Rel("F3 0F 10 05 ?? ?? ?? ?? F3 0F 11 44 24 38 F3 0F 11 4C 24 3C", 0x4, 0x8, 0x0)}}, }; diff --git a/lib/game/inc/1.3528.0.0/patterns_haloreach.inc b/lib/game/inc/1.3528.0.0/patterns_haloreach.inc index 2b0b7a00..d196491e 100644 --- a/lib/game/inc/1.3528.0.0/patterns_haloreach.inc +++ b/lib/game/inc/1.3528.0.0/patterns_haloreach.inc @@ -229,6 +229,8 @@ const OffsetPatterns kHaloreachPatterns[] = { {&OFFSET_HALOREACH_DAT_HUD_SCREEN_SCALE_AND_OFFSET, 0xd1f790, Data, { Rel("F3 0F 58 05 ?? ?? ?? ?? F3 44 0F 10 65 97 45 33 D2 F3 44 0F 10 55 9B", 0x4, 0x8, 0x0), Rel("F3 0F 10 05 ?? ?? ?? ?? 48 8D 55 A0 F3 0F 10 0D ?? ?? ?? ?? 41 B8 10 00 00 00", 0x4, 0x8, 0x0)}}, + {&OFFSET_HALOREACH_V_HUD_WIDGET_TRANSFORM_RETURN, 0x2d9443, Code, { + At("41 FF D2 84 C0 74 51 48 8B 0D ?? ?? ?? ?? 48 85 C9 74 ?? 48 8B 01", 0x3)}}, {&OFFSET_HALOREACH_PF_GET_SPLITSCREEN_SLOT_TOKEN, 0x53ec8, Code, { At("83 C8 FF 83 F9 03 77 27 8B 15 ?? ?? ?? ?? 65 48 8B 04 25 58 00 00 00 41 B8 58 01 00 00 48 63 C9 48 8B 04 D0 4A 8B 04 00 8B 84 88 B8 00 00 00", 0x0), Rel("E8 ?? ?? ?? ?? 48 8D 4F 04 8B D8 33 D2 41 B8 9C 01 00 00 E8", 0x1, 0x5, 0x0)}}, diff --git a/tools/offsets/gen_patterns.py b/tools/offsets/gen_patterns.py index 32b981e5..f62735fa 100644 --- a/tools/offsets/gen_patterns.py +++ b/tools/offsets/gen_patterns.py @@ -48,6 +48,7 @@ "OFFSET_HALO2_PF_PLAYER_COUNT2": 1, "OFFSET_HALO2_TWO_PLAYERS_TEST_HAND_OVER": 5, "OFFSET_HALO2_PF_QUIT_TO_LOBBY_TEST": 9, + "OFFSET_HALO2_PF_HUD_ASPECT_LOCK": 2, "OFFSET_HALO4_PF_COOP_PLAYER_LIMIT": 6, "OFFSET_HALO4_PF_COOP_REJOIN": 2, "OFFSET_HALO4_VIEWMODEL_ASPECT_DIVIDE": 4, From 96ea518655d42fa1f60b7a6f14074af63e7d4d21 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 19:58:38 -0400 Subject: [PATCH 2/9] fix(halo2): keep each player's HUD at their view's edges on ultrawide With MCC's "HUD anchor: Centered" (the profiles' LockMaxAspectRatio, the default) and a screen wider than 16:9, Halo 2 insets the whole-screen HUD frame to a centred 16:9 box (0x954DD0) and splits that box among the players (0x7E0A40): every split-screen HUD bunched toward the middle of the screen and the crosshairs left their views' centres. A new embedded patch, "HUD at screen edges" (0x954DF2: je -> jmp, on by default), skips the inset - MCC's "HUD anchor: Edge" - so each player's HUD sits at the edges of their own view. It applies with one player too; unchecking it in Dev Tools brings "Centered" back. Nothing changes on a 16:9 or narrower screen. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/CModule.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mcc/module/CModule.cpp b/src/mcc/module/CModule.cpp index 2624c195..bd2f38bd 100644 --- a/src/mcc/module/CModule.cpp +++ b/src/mcc/module/CModule.cpp @@ -186,6 +186,11 @@ static struct { {"splitscreen_patch2", "", OFFSET_HALO2_PF_PLAYER_COUNT1, "\x04", true, &Halo2FourPlayers}, {"splitscreen_patch3", "", OFFSET_HALO2_PF_PLAYER_COUNT2, "\x04", true, &Halo2FourPlayers}, {"splitscreen_patch4", "force making splitscreen works with more than 2 players", OFFSET_HALO2_TWO_PLAYERS_TEST_HAND_OVER, "\x83\xF8\x01\x74\x04", true, &Halo2FourPlayers}, + // With MCC's default "HUD anchor: Centered", Halo 2 fits the whole HUD frame into a centred 16:9 box + // on wider screens and splits that box between the players, so on ultrawide or multi-monitor + // screens every player's HUD bunches up toward the middle of the screen. Always "Edge" instead. + {"HUD at screen edges", "keep every player's HUD at the edges of their own view on screens wider than 16:9 " + "(ultrawide, several monitors) - the same as MCC's 'HUD anchor: Edge'", OFFSET_HALO2_PF_HUD_ASPECT_LOCK, "\xEB", true}, // Save & Quit from a modded campaign with 2+ players hung on the loading screen (reported by SR388): Halo 2 // decided the game came from its own lobby and went back to it by loading its main-menu map, which MCC // doesn't have. MCC is the lobby, so quitting always goes back to it. From 860bde150d97596f9f84e962d25850737bd8eb68 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 19:58:49 -0400 Subject: [PATCH 3/9] feat(hud): per-player HUD settings through MCC's HUD callbacks Halo CE, 2, 3, ODST and Reach ask MCC's host for an override of each HUD element right before placing it (CGameManager vtable +0x300, then the anchor at +0x2F8), with the player being drawn in a global of their own, and Halo 3, ODST and Reach pass every HUD colour through +0x308. CGameManagerHud.cpp hooks the three and keeps MCC's answer; src/mcc/hud adds the drawing player's settings on top: - a size for the whole HUD; - a HUD area: the HUD's left and right elements moved to the sides of a centred box of another shape (Screen edges, 21:9, 16:9, 4:3); - each element's offset, size and visibility; - in Halo 3, ODST and Reach, a recolour toward a hue (whites and enemy reds keep theirs). A table per game gives its drawing-player global, MCC's element ids, the units its offsets are in (the HUD canvas, or Halo 2's pixels per unit scale) and which side of its HUD box each element is on. Halo CE adds the host's offsets to x only, so its offsets come from a hook on hud_calculate_point, added to each placed point in the view being drawn; its sizes and hiding go through the host. Reach asks for the motion sensor twice - once per view for the radar centre, again per widget - so the per-widget ask, told apart by its return address, is left to MCC. With a player's settings at their defaults nothing is added, and the callbacks' outputs are only written when there is something to add, so the games get MCC's answers as before. The settings live in memory for the session; nothing reads or writes a file. Each game's answers are a Feature of every offset they read: in an MCC build without one, that game's HUD is left as it is, logged once. Halo CE's require its hook's feature, and the hook moves points only while they're available. Halo 2's area presets also need the aspect-lock offsets to know where its HUD box is; without them they leave Halo 2's HUD alone. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/CGameManager.cpp | 3 + src/mcc/CGameManager.h | 22 ++- src/mcc/CGameManagerHud.cpp | 33 ++++ src/mcc/hud/Hud.cpp | 241 +++++++++++++++++++++++++++++ src/mcc/hud/Hud.h | 52 +++++++ src/mcc/module/entry/halo1/hud.cpp | 34 ++++ 6 files changed, 384 insertions(+), 1 deletion(-) create mode 100644 src/mcc/CGameManagerHud.cpp create mode 100644 src/mcc/hud/Hud.cpp create mode 100644 src/mcc/hud/Hud.h create mode 100644 src/mcc/module/entry/halo1/hud.cpp diff --git a/src/mcc/CGameManager.cpp b/src/mcc/CGameManager.cpp index 139172e6..5a691106 100644 --- a/src/mcc/CGameManager.cpp +++ b/src/mcc/CGameManager.cpp @@ -87,6 +87,9 @@ bool CGameManager::Initialize(CGameManager* mng) { {pGameManager->table->set_state, set_state, (void**)&ppOriginal.set_state}, {pGameManager->table->game_restart, game_restart, (void**)&ppOriginal.game_restart}, {pGameManager->table->game_setup, game_setup, (void**)&ppOriginal.game_setup}, + {pGameManager->table->get_hud_element_anchor, get_hud_element_anchor, (void**)&ppOriginal.get_hud_element_anchor}, + {pGameManager->table->get_hud_element_transform, get_hud_element_transform, (void**)&ppOriginal.get_hud_element_transform}, + {pGameManager->table->transform_hud_color, transform_hud_color, (void**)&ppOriginal.transform_hud_color}, }); } diff --git a/src/mcc/CGameManager.h b/src/mcc/CGameManager.h index 43406596..a51a03b6 100644 --- a/src/mcc/CGameManager.h +++ b/src/mcc/CGameManager.h @@ -7,6 +7,8 @@ #include "CGameEngine.h" +#include + struct CGameManager { public: struct Profile_t { @@ -49,6 +51,11 @@ static bool __fastcall get_key_state(CGameManager* self, DWORD index, input_data_t* p_input); static CGamepadMapping* __fastcall retrive_gamepad_mapping(CGameManager* self, __int64 xid); + // CGameManagerHud.cpp + static bool __fastcall get_hud_element_anchor(CGameManager* self, int element, int* anchor); + static bool __fastcall get_hud_element_transform(CGameManager* self, int element, float* dx, float* dy, float* scale); + static unsigned __fastcall transform_hud_color(CGameManager* self, int user, unsigned argb); + static void __fastcall set_state(CGameManager* self, eState state); static void* __fastcall game_restart(CGameManager* self, int type, const char* reason); static char __fastcall game_setup(CGameManager* self, void* a2); @@ -93,7 +100,15 @@ // 0x2C0i64 get_xbox_user_id bool (__fastcall* get_xbox_user_id)(CGameManager* self, __int64* pId, wchar_t* pName, int size, int index); - char pad5[0xD8]; + char pad5[0x30]; + + // 0x2F8..0x308: the games ask MCC for an override of each HUD element before placing it, and + // Halo 3, ODST and Reach pass every HUD colour, with the user it's drawn for, through +0x308. + bool (__fastcall* get_hud_element_anchor)(CGameManager* self, int element, int* anchor); + bool (__fastcall* get_hud_element_transform)(CGameManager* self, int element, float* dx, float* dy, float* scale); + unsigned (__fastcall* transform_hud_color)(CGameManager* self, int user, unsigned argb); + + char pad6[0x90]; // 0x3A0i64 retrieve gamepad mapping CGamepadMapping* (__fastcall* retrive_gamepad_mapping)(CGameManager* self, __int64 xid); @@ -105,5 +120,10 @@ Microsoft::Xbox::Telemetry::CELL* cell; }; +static_assert(offsetof(CGameManager::FunctionTable, get_hud_element_anchor) == 0x2F8); +static_assert(offsetof(CGameManager::FunctionTable, get_hud_element_transform) == 0x300); +static_assert(offsetof(CGameManager::FunctionTable, transform_hud_color) == 0x308); +static_assert(offsetof(CGameManager::FunctionTable, retrive_gamepad_mapping) == 0x3A0); + extern CGameManager* pGameManager; inline CGameManager* GameManager() { return pGameManager; } diff --git a/src/mcc/CGameManagerHud.cpp b/src/mcc/CGameManagerHud.cpp new file mode 100644 index 00000000..8af5da14 --- /dev/null +++ b/src/mcc/CGameManagerHud.cpp @@ -0,0 +1,33 @@ +#include "CGameManager.h" + +#include "mcc/hud/Hud.h" + +#include + +// The games call these host methods from their HUD drawing (MCC's own versions back a feature-flagged HUD editor +// and the colour-blind filter). MCC's answer is kept and the drawing player's HUD settings are added on top - see +// mcc/hud/Hud.h. With a player's settings at their defaults the game gets MCC's answer as it was. + +bool CGameManager::get_hud_element_transform(CGameManager* self, int element, float* dx, float* dy, float* scale) { + if (ppOriginal.get_hud_element_transform(self, element, dx, dy, scale)) { + MCC::Hud::Transform(element, dx, dy, scale, _ReturnAddress()); + return true; + } + // MCC has none: ours alone, written only when there is one + float x = 0.0f, y = 0.0f, s = 1.0f; + if (!MCC::Hud::Transform(element, &x, &y, &s, _ReturnAddress())) return false; + *dx = x; + *dy = y; + *scale = s; + return true; +} + +// Only asked after get_hud_element_transform answered true. +bool CGameManager::get_hud_element_anchor(CGameManager* self, int element, int* anchor) { + if (ppOriginal.get_hud_element_anchor(self, element, anchor)) return true; + return MCC::Hud::Anchor(element, anchor); +} + +unsigned CGameManager::transform_hud_color(CGameManager* self, int user, unsigned argb) { + return MCC::Hud::Color(user, ppOriginal.transform_hud_color(self, user, argb)); +} diff --git a/src/mcc/hud/Hud.cpp b/src/mcc/hud/Hud.cpp new file mode 100644 index 00000000..d27c3167 --- /dev/null +++ b/src/mcc/hud/Hud.cpp @@ -0,0 +1,241 @@ +#include "Hud.h" + +#include "common.h" + +#include "mcc/CGameGlobal.h" +#include "mcc/module/Module.h" +#include "mcc/splitscreen/LeftRight.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +// Halo CE's placement hook (module/entry/halo1/hud.cpp) +namespace Halo1::Entry::Hud { const AlphaRing::Feature& Hooks(); } + +namespace MCC::Hud { + static PlayerHud s_players[kPlayers]; + + PlayerHud& Player(int player) { return s_players[std::clamp(player, 0, kPlayers - 1)]; } + + // --- the games ----------------------------------------------------------------------------- + + // How a game's host offsets are measured. + enum class Units { + Canvas, // the HUD's virtual canvas (Halo 3, ODST, Reach): size = float width, height + Pixels, // screen pixels / unit scale (Halo 2): size = int16 view rect {t, l, b, r} + None, // offsets come from elsewhere (Halo CE: OffsetCE) + }; + + // What each game's answers read. In an MCC build without one of them, that game's HUD is left as it is. Halo CE's + // also need its placement hook, which moves CE's elements (OffsetCE), and Reach's the return address that tells + // its widgets' motion-sensor ask apart (without it the radar would move twice). + static AlphaRing::Feature s_halo1{"Halo CE per-player HUD", {OFFSET_HALO1_PV_HUD_DRAWING_PLAYER}}; + const bool s_halo1_hook = (s_halo1.Requires(Halo1::Entry::Hud::Hooks()), true); + static AlphaRing::Feature s_halo2{"Halo 2 per-player HUD", {OFFSET_HALO2_PV_HUD_DRAWING_PLAYER, + OFFSET_HALO2_PV_HUD_VIEW_BOUNDS, OFFSET_HALO2_PV_HUD_UNIT_SCALE}}; + static AlphaRing::Feature s_halo3{"Halo 3 per-player HUD", {OFFSET_HALO3_PV_HUD_DRAWING_PLAYER, + OFFSET_HALO3_PV_HUD_CANVAS}}; + static AlphaRing::Feature s_halo3odst{"ODST per-player HUD", {OFFSET_HALO3ODST_PV_HUD_DRAWING_PLAYER, + OFFSET_HALO3ODST_PV_HUD_CANVAS}}; + static AlphaRing::Feature s_haloreach{"Reach per-player HUD", {OFFSET_HALOREACH_DAT_CURRENT_HUD_PLAYER, + OFFSET_HALOREACH_PV_HUD_CANVAS, + OFFSET_HALOREACH_V_HUD_WIDGET_TRANSFORM_RETURN}}; + + // Per game: where it keeps the player whose HUD is being drawn, how MCC's element ids map to + // ours (1 motion sensor, 2-5 grenade kinds, 6 shield/health, 7 weapon, 9 crosshair, + // 11 equipment, 12 messages; Halo 2 has no separate shield element - its shield sits with + // the motion tracker), the units of its host offsets, and for the HUD area presets the shape + // of the box the game lays its HUD out in (0: the whole view; Halo CE: a centered 4:3 box) + // and which side of it each of our elements sits on (-1 left, 1 right, 0 centered). + struct Game { + int id; + const AlphaRing::Feature* offsets; // every offset below + const AlphaRing::Offset* drawing_user; + bool user_is_short; + const signed char* elements; // [16], by MCC element id + Units units; + const AlphaRing::Offset *size, *unit_scale; // or none + float area; + signed char sides[kElementCount]; // motion sensor, shield, weapon, grenades, crosshair, equipment, messages + bool (*box_is_area)(__int64 module) = nullptr; // whether the HUD box really is `area` right now + const AlphaRing::Offset* widget_motion_sensor = nullptr; // a widget asking for the motion sensor the view moved + }; + + // Halo 2 lays its HUD out in the whole view unless the profiles' "HUD anchor: Centered" is on + // and our fix for it (the "HUD at screen edges" patch) has been switched off. In a build where + // that can't be told, the area presets leave Halo 2's HUD alone. + static bool Halo2HudInView(__int64 module) { + if (!AlphaRing::Found({OFFSET_HALO2_PV_HUD_ASPECT_LOCK, OFFSET_HALO2_PF_HUD_ASPECT_LOCK})) return false; + return !*(const bool*)(module + OFFSET_HALO2_PV_HUD_ASPECT_LOCK) || + *(const unsigned char*)(module + OFFSET_HALO2_PF_HUD_ASPECT_LOCK) == 0xEB; + } + + static constexpr signed char kHalo1Elements[16] = { + -1, MotionSensor, Grenades, -1, -1, -1, Shield, Weapon, -1, Crosshair, -1, -1, Messages, -1, -1, -1}; + static constexpr signed char kHalo2Elements[16] = { + -1, MotionSensor, Grenades, -1, -1, -1, -1, Weapon, -1, Crosshair, -1, -1, Messages, -1, -1, -1}; + static constexpr signed char kGen3Elements[16] = { + -1, MotionSensor, Grenades, Grenades, Grenades, Grenades, Shield, Weapon, -1, Crosshair, -1, Equipment, -1, -1, -1, -1}; + + static constexpr Game kGames[] = { + {CGameGlobal::Halo1, &s_halo1, &OFFSET_HALO1_PV_HUD_DRAWING_PLAYER, true, kHalo1Elements, Units::None, nullptr, + nullptr, 4.0f / 3.0f, {-1, 1, -1, -1, 0, 0, -1}}, + {CGameGlobal::Halo2, &s_halo2, &OFFSET_HALO2_PV_HUD_DRAWING_PLAYER, false, kHalo2Elements, Units::Pixels, + &OFFSET_HALO2_PV_HUD_VIEW_BOUNDS, &OFFSET_HALO2_PV_HUD_UNIT_SCALE, 0.0f, {-1, 0, 1, -1, 0, 0, -1}, Halo2HudInView}, + {CGameGlobal::Halo3, &s_halo3, &OFFSET_HALO3_PV_HUD_DRAWING_PLAYER, false, kGen3Elements, Units::Canvas, + &OFFSET_HALO3_PV_HUD_CANVAS, nullptr, 0.0f, {-1, 0, 1, -1, 0, -1, 0}}, + {CGameGlobal::Halo3ODST, &s_halo3odst, &OFFSET_HALO3ODST_PV_HUD_DRAWING_PLAYER, false, kGen3Elements, + Units::Canvas, &OFFSET_HALO3ODST_PV_HUD_CANVAS, nullptr, 0.0f, {-1, -1, 1, 1, 0, 1, 0}}, + {CGameGlobal::HaloReach, &s_haloreach, &OFFSET_HALOREACH_DAT_CURRENT_HUD_PLAYER, false, kGen3Elements, + Units::Canvas, &OFFSET_HALOREACH_PV_HUD_CANVAS, nullptr, 0.0f, {-1, 0, 1, -1, 0, -1, 0}, nullptr, + &OFFSET_HALOREACH_V_HUD_WIDGET_TRANSFORM_RETURN}, + }; + static_assert(kGames[0].id == CGameGlobal::Halo1); // OffsetCE's + + static const Game* CurrentGame(__int64& module) { + auto p_global = GameGlobal(); + if (p_global == nullptr) return nullptr; + for (auto& game : kGames) { + if (game.id != p_global->current_game) continue; + module = MCC::Module::GetSubModule(game.id)->info().hModule; + if (module == 0) return nullptr; + if (auto missing = game.offsets->Missing()) { // an MCC build without it (src/offsets) + static bool logged[std::size(kGames)]; + if (!logged[&game - kGames]) { + logged[&game - kGames] = true; + LOG_WARNING("[Offsets] {} stays off: {} isn't in this build", game.offsets->Name(), missing->name); + } + return nullptr; + } + return &game; + } + return nullptr; + } + + static int ElementOf(const Game& game, int game_element) { + return game_element >= 0 && game_element < 16 ? game.elements[game_element] : -1; + } + + // What `player`'s settings do to one element of `game` in a view `aspect` wide per unit of + // height (0: no area presets); false when nothing. + static bool Effective(const Game& game, int player, int game_element, float aspect, float* x, float* y, float* scale) { + int element = ElementOf(game, game_element); + if (player < 0 || player >= kPlayers || element < 0) return false; + auto& settings = s_players[player]; + auto& layout = settings.elements[element]; + *x = layout.x; + *y = layout.y; + *scale = layout.hidden ? 0.0f : layout.scale * settings.scale; + // the area preset moves the sides of the game's HUD box to those of a centered box of that + // shape (no wider than the view) + if (settings.area > 0 && aspect > 0.0f) { + float from = game.area > 0.0f ? std::min(game.area, aspect) : aspect; + *x += game.sides[element] * 0.5f * (std::min(kAreas[settings.area], aspect) - from) / aspect; + } + return *x != 0.0f || *y != 0.0f || *scale != 1.0f; + } + + bool Transform(int game_element, float* dx, float* dy, float* scale, const void* caller) { + __int64 module; + auto game = CurrentGame(module); + if (game == nullptr) return false; + if (game->widget_motion_sensor && caller == (const void*)(module + *game->widget_motion_sensor) && + ElementOf(*game, game_element) == MotionSensor) + return false; + + // the size of the drawing player's view: the HUD's virtual canvas, or pixels (Halo 2); + // Halo CE takes only sizes from here (its offsets: OffsetCE) + float width = 0.0f, height = 1.0f; + if (game->units == Units::Canvas) { + auto canvas = (const float*)(module + *game->size); // width, height + width = canvas[0]; + height = canvas[1]; + } else if (game->units == Units::Pixels) { + auto& rect = *(const Splitscreen::LeftRight::Rect*)(module + *game->size); + width = rect.right - rect.left; + height = rect.bottom - rect.top; + } + + auto user_at = module + *game->drawing_user; + int user = game->user_is_short ? *(short*)user_at : *(int*)user_at; + float aspect = height > 0.0f && (!game->box_is_area || game->box_is_area(module)) ? width / height : 0.0f; + float x, y, s; + if (!Effective(*game, user, game_element, aspect, &x, &y, &s)) return false; + *scale *= s; + if (s == 0.0f || game->units == Units::None || height <= 0.0f) return true; + if (game->units == Units::Pixels) { + // Halo 2 moves an element by offset x unit scale x its final scale pixels + float unit = *(const float*)(module + *game->unit_scale) * *scale; + if (unit <= 0.0f) return true; + width /= unit; + height /= unit; + } + *dx += x * width; + *dy -= y * height; // our y points up, the screen's down + return true; + } + + bool Anchor(int game_element, int* anchor) { + float dx = 0.0f, dy = 0.0f, scale = 1.0f; + if (!Transform(game_element, &dx, &dy, &scale)) return false; + *anchor = 1; // "unchanged": our offsets are relative to where the element already is + return true; + } + + bool OffsetCE(int player, int game_element, float view_width, float view_height, float* dx, float* dy) { + float x, y, s; + if (!s_halo1.Available() || view_height <= 0.0f || // with CE's other settings only + !Effective(kGames[0], player, game_element, view_width / view_height, &x, &y, &s) || + (x == 0.0f && y == 0.0f)) + return false; + *dx = x * view_width; + *dy = -y * view_height; + return true; + } + + // --- colours --------------------------------------------------------------------------------- + + static float Wrap(float degrees) { return degrees - 360.0f * std::floor(degrees / 360.0f); } + + // Moves a colour's hue toward `hue`, keeping its brightness, saturation and alpha. Greys and + // whites stay as they are, and so do strong reds: the HUD uses them for enemies and danger. + static unsigned Recolor(unsigned argb, float hue, float strength) { + float r = ((argb >> 16) & 0xFF) / 255.0f, g = ((argb >> 8) & 0xFF) / 255.0f, b = (argb & 0xFF) / 255.0f; + float max = std::max({r, g, b}), min = std::min({r, g, b}), delta = max - min; + if (max <= 0.0f || delta / max < 0.15f) return argb; + + float h = max == r ? 60.0f * std::fmod((g - b) / delta, 6.0f) : max == g ? 60.0f * ((b - r) / delta + 2.0f) + : 60.0f * ((r - g) / delta + 4.0f); + h = Wrap(h); + if ((h < 18.0f || h > 342.0f) && delta / max > 0.45f) return argb; + + float shift = Wrap(hue - h + 180.0f) - 180.0f; // shortest way around + h = Wrap(h + shift * strength); + + float s = delta / max, v = max, c = v * s, x = c * (1.0f - std::fabs(std::fmod(h / 60.0f, 2.0f) - 1.0f)), m = v - c; + float rgb[3]; + switch ((int)(h / 60.0f) % 6) { + case 0: rgb[0] = c; rgb[1] = x; rgb[2] = 0; break; + case 1: rgb[0] = x; rgb[1] = c; rgb[2] = 0; break; + case 2: rgb[0] = 0; rgb[1] = c; rgb[2] = x; break; + case 3: rgb[0] = 0; rgb[1] = x; rgb[2] = c; break; + case 4: rgb[0] = x; rgb[1] = 0; rgb[2] = c; break; + default: rgb[0] = c; rgb[1] = 0; rgb[2] = x; break; + } + auto byte = [](float f) { return (unsigned)std::lround(std::clamp(f, 0.0f, 1.0f) * 255.0f); }; + return (argb & 0xFF000000u) | byte(rgb[0] + m) << 16 | byte(rgb[1] + m) << 8 | byte(rgb[2] + m); + } + + unsigned Color(int user, unsigned argb) { + if (user < 0 || user >= kPlayers) return argb; + auto& player = s_players[user]; + return player.recolor ? Recolor(argb, player.hue, player.strength) : argb; + } +} diff --git a/src/mcc/hud/Hud.h b/src/mcc/hud/Hud.h new file mode 100644 index 00000000..2fede8d7 --- /dev/null +++ b/src/mcc/hud/Hud.h @@ -0,0 +1,52 @@ +#pragma once + +// Per-player HUD customization: move, scale or hide HUD elements and recolour the HUD, separately +// for each local player. +// +// Halo CE, 2, 3, ODST and Reach ask MCC's host (CGameManager) for a per-element override right before +// placing each HUD element (see CGameManagerHud.cpp); Halo 3, ODST and Reach also pass every HUD colour, +// with the drawing player, through the host. Answering those calls for the player being drawn is +// the whole trick: the games apply the override to that element and put it back after drawing. +// Halo CE applies host offsets wrongly (both to X), so it gets its offsets from a placement hook +// instead (module/entry/halo1/hud.cpp). +// +// The settings are kept in memory for the session; nothing is saved yet. +namespace MCC::Hud { + enum Element : int { MotionSensor, Shield, Weapon, Grenades, Crosshair, Equipment, Messages, kElementCount }; + + struct ElementLayout { + float x = 0.0f, y = 0.0f; // offset, as a fraction of the HUD canvas width/height + float scale = 1.0f; + bool hidden = false; + }; + + // Screen shapes (width / height) a player's HUD can be laid out in, centered in their view: + // the game's own layout, the view's full width (its edges), or a box of that shape. + constexpr float kFullWidth = 100.0f; + constexpr float kAreas[] = {0.0f, kFullWidth, 21.0f / 9.0f, 16.0f / 9.0f, 4.0f / 3.0f}; + constexpr int kAreaCount = sizeof(kAreas) / sizeof(*kAreas); + + struct PlayerHud { + float scale = 1.0f; // every element + int area = 0; // index in kAreas + ElementLayout elements[kElementCount]; + bool recolor = false; + float hue = 200.0f; // degrees + float strength = 1.0f; // 0 = game colours, 1 = fully the chosen hue + }; + + constexpr int kPlayers = 4; + + // A player's settings: read by the games' HUD drawing, edited by the HUD window, and what a + // profile would save and load. A default PlayerHud changes nothing. + PlayerHud& Player(int player); + + // Host callbacks (CGameManagerHud.cpp): true when `element` of the player whose HUD is being + // drawn has an override, composed onto MCC's own values. `caller`: the game's return address. + bool Transform(int game_element, float* dx, float* dy, float* scale, const void* caller = nullptr); + bool Anchor(int game_element, int* anchor); + unsigned Color(int user, unsigned argb); + + // Halo CE: pixels to move `element` of `player`'s HUD within a view of the given size. + bool OffsetCE(int player, int game_element, float view_width, float view_height, float* dx, float* dy); +} diff --git a/src/mcc/module/entry/halo1/hud.cpp b/src/mcc/module/entry/halo1/hud.cpp new file mode 100644 index 00000000..db4ac58d --- /dev/null +++ b/src/mcc/module/entry/halo1/hud.cpp @@ -0,0 +1,34 @@ +#include "halo1.h" + +#include "mcc/hud/Hud.h" +#include "mcc/splitscreen/LeftRight.h" + +#include + +// Per-player HUD element offsets for Halo CE (mcc/hud/Hud.h). MCC's own host offsets are added +// to X only in CE, so offsets are applied here instead, to every placed HUD point. +namespace Halo1::Entry::Hud { + // hud_calculate_point(local player, placement, element header, unused, use scale override, + // scale override, out point (int16 x, y relative to the viewport), MCC element id). The scale + // override is a float on the stack, so the original is called through this exact type. + using calculate_point_t = __int64(__fastcall*)(short, void*, void*, void*, bool, float, short*, int); + + EntryFeature("Halo CE per-player HUD", OFFSET_HALO1_PV_HUD_VIEWPORT_BOUNDS); + // CE's settings require it (mcc/hud/Hud.cpp): without this hook none of them apply. + const ::AlphaRing::Feature& Hooks() { return *entry_feature; } + + Halo1Entry(entry, OFFSET_HALO1_PF_HUD_CALCULATE_POINT, __int64, detour, short player, void* placement, void* header, + void* unused, bool use_scale, float scale, short* out, int element) { + auto result = ((calculate_point_t)entry.m_pOriginal)(player, placement, header, unused, use_scale, scale, out, element); + + auto& viewport = *(const MCC::Splitscreen::LeftRight::Rect*)(entry.m_target - entry.m_offset + + OFFSET_HALO1_PV_HUD_VIEWPORT_BOUNDS); + float dx, dy; + if (out && MCC::Hud::OffsetCE(player, element, viewport.right - viewport.left, viewport.bottom - viewport.top, + &dx, &dy)) { + out[0] = (short)(out[0] + std::lround(dx)); + out[1] = (short)(out[1] + std::lround(dy)); + } + return result; + } +} From 315ef914cb611f5dcf16b8627655e34a8d91c378 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 20:08:44 -0400 Subject: [PATCH 4/9] feat(hud): the HUD window A HUD item in the overlay's menu bar, after Splitscreen, opens a window with a tab per player: the whole HUD's size, its area, a recolour (hue and strength), each element's left/right, down/up, size and Hide, and Reset / Copy to all players. MCC::Hud::ImGuiContext draws it, as Splitscreen and Network draw theirs. Edits apply at once and last until MCC closes. Profile saving is off until the profiles are reworked, so the window writes no file, not even its place in imgui.ini (NoSavedSettings). Sliders clamp typed-in values to their ranges. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/hud/Hud.cpp | 118 ++++++++++++++++++++++ src/mcc/hud/Hud.h | 3 + src/render/imgui/game/mcc/CMCCContext.cpp | 3 + 3 files changed, 124 insertions(+) diff --git a/src/mcc/hud/Hud.cpp b/src/mcc/hud/Hud.cpp index d27c3167..8c15d4ec 100644 --- a/src/mcc/hud/Hud.cpp +++ b/src/mcc/hud/Hud.cpp @@ -12,8 +12,11 @@ #include #include +#include "imgui.h" + #include #include +#include #include // Halo CE's placement hook (module/entry/halo1/hud.cpp) @@ -238,4 +241,119 @@ namespace MCC::Hud { auto& player = s_players[user]; return player.recolor ? Recolor(argb, player.hue, player.strength) : argb; } + + // --- the HUD window --------------------------------------------------------------------------- + + static const char* kElementNames[kElementCount] = {"Motion tracker", "Shield / health", "Weapon / ammo", + "Grenades", "Crosshair", "Equipment", "Messages"}; + + static const char* const kAreaNames[kAreaCount] = {"Game default", "Screen edges", "21:9 box", "16:9 box", + "4:3 box"}; + + static void PlayerTab(int p) { + auto& player = Player(p); + constexpr ImGuiSliderFlags kClamp = ImGuiSliderFlags_AlwaysClamp; + + ImGui::SeparatorText("Size"); + ImGui::SetNextItemWidth(260); + ImGui::SliderFloat("Whole HUD", &player.scale, 0.25f, 3.0f, "%.2fx", kClamp); + + // presets by the shape of screen the player looks at, for views wider than their eyes follow + ImGui::SetNextItemWidth(260); + ImGui::Combo("HUD area", &player.area, kAreaNames, kAreaCount); + ImGui::SameLine(); + ImGui::TextDisabled("(?)"); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("Lays the HUD out in a box of this shape in the middle of the player's view: pull it\n" + "in from the far edges of an ultrawide (21:9) or multi-monitor view to a TV-shaped\n" + "(16:9) or classic (4:3) box, or spread Halo CE's HUD (always a 4:3 box) out to the\n" + "screen edges."); + + ImGui::SeparatorText("Colour (Halo 3, ODST, Reach)"); + ImGui::Checkbox("Recolour this player's HUD", &player.recolor); + ImGui::BeginDisabled(!player.recolor); + ImGui::ColorButton("##preview", ImColor::HSV(player.hue / 360.0f, 0.75f, 1.0f), ImGuiColorEditFlags_NoTooltip, + ImVec2(ImGui::GetFrameHeight() * 2, ImGui::GetFrameHeight())); + ImGui::SameLine(); + ImGui::SetNextItemWidth(260); + ImGui::SliderFloat("Hue", &player.hue, 0.0f, 360.0f, "%.0f", kClamp); + ImGui::SetNextItemWidth(260); + ImGui::SliderFloat("Strength", &player.strength, 0.0f, 1.0f, "%.2f", kClamp); + ImGui::EndDisabled(); + ImGui::TextDisabled("Whites and enemy reds keep their colour."); + + ImGui::SeparatorText("Elements"); + if (ImGui::BeginTable("elements", 5, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg)) { + ImGui::TableSetupColumn("Element"); + ImGui::TableSetupColumn("Left / right"); + ImGui::TableSetupColumn("Down / up"); + ImGui::TableSetupColumn("Size"); + ImGui::TableSetupColumn("Hide"); + ImGui::TableHeadersRow(); + for (int e = 0; e < kElementCount; ++e) { + auto& l = player.elements[e]; + ImGui::PushID(e); + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + ImGui::TextUnformatted(kElementNames[e]); + // the aim point doesn't move with the crosshair's picture, so it can only be resized or hidden + ImGui::BeginDisabled(e == Crosshair); + ImGui::TableSetColumnIndex(1); + ImGui::SetNextItemWidth(150); + ImGui::SliderFloat("##x", &l.x, -0.5f, 0.5f, "%+.2f", kClamp); + ImGui::TableSetColumnIndex(2); + ImGui::SetNextItemWidth(150); + ImGui::SliderFloat("##y", &l.y, -0.5f, 0.5f, "%+.2f", kClamp); + ImGui::EndDisabled(); + ImGui::TableSetColumnIndex(3); + ImGui::SetNextItemWidth(130); + ImGui::SliderFloat("##scale", &l.scale, 0.25f, 3.0f, "%.2fx", kClamp); + ImGui::TableSetColumnIndex(4); + ImGui::Checkbox("##hide", &l.hidden); + ImGui::PopID(); + } + ImGui::EndTable(); + } + ImGui::TextDisabled("Offsets are fractions of the player's view. Messages move in Halo CE and Halo 2, equipment"); + ImGui::TextDisabled("in Halo 3, ODST and Reach; Halo 2's shield moves with its motion tracker."); + + ImGui::Spacing(); + if (ImGui::Button("Reset this player")) player = PlayerHud(); + ImGui::SameLine(); + if (ImGui::Button("Copy to all players")) + for (auto& other : s_players) other = player; + } + + static void Window() { + ImGui::TextWrapped("Move, resize, hide or recolour each player's HUD - in Halo CE, Halo 2, Halo 3, ODST and " + "Halo Reach. Changes show up right away and last until MCC closes; they aren't saved."); + if (ImGui::BeginTabBar("players")) { + for (int p = 0; p < kPlayers; ++p) { + char label[16]; + snprintf(label, sizeof(label), "Player %d", p + 1); + if (ImGui::BeginTabItem(label)) { + PlayerTab(p); + ImGui::EndTabItem(); + } + } + ImGui::EndTabBar(); + } + } + + void ImGuiContext() { + static bool show_hud; + + if (ImGui::BeginMainMenuBar()) { + ImGui::MenuItem("HUD", nullptr, &show_hud); + ImGui::EndMainMenuBar(); + } + + if (show_hud) { + // nothing of it is saved, its place in imgui.ini included + ImGui::SetNextWindowSize(ImVec2(760, 0), ImGuiCond_FirstUseEver); + if (ImGui::Begin("HUD", &show_hud, ImGuiWindowFlags_NoSavedSettings)) + Window(); + ImGui::End(); + } + } } diff --git a/src/mcc/hud/Hud.h b/src/mcc/hud/Hud.h index 2fede8d7..e5c7f735 100644 --- a/src/mcc/hud/Hud.h +++ b/src/mcc/hud/Hud.h @@ -49,4 +49,7 @@ namespace MCC::Hud { // Halo CE: pixels to move `element` of `player`'s HUD within a view of the given size. bool OffsetCE(int player, int game_element, float view_width, float view_height, float* dx, float* dy); + + // The HUD window (overlay menu bar). + void ImGuiContext(); } diff --git a/src/render/imgui/game/mcc/CMCCContext.cpp b/src/render/imgui/game/mcc/CMCCContext.cpp index 041d43ba..057d82df 100644 --- a/src/render/imgui/game/mcc/CMCCContext.cpp +++ b/src/render/imgui/game/mcc/CMCCContext.cpp @@ -4,6 +4,7 @@ #include "mcc/network/Network.h" #include "mcc/splitscreen/Splitscreen.h" +#include "mcc/hud/Hud.h" #include "mcc/module/Module.h" static const char* tutorial_message = R"(TUTORIAL: @@ -57,6 +58,8 @@ void CMCCContext::render() { MCC::Splitscreen::ImGuiContext(); + MCC::Hud::ImGuiContext(); + MCC::Network::ImGuiContext(); if (ImGui::BeginMainMenuBar()) { From 3c873c0567f2be6ad84e412268790395440b705e Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 20:08:47 -0400 Subject: [PATCH 5/9] fix(halo4): fit the HUD to any split view shaped unlike its layout The HUD fit answered only for Left/Right halves. With the black bars removed a Top / Bottom view is 1280x360 HUD units for the two-player layout's 960x360, so its HUD kept to the left three quarters of the view, and on a screen that isn't 16:9 the split views took the whole screen's fit rather than their own. Every split view whose shape differs from its HUD layout now gets its own fit (reported by nanomohchine on my fork). A view its layout fits keeps the game's answers, as every stock view on a 16:9 screen does, so nothing changes there. The hook on the frame moves from splitscreen.cpp to hud_fit.cpp, under the fit's feature: it runs Left/Right's frame work when Left/Right's hooks are in (Splitscreen::Frame), then the fit's, so the bars-removed fit doesn't depend on Left/Right-only offsets. Left/Right still requires the fit's feature. Compute's extras stay on one axis: a view with room both ways (a Left/Right half wider than 16:9, a bars-removed view on 4:3) is centred one way only, since the world-marker projection cancels only Wide()'s extra. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/entry/halo4/halo4.h | 5 +++- src/mcc/module/entry/halo4/hud_fit.cpp | 30 ++++++++++++++-------- src/mcc/module/entry/halo4/splitscreen.cpp | 11 ++++---- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/mcc/module/entry/halo4/halo4.h b/src/mcc/module/entry/halo4/halo4.h index 446a3ded..ec10ae60 100644 --- a/src/mcc/module/entry/halo4/halo4.h +++ b/src/mcc/module/entry/halo4/halo4.h @@ -22,9 +22,12 @@ namespace Halo4::Entry { constexpr int kFullHudLayout = 0x80076, kHalfHudLayout = 0x80077, kQuarterHudLayout = 0x80078; 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 } + + namespace Splitscreen { + void Frame(__int64 module); // Left/Right's work before each frame, from hud_fit.cpp's hook (splitscreen.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 index 3dd24ff2..aaf92ea7 100644 --- a/src/mcc/module/entry/halo4/hud_fit.cpp +++ b/src/mcc/module/entry/halo4/hud_fit.cpp @@ -1,24 +1,25 @@ -// 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's HUD in a split view shaped unlike its HUD layout. With the black bars removed a two-player view is +// 1920x540 for the two-player layout's 960x360 units, and a Left/Right half is 960x1080 for the quarter +// layout's 640x360 (HUD units: pixels over min(width / 1280, height / 720) of the screen). The layout sits in +// the view's corner, so the bars-removed HUD kept to the left three quarters and the Left/Right one to the +// top half. // // 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. +// what it projects from the world (nametags, waypoints). While a split view's HUD is updated or drawn, the +// helpers answer for that view and its layout instead (a view its layout fits, as every stock one on a 16:9 +// screen, keeps 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, @@ -40,8 +41,6 @@ namespace Halo4::Entry::HudFit { 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); @@ -55,6 +54,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); + // One extra, Wide()'s: the world-marker projection (0x3F2783-0x3F27C5) cancels only that one, so a view with + // room both ways (a Left/Right half wider than 16:9, a bars-removed view on 4:3) is centred one way only. 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; @@ -62,7 +63,6 @@ namespace Halo4::Entry::HudFit { 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); @@ -72,6 +72,14 @@ namespace Halo4::Entry::HudFit { } const bool s_reset = (Halo4SplitscreenEntrySet()->on_remove([] { s_ever_fit = false; }), true); + // Before each frame is drawn: Left/Right's work (splitscreen.cpp, when its hooks are in), then each user's fit. + Halo4SplitscreenEntry(entry_frame, OFFSET_HALO4_PF_RENDER, void, frame) { + __int64 module = entry_frame.m_target - entry_frame.m_offset; + Splitscreen::Frame(module); + Refresh(module); + ((frame_t)entry_frame.m_pOriginal)(); + } + // 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; diff --git a/src/mcc/module/entry/halo4/splitscreen.cpp b/src/mcc/module/entry/halo4/splitscreen.cpp index dc04f856..9ec40b69 100644 --- a/src/mcc/module/entry/halo4/splitscreen.cpp +++ b/src/mcc/module/entry/halo4/splitscreen.cpp @@ -13,8 +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. + // A half's HUD only fits it with hud_fit.cpp's hooks (without them it keeps to the half's top half), and Frame + // below runs from one of them: 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). @@ -71,12 +72,10 @@ namespace Halo4::Entry::Splitscreen { s_viewmodel_divide = divide + 3; } - Halo4SplitscreenEntry(entry_render, OFFSET_HALO4_PF_RENDER, void, render) { - __int64 module = entry_render.m_target - entry_render.m_offset; + void Frame(__int64 module) { + if (!entry_feature->Available()) return; // only with the hooks above and below LeftRight::Frame(kGame, module, s_state); - HudFit::Refresh(module); ViewmodelAspect(module, LeftRight::Active(LeftRight::Players(kGame, module))); - ((render_t)entry_render.m_pOriginal)(); } Halo4SplitscreenEntry(entry_bars, OFFSET_HALO4_PF_DRAW_SPLITSCREEN_BARS, void, draw_bars) { From c6f40c128f941e0f56889111632f3c1e35cd312a Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 20:08:54 -0400 Subject: [PATCH 6/9] docs: the per-player HUD and Halo 2's centred HUD frame The host's HUD callbacks, each game's drawing-player global and offset units, Reach's second motion-sensor ask and Halo 2's "HUD anchor: Centered" inset, in docs/REVERSE_ENGINEERING.md. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- docs/REVERSE_ENGINEERING.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/REVERSE_ENGINEERING.md b/docs/REVERSE_ENGINEERING.md index 71bcebe4..4d1f6b95 100644 --- a/docs/REVERSE_ENGINEERING.md +++ b/docs/REVERSE_ENGINEERING.md @@ -336,6 +336,21 @@ Multipliers: high `3.0` (light-count group `10.0`), mid `1.0`, low `0.5` (water **Not done:** a forced-2P tier as a middle setting for 3P/4P (deliberately deferred — same 5 bytes, would need mutual exclusion with the 1P patch). Open: a per-game Performance-preset capture (low/mid tier values are currently derived, not measured); frame-cost measurement; portability to other Halo titles. +## Per-player HUD (Halo CE, 2, 3, ODST, Reach) + +**Known — mechanism.** MCC's host object (`CGameManager`) has three HUD methods the games call while drawing: `+0x2F8` `get_hud_element_anchor(element, int* anchor)`, `+0x300` `get_hud_element_transform(element, float* dx, float* dy, float* scale)` and `+0x308` `transform_hud_color(user, argb)`; MCC's own versions back a feature-flagged HUD editor and the colour-blind filter. Halo CE, 2, 3, ODST and Reach ask for a transform right before placing each HUD element (MCC element ids: 1 motion sensor, 2-5 grenades, 6 shield/health, 7 weapon, 9 crosshair, 11 equipment, 12 messages) and keep the player being drawn in a global; Halo 3, ODST and Reach also pass every HUD colour, with its user, through `+0x308`. `src/mcc/hud` answers for the drawing player, on top of MCC's answer. + +| Game | Drawing player | Offset units | +| --- | --- | --- | +| Halo CE | `0x29AF2B8` (int16) | host offsets go to x only, so offsets are added by a hook on `hud_calculate_point` (`0xB56A58`) to each placed point, in the view being drawn (`0x29AF2F0`); scale and hiding still go through the host | +| Halo 2 | `0x165C398` | offset × unit scale (`0xE14F28`) × the element's scale = pixels, in the view's bounds (`0x165C298`, int16 t, l, b, r) | +| Halo 3 | `0xAD317C` | the HUD's virtual canvas (`0xAD3148`, float width, height) | +| ODST | `0xB1AA04` | canvas `0xB1A9D8` | +| Reach | `0xD1F71C` | canvas `0xD1F6F0` | + +- **Reach asks for the motion sensor twice.** `UpdatePlayerHudView` (`0x2D94BC`) asks once per view (call at `0x2D96B7`) and bakes the answer into the radar centre the dish and blips draw from (`0xD1F6FC`...); the per-widget lookup `0x2D93A4` (widget anchor string_id → element: `0x80630` motion sensor → 1, `0x80631` → 2 grenades, `0x80632` → 6 shield, `0x80633` → 7 weapon, `0x80634` → 9 crosshair, `0x80635` → 11 equipment) asks again, returning to `0x2D9443`. That second ask is left to MCC, or a dish widget would get its offset and scale twice. +- **Halo 2 and "HUD anchor: Centered"** (the profiles' `LockMaxAspectRatio`, a global at `0x197EE40`, the last loaded profile's). On a screen wider than 16:9, `0x954DD0` insets the whole-screen HUD frame to a centred 16:9 box and `0x7E0A40` splits that box among the players, so every split-screen HUD bunches toward the middle of the screen and the crosshairs leave their views' centres. The embedded patch "HUD at screen edges" (`0x954DF2` `74` → `EB`) skips the inset - MCC's "HUD anchor: Edge" - with any number of players. Halo 3's `chud_draw_begin` (`0x2ED0D4`) insets each player's own view instead, so it doesn't bunch. + ## Other durable findings ### `CPatch` backup-capture idempotency (generic, not Reach-specific) From cd4d3885c112ceb8340f1e2179fda15e08886fad Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 21:22:17 -0400 Subject: [PATCH 7/9] fix(halo2): "HUD at screen edges" off by default On a screen wider than 16:9 with MCC's "HUD anchor: Centered", the patch puts Halo 2's HUD at the view's edges with one player too, overriding that setting, so with it on by default a single player's ultrawide HUD didn't match an unmodified game. It's now off by default: turn it on in Dev Tools -> halo2 for split screen on an ultrawide or multi-monitor screen, where "Centered" bunches every player's HUD toward the middle. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- docs/REVERSE_ENGINEERING.md | 2 +- src/mcc/module/CModule.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/REVERSE_ENGINEERING.md b/docs/REVERSE_ENGINEERING.md index 4d1f6b95..ebbb8de6 100644 --- a/docs/REVERSE_ENGINEERING.md +++ b/docs/REVERSE_ENGINEERING.md @@ -349,7 +349,7 @@ Multipliers: high `3.0` (light-count group `10.0`), mid `1.0`, low `0.5` (water | Reach | `0xD1F71C` | canvas `0xD1F6F0` | - **Reach asks for the motion sensor twice.** `UpdatePlayerHudView` (`0x2D94BC`) asks once per view (call at `0x2D96B7`) and bakes the answer into the radar centre the dish and blips draw from (`0xD1F6FC`...); the per-widget lookup `0x2D93A4` (widget anchor string_id → element: `0x80630` motion sensor → 1, `0x80631` → 2 grenades, `0x80632` → 6 shield, `0x80633` → 7 weapon, `0x80634` → 9 crosshair, `0x80635` → 11 equipment) asks again, returning to `0x2D9443`. That second ask is left to MCC, or a dish widget would get its offset and scale twice. -- **Halo 2 and "HUD anchor: Centered"** (the profiles' `LockMaxAspectRatio`, a global at `0x197EE40`, the last loaded profile's). On a screen wider than 16:9, `0x954DD0` insets the whole-screen HUD frame to a centred 16:9 box and `0x7E0A40` splits that box among the players, so every split-screen HUD bunches toward the middle of the screen and the crosshairs leave their views' centres. The embedded patch "HUD at screen edges" (`0x954DF2` `74` → `EB`) skips the inset - MCC's "HUD anchor: Edge" - with any number of players. Halo 3's `chud_draw_begin` (`0x2ED0D4`) insets each player's own view instead, so it doesn't bunch. +- **Halo 2 and "HUD anchor: Centered"** (the profiles' `LockMaxAspectRatio`, a global at `0x197EE40`, the last loaded profile's). On a screen wider than 16:9, `0x954DD0` insets the whole-screen HUD frame to a centred 16:9 box and `0x7E0A40` splits that box among the players, so every split-screen HUD bunches toward the middle of the screen and the crosshairs leave their views' centres. The embedded patch "HUD at screen edges" (`0x954DF2` `74` → `EB`, off by default) skips the inset - MCC's "HUD anchor: Edge" - with any number of players. Halo 3's `chud_draw_begin` (`0x2ED0D4`) insets each player's own view instead, so it doesn't bunch. ## Other durable findings diff --git a/src/mcc/module/CModule.cpp b/src/mcc/module/CModule.cpp index bd2f38bd..6de3ae22 100644 --- a/src/mcc/module/CModule.cpp +++ b/src/mcc/module/CModule.cpp @@ -188,9 +188,11 @@ static struct { {"splitscreen_patch4", "force making splitscreen works with more than 2 players", OFFSET_HALO2_TWO_PLAYERS_TEST_HAND_OVER, "\x83\xF8\x01\x74\x04", true, &Halo2FourPlayers}, // With MCC's default "HUD anchor: Centered", Halo 2 fits the whole HUD frame into a centred 16:9 box // on wider screens and splits that box between the players, so on ultrawide or multi-monitor - // screens every player's HUD bunches up toward the middle of the screen. Always "Edge" instead. - {"HUD at screen edges", "keep every player's HUD at the edges of their own view on screens wider than 16:9 " - "(ultrawide, several monitors) - the same as MCC's 'HUD anchor: Edge'", OFFSET_HALO2_PF_HUD_ASPECT_LOCK, "\xEB", true}, + // screens every split-screen player's HUD bunches up toward the middle of the screen. On, it's + // "Edge" whatever the profile says, with one player too, so it's off by default. + {"HUD at screen edges", "split screen on a screen wider than 16:9 (ultrawide, several monitors): keep every " + "player's HUD at the edges of their own view, not squeezed into a centred 16:9 box - MCC's " + "'HUD anchor: Edge', with one player too", OFFSET_HALO2_PF_HUD_ASPECT_LOCK, "\xEB", false}, // Save & Quit from a modded campaign with 2+ players hung on the loading screen (reported by SR388): Halo 2 // decided the game came from its own lobby and went back to it by loading its main-menu map, which MCC // doesn't have. MCC is the lobby, so quitting always goes back to it. From 4b4974993f5b05e7be6cbd9f666876cd9cadb86b Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 21:22:19 -0400 Subject: [PATCH 8/9] fix(hud): publish each player's settings whole, under a lock The HUD window edited the settings in place - fields, and whole structs on Reset and Copy to all players - while the games' HUD callbacks read them on other threads: a data race, and a callback could see half of an edit (a new position with the old size, say). The settings now sit behind an SRW lock, as SplitscreenConfigStore's writes do. A callback copies the drawing player's settings whole under the shared lock and works from that copy; the window edits a copy and publishes it whole under the exclusive lock when something changed (to every player on Copy to all players). Player(), which handed out a mutable reference, becomes Settings(n), a copy, and SetSettings(n, hud), which publishes: what a profile would load and save. The once-per-game "stays off" log flag is an atomic too. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/hud/Hud.cpp | 81 +++++++++++++++++++++++++++++---------------- src/mcc/hud/Hud.h | 8 +++-- 2 files changed, 58 insertions(+), 31 deletions(-) diff --git a/src/mcc/hud/Hud.cpp b/src/mcc/hud/Hud.cpp index 8c15d4ec..5c7377b2 100644 --- a/src/mcc/hud/Hud.cpp +++ b/src/mcc/hud/Hud.cpp @@ -15,6 +15,7 @@ #include "imgui.h" #include +#include #include #include #include @@ -23,9 +24,27 @@ namespace Halo1::Entry::Hud { const AlphaRing::Feature& Hooks(); } namespace MCC::Hud { + // The settings the games read. A player's are replaced whole under the exclusive lock and copied whole under + // the shared one, so a HUD callback on a game thread never sees half of an edit. An SRW lock rather than + // std::mutex, as in SplitscreenConfigStore: no dependence on the msvcp140 MCC loads. + static SRWLOCK s_lock = SRWLOCK_INIT; static PlayerHud s_players[kPlayers]; - PlayerHud& Player(int player) { return s_players[std::clamp(player, 0, kPlayers - 1)]; } + PlayerHud Settings(int player) { + PlayerHud settings; // the defaults for no player, which change nothing + if (player < 0 || player >= kPlayers) return settings; + AcquireSRWLockShared(&s_lock); + settings = s_players[player]; + ReleaseSRWLockShared(&s_lock); + return settings; + } + + void SetSettings(int player, const PlayerHud& settings) { + if (player < 0 || player >= kPlayers) return; + AcquireSRWLockExclusive(&s_lock); + s_players[player] = settings; + ReleaseSRWLockExclusive(&s_lock); + } // --- the games ----------------------------------------------------------------------------- @@ -110,11 +129,10 @@ namespace MCC::Hud { module = MCC::Module::GetSubModule(game.id)->info().hModule; if (module == 0) return nullptr; if (auto missing = game.offsets->Missing()) { // an MCC build without it (src/offsets) - static bool logged[std::size(kGames)]; - if (!logged[&game - kGames]) { - logged[&game - kGames] = true; + static std::atomic logged[std::size(kGames)]; // the game threads ask + auto& once = logged[&game - kGames]; + if (!once.load(std::memory_order_relaxed) && !once.exchange(true)) LOG_WARNING("[Offsets] {} stays off: {} isn't in this build", game.offsets->Name(), missing->name); - } return nullptr; } return &game; @@ -126,12 +144,12 @@ namespace MCC::Hud { return game_element >= 0 && game_element < 16 ? game.elements[game_element] : -1; } - // What `player`'s settings do to one element of `game` in a view `aspect` wide per unit of - // height (0: no area presets); false when nothing. - static bool Effective(const Game& game, int player, int game_element, float aspect, float* x, float* y, float* scale) { + // What `settings` do to one element of `game` in a view `aspect` wide per unit of height + // (0: no area presets); false when nothing. + static bool Effective(const Game& game, const PlayerHud& settings, int game_element, float aspect, float* x, + float* y, float* scale) { int element = ElementOf(game, game_element); - if (player < 0 || player >= kPlayers || element < 0) return false; - auto& settings = s_players[player]; + if (element < 0) return false; auto& layout = settings.elements[element]; *x = layout.x; *y = layout.y; @@ -170,7 +188,7 @@ namespace MCC::Hud { int user = game->user_is_short ? *(short*)user_at : *(int*)user_at; float aspect = height > 0.0f && (!game->box_is_area || game->box_is_area(module)) ? width / height : 0.0f; float x, y, s; - if (!Effective(*game, user, game_element, aspect, &x, &y, &s)) return false; + if (!Effective(*game, Settings(user), game_element, aspect, &x, &y, &s)) return false; *scale *= s; if (s == 0.0f || game->units == Units::None || height <= 0.0f) return true; if (game->units == Units::Pixels) { @@ -195,7 +213,7 @@ namespace MCC::Hud { bool OffsetCE(int player, int game_element, float view_width, float view_height, float* dx, float* dy) { float x, y, s; if (!s_halo1.Available() || view_height <= 0.0f || // with CE's other settings only - !Effective(kGames[0], player, game_element, view_width / view_height, &x, &y, &s) || + !Effective(kGames[0], Settings(player), game_element, view_width / view_height, &x, &y, &s) || (x == 0.0f && y == 0.0f)) return false; *dx = x * view_width; @@ -237,9 +255,8 @@ namespace MCC::Hud { } unsigned Color(int user, unsigned argb) { - if (user < 0 || user >= kPlayers) return argb; - auto& player = s_players[user]; - return player.recolor ? Recolor(argb, player.hue, player.strength) : argb; + auto settings = Settings(user); + return settings.recolor ? Recolor(argb, settings.hue, settings.strength) : argb; } // --- the HUD window --------------------------------------------------------------------------- @@ -250,17 +267,19 @@ namespace MCC::Hud { static const char* const kAreaNames[kAreaCount] = {"Game default", "Screen edges", "21:9 box", "16:9 box", "4:3 box"}; + // Edits a copy of the player's settings, published whole when something changed. static void PlayerTab(int p) { - auto& player = Player(p); + PlayerHud player = Settings(p); + bool changed = false; constexpr ImGuiSliderFlags kClamp = ImGuiSliderFlags_AlwaysClamp; ImGui::SeparatorText("Size"); ImGui::SetNextItemWidth(260); - ImGui::SliderFloat("Whole HUD", &player.scale, 0.25f, 3.0f, "%.2fx", kClamp); + changed |= ImGui::SliderFloat("Whole HUD", &player.scale, 0.25f, 3.0f, "%.2fx", kClamp); // presets by the shape of screen the player looks at, for views wider than their eyes follow ImGui::SetNextItemWidth(260); - ImGui::Combo("HUD area", &player.area, kAreaNames, kAreaCount); + changed |= ImGui::Combo("HUD area", &player.area, kAreaNames, kAreaCount); ImGui::SameLine(); ImGui::TextDisabled("(?)"); if (ImGui::IsItemHovered()) @@ -270,15 +289,15 @@ namespace MCC::Hud { "screen edges."); ImGui::SeparatorText("Colour (Halo 3, ODST, Reach)"); - ImGui::Checkbox("Recolour this player's HUD", &player.recolor); + changed |= ImGui::Checkbox("Recolour this player's HUD", &player.recolor); ImGui::BeginDisabled(!player.recolor); ImGui::ColorButton("##preview", ImColor::HSV(player.hue / 360.0f, 0.75f, 1.0f), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetFrameHeight() * 2, ImGui::GetFrameHeight())); ImGui::SameLine(); ImGui::SetNextItemWidth(260); - ImGui::SliderFloat("Hue", &player.hue, 0.0f, 360.0f, "%.0f", kClamp); + changed |= ImGui::SliderFloat("Hue", &player.hue, 0.0f, 360.0f, "%.0f", kClamp); ImGui::SetNextItemWidth(260); - ImGui::SliderFloat("Strength", &player.strength, 0.0f, 1.0f, "%.2f", kClamp); + changed |= ImGui::SliderFloat("Strength", &player.strength, 0.0f, 1.0f, "%.2f", kClamp); ImGui::EndDisabled(); ImGui::TextDisabled("Whites and enemy reds keep their colour."); @@ -300,16 +319,16 @@ namespace MCC::Hud { ImGui::BeginDisabled(e == Crosshair); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(150); - ImGui::SliderFloat("##x", &l.x, -0.5f, 0.5f, "%+.2f", kClamp); + changed |= ImGui::SliderFloat("##x", &l.x, -0.5f, 0.5f, "%+.2f", kClamp); ImGui::TableSetColumnIndex(2); ImGui::SetNextItemWidth(150); - ImGui::SliderFloat("##y", &l.y, -0.5f, 0.5f, "%+.2f", kClamp); + changed |= ImGui::SliderFloat("##y", &l.y, -0.5f, 0.5f, "%+.2f", kClamp); ImGui::EndDisabled(); ImGui::TableSetColumnIndex(3); ImGui::SetNextItemWidth(130); - ImGui::SliderFloat("##scale", &l.scale, 0.25f, 3.0f, "%.2fx", kClamp); + changed |= ImGui::SliderFloat("##scale", &l.scale, 0.25f, 3.0f, "%.2fx", kClamp); ImGui::TableSetColumnIndex(4); - ImGui::Checkbox("##hide", &l.hidden); + changed |= ImGui::Checkbox("##hide", &l.hidden); ImGui::PopID(); } ImGui::EndTable(); @@ -318,10 +337,16 @@ namespace MCC::Hud { ImGui::TextDisabled("in Halo 3, ODST and Reach; Halo 2's shield moves with its motion tracker."); ImGui::Spacing(); - if (ImGui::Button("Reset this player")) player = PlayerHud(); + if (ImGui::Button("Reset this player")) { + player = PlayerHud(); + changed = true; + } ImGui::SameLine(); - if (ImGui::Button("Copy to all players")) - for (auto& other : s_players) other = player; + bool copy = ImGui::Button("Copy to all players"); + + if (changed) SetSettings(p, player); + if (copy) + for (int other = 0; other < kPlayers; ++other) SetSettings(other, player); } static void Window() { diff --git a/src/mcc/hud/Hud.h b/src/mcc/hud/Hud.h index e5c7f735..0a7098eb 100644 --- a/src/mcc/hud/Hud.h +++ b/src/mcc/hud/Hud.h @@ -37,9 +37,11 @@ namespace MCC::Hud { constexpr int kPlayers = 4; - // A player's settings: read by the games' HUD drawing, edited by the HUD window, and what a - // profile would save and load. A default PlayerHud changes nothing. - PlayerHud& Player(int player); + // A player's settings, as the games' HUD drawing reads them: a copy, and a whole new set put in + // place at once (the HUD window publishes its edits so). What a profile would save and load. A + // default PlayerHud changes nothing. + PlayerHud Settings(int player); + void SetSettings(int player, const PlayerHud& settings); // Host callbacks (CGameManagerHud.cpp): true when `element` of the player whose HUD is being // drawn has an override, composed onto MCC's own values. `caller`: the game's return address. From 5747330114d5fefa2c8b982dfbc89a1423c0790a Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 21:22:46 -0400 Subject: [PATCH 9/9] fix(hud): the motion sensor gets its own view's canvas Halo 3, ODST and Reach ask MCC for the motion sensor while they set each view's HUD up, before they store that view's canvas (Halo 3 0x2ED267, then 0x2ED40C; ODST 0x3287F5, then 0x328991; Reach 0x2D96B7, then 0x2D984E): the canvas then is still the previous view's. Wherever the views differ in size - 3 players, Top / Bottom or Left/Right - the radar's offset and HUD area preset were worked out with another view's canvas. Every other element is asked for while the view's widgets are placed, after the canvas is set (Halo 3 0x2EDD80, ODST 0x3292E4, Reach 0x2D93A4). Each user's canvas is now kept from those asks (an atomic per game and user), and the motion sensor's ask gets its own view's, as of the frame before; until a view has been seen, the game's value is used as before. That is the canvas the game itself ends up with for the view, its ultrawide widening and Left/Right height included. Halo 2 reads its view bounds right after each ask, so it isn't affected. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- docs/REVERSE_ENGINEERING.md | 1 + src/mcc/hud/Hud.cpp | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/docs/REVERSE_ENGINEERING.md b/docs/REVERSE_ENGINEERING.md index ebbb8de6..450243bd 100644 --- a/docs/REVERSE_ENGINEERING.md +++ b/docs/REVERSE_ENGINEERING.md @@ -349,6 +349,7 @@ Multipliers: high `3.0` (light-count group `10.0`), mid `1.0`, low `0.5` (water | Reach | `0xD1F71C` | canvas `0xD1F6F0` | - **Reach asks for the motion sensor twice.** `UpdatePlayerHudView` (`0x2D94BC`) asks once per view (call at `0x2D96B7`) and bakes the answer into the radar centre the dish and blips draw from (`0xD1F6FC`...); the per-widget lookup `0x2D93A4` (widget anchor string_id → element: `0x80630` motion sensor → 1, `0x80631` → 2 grenades, `0x80632` → 6 shield, `0x80633` → 7 weapon, `0x80634` → 9 crosshair, `0x80635` → 11 equipment) asks again, returning to `0x2D9443`. That second ask is left to MCC, or a dish widget would get its offset and scale twice. +- **The motion sensor is asked for before its view's canvas is set.** Halo 3, ODST and Reach ask for element 1 while they set each view's HUD up, before they store that view's canvas (Halo 3 `0x2ED267`, canvas `0x2ED40C`; ODST `0x3287F5`, `0x328991`; Reach `0x2D96B7`, `0x2D984E`), so the canvas at that ask is still the previous view's - wrong wherever the views differ in size (3 players). The other elements are asked for while the view's widgets are placed (Halo 3 `0x2EDD80`, ODST `0x3292E4`, Reach `0x2D93A4`), after it. `Hud.cpp` keeps each user's canvas from those asks and gives the motion sensor's ask its own view's, as of the frame before. Halo 2 reads its view bounds right after each ask (`0x829490`), so it doesn't have this. - **Halo 2 and "HUD anchor: Centered"** (the profiles' `LockMaxAspectRatio`, a global at `0x197EE40`, the last loaded profile's). On a screen wider than 16:9, `0x954DD0` insets the whole-screen HUD frame to a centred 16:9 box and `0x7E0A40` splits that box among the players, so every split-screen HUD bunches toward the middle of the screen and the crosshairs leave their views' centres. The embedded patch "HUD at screen edges" (`0x954DF2` `74` → `EB`, off by default) skips the inset - MCC's "HUD anchor: Edge" - with any number of players. Halo 3's `chud_draw_begin` (`0x2ED0D4`) insets each player's own view instead, so it doesn't bunch. ## Other durable findings diff --git a/src/mcc/hud/Hud.cpp b/src/mcc/hud/Hud.cpp index 5c7377b2..ae0cbf9d 100644 --- a/src/mcc/hud/Hud.cpp +++ b/src/mcc/hud/Hud.cpp @@ -144,6 +144,26 @@ namespace MCC::Hud { return game_element >= 0 && game_element < 16 ? game.elements[game_element] : -1; } + // Halo 3, ODST and Reach ask for the motion sensor while they set each view's HUD up, before they store that + // view's canvas (Halo 3 0x2ED267, then 0x2ED40C; ODST 0x3287F5, then 0x328991; Reach 0x2D96B7, then 0x2D984E): + // the canvas then is still the previous view's. Every other element is asked for after, so each user's canvas + // is kept from those asks, and the motion sensor's ask gets its own view's, as of the frame before. + struct Canvas { float width, height; }; + static std::atomic s_view_canvas[std::size(kGames)][kPlayers]; // {0, 0}: not seen yet + + static void ViewCanvas(const Game& game, int user, int game_element, float* width, float* height) { + if (user < 0 || user >= kPlayers) return; + auto& kept = s_view_canvas[&game - kGames][user]; + if (ElementOf(game, game_element) != MotionSensor) { + kept.store({*width, *height}, std::memory_order_relaxed); + return; + } + Canvas canvas = kept.load(std::memory_order_relaxed); + if (canvas.width <= 0.0f) return; // first frame: the game's + *width = canvas.width; + *height = canvas.height; + } + // What `settings` do to one element of `game` in a view `aspect` wide per unit of height // (0: no area presets); false when nothing. static bool Effective(const Game& game, const PlayerHud& settings, int game_element, float aspect, float* x, @@ -171,6 +191,9 @@ namespace MCC::Hud { ElementOf(*game, game_element) == MotionSensor) return false; + auto user_at = module + *game->drawing_user; + int user = game->user_is_short ? *(short*)user_at : *(int*)user_at; + // the size of the drawing player's view: the HUD's virtual canvas, or pixels (Halo 2); // Halo CE takes only sizes from here (its offsets: OffsetCE) float width = 0.0f, height = 1.0f; @@ -178,14 +201,13 @@ namespace MCC::Hud { auto canvas = (const float*)(module + *game->size); // width, height width = canvas[0]; height = canvas[1]; + ViewCanvas(*game, user, game_element, &width, &height); } else if (game->units == Units::Pixels) { auto& rect = *(const Splitscreen::LeftRight::Rect*)(module + *game->size); width = rect.right - rect.left; height = rect.bottom - rect.top; } - auto user_at = module + *game->drawing_user; - int user = game->user_is_short ? *(short*)user_at : *(int*)user_at; float aspect = height > 0.0f && (!game->box_is_area || game->box_is_area(module)) ? width / height : 0.0f; float x, y, s; if (!Effective(*game, Settings(user), game_element, aspect, &x, &y, &s)) return false;