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 9edb083b..bf799f1e 100644 --- a/lib/game/inc/1.3528.0.0/offset_halo1.h +++ b/lib/game/inc/1.3528.0.0/offset_halo1.h @@ -4,6 +4,7 @@ DefOffset(OFFSET_HALO1_PF_RENDER, 0x1F05B0) DefOffset(OFFSET_HALO1_PF_GAME_START, 0x939D0) // engine game_start(self, manager, game_options) +DefOffset(OFFSET_HALO1_PF_HS_COMPILE, 0xB21470) // compile + run a console script: (const char* text) DefOffset(OFFSET_HALO1_PF_4PLAYERS, 0x67492) DefOffset(OFFSET_HALO1_PF_PAUSE, 0x427978) @@ -11,6 +12,18 @@ DefOffset(OFFSET_HALO1_PF_IDK, 0x85428) DefOffset(OFFSET_HALO1_PV_PLAYER_COUNT, 0x1B7B910) +// spawning (mcc/spawn; found through the retail cheat_spawn_warthog / cheat_all_chars / ai_attach_free script functions) +DefOffset(OFFSET_HALO1_PV_PLAYERS, 0x1C40480) // players data array*, element 0xC20, unit index at +0x64 +DefOffset(OFFSET_HALO1_PF_TAG_ITERATOR_NEXT, 0xA9B43C) // int (tag_iterator*) +DefOffset(OFFSET_HALO1_PF_TAG_GET_NAME, 0xA9B25C) // const char* (int tag) +DefOffset(OFFSET_HALO1_PF_TAG_GET, 0xA9B648) // void* (int tag) - tag definition data +DefOffset(OFFSET_HALO1_PF_OBJECT_PLACEMENT_DATA_NEW, 0xB35EBC) // (data*, int tag, int owner_object) +DefOffset(OFFSET_HALO1_PF_OBJECT_NEW, 0xB35F80) // int (data*) +DefOffset(OFFSET_HALO1_PF_OBJECT_GET_ORIGIN, 0xB37DE0) // (int object, vector3* out) +DefOffset(OFFSET_HALO1_PF_OBJECT_TRY_AND_GET, 0xB389A4) // void* (int object, unsigned type_mask) - object data, or null +DefOffset(OFFSET_HALO1_PF_ACTOR_CUSTOMIZE_UNIT, 0xC01DD0) // (int actor_variant, int unit) - weapon, grenades, colors +DefOffset(OFFSET_HALO1_PF_AI_ATTACH_FREE, 0xBFF120) // (int unit, int actor_variant) - creates an encounterless actor + // Left/Right split screen (mcc/splitscreen/LeftRight) DefOffset(OFFSET_HALO1_PF_SPLIT_GRID, 0xAC4108) // void (int views, int* columns, int* rows) - the window grid, rows first DefOffset(OFFSET_HALO1_PF_SPLIT_WINDOW, 0xAC4154) // void (int view, int views, short rect[4], short copy[4]) - a view's window @@ -82,3 +95,7 @@ DefOffset(OFFSET_HALO1_PV_FIRST_PERSON_MODELS, 0x2B050E8) // the renderer's firs 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 +// Per-player HUD (mcc/hud, module/entry/halo1/hud.cpp) +DefOffset(OFFSET_HALO1_PF_HUD_CALCULATE_POINT, 0xB56A58) // (player, placement, header, -, bool, float, short2* out, int mcc element) +DefOffset(OFFSET_HALO1_PV_HUD_VIEWPORT_BOUNDS, 0x29AF2F0) // int16 top, left, bottom, right of the view being drawn +DefOffset(OFFSET_HALO1_PV_HUD_DRAWING_PLAYER, 0x29AF2B8) // int16 local player whose HUD is being drawn diff --git a/lib/game/inc/1.3528.0.0/offset_halo2.h b/lib/game/inc/1.3528.0.0/offset_halo2.h index ce8f599a..21e66175 100644 --- a/lib/game/inc/1.3528.0.0/offset_halo2.h +++ b/lib/game/inc/1.3528.0.0/offset_halo2.h @@ -5,6 +5,7 @@ DefOffset(OFFSET_HALO2_PF_LOAD, 0x4F980) DefOffset(OFFSET_HALO2_PF_GAME, 0x67A220) DefOffset(OFFSET_HALO2_PF_COPY_GAME_OPTIONS, 0x39CE0) // copy_game_options(game_options) +DefOffset(OFFSET_HALO2_PF_HS_COMPILE, 0x6E17C0) // compile a console script: (const char* text, bool) DefOffset(OFFSET_HALO2_PF_ADD_LOCAL_PLAYER, 0x69D2C0)//0x69D290 @@ -30,6 +31,24 @@ DefOffset(OFFSET_HALO2_PF_COOP_CAMPAIGN, 0x6A6320) // bool () - a co-op campaign DefOffset(OFFSET_HALO2_PF_COOP_RESPAWN_ALLOWED, 0x6A5D40) // bool () - not with the Iron skull (11), not on Legendary DefOffset(OFFSET_HALO2_PV_SCENARIO, 0xE6F768) // the loaded scenario*: int starting locations +0x100 +// spawning (mcc/spawn) +DefOffset(OFFSET_HALO2_PV_TAG_INSTANCES, 0x15E4B30) // {u32 group, u32 datum, u32 address, u32 size}[tag count] +DefOffset(OFFSET_HALO2_PV_TAG_COUNT, 0x15E4B60) +DefOffset(OFFSET_HALO2_PV_TAG_NAME_OFFSETS, 0x15E4B68) // int32[tag count] into the name buffer +DefOffset(OFFSET_HALO2_PV_TAG_NAMES, 0x15E4B78) +DefOffset(OFFSET_HALO2_PV_TAG_BASE, 0xE80AB0) // tag block address -> map tag data + address +DefOffset(OFFSET_HALO2_PV_SHARED_TAG_BASE, 0xE80AC0) // addresses with the top bit set are in the shared map +// OFFSET_HALO2_PV_PLAYERS (above): data array (data at +*(+0x48)): 0x224 each, unit +0x2C +DefOffset(OFFSET_HALO2_PV_OBJECTS, 0x18B7398) // object headers: data array of 0xC, object data offset +8 +DefOffset(OFFSET_HALO2_PV_OBJECT_MEMORY, 0x18B7360) // object data = ((pool + 0x57) & ~0xF) + offset +DefOffset(OFFSET_HALO2_PF_OBJECT_GET_ORIGIN, 0x8D6780) // (int object, real_point3d*) +DefOffset(OFFSET_HALO2_PF_OBJECT_PLACEMENT_DATA_NEW, 0x8D8880) // (data* [0xC4], int tag, int owner, void*) +DefOffset(OFFSET_HALO2_PF_OBJECT_NEW, 0x8D79D0) // int (data*) +DefOffset(OFFSET_HALO2_PF_AI_PLACE, 0x618890) // (int ai_index); starting location = (3 << 30) | (squad << 16) | location +// int (int ai_index, short, int*, float*) - living actors; a squad's ai index is its index. ai_living_count (0x619B10) +// is a 13-byte thunk to it with 0, null, null, too generic to find again by pattern. +DefOffset(OFFSET_HALO2_PF_AI_LIVING_COUNT, 0x6198E0) + // Left/Right split screen (mcc/splitscreen/LeftRight) DefOffset(OFFSET_HALO2_PF_SPLIT_GRID, 0x7E09D0) // void (int views, int mode, short grid[2] columns, rows) - mode 1 stacks, others side by side DefOffset(OFFSET_HALO2_PF_SPLIT_CELL, 0x7E0BD0) // void (int view, int views, int mode, short grid[2], short cell[2], short span[2]) @@ -81,3 +100,10 @@ DefOffset(OFFSET_HALO2_PV_FIRST_PERSON_MODELS, 0x1AB11C0) // entries*, int count 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*) +// Per-player HUD (mcc/hud). With "HUD anchor: Centered" on a screen wider than 16:9, 0x954DD0 insets the whole-screen +// HUD frame to a centred 16:9 box, which 0x7E0A40 splits among the players. +DefOffset(OFFSET_HALO2_PF_HUD_ASPECT_LOCK, 0x954DF2) // je (74 3C) that skips the centred 16:9 HUD frame when the profile's aspect lock is off +DefOffset(OFFSET_HALO2_PV_HUD_ASPECT_LOCK, 0x197EE40) // bool: the profiles' LockMaxAspectRatio ("HUD anchor: Centered"), the last loaded wins +DefOffset(OFFSET_HALO2_PV_HUD_DRAWING_PLAYER, 0x165C398) // int local player whose HUD is being drawn +DefOffset(OFFSET_HALO2_PV_HUD_VIEW_BOUNDS, 0x165C298) // int16 top, left, bottom, right of that player's HUD (window bounds) +DefOffset(OFFSET_HALO2_PV_HUD_UNIT_SCALE, 0xE14F28) // float: pixels per HUD offset unit (times the element's scale) diff --git a/lib/game/inc/1.3528.0.0/offset_halo3.h b/lib/game/inc/1.3528.0.0/offset_halo3.h index 09236337..c7854ad6 100644 --- a/lib/game/inc/1.3528.0.0/offset_halo3.h +++ b/lib/game/inc/1.3528.0.0/offset_halo3.h @@ -39,6 +39,16 @@ DefOffset(OFFSET_HALO3_PF_OBJECT_PLACEMENT_DATA_NEW, 0x341508) // (data*, int ta DefOffset(OFFSET_HALO3_PF_OBJECT_NEW, 0x341AE8) // int (data*) DefOffset(OFFSET_HALO3_PF_OBJECT_POST_CREATE, 0x1EA04) // (int object) - called by the engine after object_new +// spawning (mcc/spawn), with the three above and OFFSET_HALO3_PV_TAGS_HEADER / OFFSET_HALO3_PV_TAG_NAMES +DefOffset(OFFSET_HALO3_PV_TAG_BASE, 0x1FCF4C8) // tag data = base + (instance address << 2) +DefOffset(OFFSET_HALO3_PV_SCENARIO, 0xA46A08) // scenario tag data* +DefOffset(OFFSET_HALO3_PF_AI_PLACE, 0x577AA4) // (int ai_index, bool) - ai_scripting_place_internal +DefOffset(OFFSET_HALO3_PF_TAG_LOADED, 0x12C9EC) // bool (int tag): in the loaded zone set (object_new refuses others) +// int (int input user) - the player datum that local user controls, -1: none. The player mapping globals (thread-local +// slot +0x110): input user -> player int[4] at +0x4 (what this reads), player -> input user at +0x74, set together +// at 0xEDF70; output users (views) at +0xB4 on. +DefOffset(OFFSET_HALO3_PF_PLAYER_OF_INPUT_USER, 0xEE0D4) + // c_splitscreen_config::m_config_table; the black-bar patches rewrite entries 8, 9 and 12 (0x8AE150, 0x8AE164, 0x8AE1A0) DefOffset(OFFSET_HALO3_PV_SPLITSCREEN_TABLE, 0x8AE0B0)//0x8AD0C0 diff --git a/lib/game/inc/1.3528.0.0/offset_halo3odst.h b/lib/game/inc/1.3528.0.0/offset_halo3odst.h index 01af1a48..21c7e3b7 100644 --- a/lib/game/inc/1.3528.0.0/offset_halo3odst.h +++ b/lib/game/inc/1.3528.0.0/offset_halo3odst.h @@ -16,6 +16,18 @@ DefOffset(OFFSET_HALO3ODST_PF_ADD_LOCAL_PLAYER, 0xFBFE4)//0xFBEE4 #define OFFSET_HALO3ODST_V_ENTRY_PLAYERS 0x2 #define OFFSET_HALO3ODST_V_ENTRY_PLAYERS_ACTION 0xB +// spawning (mcc/spawn; the Halo 3 functions and globals of the same names, matched by signature and call order) +DefOffset(OFFSET_HALO3ODST_PV_TAGS_HEADER, 0x20F3068) +DefOffset(OFFSET_HALO3ODST_PV_TAG_BASE, 0x2022AA8) +DefOffset(OFFSET_HALO3ODST_PV_TAG_NAMES, 0xA9EFC8) +DefOffset(OFFSET_HALO3ODST_PV_SCENARIO, 0xA9C9B8) +DefOffset(OFFSET_HALO3ODST_PF_OBJECT_PLACEMENT_DATA_NEW, 0x37C954) +DefOffset(OFFSET_HALO3ODST_PF_OBJECT_NEW, 0x37CF34) +DefOffset(OFFSET_HALO3ODST_PF_OBJECT_POST_CREATE, 0x20B80) +DefOffset(OFFSET_HALO3ODST_PF_AI_PLACE, 0x5BE6A0) // (int ai_index, bool); ai index type 4 = a squad's single location +DefOffset(OFFSET_HALO3ODST_PF_TAG_LOADED, 0x14D4C8) // bool (int tag): in the loaded zone set (object_new refuses others) +DefOffset(OFFSET_HALO3ODST_PF_PLAYER_OF_INPUT_USER, 0x108EA8) // as Halo 3's (player mapping globals: slot +0x108, set at 0x108D44) + // c_splitscreen_config::m_config_table; the black-bar patches rewrite entries 8, 9 and 12 (0x8F1FB0, 0x8F1FC4, 0x8F2000) DefOffset(OFFSET_HALO3ODST_PV_SPLITSCREEN_TABLE, 0x8F1F10)//0x8F1F20 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 ba658194..bed06e32 100644 --- a/lib/game/inc/1.3528.0.0/patterns_halo1.inc +++ b/lib/game/inc/1.3528.0.0/patterns_halo1.inc @@ -7,6 +7,9 @@ const OffsetPatterns kHalo1Patterns[] = { At("40 57 48 83 EC 40 48 C7 44 24 20 FE FF FF FF 48 89 5C 24 50 48 89 6C 24 60 48 89 74 24 68 8B F2", 0x0)}}, {&OFFSET_HALO1_PF_GAME_START, 0x939d0, Code, { At("40 53 56 57 48 81 EC 50 02 00 00 48 8B 05 ?? ?? ?? ?? 48 33 C4", 0x0)}}, + {&OFFSET_HALO1_PF_HS_COMPILE, 0xb21470, Code, { + At("48 89 5C 24 10 48 89 74 24 18 57 48 81 EC 40 04 00 00", 0x0), + Rel("66 89 0D ?? ?? 22 02 48 8B CA 66 89 05 ?? ?? 22 02 E8 ?? ?? ?? ?? C6 05 ?? ?? ?? ?? 00", 0x12, 0x16, 0x0)}}, {&OFFSET_HALO1_PF_4PLAYERS, 0x67492, Code, { At("85 C0 75 11 C7 05 ?? ?? ?? ?? 04 00 00 00 48 89 35 ?? ?? ?? ?? C6 05 ?? ?? ?? ?? 01", 0x2)}}, {&OFFSET_HALO1_PF_PAUSE, 0x427978, Code, { @@ -16,6 +19,35 @@ const OffsetPatterns kHalo1Patterns[] = { {&OFFSET_HALO1_PV_PLAYER_COUNT, 0x1b7b910, Data, { Rel("0F BF 15 ?? ?? ?? ?? 45 33 FF 48 63 F8 45 8D 77 01 41 2B D6", 0x3, 0x7, 0x0), Rel("0F B7 05 ?? ?? ?? ?? 66 89 81 24 01 00 00 0F B7 8A 58 01 00 00", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PV_PLAYERS, 0x1c40480, Data, { + Rel("48 8B 05 ?? ?? ?? ?? 83 4D FC FF 48 89 45 F0 66 89 7D F8 EB", 0x3, 0x7, 0x0), + Rel("48 8B 35 ?? ?? ?? ?? 33 DB 0F 1F 80 00 00 00 00 44 0F B7 46 22", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO1_PF_TAG_ITERATOR_NEXT, 0xa9b43c, Code, { + At("48 8B 05 ?? ?? ?? ?? 83 CA FF 44 0F BF 41 08 4C 8B C9 44 8B 58 0C", 0x0), + Rel("C7 44 24 68 74 69 6E 75 E8 ?? ?? ?? ?? 41 BE 08 00 00 00 EB", 0x9, 0xd, 0x0)}}, + {&OFFSET_HALO1_PF_TAG_GET_NAME, 0xa9b25c, Code, { + At("48 8B 05 ?? ?? ?? ?? 48 0F BF D1 48 C1 E2 05 48 63 4C 02 10", 0x0), + Rel("E8 ?? ?? ?? ?? 48 89 46 50 48 8B CE 41 0F 10 80 80 00 00 00", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_TAG_GET, 0xa9b648, Code, { + At("48 8B 05 ?? ?? ?? ?? 48 0F BF D1 48 C1 E2 05 48 63 4C 02 14", 0x0), + Rel("E8 ?? ?? ?? ?? 4C 8B C0 41 8B D2 48 63 80 E8 02 00 00 85 C0", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_OBJECT_PLACEMENT_DATA_NEW, 0xb35ebc, Code, { + At("48 89 5C 24 08 48 89 74 24 10 57 48 83 EC 20 41 8B F0 8B DA", 0x0), + Rel("E8 ?? ?? ?? ?? F2 41 0F 10 45 00 F2 0F 11 45 A3 41 8B 45 08", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_OBJECT_NEW, 0xb35f80, Code, { + At("48 83 EC 28 8A 05 ?? ?? ?? ?? 4C 8B C9 F6 D8 45 1B C0 41 83 E0 04", 0x0), + Rel("F3 0F 11 55 B4 E8 ?? ?? ?? ?? 41 83 CB FF 8B D8 41 3B C3 0F 84", 0x6, 0xa, 0x0)}}, + {&OFFSET_HALO1_PF_OBJECT_GET_ORIGIN, 0xb37de0, Code, { + At("48 89 5C 24 08 48 89 74 24 10 57 48 83 EC 20 48 8B 35 ?? ?? ?? ?? 4C 8B D2", 0x0), + Rel("E8 ?? ?? ?? ?? F3 0F 10 06 F3 0F 5C 44 24 20 F3 0F 10 4E 04", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_OBJECT_TRY_AND_GET, 0xb389a4, Code, { + At("40 53 48 83 EC 20 8B DA 8B D1 48 8B 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 4C 8B D8 33 C0 4D 85 DB 74 ?? 41 0F B6 4B 03", 0x0), + Rel("E8 ?? ?? ?? ?? 83 C9 FF 48 85 C0 0F 45 CB 8B C1 48 83 C4 20", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_ACTOR_CUSTOMIZE_UNIT, 0xc01dd0, Code, { + At("48 8B C4 48 89 58 18 55 56 57 41 54 41 55 41 56 41 57 48 81 EC 10 01 00 00", 0x0), + Rel("E8 ?? ?? ?? ?? 8B 06 B9 02 00 00 00 44 88 7C 24 58 45 8B CE", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PF_AI_ATTACH_FREE, 0xbff120, Code, { + At("48 83 EC 68 48 8B 05 ?? ?? ?? ?? 41 BB 02 00 00 00 44 8B C2", 0x0)}}, {&OFFSET_HALO1_PF_SPLIT_GRID, 0xac4108, Code, { At("48 89 5C 24 08 BB 01 00 00 00 4D 8B D8 44 8B CB", 0x0), Rel("E8 ?? ?? ?? ?? 44 8B 5C 24 58 41 8B C3 0F AF 44 24 50 3B C3", 0x1, 0x5, 0x0)}}, @@ -208,4 +240,13 @@ const OffsetPatterns kHalo1Patterns[] = { {&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)}}, + {&OFFSET_HALO1_PF_HUD_CALCULATE_POINT, 0xb56a58, Code, { + At("48 8B C4 48 89 58 18 48 89 70 20 55 57 41 55 41 56", 0x0), + Rel("E8 ?? ?? ?? ?? 0F B7 45 E2 66 89 45 D2 0F B7 C3 66 03 45 4A", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO1_PV_HUD_VIEWPORT_BOUNDS, 0x29af2f0, Data, { + Rel("0F BF 05 ?? ?? ?? ?? F3 0F 59 D7 0F 5B C0 66 0F 6E C8 0F 5B C9", 0x3, 0x7, 0x0), + Rel("44 0F B7 35 ?? ?? ?? ?? 41 0F B7 F4 8A 84 04 D8 00 00 00 FE C8", 0x4, 0x8, 0x0)}}, + {&OFFSET_HALO1_PV_HUD_DRAWING_PLAYER, 0x29af2b8, Data, { + Rel("0F B7 35 ?? ?? ?? ?? B8 03 00 00 00 66 B9 04 00 66 3B F8 75", 0x3, 0x7, 0x0), + Rel("0F BF 0D ?? ?? ?? ?? 89 4D 67 48 8B C8 48 C1 E9 10 48 89 45 6F", 0x3, 0x7, 0x0)}}, }; diff --git a/lib/game/inc/1.3528.0.0/patterns_halo2.inc b/lib/game/inc/1.3528.0.0/patterns_halo2.inc index 5e7b6a96..b8c873bc 100644 --- a/lib/game/inc/1.3528.0.0/patterns_halo2.inc +++ b/lib/game/inc/1.3528.0.0/patterns_halo2.inc @@ -12,6 +12,9 @@ const OffsetPatterns kHalo2Patterns[] = { {&OFFSET_HALO2_PF_COPY_GAME_OPTIONS, 0x39ce0, Code, { At("40 53 48 81 EC 30 03 00 00 48 8B D1 48 8D 1D ?? ?? ?? ?? 48 8B CB", 0x0), Rel("48 8B CF E8 ?? ?? ?? ?? 8B 4F 10 E8 ?? ?? ?? ?? B9 10 00 00 00 48 89 05", 0x4, 0x8, 0x0)}}, + {&OFFSET_HALO2_PF_HS_COMPILE, 0x6e17c0, Code, { + At("48 89 5C 24 08 55 56 57 41 54 41 55 41 56 41 57 48 8D AC 24 C0 EE FF FF", 0x0), + Rel("E8 ?? ?? ?? ?? 4C 8B C3 48 8D 4C 24 20 BA C8 00 00 00 FF 15", 0x1, 0x5, 0x0)}}, {&OFFSET_HALO2_PF_ADD_LOCAL_PLAYER, 0x69d2c0, Code, { At("48 89 5C 24 08 57 48 83 EC 20 48 8B FA 8B D1 48 8B 0D", 0x0), Rel("E8 ?? ?? ?? ?? FF C3 48 81 C7 D4 00 00 00 83 FB 10 7C ?? E8 ?? ?? ?? ?? E8", 0x1, 0x5, 0x0)}}, @@ -44,6 +47,44 @@ const OffsetPatterns kHalo2Patterns[] = { {&OFFSET_HALO2_PV_SCENARIO, 0xe6f768, Data, { Rel("48 8B 05 ?? ?? ?? ?? 8B DE 48 89 7C 24 68 39 98 10 02 00 00", 0x3, 0x7, 0x0), Rel("48 8B 05 ?? ?? ?? ?? 33 D2 4C 63 80 6C 01 00 00 41 83 F8 FF", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PV_TAG_INSTANCES, 0x15e4b30, Data, { + Rel("48 8B 05 ?? ?? ?? ?? 48 03 C9 4C 89 7C 24 50 4C 63 74 C8 08", 0x3, 0x7, 0x0), + Rel("66 90 0F B7 C8 48 8B 05 ?? ?? ?? ?? 48 03 C9 48 63 5C C8 08", 0x8, 0xc, 0x0)}}, + {&OFFSET_HALO2_PV_TAG_COUNT, 0x15e4b60, Data, { + Rel("0F 29 05 ?? ?? ?? ?? 8B 52 2C E8 ?? ?? ?? ?? 0F B6 F8 84 C0 0F 84 ?? ?? ?? ?? 48 8B 1D", 0x3, 0x7, 0x0), + Rel("48 83 EC 20 33 DB 48 89 1D ?? ?? ?? ?? E8 ?? ?? ?? ?? 39 1D ?? ?? ?? ?? 74 ?? 48 8B 15", 0x14, 0x18, 0x0)}}, + {&OFFSET_HALO2_PV_TAG_NAME_OFFSETS, 0x15e4b68, Data, { + Rel("48 8B 05 ?? ?? ?? ?? 48 63 14 90 3B 15 ?? ?? ?? ?? 73 ?? 48 8B C2 48 03 05", 0x3, 0x7, 0x0), + Rel("48 83 EC 20 33 DB 48 89 1D ?? ?? ?? ?? E8 ?? ?? ?? ?? 39 1D ?? ?? ?? ?? 74 ?? 48 8B 15 ?? ?? ?? ??", 0x1d, 0x21, 0x0)}}, + {&OFFSET_HALO2_PV_TAG_NAMES, 0x15e4b78, Data, { + Rel("48 8B 05 ?? ?? ?? ?? 48 63 14 90 3B 15 ?? ?? ?? ?? 73 ?? 48 8B C2 48 03 05 ?? ?? ?? ??", 0x19, 0x1d, 0x0), + Rel("48 89 1D ?? ?? ?? ?? 89 1D ?? ?? ?? ?? 88 1D ?? ?? ?? ?? 48 89 1D ?? ?? ?? ?? 48 89 1D ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 8B 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 89 1D ?? ?? ?? ?? 48 89 1D ?? ?? ?? ?? 48 83 C4 20", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PV_TAG_BASE, 0xe80ab0, Data, { + Rel("4C 8B 05 ?? ?? ?? ?? 48 89 5C 24 40 48 89 7C 24 50 0F 1F 00", 0x3, 0x7, 0x0), + Rel("48 03 0D ?? ?? ?? ?? 48 0F BF C3 48 C1 E0 06 8B 54 08 34 E8", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PV_SHARED_TAG_BASE, 0xe80ac0, Data, { + Rel("0F B7 C9 0F BA F2 1F 48 03 15 ?? ?? ?? ?? 48 6B C1 38 48 03 C2", 0xa, 0xe, 0x0), + Rel("4C 8B 35 ?? ?? ?? ?? 83 F8 FF 74 ?? 85 C0 79 ?? 8B C8 0F BA F1 1F", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PV_OBJECTS, 0x18b7398, Data, { + Rel("48 89 5C 24 10 56 48 83 EC 20 48 8B 05 ?? ?? ?? ?? 33 DB 8B F1", 0xd, 0x11, 0x0), + Rel("75 ?? 8B DE 48 8B 05 ?? ?? ?? ?? 0F B7 C9 48 69 F9 A0 08 00 00", 0x7, 0xb, 0x0)}}, + {&OFFSET_HALO2_PV_OBJECT_MEMORY, 0x18b7360, Data, { + Rel("4C 8D 3C 49 48 8B 0D ?? ?? ?? ?? 42 8B 54 BA 08 E8 ?? ?? ?? ?? 48 8B 15", 0x7, 0xb, 0x0), + Rel("48 8B 0D ?? ?? ?? ?? 8B 54 B2 08 E8 ?? ?? ?? ?? 48 8D 4D D7 4C 8D 48 7C", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PF_OBJECT_GET_ORIGIN, 0x8d6780, Code, { + At("48 89 5C 24 10 48 89 74 24 18 57 48 83 EC 20 48 8B 05 ?? ?? ?? ?? 48 8B FA", 0x0), + Rel("E8 ?? ?? ?? ?? F3 0F 10 55 B4 F3 0F 5C 56 1C F3 0F 10 45 B0", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO2_PF_OBJECT_PLACEMENT_DATA_NEW, 0x8d8880, Code, { + At("48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 48 83 EC 20 41 8B E8 8B DA 33 D2", 0x0), + Rel("E8 ?? ?? ?? ?? F2 0F 10 44 24 20 48 8D 4C 24 30 8B 44 24 28", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO2_PF_OBJECT_NEW, 0x8d79d0, Code, { + At("40 53 55 56 57 41 54 41 55 41 56 41 57 48 81 EC F8 00 00 00 48 C7 44 24 40 FE FF FF FF 48 8B F1", 0x0), + Rel("E8 ?? ?? ?? ?? 83 F8 FF 74 ?? 8B 4F 18 41 B8 04 00 00 00 8B D0", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO2_PF_AI_PLACE, 0x618890, Code, { + At("83 F9 FF 0F 84 ?? ?? ?? ?? 57 48 83 EC 60 8B C1 48 89 5C 24 70", 0x0)}}, + {&OFFSET_HALO2_PF_AI_LIVING_COUNT, 0x6198e0, Code, { + At("48 8B C4 53 57 41 56 48 83 EC 60 0F 29 70 D8 44 8B D1", 0x0), + Rel("45 33 C0 E9 ?? ?? ?? ?? BA 02 00 00 00 45 33 C9 45 33 C0 E9", 0x4, 0x8, 0x0)}}, {&OFFSET_HALO2_PF_SPLIT_GRID, 0x7e09d0, Code, { At("48 89 5C 24 08 BB 01 00 00 00 44 8B D2 44 8B D9", 0x0), Rel("E8 ?? ?? ?? ?? 44 8B 84 24 E0 00 00 00 48 8D 84 24 C8 00 00 00", 0x1, 0x5, 0x0)}}, @@ -153,4 +194,18 @@ const OffsetPatterns kHalo2Patterns[] = { {&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)}}, + {&OFFSET_HALO2_PF_HUD_ASPECT_LOCK, 0x954df2, Code, { + At("74 3C F3 0F 10 15 ?? ?? ?? ?? 66 0F 6E CF 66 0F 6E C3 0F 5B C9", 0x0)}}, + {&OFFSET_HALO2_PV_HUD_ASPECT_LOCK, 0x197ee40, Data, { + Rel("88 05 ?? ?? ?? ?? 48 8B 01 FF 50 60 8B 54 24 54 8B 4C 24 50", 0x2, 0x6, 0x0), + Rel("38 15 ?? ?? ?? ?? 44 0F B7 C2 74 ?? F3 0F 10 15 ?? ?? ?? ?? 66 0F 6E CF 66 0F 6E C3", 0x2, 0x6, 0x0)}}, + {&OFFSET_HALO2_PV_HUD_DRAWING_PLAYER, 0x165c398, Data, { + Rel("8B 0D ?? ?? ?? ?? F3 0F 59 C6 F3 0F 11 44 24 50 F2 0F 10 00", 0x2, 0x6, 0x0), + Rel("48 63 35 ?? ?? ?? ?? 8B CE 48 89 7C 24 60 0F 29 74 24 50 E8", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PV_HUD_VIEW_BOUNDS, 0x165c298, Data, { + Rel("66 41 F7 D8 48 8B 05 ?? ?? ?? ?? 66 F7 DA 48 89 44 24 50 E8", 0x7, 0xb, 0x0), + Rel("0F BF 15 ?? ?? ?? ?? 41 8B F0 45 8B E1 44 8B DA 41 8B FA 66 0F 6E C8", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO2_PV_HUD_UNIT_SCALE, 0xe14f28, Data, { + Rel("F3 0F 11 0D ?? ?? ?? ?? 4C 8D 9C 24 A0 04 00 00 49 8B 73 18", 0x4, 0x8, 0x0), + Rel("0F 5B C0 F3 0F 59 05 ?? ?? ?? ?? F3 0F 2C C0 48 83 C4 28 C3", 0x7, 0xb, 0x0)}}, }; diff --git a/lib/game/inc/1.3528.0.0/patterns_halo3.inc b/lib/game/inc/1.3528.0.0/patterns_halo3.inc index a498ea55..2f7543c6 100644 --- a/lib/game/inc/1.3528.0.0/patterns_halo3.inc +++ b/lib/game/inc/1.3528.0.0/patterns_halo3.inc @@ -78,6 +78,21 @@ const OffsetPatterns kHalo3Patterns[] = { {&OFFSET_HALO3_PF_OBJECT_POST_CREATE, 0x1ea04, Code, { At("4C 8B DC 49 89 5B 08 49 89 6B 18 49 89 73 20 57 41 56 41 57 48 83 EC 50", 0x0), Rel("E8 ?? ?? ?? ?? 8B FB 4C 8D 9C 24 E0 01 00 00 8B C7 49 8B 5B 30", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3_PV_TAG_BASE, 0x1fcf4c8, Data, { + Rel("48 8B 05 ?? ?? ?? ?? 48 8D 0C 90 48 81 C1 3C 03 00 00 33 D2", 0x3, 0x7, 0x0), + Rel("48 8B 05 ?? ?? ?? ?? 48 8D 0C 90 8B 85 10 01 00 00 C1 E8 02", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO3_PV_SCENARIO, 0xa46a08, Data, { + Rel("48 39 15 ?? ?? ?? ?? 8B C1 C7 47 38 00 09 00 02 66 89 4F 3C", 0x3, 0x7, 0x0), + Rel("48 39 15 ?? ?? ?? ?? F2 41 0F 11 03 41 89 43 08 48 0F BE 4E 01", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO3_PF_AI_PLACE, 0x577aa4, Code, { + At("48 89 5C 24 08 48 89 74 24 10 57 48 81 EC 80 00 00 00 83 CF FF", 0x0), + Rel("83 38 FF 74 ?? 8B 08 B2 01 E8 ?? ?? ?? ?? 33 D2 8B CB E8 ?? ?? ?? ?? 48 83 C4 20", 0xa, 0xe, 0x0)}}, + {&OFFSET_HALO3_PF_TAG_LOADED, 0x12c9ec, Code, { + At("83 F9 FF 74 25 48 8B 05 ?? ?? ?? ?? 8B D1 48 C1 E9 05 83 E2 1F", 0x0), + Rel("E8 ?? ?? ?? ?? 84 C0 8B CB 45 0F 45 01 41 8B D0 E8 ?? ?? ?? ?? 48 83 C4 20", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3_PF_PLAYER_OF_INPUT_USER, 0xee0d4, Code, { + At("83 C8 FF 3B C8 74 24 8B 15 ?? ?? ?? ?? 65 48 8B 04 25 58 00 00 00", 0x0), + Rel("E8 ?? ?? ?? ?? 0F B7 C8 49 8B 07 48 63 54 88 34 85 D2 0F 88", 0x1, 0x5, 0x0)}}, {&OFFSET_HALO3_PV_SPLITSCREEN_TABLE, 0x8ae0b0, Data, { Rel("48 8D 0D ?? ?? ?? ?? F3 0F 10 44 91 08 F3 0F 5C 04 91 0F 2F 05", 0x3, 0x7, 0x0)}}, {&OFFSET_HALO3_PV_SCREEN_SIZE, 0x8ac3e8, Data, { diff --git a/lib/game/inc/1.3528.0.0/patterns_halo3odst.inc b/lib/game/inc/1.3528.0.0/patterns_halo3odst.inc index 0cab920a..b71061d5 100644 --- a/lib/game/inc/1.3528.0.0/patterns_halo3odst.inc +++ b/lib/game/inc/1.3528.0.0/patterns_halo3odst.inc @@ -18,6 +18,36 @@ const OffsetPatterns kHalo3odstPatterns[] = { {&OFFSET_HALO3ODST_PF_ADD_LOCAL_PLAYER, 0xfbfe4, Code, { At("48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 48 83 EC 20 44 8B 0D ?? ?? ?? ?? 48 8B FA", 0x0), Rel("44 8A 47 21 48 8D 55 97 41 8B CE E8 ?? ?? ?? ?? 3B C6 74 ?? EB", 0xc, 0x10, 0x0)}}, + {&OFFSET_HALO3ODST_PV_TAGS_HEADER, 0x20f3068, Data, { + Rel("48 8B 1D ?? ?? ?? ?? 45 33 D2 0F BF C2 45 8B DA 3B 43 10 73", 0x3, 0x7, 0x0), + Rel("48 8B 0D ?? ?? ?? ?? FF C7 48 83 C3 10 3B 79 30 7C ?? 48 8B 15", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO3ODST_PV_TAG_BASE, 0x2022aa8, Data, { + Rel("48 8B 15 ?? ?? ?? ?? 4D 8B 5C FE 10 41 0F B7 03 41 8B 4C C0 04", 0x3, 0x7, 0x0), + Rel("48 8B 3D ?? ?? ?? ?? 0F B7 C9 8B 44 CD 04 85 C0 75 ?? 33 F6 EB", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO3ODST_PV_TAG_NAMES, 0xa9efc8, Data, { + Rel("48 8B 1D ?? ?? ?? ?? 0F B7 CD 48 63 04 8B 48 05 00 00 02 00", 0x3, 0x7, 0x0), + Rel("48 89 05 ?? ?? ?? ?? 8B D7 48 8B 01 FF 10 48 89 7C 24 38 33 D2", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO3ODST_PV_SCENARIO, 0xa9c9b8, Data, { + Rel("48 39 15 ?? ?? ?? ?? 8B C1 C7 47 38 00 09 00 03 66 89 4F 3C", 0x3, 0x7, 0x0), + Rel("48 39 15 ?? ?? ?? ?? F2 41 0F 11 03 41 89 43 08 48 0F BE 4E 01", 0x3, 0x7, 0x0)}}, + {&OFFSET_HALO3ODST_PF_OBJECT_PLACEMENT_DATA_NEW, 0x37c954, Code, { + At("48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 48 83 EC 20 41 8B E8 8B DA", 0x0), + Rel("E8 ?? ?? ?? ?? 8B 44 24 48 F2 0F 10 44 24 50 F2 0F 11 45 BC", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3ODST_PF_OBJECT_NEW, 0x37cf34, Code, { + At("48 8B C4 53 55 56 57 41 54 41 55 41 56 41 57 48 81 EC 88 00 00 00", 0x0), + Rel("E8 ?? ?? ?? ?? 8B D8 3B C6 74 ?? 44 8B 8D 20 01 00 00 44 8B C0", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3ODST_PF_OBJECT_POST_CREATE, 0x20b80, Code, { + At("4C 8B DC 49 89 5B 08 49 89 6B 18 49 89 73 20 57 41 56 41 57 48 83 EC 70", 0x0), + Rel("E8 ?? ?? ?? ?? 8B FB 4C 8D 9C 24 C0 01 00 00 8B C7 49 8B 5B 30", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3ODST_PF_AI_PLACE, 0x5be6a0, Code, { + At("48 89 5C 24 08 48 89 74 24 10 48 89 7C 24 18 55 48 8B EC 48 83 EC 70 83 C8 FF", 0x0), + Rel("83 38 FF 74 ?? 8B 08 B2 01 E8 ?? ?? ?? ?? 33 D2 8B CB E8 ?? ?? ?? ?? 48 83 C4 20", 0xa, 0xe, 0x0)}}, + {&OFFSET_HALO3ODST_PF_TAG_LOADED, 0x14d4c8, Code, { + At("83 F9 FF 74 25 48 8B 05 ?? ?? ?? ?? 8B D1 48 C1 E9 05 83 E2 1F", 0x0), + Rel("E8 ?? ?? ?? ?? 84 C0 8B CB 45 0F 45 01 41 8B D0 E8 ?? ?? ?? ?? 48 83 C4 20", 0x1, 0x5, 0x0)}}, + {&OFFSET_HALO3ODST_PF_PLAYER_OF_INPUT_USER, 0x108ea8, Code, { + At("83 C8 FF 3B C8 74 24 8B 15 ?? ?? ?? ?? 65 48 8B 04 25 58 00 00 00", 0x0), + Rel("E8 ?? ?? ?? ?? 0F B7 C8 49 8B 07 48 63 54 88 34 85 D2 0F 88", 0x1, 0x5, 0x0)}}, {&OFFSET_HALO3ODST_PV_SPLITSCREEN_TABLE, 0x8f1f10, Data, { Rel("48 8D 0D ?? ?? ?? ?? F3 0F 10 44 91 08 F3 0F 5C 04 91 0F 2F 05", 0x3, 0x7, 0x0)}}, {&OFFSET_HALO3ODST_PV_SCREEN_SIZE, 0x8f0278, Data, { diff --git a/src/input/MenuConfig.cpp b/src/input/MenuConfig.cpp index ad91e8d1..c9770654 100644 --- a/src/input/MenuConfig.cpp +++ b/src/input/MenuConfig.cpp @@ -310,6 +310,14 @@ MenuConfig MenuConfig::load() { if (vk != 0) cfg.debugKeyboardVKey = vk; else LOG_WARNING("MenuConfig: unknown key '{}' for {}, keeping the default", val, key); } + else if (key == "spawn_menu_controller") { + // the players' spawn menus: a button or combo, or NONE to turn them off + std::string upper = val; + std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper); + WORD mask = upper == "NONE" ? 0 : parseCombo(val); + if (mask != 0 || upper == "NONE") cfg.spawnMenuMask = mask; + else LOG_WARNING("MenuConfig: invalid combo '{}' for {}, keeping the default", val, key); + } else if (key.size() > 2 && key[1] == '_') { // Controller profile binding: "_ = BUTTON" (e.g. d_jump = A) auto profileIt = k_profilePrefixMap.find(key.substr(0, 2)); diff --git a/src/input/MenuConfig.h b/src/input/MenuConfig.h index 5a905a11..ff64b72f 100644 --- a/src/input/MenuConfig.h +++ b/src/input/MenuConfig.h @@ -30,6 +30,8 @@ struct MenuConfig { WORD debugComboMask = XINPUT_GAMEPAD_START | XINPUT_GAMEPAD_RIGHT_THUMB; int keyboardVKey = VK_F4; int debugKeyboardVKey = VK_F1; + // Opens a player's own spawn menu in game (mcc/spawn), on that player's controller; 0 = off. + WORD spawnMenuMask = XINPUT_GAMEPAD_DPAD_DOWN; // The built-in profiles: 0 = Default, 1 = Southpaw, 2 = Boxer, 3 = Green Thumb, // 4 = Bumper Jumper, 5 = Recon. They only seed the custom profiles the first diff --git a/src/mcc/CGameManager.h b/src/mcc/CGameManager.h index a51a03b6..c96fcff1 100644 --- a/src/mcc/CGameManager.h +++ b/src/mcc/CGameManager.h @@ -26,6 +26,7 @@ }; enum eState { + Loading = 0, Running = 1, Exit = 5, Exiting = 10, @@ -38,6 +39,8 @@ static Profile_t* get_profile(int index); static CInputDevice* get_controller(int index); static void apply_profiles(); + // Increments every time a map starts loading. + static unsigned load_generation(); // Local players in the game right now (see CGameManagerSplitscreen.cpp: Halo 4 starts with two). static int active_player_count(); diff --git a/src/mcc/CGameManagerSplitscreen.cpp b/src/mcc/CGameManagerSplitscreen.cpp index cd9cbbf3..3322c453 100644 --- a/src/mcc/CGameManagerSplitscreen.cpp +++ b/src/mcc/CGameManagerSplitscreen.cpp @@ -10,6 +10,8 @@ using AlphaRing::MatchLog::Describe; using AlphaRing::MatchLog::FirstThisMatch; +#include "input/MenuConfig.h" +#include "mcc/spawn/Spawn.h" #include @@ -40,7 +42,13 @@ static constexpr int kDeferredJoinStartPlayers = 2; static constexpr ULONGLONG kDeferredJoinDelayMs = 3000; static std::atomic s_running_since; // 0 until the current session first runs +static std::atomic s_load_generation; + +unsigned CGameManager::load_generation() { return s_load_generation; } + void CGameManager::track_state(eState state) { + if (state == Loading) + ++s_load_generation; if (state == Running && !s_running_since) // also re-sent after level transitions s_running_since = GetTickCount64(); } @@ -126,6 +134,19 @@ bool CGameManager::get_xbox_user_id(CGameManager *self, __int64 *pId, wchar_t *p return result; } +// One player, without AlphaRing's split screen: MCC reads the pads itself, and player 1's spawn menu (mcc/spawn) +// reads the controller the dashboard gives player 1. True while the menu keeps any of it - all of it while open, +// what was held as it closed until released - which MCC's own read can only be kept from by no input at all. +static bool PlayerOneSpawnMenuHasPad() { + auto profile = CGameManager::get_profile(0); + XINPUT_STATE state; + if (!g_menuConfig.spawnMenuMask || !profile || profile->controller_index < 0 || profile->controller_index >= 4 || + !AlphaRing::Input::GetXInputGetState(profile->controller_index, &state)) + return false; + XINPUT_GAMEPAD pad = state.Gamepad; + return MCC::Spawn::HandlePlayerInput(0, pad) || memcmp(&pad, &state.Gamepad, sizeof(pad)) != 0; +} + bool CGameManager::get_key_state(CGameManager *self, DWORD index, input_data_t *p_input) { bool result; LARGE_INTEGER qpc; @@ -150,8 +171,11 @@ bool CGameManager::get_key_state(CGameManager *self, DWORD index, input_data_t * return true; } - if (!p_profile->b_override) + if (!p_profile->b_override) { + if (index == 0 && PlayerOneSpawnMenuHasPad()) + return true; // the game sees player 1 released return ppOriginal.get_key_state(self, index, p_input); + } if (index >= p_profile->player_count) return false; @@ -187,6 +211,11 @@ bool CGameManager::get_key_state(CGameManager *self, DWORD index, input_data_t * if (index < 8 && p_device->state.Gamepad.wButtons != 0 && FirstThisMatch(s_press_seen[index])) MATCH_LOG("input player={} first press buttons={:#06x} (input_user={})", index, p_device->state.Gamepad.wButtons, p_device->input_user); + + // While the player's spawn menu is open it has the pad, which the game sees released; after it closes, what + // was held then is taken out of the pad until released. + if (MCC::Spawn::HandlePlayerInput(index, p_device->state.Gamepad)) + memset(&p_device->state.Gamepad, 0, sizeof(p_device->state.Gamepad)); } result = p_device diff --git a/src/mcc/hud/Hud.cpp b/src/mcc/hud/Hud.cpp index ae0cbf9d..c27b0476 100644 --- a/src/mcc/hud/Hud.cpp +++ b/src/mcc/hud/Hud.cpp @@ -2,6 +2,7 @@ #include "common.h" +#include "mcc/mcc.h" #include "mcc/CGameGlobal.h" #include "mcc/module/Module.h" #include "mcc/splitscreen/LeftRight.h" @@ -140,6 +141,11 @@ namespace MCC::Hud { return nullptr; } + bool Supported() { + __int64 module; + return MCC::IsInGame() && CurrentGame(module) != nullptr; + } + static int ElementOf(const Game& game, int game_element) { return game_element >= 0 && game_element < 16 ? game.elements[game_element] : -1; } @@ -286,8 +292,7 @@ namespace MCC::Hud { static const char* kElementNames[kElementCount] = {"Motion tracker", "Shield / health", "Weapon / ammo", "Grenades", "Crosshair", "Equipment", "Messages"}; - static const char* const kAreaNames[kAreaCount] = {"Game default", "Screen edges", "21:9 box", "16:9 box", - "4:3 box"}; + const char* const kAreaNames[kAreaCount] = {"Game default", "Screen edges", "21:9 box", "16:9 box", "4:3 box"}; // Edits a copy of the player's settings, published whole when something changed. static void PlayerTab(int p) { diff --git a/src/mcc/hud/Hud.h b/src/mcc/hud/Hud.h index 0a7098eb..6c537d73 100644 --- a/src/mcc/hud/Hud.h +++ b/src/mcc/hud/Hud.h @@ -25,6 +25,7 @@ namespace MCC::Hud { constexpr float kFullWidth = 100.0f; constexpr float kAreas[] = {0.0f, kFullWidth, 21.0f / 9.0f, 16.0f / 9.0f, 4.0f / 3.0f}; constexpr int kAreaCount = sizeof(kAreas) / sizeof(*kAreas); + extern const char* const kAreaNames[kAreaCount]; struct PlayerHud { float scale = 1.0f; // every element @@ -49,9 +50,12 @@ namespace MCC::Hud { bool Anchor(int game_element, int* anchor); unsigned Color(int user, unsigned argb); + // The running game's HUD can be customized (in a mission of a game above, with all its offsets). + bool Supported(); + // Halo CE: pixels to move `element` of `player`'s HUD within a view of the given size. bool OffsetCE(int player, int game_element, float view_width, float view_height, float* dx, float* dy); - // The HUD window (overlay menu bar). + // The HUD window (overlay menu bar); each player's spawn menu has a HUD page too (mcc/spawn). void ImGuiContext(); } diff --git a/src/mcc/module/entry/halo1/anniversary.cpp b/src/mcc/module/entry/halo1/anniversary.cpp index 1391767c..fe1efbf3 100644 --- a/src/mcc/module/entry/halo1/anniversary.cpp +++ b/src/mcc/module/entry/halo1/anniversary.cpp @@ -623,6 +623,9 @@ namespace Halo1::Entry::Anniversary { ::Entry entry_overlay_rect(Halo1EntrySet(), OFFSET_HALO1_SABER_VIEW_OVERLAY_RECT, MidFunctionThunk(&OverlayRect, &entry_overlay_rect.m_pOriginal, nullptr, 0), entry_feature); + // Quad mode is drawing, as of the last sync: three players are in quarters, as four are. + bool QuadShown() { return s_sync_quad; } + // ---- the module unloading (MCC reloads it for the next game): nothing of ours may point into it void Reset() { diff --git a/src/mcc/module/entry/halo1/console.cpp b/src/mcc/module/entry/halo1/console.cpp new file mode 100644 index 00000000..aeb2ef47 --- /dev/null +++ b/src/mcc/module/entry/halo1/console.cpp @@ -0,0 +1,19 @@ +#include "halo1.h" + +#include "mcc/CGameGlobal.h" +#include "mcc/spawn/Command.h" + +namespace MCC::Spawn::Halo1 { const AlphaRing::Feature& Offsets(); } + +namespace Halo1::Entry::Console { + // Game-thread entry for AlphaRing commands, see mcc/spawn/Command.h. Only spawning posts them, so the hook goes + // in only where Halo CE's spawning has every offset it uses (mcc/spawn/halo1.cpp). + EntryFeature("Halo CE spawning commands", OFFSET_HALO1_PF_HS_COMPILE); + const bool s_requires_spawning = (entry_feature->Requires(MCC::Spawn::Halo1::Offsets()), true); + + Halo1Entry(entry, OFFSET_HALO1_PF_HS_COMPILE, void, detour, const char* text) { + if (MCC::Command::Dispatch(CGameGlobal::Halo1, text)) + return; + ((detour_t)entry.m_pOriginal)(text); + } +} diff --git a/src/mcc/module/entry/halo2/console.cpp b/src/mcc/module/entry/halo2/console.cpp new file mode 100644 index 00000000..16ec1624 --- /dev/null +++ b/src/mcc/module/entry/halo2/console.cpp @@ -0,0 +1,19 @@ +#include "halo2.h" + +#include "mcc/CGameGlobal.h" +#include "mcc/spawn/Command.h" + +namespace MCC::Spawn::Halo2 { const AlphaRing::Feature& Offsets(); } + +namespace Halo2::Entry::Console { + // Game-thread entry for AlphaRing commands, see mcc/spawn/Command.h. Only spawning posts them, so the hook goes + // in only where Halo 2's spawning has every offset it uses (mcc/spawn/halo2.cpp). + EntryFeature("Halo 2 spawning commands", OFFSET_HALO2_PF_HS_COMPILE); + const bool s_requires_spawning = (entry_feature->Requires(MCC::Spawn::Halo2::Offsets()), true); + + Halo2Entry(entry, OFFSET_HALO2_PF_HS_COMPILE, bool, detour, const char* text, bool flag) { + if (MCC::Command::Dispatch(CGameGlobal::Halo2, text)) + return false; + return ((detour_t)entry.m_pOriginal)(text, flag); + } +} diff --git a/src/mcc/module/entry/halo3/world.cpp b/src/mcc/module/entry/halo3/world.cpp index db1e741b..2c4bc21a 100644 --- a/src/mcc/module/entry/halo3/world.cpp +++ b/src/mcc/module/entry/halo3/world.cpp @@ -2,6 +2,9 @@ #include "common.h" +#include "mcc/CGameGlobal.h" +#include "mcc/spawn/Command.h" + #include #include @@ -25,6 +28,7 @@ namespace Halo3::Entry::World { } void Prologue() { + MCC::Command::Tick(CGameGlobal::Halo3); // spawning's tasks due on this tick (mcc/spawn/Command.h) ExecuteTask(); } @@ -38,3 +42,7 @@ namespace Halo3::Entry::World { Epilogue(); } } + +// Spawning's engine calls must run on this (the simulation) thread (mcc/spawn/Command.h). +static const bool s_registered_scheduler = + (MCC::Command::RegisterScheduler(CGameGlobal::Halo3, Halo3::Entry::World::AddTask), true); diff --git a/src/mcc/module/entry/halo3odst/world.cpp b/src/mcc/module/entry/halo3odst/world.cpp index 9c079afb..43e481bb 100644 --- a/src/mcc/module/entry/halo3odst/world.cpp +++ b/src/mcc/module/entry/halo3odst/world.cpp @@ -1,6 +1,9 @@ #include "halo3odst.h" #include "common.h" + +#include "mcc/CGameGlobal.h" +#include "mcc/spawn/Command.h" #include #include @@ -24,6 +27,7 @@ namespace Halo3ODST::Entry::World { } void Prologue() { + MCC::Command::Tick(CGameGlobal::Halo3ODST); // spawning's tasks due on this tick (mcc/spawn/Command.h) ExecuteTask(); } @@ -37,3 +41,7 @@ namespace Halo3ODST::Entry::World { Epilogue(); } } + +// Spawning's engine calls must run on this (the simulation) thread (mcc/spawn/Command.h). +static const bool s_registered_scheduler = + (MCC::Command::RegisterScheduler(CGameGlobal::Halo3ODST, Halo3ODST::Entry::World::AddTask), true); diff --git a/src/mcc/spawn/Backend.h b/src/mcc/spawn/Backend.h new file mode 100644 index 00000000..15ae9d02 --- /dev/null +++ b/src/mcc/spawn/Backend.h @@ -0,0 +1,146 @@ +#pragma once + +// Helpers shared by the per-game spawn backends (implementation detail of mcc/spawn). + +#include "Spawn.h" +#include "Command.h" + +#include +#include +#include + +namespace MCC::Spawn { + struct Vector3 { float x, y, z; }; + + // Calls a function inside a game module: EngineCall(game, rva, args...). + template + inline R EngineCall(int game, __int64 rva, A... args) { + return reinterpret_cast(MCC::Command::ModuleBase(game) + rva)(args...); + } + + // Reads a global variable of a game module. + template + inline T EngineGlobal(int game, __int64 rva) { return *(T*)(MCC::Command::ModuleBase(game) + rva); } + + // Blam group tags are four characters packed big-endian: 'vehi' -> 0x76656869. + constexpr unsigned int GroupTag(const char (&s)[5]) { + return (unsigned)s[0] << 24 | (unsigned)s[1] << 16 | (unsigned)s[2] << 8 | (unsigned)s[3]; + } + + // Where to put a spawned object: `distance` ahead of an origin along its horizontal + // facing, raised by `height`, facing the same way. + struct Placement { + Vector3 position, forward, up; + // Yaw of a character standing here looking back at the player. + float YawToPlayer() const { return std::atan2(-forward.y, -forward.x); } + }; + + inline Placement PlaceAhead(const Vector3& origin, const Vector3& facing, float distance, float height) { + float fx = facing.x, fy = facing.y; + float length = std::sqrt(fx * fx + fy * fy); + if (length < 1e-3f) { fx = 1.0f; fy = 0.0f; } else { fx /= length; fy /= length; } + return {{origin.x + fx * distance, origin.y + fy * distance, origin.z + height}, {fx, fy, 0.0f}, {0.0f, 0.0f, 1.0f}}; + } + + inline float Distance2(const Vector3& a, const Vector3& b) { + float dx = a.x - b.x, dy = a.y - b.y, dz = a.z - b.z; + return dx * dx + dy * dy + dz * dz; + } + + // Weapon tags nobody can carry: mounted on a vehicle or a stand, or built into a character + // (a Monitor's welder beam). + inline bool MountedWeapon(const char* path) { + return path == nullptr || strstr(path, "\\turrets\\") || strstr(path, "\\vehicles\\") || + strstr(path, "\\characters\\") || strstr(path, "_integrated"); + } + + // The most common of the weapons voted for (tag -> votes), or -1. + template + inline int MostVoted(const Votes& votes) { + int best = -1, most = 0; + for (auto& [weapon, count] : votes) + if (count > most) { best = weapon; most = count; } + return best; + } + + // Writes a value over game data for as long as it's in scope, then puts the old one back + // (also if the game faults in the meantime: see Command::RecordChange). + template + struct ScopedPoke { + T* at = nullptr; + T saved{}; + + ScopedPoke() = default; + ScopedPoke(const ScopedPoke&) = delete; + ScopedPoke& operator=(const ScopedPoke&) = delete; + ~ScopedPoke() { + if (at == nullptr) return; + *at = saved; + MCC::Command::ForgetChange(at); + } + + void Set(T* where, T value) { + MCC::Command::RecordChange(where, sizeof(T)); + at = where; + saved = *where; + *where = value; + } + }; + + // Squads arm their actors from the scenario's weapon palette (H2/H3/ODST): the index of the + // palette entry that places `weapon` - its own entry, or else the last one, lent to `weapon` + // through `lent` - or -1 for none. `tag_at(i)` is the tag index of entry i of `count`. + template + short WeaponPaletteIndex(int weapon, int count, TagAt tag_at, ScopedPoke& lent) { + if (weapon == -1 || count == 0) return -1; + for (short i = 0; i < count; ++i) + if (*tag_at(i) == weapon) return i; + lent.Set(tag_at(count - 1), weapon); + return (short)(count - 1); + } + + // Blam team indices: 2 human (the players' side), 3 covenant; `own` keeps the character's. + inline short EngineTeam(Team team, short own) { return team == TeamAlly ? 2 : team == TeamEnemy ? 3 : own; } + + inline std::string SpawnResult(bool spawned, const std::string& name) { + return (spawned ? "Spawned " : "Couldn't spawn ") + name; + } + + // Spawn distances per category: vehicles need room, pickups land at the player's feet. + inline float SpawnDistance(Category category) { + switch (category) { + case Vehicles: return 5.0f; + case Characters: return 3.0f; + default: return 1.5f; + } + } + + // "objects\characters\brute\ai\brute_captain" -> "Brute Captain": the last part of a tag + // path, in words. Short vowel-less words are acronyms ("smg" -> "SMG", "br_ammo" -> "BR Ammo"). + inline std::string DisplayName(const char* path) { + const char* start = path ? path : ""; + if (const char* slash = strrchr(start, '\\')) start = slash + 1; + + std::string name, word; + auto flush = [&] { + if (word.empty()) return; + bool acronym = word.size() <= 4 && word.find_first_of("aeiouy") == std::string::npos; + for (auto& c : word) c = acronym ? (char)toupper((unsigned char)c) : c; + word[0] = (char)toupper((unsigned char)word[0]); + if (word == "Odst") word = "ODST"; + name += (name.empty() ? "" : " ") + word; + word.clear(); + }; + for (const char* p = start; *p; ++p) { + if (*p == '_' || *p == ' ') flush(); + else word += *p; + } + flush(); + return name.empty() ? "Unnamed" : name; + } + + // "Marine" armed with objects\weapons\rifle\battle_rifle -> "Marine with Battle Rifle". + inline std::string WithWeapon(const std::string& name, const char* weapon_path) { + return name + " with " + DisplayName(weapon_path); + } +} diff --git a/src/mcc/spawn/Command.cpp b/src/mcc/spawn/Command.cpp new file mode 100644 index 00000000..c95d19d5 --- /dev/null +++ b/src/mcc/spawn/Command.cpp @@ -0,0 +1,185 @@ +#include "Command.h" + +#include "common.h" + +#include "mcc/mcc.h" +#include "mcc/CGameEngine.h" +#include "mcc/CGameGlobal.h" +#include "mcc/CGameManager.h" +#include "mcc/module/Module.h" + +#include +#include +#include +#include +#include +#include + +namespace MCC::Command { + static constexpr const char* kPrefix = "@ar "; + static constexpr int kGames = MCC::Module::MODULE_MCC; // one slot per game module + + static std::unordered_map& Handlers() { + static std::unordered_map handlers; + return handlers; + } + + void Register(const char* verb, Handler handler) { + Handlers()[verb] = handler; + } + + static Scheduler s_schedulers[kGames]; // constant-initialized, so safe to fill from static initializers + + void RegisterScheduler(int game, Scheduler scheduler) { + if ((unsigned)game < kGames) s_schedulers[game] = scheduler; + } + + // A task belongs to the map it was queued in: after another map loads it would act on the + // new map's data, so it's dropped. + bool Schedule(int game, const std::function& task) { + if ((unsigned)game >= kGames || s_schedulers[game] == nullptr) return false; + s_schedulers[game]([generation = CGameManager::load_generation(), task] { + if (generation == CGameManager::load_generation()) task(); + }); + return true; + } + + // Tasks due on a tick of their own (ScheduleAfter), per game; its simulation thread only. + struct Delayed { + unsigned long long due; + unsigned generation; + std::function task; + }; + static struct { unsigned long long tick = 0; std::vector tasks; } s_delayed[kGames]; + + bool ScheduleAfter(int game, int ticks, const std::function& task) { + if ((unsigned)game >= kGames || s_schedulers[game] == nullptr) return false; + auto& delayed = s_delayed[game]; + delayed.tasks.push_back({delayed.tick + ticks, CGameManager::load_generation(), task}); + return true; + } + + void Tick(int game) { + if ((unsigned)game >= kGames) return; + auto& delayed = s_delayed[game]; + ++delayed.tick; + if (delayed.tasks.empty()) return; + + // taken out first: a task may schedule another + std::vector> due; + unsigned generation = CGameManager::load_generation(); + for (size_t i = 0; i < delayed.tasks.size();) { + auto& entry = delayed.tasks[i]; + if (entry.generation == generation && entry.due > delayed.tick) { ++i; continue; } + if (entry.generation == generation) due.push_back(std::move(entry.task)); // else another map's: dropped + delayed.tasks.erase(delayed.tasks.begin() + i); + } + for (auto& task : due) task(); + } + + __int64 ModuleBase(int game) { + auto p_module = MCC::Module::GetSubModule(game); + return p_module ? p_module->info().hModule : 0; + } + + bool Post(const char* format, ...) { + auto p_engine = GameEngine(); + auto p_global = GameGlobal(); + if (p_engine == nullptr || p_global == nullptr || !MCC::IsInGame()) + return false; + + char text[1024]; + int written = snprintf(text, sizeof(text), "%s", kPrefix); + va_list args; + va_start(args, format); + vsnprintf(text + written, sizeof(text) - written, format, args); + va_end(args); + + int game = p_global->current_game; + std::string command = text; + if (!Schedule(game, [game, command] { Dispatch(game, command.c_str()); })) + p_engine->execute_command("HS: %s", text); // reaches the console hook on the game thread + return true; + } + + static Args Tokenize(const char* text) { + Args args; + std::string current; + bool quoted = false, has_token = false; + for (const char* p = text; *p; ++p) { + if (*p == '"') { quoted = !quoted; has_token = true; continue; } + if (!quoted && (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n')) { + if (has_token) { args.push_back(current); current.clear(); has_token = false; } + continue; + } + current += *p; + has_token = true; + } + if (has_token) args.push_back(current); + return args; + } + + struct Change { + char* at; + std::vector saved; + }; + static thread_local std::vector t_changes; + + void RecordChange(void* at, size_t size) { + t_changes.push_back({(char*)at, std::vector((char*)at, (char*)at + size)}); + } + + void ForgetChange(void* at) { + for (auto it = t_changes.rbegin(); it != t_changes.rend(); ++it) + if (it->at == at) { + t_changes.erase(std::next(it).base()); + return; + } + } + + // After a fault: the recorded changes, newest first. + static void RestoreChanges() { + for (auto it = t_changes.rbegin(); it != t_changes.rend(); ++it) + memcpy(it->at, it->saved.data(), it->saved.size()); + t_changes.clear(); + } + + static int RecordFault(EXCEPTION_POINTERS* info, DWORD* code, void** address) { + *code = info->ExceptionRecord->ExceptionCode; + *address = info->ExceptionRecord->ExceptionAddress; + return EXCEPTION_EXECUTE_HANDLER; + } + + // Engine calls made by handlers can fault on unexpected game state; keep the game alive. + static bool CallHandler(Handler handler, int game, const Args& args, DWORD* code, void** address) { + __try { + handler(game, args); + t_changes.clear(); // anything a handler recorded is back by now + return true; + } __except (RecordFault(GetExceptionInformation(), code, address)) { + RestoreChanges(); + return false; + } + } + + bool Dispatch(int game, const char* text) { + if (text == nullptr || strncmp(text, kPrefix, strlen(kPrefix)) != 0) + return false; + + auto args = Tokenize(text + strlen(kPrefix)); + if (args.empty()) return true; + + auto it = Handlers().find(args[0]); + if (it == Handlers().end()) { + LOG_WARNING("Command: unknown '{}'", args[0]); + return true; + } + + DWORD code = 0; + void* address = nullptr; + if (!CallHandler(it->second, game, args, &code, &address)) + LOG_ERROR("Command: '{}' faulted ({:#x} at module+{:#x})", text + strlen(kPrefix), code, + (unsigned __int64)address - (unsigned __int64)ModuleBase(game)); + return true; + } +} diff --git a/src/mcc/spawn/Command.h b/src/mcc/spawn/Command.h new file mode 100644 index 00000000..ea638f71 --- /dev/null +++ b/src/mcc/spawn/Command.h @@ -0,0 +1,54 @@ +#pragma once + +#include +#include +#include + +// Game-thread execution for AlphaRing features (spawning). +// +// Engines with a simulation-tick hook register a Scheduler that runs a task on that thread +// (Halo 3 and ODST, whose console scripts compile on another thread). For the others, MCC +// hands every "HS: