using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using SideLoader;
using SideLoader.Model;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace KyazhPower;
[BepInPlugin("local.kyazhpower", "Կյաժ Power", "0.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class KyazhPowerPlugin : BaseUnityPlugin
{
public const string Guid = "local.kyazhpower";
public const string StatusId = "KyazhPower_CoopCombat";
private Harmony harmony;
private StatusEffect prefab;
private float nextCheck;
private float nextRefresh;
internal static readonly HashSet<string> Snapshot = new HashSet<string>();
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("local.kyazhpower");
harmony.PatchAll(typeof(KyazhPowerPlugin).Assembly);
SL.OnPacksLoaded += CreateBuff;
SL.OnSceneLoaded += ClearSnapshot;
if (SL.PacksLoaded)
{
CreateBuff();
}
}
private static void ClearSnapshot()
{
Snapshot.Clear();
}
private void CreateBuff()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Expected O, but got Unknown
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
try
{
SL_StatusEffect val = new SL_StatusEffect
{
TargetStatusIdentifier = "Rage",
NewStatusID = -1,
StatusIdentifier = "KyazhPower_CoopCombat",
Name = "Կյաժ Power",
Description = "+5% outgoing damage while at least two living players are in combat.",
Lifespan = 3f,
RefreshRate = 0.2f,
DisplayedInHUD = true,
IsHidden = false,
IsMalusEffect = false,
Purgeable = false,
PlayFXOnActivation = false,
PlaySpecialFXOnStop = false,
AmplifiedStatusIdentifier = "",
ComplicationStatusIdentifier = "",
RequiredStatusIdentifier = "",
Tags = new string[0],
EffectBehaviour = (EditBehaviours)1,
Effects = (SL_EffectTransform[])(object)new SL_EffectTransform[0],
BindFamily = new SL_StatusEffectFamily
{
UID = "KyazhPower_CoopCombat_Family",
Name = "Կյաժ Power",
StackBehaviour = (StackBehaviors)1,
MaxStackCount = 1,
LengthType = (LengthTypes)0
}
};
val.OnTemplateApplied += delegate(StatusEffect status)
{
prefab = status;
LoadIcon(status);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Կյաժ Power status registered.");
};
((ContentTemplate)val).ApplyTemplate();
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Could not register Kyazh Power: " + ex));
}
}
private void LoadIcon(StatusEffect status)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "buff.png");
if (!File.Exists(path))
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"buff.png is missing; using the game's temporary Rage icon.");
return;
}
Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
if (!ImageConversion.LoadImage(val, File.ReadAllBytes(path)))
{
throw new InvalidDataException("buff.png could not be decoded.");
}
((Object)val).name = "KyazhPowerIcon";
((Texture)val).wrapMode = (TextureWrapMode)1;
status.OverrideIcon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
}
internal static List<Character> Players()
{
CharacterManager manager = CharacterManager.Instance;
if (!Object.op_Implicit((Object)(object)manager))
{
return new List<Character>();
}
return (from uid in manager.PlayerCharacters.Values
select manager.GetCharacter(uid) into c
where Object.op_Implicit((Object)(object)c) && c.Initialized && !c.IsAI
select c).Distinct().ToList();
}
internal static bool InCombat(Character c)
{
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)c) || c.IsDead || !((Component)c).gameObject.activeInHierarchy)
{
return false;
}
GlobalCombatManager combatManager = Global.CombatManager;
if ((!Object.op_Implicit((Object)(object)combatManager) || !combatManager.PlayersInCombat.Contains(c)) && !Snapshot.Contains(UID.op_Implicit(c.UID)))
{
if (c.IsLocalPlayer)
{
return c.InCombat;
}
return false;
}
return true;
}
internal static bool Eligible(Character c)
{
if (Object.op_Implicit((Object)(object)c) && InCombat(c))
{
return Players().Count(InCombat) >= 2;
}
return false;
}
private void Update()
{
if (!Object.op_Implicit((Object)(object)prefab) || Time.unscaledTime < nextCheck)
{
return;
}
nextCheck = Time.unscaledTime + 0.25f;
List<Character> list = Players();
bool flag = list.Count(InCombat) >= 2;
bool flag2 = Time.unscaledTime >= nextRefresh;
if (flag2)
{
nextRefresh = Time.unscaledTime + 1f;
}
foreach (Character item in list)
{
if (!item.IsPhotonPlayerLocal || !Object.op_Implicit((Object)(object)item.StatusEffectMngr))
{
continue;
}
bool flag3 = item.StatusEffectMngr.HasStatusEffect("KyazhPower_CoopCombat");
if (flag && InCombat(item))
{
if (!flag3 || flag2)
{
item.StatusEffectMngr.AddStatusEffect("KyazhPower_CoopCombat");
}
}
else if (flag3)
{
item.StatusEffectMngr.RemoveStatusWithIdentifierName("KyazhPower_CoopCombat");
}
}
}
private void OnDestroy()
{
SL.OnPacksLoaded -= CreateBuff;
SL.OnSceneLoaded -= ClearSnapshot;
foreach (Character item in Players())
{
if (item.IsPhotonPlayerLocal && Object.op_Implicit((Object)(object)item.StatusEffectMngr))
{
item.StatusEffectMngr.RemoveStatusWithIdentifierName("KyazhPower_CoopCombat");
}
}
if (harmony != null)
{
harmony.UnpatchSelf();
}
Snapshot.Clear();
}
}
[HarmonyPatch(typeof(CharacterStats), "GetAmplifiedDamage")]
internal static class DamageBonus
{
private static void Postfix(Character ___m_character, ref DamageList _damages)
{
if (_damages == null || !KyazhPowerPlugin.Eligible(___m_character) || !Object.op_Implicit((Object)(object)___m_character.StatusEffectMngr) || !___m_character.StatusEffectMngr.HasStatusEffect("KyazhPower_CoopCombat"))
{
return;
}
foreach (DamageType item in _damages.List)
{
item.Damage *= 1.05f;
}
}
}
[HarmonyPatch(typeof(GlobalCombatManager), "LoadCombatInfos")]
internal static class LateJoinSnapshot
{
private static void Postfix(string _infos)
{
KyazhPowerPlugin.Snapshot.Clear();
if (string.IsNullOrEmpty(_infos))
{
return;
}
string[] array = _infos.Split(new char[1] { ';' });
foreach (string text in array)
{
if (!string.IsNullOrEmpty(text))
{
KyazhPowerPlugin.Snapshot.Add(text);
}
}
}
}
[HarmonyPatch(typeof(GlobalCombatManager), "RemoveCombatCharacter")]
internal static class CombatEnded
{
private static void Postfix(Character _char)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)_char))
{
KyazhPowerPlugin.Snapshot.Remove(UID.op_Implicit(_char.UID));
}
}
}