using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 FranchisePointsOnSpend
{
[BepInPlugin("com.earlj.supermarkettogether.franchisepointsonspend", "Franchise Points On Spend", "1.0.2")]
public sealed class FranchisePointsOnSpendPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(GameData), "UserCode_CmdAcquireFranchise__Int32")]
private static class FranchiseTierPatch
{
private static void Prefix(GameData __instance, out int __state)
{
__state = __instance.gameFranchisePoints;
}
private static void Postfix(GameData __instance, int __state)
{
CreditSuccessfulSpend(__instance, __state, 1);
}
}
[HarmonyPatch(typeof(UpgradesManager), "UserCode_CmdAcquirePerk__Int32__Int32")]
private static class PerkPatch
{
private static void Prefix(out int __state)
{
GameData instance = GameData.Instance;
__state = (((Object)(object)instance != (Object)null) ? instance.gameFranchisePoints : 0);
}
private static void Postfix(int pointsToReduce, int __state)
{
CreditSuccessfulSpend(GameData.Instance, __state, pointsToReduce);
}
}
private Harmony harmony;
private void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
harmony = new Harmony("com.earlj.supermarkettogether.franchisepointsonspend");
harmony.PatchAll(typeof(FranchisePointsOnSpendPlugin).Assembly);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Buying franchise tiers and perks now adds their point cost.");
}
private void OnDestroy()
{
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private static void CreditSuccessfulSpend(GameData game, int pointsBefore, int cost)
{
if (NetworkServer.active && !((Object)(object)game == (Object)null) && cost > 0 && game.gameFranchisePoints < pointsBefore)
{
long val = (long)pointsBefore + (long)cost;
game.NetworkgameFranchisePoints = (int)Math.Min(val, 2147483647L);
}
}
}
}