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 PerfectRotation v1.0.1
PerfectRotation.dll
Decompiled 6 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.Netcode; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("PerfectRotation")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1")] [assembly: AssemblyProduct("PerfectRotation")] [assembly: AssemblyTitle("PerfectRotation")] [assembly: AssemblyVersion("1.0.1.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace PerfectRotation { internal static class Patches { private static bool letStartThrough; private static bool routing; [HarmonyPrefix] [HarmonyPatch(typeof(StartOfRound), "StartGame")] private static bool BeforeStartGame(StartOfRound __instance) { if (letStartThrough || !Plugin.Enabled.Value) { return true; } if (!((NetworkBehaviour)__instance).IsServer || !__instance.inShipPhase || __instance.isChallengeFile) { return true; } if (routing) { return false; } SelectableLevel val = Rotation.ChooseNext(__instance); if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)__instance.currentLevel) { return true; } routing = true; ((MonoBehaviour)__instance).StartCoroutine(TravelThenLand(__instance, val)); return false; } private static IEnumerator TravelThenLand(StartOfRound sor, SelectableLevel target) { Terminal val = Object.FindObjectOfType<Terminal>(); sor.ChangeLevelServerRpc(target.levelID, ((Object)(object)val != (Object)null) ? val.groupCredits : 0); float t = 0f; while (!sor.travellingToNewLevel && (Object)(object)sor.currentLevel != (Object)(object)target && t < 3f) { t += Time.deltaTime; yield return null; } t = 0f; while (sor.travellingToNewLevel && t < 120f) { t += Time.deltaTime; yield return null; } yield return (object)new WaitForSeconds(Plugin.DelayAfterTravel.Value); routing = false; if (!sor.inShipPhase || sor.beganLoadingNewLevel) { yield break; } letStartThrough = true; try { sor.StartGame(); } finally { letStartThrough = false; } } [HarmonyPrefix] [HarmonyPatch(typeof(StartMatchLever), "BeginHoldingInteractOnLever")] private static void NoHaltWarning(StartMatchLever __instance) { if (Plugin.Enabled.Value && (Object)(object)TimeOfDay.Instance != (Object)null && TimeOfDay.Instance.daysUntilDeadline <= 0) { __instance.hasDisplayedTimeWarning = true; } } [HarmonyPostfix] [HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")] private static void FreeRouteParsed(TerminalNode __result) { MakeFree(__result); } [HarmonyPrefix] [HarmonyPatch(typeof(Terminal), "LoadNewNodeIfAffordable")] private static void FreeRouteConfirm(TerminalNode node) { MakeFree(node); } private static void MakeFree(TerminalNode node) { if (Plugin.FreeMoons.Value && (Object)(object)node != (Object)null && node.buyRerouteToMoon != -1) { node.itemCost = 0; } } [HarmonyPostfix] [HarmonyPatch(typeof(StartOfRound), "Start")] private static void OnRoundStart(StartOfRound __instance) { routing = false; letStartThrough = false; if (GameNetworkManager.Instance.isHostingGame) { Rotation.Load(); Rotation.LogMoonList(__instance); } } [HarmonyPostfix] [HarmonyPatch(typeof(GameNetworkManager), "SaveGame")] private static void OnSave() { if (GameNetworkManager.Instance.isHostingGame) { Rotation.Save(); } } [HarmonyPostfix] [HarmonyPatch(typeof(GameNetworkManager), "ResetSavedGameValues")] private static void OnFired() { if (GameNetworkManager.Instance.isHostingGame) { Rotation.Reset(); } } } [BepInPlugin("ak.perfectrotation", "PerfectRotation", "1.0.1")] public class Plugin : BaseUnityPlugin { public const string Guid = "ak.perfectrotation"; public const string Name = "PerfectRotation"; public const string Version = "1.0.1"; internal static ManualLogSource Log; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<bool> ForceSEnabled; internal static ConfigEntry<int> LowMoonsBeforeS; internal static ConfigEntry<string> CompanyMoon; internal static ConfigEntry<bool> NoRepeat; internal static ConfigEntry<string> Blacklist; internal static ConfigEntry<bool> FreeMoons; internal static ConfigEntry<float> DelayAfterTravel; private void Awake() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Expected O, but got Unknown //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Expected O, but got Unknown //IL_0147: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1. General", "Activer la rotation", true, "Quand on tire le levier, le vaisseau part vers une lune choisie au hasard avant d'atterrir."); ForceSEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Regle S", "Activer la regle S", true, "Apres plusieurs lunes de suite en dessous de S (D, C, B, A...), la lune suivante est forcement S ou plus (S, S+, S++, SS...).\nSeule une lune S ou plus remet le compteur a zero. Le jour de la Compagnie ne compte pas."); LowMoonsBeforeS = ((BaseUnityPlugin)this).Config.Bind<int>("2. Regle S", "Lunes basses avant une S", 2, new ConfigDescription("Nombre de lunes de suite en dessous de S avant de forcer une lune S.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>())); CompanyMoon = ((BaseUnityPlugin)this).Config.Bind<string>("3. Compagnie", "Lune de la Compagnie", "Galetry", "Le dernier jour, si le quota n'est pas atteint, le vaisseau part automatiquement vers cette lune.\nSi elle est introuvable, ce sera Gordion. Si le quota est deja atteint, le dernier jour est une lune bonus au hasard."); NoRepeat = ((BaseUnityPlugin)this).Config.Bind<bool>("4. Tirage", "Ne pas repeter les lunes", true, "Une lune deja visitee n'est pas retiree tant que toutes les autres ne sont pas passees."); Blacklist = ((BaseUnityPlugin)this).Config.Bind<string>("4. Tirage", "Liste noire", "", "Lunes a ne jamais tirer, separees par des virgules (ex : Experimentation,Embrion).\nLes lunes de la Compagnie et Liquidation sont deja exclues automatiquement."); FreeMoons = ((BaseUnityPlugin)this).Config.Bind<bool>("5. Terminal", "Lunes gratuites", true, "Router manuellement vers une lune au terminal ne coute rien (de toute facon la lune sera tiree au hasard)."); DelayAfterTravel = ((BaseUnityPlugin)this).Config.Bind<float>("6. Trajet", "Pause apres le trajet", 0.5f, new ConfigDescription("Petite pause (en secondes) entre l'arrivee en orbite et le debut de l'atterrissage.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>())); new Harmony("ak.perfectrotation").PatchAll(typeof(Patches)); Log.LogInfo((object)"PerfectRotation 1.0.1 charge."); } } internal enum Danger { Unknown, Low, High, Top } internal static class Rotation { private const string KeyLowStreak = "PerfectRotation_LowStreak"; private const string KeyVisited = "PerfectRotation_Visited"; internal static int LowStreak; internal static readonly HashSet<string> Visited = new HashSet<string>(); private static string SaveFile => GameNetworkManager.Instance?.currentSaveFileName; internal static string CleanName(string planetName) { if (string.IsNullOrEmpty(planetName)) { return ""; } return Regex.Replace(planetName, "^\\s*\\d+\\s*", "").Trim().ToLowerInvariant(); } internal static Danger GetDanger(SelectableLevel level) { string text = (level.riskLevel ?? "").Trim().ToUpperInvariant(); if (text.Length == 0 || text == "SAFE") { return Danger.Unknown; } switch (text[0]) { case 'S': if (!text.StartsWith("S-")) { return Danger.Top; } return Danger.High; case 'A': return Danger.High; case 'B': case 'C': case 'D': case 'E': case 'F': return Danger.Low; default: return Danger.Unknown; } } private static bool IsCompanyMoon(SelectableLevel level) { if (level.levelID == 3) { return true; } if (!level.spawnEnemiesAndScrap) { return true; } string text = CleanName(level.PlanetName); if (!(text == "gordion")) { return text == CleanName(Plugin.CompanyMoon.Value); } return true; } private static HashSet<string> BlacklistSet() { return new HashSet<string>(from s in (Plugin.Blacklist.Value ?? "").Split(',').Select(CleanName) where s.Length > 0 select s); } private static List<SelectableLevel> PlayableMoons(StartOfRound sor) { HashSet<string> blacklist = BlacklistSet(); return sor.levels.Where((SelectableLevel l) => (Object)(object)l != (Object)null && !IsCompanyMoon(l) && CleanName(l.PlanetName) != "liquidation" && !blacklist.Contains(CleanName(l.PlanetName))).ToList(); } private static SelectableLevel FindCompany(StartOfRound sor) { string wanted = CleanName(Plugin.CompanyMoon.Value); SelectableLevel val = ((IEnumerable<SelectableLevel>)sor.levels).FirstOrDefault((Func<SelectableLevel, bool>)((SelectableLevel l) => (Object)(object)l != (Object)null && CleanName(l.PlanetName) == wanted)); if ((Object)(object)val != (Object)null) { return val; } Plugin.Log.LogWarning((object)("Lune de la Compagnie \"" + Plugin.CompanyMoon.Value + "\" introuvable, direction Gordion.")); return ((IEnumerable<SelectableLevel>)sor.levels).FirstOrDefault((Func<SelectableLevel, bool>)((SelectableLevel l) => (Object)(object)l != (Object)null && (l.levelID == 3 || CleanName(l.PlanetName) == "gordion"))); } private static bool IsLastDayToSell() { TimeOfDay instance = TimeOfDay.Instance; if ((Object)(object)instance != (Object)null && instance.daysUntilDeadline <= 0) { return instance.profitQuota > instance.quotaFulfilled; } return false; } internal static SelectableLevel ChooseNext(StartOfRound sor) { if (IsLastDayToSell()) { SelectableLevel val = FindCompany(sor); Plugin.Log.LogInfo((object)("Dernier jour, quota non atteint : direction " + val?.PlanetName + ".")); return val; } SelectableLevel current = sor.currentLevel; List<SelectableLevel> list = (from l in PlayableMoons(sor) where (Object)(object)l != (Object)(object)current select l).ToList(); if (list.Count == 0) { Plugin.Log.LogWarning((object)"Aucune lune disponible pour le tirage, on reste sur la lune actuelle."); return null; } bool flag = Plugin.ForceSEnabled.Value && LowStreak >= Plugin.LowMoonsBeforeS.Value; List<SelectableLevel> list2 = list; if (flag) { List<SelectableLevel> list3 = list.Where((SelectableLevel l) => GetDanger(l) == Danger.Top).ToList(); if (list3.Count == 0) { Plugin.Log.LogWarning((object)"Regle S : aucune lune S ou plus disponible, tirage normal."); flag = false; } else { list2 = list3; } } if (Plugin.NoRepeat.Value) { List<SelectableLevel> list4 = list2.Where((SelectableLevel l) => !Visited.Contains(CleanName(l.PlanetName))).ToList(); if (list4.Count == 0) { if (!flag) { Visited.Clear(); Plugin.Log.LogInfo((object)"Toutes les lunes ont ete visitees, la liste repart a zero."); } } else { list2 = list4; } } SelectableLevel val2 = list2[Random.Range(0, list2.Count)]; Remember(val2); Plugin.Log.LogInfo((object)("Prochaine lune : " + val2.PlanetName + " (" + val2.riskLevel + ")" + (flag ? " - lune S forcee" : "") + $" | lunes sans S de suite : {LowStreak}")); return val2; } private static void Remember(SelectableLevel level) { Visited.Add(CleanName(level.PlanetName)); switch (GetDanger(level)) { case Danger.Low: case Danger.High: LowStreak++; break; case Danger.Top: LowStreak = 0; break; } } internal static void Load() { LowStreak = 0; Visited.Clear(); string saveFile = SaveFile; if (string.IsNullOrEmpty(saveFile)) { return; } try { LowStreak = ES3.Load<int>("PerfectRotation_LowStreak", saveFile, 0); foreach (string item in from s in ES3.Load<string>("PerfectRotation_Visited", saveFile, "").Split(',') where s.Length > 0 select s) { Visited.Add(item); } Plugin.Log.LogInfo((object)$"Memoire chargee : {LowStreak} lune(s) sans S de suite, {Visited.Count} lune(s) visitee(s)."); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Impossible de lire la memoire de la partie : " + ex.Message)); } } internal static void Save() { string saveFile = SaveFile; if (string.IsNullOrEmpty(saveFile)) { return; } try { ES3.Save<int>("PerfectRotation_LowStreak", LowStreak, saveFile); ES3.Save<string>("PerfectRotation_Visited", string.Join(",", Visited), saveFile); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Impossible d'enregistrer la memoire de la partie : " + ex.Message)); } } internal static void Reset() { LowStreak = 0; Visited.Clear(); Save(); } internal static void LogMoonList(StartOfRound sor) { IEnumerable<string> values = from l in PlayableMoons(sor) select $"{l.PlanetName} [{l.riskLevel} -> {GetDanger(l)}]"; Plugin.Log.LogInfo((object)("Lunes du tirage : " + string.Join(", ", values))); } } }