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 TerminalSeedPicker v2.0.0
plugins/TerminalSeedPicker/TerminalSeedPicker.dll
Decompiled 2 weeks agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using LethalNetworkAPI; using Microsoft.CodeAnalysis; using TMPro; using TerminalApi; using TerminalApi.Classes; 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("TerminalSeedPicker")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("TerminalSeedPicker")] [assembly: AssemblyTitle("TerminalSeedPicker")] [assembly: AssemblyVersion("1.0.0.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace TerminalSeedPicker { [BepInPlugin("thej01.lc.TerminalSeedPicker", "TerminalSeedPicker", "2.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public enum TerminalSounds { PurchaseSFX, TypoError, LoadImage, Alarm } public static class SeedVerbs { public static List<TerminalKeyword> setVerbs = new List<TerminalKeyword> { TerminalApi.CreateTerminalKeyword("set", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("s", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("change", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("modify", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("alter", true, (TerminalNode)null) }; public static List<TerminalKeyword> getVerbs = new List<TerminalKeyword> { TerminalApi.CreateTerminalKeyword("get", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("g", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("recieve", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("check", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("see", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("obtain", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("print", true, (TerminalNode)null) }; public static List<TerminalKeyword> randomVerbs = new List<TerminalKeyword> { TerminalApi.CreateTerminalKeyword("random", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("rand", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("r", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("randomize", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("randomise", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("generate", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("gen", true, (TerminalNode)null), TerminalApi.CreateTerminalKeyword("choose", true, (TerminalNode)null) }; } public enum SeedType { Random, SetNum, SetString, SetRandomized, SetChallengeMoon } [Serializable] public class SeedInfo { [SerializeField] public int seedNum; [SerializeField] public SeedType seedType; [SerializeField] public string seedWord = ""; public SeedInfo(bool fromCurrentMoon = false) { if (fromCurrentMoon) { InitFromCurrentMoon(); } else { Reset(); } } public SeedInfo(int seedNum, SeedType seedType, string seedWord = "") { this.seedNum = seedNum; this.seedWord = seedWord; this.seedType = seedType; } public void Reset() { seedNum = 0; seedWord = ""; seedType = SeedType.Random; } public void InitFromCurrentMoon() { Reset(); seedNum = StartOfRound.Instance.randomMapSeed; seedType = SeedType.Random; if (StartOfRound.Instance.isChallengeFile) { seedType = SeedType.SetChallengeMoon; } } public string GetTerminalSecondLine() { string result = ""; switch (seedType) { case SeedType.SetString: result = "[Generated from '" + seedWord + "']"; break; case SeedType.SetRandomized: result = "[Randomly generated]"; break; case SeedType.SetChallengeMoon: result = "[Challenge Moon]"; break; default: result = $"UNDEFINED SEEDTYPE: {seedType}"; break; case SeedType.Random: case SeedType.SetNum: break; } return result; } public string TerminalTextWhenSet() { string terminalSecondLine = GetTerminalSecondLine(); string text = $"[Seed has been set to {seedNum}.]"; if (!Utility.IsNullOrWhiteSpace(terminalSecondLine)) { text += "\n"; } return text + terminalSecondLine + "\n\n"; } public string GetTerminalEntry() { string terminalSecondLine = GetTerminalSecondLine(); string text = $"[Random moon seed is {seedNum}]"; if (seedType != 0) { text = $"[Set moon seed is {seedNum}]"; } if (!Utility.IsNullOrWhiteSpace(terminalSecondLine)) { text += "\n"; } return text + terminalSecondLine + "\n\n"; } public string GetLoadingText() { string text = $"Set Seed: {seedNum}"; string text2 = ""; switch (seedType) { case SeedType.SetString: text2 = "(Generated from: '" + seedWord + "')"; break; case SeedType.SetRandomized: text2 = "(Randomly Generated)"; break; case SeedType.SetChallengeMoon: text2 = "(Challenge Moon)"; break; default: text2 = "(Unknown Origin)"; break; case SeedType.SetNum: break; } if (!Utility.IsNullOrWhiteSpace(text2)) { text = text + " " + text2; } return text; } public SeedInfo Copy() { return new SeedInfo(seedNum, seedType, seedWord); } } public const string modGUID = "thej01.lc.TerminalSeedPicker"; public const string modName = "TerminalSeedPicker"; public const string modVersion = "2.0.0"; public static LNetworkMessage<SeedInfo> syncNextMoonSeedInfo; public static LNetworkEvent requestSeedFromClient; public const int minSeed = 1; public const int maxSeed = 100000000; public static readonly Harmony harmony; public static ManualLogSource Log; public static TerminalNode seedNode; public static TerminalKeyword seedKeyword; public static Terminal? terminal; public static SeedInfo currentMoonSeedInfo; public static SeedInfo nextMoonSeedInfo; public static void AddVerbToSeed(List<TerminalKeyword> keywords) { foreach (TerminalKeyword keyword in keywords) { TerminalExtenstionMethods.AddCompatibleNoun(keyword, seedKeyword, seedNode); TerminalApi.AddTerminalKeyword(keyword); } } public void Awake() { //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Log.LogInfo((object)"TerminalSeedPicker 2.0.0 is loading..."); Log.LogInfo((object)"Loading patches..."); harmony.PatchAll(); Log.LogInfo((object)"Loaded patches."); Log.LogInfo((object)"Adding terminal commands..."); AddVerbToSeed(SeedVerbs.setVerbs); AddVerbToSeed(SeedVerbs.getVerbs); AddVerbToSeed(SeedVerbs.randomVerbs); seedKeyword.defaultVerb = SeedVerbs.getVerbs[0]; TerminalApi.AddTerminalKeyword(seedKeyword, new CommandInfo { Title = "[Set/Get/Random] SEED [Seed]", TriggerNode = seedNode, DisplayTextSupplier = RunSeedCommand, Category = "Other", Description = "To modify the current moon seed or get information about it. Defaults to \"Get\"\nType \"Set SEED [Seed]\" to set a new moon seed. [Seed] can be text OR numbers.\nType \"Get SEED\" to have the terminal print info on the current seed.\nType \"Random SEED\" to set the moon seed to a completely random one." }); Log.LogInfo((object)"Added terminal commands."); Log.LogInfo((object)"TerminalSeedPicker 2.0.0 is loaded."); } public static string RunSeedCommand() { string[] array = TerminalApi.GetTerminalInput().Trim().Split(' '); bool flag = false; List<string> list = new List<string>(); for (int i = 0; i < array.Length; i++) { if (flag) { list.Add(array[i]); } else if (array[i].ToLower() == seedKeyword.word) { flag = true; i -= 2; if (i < -1) { i = -1; } } } array = list.ToArray(); string text = array[0].ToLower(); foreach (TerminalKeyword setVerb in SeedVerbs.setVerbs) { if (setVerb.word == text) { return SetSeedCommand(array); } } foreach (TerminalKeyword getVerb in SeedVerbs.getVerbs) { if (getVerb.word == text) { return GetSeedCommand(); } } foreach (TerminalKeyword randomVerb in SeedVerbs.randomVerbs) { if (randomVerb.word == text) { return RandomSeedCommand(); } } return GetSeedCommand(); } public static string SetSeedCommand(string[] inputSplitOriginal) { string[] array = new string[3]; bool flag = false; bool flag2 = false; string text = ""; array[0] = inputSplitOriginal[0]; array[1] = inputSplitOriginal[1]; for (int i = 2; i < inputSplitOriginal.Length; i++) { flag2 = false; if (!Utility.IsNullOrWhiteSpace(inputSplitOriginal[i]) && !flag) { flag = true; flag2 = true; array[2] = inputSplitOriginal[i]; } if (flag && !Utility.IsNullOrWhiteSpace(inputSplitOriginal[i])) { if (!flag2) { text += " "; } text += inputSplitOriginal[i]; } } text.Trim(); text = text.Replace("\"", ""); text = text.Replace("&", ""); text = text.Replace("^", ""); text = text.Replace("@", ""); text = text.Replace("+", ""); text = text.Replace("~", ""); if (inputSplitOriginal.Length < 3 || !flag || Utility.IsNullOrWhiteSpace(text)) { PlayTerminalAudio(TerminalSounds.TypoError); return "[Seed is empty!]\n\n"; } bool flag3 = false; flag3 = int.TryParse(text, out var result); if (flag3 && result > 100000000) { PlayTerminalAudio(TerminalSounds.TypoError); return "[Seed cannot be greater than " + 100000000.ToString("N0") + "!]\n\n"; } if (flag3 && result < 1) { PlayTerminalAudio(TerminalSounds.TypoError); return "[Seed cannot be less than " + 1.ToString("N0") + "!]\n\n"; } if (!RoundManager.Instance.playersManager.inShipPhase) { PlayTerminalAudio(TerminalSounds.TypoError); return "[Seed cannot be changed after landing.]\n\n"; } if (StartOfRound.Instance.isChallengeFile) { PlayTerminalAudio(TerminalSounds.TypoError); return "[Seed cannot be changed on a Challenge Moon.]\n\n"; } if (!flag3) { result = StringToSeed(text); } nextMoonSeedInfo.Reset(); nextMoonSeedInfo.seedNum = result; if (flag3) { nextMoonSeedInfo.seedType = SeedType.SetNum; } else { nextMoonSeedInfo.seedType = SeedType.SetString; nextMoonSeedInfo.seedWord = text; } SendSeedToAll(); PlayTerminalAudio(TerminalSounds.LoadImage); return nextMoonSeedInfo.TerminalTextWhenSet(); } public static int StringToSeed(string seedString) { int hashCode = seedString.GetHashCode(); hashCode = Math.Abs(hashCode); hashCode %= 100000000; if (hashCode < 1) { hashCode++; } return hashCode; } public static string GetSeedCommand() { if (StartOfRound.Instance.inShipPhase) { PlayTerminalAudio(TerminalSounds.TypoError); if (Random.Range(1, 100) == 1) { return "[No.]\n\n"; } return "[Must land on a moon first before checking seed!]\n\n"; } return currentMoonSeedInfo.GetTerminalEntry(); } public static string RandomSeedCommand() { if (!RoundManager.Instance.playersManager.inShipPhase) { PlayTerminalAudio(TerminalSounds.TypoError); return "[Seed cannot be changed after landing.]\n\n"; } if (StartOfRound.Instance.isChallengeFile) { PlayTerminalAudio(TerminalSounds.TypoError); return "[Seed cannot be changed on a Challenge Moon.]\n\n"; } PlayTerminalAudio(TerminalSounds.LoadImage); nextMoonSeedInfo.seedNum = Random.Range(1, 100000000); nextMoonSeedInfo.seedType = SeedType.SetRandomized; SendSeedToAll(); return nextMoonSeedInfo.TerminalTextWhenSet(); } public static void SendSeedToAll() { if (((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsServer) { syncNextMoonSeedInfo.SendClients(nextMoonSeedInfo); return; } syncNextMoonSeedInfo.SendOtherClients(nextMoonSeedInfo); syncNextMoonSeedInfo.SendServer(nextMoonSeedInfo); } public static void SyncNextMoonSeedShared(SeedInfo info) { Log.LogInfo((object)"Recieved seed info sync, values:"); nextMoonSeedInfo = info; Log.LogInfo((object)$"seedNum: {nextMoonSeedInfo.seedNum} seedType: {nextMoonSeedInfo.seedType} seedWord: {nextMoonSeedInfo.seedWord}"); } public static void SyncNextMoonSeedInfo(SeedInfo info) { SyncNextMoonSeedShared(info); } public static void SyncNextMoonSeedInfo(SeedInfo info, ulong clientID) { SyncNextMoonSeedShared(info); } public static void RequestSeedFromClient(ulong clientID) { syncNextMoonSeedInfo.SendClient(nextMoonSeedInfo, clientID); } public static Terminal GetTerminal() { if ((Object)(object)terminal == (Object)null) { terminal = Object.FindObjectOfType<Terminal>(); } return terminal; } public static void PlayTerminalAudio(TerminalSounds audio) { GetTerminal().PlayTerminalAudioServerRpc((int)audio); } static Plugin() { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown Action<SeedInfo> action = SyncNextMoonSeedInfo; Action<SeedInfo, ulong> action2 = SyncNextMoonSeedInfo; syncNextMoonSeedInfo = LNetworkMessage<SeedInfo>.Connect("thej01.lc.TerminalSeedPicker.syncNextMoonSeedInfo", (Action<SeedInfo, ulong>)SyncNextMoonSeedInfo, action, action2); requestSeedFromClient = LNetworkEvent.Connect("thej01.lc.TerminalSeedPicker.requestSeedFromClient", (Action<ulong>)RequestSeedFromClient, (Action)null, (Action<ulong>)null); harmony = new Harmony("thej01.lc.TerminalSeedPicker"); Log = new ManualLogSource("thej01.lc.TerminalSeedPicker"); seedNode = TerminalApi.CreateTerminalNode("this shouldn't appear\n\n", true, ""); seedKeyword = TerminalApi.CreateTerminalKeyword("seed", false, (TerminalNode)null); terminal = null; currentMoonSeedInfo = new SeedInfo(); nextMoonSeedInfo = new SeedInfo(); } } } namespace TerminalSeedPicker.Patches { [HarmonyPatch(typeof(PlayerControllerB))] public class PlayerControllerBPatch { [HarmonyPatch("ConnectClientToPlayerObject")] [HarmonyPostfix] public static void ResetSeedInfo() { Plugin.currentMoonSeedInfo.Reset(); Plugin.nextMoonSeedInfo.Reset(); StartOfRound.Instance.overrideRandomSeed = false; if (!((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsServer) { Plugin.requestSeedFromClient.InvokeServer(); } } } [HarmonyPatch(typeof(RoundManager))] public class RoundManagerPatch { [HarmonyPatch("GenerateNewLevelClientRpc")] [HarmonyPostfix] public static void ChangeText(RoundManager __instance) { if (Plugin.nextMoonSeedInfo.seedType != 0 && !StartOfRound.Instance.isChallengeFile) { Plugin.currentMoonSeedInfo = Plugin.nextMoonSeedInfo.Copy(); } else { Plugin.currentMoonSeedInfo.InitFromCurrentMoon(); } if (Plugin.currentMoonSeedInfo.seedType != 0) { ((TMP_Text)HUDManager.Instance.loadingText).text = Plugin.currentMoonSeedInfo.GetLoadingText(); } } [HarmonyPatch("FinishGeneratingNewLevelClientRpc")] [HarmonyPostfix] public static void ResetNextMoonInfo() { Plugin.nextMoonSeedInfo.Reset(); } [HarmonyPatch("LoadNewLevel")] [HarmonyPostfix] public static void DisableOverride() { StartOfRound.Instance.overrideRandomSeed = false; } } [HarmonyPatch(typeof(StartOfRound))] public class StartOfRoundPatch { [HarmonyPatch("StartGame")] [HarmonyPrefix] public static void ApplyNewSeed(StartOfRound __instance) { if (Plugin.nextMoonSeedInfo.seedType != 0 && !StartOfRound.Instance.isChallengeFile) { __instance.overrideRandomSeed = true; __instance.overrideSeedNumber = Plugin.nextMoonSeedInfo.seedNum; } } } }