using System;
using System.Diagnostics;
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 Eremite;
using Eremite.Buildings;
using Eremite.Controller;
using Eremite.Model;
using Eremite.Model.Effects;
using HarmonyLib;
using Microsoft.CodeAnalysis;
[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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("GetSharkCat")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Have a Shark Cat accompany you on every new settlement!")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1daa6f98b1b6415a7eeafb47d427e2717af3257a")]
[assembly: AssemblyProduct("GetSharkCat")]
[assembly: AssemblyTitle("GetSharkCat")]
[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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace GetSharkCat
{
public class CatGranter
{
private static GameNpcModel Cat => SO.Settings.GetNpc("Cat");
public static void SafeGrant()
{
SO.NpcsService.RemoveNpc(Cat);
Plugin.myLog.LogInfo((object)"Cat NPC removed.");
GrantCat();
if (Configs.EffectGrantingEnabled && IsSafetyOn())
{
GrantCatEffect();
SO.NpcsService.RemoveNpc(Cat);
Plugin.myLog.LogInfo((object)"Cat NPC removed.");
}
}
public static void UnsafeGrant()
{
GrantCat();
if (Configs.EffectGrantingEnabled)
{
GrantCatEffect();
}
}
private static void GrantCat()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
SO.NpcsService.SpawnNewNpc(Cat, ((Building)SO.BuildingsService.GetMainHearth()).Entrance);
Plugin.myLog.LogInfo((object)"Cat NPC added.");
}
private static void GrantCatEffect()
{
EffectModel effect = MB.Settings.GetEffect("[WE] First Elder Bonus");
effect.Apply((EffectContextType)0, (string)null, 0);
Plugin.myLog.LogInfo((object)"Cat effect cycle perk added.");
}
private static bool IsSafetyOn()
{
return !SO.PerksService.HasPerk("[WE] First Elder Bonus");
}
}
public static class Configs
{
private static ConfigEntry<bool> m_EffectGrantingEnabled = Bind("General", "Add Cat perk effect", defaultValue: false, "When set to true adds the associated reward perk.");
private static ConfigEntry<bool> m_CheckForDuplicates = Bind("General", "Check for duplicate cats and effects", defaultValue: true, "When set to true it checks for presence of other cats or effects being active already.");
private static ConfigEntry<bool> m_AddToOngoingGames = Bind("General", "Add in ongoing games", defaultValue: false, "When set to true executes in ongoing games.");
public static bool EffectGrantingEnabled
{
get
{
return m_EffectGrantingEnabled.Value;
}
set
{
m_EffectGrantingEnabled.Value = value;
((BaseUnityPlugin)Plugin.Instance).Config.Save();
}
}
public static bool CheckForDuplicates
{
get
{
return m_CheckForDuplicates.Value;
}
set
{
m_CheckForDuplicates.Value = value;
((BaseUnityPlugin)Plugin.Instance).Config.Save();
}
}
public static bool AddToOngoingGames
{
get
{
return m_AddToOngoingGames.Value;
}
set
{
m_AddToOngoingGames.Value = value;
((BaseUnityPlugin)Plugin.Instance).Config.Save();
}
}
private static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, string description)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
return ((BaseUnityPlugin)Plugin.Instance).Config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()));
}
}
[BepInPlugin("GetSharkCat", "GetSharkCat", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static Plugin Instance;
private Harmony harmony;
internal static ManualLogSource myLog;
private void Awake()
{
Instance = this;
harmony = Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin GetSharkCat is loaded!");
Configs.EffectGrantingEnabled = Configs.EffectGrantingEnabled;
myLog = ((BaseUnityPlugin)Instance).Logger;
}
[HarmonyPatch(typeof(MainController), "OnServicesReady")]
[HarmonyPostfix]
private static void HookMainControllerSetup()
{
((BaseUnityPlugin)Instance).Logger.LogInfo((object)"Performing game initialization on behalf of GetSharkCat.");
((BaseUnityPlugin)Instance).Logger.LogInfo((object)$"The game has loaded {MainController.Instance.Settings.effects.Length} effects.");
}
[HarmonyPatch(typeof(GameController), "StartGame")]
[HarmonyPostfix]
private static void HookEveryGameStart()
{
bool flag = MB.GameSaveService.IsNewGame();
((BaseUnityPlugin)Instance).Logger.LogInfo((object)$"Entered a game. Is this a new game: {flag}.");
if (flag)
{
if (Configs.CheckForDuplicates)
{
((BaseUnityPlugin)Instance).Logger.LogInfo((object)"Safe and new games config chosen.");
CatGranter.SafeGrant();
}
else
{
((BaseUnityPlugin)Instance).Logger.LogInfo((object)"Unsafe and new games config chosen.");
CatGranter.UnsafeGrant();
}
}
else if (Configs.AddToOngoingGames)
{
if (Configs.CheckForDuplicates)
{
((BaseUnityPlugin)Instance).Logger.LogInfo((object)"Unsafe and new games config chosen.");
CatGranter.SafeGrant();
}
else
{
((BaseUnityPlugin)Instance).Logger.LogInfo((object)"Unsafe and all games config chosen.");
CatGranter.UnsafeGrant();
}
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "GetSharkCat";
public const string PLUGIN_NAME = "GetSharkCat";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}