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 RandomMoons v1.3.1
RandomMoons.dll
Decompiled 2 years agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Threading; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using CSync.Lib; using CSync.Util; using HarmonyLib; using LethalAPI.LibTerminal; using LethalAPI.LibTerminal.Attributes; using LethalAPI.LibTerminal.Interactions; using LethalAPI.LibTerminal.Interfaces; using LethalAPI.LibTerminal.Models; using LethalConfig; using LethalConfig.ConfigItems; using LethalConfig.ConfigItems.Options; using Microsoft.CodeAnalysis; using RandomMoons.Commands; using RandomMoons.ConfigUtils; using RandomMoons.Patches; using RandomMoons.Utils; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("RandomMoons")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("Lethal Company mod that let you go to a random moon for free.")] [assembly: AssemblyFileVersion("1.2.3.0")] [assembly: AssemblyInformationalVersion("1.2.3+84a1a418a9219d3fa6a83de6e9b5b8cf963870fe")] [assembly: AssemblyProduct("RandomMoons")] [assembly: AssemblyTitle("RandomMoons")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.2.3.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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 RandomMoons { [BepInPlugin("InnohVateur.RandomMoons", "RandomMoons", "1.3.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class RandomMoons : BaseUnityPlugin { internal const string modGUID = "InnohVateur.RandomMoons"; internal const string modName = "RandomMoons"; internal const string modVersion = "1.3.0"; private readonly Harmony harmony = new Harmony("InnohVateur.RandomMoons"); private TerminalModRegistry Commands; internal static ManualLogSource Logger; public static RMConfig Config { get; private set; } private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; Config = new RMConfig(((BaseUnityPlugin)this).Config); RMConfig config = Config; ((SyncedInstance<RMConfig>)(object)config).SyncComplete = (Action<bool>)Delegate.Combine(((SyncedInstance<RMConfig>)(object)config).SyncComplete, new Action<bool>(CheckSynced)); Commands = TerminalRegistry.CreateTerminalRegistry(); Commands.RegisterFrom<ExploreCommand>(new ExploreCommand()); try { Logger.LogInfo((object)"Applying patches..."); ApplyPluginPatches(); Logger.LogInfo((object)"Patches applied!"); } catch (Exception ex) { Logger.LogError((object)ex); } Logger.LogInfo((object)"Plugin RandomMoons is loaded and operational. Have fun!"); } private void ApplyPluginPatches() { harmony.PatchAll(typeof(RandomMoons)); Logger.LogInfo((object)"Patched RandomMoons"); harmony.PatchAll(typeof(TerminalPatch)); Logger.LogInfo((object)"Patched Terminal"); harmony.PatchAll(typeof(StartOfRoundPatch)); Logger.LogInfo((object)"Patched StartOfRound"); } private void CheckSynced(bool success) { if (!success) { Logger.LogWarning((object)"SYNC FAILED"); States.ConfigStatus = false; } else if (success) { Logger.LogInfo((object)"Sync Succesfull ! Have fun !"); States.ConfigStatus = true; } else { Logger.LogDebug((object)$"Commands registered! SyncedVar: {SyncedInstance<RMConfig>.Instance.SyncedVar}"); } } } public static class MyPluginInfo { public const string PLUGIN_GUID = "RandomMoons"; public const string PLUGIN_NAME = "RandomMoons"; public const string PLUGIN_VERSION = "1.2.3"; } } namespace RandomMoons.Utils { internal class States { public static bool closedUponConfirmation = false; public static bool isInteracting = false; public static bool hasGambled = false; public static bool startUponArriving = false; public static bool confirmedAutostart = false; public static bool exploreASAP = false; public static List<string> visitedMoons = new List<string>(); public static bool ConfigStatus; public static readonly string[] vanillaMoons = new string[8] { "Level1Experimentation", "Level2Assurance", "Level3Vow", "Level4March", "Level5Rend", "Level6Dine", "Level7Offense", "Level8Titan" }; public static readonly int companyBuildingLevelID = 3; public static string lastVisitedMoon; } } namespace RandomMoons.Patches { [HarmonyPatch(typeof(GameNetworkManager))] internal class GameNetworkManagerPatch { [HarmonyPatch("StartDisconnect")] [HarmonyPrefix] public static void StartDisconnectPatch() { States.hasGambled = false; } } [HarmonyPatch(typeof(StartOfRound))] internal class StartOfRoundPatch { private static Terminal terminal = Object.FindObjectOfType<Terminal>(); [HarmonyPatch("Update")] [HarmonyPrefix] public static void UpdatePatch(StartOfRound __instance) { if (__instance.shipHasLanded && States.hasGambled) { States.hasGambled = false; States.visitedMoons.Add(States.lastVisitedMoon); } if (__instance.suckingPlayersOutOfShip) { States.visitedMoons = new List<string>(); } if (__instance.travellingToNewLevel && States.startUponArriving) { States.confirmedAutostart = true; States.startUponArriving = false; } if (__instance.CanChangeLevels() && States.exploreASAP) { if (SyncedInstance<RMConfig>.Instance.AutoStart.Value) { States.startUponArriving = true; } if (TimeOfDay.Instance.daysUntilDeadline > 0 || __instance.currentLevelID == States.companyBuildingLevelID) { SelectableLevel val = ExploreCommand.ChooseRandomMoon(terminal.moonsCatalogueList); __instance.ChangeLevelServerRpc(val.levelID, terminal.groupCredits); States.lastVisitedMoon = val.PlanetName; States.hasGambled = true; } else { __instance.ChangeLevelServerRpc(States.companyBuildingLevelID, terminal.groupCredits); } } } [HarmonyPatch("ArriveAtLevel")] [HarmonyPostfix] public static void ArriveAtLevelPatch() { if (States.confirmedAutostart) { return; } Thread.Sleep(1000); States.confirmedAutostart = false; GameObject val = GameObject.Find("StartGameLever"); if (!((Object)(object)val == (Object)null)) { StartMatchLever component = val.GetComponent<StartMatchLever>(); if (!((Object)(object)component == (Object)null)) { component.PullLever(); component.LeverAnimation(); component.StartGame(); } } } [HarmonyPatch("ChangeLevel")] [HarmonyPrefix] public static void ChangeLevelPatch() { if (States.exploreASAP) { States.exploreASAP = false; } } [HarmonyPatch("EndOfGame")] [HarmonyPostfix] public static void EndOfGamePatch() { States.exploreASAP = true; } } [HarmonyPatch(typeof(Terminal))] public class TerminalPatch { [HarmonyPatch("QuitTerminal")] [HarmonyPrefix] public static void QuitTerminalPatch() { if (States.isInteracting) { States.closedUponConfirmation = true; } } [HarmonyPatch("BeginUsingTerminal")] [HarmonyPrefix] public static void BeginUsingTerminalPatch(Terminal __instance) { if (SyncedInstance<RMConfig>.Instance.MoonSelectionType.Value != MoonSelection.MODDED) { return; } SelectableLevel[] moonsCatalogueList = __instance.moonsCatalogueList; foreach (SelectableLevel val in moonsCatalogueList) { if (!States.vanillaMoons.Contains(val.sceneName)) { return; } } SyncedInstance<RMConfig>.Instance.MoonSelectionType.Value = MoonSelection.ALL; } } } namespace RandomMoons.ConfigUtils { [DataContract] public class RMConfig : SyncedConfig<RMConfig> { [DataMember] public SyncedEntry<bool> AutoStart { get; private set; } [DataMember] public SyncedEntry<bool> AutoExplore { get; private set; } [DataMember] public SyncedEntry<bool> CheckIfVisitedDuringQuota { get; private set; } [DataMember] public SyncedEntry<bool> RestrictedCommandUsage { get; private set; } [DataMember] public SyncedEntry<MoonSelection> MoonSelectionType { get; private set; } [DataMember] public SyncedEntry<int> SyncedVar { get; private set; } public RMConfig(ConfigFile cfg) : base("InnohVateur.RandomMoons") { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_003b: Expected O, but got Unknown //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Expected O, but got Unknown //IL_0068: Expected O, but got Unknown //IL_007a: 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) //IL_0095: Expected O, but got Unknown //IL_0095: Expected O, but got Unknown //IL_00a7: 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_00c2: Expected O, but got Unknown //IL_00c2: Expected O, but got Unknown //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Expected O, but got Unknown //IL_00ef: Expected O, but got Unknown //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Expected O, but got Unknown //IL_011c: Expected O, but got Unknown //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Expected O, but got Unknown //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Expected O, but got Unknown //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Expected O, but got Unknown //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Expected O, but got Unknown //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Expected O, but got Unknown //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Expected O, but got Unknown //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Expected O, but got Unknown //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Expected O, but got Unknown ConfigManager.Register<RMConfig>(this); AutoStart = Extensions.BindSyncedEntry<bool>(cfg, new ConfigDefinition("General", "AutoStart"), false, new ConfigDescription("Automatically starts the level upon travelling to a random moon", (AcceptableValueBase)null, Array.Empty<object>())); AutoExplore = Extensions.BindSyncedEntry<bool>(cfg, new ConfigDefinition("General", "AutoExplore"), false, new ConfigDescription("Automatically explore to a random moon upon leaving the level", (AcceptableValueBase)null, Array.Empty<object>())); CheckIfVisitedDuringQuota = Extensions.BindSyncedEntry<bool>(cfg, new ConfigDefinition("General", "RegisterTravels"), false, new ConfigDescription("The same moon can't be chosen twice while the quota hasn't changed", (AcceptableValueBase)null, Array.Empty<object>())); RestrictedCommandUsage = Extensions.BindSyncedEntry<bool>(cfg, new ConfigDefinition("General", "PreventMultipleTravels"), true, new ConfigDescription("Prevents the players to execute explore multiple times without landing", (AcceptableValueBase)null, Array.Empty<object>())); MoonSelectionType = Extensions.BindSyncedEntry<MoonSelection>(cfg, new ConfigDefinition("General", "MoonSelection"), MoonSelection.ALL, new ConfigDescription("Can have three values : vanilla, modded or all, to change the moons that can be chosen. (Note : modded input without modded moons would do the same as all)", (AcceptableValueBase)null, Array.Empty<object>())); SyncedVar = Extensions.BindSyncedEntry<int>(cfg, new ConfigDefinition("Debug leftover", "DebuG leftover"), 4, new ConfigDescription("This is a debug variable, you can ignore it", (AcceptableValueBase)null, Array.Empty<object>())); BoolCheckBoxConfigItem val = new BoolCheckBoxConfigItem(AutoStart.Entry, new BoolCheckBoxOptions { RequiresRestart = false }); BoolCheckBoxConfigItem val2 = new BoolCheckBoxConfigItem(AutoExplore.Entry, new BoolCheckBoxOptions { RequiresRestart = false }); BoolCheckBoxConfigItem val3 = new BoolCheckBoxConfigItem(CheckIfVisitedDuringQuota.Entry, new BoolCheckBoxOptions { RequiresRestart = false }); BoolCheckBoxConfigItem val4 = new BoolCheckBoxConfigItem(RestrictedCommandUsage.Entry, new BoolCheckBoxOptions { RequiresRestart = false }); EnumDropDownConfigItem<MoonSelection> val5 = new EnumDropDownConfigItem<MoonSelection>(MoonSelectionType.Entry, false); LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val); LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2); LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val3); LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val4); LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val5); LethalConfigManager.SkipAutoGenFor((ConfigEntryBase)(object)SyncedVar.Entry); } } [DataContract] public enum MoonSelection { [EnumMember] ALL, [EnumMember] MODDED, [EnumMember] VANILLA } } namespace RandomMoons.Commands { public class DisplayConfigCommand { [TerminalCommand("RmConfig", false)] [CommandInfo("Displays RandomMoons config.", "")] public string DisplayConfigString() { return $"{SyncedInstance<RMConfig>.Instance.AutoStart}, {SyncedInstance<RMConfig>.Instance.AutoExplore}, {SyncedInstance<RMConfig>.Instance.CheckIfVisitedDuringQuota}, " + $"{SyncedInstance<RMConfig>.Instance.RestrictedCommandUsage}, {SyncedInstance<RMConfig>.Instance.MoonSelectionType}"; } } public class ExploreCommand { [TerminalCommand("explore", false)] [CommandInfo("Let you travel to a random moon for free !", "")] public ITerminalInteraction exec(Terminal terminal) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) States.isInteracting = true; return (ITerminalInteraction)(object)new TerminalInteraction().WithPrompt("You're going to route to a randomly chosen moon, for free.\n\nPlease CONFIRM or DENY").WithHandler((Delegate)new Func<Terminal, string, string>(onInteraction)); } private string onInteraction(Terminal terminal, string s) { //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: Expected O, but got Unknown //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Expected O, but got Unknown if (States.closedUponConfirmation) { States.closedUponConfirmation = false; States.isInteracting = false; terminal.currentNode = new TerminalNode { name = s }; terminal.OnSubmit(); return null; } if (s.ToLower() == "c" || s.ToLower() == "confirm") { if (States.hasGambled && SyncedInstance<RMConfig>.Instance.RestrictedCommandUsage.Value) { return "You have already explored. Please land before exploring once again !"; } if (StartOfRound.Instance.shipHasLanded || !StartOfRound.Instance.CanChangeLevels()) { return "Please wait before travelling to a new moon !"; } SelectableLevel val = ChooseRandomMoon(terminal.moonsCatalogueList); StartOfRound.Instance.ChangeLevelServerRpc(val.levelID, terminal.groupCredits); if (SyncedInstance<RMConfig>.Instance.AutoStart.Value) { States.startUponArriving = true; } States.lastVisitedMoon = val.PlanetName; States.isInteracting = false; States.hasGambled = true; return "A moon has been picked : " + val.PlanetName + " (" + ((object)(LevelWeatherType)(ref val.currentWeather)).ToString() + "). Enjoy the trip !"; } if (s.ToLower() == "d" || s.ToLower() == "deny") { States.isInteracting = false; return "Route cancelled."; } States.isInteracting = false; terminal.currentNode = new TerminalNode { name = s }; terminal.OnSubmit(); return null; } public static SelectableLevel ChooseRandomMoon(SelectableLevel[] moons) { Random random = new Random(); int num = random.Next(0, moons.Length); MoonSelection value = SyncedInstance<RMConfig>.Instance.MoonSelectionType.Value; if ((value == MoonSelection.VANILLA && !IsMoonVanilla(moons[num])) || (value == MoonSelection.MODDED && IsMoonVanilla(moons[num]))) { return ChooseRandomMoon(moons); } if (SyncedInstance<RMConfig>.Instance.CheckIfVisitedDuringQuota.Value && States.visitedMoons.Contains(moons[num].PlanetName)) { return ChooseRandomMoon(moons); } if (States.visitedMoons.Count == moons.Length) { States.visitedMoons = new List<string>(); } return moons[num]; } public static bool IsMoonVanilla(SelectableLevel moon) { return States.vanillaMoons.Contains(moon.sceneName); } } }