using 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 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("A Lethal Company mod that lets you travel to random moons.")] [assembly: AssemblyFileVersion("1.0.5.0")] [assembly: AssemblyInformationalVersion("1.0.5+3bb9439c464a14d6fa3bc071c28b366e20975457")] [assembly: AssemblyProduct("RandomMoons")] [assembly: AssemblyTitle("RandomMoons")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.5.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("Huntress.RandomMoons", "Huntress's RandomMoons Fork", "1.0.5")] [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 = "Huntress.RandomMoons"; internal const string modName = "Huntress's RandomMoons Fork"; internal const string modVersion = "1.0.5"; private readonly Harmony harmony = new Harmony("Huntress.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)(object)config).SyncComplete = (Action)Delegate.Combine(((SyncedInstance)(object)config).SyncComplete, new Action(CheckSynced)); Commands = TerminalRegistry.CreateTerminalRegistry(); Commands.RegisterFrom(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 CSync 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.Instance.SyncedVar}"); } } } } namespace RandomMoons.Utils { internal class States { public static bool closedUponConfirmation = false; public static bool isInteracting = false; public static bool hasGambled = false; public static List visitedMoons = new List(); 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 = 18; 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(); [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(); } if (!__instance.CanChangeLevels() || !SyncedEntry.op_Implicit(SyncedInstance.Instance.AutoExplore) || States.hasGambled) { return; } if (TimeOfDay.Instance.daysUntilDeadline > 0) { SelectableLevel val = ExploreCommand.ChooseRandomMoon(terminal.moonsCatalogueList); __instance.ChangeLevelServerRpc(val.levelID, terminal.groupCredits); States.lastVisitedMoon = val.PlanetName; States.hasGambled = true; return; } SelectableLevel val2 = ExploreCommand.ChooseRandomMoon(terminal.moonsCatalogueList); if (terminal.moonsCatalogueList.Length < States.companyBuildingLevelID) { __instance.ChangeLevelServerRpc(3, terminal.groupCredits); States.lastVisitedMoon = val2.PlanetName; States.hasGambled = true; } else { __instance.ChangeLevelServerRpc(States.companyBuildingLevelID, terminal.groupCredits); States.lastVisitedMoon = val2.PlanetName; States.hasGambled = 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.Instance.MoonSelectionType.Value != MoonSelection.MODDED) { return; } SelectableLevel[] moonsCatalogueList = __instance.moonsCatalogueList; foreach (SelectableLevel val in moonsCatalogueList) { if (!States.vanillaMoons.Contains(val.sceneName)) { return; } } SyncedInstance.Instance.MoonSelectionType.Value = MoonSelection.ALL; } } } namespace RandomMoons.ConfigUtils { [DataContract] public class RMConfig : SyncedConfig { [DataMember] public SyncedEntry AutoExplore { get; private set; } [DataMember] public SyncedEntry CheckIfVisitedDuringQuota { get; private set; } [DataMember] public SyncedEntry RestrictedCommandUsage { get; private set; } [DataMember] public SyncedEntry MoonSelectionType { get; private set; } [DataMember] public SyncedEntry SyncedVar { get; private set; } public RMConfig(ConfigFile cfg) : base("Huntress.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_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Expected O, but got Unknown //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Expected O, but got Unknown //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Expected O, but got Unknown //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Expected O, but got Unknown //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Expected O, but got Unknown //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Expected O, but got Unknown ConfigManager.Register(this); AutoExplore = Extensions.BindSyncedEntry(cfg, new ConfigDefinition("General", "AutoExplore"), false, new ConfigDescription("Automatically travels to a random moon after leaving one.", (AcceptableValueBase)null, Array.Empty())); CheckIfVisitedDuringQuota = Extensions.BindSyncedEntry(cfg, new ConfigDefinition("General", "RegisterTravels"), false, new ConfigDescription("The same moon can't be chosen twice while the quota hasn't changed (Idk if works, probably does)", (AcceptableValueBase)null, Array.Empty())); RestrictedCommandUsage = Extensions.BindSyncedEntry(cfg, new ConfigDefinition("General", "PreventMultipleTravels"), true, new ConfigDescription("Prevents the players to execute explore multiple times without landing", (AcceptableValueBase)null, Array.Empty())); MoonSelectionType = Extensions.BindSyncedEntry(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())); SyncedVar = Extensions.BindSyncedEntry(cfg, new ConfigDefinition("Debug leftover", "DebuG leftover"), 4, new ConfigDescription("This is a debug variable, you can ignore it", (AcceptableValueBase)null, Array.Empty())); BoolCheckBoxConfigItem val = new BoolCheckBoxConfigItem(AutoExplore.Entry, new BoolCheckBoxOptions { RequiresRestart = false }); BoolCheckBoxConfigItem val2 = new BoolCheckBoxConfigItem(CheckIfVisitedDuringQuota.Entry, new BoolCheckBoxOptions { RequiresRestart = false }); BoolCheckBoxConfigItem val3 = new BoolCheckBoxConfigItem(RestrictedCommandUsage.Entry, new BoolCheckBoxOptions { RequiresRestart = false }); EnumDropDownConfigItem val4 = new EnumDropDownConfigItem(MoonSelectionType.Entry, false); LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val); LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2); LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val3); LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val4); 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.Instance.CheckIfVisitedDuringQuota}, " + $"{SyncedInstance.Instance.RestrictedCommandUsage}, {SyncedInstance.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(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_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_018f: 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 (StartOfRound.Instance.shipHasLanded || !StartOfRound.Instance.CanChangeLevels()) { return "Please wait before travelling to a new moon !"; } if (States.hasGambled && SyncedEntry.op_Implicit(SyncedInstance.Instance.RestrictedCommandUsage)) { return "You cannot go to another random moon yet!"; } SelectableLevel val = ChooseRandomMoon(terminal.moonsCatalogueList); StartOfRound.Instance.ChangeLevelServerRpc(val.levelID, terminal.groupCredits); 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.Instance.MoonSelectionType.Value; if ((value == MoonSelection.VANILLA && !IsMoonVanilla(moons[num])) || (value == MoonSelection.MODDED && IsMoonVanilla(moons[num]))) { return ChooseRandomMoon(moons); } if (SyncedInstance.Instance.CheckIfVisitedDuringQuota.Value && States.visitedMoons.Contains(moons[num].PlanetName)) { return ChooseRandomMoon(moons); } if (States.visitedMoons.Count == moons.Length) { States.visitedMoons = new List(); } return moons[num]; } public static bool IsMoonVanilla(SelectableLevel moon) { return States.vanillaMoons.Contains(moon.sceneName); } } }