using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.AI; [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("MoonOfTheDay")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Adds daily and weekly seeded moons to the game!")] [assembly: AssemblyFileVersion("1.0.3.0")] [assembly: AssemblyInformationalVersion("1.0.3")] [assembly: AssemblyProduct("MoonOfTheDay")] [assembly: AssemblyTitle("MoonOfTheDay")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.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 MoonOfTheDay { [BepInPlugin("MoonOfTheDay", "MoonOfTheDay", "1.0.3")] public class Plugin : BaseUnityPlugin { public const string DailyMoonName = "Daily Moon"; public const string WeeklyMoonName = "Weekly Moon"; internal static ManualLogSource Logger; private Harmony _harmony; private bool _isPatched; private static int HighestLevelID { get; set; } = -1; public static Plugin Instance { get; private set; } private void Awake() { Instance = this; Logger = ((BaseUnityPlugin)this).Logger; PatchAll(); Logger.LogInfo((object)"Plugin MoonOfTheDay is loaded!"); } public void PatchAll() { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown if (_isPatched) { Logger.LogWarning((object)"Already patched!"); return; } Logger.LogDebug((object)"Patching..."); _harmony = new Harmony("MoonOfTheDay"); _harmony.PatchAll(); _isPatched = true; Logger.LogDebug((object)"Patched!"); } public void UnpatchAll() { if (!_isPatched) { Logger.LogWarning((object)"Not patched!"); return; } Logger.LogDebug((object)"Unpatching..."); _harmony.UnpatchSelf(); _isPatched = false; Logger.LogDebug((object)"Unpatched!"); } public static int GetDailySeed() { return (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalDays; } public static int GetWeeklySeed() { return (int)Math.Floor((float)(int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalDays / 7f); } private static void SetHighestLevelID(IEnumerable moons) { if (HighestLevelID == -1) { HighestLevelID = moons.Max((SelectableLevel moon) => moon.levelID); Logger.LogInfo((object)$"Highest vanilla level ID is {HighestLevelID}"); } } private static SelectableLevel GetCustomMoon(SelectableLevel[] moons, bool isDailyElseWeekly = true) { //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_011d: 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_0124: Unknown result type (might be due to invalid IL or missing references) SetHighestLevelID(moons); Random random = new Random(isDailyElseWeekly ? GetDailySeed() : GetWeeklySeed()); SelectableLevel[] array = moons.Where((SelectableLevel moon) => moon.levelID != 3).ToArray(); SelectableLevel obj = Object.Instantiate(array.OrderBy((SelectableLevel moon) => moon.levelID).ToArray()[random.Next(0, array.Length)]); ((Object)obj).name = (isDailyElseWeekly ? "Daily Moon" : "Weekly Moon"); obj.PlanetName = (isDailyElseWeekly ? "Daily Moon" : "Weekly Moon"); obj.LevelDescription = "This moon looks familiar..."; obj.riskLevel = "???"; obj.levelID = HighestLevelID + (isDailyElseWeekly ? 1 : 2); obj.randomWeathers = Array.Empty(); obj.overrideWeather = true; obj.currentWeather = (obj.overrideWeatherType = Enum.GetValues(typeof(LevelWeatherType)).Cast().ToArray()[random.Next(0, Enum.GetValues(typeof(LevelWeatherType)).Length)]); return obj; } public static SelectableLevel GetDailyMoon(SelectableLevel[] moons) { return GetCustomMoon(moons); } public static SelectableLevel GetWeeklyMoon(SelectableLevel[] moons) { return GetCustomMoon(moons, isDailyElseWeekly: false); } } public static class PluginInfo { public const string PLUGIN_GUID = "MoonOfTheDay"; public const string PLUGIN_NAME = "MoonOfTheDay"; public const string PLUGIN_VERSION = "1.0.3"; } } namespace MoonOfTheDay.Patches { public static class PatchRoundManagerHelpers { public static Vector3 SeededInsideUnitSphere(ref Random random) { //IL_0054: Unknown result type (might be due to invalid IL or missing references) return new Vector3((float)(random.NextDouble() * 2.0 - 1.0), (float)(random.NextDouble() * 2.0 - 1.0), (float)(random.NextDouble() * 2.0 - 1.0)); } } [HarmonyPatch(typeof(RoundManager))] public class PatchRoundManager { [HarmonyPatch("GetRandomNavMeshPositionInRadiusSpherical")] [HarmonyPrefix] public static bool GetRandomNavMeshPositionInRadiusSpherical(RoundManager __instance, ref Vector3 __result, Vector3 pos, float radius = 10f, NavMeshHit navHit = default(NavMeshHit)) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) pos = PatchRoundManagerHelpers.SeededInsideUnitSphere(ref __instance.LevelRandom) * radius + pos; __result = (NavMesh.SamplePosition(pos, ref navHit, radius, -1) ? ((NavMeshHit)(ref navHit)).position : pos); return false; } [HarmonyPatch("GetRandomNavMeshPositionInRadius")] [HarmonyPrefix] public static bool GetRandomNavMeshPositionInRadius(RoundManager __instance, ref Vector3 __result, Vector3 pos, float radius = 10f, NavMeshHit navHit = default(NavMeshHit)) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) float y = pos.y; pos = PatchRoundManagerHelpers.SeededInsideUnitSphere(ref __instance.LevelRandom) * radius + pos; pos.y = y; if (NavMesh.SamplePosition(pos, ref navHit, radius, -1)) { __result = ((NavMeshHit)(ref navHit)).position; return false; } Debug.Log((object)"Unable to get random nav mesh position in radius! Returning old pos"); __result = pos; return false; } } internal static class PatchStartOfRoundHelpers { public static bool IsVanillaMoon(SelectableLevel moon) { return !new string[2] { "Daily Moon", "Weekly Moon" }.Contains(moon.PlanetName); } } [HarmonyPatch(typeof(StartOfRound))] public class PatchStartOfRound { [HarmonyPatch("StartGame")] [HarmonyPrefix] public static void SetSeed(StartOfRound __instance) { if ((Object)(object)__instance.currentLevel == (Object)null || PatchStartOfRoundHelpers.IsVanillaMoon(__instance.currentLevel)) { return; } Plugin.Logger.LogDebug((object)("Setting seed for " + __instance.currentLevel.PlanetName + "...")); __instance.overrideRandomSeed = true; string planetName = __instance.currentLevel.PlanetName; if (!(planetName == "Daily Moon")) { if (planetName == "Weekly Moon") { __instance.overrideSeedNumber = Plugin.GetWeeklySeed(); } } else { __instance.overrideSeedNumber = Plugin.GetDailySeed(); } } [HarmonyPatch("Awake")] [HarmonyPostfix] public static void InsertMoons(StartOfRound __instance) { Plugin.Logger.LogInfo((object)"Inserting moons in StartOfRound..."); StartOfRound instance = StartOfRound.Instance; List list = instance.levels.ToList(); SelectableLevel dailyMoon = Plugin.GetDailyMoon(instance.levels); SelectableLevel weeklyMoon = Plugin.GetWeeklyMoon(instance.levels); list.RemoveAll((SelectableLevel level) => level.PlanetName == dailyMoon.PlanetName); list.RemoveAll((SelectableLevel level) => level.PlanetName == weeklyMoon.PlanetName); list.Add(dailyMoon); list.Add(weeklyMoon); instance.levels = list.ToArray(); } } internal static class PatchTerminalHelpers { public static void AddTerminalCommand(ref Terminal terminal, SelectableLevel moonToAdd) { //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Expected O, but got Unknown //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Expected O, but got Unknown //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Expected O, but got Unknown Plugin.Logger.LogDebug((object)("Adding terminal command for " + moonToAdd.PlanetName + "...")); TerminalKeyword noun = terminal.terminalNodes.allKeywords.First((TerminalKeyword keyword) => ((Object)keyword).name == "Confirm"); TerminalKeyword noun2 = terminal.terminalNodes.allKeywords.First((TerminalKeyword keyword) => ((Object)keyword).name == "Deny"); TerminalKeyword val = terminal.terminalNodes.allKeywords.First((TerminalKeyword keyword) => ((Object)keyword).name == "Route"); TerminalNode result = val.compatibleNouns[0].result.terminalOptions[0].result; TerminalKeyword val2 = ScriptableObject.CreateInstance(); ((Object)val2).name = GetKWNameForMoon(moonToAdd); val2.word = GetKWWordforMoon(moonToAdd); val2.defaultVerb = val; val2.compatibleNouns = Array.Empty(); TerminalNode val3 = ScriptableObject.CreateInstance(); ((Object)val3).name = GetTravelNodeNameForMoon(moonToAdd); val3.displayText = "Routing autopilot to " + moonToAdd.PlanetName + ".\n\nPlease enjoy your flight."; val3.clearPreviousText = true; val3.buyRerouteToMoon = moonToAdd.levelID; TerminalNode val4 = ScriptableObject.CreateInstance(); ((Object)val4).name = "Daily Moon"; val4.displayText = "The company has detected a rogue planet. It might not be available for long. Do you want to go there?\n\nIt is currently [currentPlanetTime] on this moon.\n\nPlease CONFIRM or DENY.\n\n"; val4.clearPreviousText = true; val4.displayPlanetInfo = moonToAdd.levelID; val4.buyRerouteToMoon = -2; val4.overrideOptions = true; val4.terminalOptions = (CompatibleNoun[])(object)new CompatibleNoun[2] { new CompatibleNoun { noun = noun2, result = result }, new CompatibleNoun { noun = noun, result = val3 } }; List list = terminal.terminalNodes.allKeywords.ToList(); list.Add(val2); terminal.terminalNodes.allKeywords = list.ToArray(); List list2 = val.compatibleNouns.ToList(); list2.Add(new CompatibleNoun { noun = val2, result = val4 }); val.compatibleNouns = list2.ToArray(); TerminalNode specialKeywordResult = terminal.terminalNodes.allKeywords.First((TerminalKeyword keyword) => ((Object)keyword).name == "Moons").specialKeywordResult; specialKeywordResult.displayText = specialKeywordResult.displayText + "* " + moonToAdd.PlanetName + " [planetTime]\n"; Plugin.Logger.LogDebug((object)("Added terminal command for " + moonToAdd.PlanetName + ".")); } public static string GetKWNameForMoon(SelectableLevel moon) { return "KW" + moon.PlanetName.ToLower().Replace(" ", "-"); } public static string GetKWWordforMoon(SelectableLevel moon) { return moon.PlanetName.ToLower().Replace(" ", "-"); } public static string GetTravelNodeNameForMoon(SelectableLevel moon) { return "Travel" + moon.PlanetName.ToLower().Replace(" ", "-"); } } [HarmonyPatch(typeof(Terminal))] public class PatchTerminal { [HarmonyPatch("Awake")] [HarmonyPostfix] public static void InsertMoons(Terminal __instance) { Plugin.Logger.LogDebug((object)"Inserting moons in Terminal..."); SelectableLevel dailyMoon = Plugin.GetDailyMoon(__instance.moonsCatalogueList); SelectableLevel weeklyMoon = Plugin.GetWeeklyMoon(__instance.moonsCatalogueList); List list = __instance.moonsCatalogueList.ToList(); list.RemoveAll((SelectableLevel moon) => moon.PlanetName == dailyMoon.PlanetName); list.RemoveAll((SelectableLevel moon) => moon.PlanetName == weeklyMoon.PlanetName); list.Add(dailyMoon); list.Add(weeklyMoon); __instance.moonsCatalogueList = list.ToArray(); } [HarmonyPatch("Awake")] [HarmonyPostfix] public static void AddTerminalCommands(Terminal __instance) { SelectableLevel dailyMoon = Plugin.GetDailyMoon(__instance.moonsCatalogueList); SelectableLevel weeklyMoon = Plugin.GetWeeklyMoon(__instance.moonsCatalogueList); if (__instance.terminalNodes.allKeywords.Any((TerminalKeyword keyword) => ((Object)keyword).name == PatchTerminalHelpers.GetKWNameForMoon(dailyMoon))) { Plugin.Logger.LogDebug((object)"Terminal nodes have already been modified."); return; } Plugin.Logger.LogDebug((object)"Modifying terminal nodes..."); PatchTerminalHelpers.AddTerminalCommand(ref __instance, dailyMoon); PatchTerminalHelpers.AddTerminalCommand(ref __instance, weeklyMoon); TerminalNode specialKeywordResult = __instance.terminalNodes.allKeywords.First((TerminalKeyword keyword) => ((Object)keyword).name == "Moons").specialKeywordResult; specialKeywordResult.displayText += "\n"; } } }