Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of FightingLeaderboard v1.0.0
fightMonsters.dll
Decompiled 9 months agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using GameNetcodeStuff; using HarmonyLib; using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("fightMonsters")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("fightMonsters")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("60fcee24-6c50-43cd-93b0-590b50f924ad")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace fightMonsters; [BepInPlugin("lengjing.fightMonsters", "fightMonsters", "1.0.0")] public class fightMonsters : BaseUnityPlugin { private struct PlayerStats { public string Username; public int Hits; public int Score; public float Total; public bool IsDead; } [HarmonyPatch(typeof(RoundManager))] [HarmonyPatch("DespawnPropsAtEndOfRound")] public static class StopRankingUpdates { [HarmonyPrefix] private static void Prefix() { fightMonsters fightMonsters2 = Object.FindObjectOfType<fightMonsters>(); if ((Object)(object)fightMonsters2 != (Object)null && fightMonsters2.rankingCoroutine != null) { ((MonoBehaviour)fightMonsters2).StopCoroutine(fightMonsters2.rankingCoroutine); fightMonsters2.rankingCoroutine = null; } } } [HarmonyPatch(typeof(StartOfRound))] [HarmonyPatch("gameOverAnimation")] public static class GameOverAnimation_Patch { [HarmonyPostfix] private static void Postfix(StartOfRound __instance, bool leavingOnMidnight) { if (!((NetworkBehaviour)__instance).IsServer || !ConfigMvpEnabled.Value) { return; } try { var list = (from p in Object.FindObjectsOfType<PlayerControllerB>() where (Object)(object)p != (Object)null select new { Username = p.playerUsername, Score = PlayerScoreTracker.GetScoreFast(p.playerClientId), Hits = PlayerHitTracker.GetHitsFast(p.playerClientId), Total = (float)(PlayerScoreTracker.GetScoreFast(p.playerClientId) * ConfigScoreWeightX.Value + PlayerHitTracker.GetHitsFast(p.playerClientId) * ConfigScoreWeightY.Value) / 10f } into p orderby p.Total descending select p).ToList(); if (list.Count > 0 && list[0].Score >= 0) { var anon = list[0]; string text = "<color=#FF00FF>[MVP] <color=#00FF00>" + anon.Username + "</color></color> - " + $"<color=#FFFF00>总得分: <color=#FFA500>{anon.Total:F1}</color></color> " + $"<color=#FFFF00>(得分: <color=#FFA500>{anon.Score}</color>, 有效伤害: <color=#FFA500>{anon.Hits}</color>)</color>"; HUDManager.Instance.AddTextToChatOnServer(text, -1); } } catch { } } } private float lastSendTime; private bool isCoroutineRunning; public static ConfigEntry<bool> ConfigEnabled; public static ConfigEntry<bool> ConfigMvpEnabled; public static ConfigEntry<float> ConfigInterval; public static ConfigEntry<int> ConfigTopCount; public static ConfigEntry<int> ConfigSandSpiderScore; public static ConfigEntry<int> ConfigCaveDwellerScore; public static ConfigEntry<int> ConfigCrawlerScore; public static ConfigEntry<int> ConfigMaskedPlayerScore; public static ConfigEntry<int> ConfigFlowermanScore; public static ConfigEntry<int> ConfigHoarderBugScore; public static ConfigEntry<int> ConfigNutcrackerScore; public static ConfigEntry<int> ConfigButlerScore; public static ConfigEntry<int> ConfigForestGiantScore; public static ConfigEntry<int> ConfigMouthDogScore; public static ConfigEntry<int> ConfigBaboonBirdScore; public static ConfigEntry<int> ConfigCentipedeScore; public static ConfigEntry<int> ConfigScoreWeightX; public static ConfigEntry<int> ConfigScoreWeightY; public Coroutine rankingCoroutine; private const float UPDATE_INTERVAL = 60f; private Harmony _harmony; private bool isBHeld; private Rect windowRect = new Rect(10f, 10f, 350f, 10f); private List<PlayerControllerB> cachedPlayers = new List<PlayerControllerB>(); private bool needRefresh = true; private float lastUpdateTime; private GUIStyle cachedTitleStyle; private GUIStyle cachedColumnHeaderStyle; private GUIStyle cachedHighlightStyle; private GUIStyle cachedNormalStyle; private static readonly StringBuilder _cachedSb; private List<(string, int, int, float)> _cachedRanking = new List<(string, int, int, float)>(); private const int BASE_WINDOW_HEIGHT = 120; private WaitForSecondsRealtime _cachedWait; private static readonly List<PlayerControllerB> _tempPlayers; private (string, int, int, float)[] _cachedRankingArray = Array.Empty<(string, int, int, float)>(); private float _lastRankingUpdateTime; private const float MIN_RANKING_UPDATE_INTERVAL = 0.5f; private bool _windowSizeDirty = true; private float _cachedWindowHeight; private void Awake() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Expected O, but got Unknown //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Expected O, but got Unknown //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Expected O, but got Unknown //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Expected O, but got Unknown //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Expected O, but got Unknown //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Expected O, but got Unknown //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Expected O, but got Unknown //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Expected O, but got Unknown //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Expected O, but got Unknown //IL_02bf: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Expected O, but got Unknown //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02fb: Expected O, but got Unknown //IL_0323: Unknown result type (might be due to invalid IL or missing references) //IL_032d: Expected O, but got Unknown //IL_0355: Unknown result type (might be due to invalid IL or missing references) //IL_035f: Expected O, but got Unknown //IL_0387: Unknown result type (might be due to invalid IL or missing references) //IL_0391: Expected O, but got Unknown _harmony = new Harmony("lengjing.fightMonsters"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"脚本已加载!"); ConfigEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "是否启用自动排名播报"); ConfigMvpEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "MvpEnabled", true, "是否启用MVP播报"); ConfigInterval = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Interval", 10f, new ConfigDescription("播报间隔(秒)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 300f), Array.Empty<object>())); ConfigTopCount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "TopCount", 3, new ConfigDescription("显示前几名", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>())); ConfigScoreWeightX = ((BaseUnityPlugin)this).Config.Bind<int>("ScoreFormula", "X_Value", 7, new ConfigDescription("得分权重X(需满足X+Y=10)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); ConfigScoreWeightY = ((BaseUnityPlugin)this).Config.Bind<int>("ScoreFormula", "Y_Value", 3, new ConfigDescription("有效伤害权重Y(需满足X+Y=10)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); ConfigSandSpiderScore = ((BaseUnityPlugin)this).Config.Bind<int>("MonsterScores", "SandSpiderScore", 2, new ConfigDescription("蜘蛛击杀得分", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); ConfigCaveDwellerScore = ((BaseUnityPlugin)this).Config.Bind<int>("MonsterScores", "CaveDwellerScore", 3, new ConfigDescription("食人魔击杀得分", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); ConfigCrawlerScore = ((BaseUnityPlugin)this).Config.Bind<int>("MonsterScores", "CrawlerScore", 2, new ConfigDescription("半身鱼击杀得分", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); ConfigMaskedPlayerScore = ((BaseUnityPlugin)this).Config.Bind<int>("MonsterScores", "MaskedPlayerScore", 1, new ConfigDescription("假人击杀得分", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); ConfigFlowermanScore = ((BaseUnityPlugin)this).Config.Bind<int>("MonsterScores", "FlowermanScore", 3, new ConfigDescription("小黑击杀得分", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); ConfigHoarderBugScore = ((BaseUnityPlugin)this).Config.Bind<int>("MonsterScores", "HoarderBugScore", 1, new ConfigDescription("囤积虫击杀得分", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); ConfigNutcrackerScore = ((BaseUnityPlugin)this).Config.Bind<int>("MonsterScores", "NutcrackerScore", 2, new ConfigDescription("夹子击杀得分", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); ConfigButlerScore = ((BaseUnityPlugin)this).Config.Bind<int>("MonsterScores", "ButlerScore", 2, new ConfigDescription("管家击杀得分", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); ConfigForestGiantScore = ((BaseUnityPlugin)this).Config.Bind<int>("MonsterScores", "ForestGiantScore", 5, new ConfigDescription("巨人击杀得分", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); ConfigMouthDogScore = ((BaseUnityPlugin)this).Config.Bind<int>("MonsterScores", "MouthDogScore", 3, new ConfigDescription("无眼狗击杀得分", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); ConfigBaboonBirdScore = ((BaseUnityPlugin)this).Config.Bind<int>("MonsterScores", "CaveBaboonBirdScore", 1, new ConfigDescription("狒狒鹰击杀得分", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); ConfigCentipedeScore = ((BaseUnityPlugin)this).Config.Bind<int>("MonsterScores", "CaveCentipedeScore", 1, new ConfigDescription("抱脸虫击杀得分", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); ((BaseUnityPlugin)this).Config.SettingChanged += OnConfigChanged; ((BaseUnityPlugin)this).Config.SettingChanged += ValidateWeights; UpdateWaitInterval(); } private static void ValidateWeights(object sender, SettingChangedEventArgs e) { if (!(e.ChangedSetting.Definition.Section != "ScoreFormula") && ConfigScoreWeightX.Value + ConfigScoreWeightY.Value != 10) { ConfigScoreWeightX.Value = 10 - ConfigScoreWeightY.Value; } } private void OnConfigChanged(object sender, SettingChangedEventArgs e) { if (e.ChangedSetting.Definition.Key == "Interval") { UpdateWaitInterval(); } } private void UpdateWaitInterval() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown _cachedWait = new WaitForSecondsRealtime(ConfigInterval.Value); } private void Start() { if (!isCoroutineRunning && ConfigEnabled.Value) { ((MonoBehaviour)this).StartCoroutine(AutoSendRankingUpdate()); isCoroutineRunning = true; } } private void OnDestroy() { if (rankingCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(rankingCoroutine); isCoroutineRunning = false; } } private void Update() { isBHeld = ((ButtonControl)Keyboard.current.bKey).isPressed; if (Time.realtimeSinceStartup - lastUpdateTime > 0.3f) { UpdatePlayerCache(); lastUpdateTime = Time.realtimeSinceStartup; needRefresh = true; } } private void UpdatePlayerCache() { _tempPlayers.Clear(); PlayerControllerB[] array = Object.FindObjectsOfType<PlayerControllerB>(); foreach (PlayerControllerB val in array) { if ((Object)(object)val != (Object)null) { _tempPlayers.Add(val); } } cachedPlayers = new List<PlayerControllerB>(_tempPlayers); } private void OnGUI() { //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) if (isBHeld && (((NetworkBehaviour)RoundManager.Instance).IsServer || ((NetworkBehaviour)RoundManager.Instance).IsHost)) { if (_windowSizeDirty || needRefresh) { CalculateWindowSize(); _windowSizeDirty = false; needRefresh = false; } GUI.color = new Color(0.15f, 0.15f, 0.15f, 0.97f); windowRect = GUI.Window(0, windowRect, new WindowFunction(DrawStatsWindow), ""); if (cachedTitleStyle == null) { InitStyles(); } GUI.Label(new Rect(((Rect)(ref windowRect)).x, ((Rect)(ref windowRect)).y + 4f, ((Rect)(ref windowRect)).width, 28f), "实时战斗统计 - 按住B显示", cachedTitleStyle); } } private void CalculateWindowSize() { int num = Mathf.Clamp(cachedPlayers.Count, 3, 15); _cachedWindowHeight = 28 + num * 28 + 10; ((Rect)(ref windowRect)).width = 500f; ((Rect)(ref windowRect)).height = Mathf.Clamp(_cachedWindowHeight, 120f, (float)Screen.height * 0.75f); ((Rect)(ref windowRect)).x = Mathf.Clamp(((Rect)(ref windowRect)).x, 10f, (float)Screen.width - ((Rect)(ref windowRect)).width - 10f); ((Rect)(ref windowRect)).y = Mathf.Clamp(((Rect)(ref windowRect)).y, 10f, (float)Screen.height - ((Rect)(ref windowRect)).height - 10f); } private void InitStyles() { //IL_000b: 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_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Expected O, but got Unknown //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Expected O, but got Unknown GUIStyle val = new GUIStyle(GUI.skin.label) { alignment = (TextAnchor)4, fontSize = 16, fontStyle = (FontStyle)1 }; val.normal.textColor = Color.green; cachedTitleStyle = val; GUIStyle val2 = new GUIStyle(GUI.skin.label) { fontSize = 14, alignment = (TextAnchor)4 }; val2.normal.textColor = Color.green; cachedColumnHeaderStyle = val2; GUIStyle val3 = new GUIStyle(GUI.skin.label) { fontSize = 15, fontStyle = (FontStyle)1, alignment = (TextAnchor)4 }; val3.normal.textColor = new Color(1f, 0.9f, 0.4f); cachedHighlightStyle = val3; GUIStyle val4 = new GUIStyle(GUI.skin.label) { fontSize = 14, alignment = (TextAnchor)4 }; val4.normal.textColor = new Color(0.8f, 0.8f, 0.8f); cachedNormalStyle = val4; } public IEnumerator AutoSendRankingUpdate() { while (true) { yield return _cachedWait; if (ShouldSendUpdate()) { string text = BuildOptimizedRankingMessage(); if (!string.IsNullOrEmpty(text)) { HUDManager.Instance.AddTextToChatOnServer(text, -1); lastSendTime = Time.realtimeSinceStartup; } } } } private bool ShouldSendUpdate() { if ((Object)(object)StartOfRound.Instance != (Object)null && !StartOfRound.Instance.inShipPhase && (Object)(object)HUDManager.Instance != (Object)null && ConfigEnabled.Value && ((NetworkBehaviour)RoundManager.Instance).IsHost) { return Time.realtimeSinceStartup - lastSendTime >= ConfigInterval.Value; } return false; } private string BuildOptimizedRankingMessage() { try { if (Time.realtimeSinceStartup - _lastRankingUpdateTime < 0.5f) { return null; } _lastRankingUpdateTime = Time.realtimeSinceStartup; Array.Resize(ref _cachedRankingArray, cachedPlayers.Count); for (int i = 0; i < cachedPlayers.Count; i++) { PlayerControllerB val = cachedPlayers[i]; int scoreFast = PlayerScoreTracker.GetScoreFast(val.playerClientId); int hitsFast = PlayerHitTracker.GetHitsFast(val.playerClientId); float item = (float)(scoreFast * ConfigScoreWeightX.Value + hitsFast * ConfigScoreWeightY.Value) / 10f; _cachedRankingArray[i] = (val.playerUsername, scoreFast, hitsFast, item); } Array.Sort(_cachedRankingArray, ((string, int, int, float) a, (string, int, int, float) b) => b.Item4.CompareTo(a.Item4)); StringBuilder cachedSb = _cachedSb; cachedSb.Clear(); int num = Math.Min(ConfigTopCount.Value, _cachedRankingArray.Length); for (int j = 0; j < num; j++) { (string, int, int, float) tuple = _cachedRankingArray[j]; cachedSb.Append($"\n{j + 1}. <color=#00FF00>{tuple.Item1}</color> - ").Append($"<color=#FFFF00>总得分</color>: <color=#FFA500>{tuple.Item4}</color>"); } cachedPlayers.Count((PlayerControllerB p) => p.isPlayerDead); cachedSb.Append($"\n<color=#AAAAAA>({ConfigInterval.Value}秒)</color></color>"); return cachedSb.ToString(); } catch (Exception) { return null; } } private void DrawStatsWindow(int windowID) { //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_0293: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_02e0: Unknown result type (might be due to invalid IL or missing references) //IL_0308: Unknown result type (might be due to invalid IL or missing references) //IL_0330: Unknown result type (might be due to invalid IL or missing references) if (cachedColumnHeaderStyle == null) { InitStyles(); } int count = cachedPlayers.Count; List<PlayerStats> list = new List<PlayerStats>(count); for (int i = 0; i < count; i++) { PlayerControllerB val = cachedPlayers[i]; list.Add(new PlayerStats { Username = val.playerUsername, Hits = PlayerHitTracker.GetHitsFast(val.playerClientId), Score = PlayerScoreTracker.GetScoreFast(val.playerClientId), Total = (float)(PlayerScoreTracker.GetScoreFast(val.playerClientId) * ConfigScoreWeightX.Value + PlayerHitTracker.GetHitsFast(val.playerClientId) * ConfigScoreWeightY.Value) / 10f, IsDead = val.isPlayerDead }); } list.Sort((PlayerStats a, PlayerStats b) => b.Total.CompareTo(a.Total)); GUILayout.BeginArea(new Rect(12f, 28f, ((Rect)(ref windowRect)).width - 24f, ((Rect)(ref windowRect)).height - 40f)); GUI.Label(new Rect(0f, 0f, 50f, 28f), "名次", cachedColumnHeaderStyle); GUI.Label(new Rect(50f, 0f, 140f, 28f), "玩家名称", cachedColumnHeaderStyle); GUI.Label(new Rect(190f, 0f, 80f, 28f), "有效伤害", cachedColumnHeaderStyle); GUI.Label(new Rect(270f, 0f, 80f, 28f), "得分", cachedColumnHeaderStyle); GUI.Label(new Rect(350f, 0f, 80f, 28f), "总分", cachedColumnHeaderStyle); float num = 28f; for (int j = 0; j < list.Count; j++) { PlayerStats playerStats = list[j]; bool isDead = playerStats.IsDead; bool flag = j == 0 || (j > 0 && playerStats.Total == list[j - 1].Total); GUIStyle val2 = (isDead ? cachedNormalStyle : (flag ? cachedHighlightStyle : cachedNormalStyle)); string text = playerStats.Username + (isDead ? " ☠" : ""); GUI.Label(new Rect(0f, num, 50f, 28f), $"#{j + 1}", val2); GUI.Label(new Rect(50f, num, 140f, 28f), text, val2); GUI.Label(new Rect(190f, num, 80f, 28f), playerStats.Hits.ToString(), val2); GUI.Label(new Rect(270f, num, 80f, 28f), playerStats.Score.ToString(), val2); GUI.Label(new Rect(350f, num, 80f, 28f), playerStats.Total.ToString(), val2); num += 28f; } GUILayout.EndArea(); GUI.DragWindow(); } static fightMonsters() { _cachedSb = new StringBuilder(512); _tempPlayers = new List<PlayerControllerB>(4); } } public static class PlayerHitTracker { private static readonly Dictionary<ulong, int> _playerHits = new Dictionary<ulong, int>(); private static readonly object _lock = new object(); public static void Increment(ulong playerId, Type enemyType) { lock (_lock) { _playerHits[playerId] = ((!_playerHits.TryGetValue(playerId, out var value)) ? 1 : (value + 1)); } } public static int GetHits(ulong playerId) { lock (_lock) { int value; return _playerHits.TryGetValue(playerId, out value) ? value : 0; } } public static void Reset() { lock (_lock) { _playerHits.Clear(); } } public static int GetHitsFast(ulong playerId) { int value; return _playerHits.TryGetValue(playerId, out value) ? value : 0; } } public static class PlayerScoreTracker { private static readonly Dictionary<ulong, int> _playerScores = new Dictionary<ulong, int>(); private static readonly object _lock = new object(); public static void AddScore(ulong playerId, int score) { lock (_lock) { _playerScores[playerId] = (_playerScores.TryGetValue(playerId, out var value) ? (value + score) : score); } } public static int GetScore(ulong playerId) { lock (_lock) { int value; return _playerScores.TryGetValue(playerId, out value) ? value : 0; } } public static void Reset() { lock (_lock) { _playerScores.Clear(); } } public static int GetScoreFast(ulong playerId) { int value; return _playerScores.TryGetValue(playerId, out value) ? value : 0; } } [HarmonyPatch(typeof(SandSpiderAI))] public static class SandSpiderAI_Patch { private static int ScoreValue => fightMonsters.ConfigSandSpiderScore.Value; [HarmonyPrefix] [HarmonyPatch("HitEnemy")] private static void HitEnemyPrefix(SandSpiderAI __instance, int force, PlayerControllerB playerWhoHit, ref bool ___isEnemyDead, ref int ___enemyHP) { try { if (playerWhoHit.isPlayerControlled && !playerWhoHit.isPlayerDead && ___enemyHP > 0) { PlayerHitTracker.Increment(playerWhoHit?.playerClientId ?? 0, ((object)__instance).GetType()); if (___enemyHP <= force && ___enemyHP > 0) { PlayerScoreTracker.AddScore(playerWhoHit?.playerClientId ?? 0, ScoreValue); } if (___isEnemyDead && ___enemyHP > 0) { ___enemyHP = 0; } } } catch (Exception) { } } } [HarmonyPatch(typeof(CaveDwellerAI))] public static class CaveDwellerAI_Patch { private static int ScoreValue => fightMonsters.ConfigCaveDwellerScore.Value; [HarmonyPrefix] [HarmonyPatch("HitEnemy")] private static void HitEnemyPrefix(CaveDwellerAI __instance, int force, PlayerControllerB playerWhoHit, ref bool ___isEnemyDead, ref int ___enemyHP) { try { if (playerWhoHit.isPlayerControlled && !playerWhoHit.isPlayerDead && ___enemyHP > 0) { PlayerHitTracker.Increment(playerWhoHit?.playerClientId ?? 0, ((object)__instance).GetType()); if (___enemyHP <= force && ___enemyHP > 0) { PlayerScoreTracker.AddScore(playerWhoHit?.playerClientId ?? 0, ScoreValue); } if (___isEnemyDead && ___enemyHP > 0) { ___enemyHP = 0; } } } catch (Exception) { } } } [HarmonyPatch(typeof(CrawlerAI))] public static class CrawlerAI_Patch { private static int ScoreValue => fightMonsters.ConfigCrawlerScore.Value; [HarmonyPrefix] [HarmonyPatch("HitEnemy")] private static void HitEnemyPrefix(CrawlerAI __instance, int force, PlayerControllerB playerWhoHit, ref bool ___isEnemyDead, ref int ___enemyHP) { try { if (playerWhoHit.isPlayerControlled && !playerWhoHit.isPlayerDead && ___enemyHP > 0) { PlayerHitTracker.Increment(playerWhoHit?.playerClientId ?? 0, ((object)__instance).GetType()); if (___enemyHP <= force && ___enemyHP > 0) { PlayerScoreTracker.AddScore(playerWhoHit?.playerClientId ?? 0, ScoreValue); } if (___isEnemyDead && ___enemyHP > 0) { ___enemyHP = 0; } } } catch (Exception) { } } } [HarmonyPatch(typeof(MaskedPlayerEnemy))] public static class MaskedPlayerEnemy_Patch { private static int ScoreValue => fightMonsters.ConfigMaskedPlayerScore.Value; [HarmonyPrefix] [HarmonyPatch("HitEnemy")] private static void HitEnemyPrefix(MaskedPlayerEnemy __instance, int force, PlayerControllerB playerWhoHit, ref bool ___isEnemyDead, ref int ___enemyHP) { try { if (playerWhoHit.isPlayerControlled && !playerWhoHit.isPlayerDead && ___enemyHP > 0) { PlayerHitTracker.Increment(playerWhoHit?.playerClientId ?? 0, ((object)__instance).GetType()); if (___enemyHP <= force && ___enemyHP > 0) { PlayerScoreTracker.AddScore(playerWhoHit?.playerClientId ?? 0, ScoreValue); } if (___isEnemyDead && ___enemyHP > 0) { ___enemyHP = 0; } } } catch (Exception) { } } } [HarmonyPatch(typeof(FlowermanAI))] public static class FlowermanAI_Patch { private static int ScoreValue => fightMonsters.ConfigFlowermanScore.Value; [HarmonyPrefix] [HarmonyPatch("HitEnemy")] private static void HitEnemyPrefix(FlowermanAI __instance, int force, PlayerControllerB playerWhoHit, ref bool ___isEnemyDead, ref int ___enemyHP) { try { if (playerWhoHit.isPlayerControlled && !playerWhoHit.isPlayerDead && ___enemyHP > 0) { PlayerHitTracker.Increment(playerWhoHit?.playerClientId ?? 0, ((object)__instance).GetType()); if (___enemyHP <= force && ___enemyHP > 0) { PlayerScoreTracker.AddScore(playerWhoHit?.playerClientId ?? 0, ScoreValue); } if (___isEnemyDead && ___enemyHP > 0) { ___enemyHP = 0; } } } catch (Exception) { } } } [HarmonyPatch(typeof(HoarderBugAI))] public static class HoarderBugAI_Patch { private static int ScoreValue => fightMonsters.ConfigHoarderBugScore.Value; [HarmonyPrefix] [HarmonyPatch("HitEnemy")] private static void HitEnemyPrefix(HoarderBugAI __instance, int force, PlayerControllerB playerWhoHit, ref bool ___isEnemyDead, ref int ___enemyHP) { try { if (playerWhoHit.isPlayerControlled && !playerWhoHit.isPlayerDead && ___enemyHP > 0) { PlayerHitTracker.Increment(playerWhoHit?.playerClientId ?? 0, ((object)__instance).GetType()); if (___enemyHP <= force && ___enemyHP > 0) { PlayerScoreTracker.AddScore(playerWhoHit?.playerClientId ?? 0, ScoreValue); } if (___isEnemyDead && ___enemyHP > 0) { ___enemyHP = 0; } } } catch (Exception) { } } } [HarmonyPatch(typeof(NutcrackerEnemyAI))] public static class NutcrackerEnemyAI_Patch { private static int ScoreValue => fightMonsters.ConfigNutcrackerScore.Value; [HarmonyPrefix] [HarmonyPatch("HitEnemy")] private static void HitEnemyPrefix(NutcrackerEnemyAI __instance, int force, PlayerControllerB playerWhoHit, ref bool ___isEnemyDead, ref int ___enemyHP) { try { if (playerWhoHit.isPlayerControlled && !playerWhoHit.isPlayerDead && ___enemyHP > 0) { PlayerHitTracker.Increment(playerWhoHit?.playerClientId ?? 0, ((object)__instance).GetType()); if (___enemyHP <= force && ___enemyHP > 0) { PlayerScoreTracker.AddScore(playerWhoHit?.playerClientId ?? 0, ScoreValue); } if (___isEnemyDead && ___enemyHP > 0) { ___enemyHP = 0; } } } catch (Exception) { } } } [HarmonyPatch(typeof(ButlerEnemyAI))] public static class ButlerEnemyAI_Patch { private static int ScoreValue => fightMonsters.ConfigButlerScore.Value; [HarmonyPrefix] [HarmonyPatch("HitEnemy")] private static void HitEnemyPrefix(ButlerEnemyAI __instance, int force, PlayerControllerB playerWhoHit, ref bool ___isEnemyDead, ref int ___enemyHP) { try { if (playerWhoHit.isPlayerControlled && !playerWhoHit.isPlayerDead && ___enemyHP > 0) { PlayerHitTracker.Increment(playerWhoHit?.playerClientId ?? 0, ((object)__instance).GetType()); if (___enemyHP <= force && ___enemyHP > 0) { PlayerScoreTracker.AddScore(playerWhoHit?.playerClientId ?? 0, ScoreValue); } if (___isEnemyDead && ___enemyHP > 0) { ___enemyHP = 0; } } } catch (Exception) { } } } [HarmonyPatch(typeof(ForestGiantAI))] public static class ForestGiantAI_Patch { private static int ScoreValue => fightMonsters.ConfigForestGiantScore.Value; [HarmonyPrefix] [HarmonyPatch("HitEnemy")] private static void HitEnemyPrefix(ForestGiantAI __instance, int force, PlayerControllerB playerWhoHit, ref bool ___isEnemyDead, ref int ___enemyHP) { try { if (playerWhoHit.isPlayerControlled && !playerWhoHit.isPlayerDead && ___enemyHP > 0) { PlayerHitTracker.Increment(playerWhoHit?.playerClientId ?? 0, ((object)__instance).GetType()); if (___enemyHP <= force && ___enemyHP > 0) { PlayerScoreTracker.AddScore(playerWhoHit?.playerClientId ?? 0, ScoreValue); } if (___isEnemyDead && ___enemyHP > 0) { ___enemyHP = 0; } } } catch (Exception) { } } } [HarmonyPatch(typeof(MouthDogAI))] public static class MouthDogAI_Patch { private static int ScoreValue => fightMonsters.ConfigMouthDogScore.Value; [HarmonyPrefix] [HarmonyPatch("HitEnemy")] private static void HitEnemyPrefix(MouthDogAI __instance, int force, PlayerControllerB playerWhoHit, ref bool ___isEnemyDead, ref int ___enemyHP) { try { if (playerWhoHit.isPlayerControlled && !playerWhoHit.isPlayerDead && ___enemyHP > 0) { PlayerHitTracker.Increment(playerWhoHit?.playerClientId ?? 0, ((object)__instance).GetType()); if (___enemyHP <= force && ___enemyHP > 0) { PlayerScoreTracker.AddScore(playerWhoHit?.playerClientId ?? 0, ScoreValue); } if (___isEnemyDead && ___enemyHP > 0) { ___enemyHP = 0; } } } catch (Exception) { } } } [HarmonyPatch(typeof(BaboonBirdAI))] public static class BaboonBirdAI_Patch { private static int ScoreValue => fightMonsters.ConfigBaboonBirdScore.Value; [HarmonyPrefix] [HarmonyPatch("HitEnemy")] private static void HitEnemyPrefix(BaboonBirdAI __instance, int force, PlayerControllerB playerWhoHit, ref bool ___isEnemyDead, ref int ___enemyHP) { try { if (playerWhoHit.isPlayerControlled && !playerWhoHit.isPlayerDead && ___enemyHP > 0) { PlayerHitTracker.Increment(playerWhoHit?.playerClientId ?? 0, ((object)__instance).GetType()); if (___enemyHP <= force && ___enemyHP > 0) { PlayerScoreTracker.AddScore(playerWhoHit?.playerClientId ?? 0, ScoreValue); } if (___isEnemyDead && ___enemyHP > 0) { ___enemyHP = 0; } } } catch (Exception) { } } } [HarmonyPatch(typeof(CentipedeAI))] public static class CentipedeAI_Patch { private static int ScoreValue => fightMonsters.ConfigCentipedeScore.Value; [HarmonyPrefix] [HarmonyPatch("HitEnemy")] private static void HitEnemyPrefix(CentipedeAI __instance, int force, PlayerControllerB playerWhoHit, ref bool ___isEnemyDead, ref int ___enemyHP) { try { if (playerWhoHit.isPlayerControlled && !playerWhoHit.isPlayerDead && ___enemyHP > 0) { PlayerHitTracker.Increment(playerWhoHit?.playerClientId ?? 0, ((object)__instance).GetType()); if (___enemyHP <= force && ___enemyHP > 0) { PlayerScoreTracker.AddScore(playerWhoHit?.playerClientId ?? 0, ScoreValue); } if (___isEnemyDead && ___enemyHP > 0) { ___enemyHP = 0; } } } catch (Exception) { } } } [HarmonyPatch(typeof(StartOfRound))] [HarmonyPatch("StartGame")] public static class StartOfRound_ResetStats { [HarmonyPrefix] private static void PrefixStartGame(StartOfRound __instance) { try { if (!((NetworkBehaviour)StartOfRound.Instance).IsServer) { return; } PlayerHitTracker.Reset(); PlayerScoreTracker.Reset(); fightMonsters fightMonsters2 = Object.FindObjectOfType<fightMonsters>(); if ((Object)(object)fightMonsters2 != (Object)null && fightMonsters.ConfigEnabled.Value) { if (fightMonsters2.rankingCoroutine != null) { ((MonoBehaviour)fightMonsters2).StopCoroutine(fightMonsters2.rankingCoroutine); } fightMonsters2.rankingCoroutine = ((MonoBehaviour)fightMonsters2).StartCoroutine(fightMonsters2.AutoSendRankingUpdate()); } } catch (Exception) { } } }