diff --git a/src/Cheats/TracersHandler.cs b/src/Cheats/TracersHandler.cs index 50cc5ce..246952a 100644 --- a/src/Cheats/TracersHandler.cs +++ b/src/Cheats/TracersHandler.cs @@ -1,32 +1,52 @@ using UnityEngine; namespace MalumMenu; + public static class TracersHandler { - public static void drawPlayerTracer(PlayerPhysics playerPhysics){ - try{ - - Color color = Color.clear; // All tracers are invisible by default + /// + /// Draws a tracer from the local player to another player. + /// + /// The PlayerPhysics of the target player. + public static void DrawPlayerTracer(PlayerPhysics playerPhysics) + { + try + { + var color = Color.clear; // All tracers are invisible by default - if (!playerPhysics.myPlayer.Data.IsDead){ - if (CheatToggles.tracersCrew && !playerPhysics.myPlayer.Data.Role.IsImpostor){ - if (CheatToggles.colorBasedTracers){ - color = playerPhysics.myPlayer.Data.Color; // Color-Based Tracer - }else{ - color = playerPhysics.myPlayer.Data.Role.TeamColor; // Team-Based Tracer + if (!playerPhysics.myPlayer.Data.IsDead) + { + if (CheatToggles.tracersCrew && !playerPhysics.myPlayer.Data.Role.IsImpostor || + CheatToggles.tracersImps && playerPhysics.myPlayer.Data.Role.IsImpostor) + { + if (CheatToggles.distanceBasedTracers) + { + color = GetDistanceBasedColor(playerPhysics.myPlayer.transform.position); } - }else if (CheatToggles.tracersImps && playerPhysics.myPlayer.Data.Role.IsImpostor){ - if (CheatToggles.colorBasedTracers){ + else if (CheatToggles.colorBasedTracers) + { color = playerPhysics.myPlayer.Data.Color; // Color-Based Tracer - }else{ + } + else + { color = playerPhysics.myPlayer.Data.Role.TeamColor; // Team-Based Tracer } } - }else{ - if (CheatToggles.tracersGhosts){ - if (CheatToggles.colorBasedTracers){ + } + else + { + if (CheatToggles.tracersGhosts) + { + if (CheatToggles.distanceBasedTracers) + { + color = GetDistanceBasedColor(playerPhysics.myPlayer.transform.position); + } + else if (CheatToggles.colorBasedTracers) + { color = playerPhysics.myPlayer.Data.Color; // Color-Based Tracer - }else{ + } + else + { color = Palette.White; // Ghost Tracer (White) } } @@ -34,29 +54,54 @@ public static void drawPlayerTracer(PlayerPhysics playerPhysics){ // Draw tracer between the player and LocalPlayer using the right color Utils.drawTracer(playerPhysics.myPlayer.gameObject, PlayerControl.LocalPlayer.gameObject, color); - }catch{} } - public static void drawBodyTracer(DeadBody deadBody){ - Color color = Color.clear; // All tracers are invisible by default - - if (CheatToggles.tracersBodies){ - if (CheatToggles.colorBasedTracers){ - - // Fetch the dead body's PlayerInfo - NetworkedPlayerInfo playerById = GameData.Instance.GetPlayerById(deadBody.ParentId); - - color = playerById.Color; // Color-Based Tracer - - }else{ + /// + /// Draws a tracer from the local player to a dead body. Only draws tracers for unreported dead bodies. + /// + /// The DeadBody to draw a tracer to. + public static void DrawBodyTracer(DeadBody deadBody) + { + var color = Color.clear; // All tracers are invisible by default + if (CheatToggles.tracersBodies) + { + if (CheatToggles.distanceBasedTracers) + { + color = GetDistanceBasedColor(deadBody.transform.position); + } + else if (CheatToggles.colorBasedTracers) + { + color = GameData.Instance.GetPlayerById(deadBody.ParentId).Color; // Color-Based Tracer + } + else + { color = Color.yellow; // Dead Body Tracer (Yellow) - } } // Draw tracer between the dead body and LocalPlayer using the right color Utils.drawTracer(deadBody.gameObject, PlayerControl.LocalPlayer.gameObject, color); } -} \ No newline at end of file + + /// + /// Gets a color based on the distance between the local player and a target position. + /// Closer distances are red, medium distances are yellow, and farther distances are green. + /// + /// The position to calculate the distance from. + /// A Color that represents the distance (red for close, yellow for medium, green for far). + private static Color GetDistanceBasedColor(Vector3 targetPosition) + { + const float maxDistance = 20f; // Green at 20+ units + const float minDistance = 2f; // Red at 2 units or fewer + + var distance = Vector3.Distance(targetPosition, PlayerControl.LocalPlayer.transform.position); + var normalized = Mathf.InverseLerp(minDistance, maxDistance, distance); + + // Interpolate: Red (close) -> Yellow (medium) -> Green (far) + return normalized < 0.5f + ? Color.Lerp(Color.red, Color.yellow, normalized * 2f) + : Color.Lerp(Color.yellow, Color.green, (normalized - 0.5f) * 2f); + } +} diff --git a/src/Patches/PlayerPhysicsPatches.cs b/src/Patches/PlayerPhysicsPatches.cs index c5e81e7..6fb8931 100644 --- a/src/Patches/PlayerPhysicsPatches.cs +++ b/src/Patches/PlayerPhysicsPatches.cs @@ -9,7 +9,6 @@ public static class PlayerPhysics_LateUpdate { public static void Postfix(PlayerPhysics __instance) { - MalumESP.PlayerNametags(__instance); MalumESP.seeGhostsCheat(__instance); @@ -33,18 +32,15 @@ public static void Postfix(PlayerPhysics __instance) MalumPPMCheats.changeRolePPM(); MalumPPMCheats.forceRolePPM(); - TracersHandler.drawPlayerTracer(__instance); + TracersHandler.DrawPlayerTracer(__instance); GameObject[] bodyObjects = GameObject.FindGameObjectsWithTag("DeadBody"); foreach(GameObject bodyObject in bodyObjects) // Finds and loops through all dead bodies { DeadBody deadBody = bodyObject.GetComponent(); - if (deadBody){ - if (!deadBody.Reported){ // Only draw tracers for unreported dead bodies - TracersHandler.drawBodyTracer(deadBody); - } - } + if (!deadBody || deadBody.Reported) continue; // Only draw tracers for unreported dead bodies + TracersHandler.DrawBodyTracer(deadBody); } try @@ -60,7 +56,6 @@ public static void Postfix(PlayerPhysics __instance) PlayerControl.LocalPlayer.MyPhysics.GhostSpeed = Mathf.Abs(PlayerControl.LocalPlayer.MyPhysics.GhostSpeed); } }catch (NullReferenceException) {} - } } diff --git a/src/UI/MenuUI.cs b/src/UI/MenuUI.cs index 1ed42cf..fd6be81 100644 --- a/src/UI/MenuUI.cs +++ b/src/UI/MenuUI.cs @@ -58,7 +58,8 @@ private void Start() new ToggleInfo(" Impostors", () => CheatToggles.tracersImps, x => CheatToggles.tracersImps = x), new ToggleInfo(" Ghosts", () => CheatToggles.tracersGhosts, x => CheatToggles.tracersGhosts = x), new ToggleInfo(" Dead Bodies", () => CheatToggles.tracersBodies, x => CheatToggles.tracersBodies = x), - new ToggleInfo(" Color-based", () => CheatToggles.colorBasedTracers, x => CheatToggles.colorBasedTracers = x) + new ToggleInfo(" Color-based", () => CheatToggles.colorBasedTracers, x => CheatToggles.colorBasedTracers = x), + new ToggleInfo(" Distance-based", () => CheatToggles.distanceBasedTracers, x => CheatToggles.distanceBasedTracers = x) ]), new SubmenuInfo("Minimap", false, [