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.Text;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[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("BuffsTimer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+2bdf5cf136b27f013d8104546387b1fa3378b1fe")]
[assembly: AssemblyProduct("Buffs Timer")]
[assembly: AssemblyTitle("BuffsTimer")]
[assembly: AssemblyVersion("1.0.3.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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]
[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]
[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 BuffsTimer
{
public class BuffsMonitorComponent : MonoBehaviour
{
private Text _targetText;
public void Setup(Text targetText)
{
_targetText = targetText;
}
private void FixedUpdate()
{
StringBuilder stringBuilder = new StringBuilder();
if (Plugin.Buffs.Count > 0)
{
foreach (ItemBuff buff in Plugin.Buffs)
{
if (buff.IsBuffEnded())
{
continue;
}
Dictionary<string, float> buffsAmount = buff.GetBuffsAmount();
Dictionary<string, float> buffsMaxAmount = buff.GetBuffsMaxAmount();
stringBuilder.AppendLine(buff.ToString());
foreach (KeyValuePair<string, float> item in buffsAmount.Where((KeyValuePair<string, float> buffAmount) => Math.Round(buffAmount.Value, 2) != 0.0))
{
stringBuilder.AppendLine($"\t<color=\"lightblue\">{item.Key} {item.Value:F2} ({buffsMaxAmount[item.Key]:F2})</color>");
}
}
}
_targetText.text = stringBuilder.ToString();
}
}
[HarmonyPatch(typeof(HandItem))]
public class HandItemP
{
[HarmonyPostfix]
[HarmonyPatch("Start")]
public static void Postfix(HandItem __instance)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
__instance.itemUseEvent.AddListener(new UnityAction(Action));
void Action()
{
string prefabName = __instance.item.prefabName;
Plugin.Logger.LogInfo((object)prefabName);
if (!Plugin.Buffs.Any((ItemBuff b) => (b.ItemPrefabName.Equals("Item_Milk") && prefabName.Equals("Item_Cocoa_Full")) || (b.ItemPrefabName.Equals("Item_Cocoa_Full") && prefabName.Equals("Item_Milk"))))
{
HandItem val = __instance;
HandItem val2 = val;
HandItem_Buff val3 = (HandItem_Buff)(object)((val2 is HandItem_Buff) ? val2 : null);
BuffContainer buff;
if (val3 == null)
{
HandItem_Food val4 = (HandItem_Food)(object)((val2 is HandItem_Food) ? val2 : null);
if (val4 == null || !val4.useBuff)
{
return;
}
buff = val4.buff;
}
else
{
buff = val3.buff;
}
if (Plugin.Buffs.Any((ItemBuff b) => b.ItemPrefabName.Equals(prefabName)))
{
Plugin.Buffs.FirstOrDefault((ItemBuff b) => b.ItemPrefabName.Equals(prefabName)).Buffs.Add(buff);
}
else
{
ItemBuff itemBuff = new ItemBuff(prefabName, buff);
Plugin.Logger.LogInfo((object)itemBuff.ToString());
Plugin.Buffs.Add(itemBuff);
}
}
}
}
}
public class ItemBuff
{
public string ItemPrefabName { get; }
public List<BuffContainer> Buffs { get; }
public ItemBuff(string itemName, BuffContainer buff)
{
ItemPrefabName = itemName;
Buffs = new List<BuffContainer>(1) { buff };
}
public override string ToString()
{
float timer = GetTimer();
string arg = ItemPrefabName.Replace('_', ' ').Replace("Item", "").Replace("Denizen", "");
return $"{arg}: {timer:F2}s";
}
public bool IsBuffEnded()
{
if (!((double)GetTimer() <= 0.01))
{
return false;
}
Plugin.Buffs.Remove(this);
return true;
}
private float GetTimer()
{
float buff = ((GameEntity)ENT_Player.playerObject).curBuffs.GetBuff("buffTimeMult");
float num = 1f / Mathf.Max(1f + buff, 0.1f);
return Buffs.Last().buffTime / (Buffs.Last().loseRate * num);
}
public Dictionary<string, float> GetBuffsAmount()
{
Dictionary<string, float> dictionary = new Dictionary<string, float>();
foreach (Buff item in Buffs.SelectMany((BuffContainer buff) => buff.buffs))
{
if (dictionary.ContainsKey(item.id))
{
dictionary[item.id] += item.amount;
}
else
{
dictionary.Add(item.id, item.amount);
}
}
return dictionary;
}
public Dictionary<string, float> GetBuffsMaxAmount()
{
Dictionary<string, float> dictionary = new Dictionary<string, float>();
foreach (Buff item in Buffs.SelectMany((BuffContainer buff) => buff.buffs))
{
if (dictionary.ContainsKey(item.id))
{
dictionary[item.id] += item.maxAmount;
}
else
{
dictionary.Add(item.id, item.maxAmount);
}
}
return dictionary;
}
}
[BepInPlugin("com.crusifixknight.whiteknuckle-buffstimer", "Buffs Timer", "1.0.3")]
public class Plugin : BaseUnityPlugin
{
private Harmony _harmony;
public static readonly List<ItemBuff> Buffs = new List<ItemBuff>();
internal static ManualLogSource Logger { get; private set; } = null;
private void Awake()
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
_harmony = new Harmony("com.crusifixknight.whiteknuckle-buffstimer.harmony");
_harmony.PatchAll();
Logger.LogInfo((object)"Plugin Buffs Timer is loaded!");
((Object)((Component)this).gameObject).hideFlags = (HideFlags)4;
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnDestroy()
{
_harmony.UnpatchSelf();
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
GameObject val = GameObject.Find("GameManager/Canvas/Game UI/GameStateTrackers");
if ((Object)(object)val != (Object)null)
{
Buffs.Clear();
GameObject val2 = new GameObject("BuffTimer");
val2.transform.SetParent(val.transform, false);
Text val3 = val2.AddComponent<Text>();
val3.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
val3.fontSize = 18;
((Graphic)val3).color = Color.white;
((Graphic)val3).raycastTarget = false;
RectTransform component = val2.GetComponent<RectTransform>();
Vector2 val4 = default(Vector2);
((Vector2)(ref val4))..ctor(0f, 1f);
component.pivot = val4;
Vector2 anchorMin = (component.anchorMax = val4);
component.anchorMin = anchorMin;
component.sizeDelta = new Vector2(300f, 700f);
val2.AddComponent<BuffsMonitorComponent>().Setup(val3);
}
}
}
internal static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.crusifixknight.whiteknuckle-buffstimer";
public const string PLUGIN_NAME = "Buffs Timer";
public const string PLUGIN_VERSION = "1.0.3";
}
}