using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("Streaks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+56914ad98367f3593801de29a688e8474c2f59bd")]
[assembly: AssemblyProduct("Streaks")]
[assembly: AssemblyTitle("Streaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 Streaks
{
[BepInPlugin("lofen.streaks", "Streaks", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger;
internal static ConfigEntry<int> MinStreakThresh;
internal static ConfigEntry<int> MaxStreakThresh;
internal static ConfigEntry<int> MaxWinThresh;
private void Awake()
{
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin Streaks is loaded!");
MinStreakThresh = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Minimum streak threshold", 3, "Only show streaks at least this long.");
MaxStreakThresh = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Maximum streak threshold", 100, "Only show streaks less than this long.");
MaxWinThresh = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Maximum win threshold", 100, "Only show streaks when player has less than this amount of wins.");
Harmony val = new Harmony("lofen.streaks");
val.PatchAll(typeof(Patch));
}
}
[HarmonyPatch]
public class Patch
{
public static Dictionary<int, int> WinStreaks = new Dictionary<int, int>();
public static Dictionary<int, int> LoseStreaks = new Dictionary<int, int>();
[HarmonyPatch(typeof(Player), "WinAGame")]
[HarmonyPostfix]
public static void WinAGame(ref Player __instance)
{
LoseStreaks.Remove(__instance.Id);
if (WinStreaks.ContainsKey(__instance.Id))
{
WinStreaks[__instance.Id] = WinStreaks[__instance.Id] + 1;
}
else
{
WinStreaks.Add(__instance.Id, 1);
}
}
[HarmonyPatch(typeof(Player), "Kill")]
[HarmonyPostfix]
public static void Kill(ref Player __instance)
{
if (!__instance.stillAliveThisRound)
{
WinStreaks.Remove(__instance.Id);
if (LoseStreaks.ContainsKey(__instance.Id))
{
LoseStreaks[__instance.Id] = LoseStreaks[__instance.Id] + 1;
}
else
{
LoseStreaks.Add(__instance.Id, 1);
}
}
}
[HarmonyPatch(typeof(AbilitySelectController), "Init")]
[HarmonyPostfix]
public static void LoserPostInit(ref TextMeshProUGUI ___ScoreText)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
LoseStreaks.Clear();
((TMP_Text)___ScoreText).outlineWidth = 0.25f;
((TMP_Text)___ScoreText).outlineColor = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue);
}
[HarmonyPatch(typeof(AbilitySelectController), "Update")]
[HarmonyPrefix]
public static bool LoserPreUpdate(ref TextMeshProUGUI ___ScoreText, ref Player ___player)
{
if (((TMP_Text)___ScoreText).text != $"{___player.GamesWon}")
{
((TMP_Text)___ScoreText).text = $"{___player.GamesWon}";
}
return true;
}
[HarmonyPatch(typeof(AbilitySelectController), "Update")]
[HarmonyPostfix]
public static void LoserPostUpdate(ref TextMeshProUGUI ___ScoreText, ref Player ___player)
{
string text = $"{___player.GamesWon}";
if (GetStreak(___player, LoseStreaks, out var streak))
{
text += $"<color=red><sup>{streak}</sup></color>";
}
if (((TMP_Text)___ScoreText).text != text)
{
((TMP_Text)___ScoreText).text = text;
}
}
[HarmonyPatch(typeof(AbilitySelectWinner), "Init")]
[HarmonyPostfix]
public static void WinnerPostInit(ref TextMeshProUGUI ___ScoreText)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
WinStreaks.Clear();
((TMP_Text)___ScoreText).outlineWidth = 0.25f;
((TMP_Text)___ScoreText).outlineColor = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue);
}
[HarmonyPatch(typeof(AbilitySelectWinner), "Update")]
[HarmonyPrefix]
public static bool WinnerPreUpdate(ref TextMeshProUGUI ___ScoreText, ref Player ___player)
{
string text = $"{___player.GamesWon}";
if (GetStreak(___player, WinStreaks, out var streak))
{
text += $"<color=green><sup>{streak}</sup></color>";
}
if (((TMP_Text)___ScoreText).text != text)
{
((TMP_Text)___ScoreText).text = text;
}
return false;
}
public static bool GetStreak(Player p, Dictionary<int, int> streaks, out int streak)
{
streak = 0;
if (streaks.ContainsKey(p.Id))
{
streak = streaks[p.Id];
}
return p.GamesWon < Plugin.MaxWinThresh.Value && Plugin.MinStreakThresh.Value <= streak && streak < Plugin.MaxStreakThresh.Value;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "Streaks";
public const string PLUGIN_NAME = "Streaks";
public const string PLUGIN_VERSION = "1.0.1";
}
}