From 4ed11b67e73503ad6089c6d20194365abe91625e Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 17 May 2022 18:31:25 -0400 Subject: [PATCH] Add Front-Facing View --- mods/src/input/toggle.c | 42 ++++++++++++++++++++++++++++- symbols/include/symbols/minecraft.h | 5 ++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/mods/src/input/toggle.c b/mods/src/input/toggle.c index 3a03041..70e2b88 100644 --- a/mods/src/input/toggle.c +++ b/mods/src/input/toggle.c @@ -29,9 +29,44 @@ static void _handle_toggle_options(unsigned char *minecraft) { hide_gui_toggle = 0; if (third_person_toggle % 2 != 0) { // Toggle Third Person - *(options + Options_third_person_property_offset) = *(options + Options_third_person_property_offset) ^ 1; + *(options + Options_third_person_property_offset) = (*(options + Options_third_person_property_offset) + 1) % 3; } third_person_toggle = 0; + // Fix Broken Value From Third-Person OptionsButton Toggle + // (Because Front-Facing Code Repurposes A Boolean As A Ternary) + if (*(options + Options_third_person_property_offset) == 3) { + *(options + Options_third_person_property_offset) = 0; + } + } +} + +// Font-Facing View +static void GameRenderer_setupCamera_injection(unsigned char *game_renderer, float param_1, int param_2) { + // Get Objects + unsigned char *minecraft = *(unsigned char **) (game_renderer + GameRenderer_minecraft_property_offset); + unsigned char *player = *(unsigned char **) (minecraft + Minecraft_player_property_offset); + + // Check If In Third-Person + unsigned char *options = minecraft + Minecraft_options_property_offset; + int is_font_facing = (*(options + Options_third_person_property_offset) == 2); + + // Invert Rotation + if (is_font_facing && player != NULL) { + *(float *) (player + Entity_yaw_property_offset) = 180.f + (*(float *) (player + Entity_yaw_property_offset)); + *(float *) (player + Entity_old_yaw_property_offset) = 180.f + (*(float *) (player + Entity_old_yaw_property_offset)); + *(float *) (player + Entity_pitch_property_offset) = -(*(float *) (player + Entity_pitch_property_offset)); + *(float *) (player + Entity_old_pitch_property_offset) = -(*(float *) (player + Entity_old_pitch_property_offset)); + } + + // Call Original Method + (*GameRenderer_setupCamera)(game_renderer, param_1, param_2); + + // Revert + if (is_font_facing && player != NULL) { + *(float *) (player + Entity_yaw_property_offset) = -180.f + (*(float *) (player + Entity_yaw_property_offset)); + *(float *) (player + Entity_old_yaw_property_offset) = -180.f + (*(float *) (player + Entity_old_yaw_property_offset)); + *(float *) (player + Entity_pitch_property_offset) = -(*(float *) (player + Entity_pitch_property_offset)); + *(float *) (player + Entity_old_pitch_property_offset) = -(*(float *) (player + Entity_old_pitch_property_offset)); } } @@ -39,4 +74,9 @@ static void _handle_toggle_options(unsigned char *minecraft) { void _init_toggle() { enable_toggles = feature_has("Bind Common Toggleable Options To Function Keys", server_disabled); input_run_on_tick(_handle_toggle_options); + + // Font-Facing View + if (enable_toggles) { + overwrite_calls((void *) GameRenderer_setupCamera, (void *) GameRenderer_setupCamera_injection); + } } diff --git a/symbols/include/symbols/minecraft.h b/symbols/include/symbols/minecraft.h index 169316b..1ab7128 100644 --- a/symbols/include/symbols/minecraft.h +++ b/symbols/include/symbols/minecraft.h @@ -202,6 +202,9 @@ static uint32_t Minecraft_perf_renderer_property_offset = 0xcbc; // PerfRenderer typedef void (*GameRenderer_render_t)(unsigned char *game_renderer, float param_1); static GameRenderer_render_t GameRenderer_render = (GameRenderer_render_t) 0x4a338; +typedef void (*GameRenderer_setupCamera_t)(unsigned char *game_renderer, float param_1, int param_2); +static GameRenderer_setupCamera_t GameRenderer_setupCamera = (GameRenderer_setupCamera_t) 0x489f8; + static uint32_t GameRenderer_minecraft_property_offset = 0x4; // Minecraft * // Mouse @@ -326,10 +329,12 @@ static uint32_t Entity_x_property_offset = 0x4; // float static uint32_t Entity_y_property_offset = 0x8; // float static uint32_t Entity_z_property_offset = 0xc; // float static uint32_t Entity_yaw_property_offset = 0x40; // float +static uint32_t Entity_pitch_property_offset = 0x44; // float static uint32_t Entity_old_x_property_offset = 0x28; // float static uint32_t Entity_old_y_property_offset = 0x2c; // float static uint32_t Entity_old_z_property_offset = 0x30; // float static uint32_t Entity_old_yaw_property_offset = 0x48; // float +static uint32_t Entity_old_pitch_property_offset = 0x4c; // float // Mob