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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[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("HitsujiSauce.FreeMoonReSelect")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FreeMoonReSelect")]
[assembly: AssemblyTitle("HitsujiSauce.FreeMoonReSelect")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.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;
}
}
[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 SprayColorFixed.Patches
{
[HarmonyPatch(typeof(TVScript))]
public class ExampleTVPatch
{
[HarmonyPatch("SwitchTVLocalClient")]
[HarmonyPrefix]
private static void SwitchTVPrefix(TVScript __instance)
{
StartOfRound.Instance.shipRoomLights.SetShipLightsBoolean(__instance.tvOn);
}
}
}
namespace FreeMoonReSelect
{
[BepInPlugin("HitsujiSauce.FreeMoonReSelect", "FreeMoonReSelect", "1.0.0")]
public class FreeRouteReSelect : BaseUnityPlugin
{
public enum RerouteRestrictMode
{
AllowAll,
HostOnly,
NoAccess
}
[HarmonyPatch(typeof(Terminal), "TextPostProcess")]
private class TextPostProcessPatch
{
[HarmonyPrefix]
private static void Prefix(Terminal __instance, TerminalNode node)
{
if (!((Object)(object)node == (Object)null) && ((Object)node).name != null && ((Object)node).name.EndsWith("route"))
{
int displayPlanetInfo = node.displayPlanetInfo;
if (displayPlanetInfo != -1 && FreeMoonToday.ContainsLevelID(displayPlanetInfo))
{
node.itemCost = 0;
__instance.totalCostOfItems = 0;
}
}
}
[HarmonyPostfix]
private static void Postfix(ref string __result, TerminalNode node)
{
if (!((Object)(object)node == (Object)null) && ((Object)node).name != null && ((Object)node).name.EndsWith("route"))
{
int displayPlanetInfo = node.displayPlanetInfo;
if (displayPlanetInfo != -1 && FreeMoonToday.ContainsLevelID(displayPlanetInfo))
{
__result += "\n\nThis route is free today!\n\n\n";
}
}
}
}
[HarmonyPatch(typeof(StartOfRound), "ChangeLevel")]
public class RecordSelectedMoon
{
private static void Postfix(StartOfRound __instance, int levelID)
{
string planetName = __instance.levels[levelID].PlanetName;
FreeMoonToday.Add(levelID, planetName);
Logger.LogInfo((object)$"[MoonFree] {levelID} {planetName}.");
}
}
[HarmonyPatch(typeof(Terminal), "OnSubmit")]
public class PatchMoonPurchaseFreeOnSubmit
{
private static void Prefix(Terminal __instance)
{
TerminalNode val = __instance.ParsePlayerSentence();
if (!((Object)(object)val == (Object)null) && val.buyRerouteToMoon >= 0)
{
int levelID = FreeMoonToday.GetLevelID(((Object)val).name);
if (FreeMoonToday.ContainsLevelID(levelID))
{
val.itemCost = 0;
}
}
}
}
[HarmonyPatch(typeof(Terminal), "LoadNewNodeIfAffordable")]
public class PatchMoonPurchaseFree
{
private static void Prefix(Terminal __instance, TerminalNode node)
{
if (node.buyRerouteToMoon >= 0 && FreeMoonToday.ContainsLevelID(node.buyRerouteToMoon))
{
node.itemCost = 0;
}
if (NetworkManager.Singleton.IsHost)
{
lastHostRerouteTime = Time.time;
}
}
}
[HarmonyPatch(typeof(TimeOfDay), "OnDayChanged")]
public class ResetFreeMoonEachDay
{
private static void Postfix()
{
FreeMoonToday.Clear();
StartOfRound instance = StartOfRound.Instance;
if ((Object)(object)instance?.currentLevel != (Object)null)
{
int levelID = instance.currentLevel.levelID;
string name = ((Object)instance.currentLevel).name;
FreeMoonToday.Add(levelID, name);
}
}
}
[HarmonyPatch(typeof(StartMatchLever), "StartGame")]
public class ResetFreeMoonOnStartFromCompany
{
private static void Prefix()
{
StartOfRound instance = StartOfRound.Instance;
if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.currentLevel == (Object)null) && instance.currentLevel.levelID == 3)
{
FreeMoonToday.Clear();
FreeMoonToday.Add(instance.currentLevel.levelID, ((Object)instance.currentLevel).name);
Logger.LogInfo((object)"[MoonFree] Reset due to departure from Company.");
}
}
}
[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
public class ClearFreeMoonOnShutdown
{
private static void Postfix()
{
FreeMoonToday.Clear();
restrictRerouteMode = RerouteRestrictMode.AllowAll;
}
}
[HarmonyPatch(typeof(HUDManager), "Update")]
public class ToggleRestrictModePatch
{
private static void Postfix()
{
if (NetworkManager.Singleton.IsHost && ((ButtonControl)Keyboard.current[(Key)102]).wasPressedThisFrame)
{
FreeRouteReSelect.restrictRerouteMode = (RerouteRestrictMode)((int)(FreeRouteReSelect.restrictRerouteMode + 1) % 3);
RerouteRestrictMode restrictRerouteMode = FreeRouteReSelect.restrictRerouteMode;
if (1 == 0)
{
}
string text = restrictRerouteMode switch
{
RerouteRestrictMode.AllowAll => "Mode: AllowAll.",
RerouteRestrictMode.HostOnly => "Mode: SelectHostOnly.",
RerouteRestrictMode.NoAccess => "Mode: TerminalNoAccess.",
_ => "Unknown mode",
};
if (1 == 0)
{
}
string text2 = text;
Logger.LogInfo((object)$"[MoonFree] Reroute mode changed: {FreeRouteReSelect.restrictRerouteMode}");
HUDManager.Instance.DisplayTip("Reroute Restriction", text2, false, false, "LC_Tip1");
}
}
}
[HarmonyPatch(typeof(StartOfRound), "ChangeLevelServerRpc")]
public class ValidateRerouteOrigin
{
private static bool Prefix(StartOfRound __instance, ref int levelID, ref int newGroupCreditsAmount)
{
if (!NetworkManager.Singleton.IsHost)
{
return true;
}
float time = Time.time;
float num = time - lastHostRerouteTime;
if (restrictRerouteMode != 0 && num > 0.5f)
{
int currentLevelID = __instance.currentLevelID;
levelID = currentLevelID;
Terminal val = Object.FindObjectOfType<Terminal>();
if ((Object)(object)val != (Object)null)
{
newGroupCreditsAmount = val.groupCredits;
}
__instance.CancelChangeLevelClientRpc(newGroupCreditsAmount);
Logger.LogWarning((object)"[MoonFree] ❌ Reroute denied.");
return false;
}
return true;
}
}
[HarmonyPatch(typeof(StartMatchLever), "StartGame")]
public class StartMatchLeverTime
{
private static void Prefix(StartMatchLever __instance)
{
lastHostStartGameTime = Time.time;
}
}
[HarmonyPatch(typeof(StartOfRound), "StartGameServerRpc")]
public class StartGameClientDeny
{
private static bool Prefix(StartOfRound __instance)
{
if (!NetworkManager.Singleton.IsHost)
{
return true;
}
float time = Time.time;
float num = time - lastHostStartGameTime;
if (restrictRerouteMode != 0 && num > 1f)
{
Terminal val = Object.FindObjectOfType<Terminal>();
int groupCredits = val.groupCredits;
StartMatchLever val2 = Object.FindObjectOfType<StartMatchLever>();
val2.CancelStartGame();
__instance.ChangeLevelClientRpc(__instance.currentLevelID, groupCredits);
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Terminal), "SetTerminalInUseLocalClient")]
public class TerminalInteractIsHost
{
private static bool Prefix(Terminal __instance)
{
lastHostTerminalInteractTime = Time.time;
return true;
}
}
[HarmonyPatch(typeof(Terminal), "SetTerminalInUseServerRpc")]
public class KickFromTerminalImmediately
{
private static bool Prefix(Terminal __instance)
{
if (!NetworkManager.Singleton.IsHost)
{
return true;
}
float time = Time.time;
float num = time - lastHostTerminalInteractTime;
StartOfRound val = Object.FindObjectOfType<StartOfRound>();
if ((Object)(object)val != (Object)null && !val.inShipPhase && val.currentLevelID != 3)
{
return true;
}
if (restrictRerouteMode == RerouteRestrictMode.NoAccess && num > 1f)
{
__instance.KickOffTerminalClientRpc();
return false;
}
return true;
}
}
public static LevelNameMap FreeMoonToday = new LevelNameMap();
public ConfigEntry<string> toggleKeyBind;
public static Key toggleKey = (Key)0;
public static RerouteRestrictMode restrictRerouteMode = RerouteRestrictMode.AllowAll;
public static float lastHostRerouteTime = -999f;
public static float lastHostTerminalInteractTime = -999f;
public static float lastHostStartGameTime = -999f;
public static FreeRouteReSelect Instance { get; private set; } = null;
internal static ManualLogSource Logger { get; private set; } = null;
internal static Harmony? Harmony { get; set; }
private void Awake()
{
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
toggleKeyBind = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ToggleLockKey", "F9", "キーでホスト専用ルート制限をオン/オフします");
if (!Enum.TryParse<Key>(toggleKeyBind.Value, ignoreCase: true, out toggleKey))
{
Logger.LogWarning((object)("Invalid key '" + toggleKeyBind.Value + "', defaulting to F9."));
toggleKey = (Key)102;
}
Patch();
Logger.LogInfo((object)"HitsujiSauce.FreeMoonReSelect v1.0.0 has loaded!");
}
internal static void Patch()
{
//IL_000d: 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_0018: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("HitsujiSauce.FreeMoonReSelect");
}
Harmony.PatchAll();
}
internal static void Unpatch()
{
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
public class LevelNameMap
{
private List<(int LevelID, string Name)> _items;
public LevelNameMap()
{
_items = new List<(int, string)>();
}
public void Add(int levelID, string name)
{
if (!string.IsNullOrEmpty(name))
{
_items.Add((levelID, name));
}
}
public void Clear()
{
_items.Clear();
}
public int GetLevelID(string name)
{
string name2 = name;
if (string.IsNullOrEmpty(name2))
{
return -1;
}
(int, string) tuple = _items.FirstOrDefault<(int, string)>(((int LevelID, string Name) x) => x.Name == name2);
int result;
if (tuple.Item1 != 0)
{
(result, _) = tuple;
}
else
{
result = -1;
}
return result;
}
public bool ContainsLevelID(int levelID)
{
return _items.Any<(int, string)>(((int LevelID, string Name) x) => x.LevelID == levelID);
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "HitsujiSauce.FreeMoonReSelect";
public const string PLUGIN_NAME = "FreeMoonReSelect";
public const string PLUGIN_VERSION = "1.0.0";
}
}