Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/REVERSE_ENGINEERING.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,22 @@ Multipliers: high `3.0` (light-count group `10.0`), mid `1.0`, low `0.5` (water

**Not done:** a forced-2P tier as a middle setting for 3P/4P (deliberately deferred — same 5 bytes, would need mutual exclusion with the 1P patch). Open: a per-game Performance-preset capture (low/mid tier values are currently derived, not measured); frame-cost measurement; portability to other Halo titles.

## Per-player HUD (Halo CE, 2, 3, ODST, Reach)

**Known — mechanism.** MCC's host object (`CGameManager`) has three HUD methods the games call while drawing: `+0x2F8` `get_hud_element_anchor(element, int* anchor)`, `+0x300` `get_hud_element_transform(element, float* dx, float* dy, float* scale)` and `+0x308` `transform_hud_color(user, argb)`; MCC's own versions back a feature-flagged HUD editor and the colour-blind filter. Halo CE, 2, 3, ODST and Reach ask for a transform right before placing each HUD element (MCC element ids: 1 motion sensor, 2-5 grenades, 6 shield/health, 7 weapon, 9 crosshair, 11 equipment, 12 messages) and keep the player being drawn in a global; Halo 3, ODST and Reach also pass every HUD colour, with its user, through `+0x308`. `src/mcc/hud` answers for the drawing player, on top of MCC's answer.

| Game | Drawing player | Offset units |
| --- | --- | --- |
| Halo CE | `0x29AF2B8` (int16) | host offsets go to x only, so offsets are added by a hook on `hud_calculate_point` (`0xB56A58`) to each placed point, in the view being drawn (`0x29AF2F0`); scale and hiding still go through the host |
| Halo 2 | `0x165C398` | offset × unit scale (`0xE14F28`) × the element's scale = pixels, in the view's bounds (`0x165C298`, int16 t, l, b, r) |
| Halo 3 | `0xAD317C` | the HUD's virtual canvas (`0xAD3148`, float width, height) |
| ODST | `0xB1AA04` | canvas `0xB1A9D8` |
| Reach | `0xD1F71C` | canvas `0xD1F6F0` |

- **Reach asks for the motion sensor twice.** `UpdatePlayerHudView` (`0x2D94BC`) asks once per view (call at `0x2D96B7`) and bakes the answer into the radar centre the dish and blips draw from (`0xD1F6FC`...); the per-widget lookup `0x2D93A4` (widget anchor string_id → element: `0x80630` motion sensor → 1, `0x80631` → 2 grenades, `0x80632` → 6 shield, `0x80633` → 7 weapon, `0x80634` → 9 crosshair, `0x80635` → 11 equipment) asks again, returning to `0x2D9443`. That second ask is left to MCC, or a dish widget would get its offset and scale twice.
- **The motion sensor is asked for before its view's canvas is set.** Halo 3, ODST and Reach ask for element 1 while they set each view's HUD up, before they store that view's canvas (Halo 3 `0x2ED267`, canvas `0x2ED40C`; ODST `0x3287F5`, `0x328991`; Reach `0x2D96B7`, `0x2D984E`), so the canvas at that ask is still the previous view's - wrong wherever the views differ in size (3 players). The other elements are asked for while the view's widgets are placed (Halo 3 `0x2EDD80`, ODST `0x3292E4`, Reach `0x2D93A4`), after it. `Hud.cpp` keeps each user's canvas from those asks and gives the motion sensor's ask its own view's, as of the frame before. Halo 2 reads its view bounds right after each ask (`0x829490`), so it doesn't have this.
- **Halo 2 and "HUD anchor: Centered"** (the profiles' `LockMaxAspectRatio`, a global at `0x197EE40`, the last loaded profile's). On a screen wider than 16:9, `0x954DD0` insets the whole-screen HUD frame to a centred 16:9 box and `0x7E0A40` splits that box among the players, so every split-screen HUD bunches toward the middle of the screen and the crosshairs leave their views' centres. The embedded patch "HUD at screen edges" (`0x954DF2` `74` → `EB`, off by default) skips the inset - MCC's "HUD anchor: Edge" - with any number of players. Halo 3's `chud_draw_begin` (`0x2ED0D4`) insets each player's own view instead, so it doesn't bunch.

## Other durable findings

### `CPatch` backup-capture idempotency (generic, not Reach-specific)
Expand Down
4 changes: 4 additions & 0 deletions lib/game/inc/1.3528.0.0/offset_halo3.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ DefOffset(OFFSET_HALO3_PF_VIEW_SETUP, 0x282EC4) // void (view*, int slot, int pl
DefOffset(OFFSET_HALO3_PF_TITLE_SAFE, 0x272010) // void (short rect[4] {top, left, bottom, right}) - the screen's title-safe box, 5% in from each edge
DefOffset(OFFSET_HALO3_VIEW_SETUP_TITLE_SAFE_RETURN, 0x282F10) // where the view setup's call to it returns

// Per-player HUD (mcc/hud)
DefOffset(OFFSET_HALO3_PV_HUD_DRAWING_PLAYER, 0xAD317C) // int user whose HUD is being drawn
DefOffset(OFFSET_HALO3_PV_HUD_CANVAS, 0xAD3148) // float width, height of that user's HUD virtual canvas

struct halo3_teb_data_definition {
void* zero;
void* actor;
Expand Down
4 changes: 4 additions & 0 deletions lib/game/inc/1.3528.0.0/offset_halo3odst.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ DefOffset(OFFSET_HALO3ODST_PF_HUD_LAYOUT, 0x3284B4) // record* - +0x94 int canva
DefOffset(OFFSET_HALO3ODST_PF_VIEW_SETUP, 0x2ABAC8) // void (view*, int slot, int players, int, int, void*) - as Halo 3's
DefOffset(OFFSET_HALO3ODST_PF_TITLE_SAFE, 0x29F634) // void (short rect[4]) - the screen's title-safe box, 5% in from each edge
DefOffset(OFFSET_HALO3ODST_VIEW_SETUP_TITLE_SAFE_RETURN, 0x2ABB14) // where the view setup's call to it returns

// Per-player HUD (mcc/hud); see offset_halo3.h
DefOffset(OFFSET_HALO3ODST_PV_HUD_DRAWING_PLAYER, 0xB1AA04)
DefOffset(OFFSET_HALO3ODST_PV_HUD_CANVAS, 0xB1A9D8)
6 changes: 6 additions & 0 deletions lib/game/inc/1.3528.0.0/offset_haloreach.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ DefOffset(OFFSET_HALOREACH_PV_HUD_CANVAS, 0xD1F6F0) // float width, height of th
DefOffset(OFFSET_HALOREACH_DAT_HUD_BASIS, 0xD1F740) // float4[5], ending where the next begins
DefOffset(OFFSET_HALOREACH_DAT_HUD_SCREEN_SCALE_AND_OFFSET, 0xD1F790) // chud_screen_scale_and_offset: float xInset, yInset, halfW, halfH

// Per-player HUD (mcc/hud; the player is DAT_CURRENT_HUD_PLAYER, the canvas PV_HUD_CANVAS). Where the per-widget
// get_hud_element_transform call (0x2D93A4, widget anchor -> element) returns. UpdatePlayerHudView already asks for the
// motion sensor (element 1) once per view and bakes the answer into the radar centre the dish and blips draw from, so a
// dish widget asking again here would get it twice.
DefOffset(OFFSET_HALOREACH_V_HUD_WIDGET_TRANSFORM_RETURN, 0x2D9443)

// Dev Tools' resolution/FOV table dump (mcc/module/Module.cpp)
DefOffset(OFFSET_HALOREACH_PF_GET_SPLITSCREEN_SLOT_TOKEN, 0x53EC8) // unsigned (int slot)
DefOffset(OFFSET_HALOREACH_PF_RESOLVE_HUD_PROFILE, 0x2C2F60) // int (unsigned token)
Expand Down
6 changes: 6 additions & 0 deletions lib/game/inc/1.3528.0.0/patterns_halo3.inc
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,10 @@ const OffsetPatterns kHalo3Patterns[] = {
Rel("E8 ?? ?? ?? ?? 66 83 85 10 09 00 00 50 BA 04 00 00 00 48 8D 4D 70", 0x1, 0x5, 0x0)}},
{&OFFSET_HALO3_VIEW_SETUP_TITLE_SAFE_RETURN, 0x282f10, Code, {
At("E8 ?? ?? ?? ?? 48 8D 15 ?? ?? ?? ?? 49 8B EF 49 8D 47 FC 4A 8D 04 B0 48 8D 0C 80", 0x5)}},
{&OFFSET_HALO3_PV_HUD_DRAWING_PLAYER, 0xad317c, Data, {
Rel("8B 15 ?? ?? ?? ?? F3 0F 59 C1 F3 4C 0F 2C C8 F3 41 0F 10 00", 0x2, 0x6, 0x0),
Rel("48 63 05 ?? ?? ?? ?? 48 69 C8 C8 28 00 00 4A 8B 04 02 8B 94 08 60 14 00 00", 0x3, 0x7, 0x0)}},
{&OFFSET_HALO3_PV_HUD_CANVAS, 0xad3148, Data, {
Rel("F3 0F 11 1D ?? ?? ?? ?? 66 0F 6E 43 14 0F 5B C0 F3 0F 11 35", 0x4, 0x8, 0x0),
Rel("F3 0F 10 05 ?? ?? ?? ?? F3 0F 11 44 24 30 F3 0F 11 4C 24 34", 0x4, 0x8, 0x0)}},
};
6 changes: 6 additions & 0 deletions lib/game/inc/1.3528.0.0/patterns_halo3odst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ const OffsetPatterns kHalo3odstPatterns[] = {
Rel("E8 ?? ?? ?? ?? 66 83 85 10 09 00 00 50 BA 04 00 00 00 48 8D 4D 70", 0x1, 0x5, 0x0)}},
{&OFFSET_HALO3ODST_VIEW_SETUP_TITLE_SAFE_RETURN, 0x2abb14, Code, {
At("E8 ?? ?? ?? ?? 48 8D 15 ?? ?? ?? ?? 49 8B EF 49 8D 47 FC 4A 8D 04 B0 48 8D 0C 80", 0x5)}},
{&OFFSET_HALO3ODST_PV_HUD_DRAWING_PLAYER, 0xb1aa04, Data, {
Rel("44 89 3D ?? ?? ?? ?? E8 ?? ?? ?? ?? 89 05 ?? ?? ?? ?? 41 8B CF 8B 94 3E 68 15 00 00", 0x3, 0x7, 0x0),
Rel("8B 15 ?? ?? ?? ?? 0F 29 74 24 20 F3 0F 10 35 ?? ?? ?? ?? F3 0F 59 C6 F3 4C 0F 2C C8", 0x2, 0x6, 0x0)}},
{&OFFSET_HALO3ODST_PV_HUD_CANVAS, 0xb1a9d8, Data, {
Rel("F3 0F 10 0D ?? ?? ?? ?? F3 0F 11 4D F8 66 0F 6E C0 0F 5B C0", 0x4, 0x8, 0x0),
Rel("F3 0F 10 05 ?? ?? ?? ?? F3 0F 11 44 24 38 F3 0F 11 4C 24 3C", 0x4, 0x8, 0x0)}},
};
2 changes: 2 additions & 0 deletions lib/game/inc/1.3528.0.0/patterns_haloreach.inc
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ const OffsetPatterns kHaloreachPatterns[] = {
{&OFFSET_HALOREACH_DAT_HUD_SCREEN_SCALE_AND_OFFSET, 0xd1f790, Data, {
Rel("F3 0F 58 05 ?? ?? ?? ?? F3 44 0F 10 65 97 45 33 D2 F3 44 0F 10 55 9B", 0x4, 0x8, 0x0),
Rel("F3 0F 10 05 ?? ?? ?? ?? 48 8D 55 A0 F3 0F 10 0D ?? ?? ?? ?? 41 B8 10 00 00 00", 0x4, 0x8, 0x0)}},
{&OFFSET_HALOREACH_V_HUD_WIDGET_TRANSFORM_RETURN, 0x2d9443, Code, {
At("41 FF D2 84 C0 74 51 48 8B 0D ?? ?? ?? ?? 48 85 C9 74 ?? 48 8B 01", 0x3)}},
{&OFFSET_HALOREACH_PF_GET_SPLITSCREEN_SLOT_TOKEN, 0x53ec8, Code, {
At("83 C8 FF 83 F9 03 77 27 8B 15 ?? ?? ?? ?? 65 48 8B 04 25 58 00 00 00 41 B8 58 01 00 00 48 63 C9 48 8B 04 D0 4A 8B 04 00 8B 84 88 B8 00 00 00", 0x0),
Rel("E8 ?? ?? ?? ?? 48 8D 4F 04 8B D8 33 D2 41 B8 9C 01 00 00 E8", 0x1, 0x5, 0x0)}},
Expand Down
3 changes: 3 additions & 0 deletions src/mcc/CGameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ bool CGameManager::Initialize(CGameManager* mng) {
{pGameManager->table->set_state, set_state, (void**)&ppOriginal.set_state},
{pGameManager->table->game_restart, game_restart, (void**)&ppOriginal.game_restart},
{pGameManager->table->game_setup, game_setup, (void**)&ppOriginal.game_setup},
{pGameManager->table->get_hud_element_anchor, get_hud_element_anchor, (void**)&ppOriginal.get_hud_element_anchor},
{pGameManager->table->get_hud_element_transform, get_hud_element_transform, (void**)&ppOriginal.get_hud_element_transform},
{pGameManager->table->transform_hud_color, transform_hud_color, (void**)&ppOriginal.transform_hud_color},
});
}

Expand Down
22 changes: 21 additions & 1 deletion src/mcc/CGameManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "CGameEngine.h"

#include <cstddef>

struct CGameManager {
public:
struct Profile_t {
Expand Down Expand Up @@ -49,6 +51,11 @@
static bool __fastcall get_key_state(CGameManager* self, DWORD index, input_data_t* p_input);
static CGamepadMapping* __fastcall retrive_gamepad_mapping(CGameManager* self, __int64 xid);

// CGameManagerHud.cpp
static bool __fastcall get_hud_element_anchor(CGameManager* self, int element, int* anchor);
static bool __fastcall get_hud_element_transform(CGameManager* self, int element, float* dx, float* dy, float* scale);
static unsigned __fastcall transform_hud_color(CGameManager* self, int user, unsigned argb);

static void __fastcall set_state(CGameManager* self, eState state);
static void* __fastcall game_restart(CGameManager* self, int type, const char* reason);
static char __fastcall game_setup(CGameManager* self, void* a2);
Expand Down Expand Up @@ -93,7 +100,15 @@
// 0x2C0i64 get_xbox_user_id
bool (__fastcall* get_xbox_user_id)(CGameManager* self, __int64* pId, wchar_t* pName, int size, int index);

char pad5[0xD8];
char pad5[0x30];

// 0x2F8..0x308: the games ask MCC for an override of each HUD element before placing it, and
// Halo 3, ODST and Reach pass every HUD colour, with the user it's drawn for, through +0x308.
bool (__fastcall* get_hud_element_anchor)(CGameManager* self, int element, int* anchor);
bool (__fastcall* get_hud_element_transform)(CGameManager* self, int element, float* dx, float* dy, float* scale);
unsigned (__fastcall* transform_hud_color)(CGameManager* self, int user, unsigned argb);

char pad6[0x90];

// 0x3A0i64 retrieve gamepad mapping
CGamepadMapping* (__fastcall* retrive_gamepad_mapping)(CGameManager* self, __int64 xid);
Expand All @@ -105,5 +120,10 @@
Microsoft::Xbox::Telemetry::CELL* cell;
};

static_assert(offsetof(CGameManager::FunctionTable, get_hud_element_anchor) == 0x2F8);
static_assert(offsetof(CGameManager::FunctionTable, get_hud_element_transform) == 0x300);
static_assert(offsetof(CGameManager::FunctionTable, transform_hud_color) == 0x308);
static_assert(offsetof(CGameManager::FunctionTable, retrive_gamepad_mapping) == 0x3A0);

extern CGameManager* pGameManager;
inline CGameManager* GameManager() { return pGameManager; }
33 changes: 33 additions & 0 deletions src/mcc/CGameManagerHud.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "CGameManager.h"

#include "mcc/hud/Hud.h"

#include <intrin.h>

// The games call these host methods from their HUD drawing (MCC's own versions back a feature-flagged HUD editor
// and the colour-blind filter). MCC's answer is kept and the drawing player's HUD settings are added on top - see
// mcc/hud/Hud.h. With a player's settings at their defaults the game gets MCC's answer as it was.

bool CGameManager::get_hud_element_transform(CGameManager* self, int element, float* dx, float* dy, float* scale) {
if (ppOriginal.get_hud_element_transform(self, element, dx, dy, scale)) {
MCC::Hud::Transform(element, dx, dy, scale, _ReturnAddress());
return true;
}
// MCC has none: ours alone, written only when there is one
float x = 0.0f, y = 0.0f, s = 1.0f;
if (!MCC::Hud::Transform(element, &x, &y, &s, _ReturnAddress())) return false;
*dx = x;
*dy = y;
*scale = s;
return true;
}

// Only asked after get_hud_element_transform answered true.
bool CGameManager::get_hud_element_anchor(CGameManager* self, int element, int* anchor) {
if (ppOriginal.get_hud_element_anchor(self, element, anchor)) return true;
return MCC::Hud::Anchor(element, anchor);
}

unsigned CGameManager::transform_hud_color(CGameManager* self, int user, unsigned argb) {
return MCC::Hud::Color(user, ppOriginal.transform_hud_color(self, user, argb));
}
Loading
Loading