using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LC_Television_Unlock")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LC_Television_Unlock")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b00f815c-a448-4733-a904-558ef48cc2cc")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LC_Television_Unlock;
internal class TelevisionConfigManager
{
public static TelevisionConfigManager Instance { get; private set; }
public static ConfigEntry<bool> Television { get; private set; }
public static void Init(ConfigFile config)
{
Instance = new TelevisionConfigManager(config);
}
private TelevisionConfigManager(ConfigFile config)
{
Television = config.Bind<bool>("Decorations", "Television", true, "Unlock the television on new save.\nSet to false if you want to disable this mod.");
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class NewSaveStartPatch
{
[HarmonyPatch("firstDayAnimation")]
[HarmonyPostfix]
internal static void LoadTelevisionFromConfig()
{
if (StartOfRound.Instance.gameStats.daysSpent == 0 && !StartOfRound.Instance.isChallengeFile)
{
LCTelevisionUnlockBase.logger.LogInfo((object)"New save detected, loading TV from config.");
if (!GameNetworkManager.Instance.isHostingGame)
{
return;
}
List<UnlockableItem> unlockables = StartOfRound.Instance.unlockablesList.unlockables;
{
foreach (UnlockableItem item in unlockables)
{
string unlockableName = item.unlockableName;
int unlockableID = unlockables.IndexOf(item);
if (CheckConfig(unlockableID, unlockableName))
{
break;
}
}
return;
}
}
LCTelevisionUnlockBase.logger.LogInfo((object)"Not a new save, not loading TV from config.");
}
private static bool CheckConfig(int unlockableID, string unlockableName)
{
if (unlockableName.Equals("Television"))
{
if (TelevisionConfigManager.Television.Value)
{
LCTelevisionUnlockBase.logger.LogInfo((object)$"Found Television with unlockableName {unlockableName} and ID {unlockableID}. Unlocking.");
UnlockShipItem(StartOfRound.Instance, unlockableID, unlockableName);
}
return true;
}
return false;
}
private static void UnlockShipItem(StartOfRound instance, int unlockableID, string name)
{
try
{
LCTelevisionUnlockBase.logger.LogInfo((object)("Attempting to unlock " + name));
MethodInfo method = ((object)instance).GetType().GetMethod("UnlockShipObject", BindingFlags.Instance | BindingFlags.NonPublic);
method.Invoke(instance, new object[1] { unlockableID });
LCTelevisionUnlockBase.logger.LogInfo((object)("Spawning " + name));
}
catch (NullReferenceException arg)
{
LCTelevisionUnlockBase.logger.LogError((object)$"Could not invoke UnlockShipObject method: {arg}");
}
}
}
[BepInPlugin("Robopirate.LCTelevisionUnlock", "LCTelevisionUnlock", "1.0.0")]
public class LCTelevisionUnlockBase : BaseUnityPlugin
{
private const string modGUID = "Robopirate.LCTelevisionUnlock";
private const string modName = "LCTelevisionUnlock";
private const string modVersion = "1.0.0";
private readonly Harmony harmony = new Harmony("Robopirate.LCTelevisionUnlock");
private static LCTelevisionUnlockBase Instance;
internal static ManualLogSource logger;
public static ConfigEntry<bool> Television { get; private set; }
private void Awake()
{
logger = ((BaseUnityPlugin)this).Logger;
logger.LogInfo((object)"[LCTelevisionUnlock] has awoken :)");
TelevisionConfigManager.Init(((BaseUnityPlugin)this).Config);
harmony.PatchAll(typeof(LCTelevisionUnlockBase));
harmony.PatchAll(typeof(NewSaveStartPatch));
logger.LogInfo((object)"Plugin Robopirate.LCTelevisionUnlock is loaded!");
}
}