From 02c73176a5c8e7506e8f1e198e067b1ab4d8dc7b Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Wed, 21 Sep 2022 23:06:58 -0400 Subject: [PATCH] Fix Particles In Front-Facing View --- launcher/src/client/available-feature-flags | 2 +- mods/src/input/toggle.c | 51 ++++++++++++++++----- mods/src/title-screen/title-screen.cpp | 2 +- symbols/include/symbols/minecraft.h | 5 ++ 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/launcher/src/client/available-feature-flags b/launcher/src/client/available-feature-flags index 92e398f..722ec8f 100644 --- a/launcher/src/client/available-feature-flags +++ b/launcher/src/client/available-feature-flags @@ -32,7 +32,7 @@ TRUE Disable V-Sync TRUE Fix Options Screen TRUE Force Touch GUI Inventory TRUE Fix Pause Menu -TRUE Improved Title Screen Background +TRUE Add Title Screen Background TRUE Force Touch GUI Button Behavior TRUE Improved Button Hover Behavior TRUE Implement Create World Dialog diff --git a/mods/src/input/toggle.c b/mods/src/input/toggle.c index 955acb2..ad26f61 100644 --- a/mods/src/input/toggle.c +++ b/mods/src/input/toggle.c @@ -42,32 +42,58 @@ static void _handle_toggle_options(unsigned char *minecraft) { } // Font-Facing View +static void invert_rotation(unsigned char *entity) { + if (entity != NULL) { + *(float *) (entity + Entity_yaw_property_offset) = 180.f + (*(float *) (entity + Entity_yaw_property_offset)); + *(float *) (entity + Entity_old_yaw_property_offset) = 180.f + (*(float *) (entity + Entity_old_yaw_property_offset)); + *(float *) (entity + Entity_pitch_property_offset) = -(*(float *) (entity + Entity_pitch_property_offset)); + *(float *) (entity + Entity_old_pitch_property_offset) = -(*(float *) (entity + Entity_old_pitch_property_offset)); + } +} +static void revert_rotation(unsigned char *entity) { + if (entity != NULL) { + *(float *) (entity + Entity_yaw_property_offset) = -180.f + (*(float *) (entity + Entity_yaw_property_offset)); + *(float *) (entity + Entity_old_yaw_property_offset) = -180.f + (*(float *) (entity + Entity_old_yaw_property_offset)); + *(float *) (entity + Entity_pitch_property_offset) = -(*(float *) (entity + Entity_pitch_property_offset)); + *(float *) (entity + Entity_old_pitch_property_offset) = -(*(float *) (entity + Entity_old_pitch_property_offset)); + } +} +static int is_front_facing = 0; +static unsigned char *stored_player = NULL; 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); + stored_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); + is_front_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)); + if (is_front_facing) { + invert_rotation(stored_player); } // 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)); + if (is_front_facing) { + revert_rotation(stored_player); + } +} +static void ParticleEngine_render_injection(unsigned char *particle_engine, unsigned char *entity, float param_2) { + // Invert Rotation + if (is_front_facing && stored_player == entity) { + invert_rotation(stored_player); + } + + // Call Original Method + (*ParticleEngine_render)(particle_engine, entity, param_2); + + // Revert + if (is_front_facing && stored_player == entity) { + revert_rotation(stored_player); } } @@ -79,5 +105,6 @@ void _init_toggle() { // Font-Facing View if (enable_toggles) { overwrite_calls((void *) GameRenderer_setupCamera, (void *) GameRenderer_setupCamera_injection); + overwrite_calls((void *) ParticleEngine_render, (void *) ParticleEngine_render_injection); } } diff --git a/mods/src/title-screen/title-screen.cpp b/mods/src/title-screen/title-screen.cpp index d99a9d8..a6169d8 100644 --- a/mods/src/title-screen/title-screen.cpp +++ b/mods/src/title-screen/title-screen.cpp @@ -45,7 +45,7 @@ static void StartMenuScreen_buttonClicked_injection(unsigned char *screen, unsig // Init void init_title_screen() { // Improved Title Screen Background - if (feature_has("Improved Title Screen Background", server_disabled)) { + if (feature_has("Add Title Screen Background", server_disabled)) { // Switch Background overwrite_call((void *) 0x39528, (void *) StartMenuScreen_render_Screen_renderBackground_injection); overwrite_call((void *) 0x3dee0, (void *) StartMenuScreen_render_Screen_renderBackground_injection); diff --git a/symbols/include/symbols/minecraft.h b/symbols/include/symbols/minecraft.h index 115fe76..279344a 100644 --- a/symbols/include/symbols/minecraft.h +++ b/symbols/include/symbols/minecraft.h @@ -226,6 +226,11 @@ static GameRenderer_setupCamera_t GameRenderer_setupCamera = (GameRenderer_setup static uint32_t GameRenderer_minecraft_property_offset = 0x4; // Minecraft * +// ParticleEngine + +typedef void (*ParticleEngine_render_t)(unsigned char *particle_engine, unsigned char *entity, float param_2); +static ParticleEngine_render_t ParticleEngine_render = (ParticleEngine_render_t) 0x43060; + // Mouse typedef int (*Mouse_get_t)();