using 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.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using LethalConstellations.PluginCore;
using Microsoft.CodeAnalysis;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("RandomMoonFX")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+8cb5cd06dd5dd34046596f972e5633d1558841cf")]
[assembly: AssemblyProduct("RandomMoonFX")]
[assembly: AssemblyTitle("RandomMoonFX")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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 RandomMoonFX
{
internal class Config
{
public readonly List<string> MoonsBlacklist = new List<string>();
public readonly ConfigEntry<bool> CelestialTintAnimation;
public readonly ConfigEntry<bool> ChameleonAnimation;
public readonly ConfigEntry<float> AnimationTimeOverride;
public readonly ConfigEntry<bool> ActivateRandomMoons;
public readonly ConfigEntry<bool> ExcludePreviouslyVisited;
public readonly ConfigEntry<bool> ConstellationsCheck;
public readonly ConfigEntry<string> MoonsBlacklistStr;
public readonly ConfigEntry<bool> QuotaCheck;
public readonly ConfigEntry<bool> RandomizeLastDay;
public readonly ConfigEntry<bool> GaletryCompany;
public readonly ConfigEntry<bool> ActivateFreeMoons;
public Config(ConfigFile cfg)
{
cfg.SaveOnConfigSet = false;
CelestialTintAnimation = cfg.Bind<bool>("Routing animation", "Celestial_Tint animation", true, "Enable compatibility with Celestial_Tint routing animation (which is a little bit longer than vanilla).\nWill be automatically false if Celestial_Tint is not installed.");
ChameleonAnimation = cfg.Bind<bool>("Routing animation", "Chameleon animation", true, "Enable compatibility with Chameleon routing animation (which is longer than vanilla).\nWill be automatically false if Chameleon is not installed.");
AnimationTimeOverride = cfg.Bind<float>("Routing animation", "Animation time override", -1f, "If not -1, will change the time of the routing animation.\nIf you have Celestial_Tint or Chameleon compatibility enabled the time will be changed automatically but you can still modify it with this config.\nDefault value is 1.5, Celestial_Tint is 4 and Chameleon is 7.5.");
ActivateRandomMoons = cfg.Bind<bool>("Randomization method", "Activate Random Moons", true, "Allow the mod to randomize the moon. Disabling this config effectively prevent the mod to work.\nFor testing purpose.");
ExcludePreviouslyVisited = cfg.Bind<bool>("Randomization method", "Exclude previously visited", false, "Enable this if you want to exclude already visited moons from the randomization method. This will reset when all moons have been seen once.");
ConstellationsCheck = cfg.Bind<bool>("Randomization method", "LethalConstellations check", true, "Enable compatibility with LethalConstellations by preventing the randomization method to choose a moon that is not included in the current constellations.\nWill be automatically false if LethalConstellations is not installed.");
MoonsBlacklistStr = cfg.Bind<string>("Randomization method", "Moons Blacklist", "", "Comma separated list of moons that will never be chosen by the randomization method, if you don't want to play on specifics moons.\nThis Experimentation,Embrion,Asteroid-14,Espira is a valid example.");
QuotaCheck = cfg.Bind<bool>("Last day check", "Quota check", true, "If true, the ship will route to Gordion on the last day if quota has not been met yet. If false, there will be no quota check and the ship will route to Gordion only on the last day.");
RandomizeLastDay = cfg.Bind<bool>("Last day check", "Randomize last day", false, "Enable this if you don't want to auto route to Gordion on the last day if there is not enough scraps in the ship to meet quota (other players potential dead bodies included), this allows you to randomize a moon on the last day to mess around but you will be fired at the end of the day.");
GaletryCompany = cfg.Bind<bool>("Last day check", "Galetry Company Moon", true, "Enable compatibility with Wesley's Moons special company moon 'Galetry'. This will allow this mod to route to Galetry on the last day instead of Gordion.\nWill be automatically false if Wesley's Moons is not installed.");
ActivateFreeMoons = cfg.Bind<bool>("Misc", "Activate Free Moons", true, "Prevent credits consumption when manually routing to a moon in the terminal. This is for avoiding people wasting money on a moon that is not going to be played because of the randomization method.\nThis config works even if 'Activate Random Moons' is false.");
cfg.Save();
cfg.SaveOnConfigSet = true;
}
public void SetupCustomConfigs()
{
if (MoonsBlacklistStr == null || MoonsBlacklistStr.Value == "")
{
return;
}
foreach (string item in from s in MoonsBlacklistStr.Value.Split(',')
select s.Trim())
{
MoonsBlacklist.Add(item);
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPrefix]
[HarmonyPatch("StartGame")]
public static bool RandomizeMoonPatch()
{
if (Plugin.instance.IsStarting)
{
Plugin.instance.IsStarting = false;
return true;
}
Plugin.instance.RouteRandomPlanet();
return false;
}
[HarmonyPostfix]
[HarmonyPatch("TravelToLevelEffects")]
public static IEnumerator StartMoonPatch(IEnumerator result)
{
while (result.MoveNext())
{
yield return result.Current;
}
if (Plugin.instance.IsStarting)
{
StartMatchLever lever = Object.FindObjectOfType<StartMatchLever>();
lever.triggerScript.interactable = false;
yield return (object)new WaitForSeconds(Plugin.instance.AnimationTime);
lever.triggerScript.interactable = true;
Plugin.instance.StartRandomPlanet();
}
}
}
[HarmonyPatch(typeof(StartMatchLever))]
internal class StartMatchLeverPatch
{
[HarmonyPrefix]
[HarmonyPatch("BeginHoldingInteractOnLever")]
public static bool DisabledLastDayWarningPatch()
{
if (StartOfRound.Instance.CanChangeLevels() && Plugin.instance.LastDayOfQuota())
{
return false;
}
return true;
}
[HarmonyPostfix]
[HarmonyPatch("BeginHoldingInteractOnLever")]
public static void DisabledLongHoldTime(ref StartMatchLever __instance)
{
if (TimeOfDay.Instance.daysUntilDeadline <= 0 && __instance.playersManager.inShipPhase && StartOfRound.Instance.currentLevel.planetHasTime && Plugin.instance.LastDayOfQuota())
{
__instance.triggerScript.timeToHold = 0.7f;
}
}
}
[HarmonyPatch(typeof(Terminal))]
internal class TerminalPatch
{
[HarmonyPostfix]
[HarmonyPatch("Awake")]
public static void AwakePatch()
{
Plugin.instance.terminal = Object.FindObjectOfType<Terminal>();
}
[HarmonyPrefix]
[HarmonyPatch("LoadNewNode")]
public static void LoadNewNodePrePatch(ref TerminalNode node)
{
if ((Object)(object)Plugin.instance.terminal != (Object)null && (Object)(object)node != (Object)null && node.buyRerouteToMoon == -2)
{
Plugin.instance.terminalCostOfItems = Plugin.instance.terminal.totalCostOfItems;
Plugin.instance.terminal.totalCostOfItems = 0;
}
}
[HarmonyPostfix]
[HarmonyPatch("LoadNewNode")]
public static void LoadNewNodePostPatch(ref TerminalNode node)
{
if ((Object)(object)Plugin.instance.terminal != (Object)null && (Object)(object)node != (Object)null && Plugin.instance.terminalCostOfItems != -5)
{
Plugin.instance.terminal.totalCostOfItems = 0;
Plugin.instance.terminalCostOfItems = -5;
}
}
[HarmonyPrefix]
[HarmonyPatch("LoadNewNodeIfAffordable")]
public static void LoadNewNodeIfAffordablePatch(ref TerminalNode node)
{
if ((Object)(object)Plugin.instance.terminal != (Object)null && (Object)(object)node != (Object)null && node.buyRerouteToMoon != -1)
{
node.itemCost = 0;
}
}
}
[BepInPlugin("zigzag.randommoonfx", "RandomMoonFX", "1.3.4")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
private const string GUID = "zigzag.randommoonfx";
private const string NAME = "RandomMoonFX";
private const string VERSION = "1.3.4";
public static Plugin instance;
private readonly Harmony harmony = new Harmony("zigzag.randommoonfx");
private readonly int GordionID = 3;
public int GaletryID = -99;
public float AnimationTime = 1.5f;
public bool IsStarting = false;
public Terminal? terminal;
public int terminalCostOfItems = -5;
public bool constellationsCompatibility = false;
public List<string> VisitedMoons = new List<string>();
internal static Config config { get; private set; }
private void Awake()
{
instance = this;
SetParameters();
if (config.ActivateRandomMoons.Value)
{
harmony.CreateClassProcessor(typeof(StartOfRoundPatch), true).Patch();
harmony.CreateClassProcessor(typeof(StartMatchLeverPatch), true).Patch();
}
if (config.ActivateFreeMoons.Value)
{
harmony.CreateClassProcessor(typeof(TerminalPatch), true).Patch();
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"RandomMoonFX is loaded !");
}
private void SetParameters()
{
config = new Config(((BaseUnityPlugin)this).Config);
config.SetupCustomConfigs();
if (config.ChameleonAnimation.Value && Chainloader.PluginInfos.ContainsKey("butterystancakes.lethalcompany.chameleon"))
{
AnimationTime = 7.5f;
}
if (config.CelestialTintAnimation.Value && Chainloader.PluginInfos.ContainsKey("CelestialTint"))
{
AnimationTime = 4f;
}
if (config.AnimationTimeOverride.Value >= 0f)
{
AnimationTime = config.AnimationTimeOverride.Value;
}
if (config.GaletryCompany.Value && Chainloader.PluginInfos.ContainsKey("JacobG5.WesleyMoons"))
{
GaletryID = -1;
}
if (config.ConstellationsCheck.Value && Chainloader.PluginInfos.ContainsKey("com.github.darmuh.LethalConstellations"))
{
constellationsCompatibility = true;
}
}
public bool LastDayOfQuota()
{
if (Utils.IsLastDayRandom())
{
return false;
}
if (config.QuotaCheck.Value)
{
return TimeOfDay.Instance.daysUntilDeadline == 0 && TimeOfDay.Instance.profitQuota > TimeOfDay.Instance.quotaFulfilled;
}
return TimeOfDay.Instance.daysUntilDeadline == 0;
}
public void RouteRandomPlanet()
{
if (LastDayOfQuota())
{
if (GaletryID != -99)
{
if (GaletryID == -1)
{
SelectableLevel[] levels = StartOfRound.Instance.levels;
foreach (SelectableLevel val in levels)
{
if (val.PlanetName == "98 Galetry")
{
GaletryID = val.levelID;
break;
}
}
}
if (GaletryID != -1)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Force navigating to 98 Galetry");
StartOfRound.Instance.ChangeLevelServerRpc(GaletryID, Object.FindObjectOfType<Terminal>().groupCredits);
IsStarting = true;
return;
}
((BaseUnityPlugin)this).Logger.LogError((object)"Galetry Moon was not found");
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"Force navigating to the Company Building");
StartOfRound.Instance.ChangeLevelServerRpc(GordionID, Object.FindObjectOfType<Terminal>().groupCredits);
}
else
{
SelectableLevel val2 = TimeOfDay.Instance.currentLevel;
while (val2.PlanetName == TimeOfDay.Instance.currentLevel.PlanetName)
{
val2 = StartOfRound.Instance.levels[Random.Range(0, StartOfRound.Instance.levels.Length)];
if (!Utils.IsMoonValid(val2))
{
val2 = TimeOfDay.Instance.currentLevel;
}
}
((BaseUnityPlugin)this).Logger.LogInfo((object)("Navigating to " + val2.PlanetName));
StartOfRound.Instance.ChangeLevelServerRpc(val2.levelID, Object.FindObjectOfType<Terminal>().groupCredits);
}
IsStarting = true;
}
public void StartRandomPlanet()
{
StartOfRound.Instance.StartGameServerRpc();
}
}
internal class Utils
{
public static bool IsLastDayRandom()
{
if (TimeOfDay.Instance.daysUntilDeadline != 0 || !Plugin.config.RandomizeLastDay.Value)
{
return false;
}
bool? inShip = true;
int num = 5 * (StartOfRound.Instance.allPlayerObjects.Length - 1);
int num2 = Object.FindObjectsOfType<GrabbableObject>().Where(delegate(GrabbableObject o)
{
int result;
if (o.itemProperties.isScrap && o.itemProperties.minValue > 0 && !(o is RagdollGrabbableObject))
{
StunGrenadeItem val = (StunGrenadeItem)(object)((o is StunGrenadeItem) ? o : null);
if (val == null || !val.hasExploded || !val.DestroyGrenade)
{
result = ((!inShip.HasValue || (o.isInShipRoom == inShip && o.isInElevator == inShip)) ? 1 : 0);
goto IL_0094;
}
}
result = 0;
goto IL_0094;
IL_0094:
return (byte)result != 0;
}).ToList()
.Sum((GrabbableObject s) => s.scrapValue);
if (num2 + num + TimeOfDay.Instance.quotaFulfilled >= TimeOfDay.Instance.profitQuota)
{
return false;
}
return true;
}
public static bool IsMoonValid(SelectableLevel selectableLevel)
{
if (selectableLevel.PlanetName == "44 Liquidation" || selectableLevel.PlanetName == "71 Gordion" || (Plugin.instance.GaletryID != -99 && selectableLevel.PlanetName == "98 Galetry"))
{
return false;
}
if (IsMoonBlacklisted(selectableLevel) || (Plugin.instance.constellationsCompatibility && !IsMoonValidFromConstellation(selectableLevel)))
{
return false;
}
if (!Plugin.config.ExcludePreviouslyVisited.Value || Plugin.instance.constellationsCompatibility)
{
return true;
}
if (Plugin.instance.VisitedMoons.Count == 0 || !Plugin.instance.VisitedMoons.Contains(selectableLevel.PlanetName))
{
Plugin.instance.VisitedMoons.Add(selectableLevel.PlanetName);
return true;
}
if (Plugin.instance.VisitedMoons.Count >= StartOfRound.Instance.levels.Length - 2 - ((Plugin.instance.GaletryID != -99) ? 1 : 0) - Plugin.config.MoonsBlacklist.Count)
{
Plugin.instance.VisitedMoons.Clear();
Plugin.instance.VisitedMoons.Add(selectableLevel.PlanetName);
return true;
}
return false;
}
public static bool IsMoonBlacklisted(SelectableLevel selectableLevel)
{
if (Plugin.config.MoonsBlacklist.Count == 0)
{
return false;
}
string moonName = Regex.Replace(selectableLevel.PlanetName, "^[0-9]+", string.Empty);
if (moonName[0] == ' ')
{
string text = moonName;
moonName = text.Substring(1, text.Length - 1);
}
return Plugin.config.MoonsBlacklist.Exists((string i) => i == moonName);
}
public static bool IsMoonValidFromConstellation(SelectableLevel selectableLevel)
{
return ClassMapper.IsLevelInConstellation(selectableLevel, "");
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}