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.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using EntityStates;
using Microsoft.CodeAnalysis;
using MonoMod.RuntimeDetour;
using On.RoR2;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;
[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("BossDPS")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BossDPS")]
[assembly: AssemblyTitle("BossDPS")]
[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 BossDPS
{
[BepInPlugin("Rude.BossDPS", "BossDPS", "1.0.0")]
public class BossDPSPlugin : BaseUnityPlugin
{
public const string PluginGUID = "Rude.BossDPS";
public const string PluginAuthor = "Rude";
public const string PluginName = "BossDPS";
public const string PluginVersion = "1.0.0";
private static Hook overrideHook;
private TeleportEventInfo teleporterInfo = new TeleportEventInfo();
public void Start()
{
}
public void Awake()
{
Log.Init(((BaseUnityPlugin)this).Logger);
Log.Info("BossDPS new patch :)");
HookMethod();
HookEvents();
}
private void HookEvents()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
ChargingState.OnEnter += (hook_OnEnter)delegate(orig_OnEnter orig, BaseState self)
{
orig.Invoke(self);
teleporterInfo = new TeleportEventInfo();
teleporterInfo.start();
};
ChargingState.OnExit += (hook_OnExit)delegate(orig_OnExit orig, BaseState self)
{
orig.Invoke(self);
teleporterInfo.end();
HandleTeleportDone();
};
}
private void HookMethod()
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
MethodInfo method = typeof(GlobalEventManager).GetMethod("ClientDamageNotified", BindingFlags.Static | BindingFlags.Public);
MethodInfo method2 = typeof(BossDPSPlugin).GetMethod("TrackDamage", BindingFlags.Instance | BindingFlags.NonPublic);
overrideHook = new Hook((MethodBase)method, method2, (object)this);
}
private bool isPlayer(CharacterBody body)
{
return body.isPlayerControlled = true;
}
private bool isMinion(CharacterBody body)
{
return Object.op_Implicit((Object)(object)body.master.minionOwnership) && Object.op_Implicit((Object)(object)body.master.minionOwnership.ownerMaster) && body.master.minionOwnership.ownerMaster.GetBody().isPlayerControlled;
}
private string getMaster(CharacterBody body)
{
return body.master.minionOwnership.ownerMaster.GetBody().GetUserName();
}
private string getPlayer(CharacterBody body)
{
if (isMinion(body))
{
return getMaster(body);
}
return body.GetUserName();
}
private void TrackDamage(Action<DamageDealtMessage> orig, DamageDealtMessage damageDealtMessage)
{
orig(damageDealtMessage);
if (!teleporterInfo.started)
{
return;
}
try
{
CharacterBody component = damageDealtMessage.attacker.GetComponent<CharacterBody>();
if (component.isPlayerControlled || isMinion(component))
{
string player = getPlayer(component);
ulong damage = (ulong)damageDealtMessage.damage;
teleporterInfo.addDamage(player, damage);
}
}
catch (Exception)
{
}
}
private string FormatNumber(ulong num)
{
if (num >= 100000000)
{
return ((double)num / 1000000.0).ToString("0.#M");
}
if (num >= 1000000)
{
return ((double)num / 1000000.0).ToString("0.##M");
}
if (num >= 100000)
{
return ((double)num / 1000.0).ToString("0.#k");
}
if (num >= 10000)
{
return ((double)num / 1000.0).ToString("0.#k");
}
return num.ToString("#,0");
}
private void SendChatMessage(string message)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
SimpleChatMessage val = new SimpleChatMessage();
val.baseToken = "{0}";
val.paramTokens = new string[1] { message };
Chat.SendBroadcastChat((ChatMessageBase)(object)val);
}
public void Update()
{
}
private void HandleTeleportDone()
{
if (NetworkServer.active)
{
ulong totalDamage = teleporterInfo.damageDone.Aggregate(0uL, (ulong sum, KeyValuePair<string, ulong> entry) => sum + entry.Value);
IEnumerable<string> values = from entry in teleporterInfo.damageDone
orderby entry.Value descending
select $"\t<color=#e5eefc>{entry.Key}:</color> {FormatNumber(entry.Value)} ({Math.Round((decimal)entry.Value / (decimal)totalDamage * 100m, 1)}%)";
SendChatMessage("<style=cEvent><style=cDeath>Teleporter <sprite name=\"TP\" tint=1></style> event finished in </style>" + teleporterInfo.elapsed().Minutes.ToString().PadLeft(2, '0') + ":" + teleporterInfo.elapsed().Seconds.ToString().PadLeft(2, '0') + "\n<style=cIsUtility>Damage done:</style>\n" + string.Join("\n", values));
}
}
}
internal class TeleportEventInfo
{
private DateTime startTime;
private DateTime endTime;
public bool started { get; private set; } = false;
public Dictionary<string, ulong> damageDone { get; } = new Dictionary<string, ulong>();
public void addDamage(string player, ulong damage)
{
if (damageDone.ContainsKey(player))
{
damageDone[player] += damage;
}
else
{
damageDone.Add(player, damage);
}
}
public void start()
{
started = true;
startTime = DateTime.Now;
}
public void end()
{
started = false;
endTime = DateTime.Now;
}
public TimeSpan elapsed()
{
_ = endTime;
if (false)
{
end();
}
return endTime - startTime;
}
}
internal static class Log
{
private static ManualLogSource _logSource;
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
internal static void Debug(object data)
{
_logSource.LogDebug(data);
}
internal static void Error(object data)
{
_logSource.LogError(data);
}
internal static void Fatal(object data)
{
_logSource.LogFatal(data);
}
internal static void Info(object data)
{
_logSource.LogInfo(data);
}
internal static void Message(object data)
{
_logSource.LogMessage(data);
}
internal static void Warning(object data)
{
_logSource.LogWarning(data);
}
}
}