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 BetterPaths v0.1.1
BepInEx/plugins/BetterPaths/BetterPaths.dll
Decompiled 3 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("BetterPaths")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.1.0")] [assembly: AssemblyInformationalVersion("0.1.1")] [assembly: AssemblyProduct("BetterPaths")] [assembly: AssemblyTitle("BetterPaths")] [assembly: AssemblyVersion("0.1.1.0")] namespace BetterPaths; [BepInPlugin("com.bananas4dragons.betterpaths", "BetterPaths", "0.1.1")] public sealed class BetterPathsPlugin : BaseUnityPlugin { private sealed class RoadSettings { internal readonly ConfigEntry<float> StaminaReduction; internal readonly ConfigEntry<float> SpeedIncrease; internal readonly ConfigEntry<float> CartMassReduction; internal readonly HashSet<string> Prefabs = new HashSet<string>(StringComparer.OrdinalIgnoreCase); internal RoadSettings(ConfigFile config, string section, float staminaReduction) { RoadSettings roadSettings = this; StaminaReduction = BindPercent(config, section, "Sprint Stamina Reduction", staminaReduction, 100f, "Percentage reduction in stamina spent sprinting on this surface."); SpeedIncrease = BindPercent(config, section, "Speed Increase", 20f, 200f, "Percentage increase to sprint speed on this surface."); CartMassReduction = BindPercent(config, section, "Cart Mass Reduction", 50f, 99f, "Percentage reduction in physical cart mass when its puller is on this surface."); ConfigEntry<string> prefabNames = config.Bind<string>(section, "Extra Road Prefabs", "", "Comma-separated prefab IDs of built road pieces that should use these settings."); RefreshPrefabs(); prefabNames.SettingChanged += delegate { RefreshPrefabs(); }; void RefreshPrefabs() { roadSettings.Prefabs.Clear(); string[] array = prefabNames.Value.Split(new char[1] { ',' }); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length > 0) { roadSettings.Prefabs.Add(text); } } } } private static ConfigEntry<float> BindPercent(ConfigFile config, string section, string key, float value, float maximum, string description) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown return config.Bind<float>(section, key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, maximum), Array.Empty<object>())); } } [HarmonyPatch] private static class MovementPatches { [HarmonyPostfix] [HarmonyPatch(typeof(Player), "GetRunSpeedFactor")] private static void ApplySprintSpeed(Player __instance, ref float __result) { RoadSettings roadSettings = FindRoad(__instance); if (roadSettings != null) { __result *= 1f + roadSettings.SpeedIncrease.Value / 100f; } } [HarmonyPrefix] [HarmonyPatch(typeof(Player), "CheckRun", new Type[] { typeof(Vector3), typeof(float) })] private static void ReduceStaminaDrain(Player __instance, ref float ___m_runStaminaDrain, out float? __state) { __state = null; RoadSettings roadSettings = FindRoad(__instance); if (roadSettings != null && roadSettings.StaminaReduction.Value > 0f) { __state = ___m_runStaminaDrain; ___m_runStaminaDrain *= 1f - roadSettings.StaminaReduction.Value / 100f; } } [HarmonyFinalizer] [HarmonyPatch(typeof(Player), "CheckRun", new Type[] { typeof(Vector3), typeof(float) })] private static void RestoreStaminaDrain(ref float ___m_runStaminaDrain, float? __state) { if (__state.HasValue) { ___m_runStaminaDrain = __state.Value; } } } [HarmonyPatch] private static class CartPatches { private static readonly Dictionary<Vagon, (float Reduction, float FullMass)> ReducedCarts = new Dictionary<Vagon, (float, float)>(); private static Action<Vagon> updateMass; private static Action<Vagon, float> setMass; [HarmonyPrepare] private static void Prepare() { updateMass = AccessTools.MethodDelegate<Action<Vagon>>(AccessTools.DeclaredMethod(typeof(Vagon), "UpdateMass", Type.EmptyTypes, (Type[])null), (object)null, true); setMass = AccessTools.MethodDelegate<Action<Vagon, float>>(AccessTools.DeclaredMethod(typeof(Vagon), "SetMass", new Type[1] { typeof(float) }, (Type[])null), (object)null, true); } private static bool OwnsCart(ZNetView view) { if (Object.op_Implicit((Object)(object)view) && view.IsValid()) { return view.IsOwner(); } return false; } private static float GetReduction(ConfigurableJoint joint) { Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer) || !Object.op_Implicit((Object)(object)joint)) { return 0f; } Rigidbody connectedBody = ((Joint)joint).connectedBody; if (!Object.op_Implicit((Object)(object)connectedBody) || (Object)(object)((Component)connectedBody).gameObject != (Object)(object)((Component)localPlayer).gameObject) { return 0f; } return FindRoad(localPlayer)?.CartMassReduction.Value ?? 0f; } [HarmonyPrefix] [HarmonyPatch(typeof(Vagon), "SetMass", new Type[] { typeof(float) })] [HarmonyPriority(0)] private static void ReduceMass(Vagon __instance, ZNetView ___m_nview, ConfigurableJoint ___m_attachJoin, ref float __0) { float num = (OwnsCart(___m_nview) ? GetReduction(___m_attachJoin) : 0f); if (num <= 0f) { ReducedCarts.Remove(__instance); return; } ReducedCarts[__instance] = (num, __0); __0 *= 1f - num / 100f; } [HarmonyPostfix] [HarmonyPatch(typeof(Vagon), "Update")] private static void RefreshMassOnRoadChange(Vagon __instance, ZNetView ___m_nview, ConfigurableJoint ___m_attachJoin) { (float, float) value; bool flag = ReducedCarts.TryGetValue(__instance, out value); if (!OwnsCart(___m_nview)) { if (flag) { ReducedCarts.Remove(__instance); setMass(__instance, value.Item2); } } else if (value.Item1 != GetReduction(___m_attachJoin)) { updateMass(__instance); } } [HarmonyPostfix] [HarmonyPatch(typeof(Vagon), "OnDestroy")] private static void ForgetCart(Vagon __instance) { ReducedCarts.Remove(__instance); } internal static void RestoreCarts() { foreach (KeyValuePair<Vagon, (float, float)> reducedCart in ReducedCarts) { if (Object.op_Implicit((Object)(object)reducedCart.Key)) { setMass(reducedCart.Key, reducedCart.Value.Item2); } } ReducedCarts.Clear(); } } public const string Id = "com.bananas4dragons.betterpaths"; private static BetterPathsPlugin instance; private readonly List<Harmony> patches = new List<Harmony>(); private RoadSettings pathen; private RoadSettings pavedRoad; private void Awake() { instance = this; pathen = new RoadSettings(((BaseUnityPlugin)this).Config, "Pathen", 50f); pavedRoad = new RoadSettings(((BaseUnityPlugin)this).Config, "Paved Road", 80f); Install("movement", typeof(MovementPatches)); Install("cart", typeof(CartPatches)); } private void Install(string feature, Type patchType) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown Harmony val = new Harmony("com.bananas4dragons.betterpaths." + feature); try { val.CreateClassProcessor(patchType).Patch(); patches.Add(val); ((BaseUnityPlugin)this).Logger.LogInfo((object)("BetterPaths enabled " + feature + ".")); } catch (Exception arg) { val.UnpatchSelf(); ((BaseUnityPlugin)this).Logger.LogError((object)$"BetterPaths could not enable {feature}: {arg}"); } } private void OnDestroy() { foreach (Harmony patch in patches) { patch.UnpatchSelf(); } CartPatches.RestoreCarts(); instance = null; } private static RoadSettings FindRoad(Player player) { //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)player) || (Object)(object)player != (Object)(object)Player.m_localPlayer || ((Character)player).IsDead() || ((Character)player).IsTeleporting() || !((Character)player).IsOnGround() || ((Character)player).IsSwimming() || ((Character)player).IsRiding()) { return null; } Collider lastGroundCollider = ((Character)player).GetLastGroundCollider(); if (!Object.op_Implicit((Object)(object)lastGroundCollider)) { return null; } Heightmap val = default(Heightmap); if (((Component)lastGroundCollider).TryGetComponent<Heightmap>(ref val)) { Texture2D paintMask = val.GetPaintMask(); if (!Object.op_Implicit((Object)(object)paintMask) || !((Texture)paintMask).isReadable) { return null; } int num = default(int); int num2 = default(int); val.WorldToVertexMask(((Component)player).transform.position, ref num, ref num2); Color paintMask2 = val.GetPaintMask(num, num2); if (paintMask2.b >= 0.4f && paintMask2.b > paintMask2.r && paintMask2.b > paintMask2.g) { return instance.pavedRoad; } if (paintMask2.r >= 0.4f && paintMask2.r > paintMask2.b && paintMask2.r > paintMask2.g) { return instance.pathen; } return null; } if (instance.pathen.Prefabs.Count == 0 && instance.pavedRoad.Prefabs.Count == 0) { return null; } Piece componentInParent = ((Component)lastGroundCollider).GetComponentInParent<Piece>(); if (!Object.op_Implicit((Object)(object)componentInParent)) { return null; } string text = ((Object)((Component)componentInParent).gameObject).name; if (text.EndsWith("(Clone)", StringComparison.Ordinal)) { text = text.Substring(0, text.Length - "(Clone)".Length).TrimEnd(Array.Empty<char>()); } if (instance.pavedRoad.Prefabs.Contains(text)) { return instance.pavedRoad; } if (!instance.pathen.Prefabs.Contains(text)) { return null; } return instance.pathen; } }