From 7dd7d2d0b15bf9fb18f3a1de878078b4a300c843 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 19:41:56 -0400 Subject: [PATCH 1/7] feat(offsets): Anniversary renderer addresses for Halo CE and Halo 2 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 Anniversary (Saber3D) split screen: its cameras and camera list, the split render targets' children, the frame and its composite, the classic HUD pass and each view's screen effects, and the game side of the frame - the views' hand-over, the object and first-person sync, and who is hidden in which view (56); - Halo 2's: the views' hand-over and the local player count's other "== 2" test sites, the camera list, the frame, its composite and HDR pass, the render targets and texture deletion, and the per-view visible objects, own-unit test and first-person sync (32). COVER pins down the first-person sync's slot check (cmp r15d, 1 / ja) whose limit the CE mode widens; COVER_BEFORE starts the pattern of the CE overlay rect's mid-function hook 0x32 bytes earlier, over the registers 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 | 58 ++++++++ lib/game/inc/1.3528.0.0/offset_halo2.h | 47 +++++- lib/game/inc/1.3528.0.0/patterns_halo1.inc | 164 +++++++++++++++++++++ lib/game/inc/1.3528.0.0/patterns_halo2.inc | 88 +++++++++++ tools/offsets/gen_patterns.py | 7 +- 5 files changed, 360 insertions(+), 4 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 09114586..059e5fe0 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,61 @@ 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") + +// Anniversary graphics (Saber3D) with 3-4 players (module/entry/halo1/anniversary.cpp) +DefOffset(OFFSET_HALO1_PV_LOCAL_PLAYERS, 0x2EA2D90) // players globals*, int16 local player count at +0xB4 +DefOffset(OFFSET_HALO1_PV_RENDER_WINDOWS, 0x2D9CADC) // the game's view windows, 0xAC each: int16 view, rect at +0x84 +DefOffset(OFFSET_HALO1_PV_RENDER_CAMERAS, 0x2D9BDD4) // the players' cameras, 0x2A8 each: field of view at +0x38 +DefOffset(OFFSET_HALO1_PV_WINDOW_FIELDS_OF_VIEW, 0x1B7D6E8) // float per view, from view -1 +DefOffset(OFFSET_HALO1_PF_RENDER_WINDOW_CAMERA, 0xAC450C) // void (window*, camera*) - the window's camera +DefOffset(OFFSET_HALO1_PF_SABER_HAND_OVER_VIEWS, 0x89B70) // void () - each tick: views 0 and 1 to the renderer +DefOffset(OFFSET_HALO1_PF_SABER_HAND_OVER_VIEW, 0xB29268) // void (int view) - a view's camera to the renderer's +DefOffset(OFFSET_HALO1_PV_SABER_CAMERAS, 0x2B17B90) // camera*[], int count at +8 +DefOffset(OFFSET_HALO1_PF_SABER_ADD_CAMERA, 0x4684C0) // int () +DefOffset(OFFSET_HALO1_PF_SABER_DELETE_CAMERA, 0x2B1EA0) // void (camera*) +DefOffset(OFFSET_HALO1_PF_SABER_CAMERA_SET_FOV, 0x11B020) // void (camera*, float degrees) +DefOffset(OFFSET_HALO1_PV_SABER_SPLIT, 0x2E3B821) // bool, the game's: split screen +DefOffset(OFFSET_HALO1_PF_SABER_SET_SPLIT, 0x4150F0) // void (state*) - adds or drops the second camera as the above changes +DefOffset(OFFSET_HALO1_PF_SABER_SPLIT_LAYOUT, 0x415200) // void (state*, bool split) - the cameras' viewports +DefOffset(OFFSET_HALO1_PV_SABER_SPLIT_STATE, 0x2E3CCA8) // state*, split screen at +0x41 +DefOffset(OFFSET_HALO1_PV_SABER_DEVICE, 0x2E3BDD8) // device*, settings* at +0x118: pixel aspect +0x1C, width +0x20, height +0x24 +DefOffset(OFFSET_HALO1_PV_SABER_CONTEXT, 0x2E3BDE0) // context*, vt+0x190 copies a region +DefOffset(OFFSET_HALO1_PV_SABER_RENDERER, 0x1C33E30) // renderer*, cameras changed at +0x92 +DefOffset(OFFSET_HALO1_PV_SABER_SCENE, 0x1BEA9E0) // scene*, the frame's camera list at +0xB0 +DefOffset(OFFSET_HALO1_PF_SABER_PREPARE_FRAME, 0x455170) // void (scene renderer*) +DefOffset(OFFSET_HALO1_PF_SABER_BUILD_CAMERA_LIST, 0x4547E0) // (-, list*, bool split, -) +DefOffset(OFFSET_HALO1_PF_SABER_LIST_CAMERA, 0x2EA720) // int (list*, camera*, flags, split index, 12 more) - appends a copy +DefOffset(OFFSET_HALO1_PV_SABER_ZOOMED_FOV, 0x1944B70) // float, a view below this field of view is zoomed +DefOffset(OFFSET_HALO1_PF_SABER_RENDER_FRAME, 0x455A10) +DefOffset(OFFSET_HALO1_PF_SABER_COMPOSITE, 0x45E2B0) // void (int list index) - copies the view's image to its half +DefOffset(OFFSET_HALO1_PV_SABER_VIEW_IMAGES, 0x2D62890) // texture*[2], current index at 0x1B7B11C +DefOffset(OFFSET_HALO1_PV_SABER_VIEW_IMAGE_INDEX, 0x1B7B11C) +DefOffset(OFFSET_HALO1_PV_SABER_SCREEN_IMAGE, 0x2E3D0D0) // texture*, the frame's full-screen image +DefOffset(OFFSET_HALO1_PF_SABER_TEXTURE_CREATE_CHILD, 0x1F9D20) // texture* (parent*, name, width, height, -, flags) +DefOffset(OFFSET_HALO1_PF_SABER_CLASSIC_HUD, 0x740B0) // void () - the classic HUD over the image: views 0 and 1, then view -1 +DefOffset(OFFSET_HALO1_PF_HUD_VIEW, 0xB29438) // void (int view) - the HUD's view (window, drawing player) +DefOffset(OFFSET_HALO1_PF_HUD_VIEW_DRAW, 0xBABD38) // void (int view, state*) - the view's HUD, state 0x29E07C0 +DefOffset(OFFSET_HALO1_PV_HUD_VIEW_DRAW_STATE, 0x29E07C0) +DefOffset(OFFSET_HALO1_PF_HUD_VIEW_DRAW_2, 0xB31D88) // void () - then these two +DefOffset(OFFSET_HALO1_PF_HUD_VIEW_DRAW_3, 0xAC8844) // void () - skipped while 0x2EA0218 and 0x2E3B450 are set +DefOffset(OFFSET_HALO1_PV_HUD_VIEW_DRAW_3_SKIP_1, 0x2EA0218) // int +DefOffset(OFFSET_HALO1_PV_HUD_VIEW_DRAW_3_SKIP_2, 0x2E3B450) // bool +DefOffset(OFFSET_HALO1_PF_SABER_VIEW_OVERLAY, 0x4512D0) // void (-, camera*, int split index) - a view's screen effects +DefOffset(OFFSET_HALO1_SABER_VIEW_OVERLAY_RECT, 0x4513AC) // in it, its rect is set: left r11d, top r9d, right r10d, bottom eax +DefOffset(OFFSET_HALO1_PF_SABER_SYNC, 0x89F00) // void () - each frame: the game's state to the renderer +DefOffset(OFFSET_HALO1_PF_SABER_SYNC_OBJECT, 0x7D350) // void (record*) - an object's, record {int16 index, +8 body**, +0x10 second**} +DefOffset(OFFSET_HALO1_PV_RENDER_OBJECTS, 0x29E0900) // data array*, 0x7C each: object at +0x2C +DefOffset(OFFSET_HALO1_PV_DIRECTORS, 0x2D9B960) // 0xF8 each: +0xC, update at +0x10 +DefOffset(OFFSET_HALO1_PF_FIRST_PERSON_DIRECTOR, 0xC5263C) // the first-person director's update +DefOffset(OFFSET_HALO1_PF_LOCAL_PLAYER_UNIT_FLAG, 0xAB16A4) // int (int local) - the local player's unit has flag 0x1D4 & 2 +DefOffset(OFFSET_HALO1_PF_FIRST_PERSON_PREPARE, 0xB27510) // void () - for the HUD's view, then +DefOffset(OFFSET_HALO1_PF_FIRST_PERSON_UPDATE, 0xB275B8) // void () - its first-person weapon, for the renderer while +DefOffset(OFFSET_HALO1_PV_FIRST_PERSON_FOR_RENDERER, 0x2EA32F8) // int +DefOffset(OFFSET_HALO1_PV_FIRST_PERSON_WEAPONS, 0x1B7AA88) // int[4] per view: the object whose nodes are at 0x1C384A0, 0xD00 per view +DefOffset(OFFSET_HALO1_PV_FIRST_PERSON_ARMS, 0x1B7AA98) // int[4], nodes at 0x1C350A0 +DefOffset(OFFSET_HALO1_PF_FIRST_PERSON_SYNC, 0x7AC60) // void (int object, int slot) - a view's first-person weapon or arms (the nodes of the view it's in above) to the renderer's model for (slot, object), made on first use +DefOffset(OFFSET_HALO1_FIRST_PERSON_SYNC_SLOT_LIMIT, 0x7AE64) // in it: cmp r15d, 1 / ja - a slot past 1 gets no nodes +DefOffset(OFFSET_HALO1_PV_FIRST_PERSON_MODELS, 0x2B050E8) // the renderer's first-person models: entry*, int count at +8; entry 0x20: int slot, int object, bytes +0x1C/+0x1E hidden in view 0/1 (wanted), +0x1D/+0x1F (applied) +DefOffset(OFFSET_HALO1_PF_OBJECT_HIDDEN_VIEWS, 0xAB2890) // int (int object) - views (bits 0, 1) the object is hidden in +DefOffset(OFFSET_HALO1_PF_DIRECTOR_CAMERA_MODE, 0xB14EA4) // short (int local) - 0 in first person +DefOffset(OFFSET_HALO1_PV_HIDDEN_OBJECT_CAMERA, 0x1B87A20) // bool on, int16 mode at +2 (2 hides), int object at +0x34 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..ce8f599a 100644 --- a/lib/game/inc/1.3528.0.0/offset_halo2.h +++ b/lib/game/inc/1.3528.0.0/offset_halo2.h @@ -15,8 +15,8 @@ DefOffset(OFFSET_HALO2_PF_PLAYER_VALID, 0x6A6C80)//0x6A6C30 DefOffset(OFFSET_HALO2_PF_PLAYER_COUNT1, 0x8940CA)//0x893FDA DefOffset(OFFSET_HALO2_PF_PLAYER_COUNT2, 0x894127)//0x894037 -// The views' hand-over splits the screen only for exactly two local players (cmp eax, 2 / jne); -// splitscreen_patch4 makes it any count but one (cmp eax, 1 / je) +// The views' hand-over splits the screen only for exactly two local players (cmp eax, 2 / jne, where the call to the +// local player count returns); splitscreen_patch4 makes it any count but one (cmp eax, 1 / je) DefOffset(OFFSET_HALO2_TWO_PLAYERS_TEST_HAND_OVER, 0x5153E) // In the main loop's quit handling (0x679CD0): call 0x6A6320 (did this game come from a Halo 2 lobby?), then @@ -38,3 +38,46 @@ 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 + +// Anniversary graphics (Saber3D) with 3-4 players (module/entry/halo2/anniversary.cpp) +DefOffset(OFFSET_HALO2_PF_CINEMATIC, 0x6F4A20) // bool () - one view (cinematics) +DefOffset(OFFSET_HALO2_PF_LOCAL_PLAYER_COUNT, 0x6A4380) // int () - a 12-byte leaf +// returns from its other "== 2" (split screen) tests (the views' hand-over's is OFFSET_HALO2_TWO_PLAYERS_TEST_HAND_OVER, +// above): the object sync, a screen effect, and three first-person effect callbacks +DefOffset(OFFSET_HALO2_TWO_PLAYERS_TEST_OBJECT_SYNC, 0x6A00C) +DefOffset(OFFSET_HALO2_TWO_PLAYERS_TEST_SCREEN_EFFECT, 0x6F40C) +DefOffset(OFFSET_HALO2_TWO_PLAYERS_TEST_FIRST_PERSON_1, 0x64004) +DefOffset(OFFSET_HALO2_TWO_PLAYERS_TEST_FIRST_PERSON_2, 0x64F4E) +DefOffset(OFFSET_HALO2_TWO_PLAYERS_TEST_FIRST_PERSON_3, 0x65559) +DefOffset(OFFSET_HALO2_PF_SABER_HAND_OVER_VIEW, 0x5F510) // void (int view, bool split) - observer camera(view) -> cams[view] +DefOffset(OFFSET_HALO2_PV_SABER_CAMERAS, 0x1E91210) // container*: camera*[] at +0x100, int count +0x108 +DefOffset(OFFSET_HALO2_PF_SABER_CAMERA_SET_FOV, 0xBC560) // void (camera*, float vertical degrees) - also the projection +DefOffset(OFFSET_HALO2_PV_SABER_DEVICE, 0x1E8D418) // device*, settings* at +0x118: out w +0x10, h +0x14, pixel aspect +0x1C +DefOffset(OFFSET_HALO2_PV_SABER_CONTEXT, 0x1E8D420) // context*, ID3D11DeviceContext* at +0xD58 +DefOffset(OFFSET_HALO2_PV_SABER_SCENE, 0x1A250F8) // scene*, the renderer's camera list at +0x140 +DefOffset(OFFSET_HALO2_PF_SABER_BUILD_CAMERA_LIST, 0x2DDCB0) // (renderer*, list*, bool split, -) +DefOffset(OFFSET_HALO2_PF_SABER_LIST_CAMERA, 0x1C7740) // int (list*, camera*, flags, split index, 6 more) - appends a copy +DefOffset(OFFSET_HALO2_PF_SABER_RENDER_FRAME, 0x2DEC00) // void () +DefOffset(OFFSET_HALO2_PF_SABER_COMPOSITE, 0x1D2A00) // void (texture*, bool split, int index) - a view's image to its half +DefOffset(OFFSET_HALO2_SABER_COMPOSITE_DRAW, 0x1D2C33) // in it, the quad's vertices are at rsp+0xC0 (x, y, z, -, u, v; 0x18 each) +DefOffset(OFFSET_HALO2_PF_SABER_AFTER_CAMERAS, 0x2E3F70) // void () - after the views, before the UI and HUD +DefOffset(OFFSET_HALO2_PF_SABER_HDR_PASS, 0x210BF0) // void (-, -, -, -, -, float, int hdr view, bool, ...) - a view's exposure adaptation, bloom and tonemapping +DefOffset(OFFSET_HALO2_PV_SABER_HDR_VIEWS, 0x1AB8600) // 0x4C per HDR view (4): settings, +0x3C measured luminance, +0x40 exposure, +0x44 adapted luminance, int +0x48 frames +DefOffset(OFFSET_HALO2_PV_SABER_HDR_READ_BACKS, 0x1AB8758) // texture*[4][2] - per HDR view, the luminance read back on alternate frames +// texture* (set*, name, ...9 in all) - adds a render target to a set: count at +0xC, entries at +0x10 (0x30 each: +// texture* +0, flags +8). A split target also gets "_split0" (flags 0x20000000, full width, half height - both views +// are drawn into it in turn) and, for per-view history, "_split1" (0x40000000). A texture's vtable +0xA0 is +// bool (texture*, width, height, mips, format, depth, samples, data) - no-op if unchanged, else remade; fields +// width +0x20, height +0x22, depth +0x24, format +0x26, samples +0x28 (int16), mips +0x2A (byte). +DefOffset(OFFSET_HALO2_PF_SABER_ADD_RENDER_TARGET, 0xF7750) +// void (manager*, int index) - the texture manager deletes its texture `index` (texture*[] at +0x220), children +// first, whatever the texture's reference count (+0x78); a render-target set's teardown (0xF8750) gets here +DefOffset(OFFSET_HALO2_PF_SABER_DELETE_TEXTURE, 0x1A5990) +DefOffset(OFFSET_HALO2_PF_PLAYER_VISIBLE_OBJECTS, 0x608A0) // void (int local) - the window's visible objects, as view 0's (local 0) or view 1's +DefOffset(OFFSET_HALO2_PF_OWN_UNIT_IN_FIRST_PERSON, 0x5FE80) // bool (int object, int local) - the local player's unit, in first person +DefOffset(OFFSET_HALO2_PF_FIRST_PERSON_SYNC, 0x6D0D0) // void () - players 1-2's first-person models, each hidden in the other's view +DefOffset(OFFSET_HALO2_PF_FIRST_PERSON_BUILD, 0x81BFB0) // void (int local) +DefOffset(OFFSET_HALO2_PV_FIRST_PERSON_MODELS, 0x1AB11C0) // entries*, int count at +8; 0x28 each: +8 object**, +0x1C owner, +0x20 active +DefOffset(OFFSET_HALO2_PV_MODEL_LEVELS, 0x1DC36F0) // unsigned char* detail levels, int count at +8 - the current one is the last +DefOffset(OFFSET_HALO2_PF_SABER_OBJECT_SHOW, 0x69C30) // void (object*) +DefOffset(OFFSET_HALO2_PF_SABER_OBJECT_HIDE, 0x69CA0) // void (object*) 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..e19527d5 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,168 @@ 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_PV_LOCAL_PLAYERS, 0x2ea2d90, Data, { + Rel("48 8B 05 ?? ?? ?? ?? 0F 57 C0 0F 57 C9 0F B7 88 B4 00 00 00", 0x3, 0x7, 0x0), + Rel("48 8B 05 ?? ?? ?? ?? 48 63 C9 8B 8C 88 C8 00 00 00 83 F9 FF", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PV_RENDER_WINDOWS, 0x2d9cadc, Data, { + Rel("48 8D 0D ?? ?? ?? ?? F3 0F 11 25 ?? ?? ?? ?? E8 ?? ?? ?? ?? 0F B7 87 B4 00 00 00 BE 01 00 00 00", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PV_RENDER_CAMERAS, 0x2d9bdd4, Data, { + Rel("48 0F BF C6 48 69 E8 A8 02 00 00 48 8D 05 ?? ?? ?? ?? 48 03 E8", 0xe, 0x12, 0x0), + Rel("48 0F BF C1 48 8D 0D ?? ?? ?? ?? 48 69 C0 A8 02 00 00 48 03 C1", 0x7, 0xb, 0x0)}}, + {&OFFSET_HALO1_PV_WINDOW_FIELDS_OF_VIEW, 0x1b7d6e8, Data, { + Rel("4C 8D 35 ?? ?? ?? ?? 41 C7 04 B6 00 00 A0 42 41 3B C8 75 ?? 88 53 02", 0x3, 0x7, 0x0), + Rel("F3 0F 11 05 ?? ?? ?? ?? 4C 8D 05 ?? ?? ?? ?? 66 89 2D ?? ?? D1 02 8B D6 40 88 35", 0x4, 0x8, 0x0)}}, + {&OFFSET_HALO1_PF_RENDER_WINDOW_CAMERA, 0xac450c, Code, { + At("48 8B C4 48 89 58 08 48 89 70 10 48 89 78 18 4C 89 70 20 55 48 8D 68 A1 48 81 EC 90 00 00 00 48 8B FA", 0x0), + Rel("E8 ?? ?? ?? ?? 0F B7 87 B4 00 00 00 BE 01 00 00 00 66 3B C6", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_HAND_OVER_VIEWS, 0x89b70, Code, { + At("48 89 5C 24 10 48 89 6C 24 18 48 89 74 24 20 57 48 83 EC 20 48 8B 3D ?? ?? ?? ?? 33 DB", 0x0), + Rel("E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 8B 5C 24 50 48 8B 6C 24 58 48 8B 74 24 60", 0x6, 0xa, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_HAND_OVER_VIEW, 0xb29268, Code, { + At("48 89 5C 24 08 55 48 8B EC 48 83 EC 60 80 3D ?? ?? ?? ?? 00", 0x0), + Rel("B9 01 00 00 00 66 39 88 B4 00 00 00 7E ?? E8 ?? ?? ?? ?? 48 83 C4 28", 0xf, 0x13, 0x0)}}, + {&OFFSET_HALO1_PV_SABER_CAMERAS, 0x2b17b90, Data, { + Rel("48 8B 0D ?? ?? ?? ?? 0F 1F 00 83 C0 FE 4C 63 C0 49 C1 E0 03", 0x3, 0x7, 0x0), + Rel("48 8B 05 ?? ?? ?? ?? 48 8B 30 F3 0F 10 44 24 30 F3 0F 11 46 30", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_ADD_CAMERA, 0x4684c0, Code, { + At("48 89 5C 24 08 48 89 74 24 10 57 48 81 EC C0 00 00 00 E8 ?? ?? ?? ?? 48 8B C8 48 8B D8 FF 15 ?? ?? ?? ?? 8B 4B 30 33 F6 FF C1 89 4B 30 33 C0 F0 0F B1 35 ?? ?? ?? ?? 83 F8 10 75 ?? 8B D0 41 B8 98 03 00 00", 0x0), + Rel("E8 ?? ?? ?? ?? 85 C0 40 0F 94 C6 8B C6 48 83 C4 58 5F 5E 5D", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_DELETE_CAMERA, 0x2b1ea0, Code, { + Rel("E8 ?? ?? ?? ?? 4C 89 B3 20 28 00 00 48 8B 5C 24 50 48 8B 6C 24 58", 0x1, 0x5, 0x0), + Rel("E8 ?? ?? ?? ?? 8B 15 ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? 2B D3 48 8D 0C 07 FF CA 4C 63 C2", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_CAMERA_SET_FOV, 0x11b020, Code, { + At("40 53 48 83 EC 20 F3 0F 11 89 4C 01 00 00 48 8B D9", 0x0), + Rel("E8 ?? ?? ?? ?? F3 0F 10 8C 24 F8 00 00 00 44 0F 28 7C 24 20", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PV_SABER_SPLIT, 0x2e3b821, Data, { + Rel("C6 05 ?? ?? ?? ?? 00 48 8B 5C 24 50 48 8B 6C 24 60 48 8B 74 24 68", 0x2, 0x7, 0x0), + Rel("0F 9F 05 ?? ?? ?? ?? 48 8B 4C 24 60 48 83 C1 38 E8 ?? ?? ?? ?? 48 8B 8D 40 11 00 00", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_SET_SPLIT, 0x4150f0, Code, { + At("40 53 48 83 EC 30 48 C7 44 24 20 FE FF FF FF 0F B6 1D", 0x0), + Rel("E8 ?? ?? ?? ?? 49 8D 4D 38 E8 ?? ?? ?? ?? 90 49 8B 0C 24 83 29 01 75 ?? E8", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_SPLIT_LAYOUT, 0x415200, Code, { + At("48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 48 83 EC 40 48 8B 05 ?? ?? ?? ?? 0F 29 74 24 30", 0x0), + Rel("0F B6 D3 E8 ?? ?? ?? ?? 8B 0D ?? ?? ?? ?? 65 48 8B 04 25 58 00 00 00 BA 80 00 00 00", 0x4, 0x8, 0x0)}}, + {&OFFSET_HALO1_PV_SABER_SPLIT_STATE, 0x2e3cca8, Data, { + Rel("C7 87 80 00 00 00 00 00 80 3F 48 8B 0D ?? ?? ?? ?? 8B 41 18", 0xd, 0x11, 0x0), + Rel("48 8B 2D ?? ?? ?? ?? 48 89 78 18 41 8B FD 4C 89 78 D8 44 8B 3D", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PV_SABER_DEVICE, 0x2e3bdd8, Data, { + Rel("48 8B 05 ?? ?? ?? ?? 48 8B 88 18 01 00 00 8B 51 2C 8B 41 28", 0x3, 0x7, 0x0), + Rel("48 8B 0D ?? ?? ?? ?? 48 8D 54 24 30 66 0F 7F 44 24 20 48 8B 01", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PV_SABER_CONTEXT, 0x2e3bde0, Data, { + Rel("48 8B 01 44 8B C2 48 8B 15 ?? ?? ?? ?? 48 FF A0 D8 00 00 00", 0x9, 0xd, 0x0), + Rel("48 8B 01 44 8B C2 48 8B 15 ?? ?? ?? ?? 48 FF A0 E8 00 00 00", 0x9, 0xd, 0x0)}}, + {&OFFSET_HALO1_PV_SABER_RENDERER, 0x1c33e30, Data, { + Rel("48 8B 05 ?? ?? ?? ?? C6 80 91 00 00 00 01 48 8D 85 B0 00 00 00", 0x3, 0x7, 0x0), + Rel("48 8B 05 ?? ?? ?? ?? 48 8D 0C C9 48 8D 04 C8 48 05 18 05 00 00", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PV_SABER_SCENE, 0x1bea9e0, Data, { + Rel("48 8B 05 ?? ?? ?? ?? 8B 88 9C 00 00 00 C1 E9 08 F6 C1 01 75", 0x3, 0x7, 0x0), + Rel("C7 85 2C 02 00 00 00 00 80 3F 48 8B 0D ?? ?? ?? ?? 48 8B 01", 0xd, 0x11, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_PREPARE_FRAME, 0x455170, Code, { + At("4C 8B DC 53 56 41 56 48 81 EC 90 00 00 00 48 8B 05", 0x0)}}, + {&OFFSET_HALO1_PF_SABER_BUILD_CAMERA_LIST, 0x4547e0, Code, { + At("48 8B C4 48 89 58 08 48 89 68 10 48 89 70 18 57 41 54 41 55 41 56 41 57 48 81 EC D0 00 00 00 8B 0D", 0x0), + Rel("E8 ?? ?? ?? ?? 48 8B 15 ?? ?? ?? ?? 83 BA 94 BE 00 00 01 4C 8D 82 E8 04 00 00", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_LIST_CAMERA, 0x2ea720, Code, { + At("48 8B C4 48 89 58 18 55 56 57 41 54 41 55 41 56 41 57 48 8D A8 78 FC FF FF", 0x0), + Rel("F3 44 0F 11 44 24 20 E8 ?? ?? ?? ?? 4C 8D 9C 24 D0 00 00 00", 0x8, 0xc, 0x0)}}, + {&OFFSET_HALO1_PV_SABER_ZOOMED_FOV, 0x1944b70, Data, { + Rel("F3 0F 10 05 ?? ?? ?? ?? F3 0F 11 44 24 28 41 B9 68 05 00 00", 0x4, 0x8, 0x0), + Rel("F3 0F 10 0D ?? ?? ?? ?? F3 0F 11 4D F8 44 89 65 FC 45 8B FC", 0x4, 0x8, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_RENDER_FRAME, 0x455a10, Code, { + At("48 8B C4 55 41 54 41 55 41 56 41 57 48 8D A8 88 F3 FF FF", 0x0), + Rel("E8 ?? ?? ?? ?? 41 83 BE 88 00 00 00 00 74 ?? E8 ?? ?? ?? ?? 41 83 7E 70 00", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_COMPOSITE, 0x45e2b0, Code, { + At("48 89 5C 24 08 48 89 74 24 10 57 48 83 EC 60 80 3D ?? ?? ?? ?? 00", 0x0), + Rel("E8 ?? ?? ?? ?? 41 FF C6 48 8B 05 ?? ?? ?? ?? 8B 88 38 02 00 00 8B C6 85 C9", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PV_SABER_VIEW_IMAGES, 0x2d62890, Data, { + Rel("48 8D 3D ?? ?? ?? ?? 4C 8B 24 CF 33 F6 89 74 24 20 44 8B CE", 0x3, 0x7, 0x0), + Rel("48 8D 3D ?? ?? ?? ?? 48 8B 3C CF 0F 57 C0 F3 0F 7F 44 24 50", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PV_SABER_VIEW_IMAGE_INDEX, 0x1b7b11c, Data, { + Rel("48 8B 7C 24 68 89 1D ?? ?? ?? ?? 48 8B 5C 24 50 48 83 C4 40", 0x7, 0xb, 0x0), + Rel("48 8B 74 24 78 C7 05 ?? ?? ?? ?? FF FF FF FF 48 83 C4 60 5F", 0x7, 0xf, 0x0)}}, + {&OFFSET_HALO1_PV_SABER_SCREEN_IMAGE, 0x2e3d0d0, Data, { + Rel("42 89 6C 01 1C EB ?? 48 8B 0D ?? ?? ?? ?? 40 32 FF 48 85 C9 74", 0xa, 0xe, 0x0), + Rel("48 8B 05 ?? ?? ?? ?? 48 85 C0 48 0F 45 C8 48 89 0D ?? ?? ?? ?? 4C 8D 05", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_TEXTURE_CREATE_CHILD, 0x1f9d20, Code, { + At("48 89 5C 24 10 48 89 6C 24 18 48 89 74 24 20 57 48 83 EC 40 8B 99 88 00 00 00", 0x0), + Rel("E8 ?? ?? ?? ?? 4C 8B E8 48 8D 84 24 90 00 00 00 48 3B F8 74", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_CLASSIC_HUD, 0x740b0, Code, { + At("48 8B C4 57 48 81 EC A0 00 00 00 48 C7 40 98 FE FF FF FF", 0x0), + Rel("48 8D 05 ?? ?? ?? ?? 48 89 05 ?? ?? ?? ?? 48 8D 05 ?? ?? ?? ?? 48 89 05 ?? ?? ?? ?? 4C 89 6D 90", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PF_HUD_VIEW, 0xb29438, Code, { + At("48 89 5C 24 08 57 48 83 EC 30 48 63 D9 33 D2 48 8D 0D", 0x0), + Rel("80 78 0A 00 74 ?? B9 FF FF FF FF E8 ?? ?? ?? ?? B9 FF FF FF FF", 0xc, 0x10, 0x0)}}, + {&OFFSET_HALO1_PF_HUD_VIEW_DRAW, 0xbabd38, Code, { + At("48 8B C4 48 89 58 08 48 89 68 10 48 89 70 18 57 48 83 EC 40 80 3D ?? ?? ?? ?? 00", 0x0), + Rel("48 8D 95 60 01 00 00 41 0F B7 CF E8 ?? ?? ?? ?? 48 8D 4C 24 20", 0xc, 0x10, 0x0)}}, + {&OFFSET_HALO1_PV_HUD_VIEW_DRAW_STATE, 0x29e07c0, Data, { + Rel("0F BF 0D ?? ?? ?? ?? BE 02 00 00 00 44 8D 76 0D 41 2B CF 0F 84", 0x3, 0x7, 0x0), + Rel("B9 01 00 00 00 E8 ?? ?? ?? ?? B9 01 00 00 00 48 8D 15 ?? ?? ?? ?? E8 ?? ?? ?? ?? E8", 0x12, 0x16, 0x0)}}, + {&OFFSET_HALO1_PF_HUD_VIEW_DRAW_2, 0xb31d88, Code, { + At("48 8B C4 48 89 58 08 48 89 70 10 48 89 78 18 55 41 56 41 57 48 8D 68 A1 48 81 EC C0 00 00 00", 0x0), + Rel("B9 01 00 00 00 E8 ?? ?? ?? ?? B9 01 00 00 00 48 8D 15 ?? ?? ?? ?? E8 ?? ?? ?? ?? E8 ?? ?? ?? ??", 0x1c, 0x20, 0x0)}}, + {&OFFSET_HALO1_PF_HUD_VIEW_DRAW_3, 0xac8844, Code, { + At("48 8B C4 48 89 58 08 48 89 70 10 48 89 78 18 4C 89 60 20 55 41 56 41 57 48 8D 68 D8 48 81 EC 10 01 00 00 0F 29 70 D8", 0x0), + Rel("E8 ?? ?? ?? ?? 48 8B 0D ?? ?? ?? ?? 48 8B 01 4C 8B 90 20 01 00 00 48 8B 05", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PV_HUD_VIEW_DRAW_3_SKIP_1, 0x2ea0218, Data, { + Rel("0F 94 C0 89 05 ?? ?? ?? ?? 48 8B 0F BB FF FF FF FF 48 85 C9", 0x5, 0x9, 0x0), + Rel("48 8B F9 39 1D ?? ?? ?? ?? 74 ?? 38 1D ?? ?? ?? ?? 75 ?? E8 ?? ?? ?? ?? 48 8B F8 48 85 FF", 0x5, 0x9, 0x0)}}, + {&OFFSET_HALO1_PV_HUD_VIEW_DRAW_3_SKIP_2, 0x2e3b450, Data, { + Rel("88 05 ?? ?? ?? ?? F6 C1 10 0F 84 ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? 48 89 84 24 88 00 00 00", 0x2, 0x6, 0x0), + Rel("74 ?? 80 3D ?? ?? ?? ?? 00 75 ?? E8 ?? ?? ?? ?? 83 FB 01 7E ?? 48 8B 0D ?? ?? ?? ?? 48 8B 01", 0x4, 0x9, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_VIEW_OVERLAY, 0x4512d0, Code, { + At("48 89 5C 24 08 55 48 8D 6C 24 A9 48 81 EC 90 00 00 00", 0x0), + Rel("E8 ?? ?? ?? ?? 48 8B 15 ?? ?? ?? ?? FF C3 48 81 C7 C8 03 00 00 3B 9A B8 00 00 00", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_SABER_VIEW_OVERLAY_RECT, 0x4513ac, Code, { + At("F3 44 0F 2C D8 F3 44 0F 2C D2 41 FF CB 41 FF C2 EB ?? F3 0F 59 C3 F3 0F 5C D8 F3 44 0F 2C C8 F3 0F 2C C3 41 FF C9 FF C0 C7 05 ?? ?? ?? ?? 00 00 00 00 48 63 93 20 02 00 00 48 8B 0D", 0x32)}}, + {&OFFSET_HALO1_PF_SABER_SYNC, 0x89f00, Code, { + At("48 8B C4 55 41 54 41 55 41 56 41 57 48 8D A8 08 FF FF FF 48 81 EC D0 01 00 00 48 C7 45 70 FE FF FF FF", 0x0), + Rel("E8 ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? 48 85 C0 74 ?? 80 38 00 74 ?? 0F BF 40 10", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_SYNC_OBJECT, 0x7d350, Code, { + At("48 8B C4 55 41 54 41 55 41 56 41 57 48 8D A8 28 FE FF FF 48 81 EC B0 02 00 00 48 C7 85 F0 00 00 00 FE FF FF FF", 0x0), + Rel("48 C1 E1 05 48 03 C8 E8 ?? ?? ?? ?? FF C3 3B 1D ?? ?? ?? ?? 7C ?? 48 83 C4 20", 0x8, 0xc, 0x0)}}, + {&OFFSET_HALO1_PV_RENDER_OBJECTS, 0x29e0900, Data, { + Rel("48 8B 05 ?? ?? ?? ?? 4D 8B F9 0F B7 C9 49 8B F0 4C 6B D1 7C", 0x3, 0x7, 0x0), + Rel("4C 8B 35 ?? ?? ?? ?? 44 8B E1 49 8B CE 49 8B F1 41 0F B7 E8", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PV_DIRECTORS, 0x2d9b960, Data, { + Rel("F3 0F 59 15 ?? ?? ?? ?? F3 0F 59 D5 F3 0F 5C C2 F3 0F 11 01", 0x4, 0x8, 0x0), + Rel("4C 8D 15 ?? ?? ?? ?? 33 C9 40 84 FF 75 ?? 66 46 39 4C 13 5A 74", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PF_FIRST_PERSON_DIRECTOR, 0xc5263c, Code, { + At("4C 8B DC 49 89 5B 08 49 89 6B 10 49 89 73 18 57 48 83 EC 30 48 0F BF 02", 0x0), + Rel("48 8D 05 ?? ?? ?? ?? 4A 39 44 31 10 75 ?? 46 0F 2F 54 31 0C 72", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PF_LOCAL_PLAYER_UNIT_FLAG, 0xab16a4, Code, { + At("48 83 EC 28 83 F9 FF 74 52 48 8B 05 ?? ?? ?? ?? 48 63 C9 8B 94 88 B8 00 00 00", 0x0), + Rel("E8 ?? ?? ?? ?? 85 C0 75 ?? 48 8B 07 41 8B D4 48 8B CF FF 90 30 03 00 00", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_FIRST_PERSON_PREPARE, 0xb27510, Code, { + At("40 53 48 83 EC 20 B9 11 00 00 00 E8 ?? ?? ?? ?? 0F B7 0D ?? ?? ?? ?? 84 C0", 0x0), + Rel("89 1D ?? ?? ?? ?? 66 39 B7 B4 00 00 00 7E ?? 8B CE E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 89 35", 0x17, 0x1b, 0x0)}}, + {&OFFSET_HALO1_PF_FIRST_PERSON_UPDATE, 0xb275b8, Code, { + At("48 8B C4 48 89 58 08 48 89 70 10 48 89 78 18 55 41 54 41 55 41 56 41 57 48 8D A8 E8 F2 FF FF", 0x0), + Rel("E8 ?? ?? ?? ?? EB ?? 48 8D 4C 24 20 E8 ?? ?? ?? ?? 80 F3 01 40 80 FF 01 75", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PV_FIRST_PERSON_FOR_RENDERER, 0x2ea32f8, Data, { + Rel("44 8B 25 ?? ?? ?? ?? 48 89 44 24 78 49 8D 89 08 02 00 00 48 89 55 B8", 0x3, 0x7, 0x0), + Rel("89 1D ?? ?? ?? ?? 66 39 9F B4 00 00 00 7E ?? 33 C9 E8 ?? ?? ?? ?? 48 8B 3D", 0x2, 0x6, 0x0)}}, + {&OFFSET_HALO1_PV_FIRST_PERSON_WEAPONS, 0x1b7aa88, Data, { + Rel("48 8D 3D ?? ?? ?? ?? BA 04 00 00 00 48 3B F8 8B CA 48 8B C5", 0x3, 0x7, 0x0), + Rel("48 8D 3D ?? ?? ?? ?? 48 3B C7 48 1B C9 48 83 C8 FF 48 F7 D1", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PV_FIRST_PERSON_ARMS, 0x1b7aa98, Data, { + Rel("48 8D 0D ?? ?? ?? ?? 48 3B C8 49 8B C6 48 1B C9 48 F7 D1 83 E1 04", 0x3, 0x7, 0x0), + Rel("48 8D 05 ?? ?? ?? ?? BA 04 00 00 00 48 3B F8 8B CA 48 C7 C0 FF FF FF FF", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PF_FIRST_PERSON_SYNC, 0x7ac60, Code, { + At("40 55 56 57 41 54 41 55 41 56 41 57 48 8D AC 24 F0 FE FF FF 48 81 EC 10 02 00 00 48 C7 45 80 FE FF FF FF", 0x0), + Rel("BA 01 00 00 00 E8 ?? ?? ?? ?? 8B 0D ?? ?? ?? ?? BA 01 00 00 00 E8 ?? ?? ?? ?? 8B 0D", 0x6, 0xa, 0x0)}}, + {&OFFSET_HALO1_FIRST_PERSON_SYNC_SLOT_LIMIT, 0x7ae64, Code, { + At("41 83 FF 01 77 44 49 8B C7 48 8D 0D ?? ?? ?? ?? 42 3B BC B9", 0x0)}}, + {&OFFSET_HALO1_PV_FIRST_PERSON_MODELS, 0x2b050e8, Data, { + Rel("48 03 35 ?? ?? ?? ?? 44 89 3E 89 7E 04 44 89 76 18 4C 8D 4E 08", 0x3, 0x7, 0x0), + Rel("48 8B 05 ?? ?? ?? ?? 48 8B 54 06 10 48 8D 1C 06 48 85 D2 0F 84", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PF_OBJECT_HIDDEN_VIEWS, 0xab2890, Code, { + At("48 83 EC 28 4C 8B 15 ?? ?? ?? ?? 41 BB 01 00 00 00 44 8B C9", 0x0), + Rel("8B D8 E8 ?? ?? ?? ?? 0B C3 48 8B 5C 24 30 48 83 C4 20 5F C3", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PF_DIRECTOR_CAMERA_MODE, 0xb14ea4, Code, { + At("48 0F BF C1 4C 8D 05 ?? ?? ?? ?? 48 69 C8 F8 00 00 00 48 8D 15", 0x0), + Rel("E8 ?? ?? ?? ?? 66 83 E8 02 66 83 F8 01 41 0F 97 C1 41 8B C1", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PV_HIDDEN_OBJECT_CAMERA, 0x1b87a20, Data, { + Rel("40 88 35 ?? ?? ?? ?? 48 81 C3 F8 00 00 00 C6 05 ?? ?? ?? ?? 01 66 83 FF 04", 0x3, 0x7, 0x0), + Rel("80 3D ?? ?? ?? ?? 00 74 ?? B8 02 00 00 00 66 39 05 ?? ?? 0D 01 75 ?? 44 39 0D", 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 534fdd03..5e7b6a96 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,92 @@ 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_CINEMATIC, 0x6f4a20, Code, { + Rel("E8 ?? ?? ?? ?? 84 C0 75 ?? 44 38 B4 3B CA 00 00 00 74 ?? B0 01 EB", 0x1, 0x5, 0x0), + Rel("FF E2 E8 ?? ?? ?? ?? 84 C0 0F 85 ?? ?? ?? ?? 66 41 83 BF 10 02 00 00 FF", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PF_LOCAL_PLAYER_COUNT, 0x6a4380, Code, { + Rel("48 89 74 24 30 E8 ?? ?? ?? ?? 8B C8 B8 01 00 00 00 3B C8 7D", 0x6, 0xa, 0x0), + Rel("E8 ?? ?? ?? ?? 0F BF 4D 02 83 F8 02 41 0F BF 06 45 0F BF 46 02", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO2_TWO_PLAYERS_TEST_OBJECT_SYNC, 0x6a00c, Code, { + At("E8 ?? ?? ?? ?? 90 E8 ?? ?? ?? ?? 84 C0 75 ?? E8 ?? ?? ?? ?? 83 F8 02 75 05 40 B6 01 EB", 0x14)}}, + {&OFFSET_HALO2_TWO_PLAYERS_TEST_SCREEN_EFFECT, 0x6f40c, Code, { + At("E8 ?? ?? ?? ?? 83 F8 02 75 0E 4C 8D 44 24 28 8D 50 FF E8 ?? ?? ?? ?? 90", 0x5)}}, + {&OFFSET_HALO2_TWO_PLAYERS_TEST_FIRST_PERSON_1, 0x64004, Code, { + At("44 8B F1 E8 ?? ?? ?? ?? 84 C0 75 ?? E8 ?? ?? ?? ?? 83 F8 02 75 04 B3 01 EB 02", 0x11)}}, + {&OFFSET_HALO2_TWO_PLAYERS_TEST_FIRST_PERSON_2, 0x64f4e, Code, { + At("E8 ?? ?? ?? ?? 90 E8 ?? ?? ?? ?? 84 C0 75 ?? E8 ?? ?? ?? ?? 83 F8 02 75 04 B3 01 EB 02", 0x14)}}, + {&OFFSET_HALO2_TWO_PLAYERS_TEST_FIRST_PERSON_3, 0x65559, Code, { + At("4C 0F 45 E0 E8 ?? ?? ?? ?? 84 C0 75 ?? E8 ?? ?? ?? ?? 83 F8 02 75 04 B3 01 EB 02", 0x12)}}, + {&OFFSET_HALO2_PF_SABER_HAND_OVER_VIEW, 0x5f510, Code, { + At("48 89 5C 24 08 57 48 81 EC F0 00 00 00 48 63 D9", 0x0), + Rel("E8 ?? ?? ?? ?? 84 DB 74 ?? 0F B6 D3 B9 01 00 00 00 E8 ?? ?? ?? ?? 48 8B 05", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO2_PV_SABER_CAMERAS, 0x1e91210, Data, { + Rel("48 8B 0D ?? ?? ?? ?? 33 DB 48 89 74 24 50 8B 91 08 01 00 00", 0x3, 0x7, 0x0), + Rel("48 8B 0D ?? ?? ?? ?? FF D3 90 83 7D 84 00 75 ?? 48 8B 4D 88 E8", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PF_SABER_CAMERA_SET_FOV, 0xbc560, Code, { + At("40 53 48 83 EC 20 F3 0F 11 89 54 01 00 00 48 8B D9", 0x0), + Rel("E8 ?? ?? ?? ?? F3 0F 5C B3 54 01 00 00 44 0F 28 7C 24 50 44 0F 28 74 24 60", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO2_PV_SABER_DEVICE, 0x1e8d418, Data, { + Rel("48 8B 05 ?? ?? ?? ?? F3 0F 11 49 6C 83 B8 14 01 00 00 02 7D", 0x3, 0x7, 0x0), + Rel("48 8B 0D ?? ?? ?? ?? 48 8B 01 4C 8D 44 24 50 BA 3D 00 00 00", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PV_SABER_CONTEXT, 0x1e8d420, Data, { + Rel("48 8B 0D ?? ?? ?? ?? 48 8B 01 FF 90 D0 00 00 00 44 89 7C 24 30", 0x3, 0x7, 0x0), + Rel("48 8B 05 ?? ?? ?? ?? 48 8B 88 58 0D 00 00 49 89 48 08 49 89 50 10", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PV_SABER_SCENE, 0x1a250f8, Data, { + Rel("4C 8B 05 ?? ?? ?? ?? 4C 89 4C 24 28 45 33 C9 4C 89 54 24 20", 0x3, 0x7, 0x0), + Rel("48 8B 05 ?? ?? ?? ?? 85 DB 75 ?? 81 48 10 00 01 00 00 40 88 35", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PF_SABER_BUILD_CAMERA_LIST, 0x2ddcb0, Code, { + At("48 8B C4 55 56 57 41 54 41 55 41 56 41 57 48 8D A8 B8 F8 FF FF", 0x0)}}, + {&OFFSET_HALO2_PF_SABER_LIST_CAMERA, 0x1c7740, Code, { + At("40 55 56 57 41 56 41 57 48 8D AC 24 60 F9 FF FF", 0x0), + Rel("E8 ?? ?? ?? ?? 4C 63 F8 4D 69 F7 58 07 00 00 4C 03 74 24 68", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO2_PF_SABER_RENDER_FRAME, 0x2dec00, Code, { + At("48 8B C4 57 41 54 41 55 41 56 41 57 48 81 EC D0 00 00 00", 0x0), + Rel("48 8B 89 48 02 00 00 FF 15 ?? ?? ?? ?? EB ?? E8 ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? C6 80 ?? ?? ?? ?? 01", 0x10, 0x14, 0x0)}}, + {&OFFSET_HALO2_PF_SABER_COMPOSITE, 0x1d2a00, Code, { + At("48 85 C9 0F 84 ?? ?? ?? ?? 48 8B C4 55 41 54 41 55 41 56 41 57", 0x0), + Rel("80 F2 01 48 8B 9C 24 88 00 00 00 48 83 C4 70 5F E9 ?? ?? ?? ??", 0x11, 0x15, 0x0)}}, + {&OFFSET_HALO2_SABER_COMPOSITE_DRAW, 0x1d2c33, Code, { + At("41 B9 18 00 00 00 45 8D 41 EC 48 8D 55 C0 48 8B 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 90 48 8D 4C 24 50 E8 ?? ?? ?? ?? 48 8B 4D 20 48 33 CC E8 ?? ?? ?? ?? 4C 8D 9C 24 30 01 00 00", 0x0)}}, + {&OFFSET_HALO2_PF_SABER_AFTER_CAMERAS, 0x2e3f70, Code, { + At("40 53 48 83 EC 20 48 8B 05 ?? ?? ?? ?? 48 8B 1D ?? ?? ?? ?? 83 B8 48 01 00 00 00", 0x0), + Rel("3B 1E 7C ?? E8 ?? ?? ?? ?? 48 8B 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 90 48 8B 45 80 48 85 C0", 0x5, 0x9, 0x0)}}, + {&OFFSET_HALO2_PF_SABER_HDR_PASS, 0x210bf0, Code, { + At("48 8B C4 48 89 58 08 48 89 70 10 55 57 41 54 41 56", 0x0), + Rel("48 8B 74 24 70 0F 28 74 24 40 48 83 C4 50 41 5E E9 ?? ?? ?? ??", 0x11, 0x15, 0x0)}}, + {&OFFSET_HALO2_PV_SABER_HDR_VIEWS, 0x1ab8600, Data, { + Rel("4C 8D 25 ?? ?? ?? ?? 4C 89 7C 24 64 4D 6B F6 4C 48 8D 3C 00", 0x3, 0x7, 0x0), + Rel("48 8D 15 ?? ?? ?? ?? 0F 10 4D E0 48 8B 5C 24 60 48 6B CF 4C", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PV_SABER_HDR_READ_BACKS, 0x1ab8758, Data, { + Rel("4C 8D 3D ?? ?? ?? ?? 45 8B F4 0F 1F 40 00 66 66 0F 1F 84 00 00 00 00 00", 0x3, 0x7, 0x0), + Rel("48 8D 3D ?? ?? ?? ?? 4C 8B 40 F0 48 8D 58 F0 48 8B 10 F3 0F 11 74 24 28", 0x3, 0x7, -0x40)}}, + {&OFFSET_HALO2_PF_SABER_ADD_RENDER_TARGET, 0xf7750, Code, { + At("40 53 55 56 57 41 54 41 55 41 56 41 57 48 81 EC 08 01 00 00", 0x0), + Rel("E8 ?? ?? ?? ?? 41 8B 4E 0C 41 89 8E 48 2B 00 00 41 8B 4E 0C", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO2_PF_SABER_DELETE_TEXTURE, 0x1a5990, Code, { + At("41 56 48 83 EC 40 48 C7 44 24 20 FE FF FF FF 48 89 5C 24 50 48 89 6C 24 58 48 89 74 24 60 48 89 7C 24 68 48 63 DA", 0x0), + Rel("E8 ?? ?? ?? ?? 90 FF C7 48 83 C6 08 3B BB 28 02 00 00 7C ?? 48 89 2D", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO2_PF_PLAYER_VISIBLE_OBJECTS, 0x608a0, Code, { + At("48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 48 83 EC 20 8B D9", 0x0)}}, + {&OFFSET_HALO2_PF_OWN_UNIT_IN_FIRST_PERSON, 0x5fe80, Code, { + At("48 89 5C 24 10 56 48 83 EC 20 8B F1 8B DA 8B CA", 0x0), + Rel("E8 ?? ?? ?? ?? 40 84 FF 74 ?? 84 C0 75 ?? BA 01 00 00 00 8B CB E8", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO2_PF_FIRST_PERSON_SYNC, 0x6d0d0, Code, { + At("41 54 41 56 48 83 EC 28 33 C9 E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 84 C0 75 ?? E8", 0x0), + Rel("84 C0 0F 85 ?? ?? ?? ?? 48 89 5C 24 30 E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 44 0F B6 05", 0x13, 0x17, 0x0)}}, + {&OFFSET_HALO2_PF_FIRST_PERSON_BUILD, 0x81bfb0, Code, { + At("48 89 5C 24 10 57 B8 90 34 00 00 E8 ?? ?? ?? ?? 48 2B E0 48 63 D9", 0x0), + Rel("E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 84 C0 75 ?? E8 ?? ?? ?? ?? 83 F8 02 75 ?? 8D 48 FF 41 B4 01", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO2_PV_FIRST_PERSON_MODELS, 0x1ab11c0, Data, { + Rel("48 8B 05 ?? ?? ?? ?? C6 44 10 20 01 FF C1 48 8D 52 28 3B 0D", 0x3, 0x7, 0x0), + Rel("48 8B 1D ?? ?? ?? ?? 48 83 C3 08 49 03 DC 48 8B 0B 48 85 C9", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PV_MODEL_LEVELS, 0x1dc36f0, Data, { + Rel("48 8B 05 ?? ?? ?? ?? 0F B6 44 01 FF 42 0F B6 14 10 80 FA FF", 0x3, 0x7, 0x0), + Rel("48 8B 05 ?? ?? ?? ?? 48 8B 52 10 0F B6 44 01 FF 44 0F B6 1C 10", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PF_SABER_OBJECT_SHOW, 0x69c30, Code, { + At("4C 8B C1 48 85 C9 74 58 44 8B 49 0C 41 F6 C1 01 75", 0x0), + Rel("33 C9 F6 41 0C 01 75 ?? 48 85 C0 74 ?? 48 8B 08 E8 ?? ?? ?? ?? EB", 0x11, 0x15, 0x0)}}, + {&OFFSET_HALO2_PF_SABER_OBJECT_HIDE, 0x69ca0, Code, { + At("4C 8B C1 48 85 C9 74 58 44 8B 49 0C 41 F6 C1 01 74", 0x0), + Rel("E8 ?? ?? ?? ?? 45 84 E4 0F 84 ?? ?? ?? ?? 48 8B 43 08 48 85 C0 74 ?? 48 8B 00", 0x1, 0x5, 0x0)}}, }; diff --git a/tools/offsets/gen_patterns.py b/tools/offsets/gen_patterns.py index 32b981e5..b973db59 100644 --- a/tools/offsets/gen_patterns.py +++ b/tools/offsets/gen_patterns.py @@ -44,6 +44,7 @@ "OFFSET_HALO1_PF_4PLAYERS": 0x1A, "OFFSET_HALO1_PF_PAUSE": 2, "OFFSET_HALO1_PF_IDK": 6, + "OFFSET_HALO1_FIRST_PERSON_SYNC_SLOT_LIMIT": 6, "OFFSET_HALO2_PF_PLAYER_COUNT1": 1, "OFFSET_HALO2_PF_PLAYER_COUNT2": 1, "OFFSET_HALO2_TWO_PLAYERS_TEST_HAND_OVER": 5, @@ -57,10 +58,12 @@ } # Mid-function hooks whose detours rewrite what the code before them set up: the pattern starts at least this many -# 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. +# bytes earlier (halo1/splitscreen.cpp ScopeGrid: rsp+0x40..0x48 and 0x64/xmm15; halo1/anniversary.cpp +# OverlayRect: the rect in r11d, r9d, r10d, eax). An offset right after a call - a return address - always takes +# the call as well. COVER_BEFORE = { "OFFSET_HALO1_SCOPE_GRID_SET": 0x45, + "OFFSET_HALO1_SABER_VIEW_OVERLAY_RECT": 0x32, } # Offsets with no binary here to pattern from. From aff8fc87f58ab8f071a99e0be9d54b68986535ba Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 20:38:29 -0400 Subject: [PATCH 2/7] feat(halo1): Anniversary graphics with 3-4 players Halo CE's Anniversary (Saber3D) renderer draws split screen as exactly two stacked views, with two cameras, two-slot per-view state and render targets whose split children are half the screen. The mode keeps that two-view frame and alternates what is in it: players 1 and 2 on one frame, 3 and 4 on the next, so each view updates at half the frame rate. module/entry/halo1/anniversary.cpp, ported from the kirklandsig fork (v1.9-v2.0.1): - cameras for views 3 and 4 made with the renderer's AddCamera as split screen starts and kept past its camera count; quarter viewports; - quarter-size children swapped into every split render target for the frame, each view copied into its quadrant of an image of ours, copied to the screen before the HUD; the classic HUD pass draws each view's HUD in its quadrant, and each view's screen effects stay in it; - game side, players 3 and 4's cameras handed over inside the game's own hand-over (a frame stale otherwise), their units hidden only in their own views, and first-person models of their own (slots 2-3: the slot check in the first-person sync is widened from 1 to 3 once the mode runs, after its bytes are checked, and put back as the module unloads). Three players get quarters (the fourth black): splitscreen.cpp's window hook lays their windows out as four, so the feature requires the split screen hooks' (Feature::Requires) - on a build missing one of them none of these hooks go in. The quarter-size children are made the first time the mode draws after the game made its split targets (the fork made them alongside, mode or not), so nothing is allocated for a game that never runs it. halo1.h declares what the two files share: the split-screen hooks' feature, their Classic check (now Splitscreen::ClassicShown, which the mode reads too) and the mode's Quad. It runs only in a mission that started with it chosen (Splitscreen::AnniversaryQuadActive); nothing starts one yet. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/entry/halo1/anniversary.cpp | 635 +++++++++++++++++++++ src/mcc/module/entry/halo1/halo1.h | 11 + src/mcc/module/entry/halo1/splitscreen.cpp | 11 +- src/mcc/splitscreen/Splitscreen.cpp | 6 + src/mcc/splitscreen/Splitscreen.h | 7 + 5 files changed, 667 insertions(+), 3 deletions(-) create mode 100644 src/mcc/module/entry/halo1/anniversary.cpp diff --git a/src/mcc/module/entry/halo1/anniversary.cpp b/src/mcc/module/entry/halo1/anniversary.cpp new file mode 100644 index 00000000..e9299f87 --- /dev/null +++ b/src/mcc/module/entry/halo1/anniversary.cpp @@ -0,0 +1,635 @@ +// Halo CE Anniversary graphics with 3-4 players (experimental, MCC::Splitscreen::AnniversaryQuadChosen). +// +// The Anniversary (Saber3D) renderer draws split screen as exactly two views stacked: two cameras, render targets +// with two half-height children (_SPLIT_1/_SPLIT_2) that a two-way switch picks between, a composite that copies +// each view's image into its half of the screen, and a good deal of per-view state with two slots. Quad mode keeps +// that two-view frame and alternates what is in it: players 1 and 2 on one frame, 3 and 4 on the next. Every +// split target gets quarter-size children swapped in for the frame, the cameras get quarter viewports, and each +// view is copied into its quadrant of an image of our own, which is copied to the screen before the HUD. +#include "halo1.h" + +#include "mcc/CGameGlobal.h" +#include "mcc/module/entry/PreservingThunk.h" +#include "mcc/module/patch/CPatch.h" +#include "mcc/splitscreen/Splitscreen.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace Halo1::Entry::Anniversary { + EntryFeature("Halo CE Anniversary graphics with 3-4 players", + OFFSET_HALO1_PV_PLAYER_COUNT, OFFSET_HALO1_PV_SABER_DEVICE, OFFSET_HALO1_PV_SABER_CAMERAS, + OFFSET_HALO1_PF_SABER_DELETE_CAMERA, OFFSET_HALO1_PV_SABER_SPLIT, OFFSET_HALO1_PF_SABER_ADD_CAMERA, + OFFSET_HALO1_PF_SABER_CAMERA_SET_FOV, OFFSET_HALO1_PV_SABER_RENDERER, OFFSET_HALO1_PV_SABER_SPLIT_STATE, + OFFSET_HALO1_PF_SABER_SPLIT_LAYOUT, OFFSET_HALO1_PF_FIRST_PERSON_PREPARE, + OFFSET_HALO1_PV_FIRST_PERSON_FOR_RENDERER, OFFSET_HALO1_PF_FIRST_PERSON_UPDATE, + OFFSET_HALO1_PV_FIRST_PERSON_WEAPONS, OFFSET_HALO1_PV_FIRST_PERSON_ARMS, OFFSET_HALO1_PV_LOCAL_PLAYERS, + OFFSET_HALO1_PV_RENDER_WINDOWS, OFFSET_HALO1_PV_RENDER_CAMERAS, OFFSET_HALO1_PF_SPLIT_WINDOW, + OFFSET_HALO1_PV_WINDOW_FIELDS_OF_VIEW, OFFSET_HALO1_PF_RENDER_WINDOW_CAMERA, + OFFSET_HALO1_PF_SABER_HAND_OVER_VIEW, OFFSET_HALO1_PF_DIRECTOR_CAMERA_MODE, + OFFSET_HALO1_PV_HIDDEN_OBJECT_CAMERA, OFFSET_HALO1_PV_RENDER_OBJECTS, OFFSET_HALO1_PV_DIRECTORS, + OFFSET_HALO1_PF_FIRST_PERSON_DIRECTOR, OFFSET_HALO1_PF_LOCAL_PLAYER_UNIT_FLAG, OFFSET_HALO1_PV_SABER_SCENE, + OFFSET_HALO1_PV_SABER_ZOOMED_FOV, OFFSET_HALO1_PV_SABER_CONTEXT, OFFSET_HALO1_PV_SABER_VIEW_IMAGES, + OFFSET_HALO1_PV_SABER_VIEW_IMAGE_INDEX, OFFSET_HALO1_PV_SABER_SCREEN_IMAGE, OFFSET_HALO1_PF_HUD_VIEW_DRAW, + OFFSET_HALO1_PV_HUD_VIEW_DRAW_STATE, OFFSET_HALO1_PF_HUD_VIEW_DRAW_2, OFFSET_HALO1_PF_HUD_VIEW_DRAW_3, + OFFSET_HALO1_PV_HUD_VIEW_DRAW_3_SKIP_1, OFFSET_HALO1_PV_HUD_VIEW_DRAW_3_SKIP_2, + OFFSET_HALO1_PV_ANNIVERSARY_SHOWN, OFFSET_HALO1_PF_FIRST_PERSON_SYNC, + OFFSET_HALO1_FIRST_PERSON_SYNC_SLOT_LIMIT, OFFSET_HALO1_PV_FIRST_PERSON_MODELS); + // Three players' windows are laid out as quarters by splitscreen.cpp's window hook: on a build without one of its + // hooks, none of these go in either and 3-4 player missions start in Classic. + const bool s_requires_split_screen = (entry_feature->Requires(Splitscreen::Hooks()), true); + + // Everything the mode hooks and reaches is in this build (MCC::Splitscreen::ClassicGraphicsScope asks). + bool Available() { return entry_feature->Available(); } + + int LocalPlayers(__int64 module) { return *(short*)(module + OFFSET_HALO1_PV_PLAYER_COUNT); } + int Views(__int64 module) { return std::clamp(LocalPlayers(module), 0, 4); } + // The mode is set up for a 3-4 player mission that started with it chosen (its cameras made as split screen + // starts) and runs while Anniversary graphics are on screen: Back switches them in the middle of a mission. + bool QuadReady(__int64 module) { + return MCC::Splitscreen::AnniversaryQuadActive(CGameGlobal::Halo1) && Views(module) > 2; + } + bool Quad(__int64 module) { return QuadReady(module) && !Splitscreen::ClassicShown(module); } + + char* Settings(__int64 module) { return *(char**)(*(char**)(module + OFFSET_HALO1_PV_SABER_DEVICE) + 0x118); } + int ScreenWidth(__int64 module) { return *(int*)(Settings(module) + 0x20); } + int ScreenHeight(__int64 module) { return *(int*)(Settings(module) + 0x24); } + + char** Cameras(__int64 module) { return *(char***)(module + OFFSET_HALO1_PV_SABER_CAMERAS); } + int& CameraCount(__int64 module) { return *(int*)(module + OFFSET_HALO1_PV_SABER_CAMERAS + 8); } + int CameraCapacity(__int64 module) { return *(int*)(module + OFFSET_HALO1_PV_SABER_CAMERAS + 0xC); } + + // The renderer's cameras 0 and 1, and ours for views 2 and 3 (below). + char* s_extra_cameras[2] = {}; + char* Camera(__int64 module, int view) { + if (view >= 2) return view < 4 ? s_extra_cameras[view - 2] : nullptr; + return view >= 0 && view < CameraCount(module) ? Cameras(module)[view] : nullptr; + } + + // ---- render targets: quarter-size children beside the split ones. The texture manager finds textures by + // name, so ours carry their size, and a resize makes new ones. They're made when quad mode first draws after + // the game made its split children (MakeChildren), so a game that never runs the mode doesn't get them. + + std::string SizedName(const char* name, int width, int height) { + return std::string(name) + "_" + std::to_string(width) + "x" + std::to_string(height); + } + + struct QuadChild { + std::string name; // to make at width x height, with the split child's flags; empty once taken + int width = 0, height = 0, flags = 0; + char* texture = nullptr; // ours, once made + }; + struct QuadChildren { + char* parent; + QuadChild child[2]; + }; + std::mutex s_children_mutex; + std::vector s_children; + std::atomic s_children_wanted = false; // the game made a split child since MakeChildren last looked + + extern ::Entry entry_create_child; + // the fifth argument is unused; the sixth's low word is the texture's flags (+0x7C) + using create_child_t = char* (*)(char* parent, const char* name, int width, int height, __int64, int flags); + + bool EndsWith(const char* text, const char* suffix) { + size_t n = strlen(text), m = strlen(suffix); + return n >= m && strcmp(text + n - m, suffix) == 0; + } + + char* CreateChild(char* parent, const char* name, int width, int height, __int64 unused, int flags) { + auto original = (create_child_t)entry_create_child.m_pOriginal; + char* child = original(parent, name, width, height, unused, flags); + int which = EndsWith(name, "_SPLIT_1") ? 0 : EndsWith(name, "_SPLIT_2") ? 1 : -1; + if (which >= 0 && child != nullptr) { + std::lock_guard lock(s_children_mutex); + auto it = std::find_if(s_children.begin(), s_children.end(), [&](auto& e) { return e.parent == parent; }); + if (it == s_children.end()) it = s_children.insert(s_children.end(), {parent}); + it->child[which] = {SizedName((std::string(name) + "_QUAD").c_str(), width / 2, height), width / 2, height, flags}; + s_children_wanted = true; + } + return child; + } + ::Entry entry_create_child(Halo1EntrySet(), OFFSET_HALO1_PF_SABER_TEXTURE_CREATE_CHILD, (void*)&CreateChild, + entry_feature); + + // Render thread, before a quad frame: the children wanted, made outside our lock (the game's texture creation + // takes locks of its own), each kept unless the game made its split child again meanwhile. + void MakeChildren() { + if (!s_children_wanted.exchange(false)) return; + struct Wanted { + char* parent; + int which; + QuadChild child; + }; + std::vector wanted; + { + std::lock_guard lock(s_children_mutex); + for (auto& e : s_children) + for (int which = 0; which < 2; ++which) + if (!e.child[which].name.empty()) { + wanted.push_back({e.parent, which, e.child[which]}); + e.child[which].name.clear(); + } + } + auto create = (create_child_t)entry_create_child.m_pOriginal; + int made = 0; + for (auto& w : wanted) { + char* texture = create(w.parent, w.child.name.c_str(), w.child.width, w.child.height, 0, w.child.flags); + if (texture == nullptr) continue; + std::lock_guard lock(s_children_mutex); + auto it = std::find_if(s_children.begin(), s_children.end(), [&](auto& e) { return e.parent == w.parent; }); + if (it == s_children.end() || !it->child[w.which].name.empty()) continue; + it->child[w.which].texture = texture; + ++made; + } + if (made > 0) LOG_INFO("Halo CE Anniversary 3-4 players: {} quarter-size render targets made", made); + } + + void SwapChildren() { + std::lock_guard lock(s_children_mutex); + for (auto& e : s_children) { + if (e.child[0].texture == nullptr || e.child[1].texture == nullptr) continue; + std::swap(*(char**)(e.parent + 0xA8), e.child[0].texture); + std::swap(*(char**)(e.parent + 0xB0), e.child[1].texture); + } + } + + // ---- cameras: the renderer makes one for the second view; the third and fourth are ours. They are made by + // the renderer's AddCamera and then kept past its camera count, so that everything it bounds by that count + // stays with two views - its screen effects, for one, start in any camera below the count and write two-slot + // arrays. Quarter viewports for all four. + + void DropExtraCameras(__int64 module) { + for (char*& camera : s_extra_cameras) { + if (camera != nullptr) ((void (*)(char*))(module + OFFSET_HALO1_PF_SABER_DELETE_CAMERA))(camera); + camera = nullptr; + } + } + + // As split screen starts (and at the sync, while split screen is on without them). + void MakeExtraCameras(__int64 module) { + int& count = CameraCount(module); + if (!QuadReady(module) || s_extra_cameras[0] != nullptr || count != 2) return; + for (int i = 0; i < 2; ++i) ((int (*)())(module + OFFSET_HALO1_PF_SABER_ADD_CAMERA))(); + if (count == 4) { + s_extra_cameras[0] = Cameras(module)[2]; + s_extra_cameras[1] = Cameras(module)[3]; + LOG_INFO("Halo CE Anniversary 3-4 players: cameras for views 3 and 4 made"); + } + count = 2; + } + + Halo1Entry(entry_set_split, OFFSET_HALO1_PF_SABER_SET_SPLIT, void, set_split, char* state) { + __int64 module = entry_set_split.m_target - entry_set_split.m_offset; + if (!*(bool*)(module + OFFSET_HALO1_PV_SABER_SPLIT) && state[0x41]) DropExtraCameras(module); // turning off + ((set_split_t)entry_set_split.m_pOriginal)(state); + if (state[0x41]) MakeExtraCameras(module); + } + + bool s_quarters = false; // the cameras have quarter viewports + + bool HasQuarters(__int64 module) { + float width = ScreenWidth(module) * 0.5f, height = ScreenHeight(module) * 0.5f; + for (int view = 0; view < 4; ++view) + if (char* camera = Camera(module, view)) + if (*(float*)(camera + 0x144) != width || *(float*)(camera + 0x148) != height) return false; + return true; + } + + void QuarterLayout(__int64 module) { + int width = ScreenWidth(module), height = ScreenHeight(module); + float aspect = (float)height / (float)width / *(float*)(Settings(module) + 0x1C); + for (int view = 0; view < 4; ++view) { + char* camera = Camera(module, view); + if (camera == nullptr) continue; + *(float*)(camera + 0x154) = aspect; + ((void (*)(char*, float))(module + OFFSET_HALO1_PF_SABER_CAMERA_SET_FOV))(camera, *(float*)(camera + 0x14C)); + *(__int64*)(camera + 0x13C) = 0; + *(float*)(camera + 0x144) = width * 0.5f; + *(float*)(camera + 0x148) = height * 0.5f; + *(float*)(camera + 0x158) = width * 0.5f / *(float*)(camera + 0x134); + *(float*)(camera + 0x15C) = height * 0.5f / *(float*)(camera + 0x138); + } + *(unsigned char*)(*(char**)(module + OFFSET_HALO1_PV_SABER_RENDERER) + 0x92) = 1; + } + + // Leaving quad mode (or a list drawn whole, as cutscenes are): the renderer's own layout again. + void Layout(__int64 module, bool quad, bool split) { + if (quad) { + if (!HasQuarters(module)) QuarterLayout(module); + s_quarters = true; + } else if (s_quarters) { + s_quarters = false; + char* state = *(char**)(module + OFFSET_HALO1_PV_SABER_SPLIT_STATE); + if (state != nullptr) ((void (*)(char*, bool))(module + OFFSET_HALO1_PF_SABER_SPLIT_LAYOUT))(state, split); + } + } + + // ---- the pairs. Each frame the game hands its state to the renderer (the sync) and builds a camera list, + // which the next frame's sync commits for the renderer to draw. The lists alternate pairs, players 1 and 2 + // then 3 and 4, and what the sync hands over for the views goes with the list it builds. + + std::atomic s_pair = 0; // the pair of the list the sync builds + std::atomic s_sync_quad = false; // the sync is in quad mode + std::atomic s_listed_pair = 0; // the pair of the list the renderer draws + std::atomic s_waiting_pair = 0; // the pair of the list built aside, waiting to be committed + thread_local bool t_second_pair = false; // the sync is handing players 3 and 4's frame over (first_person_sync) + unsigned char* s_slot_limit = nullptr; // first_person_sync's slot check, while it's widened + void WidenSlotLimit(__int64 module); + + Halo1Entry(entry_sync, OFFSET_HALO1_PF_SABER_SYNC, void, sync) { + __int64 module = entry_sync.m_target - entry_sync.m_offset; + char* split = *(char**)(module + OFFSET_HALO1_PV_SABER_SPLIT_STATE); + if (split != nullptr && split[0x41]) MakeExtraCameras(module); + bool quad = Quad(module); + s_sync_quad = quad; + s_pair = quad ? s_pair ^ 1 : 0; + if (quad && s_slot_limit == nullptr) WidenSlotLimit(module); + t_second_pair = s_pair == 1; + ((sync_t)entry_sync.m_pOriginal)(); + t_second_pair = false; + } + + // ---- each frame the game hands its views 0 and 1 to the renderer's cameras (hand_over_view), then queues the + // worker's list build, which copies each view's camera (list_camera). Views 2 and 3 go over right after view 1, + // before the build is queued: handed over after the game's hand-over returned, players 3 and 4's list took their + // cameras as they were the frame before more than half the time (2351 of 4200 copies in a trace), and their + // views jumped between two frames. + + thread_local bool t_hand_over = false; // handing over + thread_local bool t_view_block = false; // and each view's HUD view and first-person weapon were worked out + + // The first-person weapon of the view the HUD is set up for, for the renderer (views 0-3, the renderer takes 0-1). + void FirstPersonView(__int64 module, int view) { + ((void (*)(int))(module + OFFSET_HALO1_PF_HUD_VIEW))(view); + ((void (*)())(module + OFFSET_HALO1_PF_FIRST_PERSON_PREPARE))(); + *(int*)(module + OFFSET_HALO1_PV_FIRST_PERSON_FOR_RENDERER) = 1; + ((void (*)())(module + OFFSET_HALO1_PF_FIRST_PERSON_UPDATE))(); + *(int*)(module + OFFSET_HALO1_PV_FIRST_PERSON_FOR_RENDERER) = 0; + } + + // Players 3 and 4's frame: the sync hands the renderer views 0 and 1's first-person weapon and arms, so theirs + // are put in views 0 and 1's places, and a view nobody has is -1 in both (first_person_sync, below, takes the + // nodes from views 2 and 3's own, which the game finds by the object in the view's place). + void FirstPersonPair(__int64 module, int views) { + const __int64 kObjects[] = {OFFSET_HALO1_PV_FIRST_PERSON_WEAPONS, OFFSET_HALO1_PV_FIRST_PERSON_ARMS}; + for (__int64 objects : kObjects) { + int* object = (int*)(module + objects); + for (int slot = 0; slot < 2; ++slot) { + if (slot + 2 >= views) object[slot + 2] = -1; + object[slot] = object[slot + 2]; + } + } + } + + Halo1Entry(entry_hand_over, OFFSET_HALO1_PF_SABER_HAND_OVER_VIEWS, void, hand_over) { + t_hand_over = true; + t_view_block = false; + ((hand_over_t)entry_hand_over.m_pOriginal)(); + t_hand_over = false; + } + + Halo1Entry(entry_hand_over_view, OFFSET_HALO1_PF_SABER_HAND_OVER_VIEW, void, hand_over_view, int index) { + auto original = (hand_over_view_t)entry_hand_over_view.m_pOriginal; + original(index); + if (index != 1 || !t_hand_over || !s_sync_quad) return; + __int64 module = entry_hand_over_view.m_target - entry_hand_over_view.m_offset; + int players = *(short*)(*(char**)(module + OFFSET_HALO1_PV_LOCAL_PLAYERS) + 0xB4); + int views = (std::min)(players, s_extra_cameras[1] != nullptr ? 4 : s_extra_cameras[0] != nullptr ? 3 : 2); + // the hand-over (0xB29268 -> 0x7B480) writes the renderer's camera `view` if it is below the count: our + // cameras stand in the array's slots past it for the moment + int& count = CameraCount(module); + if (views > 2 && CameraCapacity(module) >= 4 && count == 2) { + Cameras(module)[2] = s_extra_cameras[0]; + Cameras(module)[3] = s_extra_cameras[1]; + count = views; + for (int view = 2; view < views; ++view) { + char* window = (char*)(module + OFFSET_HALO1_PV_RENDER_WINDOWS + view * 0xAC); + char* camera = (char*)(module + OFFSET_HALO1_PV_RENDER_CAMERAS + view * 0x2A8); + *(short*)window = (short)view; + window[2] = 0; + ((void (*)(int, int, short*, short*))(module + OFFSET_HALO1_PF_SPLIT_WINDOW))( + view, players, (short*)(window + 0x84), (short*)(window + 0x8C)); + *(float*)(module + OFFSET_HALO1_PV_WINDOW_FIELDS_OF_VIEW + (view + 1) * 4) = *(float*)(camera + 0x38); + ((void (*)(char*, char*))(module + OFFSET_HALO1_PF_RENDER_WINDOW_CAMERA))(window, camera); + if (t_view_block) FirstPersonView(module, view); + original(view); + } + count = 2; + } + if (s_pair == 1) FirstPersonPair(module, views); + } + + // ---- players 3 and 4's first-person models. The renderer keeps one per view slot and weapon, posed each frame + // by first_person_sync (active camo too), and the game addresses the rest of a first-person gun - its display + // (the assault rifle's round count), its fire and reload effects - by local player, 0 to 3. Players 3 and 4's + // frames hand theirs over as slots 2 and 3, shown in views 0 and 1: the pairs never share a model, and the game + // finds players 3 and 4's where it looks for them. The game gives a slot past 1 no nodes (a check in + // first_person_sync); its per-view arrays have four, and the check is widened to them as quad mode starts. + + void WidenSlotLimit(__int64 module) { + auto check = (unsigned char*)(module + OFFSET_HALO1_FIRST_PERSON_SYNC_SLOT_LIMIT); + unsigned char limit = 3; + if (memcmp(check, "\x41\x83\xFF\x01\x77", 5) == 0 && CPatch::apply(check + 3, &limit, 1)) s_slot_limit = check + 3; + } + + void RestoreSlotLimit() { + unsigned char limit = 1; + if (s_slot_limit != nullptr) CPatch::apply(s_slot_limit, &limit, 1); + s_slot_limit = nullptr; + } + + char* FirstPersonModel(__int64 module, int slot, int object) { + char* entries = *(char**)(module + OFFSET_HALO1_PV_FIRST_PERSON_MODELS); + int count = *(int*)(module + OFFSET_HALO1_PV_FIRST_PERSON_MODELS + 8); + for (int i = 0; entries != nullptr && i < count; ++i) { + char* entry = entries + i * 0x20; + if (*(int*)entry == slot && *(int*)(entry + 4) == object) return entry; + } + return nullptr; + } + + Halo1Entry(entry_first_person_sync, OFFSET_HALO1_PF_FIRST_PERSON_SYNC, void, first_person_sync, int object, int slot) { + auto original = (first_person_sync_t)entry_first_person_sync.m_pOriginal; + if (!t_second_pair || s_slot_limit == nullptr || slot < 0 || slot > 1) return original(object, slot); + __int64 module = entry_first_person_sync.m_target - entry_first_person_sync.m_offset; + // the game copies the nodes of the view whose weapon or arms the object is, and from null for neither + if (object != ((int*)(module + OFFSET_HALO1_PV_FIRST_PERSON_WEAPONS))[slot + 2] && + object != ((int*)(module + OFFSET_HALO1_PV_FIRST_PERSON_ARMS))[slot + 2]) + return; + original(object, slot + 2); + if (slot != 0) return; + // the game shows every slot's model but slot 0's in view 1: slot 2's is view 0's + char* model = FirstPersonModel(module, 2, object); + if (model != nullptr && model[0x1E] == 0) { + model[0x1C] = 0; + model[0x1E] = 1; + } + } + + // ---- who is seen in which view. The renderer's objects have a hidden flag per view (0 and 1), which the sync + // sets from the game: a local player's own unit is hidden in its view while in first person, and each player + // has models of its own seen only in its view. The game answers for players 1 and 2; in quad mode, for the pair. + + int* LocalUnits(__int64 module) { return (int*)(*(char**)(module + OFFSET_HALO1_PV_LOCAL_PLAYERS) + 0xC8); } + + int Viewer(int slot) { return slot + 2 * s_pair; } // the local player seen through the view + + int CameraMode(__int64 module, int local) { // 0: first person + return ((short (*)(int))(module + OFFSET_HALO1_PF_DIRECTOR_CAMERA_MODE))(local); + } + + Halo1Entry(entry_hidden_views, OFFSET_HALO1_PF_OBJECT_HIDDEN_VIEWS, int, hidden_views, int object) { + if (!s_sync_quad) return ((hidden_views_t)entry_hidden_views.m_pOriginal)(object); + __int64 module = entry_hidden_views.m_target - entry_hidden_views.m_offset; + int* units = LocalUnits(module); + int hidden = 0; + for (int slot = 0; slot < 2; ++slot) + if (object != -1 && units[Viewer(slot)] == object && CameraMode(module, Viewer(slot)) == 0) hidden |= 1 << slot; + if (hidden != 0) return hidden; + // and, as the game does, both for the object a special camera is set to hide + bool hides = *(bool*)(module + OFFSET_HALO1_PV_HIDDEN_OBJECT_CAMERA) && *(short*)(module + OFFSET_HALO1_PV_HIDDEN_OBJECT_CAMERA + 2) == 2 + && *(int*)(module + OFFSET_HALO1_PV_HIDDEN_OBJECT_CAMERA + 0x34) == object; + return hides ? 3 : 0; + } + + void Hide(char* object, int slot, bool hidden) { + ((void (*)(char*, int))(*(void***)object)[(hidden ? 0x328 : 0x330) / 8])(object, slot); + } + + // The players' own models: the first shown in their view in first person (unless seated), the second out of it. + Halo1Entry(entry_sync_object, OFFSET_HALO1_PF_SABER_SYNC_OBJECT, void, sync_object, char* record) { + ((sync_object_t)entry_sync_object.m_pOriginal)(record); + if (!s_sync_quad) return; + __int64 module = entry_sync_object.m_target - entry_sync_object.m_offset; + char* objects = *(char**)(module + OFFSET_HALO1_PV_RENDER_OBJECTS); + int object = *(int*)(objects + *(int*)(objects + 0x34) + *(unsigned short*)record * 0x7C + 0x2C); + int* units = LocalUnits(module); + int local = object == -1 ? 4 : int(std::find(units, units + 4, object) - units); + if (local > 3) return; + char* director = (char*)(module + OFFSET_HALO1_PV_DIRECTORS + local * 0xF8); + bool first_person = *(__int64*)(director + 0x10) == module + OFFSET_HALO1_PF_FIRST_PERSON_DIRECTOR + && *(float*)(director + 0xC) <= 0.0f; + bool seated = ((int (*)(int))(module + OFFSET_HALO1_PF_LOCAL_PLAYER_UNIT_FLAG))(local) != 0; + char** first = *(char***)(record + 8); + char** second = *(char***)(record + 0x10); + for (int slot = 0; slot < 2; ++slot) { + bool own = Viewer(slot) == local; + if (first != nullptr && *first != nullptr) Hide(*first, slot, !(own && first_person && !seated)); + if (second != nullptr && *second != nullptr) Hide(*second, slot, !own || first_person || seated); + } + } + + // ---- the camera list: the pair's cameras in place of the first two + + thread_local int t_pair = -1; // the pair of the list being built + + char* RenderList(__int64 module) { return *(char**)(module + OFFSET_HALO1_PV_SABER_SCENE) + 0xB0; } + + Halo1Entry(entry_prepare, OFFSET_HALO1_PF_SABER_PREPARE_FRAME, void, prepare, char* scene) { + if (*(int*)(scene + 0xBE58) && *(int*)(scene + 0xBE5C)) s_listed_pair = s_waiting_pair.load(); // committing + ((prepare_t)entry_prepare.m_pOriginal)(scene); + } + + Halo1Entry(entry_build_list, OFFSET_HALO1_PF_SABER_BUILD_CAMERA_LIST, __int64, build_list, void* a, char* list, + __int64 split, void* d) { + __int64 module = entry_build_list.m_target - entry_build_list.m_offset; + bool quad = Quad(module) && (unsigned char)split; + Layout(module, quad, (unsigned char)split); + if (!quad) return ((build_list_t)entry_build_list.m_pOriginal)(a, list, split, d); + int pair = s_pair; + t_pair = pair; + auto result = ((build_list_t)entry_build_list.m_pOriginal)(a, list, split, d); + t_pair = -1; + (list == RenderList(module) ? s_listed_pair : s_waiting_pair) = pair; + return result; + } + + // The list takes a copy of each camera and works its aspect out from the view's height over the screen's width, + // which a quarter view is not: the copy gets a height it comes out right with, and its own back once listed. + Halo1Entry(entry_list_camera, OFFSET_HALO1_PF_SABER_LIST_CAMERA, __int64, list_camera, char* list, char* camera, + __int64 flags, __int64 index, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9, __int64 a10, + __int64 a11, __int64 a12, __int64 a13, __int64 a14, __int64 a15, __int64 a16) { + auto original = [&](char* listed, __int64 listed_flags) { + return ((list_camera_t)entry_list_camera.m_pOriginal)(list, listed, listed_flags, index, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16); + }; + if (t_pair < 0 || !(flags & 0x300)) return original(camera, flags); + __int64 module = entry_list_camera.m_target - entry_list_camera.m_offset; + int slot = (flags & 0x100) ? 0 : 1; + int source = t_pair == 0 ? slot : (std::min)(2 + slot, Views(module) - 1); // 3 players: the third twice + char* source_camera = Camera(module, source); + if (source_camera == nullptr) return original(camera, flags); + + alignas(16) char view[0x398]; + memcpy(view, source_camera, sizeof view); + float width = *(float*)(view + 0x144), height = *(float*)(view + 0x148); + *(float*)(view + 0x148) = height * ScreenWidth(module) / width; + *(int*)(view + 0x220) = slot; // the renderer's per-view tables have two slots + flags &= ~0x1000; + if (*(float*)(module + OFFSET_HALO1_PV_SABER_ZOOMED_FOV) > *(float*)(view + 0x14C)) flags |= 0x1000; + __int64 entry = original(view, flags); + char* listed = list + 0x10 + (int)entry * 0x3C8 + 0x30; + *(float*)(listed + 0x148) = height; + *(float*)(listed + 0x15C) = height / *(float*)(listed + 0x138); + return entry; + } + + // ---- the frame + + bool s_quad = false; // this frame is drawn in quarters + int s_frame_pair = 0; // and shows this pair + int s_frame_views = 0; + char* s_image = nullptr; // our full-screen image the quadrants are copied into + + // 3 players: the second pair's frames have nobody's second view + bool NoFourthView(int index) { return s_frame_pair == 1 && index == 1 && s_frame_views < 4; } + + struct CopyRegion { + char* source; + char* destination; + char zero[0x10]; + int x, y; + __int64 zero2; + int width, height; + }; + + int TextureWidth(char* texture) { return ((int (*)(char*))(*(void***)texture)[0x18 / 8])(texture); } + int TextureHeight(char* texture) { return ((int (*)(char*))(*(void***)texture)[0x20 / 8])(texture); } + + void Copy(__int64 module, char* source, char* destination, int x, int y) { + CopyRegion region{source, destination, {}, x, y, 0, TextureWidth(source), TextureHeight(source)}; + char* context = *(char**)(module + OFFSET_HALO1_PV_SABER_CONTEXT); + ((void (*)(char*, CopyRegion*))(*(void***)context)[0x190 / 8])(context, ®ion); + } + + Halo1Entry(entry_frame, OFFSET_HALO1_PF_SABER_RENDER_FRAME, __int64, frame, void* a, void* b, void* c, void* d) { + __int64 module = entry_frame.m_target - entry_frame.m_offset; + s_quad = Quad(module) && (*(unsigned*)RenderList(module) & 1); + if (!s_quad) return ((frame_t)entry_frame.m_pOriginal)(a, b, c, d); + s_frame_pair = s_listed_pair; + s_frame_views = Views(module); + MakeChildren(); + SwapChildren(); + auto result = ((frame_t)entry_frame.m_pOriginal)(a, b, c, d); + SwapChildren(); + return result; + } + + Halo1Entry(entry_composite, OFFSET_HALO1_PF_SABER_COMPOSITE, void, composite, int camera) { + if (!s_quad) return ((composite_t)entry_composite.m_pOriginal)(camera); + __int64 module = entry_composite.m_target - entry_composite.m_offset; + char* view = *(char**)(module + OFFSET_HALO1_PV_SABER_VIEW_IMAGES + + 8 * (__int64)*(int*)(module + OFFSET_HALO1_PV_SABER_VIEW_IMAGE_INDEX)); + int width = ScreenWidth(module), height = ScreenHeight(module); + if (view != nullptr) { + if (s_image == nullptr || TextureWidth(s_image) != width || TextureHeight(s_image) != height) + s_image = ((create_child_t)entry_create_child.m_pOriginal)( + view, SizedName("ALPHARING_QUAD_IMAGE", width, height).c_str(), width, height, + 0, *(unsigned short*)(view + 0x7C)); + if (s_image != nullptr && !NoFourthView(camera)) + Copy(module, view, s_image, (camera & 1) * (width / 2), s_frame_pair * (height / 2)); + } + ((composite_t)entry_composite.m_pOriginal)(camera); + char* target = *(char**)(module + OFFSET_HALO1_PV_SABER_SCREEN_IMAGE); + if (camera == 1 && s_image != nullptr && target != nullptr) Copy(module, s_image, target, 0, 0); + } + + // ---- the classic HUD over the image: its pass draws views 0 and 1 in the screen's halves, then view -1 (the + // screen's own) over all of it. In quad mode each view gets its quadrant, and views 2 and 3 are drawn before -1. + + thread_local bool t_hud_pass = false; // in the pass + thread_local bool t_hud_second = false; // and past view 1 + + void SetViewport(__int64 module, int x, int y, int width, int height) { + char* context = *(char**)(module + OFFSET_HALO1_PV_SABER_CONTEXT); + ((void (*)(char*, int, int, int, int, float, float))(*(void***)context)[0x120 / 8])(context, x, y, width, height, + 0.0f, 1.0f); + } + + void QuadrantViewport(__int64 module, int view) { + char* settings = Settings(module); + int width = *(int*)(settings + 0x10) / 2, height = *(int*)(settings + 0x14) / 2; + SetViewport(module, (view & 1) * width, (view >> 1) * height, width, height); + } + + Halo1Entry(entry_hud_pass, OFFSET_HALO1_PF_SABER_CLASSIC_HUD, void, hud_pass) { + t_hud_pass = s_quad; + t_hud_second = false; + ((hud_pass_t)entry_hud_pass.m_pOriginal)(); + t_hud_pass = false; + } + + Halo1Entry(entry_hud_view, OFFSET_HALO1_PF_HUD_VIEW, void, hud_view, int view) { + auto original = (hud_view_t)entry_hud_view.m_pOriginal; + if (t_hand_over) t_view_block = true; + if (!t_hud_pass) return original(view); + __int64 module = entry_hud_view.m_target - entry_hud_view.m_offset; + if (view == 0 || view == 1) { + QuadrantViewport(module, view); + t_hud_second = view == 1; + } else if (view == -1 && t_hud_second) { + t_hud_second = false; + for (int extra = 2; extra < s_frame_views; ++extra) { + QuadrantViewport(module, extra); + original(extra); + ((void (*)(int, void*))(module + OFFSET_HALO1_PF_HUD_VIEW_DRAW))( + extra, (void*)(module + OFFSET_HALO1_PV_HUD_VIEW_DRAW_STATE)); + ((void (*)())(module + OFFSET_HALO1_PF_HUD_VIEW_DRAW_2))(); + if (!*(int*)(module + OFFSET_HALO1_PV_HUD_VIEW_DRAW_3_SKIP_1) + || !*(bool*)(module + OFFSET_HALO1_PV_HUD_VIEW_DRAW_3_SKIP_2)) + ((void (*)())(module + OFFSET_HALO1_PF_HUD_VIEW_DRAW_3))(); + } + char* settings = Settings(module); + SetViewport(module, 0, 0, *(int*)(settings + 0x10), *(int*)(settings + 0x14)); + } + original(view); + } + + // ---- each view's screen effects cover its half of the screen: its quadrant instead + + Halo1Entry(entry_overlay, OFFSET_HALO1_PF_SABER_VIEW_OVERLAY, void, view_overlay, void* a, char* camera, + __int64 index) { + if (s_quad && NoFourthView((int)index)) return; + ((view_overlay_t)entry_overlay.m_pOriginal)(a, camera, index); + } + + extern ::Entry entry_overlay_rect; + + void OverlayRect(char* locals) { // the rect is left r11d, top r9d, right r10d, bottom eax; the index is r8d + int index = *(int*)(locals - 0x20); + if (!s_quad || index < 0 || index > 1) return; + char* settings = Settings(entry_overlay_rect.m_target - entry_overlay_rect.m_offset); + int width = *(int*)(settings + 0x28) / 2, height = *(int*)(settings + 0x2C) / 2; + int left = index * width, top = s_frame_pair * height; + *(__int64*)(locals - 0x38) = left; + *(__int64*)(locals - 0x28) = top; + *(__int64*)(locals - 0x30) = left + width; + *(__int64*)(locals - 0x08) = top + height; + } + ::Entry entry_overlay_rect(Halo1EntrySet(), OFFSET_HALO1_SABER_VIEW_OVERLAY_RECT, + MidFunctionThunk(&OverlayRect, &entry_overlay_rect.m_pOriginal, nullptr, 0), entry_feature); + + // ---- the module unloading (MCC reloads it for the next game): nothing of ours may point into it + + void Reset() { + { + std::lock_guard lock(s_children_mutex); + s_children.clear(); + } + s_children_wanted = false; + s_image = nullptr; + s_extra_cameras[0] = s_extra_cameras[1] = nullptr; // the renderer's heap goes with the module + s_quarters = false; + s_quad = false; + s_sync_quad = false; + s_pair = s_listed_pair = s_waiting_pair = 0; + RestoreSlotLimit(); + } + const bool s_reset = (Halo1EntrySet()->on_remove(&Reset), true); +} diff --git a/src/mcc/module/entry/halo1/halo1.h b/src/mcc/module/entry/halo1/halo1.h index dea2d9d6..c87074f5 100644 --- a/src/mcc/module/entry/halo1/halo1.h +++ b/src/mcc/module/entry/halo1/halo1.h @@ -12,3 +12,14 @@ inline EntrySet* Halo1EntrySet() {return &g_pHalo1EntrySet;}; typedef returnType (*pDetour##_t)(...); \ ::Entry name(Halo1EntrySet(), offset, pDetour, entry_feature); \ returnType pDetour(__VA_ARGS__) + +namespace Halo1::Entry { + namespace Splitscreen { + const ::AlphaRing::Feature& Hooks(); // its hooks and offsets, which Anniversary graphics with 3-4 players require + bool ClassicShown(__int64 module); // Classic graphics are on screen (Back switches them in a mission) + } + + namespace Anniversary { + bool Quad(__int64 module); // 3-4 players drawn in quarters, Anniversary graphics (anniversary.cpp) + } +} diff --git a/src/mcc/module/entry/halo1/splitscreen.cpp b/src/mcc/module/entry/halo1/splitscreen.cpp index ce239a60..80151a62 100644 --- a/src/mcc/module/entry/halo1/splitscreen.cpp +++ b/src/mcc/module/entry/halo1/splitscreen.cpp @@ -13,11 +13,13 @@ namespace Halo1::Entry::Splitscreen { 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); + const ::AlphaRing::Feature& Hooks() { return *entry_feature; } + + bool ClassicShown(__int64 module) { return *(int*)(module + OFFSET_HALO1_PV_ANNIVERSARY_SHOWN) == 0; } // 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); + return ClassicShown(module) && MCC::Splitscreen::LeftRight::OnScreen(CGameGlobal::Halo1, views); } int Views(__int64 module) { return ((int (*)())(module + OFFSET_HALO1_PF_SPLIT_VIEWS))(); } @@ -32,9 +34,12 @@ namespace Halo1::Entry::Splitscreen { 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)) { + __int64 module = entry_window.m_target - entry_window.m_offset; + if (views == 3 && view >= 0 && view < 3 && OnScreen(module, 3)) { views = view == 0 ? 2 : 4; if (view == 2) view = 3; + } else if (views == 3 && Anniversary::Quad(module)) { + views = 4; // Anniversary graphics with 3-4 players draw every view in a quarter (anniversary.cpp) } ((split_window_t)entry_window.m_pOriginal)(view, views, rect, copy); } diff --git a/src/mcc/splitscreen/Splitscreen.cpp b/src/mcc/splitscreen/Splitscreen.cpp index 4050792b..e9699190 100644 --- a/src/mcc/splitscreen/Splitscreen.cpp +++ b/src/mcc/splitscreen/Splitscreen.cpp @@ -10,6 +10,8 @@ #include "log/MatchLog.h" #include "LeftRight.h" +#include + namespace MCC::Splitscreen { DefDetourFunction(__int64, __fastcall, get_index_by_xuid, void* a1, __int64 xuid) { auto p_setting = AlphaRing::Global::MCC::Splitscreen(); @@ -40,6 +42,10 @@ namespace MCC::Splitscreen { return true; } + static std::atomic s_anniversary_quad_game{-1}; // the Halo CE / Halo 2 game whose mission started with it + + bool AnniversaryQuadActive(int game) { return s_anniversary_quad_game == game; } + ClassicGraphicsScope::ClassicGraphicsScope(unsigned char* game_options, int game) { auto p_setting = AlphaRing::Global::MCC::Splitscreen(); diff --git a/src/mcc/splitscreen/Splitscreen.h b/src/mcc/splitscreen/Splitscreen.h index 3a776f28..66d4f345 100644 --- a/src/mcc/splitscreen/Splitscreen.h +++ b/src/mcc/splitscreen/Splitscreen.h @@ -21,3 +21,10 @@ namespace MCC::Splitscreen { unsigned char m_saved = 0; }; } + +namespace MCC::Splitscreen { + // Halo CE and Halo 2 with 3-4 players in Anniversary graphics: whether the mission running in `game` + // (CGameGlobal::Halo1 or Halo2) started with them chosen. Such a mission draws its 3-4 views whenever + // Anniversary graphics are on screen. + bool AnniversaryQuadActive(int game); +} From e113ca4a66411b6f92b5b5973bcb5200ed50b7fd Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 20:38:32 -0400 Subject: [PATCH 3/7] feat(halo2): Anniversary graphics with 3-4 players Halo 2 Anniversary's renderer draws split screen for exactly two local players. As in Halo CE the frame keeps its two views and the pairs take turns. module/entry/halo2/anniversary.cpp and CellShaders.h, ported from the kirklandsig fork (v1.9-v2.0.1): - the game's glue splits the screen only for exactly two players: at its six "== 2" sites (by return address) the local player count answers 2 while the mode runs - the count's 12-byte leaf goes through PreservingThunk and reads the count as the leaf does; - players 3 and 4 get camera copies of ours, handed over after view 1; each listed camera takes its player's cell in Halo 2's own grid (with three players, player 1 keeps the wide top half), and the pair rides in the list's flags to the frame that draws it; - the views are drawn a quarter of the screen in size: the renderer's "_split" render targets are remade half as wide while the mode runs and put back after (texture deletion is hooked so none is kept past the engine's delete) - 60 fps instead of 30 with four players on the test box; - the game's composite quad leaves no pixels with more than two players, so it's collapsed to a point and each view's image is drawn into its cell by a small shader of ours (CellShaders.h); the other pair's cells are kept in a texture of ours and put back before the HUD; - game side, each window's visible objects, the own-unit test and the first-person models follow the pair, and players 3 and 4's frames adapt their exposure to their own picture (they followed player 1's). Two players aren't touched: the game's composite runs as it does, under the D3D11 composite clip of #23 (render/d3d11/Hook.cpp). The fork drew two players with the same shader for the same black screen; that branch isn't ported. The clip only takes a 6-index draw whose image is one player's share of the screen tall, and the mode's images are half the screen tall with 3-4 players, so the two don't meet. halo2.h declares what the mode reads from its neighbours: the split screen's Splitscreen::ClassicShown and players.cpp's Handle and Player. Like Halo CE's, it runs only in a mission that started with it chosen; nothing starts one yet. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/entry/halo2/CellShaders.h | 63 ++ src/mcc/module/entry/halo2/anniversary.cpp | 658 +++++++++++++++++++++ src/mcc/module/entry/halo2/halo2.h | 11 + 3 files changed, 732 insertions(+) create mode 100644 src/mcc/module/entry/halo2/CellShaders.h create mode 100644 src/mcc/module/entry/halo2/anniversary.cpp diff --git a/src/mcc/module/entry/halo2/CellShaders.h b/src/mcc/module/entry/halo2/CellShaders.h new file mode 100644 index 00000000..07fbecb5 --- /dev/null +++ b/src/mcc/module/entry/halo2/CellShaders.h @@ -0,0 +1,63 @@ +#pragma once + +// A view image drawn into a rectangle (the viewport): a full-screen triangle and a linear sample. Built with +// fxc /T vs_4_0 /E vs and /T ps_4_0 /E ps (/O3 /Qstrip_reflect /Qstrip_debug) from: +// +// Texture2D image : register(t0); +// SamplerState linear_clamp : register(s0); +// +// void vs(uint id : SV_VertexID, out float4 position : SV_Position, out float2 uv : TEXCOORD0) { +// uv = float2((id << 1) & 2, id & 2); +// position = float4(uv * float2(2, -2) + float2(-1, 1), 0, 1); +// } +// +// float4 ps(float4 position : SV_Position, float2 uv : TEXCOORD0) : SV_Target { +// return float4(image.Sample(linear_clamp, uv).rgb, 1); +// } + +constexpr unsigned char kCellVS[] = { + 0x44, 0x58, 0x42, 0x43, 0x65, 0xf2, 0xfa, 0xf5, 0x57, 0x5b, 0x9c, 0xec, 0xf4, 0x2b, 0xe6, 0x70, 0x22, 0x98, 0x90, 0x72, + 0x01, 0x00, 0x00, 0x00, 0xd8, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, + 0xb8, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x01, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78, 0x49, 0x44, 0x00, 0x4f, 0x53, 0x47, 0x4e, + 0x50, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x0c, 0x00, 0x00, + 0x53, 0x56, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, 0x52, 0x44, + 0x00, 0xab, 0xab, 0xab, 0x53, 0x48, 0x44, 0x52, 0x18, 0x01, 0x00, 0x00, 0x40, 0x00, 0x01, 0x00, 0x46, 0x00, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x04, 0x12, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x67, 0x00, 0x00, 0x04, + 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0x32, 0x20, 0x10, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x07, 0x12, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0a, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x07, 0x12, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x07, 0x42, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0a, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x56, 0x00, 0x00, 0x05, + 0x32, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0f, + 0x32, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, + 0x00, 0x00, 0x80, 0xbf, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, + 0x32, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x08, + 0xc2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x3e, 0x00, 0x00, 0x01, +}; + +constexpr unsigned char kCellPS[] = { + 0x44, 0x58, 0x42, 0x43, 0xd7, 0x93, 0x6c, 0x3b, 0xf4, 0x5e, 0xe6, 0x2d, 0x54, 0xf4, 0x58, 0x32, 0xd6, 0xde, 0x3d, 0x67, + 0x01, 0x00, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, + 0xb8, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x50, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0f, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, + 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x00, 0xab, 0xab, 0xab, 0x4f, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x61, 0x72, 0x67, 0x65, + 0x74, 0x00, 0xab, 0xab, 0x53, 0x48, 0x44, 0x52, 0x94, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, + 0x5a, 0x00, 0x00, 0x03, 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x18, 0x00, 0x04, 0x00, 0x70, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x62, 0x10, 0x00, 0x03, 0x32, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, + 0x45, 0x00, 0x00, 0x09, 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x46, 0x7e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, + 0x72, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, + 0x82, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x3e, 0x00, 0x00, 0x01, +}; diff --git a/src/mcc/module/entry/halo2/anniversary.cpp b/src/mcc/module/entry/halo2/anniversary.cpp new file mode 100644 index 00000000..ad97356e --- /dev/null +++ b/src/mcc/module/entry/halo2/anniversary.cpp @@ -0,0 +1,658 @@ +// Halo 2 Anniversary graphics with 3-4 players (experimental, MCC::Splitscreen::AnniversaryQuadChosen). +// +// H2A's Saber renderer draws split screen for exactly two local players: the game hands two views over, the renderer +// draws each at full width and half height, and a quad puts each image on its half of the screen. As in Halo CE +// (halo1/anniversary.cpp) the frame keeps its two views and the pairs alternate: players 1 and 2 on one frame, 3 and 4 +// on the next. The views are drawn a quarter of the screen in size (QuarterViews), each camera shaped like its +// player's cell in Halo 2's own grid, and each image is drawn into that cell. The other pair's cells are kept in a +// texture of ours and put back before the HUD, which Halo 2's window loop already draws for every player. What the +// game works out per view (visible objects, the own body, first-person models) follows the pair. Two players are left +// to the game and the D3D11 composite clip (render/d3d11/Hook.cpp). +#include "halo2.h" + +#include "mcc/CGameGlobal.h" +#include "mcc/module/entry/PreservingThunk.h" +#include "mcc/splitscreen/Splitscreen.h" +#include "CellShaders.h" + +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace Halo2::Entry::Anniversary { + EntryFeature("Halo 2 Anniversary graphics with 3-4 players", + OFFSET_HALO2_PV_RESPAWN, OFFSET_HALO2_PV_ANNIVERSARY, OFFSET_HALO2_PV_CLASSIC_SHOWN, OFFSET_HALO2_PF_CINEMATIC, + OFFSET_HALO2_PV_PLAYERS, OFFSET_HALO2_PV_SABER_DEVICE, OFFSET_HALO2_PF_SPLIT_GRID, OFFSET_HALO2_PF_SPLIT_CELL, + OFFSET_HALO2_TWO_PLAYERS_TEST_HAND_OVER, OFFSET_HALO2_TWO_PLAYERS_TEST_OBJECT_SYNC, + OFFSET_HALO2_TWO_PLAYERS_TEST_SCREEN_EFFECT, OFFSET_HALO2_TWO_PLAYERS_TEST_FIRST_PERSON_1, + OFFSET_HALO2_TWO_PLAYERS_TEST_FIRST_PERSON_2, OFFSET_HALO2_TWO_PLAYERS_TEST_FIRST_PERSON_3, + OFFSET_HALO2_PV_SABER_CAMERAS, OFFSET_HALO2_PF_SABER_CAMERA_SET_FOV, OFFSET_HALO2_PV_MODEL_LEVELS, + OFFSET_HALO2_PF_FIRST_PERSON_BUILD, OFFSET_HALO2_PV_FIRST_PERSON_MODELS, OFFSET_HALO2_PF_SABER_OBJECT_SHOW, + OFFSET_HALO2_PF_SABER_OBJECT_HIDE, OFFSET_HALO2_PV_SABER_CONTEXT, OFFSET_HALO2_PV_SABER_SCENE, + OFFSET_HALO2_PV_SABER_HDR_VIEWS, OFFSET_HALO2_PV_SABER_HDR_READ_BACKS); + + // Everything the mode hooks and reaches is in this build (MCC::Splitscreen::ClassicGraphicsScope asks). + bool Available() { return entry_feature->Available(); } + + int Players(__int64 module) { + return std::clamp((int)*(short*)(*(char**)(module + OFFSET_HALO2_PV_RESPAWN) + 8), 0, 4); + } + + // A mission that started with the mode chosen, with 3-4 players and Anniversary graphics on screen (Back switches + // them in the middle of a mission), outside cinematics. + bool Quad(__int64 module) { + return MCC::Splitscreen::AnniversaryQuadActive(CGameGlobal::Halo2) && Players(module) >= 3 && + !Splitscreen::ClassicShown(module) && !((bool (*)())(module + OFFSET_HALO2_PF_CINEMATIC))(); + } + + // Whether local player `player` has had a unit since the module loaded. Players 3 and 4 wait for a co-op respawn + // (the missions have starting places for two), and until then their camera looks at nothing: Classic shows their + // window black, and so does this. + std::atomic s_spawned[4] = {}; + bool Spawned(__int64 module, int player) { + if (s_spawned[player]) return true; + int handle = Entry::Players::Handle(module, player); + char* data = handle != -1 ? Entry::Players::Player(module, handle) : nullptr; + return data != nullptr && (s_spawned[player] = *(int*)(data + 0x2C) != -1); // the player's unit + } + + char* Settings(__int64 module) { return *(char**)(*(char**)(module + OFFSET_HALO2_PV_SABER_DEVICE) + 0x118); } + + // A player's cell in Halo 2's grid (the one its HUD is drawn in), in pixels of the screen or of the views. + struct Cell { + int left, top, right, bottom; + }; + Cell PlayerCell(__int64 module, int player, int players, bool screen) { + char* settings = Settings(module); + int width = *(int*)(settings + (screen ? 0x10 : 0x20)), height = *(int*)(settings + (screen ? 0x14 : 0x24)); + short grid[2], cell[2], span[2]; + ((void (*)(int, int, short*))(module + OFFSET_HALO2_PF_SPLIT_GRID))(players, 1, grid); + ((void (*)(int, int, int, short*, short*, short*))(module + OFFSET_HALO2_PF_SPLIT_CELL))(player, players, 1, grid, + cell, span); + int columns = (std::max)((int)grid[0], 1), rows = (std::max)((int)grid[1], 1); + return {cell[0] * width / columns, cell[1] * height / rows, (cell[0] + span[0]) * width / columns, + (cell[1] + span[1]) * height / rows}; + } + + // ---- split screen: the game's glue turns it on for exactly two local players; at its sites quad mode answers two + + const AlphaRing::Offset* const kTwoPlayerTests[] = { + &OFFSET_HALO2_TWO_PLAYERS_TEST_HAND_OVER, &OFFSET_HALO2_TWO_PLAYERS_TEST_OBJECT_SYNC, + &OFFSET_HALO2_TWO_PLAYERS_TEST_SCREEN_EFFECT, &OFFSET_HALO2_TWO_PLAYERS_TEST_FIRST_PERSON_1, + &OFFSET_HALO2_TWO_PLAYERS_TEST_FIRST_PERSON_2, &OFFSET_HALO2_TWO_PLAYERS_TEST_FIRST_PERSON_3}; + + bool TwoPlayerTest(__int64 at) { + return std::any_of(std::begin(kTwoPlayerTests), std::end(kTwoPlayerTests), [&](auto test) { return *test == at; }); + } + + PreservedEntry(entry_local_players, Halo2EntrySet(), OFFSET_HALO2_PF_LOCAL_PLAYER_COUNT, local_players, void*, void*, + void*, void*, __int64 caller) { + __int64 module = entry_local_players.m_target - entry_local_players.m_offset; + int players = *(short*)(*(char**)(module + OFFSET_HALO2_PV_RESPAWN) + 8); // as the game's leaf reads it + if (players > 2 && MCC::Splitscreen::AnniversaryQuadActive(CGameGlobal::Halo2) && TwoPlayerTest(caller - module) && + Quad(module)) + return 2; + return players; + } + + // ---- players 3 and 4: two cameras of ours (the renderer's slots past 1 can be the scene's picture-in-picture + // cameras), handed over after the game's two + + char* s_cameras[2] = {}; + std::atomic s_pair = 0; // the pair of the next camera list + + char*** CameraArray(__int64 module) { return (char***)(*(char**)(module + OFFSET_HALO2_PV_SABER_CAMERAS) + 0x100); } + int& CameraCount(__int64 module) { return *(int*)(*(char**)(module + OFFSET_HALO2_PV_SABER_CAMERAS) + 0x108); } + + Halo2Entry(entry_hand_over, OFFSET_HALO2_PF_SABER_HAND_OVER_VIEW, void, hand_over, int view, bool split) { + ((hand_over_t)entry_hand_over.m_pOriginal)(view, split); + __int64 module = entry_hand_over.m_target - entry_hand_over.m_offset; + if (view != 1 || !Quad(module) || CameraCount(module) < 2) return; + char**& array = *CameraArray(module); + int& count = CameraCount(module); + for (char*& camera : s_cameras) { + if (camera == nullptr) { + camera = (char*)_aligned_malloc(0x398, 16); + if (camera == nullptr) return; + memcpy(camera, array[1], 0x398); + } + memcpy(camera + 0x13C, array[1] + 0x13C, 0x10); // the viewport, as the game lays out view 1's + } + // The hand-over writes the renderer's camera `view`: ours stand in a copy of the array meanwhile (the list + // is built after this whole hand-over, which it waits for). + constexpr int kMaxCameras = 16; + if (count > kMaxCameras) return; + char* cameras[kMaxCameras] = {}; + std::copy(array, array + count, cameras); + cameras[2] = s_cameras[0]; + cameras[3] = s_cameras[1]; + char** stock = array; + int stock_count = count; + array = cameras; + count = (std::max)(count, 4); + for (int player = 2; player < Players(module); ++player) + ((hand_over_t)entry_hand_over.m_pOriginal)(player, split); + array = stock; + count = stock_count; + } + + // ---- the camera list: the pair's cameras, each shaped like its player's cell, and the pair in the list's flags + // (which the renderer only reads bits 0 and 1 of) so that it reaches the frame that draws the list + + constexpr unsigned kQuadList = 1u << 28, kSecondPairList = 1u << 30; + + thread_local int t_pair = -1; // the pair of the list being built + + Halo2Entry(entry_build_list, OFFSET_HALO2_PF_SABER_BUILD_CAMERA_LIST, __int64, build_list, void* renderer, + unsigned* list, __int64 split, void* r9) { + __int64 module = entry_build_list.m_target - entry_build_list.m_offset; + if (!(unsigned char)split || !Quad(module)) { + s_pair = 0; + return ((build_list_t)entry_build_list.m_pOriginal)(renderer, list, split, r9); + } + int pair = s_pair; + t_pair = pair; + auto result = ((build_list_t)entry_build_list.m_pOriginal)(renderer, list, split, r9); + t_pair = -1; + *list |= kQuadList | (pair ? kSecondPairList : 0); + s_pair = pair ^ 1; + return result; + } + + Halo2Entry(entry_list_camera, OFFSET_HALO2_PF_SABER_LIST_CAMERA, __int64, list_camera, void* list, char* camera, + __int64 flags, __int64 index, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9, __int64 a10) { + auto original = [&](char* listed) { + return ((list_camera_t)entry_list_camera.m_pOriginal)(list, listed, flags, index, a5, a6, a7, a8, a9, a10); + }; + if (t_pair < 0 || !(flags & 0x30)) return original(camera); + __int64 module = entry_list_camera.m_target - entry_list_camera.m_offset; + int slot = (flags & 0x10) ? 0 : 1, players = Players(module); + int player = (std::min)(slot + 2 * t_pair, players - 1); // 3 players: the third twice, the second not drawn + char* source = player < 2 ? camera : s_cameras[player - 2]; + if (source == nullptr) return original(camera); + + alignas(16) char view[0x398]; + memcpy(view, source, sizeof view); + if (source != camera) { // prepared as the builder prepares the game's: no scene links, its near and far + memset(view + 0x200, 0, 0x20); + memcpy(view + 0x80, camera + 0x80, 8); + } + Cell cell = PlayerCell(module, player, players, false); + *(float*)(view + 0x158) = (float)(cell.bottom - cell.top) / (float)(cell.right - cell.left) / *(float*)(Settings(module) + 0x1C); + *(float*)(view + 0x144) = (float)(cell.right - cell.left); + *(float*)(view + 0x148) = (float)(cell.bottom - cell.top); + ((void (*)(char*, float))(module + OFFSET_HALO2_PF_SABER_CAMERA_SET_FOV))(view, *(float*)(view + 0x154)); + *(int*)(view + 0x220) = slot; // the renderer's per-view tables have two slots + if (player != slot + 2 * t_pair) flags |= 4; // 3 players: listed as a second view, which is skipped + return original(view); + } + + // ---- what each view shows (game side): the game works out two views' visible objects, own body and first-person + // models, for local players 0 and 1; in quad mode those are the players of the pair whose list the frame builds + + std::atomic s_sync_pair = 0; // the pair the game frame's per-view work is for + std::atomic s_sync_quad = false; // and whether it's in quad mode (as of its window loop) + + int Viewer(int slot) { return slot + 2 * s_sync_pair; } + + // Each window's visible objects, stored for view 0 (local player 0) or view 1 (the others): here for the view of + // its player in the pair, and not at all for the other pair. + Halo2Entry(entry_visible_objects, OFFSET_HALO2_PF_PLAYER_VISIBLE_OBJECTS, void, visible_objects, int local) { + __int64 module = entry_visible_objects.m_target - entry_visible_objects.m_offset; + bool quad = Quad(module); + if (local == 0) { // the window loop starts every game frame with player 1 + s_sync_quad = quad; + s_sync_pair = s_pair.load(); + } + if (!quad) return ((visible_objects_t)entry_visible_objects.m_pOriginal)(local); + int slot = local - 2 * s_sync_pair; + if (slot == 0 || slot == 1) ((visible_objects_t)entry_visible_objects.m_pOriginal)(slot); + } + + // Whether `object` is the unit of view `local`'s player, seen in first person (hidden in that view). + Halo2Entry(entry_own_unit, OFFSET_HALO2_PF_OWN_UNIT_IN_FIRST_PERSON, bool, own_unit, int object, int local) { + if (local < 0 || local > 1 || !s_sync_quad) return ((own_unit_t)entry_own_unit.m_pOriginal)(object, local); + int viewer = Viewer(local); + return viewer < Players(entry_own_unit.m_target - entry_own_unit.m_offset) && + ((own_unit_t)entry_own_unit.m_pOriginal)(object, viewer); + } + + // A first-person model's parts (as the game's first-person sync finds them). + char* ModelComponent(__int64 module, char* object) { + char* model = *(char**)(object + 0x18); + if (model == nullptr) return nullptr; + char* levels = *(char**)(module + OFFSET_HALO2_PV_MODEL_LEVELS); + int level = (unsigned char)levels[*(int*)(module + OFFSET_HALO2_PV_MODEL_LEVELS + 8) - 1]; + unsigned char index = (*(unsigned char**)(*(char**)(model + 0xC0) + 0x10))[level]; + return index == 0xFF ? nullptr : (*(char***)(model + 0xB0))[index]; + } + + // The first-person sync, for the pair: every player's models are built (the game builds players 1 and 2's), and + // each shows only in its owner's view. The game's own only hides, as its owners never change views. + Halo2Entry(entry_first_person, OFFSET_HALO2_PF_FIRST_PERSON_SYNC, void, first_person) { + __int64 module = entry_first_person.m_target - entry_first_person.m_offset; + if (!Quad(module)) return ((first_person_t)entry_first_person.m_pOriginal)(); + for (int player = 0; player < Players(module); ++player) + ((void (*)(int))(module + OFFSET_HALO2_PF_FIRST_PERSON_BUILD))(player); + + char* entries = *(char**)(module + OFFSET_HALO2_PV_FIRST_PERSON_MODELS); + int count = *(int*)(module + OFFSET_HALO2_PV_FIRST_PERSON_MODELS + 8); + for (int i = 0; i < count; ++i) { + char* entry = entries + i * 0x28; + char** handle = *(char***)(entry + 8); + char* object = handle != nullptr ? *handle : nullptr; + if (object == nullptr) continue; + bool active = entry[0x20] != 0, shown = (object[0xC] & 1) != 0; + if (active != shown) + ((void (*)(char*))(module + (active ? OFFSET_HALO2_PF_SABER_OBJECT_SHOW : OFFSET_HALO2_PF_SABER_OBJECT_HIDE)))(object); + + int owner = *(int*)(entry + 0x1C); + char* component = ModelComponent(module, object); + for (int slot = 0; slot < 2; ++slot) { + bool mine = owner == Viewer(slot); + unsigned& views = *(unsigned*)(object + 0x10); + views = mine ? views & ~(0x80u << slot) : views | (0x80u << slot); + if (component == nullptr) continue; + char** parts = *(char***)(component + 0x68); + for (int j = 0; j < *(int*)(component + 0x70); ++j) { + char* part = parts[j]; + unsigned char hidden = (unsigned char)(8 << slot), & flags = *(unsigned char*)(part + 0x50); + void** vtable = *(void***)part; + if (!mine && !(flags & hidden)) { + ((void (*)(char*, int))vtable[0x88 / 8])(part, slot); + flags |= hidden; + } else if (mine && (flags & hidden)) { + if (!(flags & 4)) ((void (*)(char*, int))vtable[0x90 / 8])(part, slot); + flags &= ~hidden; + } + } + } + } + } + + // ---- the frame (render thread): each view is drawn into its player's cell, the cell is kept in a texture of + // ours, and the other pair's cells are put back before the HUD + + bool s_frame_quad = false; + int s_frame_pair = 0, s_frame_players = 0; + bool s_drawn[4] = {}; + bool s_collapse = false; // the game's composite quad covers nothing (CompositeQuad) + ID3D11Texture2D* s_kept = nullptr; // the cells, as last drawn + ID3D11Resource* s_target = nullptr; // the frame's target the views are drawn to + bool s_target_ready = false; // and ours made to match it (PrepareTarget) + // players 3 and 4's exposure (hdr_pass): views 0 and 1's adaptation on their frames, and whether it's kept yet + constexpr int kHdrView = 0x4C, kHdrAdaptation = 0x3C, kHdrAdaptationSize = 0x10; + char s_second_pair_adaptation[2][kHdrAdaptationSize]; + bool s_second_pair_adapting[2] = {}; + + // 3 players: nobody's second view on the second pair's frames + bool NoSecondView() { return s_frame_pair == 1 && s_frame_players < 4; } + + ID3D11DeviceContext* Context(__int64 module) { + return *(ID3D11DeviceContext**)(*(char**)(module + OFFSET_HALO2_PV_SABER_CONTEXT) + 0xD58); + } + + // ---- quarter-size views. The renderer draws a view the size of the target it's drawn into - the "_split" + // textures of its render targets, full width and half height, both views in turn. For as long as quad mode lasts + // they're made half as wide, their cell's size: half the pixels to draw. + + std::mutex s_split_mutex; // both lists: targets are added and deleted off the render thread too + std::vector s_split_textures; // every render target's "_split" textures + + Halo2Entry(entry_add_target, OFFSET_HALO2_PF_SABER_ADD_RENDER_TARGET, char*, add_target, char* set, void* name, + __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9) { + int before = *(int*)(set + 0xC); + char* target = ((add_target_t)entry_add_target.m_pOriginal)(set, name, a3, a4, a5, a6, a7, a8, a9); + int after = *(int*)(set + 0xC); + std::lock_guard lock(s_split_mutex); + for (int i = before; i < after; ++i) { + char* entry = set + 0x10 + i * 0x30; + char* texture = *(char**)entry; + if (texture != nullptr && (*(unsigned*)(entry + 8) & 0x60000000) && + std::find(s_split_textures.begin(), s_split_textures.end(), texture) == s_split_textures.end()) + s_split_textures.push_back(texture); + } + return target; + } + + struct Narrowed { + char* texture; + short width; // as the renderer made it + }; + std::vector s_narrowed; + bool s_views_narrowed = false; // render thread: the last frame was quad mode's, so there may be widths to put back + + // The renderer deletes a texture whatever its reference count (a target set's teardown, a new resolution): it + // leaves both lists first. Nothing the lists' users call on a texture takes the texture manager's lock, which the + // deleting thread may hold. + Halo2Entry(entry_delete_texture, OFFSET_HALO2_PF_SABER_DELETE_TEXTURE, void, delete_texture, char* manager, + int index) { + if (char* texture = (*(char***)(manager + 0x220))[index]) { + std::lock_guard lock(s_split_mutex); + s_split_textures.erase(std::remove(s_split_textures.begin(), s_split_textures.end(), texture), + s_split_textures.end()); + s_narrowed.erase(std::remove_if(s_narrowed.begin(), s_narrowed.end(), + [&](auto& n) { return n.texture == texture; }), + s_narrowed.end()); + } + ((delete_texture_t)entry_delete_texture.m_pOriginal)(manager, index); + } + + // Made again at `width`: its GPU resources released (vtable +0xC8), and its description, which the renderer keeps + // fixed once made (bit 27 of +0x98), set again (+0xA0 makes the resources). + void Remake(char* texture, int width) { + using release_t = void (*)(char*); + using make_t = bool (*)(char*, int width, int height, int mips, int format, int depth, int samples, void*); + void** vtable = *(void***)texture; + ((release_t)vtable[0xC8 / 8])(texture); + unsigned& flags = *(unsigned*)(texture + 0x98); + unsigned fixed = flags & 0x08000000u; + flags &= ~0x08000000u; + ((make_t)vtable[0xA0 / 8])(texture, width, *(short*)(texture + 0x22), *(unsigned char*)(texture + 0x2A), + *(short*)(texture + 0x26), *(short*)(texture + 0x24), *(short*)(texture + 0x28), nullptr); + flags |= fixed; + } + + void QuarterViews(bool on) { + std::lock_guard lock(s_split_mutex); + if (!on) { + for (auto& narrowed : s_narrowed) Remake(narrowed.texture, narrowed.width); + s_narrowed.clear(); + return; + } + int narrowed = 0; + for (char* texture : s_split_textures) { + short width = *(short*)(texture + 0x20); + auto it = std::find_if(s_narrowed.begin(), s_narrowed.end(), [&](auto& n) { return n.texture == texture; }); + if (it != s_narrowed.end() && width == it->width / 2) continue; + if (width < 2) continue; + if (it == s_narrowed.end()) it = s_narrowed.insert(s_narrowed.end(), {texture, width}); + else it->width = width; // the renderer made it again (a new resolution) + Remake(texture, width / 2); + ++narrowed; + } + if (narrowed > 0) + LOG_INFO("Halo 2 Anniversary 3-4 players: {} render targets made cell-sized", narrowed); + } + + Halo2Entry(entry_frame, OFFSET_HALO2_PF_SABER_RENDER_FRAME, void, frame) { + __int64 module = entry_frame.m_target - entry_frame.m_offset; + unsigned flags = *(unsigned*)(*(char**)(module + OFFSET_HALO2_PV_SABER_SCENE) + 0x140); + s_frame_quad = (flags & 1) && (flags & kQuadList); + s_frame_pair = (flags & kSecondPairList) ? 1 : 0; + s_frame_players = Players(module); + memset(s_drawn, 0, sizeof s_drawn); + if (!s_frame_quad) s_second_pair_adapting[0] = s_second_pair_adapting[1] = false; + if (s_frame_quad || s_views_narrowed) QuarterViews(s_frame_quad); + s_views_narrowed = s_frame_quad; + ((frame_t)entry_frame.m_pOriginal)(); + if (s_target != nullptr) { + s_target->Release(); + s_target = nullptr; + } + s_target_ready = false; + } + + // ---- each view's exposure. H2A adapts a view's exposure to its luminance of the frame before (read back a + // frame late, into one of two textures in turn): with the pairs alternating, that was the other pair's picture, + // and player 3's view followed where player 1 looked - washed out while player 1 faced something dark, pulsing as + // both moved. The renderer keeps this for four views; players 3 and 4's frames get their own adaptation and the + // read-back textures of views 2 and 3, which two views never use, for their HDR pass. + + Halo2Entry(entry_hdr_pass, OFFSET_HALO2_PF_SABER_HDR_PASS, void, hdr_pass, __int64 a1, __int64 a2, __int64 a3, + __int64 a4, __int64 a5, __int64 a6, __int64 hdr_view, __int64 a8) { + auto original = (hdr_pass_t)entry_hdr_pass.m_pOriginal; + int view = (int)hdr_view; + if (!s_frame_quad || s_frame_pair != 1 || view < 0 || view > 1) + return original(a1, a2, a3, a4, a5, a6, hdr_view, a8); + __int64 module = entry_hdr_pass.m_target - entry_hdr_pass.m_offset; + char* adaptation = (char*)(module + OFFSET_HALO2_PV_SABER_HDR_VIEWS) + view * kHdrView + kHdrAdaptation; + void** read_backs = (void**)(module + OFFSET_HALO2_PV_SABER_HDR_READ_BACKS) + view * 2; + void** spare = read_backs + 4; // view + 2's + char* mine = s_second_pair_adaptation[view]; + if (!s_second_pair_adapting[view]) { // starting from the first pair's, its frame count started again + memcpy(mine, adaptation, kHdrAdaptationSize); + *(int*)(mine + 0xC) = 0; + s_second_pair_adapting[view] = true; + } + auto exchange = [&] { + std::swap_ranges(adaptation, adaptation + kHdrAdaptationSize, mine); + std::swap_ranges(read_backs, read_backs + 2, spare); + }; + exchange(); + original(a1, a2, a3, a4, a5, a6, hdr_view, a8); + exchange(); + } + + // Copies a cell from the frame's target to ours (keep) or back. + void CopyCell(ID3D11DeviceContext* context, const Cell& cell, bool keep) { + D3D11_BOX box{(UINT)cell.left, (UINT)cell.top, 0, (UINT)cell.right, (UINT)cell.bottom, 1}; + if (keep) context->CopySubresourceRegion(s_kept, 0, cell.left, cell.top, 0, s_target, 0, &box); + else context->CopySubresourceRegion(s_target, 0, cell.left, cell.top, 0, s_kept, 0, &box); + } + + // The view's image drawn into its cell by shaders of ours (CellShaders.h). The game's own composite quad leaves no + // pixels with more than two players, retargeted or not (its stock 3-4 player Anniversary is black too), though its + // target and image are bound; it is kept to bind them and made to cover nothing. + struct CellDrawer { + ID3D11Device* device = nullptr; // not held: the objects below hold it + ID3D11VertexShader* vs = nullptr; + ID3D11PixelShader* ps = nullptr; + ID3D11SamplerState* sampler = nullptr; + ID3D11RasterizerState* raster = nullptr; + + void Release() { + for (IUnknown* held : std::initializer_list{vs, ps, sampler, raster}) + if (held != nullptr) held->Release(); + *this = {}; + } + + bool Ready(ID3D11Device* current) { + if (device == current && raster != nullptr) return true; + Release(); + D3D11_SAMPLER_DESC sampling{}; + sampling.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; + sampling.AddressU = sampling.AddressV = sampling.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; + sampling.MaxLOD = D3D11_FLOAT32_MAX; + D3D11_RASTERIZER_DESC rasterizing{}; + rasterizing.FillMode = D3D11_FILL_SOLID; + rasterizing.CullMode = D3D11_CULL_NONE; + rasterizing.DepthClipEnable = TRUE; + if (FAILED(current->CreateVertexShader(kCellVS, sizeof kCellVS, nullptr, &vs)) || + FAILED(current->CreatePixelShader(kCellPS, sizeof kCellPS, nullptr, &ps)) || + FAILED(current->CreateSamplerState(&sampling, &sampler)) || + FAILED(current->CreateRasterizerState(&rasterizing, &raster))) { + Release(); + return false; + } + device = current; + return true; + } + } s_drawer; + + // The frame's target, at its first view: our kept copy made to its description, and our shaders to its device. + bool PrepareTarget(ID3D11DeviceContext* context, ID3D11RenderTargetView* screen) { + screen->GetResource(&s_target); + ID3D11Texture2D* target = nullptr; + if (s_target == nullptr || FAILED(s_target->QueryInterface(__uuidof(ID3D11Texture2D), (void**)&target))) + return false; + D3D11_TEXTURE2D_DESC desc; + target->GetDesc(&desc); + target->Release(); + if (s_kept != nullptr) { + D3D11_TEXTURE2D_DESC kept; + s_kept->GetDesc(&kept); + if (kept.Width != desc.Width || kept.Height != desc.Height || kept.Format != desc.Format) { + s_kept->Release(); + s_kept = nullptr; + } + } + ID3D11Device* device = nullptr; + context->GetDevice(&device); + if (device == nullptr) return false; + if (s_kept == nullptr) { + desc.MipLevels = desc.ArraySize = 1; + desc.SampleDesc = {1, 0}; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.BindFlags = desc.CPUAccessFlags = desc.MiscFlags = 0; + device->CreateTexture2D(&desc, nullptr, &s_kept); + } + bool ready = s_kept != nullptr && s_drawer.Ready(device); + device->Release(); + return ready; + } + + // Draws `image` into `cell` of the bound target, leaving the pipeline as it was. + void DrawCell(ID3D11DeviceContext* context, ID3D11ShaderResourceView* image, const Cell& cell) { + D3D11_PRIMITIVE_TOPOLOGY topology; + context->IAGetPrimitiveTopology(&topology); + ID3D11InputLayout* layout = nullptr; + context->IAGetInputLayout(&layout); + ID3D11VertexShader* vs = nullptr; + context->VSGetShader(&vs, nullptr, nullptr); + ID3D11HullShader* hs = nullptr; + context->HSGetShader(&hs, nullptr, nullptr); + ID3D11DomainShader* ds = nullptr; + context->DSGetShader(&ds, nullptr, nullptr); + ID3D11GeometryShader* gs = nullptr; + context->GSGetShader(&gs, nullptr, nullptr); + ID3D11PixelShader* ps = nullptr; + context->PSGetShader(&ps, nullptr, nullptr); + ID3D11SamplerState* sampler = nullptr; + context->PSGetSamplers(0, 1, &sampler); + ID3D11RasterizerState* raster = nullptr; + context->RSGetState(&raster); + D3D11_VIEWPORT viewports[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; + UINT viewport_count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; + context->RSGetViewports(&viewport_count, viewports); + ID3D11BlendState* blend = nullptr; + float blend_factor[4]; + UINT sample_mask = 0; + context->OMGetBlendState(&blend, blend_factor, &sample_mask); + ID3D11DepthStencilState* depth = nullptr; + UINT stencil_ref = 0; + context->OMGetDepthStencilState(&depth, &stencil_ref); + + D3D11_VIEWPORT viewport{(float)cell.left, (float)cell.top, (float)(cell.right - cell.left), + (float)(cell.bottom - cell.top), 0.0f, 1.0f}; + context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + context->IASetInputLayout(nullptr); + context->VSSetShader(s_drawer.vs, nullptr, 0); + context->HSSetShader(nullptr, nullptr, 0); + context->DSSetShader(nullptr, nullptr, 0); + context->GSSetShader(nullptr, nullptr, 0); + context->PSSetShader(s_drawer.ps, nullptr, 0); + context->PSSetShaderResources(0, 1, &image); + context->PSSetSamplers(0, 1, &s_drawer.sampler); + context->RSSetState(s_drawer.raster); + context->RSSetViewports(1, &viewport); + context->OMSetBlendState(nullptr, nullptr, 0xFFFFFFFF); + context->OMSetDepthStencilState(nullptr, 0); + context->Draw(3, 0); + + context->IASetPrimitiveTopology(topology); + context->IASetInputLayout(layout); + context->VSSetShader(vs, nullptr, 0); + context->HSSetShader(hs, nullptr, 0); + context->DSSetShader(ds, nullptr, 0); + context->GSSetShader(gs, nullptr, 0); + context->PSSetShader(ps, nullptr, 0); + context->PSSetSamplers(0, 1, &sampler); + context->RSSetState(raster); + context->RSSetViewports(viewport_count, viewports); + context->OMSetBlendState(blend, blend_factor, sample_mask); + context->OMSetDepthStencilState(depth, stencil_ref); + for (IUnknown* held : std::initializer_list{layout, vs, hs, ds, gs, ps, sampler, raster, blend, depth}) + if (held != nullptr) held->Release(); + } + + extern ::Entry entry_composite; + using composite_t = void (*)(void* texture, bool split, int index); + + // The game's composite with its quad collapsed: the view's image, which it leaves bound, for our shaders to draw. + ID3D11ShaderResourceView* CollapsedImage(ID3D11DeviceContext* context, void* texture, bool split, int index) { + s_collapse = true; + ((composite_t)entry_composite.m_pOriginal)(texture, split, index); + s_collapse = false; + ID3D11ShaderResourceView* image = nullptr; + context->PSGetShaderResources(0, 1, &image); + return image; + } + + // Quad mode's frames only. With two players the game's composite runs as it is, under the D3D11 composite clip + // (megabitt01/AlphaRing#23, render/d3d11/Hook.cpp), which fixed its black screen; that clip matches a quad by its + // image being one player's share of the screen tall, which quad mode's half-height images aren't with 3-4. + Halo2Entry(entry_composite, OFFSET_HALO2_PF_SABER_COMPOSITE, void, composite, void* texture, bool split, int index) { + auto original = (composite_t)entry_composite.m_pOriginal; + if (!s_frame_quad || !split || index < 0 || index > 1) return original(texture, split, index); + if (index == 1 && NoSecondView()) return; + __int64 module = entry_composite.m_target - entry_composite.m_offset; + int player = index + 2 * s_frame_pair; + Cell cell = PlayerCell(module, player, s_frame_players, true); + auto context = Context(module); + ID3D11ShaderResourceView* image = CollapsedImage(context, texture, split, index); + ID3D11RenderTargetView* screen = nullptr; + context->OMGetRenderTargets(1, &screen, nullptr); + if (s_target == nullptr && screen != nullptr) s_target_ready = PrepareTarget(context, screen); + if (s_target_ready && image != nullptr) { + if (Spawned(module, player)) DrawCell(context, image, cell); + CopyCell(context, cell, true); + s_drawn[player] = true; + } + if (image != nullptr) image->Release(); + if (screen != nullptr) screen->Release(); + } + + // The game's quad with all four corners on one point. + void CompositeQuad(char* locals) { + if (!s_collapse) return; + for (int i = 0; i < 4; ++i) { + float* vertex = (float*)(locals + 0xC0 + i * 0x18); + vertex[0] = vertex[1] = 0.0f; + } + } + extern ::Entry entry_composite_quad; + ::Entry entry_composite_quad(Halo2EntrySet(), OFFSET_HALO2_SABER_COMPOSITE_DRAW, + MidFunctionThunk(&CompositeQuad, &entry_composite_quad.m_pOriginal, nullptr, 0), + entry_feature); + + Halo2Entry(entry_after_views, OFFSET_HALO2_PF_SABER_AFTER_CAMERAS, void, after_views) { + if (s_frame_quad && s_target_ready) { + __int64 module = entry_after_views.m_target - entry_after_views.m_offset; + for (int player = 0; player < s_frame_players; ++player) + if (!s_drawn[player]) CopyCell(Context(module), PlayerCell(module, player, s_frame_players, true), false); + } + ((after_views_t)entry_after_views.m_pOriginal)(); + } + + // ---- the module unloading (MCC reloads it for the next game): nothing of ours may point into it + + void Reset() { + for (char*& camera : s_cameras) { + _aligned_free(camera); + camera = nullptr; + } + if (s_kept != nullptr) { + s_kept->Release(); + s_kept = nullptr; + } + s_drawer.Release(); + { + std::lock_guard lock(s_split_mutex); + s_split_textures.clear(); + s_narrowed.clear(); + } + s_views_narrowed = false; + for (auto& spawned : s_spawned) spawned = false; + s_pair = s_sync_pair = 0; + s_frame_quad = false; + s_second_pair_adapting[0] = s_second_pair_adapting[1] = false; + } + const bool s_reset = (Halo2EntrySet()->on_remove(&Reset), true); +} diff --git a/src/mcc/module/entry/halo2/halo2.h b/src/mcc/module/entry/halo2/halo2.h index 26cc614d..d49d1d38 100644 --- a/src/mcc/module/entry/halo2/halo2.h +++ b/src/mcc/module/entry/halo2/halo2.h @@ -13,3 +13,14 @@ inline EntrySet* Halo2EntrySet() {return &g_pHalo2EntrySet;}; typedef returnType (*pDetour##_t)(__VA_ARGS__); \ ::Entry name(Halo2EntrySet(), offset, pDetour, entry_feature); \ returnType pDetour(__VA_ARGS__) + +namespace Halo2::Entry { + namespace Players { + int Handle(__int64 module, int local); // local player `local`'s player handle, -1: none (players.cpp) + char* Player(__int64 module, int handle); // that player's data, or null + } + + namespace Splitscreen { + bool ClassicShown(__int64 module); // Classic graphics are on screen (Back switches them in a mission) + } +} From 02e387e06dc3f56f426d660d439c43fc4d7957a5 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Fri, 2 Oct 2026 20:38:35 -0400 Subject: [PATCH 4/7] feat(splitscreen): Anniversary graphics with 3-4 players, a saved choice Everyone's choice, off by default: SplitscreenConfigStore keeps it as -1.anniversary_quad in alpha_ring_splitscreen.cfg, beside the layout (the key the kirklandsig fork uses), loaded with the rest of the file and kept in an atomic, as the layout preference is. Nothing else is written. ClassicGraphicsScope takes it as a Halo CE or Halo 2 mission starts. Chosen, and with every offset of that game's mode in the build, the mission runs the mode whenever it shows Anniversary graphics with 3-4 players - Back switches between Classic and Anniversary in the middle of it, side by side included - and with 3-4 players it keeps Anniversary at the start instead of Classic (side by side still starts in Classic). Off, missions start as before and run none of it. Dev Tools gets a checkbox under the split-screen layout combo. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DPJBucDk2kQ8oms9Kf7NLs --- src/mcc/module/Module.cpp | 9 ++++++ .../module/patch/SplitscreenConfigStore.cpp | 13 +++++++++ src/mcc/module/patch/SplitscreenConfigStore.h | 6 ++++ src/mcc/splitscreen/Splitscreen.cpp | 28 +++++++++++++++++-- src/mcc/splitscreen/Splitscreen.h | 13 ++++++--- 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/mcc/module/Module.cpp b/src/mcc/module/Module.cpp index cc5a1c4d..25ff0a89 100644 --- a/src/mcc/module/Module.cpp +++ b/src/mcc/module/Module.cpp @@ -12,6 +12,7 @@ #include "mcc/module/patch/PatchConfig.h" #include "mcc/module/patch/SplitscreenConfigStore.h" #include "mcc/splitscreen/LeftRight.h" +#include "mcc/splitscreen/Splitscreen.h" #include "global/Global.h" #include "log/DebugFlags.h" @@ -244,6 +245,14 @@ namespace MCC::Module { 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."); + // Everyone's choice for Halo CE and Halo 2 with 3-4 players (mcc/splitscreen/Splitscreen.h), + // saved in alpha_ring_splitscreen.cfg as the layout is. + bool anniversary = MCC::Splitscreen::AnniversaryQuadChosen(); + if (ImGui::Checkbox("Anniversary graphics with 3-4 players (Halo CE, Halo 2; experimental)", &anniversary)) + MCC::Splitscreen::ChooseAnniversaryQuad(anniversary); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("Off: Halo CE and Halo 2 missions with 3 or 4 players start in Classic graphics, as their Anniversary renderers only draw two views. On: they keep Anniversary graphics (when MCC is set to them) and draw every view, also after Back switches graphics in the middle of a mission; side by side still starts in Classic. The renderers still draw two views at a time, so they alternate: players 1 and 2 on one frame, 3 and 4 on the next (each view updates at half the frame rate). Takes effect at the next mission start."); + if (!ImGui::BeginTabBar("patch")) return; // under each game's black-bar controls, disabled while Left / Right is chosen diff --git a/src/mcc/module/patch/SplitscreenConfigStore.cpp b/src/mcc/module/patch/SplitscreenConfigStore.cpp index 1698cd0e..f2d89b85 100644 --- a/src/mcc/module/patch/SplitscreenConfigStore.cpp +++ b/src/mcc/module/patch/SplitscreenConfigStore.cpp @@ -27,6 +27,8 @@ namespace { std::atomic g_twoPlayerLayout{ AlphaRing::SplitscreenConfigStore::TwoPlayerLayout::TopBottom}; std::atomic g_layoutGeneration{0}; + std::atomic g_anniversaryQuad{false}; + constexpr const char* ANNIVERSARY_QUAD_KEY = "anniversary_quad"; // Publishes the layout and bumps the generation only on an actual change, // so re-selecting the current layout never triggers a render-target rebuild. @@ -267,6 +269,8 @@ namespace AlphaRing::SplitscreenConfigStore { } g_twoPlayerLayout.store(layout, std::memory_order_release); + auto quad = g_states.find(MakeKey(-1, ANNIVERSARY_QUAD_KEY)); + g_anniversaryQuad.store(quad != g_states.end() && quad->second != 0.0f, std::memory_order_release); RebuildWrites(); if (migrated) WriteFile(); @@ -291,6 +295,15 @@ namespace AlphaRing::SplitscreenConfigStore { return g_twoPlayerLayout.load(std::memory_order_acquire); } + bool GetAnniversaryQuad() { + return g_anniversaryQuad.load(std::memory_order_acquire); + } + + void SetAnniversaryQuad(bool on) { + Set(-1, ANNIVERSARY_QUAD_KEY, on ? 1.0f : 0.0f); + g_anniversaryQuad.store(on, std::memory_order_release); + } + bool LeftRightAvailable() { using namespace HaloReach::Entry; // and the render hook, which re-applies the table after each level load resets it, with what rebuilds the diff --git a/src/mcc/module/patch/SplitscreenConfigStore.h b/src/mcc/module/patch/SplitscreenConfigStore.h index a41ccbb0..41899996 100644 --- a/src/mcc/module/patch/SplitscreenConfigStore.h +++ b/src/mcc/module/patch/SplitscreenConfigStore.h @@ -44,6 +44,12 @@ namespace AlphaRing::SplitscreenConfigStore { TwoPlayerLayout GetTwoPlayerLayout(); void SetTwoPlayerLayout(TwoPlayerLayout layout, __int64 hModule); + // Halo CE and Halo 2 missions with 3-4 players start in Anniversary graphics instead of Classic + // (MCC::Splitscreen::AnniversaryQuadChosen). Saved as -1.anniversary_quad, off unless saved on; read + // as missions start, so it's kept loaded like the layout preference. + bool GetAnniversaryQuad(); + void SetAnniversaryQuad(bool on); + // This haloreach.dll build has every hook that draws Left/Right: the full-height views' render targets and // their rebuild on a live switch, the CUI variant, the HUD, the black bars, and the render hook that re-applies // the table. On an MCC update where one isn't found (src/offsets) the saved preference is kept, but the stock diff --git a/src/mcc/splitscreen/Splitscreen.cpp b/src/mcc/splitscreen/Splitscreen.cpp index e9699190..a63bf901 100644 --- a/src/mcc/splitscreen/Splitscreen.cpp +++ b/src/mcc/splitscreen/Splitscreen.cpp @@ -8,10 +8,15 @@ #include "../CGameManager.h" #include "log/MatchLog.h" +#include "mcc/CGameGlobal.h" +#include "mcc/module/patch/SplitscreenConfigStore.h" #include "LeftRight.h" #include +namespace Halo1::Entry::Anniversary { bool Available(); } +namespace Halo2::Entry::Anniversary { bool Available(); } + namespace MCC::Splitscreen { DefDetourFunction(__int64, __fastcall, get_index_by_xuid, void* a1, __int64 xuid) { auto p_setting = AlphaRing::Global::MCC::Splitscreen(); @@ -44,18 +49,35 @@ namespace MCC::Splitscreen { static std::atomic s_anniversary_quad_game{-1}; // the Halo CE / Halo 2 game whose mission started with it + bool AnniversaryQuadChosen() { return AlphaRing::SplitscreenConfigStore::GetAnniversaryQuad(); } + void ChooseAnniversaryQuad(bool on) { AlphaRing::SplitscreenConfigStore::SetAnniversaryQuad(on); } bool AnniversaryQuadActive(int game) { return s_anniversary_quad_game == game; } + // The game's 3-4 player mode has all its offsets in this MCC build (always in the one they were written for). + static bool AnniversaryQuadAvailable(int game) { + return game == CGameGlobal::Halo1 ? Halo1::Entry::Anniversary::Available() + : game == CGameGlobal::Halo2 ? Halo2::Entry::Anniversary::Available() + : false; + } + 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); + bool split = p_setting->b_override && game_options != nullptr; // AlphaRing's split screen sets this mission up + bool left_right = split && LeftRight::Chosen() && LeftRight::Supports(game, p_setting->player_count); LeftRight::StartClassicMission(game, left_right); - if (!p_setting->b_override || game_options == nullptr) return; + // Chosen, the 3-4 player mode is set up for the whole mission, whichever graphics it starts in: Back + // switches Halo CE and Halo 2 to Anniversary in the middle of one, side by side included. + bool quad = split && AnniversaryQuadChosen() && AnniversaryQuadAvailable(game); + s_anniversary_quad_game = quad ? game : -1; + if (!split) return; if (p_setting->player_count <= 2 && !left_right) return; bool anniversary = game_options[0] & 1; if (!anniversary) return; + if (quad && !left_right) { + LOG_INFO("Splitscreen: {} players in Anniversary graphics (experimental)", p_setting->player_count); + return; + } LOG_INFO("Splitscreen: {} players{}, starting in Classic graphics", p_setting->player_count, left_right ? " side by side" : ""); diff --git a/src/mcc/splitscreen/Splitscreen.h b/src/mcc/splitscreen/Splitscreen.h index 66d4f345..698dab01 100644 --- a/src/mcc/splitscreen/Splitscreen.h +++ b/src/mcc/splitscreen/Splitscreen.h @@ -9,7 +9,9 @@ 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. + // is cleared only while the engine copies the options, leaving MCC's own setting untouched. With 3-4 + // players (not side by side) both can keep Anniversary instead, an experimental choice + // (module/entry/halo1/anniversary.cpp, module/entry/halo2/anniversary.cpp). class ClassicGraphicsScope { public: // `game`: CGameGlobal::Halo1 or Halo2 @@ -23,8 +25,11 @@ namespace MCC::Splitscreen { } namespace MCC::Splitscreen { - // Halo CE and Halo 2 with 3-4 players in Anniversary graphics: whether the mission running in `game` - // (CGameGlobal::Halo1 or Halo2) started with them chosen. Such a mission draws its 3-4 views whenever - // Anniversary graphics are on screen. + // Halo CE and Halo 2 with 3-4 players in Anniversary graphics: everyone's saved choice (off unless + // chosen), which takes effect as a mission starts, and whether the mission running in `game` + // (CGameGlobal::Halo1 or Halo2) started with it. Such a mission draws its 3-4 views whenever + // Anniversary graphics are on screen; it starts in them unless it's side by side. + bool AnniversaryQuadChosen(); + void ChooseAnniversaryQuad(bool on); bool AnniversaryQuadActive(int game); } From 5d3f2f9b89e3f8bd6c6b153b4c96ad067ae83043 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Wed, 7 Oct 2026 11:56:40 -0400 Subject: [PATCH 5/7] fix(halo1): CE's quarter-size render targets follow the game's textures The parents and children CE's 3-4 player mode kept (and its full-screen image) outlived the game's textures: a render target set let go on a resize (0x20B000 -> 0x1F6BF0) left the frame's swap writing through freed parents, and the children made on the first quad frame could be made against a parent freed meanwhile. - The quarter-size children are made as the game makes its split ones, while their parent is alive, and only while the mode is chosen or the mission runs in it (a choice taken off in a mission holds until the next one, as the rest of the mode does), so a game that never runs it doesn't get them. - The texture manager's delete (0x1F6BF0, a new offset with patterns) is hooked: an entry whose parent goes is dropped, the game's own children put back in first if ours are in it (the frame), and a child of ours or the image that goes is forgotten. - A mission starts in the mode only when every split render target the module made has ours beside it; a choice made after Halo CE made its render targets takes effect the next time it loads. 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 | 3 + lib/game/inc/1.3528.0.0/patterns_halo1.inc | 3 + src/mcc/module/entry/halo1/anniversary.cpp | 132 +++++++++++---------- src/mcc/splitscreen/Splitscreen.cpp | 3 +- 4 files changed, 78 insertions(+), 63 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 059e5fe0..9edb083b 100644 --- a/lib/game/inc/1.3528.0.0/offset_halo1.h +++ b/lib/game/inc/1.3528.0.0/offset_halo1.h @@ -52,6 +52,9 @@ DefOffset(OFFSET_HALO1_PV_SABER_VIEW_IMAGES, 0x2D62890) // texture*[2], current DefOffset(OFFSET_HALO1_PV_SABER_VIEW_IMAGE_INDEX, 0x1B7B11C) DefOffset(OFFSET_HALO1_PV_SABER_SCREEN_IMAGE, 0x2E3D0D0) // texture*, the frame's full-screen image DefOffset(OFFSET_HALO1_PF_SABER_TEXTURE_CREATE_CHILD, 0x1F9D20) // texture* (parent*, name, width, height, -, flags) +// void (manager*, int index) - the texture manager deletes its texture `index` (texture*[] at +0x1B8): its split +// children (+0xA8, +0xB0) first, then the texture itself; a render target set's release (0x20B000) gets here +DefOffset(OFFSET_HALO1_PF_SABER_DELETE_TEXTURE, 0x1F6BF0) DefOffset(OFFSET_HALO1_PF_SABER_CLASSIC_HUD, 0x740B0) // void () - the classic HUD over the image: views 0 and 1, then view -1 DefOffset(OFFSET_HALO1_PF_HUD_VIEW, 0xB29438) // void (int view) - the HUD's view (window, drawing player) DefOffset(OFFSET_HALO1_PF_HUD_VIEW_DRAW, 0xBABD38) // void (int view, state*) - the view's HUD, state 0x29E07C0 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 e19527d5..ba658194 100644 --- a/lib/game/inc/1.3528.0.0/patterns_halo1.inc +++ b/lib/game/inc/1.3528.0.0/patterns_halo1.inc @@ -126,6 +126,9 @@ const OffsetPatterns kHalo1Patterns[] = { {&OFFSET_HALO1_PF_SABER_TEXTURE_CREATE_CHILD, 0x1f9d20, Code, { At("48 89 5C 24 10 48 89 6C 24 18 48 89 74 24 20 57 48 83 EC 40 8B 99 88 00 00 00", 0x0), Rel("E8 ?? ?? ?? ?? 4C 8B E8 48 8D 84 24 90 00 00 00 48 3B F8 74", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_SABER_DELETE_TEXTURE, 0x1f6bf0, Code, { + At("48 89 5C 24 10 56 57 41 56 48 83 EC 20 48 63 C2", 0x0), + Rel("E8 ?? ?? ?? ?? 81 A3 28 01 00 00 FF FF FF DF 48 83 C4 20 5B", 0x1, 0x5, 0x0)}}, {&OFFSET_HALO1_PF_SABER_CLASSIC_HUD, 0x740b0, Code, { At("48 8B C4 57 48 81 EC A0 00 00 00 48 C7 40 98 FE FF FF FF", 0x0), Rel("48 8D 05 ?? ?? ?? ?? 48 89 05 ?? ?? ?? ?? 48 8D 05 ?? ?? ?? ?? 48 89 05 ?? ?? ?? ?? 4C 89 6D 90", 0x3, 0x7, 0x0)}}, diff --git a/src/mcc/module/entry/halo1/anniversary.cpp b/src/mcc/module/entry/halo1/anniversary.cpp index e9299f87..1391767c 100644 --- a/src/mcc/module/entry/halo1/anniversary.cpp +++ b/src/mcc/module/entry/halo1/anniversary.cpp @@ -44,9 +44,6 @@ namespace Halo1::Entry::Anniversary { // hooks, none of these go in either and 3-4 player missions start in Classic. const bool s_requires_split_screen = (entry_feature->Requires(Splitscreen::Hooks()), true); - // Everything the mode hooks and reaches is in this build (MCC::Splitscreen::ClassicGraphicsScope asks). - bool Available() { return entry_feature->Available(); } - int LocalPlayers(__int64 module) { return *(short*)(module + OFFSET_HALO1_PV_PLAYER_COUNT); } int Views(__int64 module) { return std::clamp(LocalPlayers(module), 0, 4); } // The mode is set up for a 3-4 player mission that started with it chosen (its cameras made as split screen @@ -71,26 +68,24 @@ namespace Halo1::Entry::Anniversary { return view >= 0 && view < CameraCount(module) ? Cameras(module)[view] : nullptr; } - // ---- render targets: quarter-size children beside the split ones. The texture manager finds textures by - // name, so ours carry their size, and a resize makes new ones. They're made when quad mode first draws after - // the game made its split children (MakeChildren), so a game that never runs the mode doesn't get them. + // ---- render targets: quarter-size children beside the split ones, made as the game makes those (its parent is + // alive then) while the mode is chosen, so a game that never runs it doesn't get them. The texture manager finds + // textures by name, so ours carry their size, and a resize makes new ones; the manager keeps them until the module + // goes, and a parent's set made again at a size it had takes them back. std::string SizedName(const char* name, int width, int height) { return std::string(name) + "_" + std::to_string(width) + "x" + std::to_string(height); } - struct QuadChild { - std::string name; // to make at width x height, with the split child's flags; empty once taken - int width = 0, height = 0, flags = 0; - char* texture = nullptr; // ours, once made - }; struct QuadChildren { char* parent; - QuadChild child[2]; + char* children[2]; // ours, or the game's split ones while ours are in the parent + bool swapped = false; // ours are in the parent (the frame, below) }; std::mutex s_children_mutex; std::vector s_children; - std::atomic s_children_wanted = false; // the game made a split child since MakeChildren last looked + std::atomic s_image = nullptr; // our full-screen image the quadrants are copied into (the composite) + std::atomic s_children_logged = false; extern ::Entry entry_create_child; // the fifth argument is unused; the sixth's low word is the texture's flags (+0x7C) @@ -106,57 +101,71 @@ namespace Halo1::Entry::Anniversary { char* child = original(parent, name, width, height, unused, flags); int which = EndsWith(name, "_SPLIT_1") ? 0 : EndsWith(name, "_SPLIT_2") ? 1 : -1; if (which >= 0 && child != nullptr) { + // chosen, or the mission running in the mode (the choice taken off in it holds until the next one) + bool wanted = MCC::Splitscreen::AnniversaryQuadChosen() || + MCC::Splitscreen::AnniversaryQuadActive(CGameGlobal::Halo1); + char* quad = wanted + ? original(parent, SizedName((std::string(name) + "_QUAD").c_str(), width / 2, height).c_str(), + width / 2, height, unused, flags) + : nullptr; std::lock_guard lock(s_children_mutex); auto it = std::find_if(s_children.begin(), s_children.end(), [&](auto& e) { return e.parent == parent; }); - if (it == s_children.end()) it = s_children.insert(s_children.end(), {parent}); - it->child[which] = {SizedName((std::string(name) + "_QUAD").c_str(), width / 2, height), width / 2, height, flags}; - s_children_wanted = true; + if (it == s_children.end()) it = s_children.insert(s_children.end(), {parent, {nullptr, nullptr}}); + it->children[which] = quad; + if (quad != nullptr && !s_children_logged.exchange(true)) + LOG_INFO("Halo CE Anniversary 3-4 players: quarter-size render targets made beside the split ones"); } return child; } ::Entry entry_create_child(Halo1EntrySet(), OFFSET_HALO1_PF_SABER_TEXTURE_CREATE_CHILD, (void*)&CreateChild, entry_feature); - // Render thread, before a quad frame: the children wanted, made outside our lock (the game's texture creation - // takes locks of its own), each kept unless the game made its split child again meanwhile. - void MakeChildren() { - if (!s_children_wanted.exchange(false)) return; - struct Wanted { - char* parent; - int which; - QuadChild child; - }; - std::vector wanted; - { - std::lock_guard lock(s_children_mutex); - for (auto& e : s_children) - for (int which = 0; which < 2; ++which) - if (!e.child[which].name.empty()) { - wanted.push_back({e.parent, which, e.child[which]}); - e.child[which].name.clear(); - } - } - auto create = (create_child_t)entry_create_child.m_pOriginal; - int made = 0; - for (auto& w : wanted) { - char* texture = create(w.parent, w.child.name.c_str(), w.child.width, w.child.height, 0, w.child.flags); - if (texture == nullptr) continue; - std::lock_guard lock(s_children_mutex); - auto it = std::find_if(s_children.begin(), s_children.end(), [&](auto& e) { return e.parent == w.parent; }); - if (it == s_children.end() || !it->child[w.which].name.empty()) continue; - it->child[w.which].texture = texture; - ++made; - } - if (made > 0) LOG_INFO("Halo CE Anniversary 3-4 players: {} quarter-size render targets made", made); + // Everything the mode hooks and reaches is in this build, and every split render target the game has made has + // ours beside it - it made none while the mode wasn't chosen (MCC::Splitscreen::ClassicGraphicsScope asks as a + // mission starts; a choice made after this module's render targets takes effect the next time Halo CE loads). + bool Available() { + if (!entry_feature->Available()) return false; + std::lock_guard lock(s_children_mutex); + return std::none_of(s_children.begin(), s_children.end(), + [](auto& e) { return e.children[0] == nullptr || e.children[1] == nullptr; }); + } + + void Swap(QuadChildren& e) { + std::swap(*(char**)(e.parent + 0xA8), e.children[0]); + std::swap(*(char**)(e.parent + 0xB0), e.children[1]); + e.swapped = !e.swapped; } - void SwapChildren() { + // For the frame: ours into every split target that has both (in), the game's back (out). + void SwapChildren(bool in) { std::lock_guard lock(s_children_mutex); - for (auto& e : s_children) { - if (e.child[0].texture == nullptr || e.child[1].texture == nullptr) continue; - std::swap(*(char**)(e.parent + 0xA8), e.child[0].texture); - std::swap(*(char**)(e.parent + 0xB0), e.child[1].texture); + for (auto& e : s_children) + if (e.swapped != in && e.children[0] != nullptr && e.children[1] != nullptr) Swap(e); + } + + // The texture manager deleting its texture `index` (a render target set let go on a resize, for one): nothing of + // ours may point at it after. A parent takes whatever is in its +0xA8/+0xB0 with it, so the game's own children + // go back in first. + Halo1Entry(entry_delete_texture, OFFSET_HALO1_PF_SABER_DELETE_TEXTURE, void, delete_texture, char* manager, + int index) { + if (char* texture = (*(char***)(manager + 0x1B8))[index]) { + std::lock_guard lock(s_children_mutex); + for (auto it = s_children.begin(); it != s_children.end();) { + if (it->swapped && (it->parent == texture || *(char**)(it->parent + 0xA8) == texture || + *(char**)(it->parent + 0xB0) == texture || it->children[0] == texture || + it->children[1] == texture)) + Swap(*it); + if (it->parent == texture) { + it = s_children.erase(it); + continue; + } + for (char*& child : it->children) + if (child == texture) child = nullptr; + ++it; + } + s_image.compare_exchange_strong(texture, nullptr); } + ((delete_texture_t)entry_delete_texture.m_pOriginal)(manager, index); } // ---- cameras: the renderer makes one for the second view; the third and fourth are ours. They are made by @@ -485,7 +494,6 @@ namespace Halo1::Entry::Anniversary { bool s_quad = false; // this frame is drawn in quarters int s_frame_pair = 0; // and shows this pair int s_frame_views = 0; - char* s_image = nullptr; // our full-screen image the quadrants are copied into // 3 players: the second pair's frames have nobody's second view bool NoFourthView(int index) { return s_frame_pair == 1 && index == 1 && s_frame_views < 4; } @@ -514,10 +522,9 @@ namespace Halo1::Entry::Anniversary { if (!s_quad) return ((frame_t)entry_frame.m_pOriginal)(a, b, c, d); s_frame_pair = s_listed_pair; s_frame_views = Views(module); - MakeChildren(); - SwapChildren(); + SwapChildren(true); auto result = ((frame_t)entry_frame.m_pOriginal)(a, b, c, d); - SwapChildren(); + SwapChildren(false); return result; } @@ -527,17 +534,18 @@ namespace Halo1::Entry::Anniversary { char* view = *(char**)(module + OFFSET_HALO1_PV_SABER_VIEW_IMAGES + 8 * (__int64)*(int*)(module + OFFSET_HALO1_PV_SABER_VIEW_IMAGE_INDEX)); int width = ScreenWidth(module), height = ScreenHeight(module); + char* image = s_image; if (view != nullptr) { - if (s_image == nullptr || TextureWidth(s_image) != width || TextureHeight(s_image) != height) - s_image = ((create_child_t)entry_create_child.m_pOriginal)( + if (image == nullptr || TextureWidth(image) != width || TextureHeight(image) != height) + s_image = image = ((create_child_t)entry_create_child.m_pOriginal)( view, SizedName("ALPHARING_QUAD_IMAGE", width, height).c_str(), width, height, 0, *(unsigned short*)(view + 0x7C)); - if (s_image != nullptr && !NoFourthView(camera)) - Copy(module, view, s_image, (camera & 1) * (width / 2), s_frame_pair * (height / 2)); + if (image != nullptr && !NoFourthView(camera)) + Copy(module, view, image, (camera & 1) * (width / 2), s_frame_pair * (height / 2)); } ((composite_t)entry_composite.m_pOriginal)(camera); char* target = *(char**)(module + OFFSET_HALO1_PV_SABER_SCREEN_IMAGE); - if (camera == 1 && s_image != nullptr && target != nullptr) Copy(module, s_image, target, 0, 0); + if (camera == 1 && image != nullptr && target != nullptr) Copy(module, image, target, 0, 0); } // ---- the classic HUD over the image: its pass draws views 0 and 1 in the screen's halves, then view -1 (the @@ -622,8 +630,8 @@ namespace Halo1::Entry::Anniversary { std::lock_guard lock(s_children_mutex); s_children.clear(); } - s_children_wanted = false; s_image = nullptr; + s_children_logged = false; s_extra_cameras[0] = s_extra_cameras[1] = nullptr; // the renderer's heap goes with the module s_quarters = false; s_quad = false; diff --git a/src/mcc/splitscreen/Splitscreen.cpp b/src/mcc/splitscreen/Splitscreen.cpp index a63bf901..e1834ef5 100644 --- a/src/mcc/splitscreen/Splitscreen.cpp +++ b/src/mcc/splitscreen/Splitscreen.cpp @@ -53,7 +53,8 @@ namespace MCC::Splitscreen { void ChooseAnniversaryQuad(bool on) { AlphaRing::SplitscreenConfigStore::SetAnniversaryQuad(on); } bool AnniversaryQuadActive(int game) { return s_anniversary_quad_game == game; } - // The game's 3-4 player mode has all its offsets in this MCC build (always in the one they were written for). + // The game's 3-4 player mode has all its offsets in this MCC build (always in the one they were written for), and + // for Halo CE the render targets it draws into. static bool AnniversaryQuadAvailable(int game) { return game == CGameGlobal::Halo1 ? Halo1::Entry::Anniversary::Available() : game == CGameGlobal::Halo2 ? Halo2::Entry::Anniversary::Available() From 8a3e130697a0da2581c089baf11c65430ace15ea Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Tue, 27 Oct 2026 21:08:16 -0400 Subject: [PATCH 6/7] fix(halo2): two players' Anniversary views each fill their half With two players in Halo 2 Anniversary graphics, the game's composite runs under the D3D11 composite clip from #23. The clip sets the viewport to the player's slot, but the game's quad already places the image in that half, so each view came out squeezed into half of its half: the top quarter and the bottom quarter, with a black band between (seen on master-chief alone, MCC 1.3528 under Proton). Each view is now drawn into its half by the cell shaders the 3-4 player mode uses, and the game's quad isn't drawn, so the clip (DrawIndexed only) doesn't act. Co-Authored-By: Claude Opus 5.5 --- src/mcc/module/entry/halo2/anniversary.cpp | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/mcc/module/entry/halo2/anniversary.cpp b/src/mcc/module/entry/halo2/anniversary.cpp index ad97356e..8574387f 100644 --- a/src/mcc/module/entry/halo2/anniversary.cpp +++ b/src/mcc/module/entry/halo2/anniversary.cpp @@ -6,8 +6,8 @@ // on the next. The views are drawn a quarter of the screen in size (QuarterViews), each camera shaped like its // player's cell in Halo 2's own grid, and each image is drawn into that cell. The other pair's cells are kept in a // texture of ours and put back before the HUD, which Halo 2's window loop already draws for every player. What the -// game works out per view (visible objects, the own body, first-person models) follows the pair. Two players are left -// to the game and the D3D11 composite clip (render/d3d11/Hook.cpp). +// game works out per view (visible objects, the own body, first-person models) follows the pair. With two players each +// view is drawn into its half by the same shaders (composite). #include "halo2.h" #include "mcc/CGameGlobal.h" @@ -585,14 +585,26 @@ namespace Halo2::Entry::Anniversary { return image; } - // Quad mode's frames only. With two players the game's composite runs as it is, under the D3D11 composite clip - // (megabitt01/AlphaRing#23, render/d3d11/Hook.cpp), which fixed its black screen; that clip matches a quad by its - // image being one player's share of the screen tall, which quad mode's half-height images aren't with 3-4. Halo2Entry(entry_composite, OFFSET_HALO2_PF_SABER_COMPOSITE, void, composite, void* texture, bool split, int index) { auto original = (composite_t)entry_composite.m_pOriginal; + __int64 module = entry_composite.m_target - entry_composite.m_offset; + // Two players: the game's quad leaves the screen black under Proton (megabitt01/AlphaRing#23), and the D3D11 + // composite clip that fixed it (render/d3d11/Hook.cpp) draws each image into half of its half - the quad + // already places the image, and the clip's viewport shrinks it again. So each view is drawn into its half by + // our shaders, and the game's quad (and with it the clip, which only takes DrawIndexed) isn't drawn. + if (split && index >= 0 && index <= 1 && !s_frame_quad && Players(module) == 2) { + auto context = Context(module); + ID3D11ShaderResourceView* image = CollapsedImage(context, texture, split, index); + ID3D11Device* device = nullptr; + context->GetDevice(&device); + if (image != nullptr && device != nullptr && s_drawer.Ready(device)) + DrawCell(context, image, PlayerCell(module, index, 2, true)); + if (device != nullptr) device->Release(); + if (image != nullptr) image->Release(); + return; + } if (!s_frame_quad || !split || index < 0 || index > 1) return original(texture, split, index); if (index == 1 && NoSecondView()) return; - __int64 module = entry_composite.m_target - entry_composite.m_offset; int player = index + 2 * s_frame_pair; Cell cell = PlayerCell(module, player, s_frame_players, true); auto context = Context(module); From 6050f4ba45286d8438273d246b0811a4f5b9ff34 Mon Sep 17 00:00:00 2001 From: John P <7864917+kirklandsig@users.noreply.github.com> Date: Thu, 19 Nov 2026 11:56:33 -0500 Subject: [PATCH 7/7] fix(halo2): two players' views keep the game's quad until our shaders are made Two cases from review of the two-player composite: - If our cell shaders can't be made for the device (first frame, or a device recreated), the game's quad was already collapsed and nothing replaced it, so the half stayed black. The shaders are now made first, and without them the game's quad runs under #23's clip, as before. - With no image, the game's composite returns at once and binds nothing, so the view picked up whatever was still bound at t0 and stretched it over its half. With two players a null texture now goes straight to the game's composite. In quad mode the frame's target is still prepared as before, but that view's leftover t0 isn't drawn and its cell isn't marked, so the player's kept picture is put back. Co-Authored-By: Claude Opus 5.5 --- src/mcc/module/entry/halo2/anniversary.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/mcc/module/entry/halo2/anniversary.cpp b/src/mcc/module/entry/halo2/anniversary.cpp index 8574387f..8c6d8a79 100644 --- a/src/mcc/module/entry/halo2/anniversary.cpp +++ b/src/mcc/module/entry/halo2/anniversary.cpp @@ -591,16 +591,22 @@ namespace Halo2::Entry::Anniversary { // Two players: the game's quad leaves the screen black under Proton (megabitt01/AlphaRing#23), and the D3D11 // composite clip that fixed it (render/d3d11/Hook.cpp) draws each image into half of its half - the quad // already places the image, and the clip's viewport shrinks it again. So each view is drawn into its half by - // our shaders, and the game's quad (and with it the clip, which only takes DrawIndexed) isn't drawn. + // our shaders, and the game's quad (and with it the clip, which only takes DrawIndexed) isn't drawn. Until our + // shaders are made for the device, the game's quad runs under the clip as before. if (split && index >= 0 && index <= 1 && !s_frame_quad && Players(module) == 2) { + // No image: the game's composite returns at once and binds nothing, so t0 wouldn't be this view's. + if (texture == nullptr) return original(texture, split, index); auto context = Context(module); - ID3D11ShaderResourceView* image = CollapsedImage(context, texture, split, index); ID3D11Device* device = nullptr; context->GetDevice(&device); - if (image != nullptr && device != nullptr && s_drawer.Ready(device)) - DrawCell(context, image, PlayerCell(module, index, 2, true)); + bool ready = device != nullptr && s_drawer.Ready(device); if (device != nullptr) device->Release(); - if (image != nullptr) image->Release(); + if (!ready) return original(texture, split, index); + ID3D11ShaderResourceView* image = CollapsedImage(context, texture, split, index); + if (image != nullptr) { + DrawCell(context, image, PlayerCell(module, index, 2, true)); + image->Release(); + } return; } if (!s_frame_quad || !split || index < 0 || index > 1) return original(texture, split, index); @@ -609,6 +615,12 @@ namespace Halo2::Entry::Anniversary { Cell cell = PlayerCell(module, player, s_frame_players, true); auto context = Context(module); ID3D11ShaderResourceView* image = CollapsedImage(context, texture, split, index); + // No image: the game's composite bound nothing, so t0 isn't this view's. The frame's target is still prepared + // below; the cell isn't drawn or marked, so the player's kept picture is put back after the views. + if (texture == nullptr && image != nullptr) { + image->Release(); + image = nullptr; + } ID3D11RenderTargetView* screen = nullptr; context->OMGetRenderTargets(1, &screen, nullptr); if (s_target == nullptr && screen != nullptr) s_target_ready = PrepareTarget(context, screen);