Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of BreadCrumbs v1.1.0
BreadCrumbs.dll
Decompiled 2 years agousing System; using System.Collections; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using OPJosMod.BreadCrumbs.Patches; using Unity.Netcode; using UnityEngine; using UnityEngine.AI; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("OPJosMod")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("OPJosMod")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("70095872-b952-4e27-bbc4-3d70d0238f39")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] namespace OPJosMod.BreadCrumbs { public static class ConfigVariables { public static Key retraceButton; } [BepInPlugin("OpJosMod.BreadCrumbs", "BreadCrumbs", "1.1.0")] public class OpJosMod : BaseUnityPlugin { private const string modGUID = "OpJosMod.BreadCrumbs"; private const string modName = "BreadCrumbs"; private const string modVersion = "1.1.0"; private readonly Harmony harmony = new Harmony("OpJosMod.BreadCrumbs"); private static OpJosMod Instance; internal ManualLogSource mls; private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } mls = Logger.CreateLogSource("OpJosMod.BreadCrumbs"); mls.LogInfo((object)"mod has started"); setupConfig(); PlayerControllerBPatch.SetLogSource(mls); EntranceTeleportPatch.SetLogSource(mls); ShipTeleporterPatch.SetLogSource(mls); harmony.PatchAll(); } private void setupConfig() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) ConfigEntry<Key> val = ((BaseUnityPlugin)this).Config.Bind<Key>("Retrace Steps Button", "RetraceStepsButton", (Key)22, "Button used to start walking back to the front door"); ConfigVariables.retraceButton = val.Value; } } } namespace OPJosMod.BreadCrumbs.Utils { public class ReflectionUtils { public static void InvokeMethod(object obj, string methodName, object[] parameters) { Type type = obj.GetType(); MethodInfo method = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); method.Invoke(obj, parameters); } public static void InvokeMethod(object obj, Type forceType, string methodName, object[] parameters) { MethodInfo method = forceType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); method.Invoke(obj, parameters); } public static void SetPropertyValue(object obj, string propertyName, object value) { Type type = obj.GetType(); PropertyInfo property = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); property.SetValue(obj, value); } public static T InvokeMethod<T>(object obj, string methodName, object[] parameters) { Type type = obj.GetType(); MethodInfo method = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); return (T)method.Invoke(obj, parameters); } public static T GetFieldValue<T>(object obj, string fieldName) { Type type = obj.GetType(); FieldInfo field = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); return (T)field.GetValue(obj); } public static void SetFieldValue(object obj, string fieldName, object value) { Type type = obj.GetType(); FieldInfo field = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); field.SetValue(obj, value); } } } namespace OPJosMod.BreadCrumbs.Patches { [HarmonyPatch(typeof(ShipTeleporter))] internal class ShipTeleporterPatch : MonoBehaviour { private static ManualLogSource mls; public static void SetLogSource(ManualLogSource logSource) { mls = logSource; } [HarmonyPatch("beamUpPlayer")] [HarmonyPrefix] private static void beamUpPlayerPatch() { PlayerControllerB targetedPlayer = StartOfRound.Instance.mapScreen.targetedPlayer; if ((Object)(object)targetedPlayer != (Object)null && targetedPlayer.playerClientId == StartOfRound.Instance.localPlayerController.playerClientId) { PlayerControllerBPatch.RemoveMeshForPlayer(); } } [HarmonyPatch("beamOutPlayer")] [HarmonyPostfix] private static void beamOutPlayerPatch() { PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController; if (localPlayerController.isInsideFactory) { PlayerControllerBPatch.InitializeNaveMeshForPlayer(); } } } [HarmonyPatch(typeof(EntranceTeleport))] internal class EntranceTeleportPatch : MonoBehaviour { private static ManualLogSource mls; public static void SetLogSource(ManualLogSource logSource) { mls = logSource; } [HarmonyPatch("TeleportPlayer")] [HarmonyPostfix] private static void TeleportPlayerPatch() { PlayerControllerBPatch.RemoveMeshForPlayer(); PlayerControllerBPatch.InitializeNaveMeshForPlayer(); } } [HarmonyPatch(typeof(PlayerControllerB))] internal class PlayerControllerBPatch : MonoBehaviour { private static ManualLogSource mls; private static bool togglingAutoMove = false; private static NavMeshPath path1; private static NavMeshAgent agent; private static bool moveTowardsDestination = false; private static Vector3 destination; public static bool hasInitialized = false; public static float lastClickedAt = Time.time; public static float clickDelay = 0.2f; public static void SetLogSource(ManualLogSource logSource) { mls = logSource; } [HarmonyPatch("Update")] [HarmonyPostfix] private static void patchUpdate(PlayerControllerB __instance) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) if (((NetworkBehaviour)__instance).IsOwner && !__instance.inTerminalMenu && !__instance.isTypingChat && __instance.isInsideFactory) { try { if (((ButtonControl)Keyboard.current[ConfigVariables.retraceButton]).wasPressedThisFrame && !togglingAutoMove) { togglingAutoMove = true; ((MonoBehaviour)__instance).StartCoroutine(toggleSpeed(__instance)); } } catch { } } AutoWalk(__instance); } [HarmonyPatch("KillPlayer")] [HarmonyPrefix] private static void killPlayerPatch(PlayerControllerB __instance) { if (__instance.playerClientId == StartOfRound.Instance.localPlayerController.playerClientId) { RemoveMeshForPlayer(); } } private static IEnumerator toggleSpeed(PlayerControllerB __instance) { yield return (object)new WaitForSeconds(0.2f); if (!moveTowardsDestination) { HUDManager.Instance.DisplayTip("Headed Back", "Started", false, false, "LC_Tip1"); moveTowardsDestination = true; InitializeNaveMeshForPlayer(); yield return (object)new WaitForSeconds(0.2f); startRunToNewPosition(__instance); } else if (moveTowardsDestination) { HUDManager.Instance.DisplayTip("Headed Back", "Stopped", false, false, "LC_Tip1"); ((Behaviour)agent).enabled = false; moveTowardsDestination = false; yield return (object)new WaitForSeconds(0.2f); RemoveMeshForPlayer(); } togglingAutoMove = false; } private static void AutoWalk(PlayerControllerB __instance) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) if (hasInitialized && (Object)(object)((Component)__instance).gameObject.GetComponent<NavMeshAgent>() != (Object)null && moveTowardsDestination && __instance.isInsideFactory) { if (Vector3.Distance(((Component)__instance).transform.position, destination) < 1f) { mls.LogMessage((object)"reached destination!"); HUDManager.Instance.DisplayTip("Arrived!", "", false, false, "LC_Tip1"); ((Behaviour)agent).enabled = false; moveTowardsDestination = false; } agent.SetDestination(destination); } } public static void InitializeNaveMeshForPlayer() { //IL_0130: Unknown result type (might be due to invalid IL or missing references) try { PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController; if ((Object)(object)localPlayerController == (Object)null || (Object)(object)((Component)localPlayerController).gameObject == (Object)null || !localPlayerController.isInsideFactory) { mls.LogMessage((object)"PlayerControllerB instance or its GameObject is null. or they are outside"); return; } if ((Object)(object)((Component)localPlayerController).gameObject.GetComponent<NavMeshAgent>() == (Object)null) { agent = ((Component)localPlayerController).gameObject.AddComponent<NavMeshAgent>(); agent.speed = 2f; agent.acceleration = 25f; agent.angularSpeed = 225f; agent.stoppingDistance = 0.5f; agent.autoBraking = false; agent.autoTraverseOffMeshLink = false; agent.obstacleAvoidanceType = (ObstacleAvoidanceType)4; agent.radius = 0.4f; agent.height = 2f; agent.avoidancePriority = 99; agent.autoRepath = true; hasInitialized = true; } else { agent = ((Component)localPlayerController).gameObject.GetComponent<NavMeshAgent>(); } ((Behaviour)agent).enabled = false; moveTowardsDestination = false; } catch (Exception ex) { mls.LogError((object)ex); } } public static void RemoveMeshForPlayer() { PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController; if ((Object)(object)((Component)localPlayerController).gameObject.GetComponent<NavMeshAgent>() != (Object)null) { Object.Destroy((Object)(object)((Component)localPlayerController).gameObject.GetComponent<NavMeshAgent>()); } } private static void startRunToNewPosition(PlayerControllerB player) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) ((Behaviour)agent).enabled = true; if (!SetDestinationToPosition(RoundManager.FindMainEntrancePosition(false, false))) { SetDestinationToPosition(RoundManager.FindMainEntrancePosition(false, false)); } } private static bool SetDestinationToPosition(Vector3 position) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) try { position = RoundManager.Instance.GetNavMeshPosition(position, RoundManager.Instance.navHit, 1.75f, -1); moveTowardsDestination = true; destination = RoundManager.Instance.GetNavMeshPosition(position, RoundManager.Instance.navHit, -1f, -1); return true; } catch (Exception ex) { mls.LogError((object)ex); InitializeNaveMeshForPlayer(); } return false; } } }