using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GlassCannon.Patches;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GlassCannon")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("GlassCannon")]
[assembly: AssemblyTitle("GlassCannon")]
[assembly: AssemblyVersion("1.0.1.0")]
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 GlassCannon
{
[BepInPlugin("soundedsquash.glasscannon", "Glass Cannon", "1.0.0.0")]
public class GlassCannonBase : BaseUnityPlugin
{
private const string PluginGuid = "soundedsquash.glasscannon";
private const string PluginName = "Glass Cannon";
private const string PluginVersion = "1.0.0.0";
private readonly Harmony _harmony = new Harmony("soundedsquash.glasscannon");
private static readonly ManualLogSource ManualLogSource = Logger.CreateLogSource("soundedsquash.glasscannon");
public void Awake()
{
Settings.Initialize(((BaseUnityPlugin)this).Config, ManualLogSource);
((Component)this).gameObject.AddComponent<ValuableObjectManager>();
if (!(Settings.DollarMultiplier.Value > 0f))
{
ManualLogSource.LogError((object)$"Invalid Dollar Multiplier value {Settings.DollarMultiplier.Value}. Resetting to {Settings.DollarMultiplierDefault}");
Settings.DollarMultiplier.Value = Settings.DollarMultiplierDefault;
}
if (Settings.ItemImpactBehavior.Value < 0 || Settings.ItemImpactBehavior.Value > 2)
{
ManualLogSource.LogError((object)$"Invalid Item Impact Behavior value: {Settings.ItemImpactBehavior.Value}. Resetting to {Settings.ItemImpactBehaviorDefault}");
Settings.ItemImpactBehavior.Value = Settings.ItemImpactBehaviorDefault;
}
_harmony.PatchAll();
ManualLogSource.LogInfo((object)"Glass Cannon loaded");
}
}
public static class Settings
{
public static float DollarMultiplierDefault = 2f;
public static int ItemImpactBehaviorDefault = 1;
public static ConfigEntry<float> DollarMultiplier { get; private set; }
public static ConfigEntry<int> ItemImpactBehavior { get; private set; }
public static ManualLogSource Logger { get; private set; }
internal static void Initialize(ConfigFile config, ManualLogSource logger)
{
Logger = logger;
DollarMultiplier = config.Bind<float>("General", "DollarMultiplier", 2f, "The multiplier that is applied to item value. 2 doubles the value. 1 is the same. Any number between 0 and 1 will lose value.");
ItemImpactBehavior = config.Bind<int>("General", "ItemImpactBehavior", 1, "0 - Default impacts. 1 - Break on impact. 2 - No impact damage.");
}
}
}
namespace GlassCannon.Patches
{
[HarmonyPatch(typeof(PhysGrabObjectImpactDetector))]
public static class PhysGrabObjectImpactDetectorPatches
{
[HarmonyPatch("Break")]
[HarmonyPrefix]
private static void BreakPrefix(ref float valueLost, Vector3 _contactPoint, int breakLevel)
{
valueLost = Settings.ItemImpactBehavior.Value switch
{
1 => float.MaxValue,
2 => 0f,
_ => valueLost,
};
Settings.Logger.LogDebug((object)$"Break detected. {valueLost} value lost. [{Settings.ItemImpactBehavior.Value}]");
}
}
[HarmonyPatch(typeof(RoundDirector))]
public static class RoundDirectorPatches
{
[HarmonyPatch("StartRoundLogic")]
[HarmonyPostfix]
public static void StartRoundLogicPostfix()
{
Settings.Logger.LogDebug((object)"StartRoundLogicPostfix Started");
if ((Object)(object)ValuableObjectManager.Instance != (Object)null)
{
ValuableObjectManager.Instance.MultiplyValuableObjectsValue();
}
Settings.Logger.LogDebug((object)"StartRoundLogicPostfix Ended");
}
}
[HarmonyPatch(typeof(ValuableObject))]
public static class ValuableObjectPatches
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPostfix(ValuableObject __instance)
{
if ((Object)(object)ValuableObjectManager.Instance != (Object)null)
{
ValuableObjectManager.Instance.AddValuableObject(__instance);
Settings.Logger.LogDebug((object)("ValuableObject " + ((Object)__instance).name + " added"));
}
}
}
public class ValuableObjectManager : MonoBehaviour
{
private float DollarMultiplier = Settings.DollarMultiplier.Value;
private List<ValuableObject> allValuableObjects = new List<ValuableObject>();
public static ValuableObjectManager Instance { get; private set; }
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
}
}
public void AddValuableObject(ValuableObject obj)
{
if (!allValuableObjects.Contains(obj))
{
allValuableObjects.Add(obj);
}
}
public void RemoveValuableObject(ValuableObject obj)
{
allValuableObjects.Remove(obj);
}
private List<ValuableObject> GetAllValuableObjects()
{
return new List<ValuableObject>(allValuableObjects);
}
private void RemoveAllValuableObjects()
{
allValuableObjects.Clear();
Settings.Logger.LogDebug((object)"allValuableObjects cleared");
}
public void MultiplyValuableObjectsValue()
{
Settings.Logger.LogDebug((object)"MultiplyValuableObjectsValue Started");
List<ValuableObject> list = GetAllValuableObjects();
Settings.Logger.LogDebug((object)$"MultiplyValuableObjectsValue {list.Count} items");
foreach (ValuableObject item in list)
{
float num = item.dollarValueOriginal * DollarMultiplier;
Settings.Logger.LogDebug((object)$"Changed {((Object)item).name} value from {item.dollarValueOriginal} to {num}");
item.dollarValueOriginal = num;
item.dollarValueCurrent = num;
}
RemoveAllValuableObjects();
Settings.Logger.LogDebug((object)"MultiplyValuableObjectsValue Ended");
}
}
}