using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using InControl;
using SFQoL;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("MatchTarget")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+41b71358dc49f857b92d5f2d235899f116cebe8e")]
[assembly: AssemblyProduct("MatchTarget")]
[assembly: AssemblyTitle("MatchTarget")]
[assembly: AssemblyVersion("1.0.3.0")]
namespace SFQoL
{
internal static class Compat
{
private static bool searched;
private static FieldInfo roundsActive;
private static PropertyInfo roundsArmed;
private static FieldInfo cardPicking;
private static bool cardSearched;
public static bool Rounds
{
get
{
Find();
try
{
if ((object)roundsArmed != null && (bool)roundsArmed.GetValue(null, null))
{
return true;
}
if ((object)roundsActive != null && (bool)roundsActive.GetValue(null))
{
return true;
}
}
catch
{
}
return false;
}
}
public static bool CardScreen
{
get
{
if (!cardSearched)
{
Type type = RoundsType("StickRounds.CardPick");
cardSearched = (object)type != null || Time.frameCount > 1;
if ((object)type != null)
{
cardPicking = type.GetField("Picking", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
}
}
try
{
return (object)cardPicking != null && (bool)cardPicking.GetValue(null);
}
catch
{
return false;
}
}
}
public static bool RoundsMatch
{
get
{
Find();
try
{
return (object)roundsActive != null && (bool)roundsActive.GetValue(null) && !GameManager.stillInMenu;
}
catch
{
return false;
}
}
}
private static Type RoundsType(string name)
{
if (!Chainloader.PluginInfos.TryGetValue("stickfight.stickrounds", out var value) || (Object)(object)value.Instance == (Object)null)
{
return null;
}
return ((object)value.Instance).GetType().Assembly.GetType(name, throwOnError: false);
}
private static void Find()
{
if (!searched)
{
Type type = RoundsType("StickRounds.RoundsMode");
searched = (object)type != null || Time.frameCount > 1;
if ((object)type != null)
{
roundsActive = type.GetField("Active", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
roundsArmed = type.GetProperty("Armed", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
}
}
}
public static bool IsBotDevice(InputDevice d)
{
if (d != null)
{
return ((object)d).GetType().Name == "BotDevice";
}
return false;
}
}
internal static class QolConfig
{
public static ConfigEntry<bool> Enabled(ConfigFile config, string section, string description)
{
return config.Bind<bool>(section, "Enabled", true, description);
}
private static Dictionary<ConfigDefinition, string> Orphans(ConfigFile config)
{
return Traverse.Create((object)config).Property("OrphanedEntries", (object[])null).GetValue<Dictionary<ConfigDefinition, string>>();
}
public static string Old(ConfigFile config, string section, string key)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
Dictionary<ConfigDefinition, string> dictionary = Orphans(config);
if (dictionary == null || !dictionary.TryGetValue(new ConfigDefinition(section, key), out var value))
{
return null;
}
return value;
}
public static void SetOld(ConfigFile config, string section, string key, string value)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
Dictionary<ConfigDefinition, string> dictionary = Orphans(config);
if (dictionary != null)
{
dictionary[new ConfigDefinition(section, key)] = value;
}
}
public static void DropOld(ConfigFile config)
{
Dictionary<ConfigDefinition, string> dictionary = Orphans(config);
if (dictionary != null && dictionary.Count != 0)
{
dictionary.Clear();
config.Save();
}
}
public static void DropOld(ConfigFile config, params string[] keep)
{
Dictionary<ConfigDefinition, string> dictionary = Orphans(config);
if (dictionary == null || dictionary.Count == 0)
{
return;
}
List<ConfigDefinition> list = new List<ConfigDefinition>();
foreach (ConfigDefinition key in dictionary.Keys)
{
if (Array.IndexOf(keep, key.Section) < 0)
{
list.Add(key);
}
}
if (list.Count == 0)
{
return;
}
foreach (ConfigDefinition item in list)
{
dictionary.Remove(item);
}
config.Save();
}
}
internal static class Ui
{
public static readonly Color Panel = new Color(0.176f, 0.176f, 0.176f);
public static readonly Color Strip = new Color(0.147f, 0.147f, 0.147f);
public static readonly Color Item = new Color(0.265f, 0.265f, 0.265f);
public static readonly Color Grey = new Color(0.6f, 0.6f, 0.6f);
private static TMP_FontAsset font;
private static Sprite box;
private static bool boxSearched;
private static Camera menuCam;
private static float menuCamSearchAt;
public static TMP_FontAsset Font
{
get
{
if ((Object)(object)font == (Object)null)
{
GameManager instance = GameManager.Instance;
if ((Object)(object)instance != (Object)null && (Object)(object)instance.winText != (Object)null)
{
font = ((TMP_Text)instance.winText).font;
}
if ((Object)(object)font == (Object)null)
{
TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
foreach (TMP_FontAsset val in array)
{
if (((Object)val).name.StartsWith("Anton"))
{
font = val;
break;
}
}
}
}
return font;
}
}
public static Sprite BoxSprite
{
get
{
if ((Object)(object)box == (Object)null && !boxSearched)
{
boxSearched = true;
Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
foreach (Sprite val in array)
{
if (((Object)val).name == "box")
{
box = val;
break;
}
}
}
return box;
}
}
public static int MenuLayer
{
get
{
int num = LayerMask.NameToLayer("MENU");
if (num < 0)
{
return 31;
}
return num;
}
}
public static void Attach(Canvas c)
{
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Invalid comparison between Unknown and I4
if ((Object)(object)c == (Object)null)
{
return;
}
if (((Object)(object)menuCam == (Object)null || !((Behaviour)menuCam).isActiveAndEnabled) && Time.unscaledTime >= menuCamSearchAt)
{
menuCamSearchAt = Time.unscaledTime + 1f;
menuCam = null;
Camera[] allCameras = Camera.allCameras;
foreach (Camera val in allCameras)
{
if (((Object)val).name == "Camera_Pause" && (val.cullingMask & (1 << MenuLayer)) != 0)
{
menuCam = val;
break;
}
}
}
if ((Object)(object)menuCam != (Object)null && ((Behaviour)menuCam).isActiveAndEnabled)
{
if ((int)c.renderMode != 1 || (Object)(object)c.worldCamera != (Object)(object)menuCam)
{
c.renderMode = (RenderMode)1;
c.worldCamera = menuCam;
c.planeDistance = 1f;
}
}
else if ((int)c.renderMode != 0)
{
c.renderMode = (RenderMode)0;
}
}
public static Canvas MakeCanvas(string name, int order)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject(name)
{
layer = MenuLayer
};
Object.DontDestroyOnLoad((Object)val);
Canvas val2 = val.AddComponent<Canvas>();
val2.renderMode = (RenderMode)0;
val2.sortingOrder = order;
Attach(val2);
CanvasScaler obj = val.AddComponent<CanvasScaler>();
obj.uiScaleMode = (ScaleMode)1;
obj.referenceResolution = new Vector2(1920f, 1080f);
obj.matchWidthOrHeight = 0.5f;
return val2;
}
public static RectTransform Rect(Transform parent, string name)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: 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_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Expected O, but got Unknown
GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) })
{
layer = ((Component)parent).gameObject.layer
};
val.transform.SetParent(parent, false);
RectTransform val2 = (RectTransform)val.transform;
Vector2 val3 = default(Vector2);
((Vector2)(ref val3))..ctor(0.5f, 0.5f);
val2.anchorMax = val3;
val2.anchorMin = val3;
val2.pivot = new Vector2(0.5f, 0.5f);
return val2;
}
public static Image Box(Transform parent, string name, Color color, Vector2 pos, Vector2 size, bool rounded = false)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: 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_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
RectTransform obj = Rect(parent, name);
obj.anchoredPosition = pos;
obj.sizeDelta = size;
Image val = ((Component)obj).gameObject.AddComponent<Image>();
((Graphic)val).color = color;
((Graphic)val).raycastTarget = false;
if (rounded && (Object)(object)BoxSprite != (Object)null)
{
val.sprite = BoxSprite;
Vector4 border = BoxSprite.border;
if (((Vector4)(ref border)).sqrMagnitude > 0f)
{
val.type = (Type)1;
}
}
return val;
}
public static void Fill(RectTransform rt, float inset)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
rt.anchorMin = Vector2.zero;
rt.anchorMax = Vector2.one;
rt.offsetMin = new Vector2(inset, inset);
rt.offsetMax = new Vector2(0f - inset, 0f - inset);
}
public static TextMeshProUGUI Text(Transform parent, string name, string text, float size, Color color, TextAlignmentOptions align)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
TextMeshProUGUI val = ((Component)Rect(parent, name)).gameObject.AddComponent<TextMeshProUGUI>();
if ((Object)(object)Font != (Object)null)
{
((TMP_Text)val).font = Font;
}
((TMP_Text)val).fontSize = size;
((Graphic)val).color = color;
((TMP_Text)val).alignment = align;
((TMP_Text)val).enableWordWrapping = false;
((TMP_Text)val).richText = true;
((Graphic)val).raycastTarget = false;
((TMP_Text)val).text = text;
return val;
}
public static Color PlayerColor(Controller c)
{
//IL_00bf: 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_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)c != (Object)null)
{
SpriteRenderer componentInChildren = ((Component)c).GetComponentInChildren<SpriteRenderer>();
SetColorWhenDamaged val = (((Object)(object)componentInChildren != (Object)null) ? ((Component)componentInChildren).GetComponent<SetColorWhenDamaged>() : null);
if ((Object)(object)val == (Object)null)
{
val = ((Component)c).GetComponentInChildren<SetColorWhenDamaged>(true);
}
if ((Object)(object)val != (Object)null && val.startColor.a > 0f)
{
Color startColor = val.startColor;
startColor.a = 1f;
return startColor;
}
ControllerHandler instance = ControllerHandler.Instance;
if ((Object)(object)instance != (Object)null && instance.colors != null && c.playerID >= 0 && c.playerID < instance.colors.Length && (Object)(object)instance.colors[c.playerID] != (Object)null)
{
return instance.colors[c.playerID].color;
}
}
return Color.white;
}
public static Color SlotColor(int id)
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
ControllerHandler instance = ControllerHandler.Instance;
if ((Object)(object)instance != (Object)null && instance.colors != null && id >= 0 && id < instance.colors.Length && (Object)(object)instance.colors[id] != (Object)null)
{
Color color = instance.colors[id].color;
color.a = 1f;
return color;
}
return Color.white;
}
public static string Hex(Color c)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
return "#" + ((int)(Mathf.Clamp01(c.r) * 255f)).ToString("X2") + ((int)(Mathf.Clamp01(c.g) * 255f)).ToString("X2") + ((int)(Mathf.Clamp01(c.b) * 255f)).ToString("X2");
}
public static string Colored(string text, Color c)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
return "<color=" + Hex(c) + ">" + text + "</color>";
}
public static Color WithAlpha(Color c, float a)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
c.a = a;
return c;
}
}
}
namespace MatchTarget
{
[BepInPlugin("stickfight.matchtarget", "First To N", "1.0.3")]
public class Plugin : BaseUnityPlugin
{
public const string Guid = "stickfight.matchtarget";
public const string Name = "First To N";
public const string Version = "1.0.3";
internal static ManualLogSource Log;
internal static ConfigEntry<string> FirstTo;
internal static ConfigEntry<WinDisplay> Display;
private const string Endless = "Endless";
private static readonly string[] Targets = new string[7] { "3", "5", "10", "20", "50", "100", "Endless" };
internal static int WinsNeeded
{
get
{
if (!int.TryParse(FirstTo.Value, out var result))
{
return 0;
}
return result;
}
}
private void Awake()
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Expected O, but got Unknown
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Expected O, but got Unknown
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
string text = QolConfig.Old(((BaseUnityPlugin)this).Config, "Match", "WinsNeeded");
FirstTo = ((BaseUnityPlugin)this).Config.Bind<string>("Match", "FirstTo", "10", new ConfigDescription("Round wins that win the match. Then everyone goes back to the lobby. Endless = the game's endless matches.", (AcceptableValueBase)(object)new AcceptableValueList<string>(Targets), new object[0]));
if (text != null)
{
FirstTo.Value = Nearest(text);
}
string text2 = QolConfig.Old(((BaseUnityPlugin)this).Config, "Match", "ScoreBar");
Display = ((BaseUnityPlugin)this).Config.Bind<WinDisplay>("Match", "WinDisplay", WinDisplay.Bar, "Bar = a score bar at the top. Corners = the game's counters; Off = none. SHOW WINS (GAME OPTIONS) sets it too.");
if (text2 != null && text2.Trim().ToLowerInvariant() == "false")
{
Display.Value = WinDisplay.Corners;
}
QolConfig.DropOld(((BaseUnityPlugin)this).Config);
Display.SettingChanged += delegate
{
ShowWinsRow.Refresh();
};
new Harmony("stickfight.matchtarget").PatchAll(typeof(Plugin).Assembly);
GameObject val = new GameObject("MatchTarget");
Object.DontDestroyOnLoad((Object)val);
((Object)val).hideFlags = (HideFlags)61;
val.AddComponent<Match>();
val.AddComponent<Bar>();
SceneManager.sceneLoaded += delegate(Scene scene, LoadSceneMode mode)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
if ((int)mode == 0)
{
Match.OnLobbyLoaded();
}
};
((BaseUnityPlugin)this).Logger.LogInfo((object)"First To N 1.0.3 loaded.");
}
private static string Nearest(string old)
{
if (!int.TryParse(old.Trim(), out var result))
{
return "10";
}
if (result <= 0)
{
return "Endless";
}
string text = Targets[0];
string[] targets = Targets;
foreach (string text2 in targets)
{
if (int.TryParse(text2, out var result2) && Mathf.Abs(result2 - result) < Mathf.Abs(int.Parse(text) - result))
{
text = text2;
}
}
return text;
}
}
internal enum WinDisplay
{
Bar,
Corners,
Off
}
internal class Match : MonoBehaviour
{
private sealed class Rejoin
{
public int Id;
public bool Keyboard;
public string Type;
public string Name;
public int Sort;
}
private const float BannerTime = 5f;
private static readonly Dictionary<int, int> wins = new Dictionary<int, int>();
private static Match inst;
public static bool Ending;
private static float endAt;
private static readonly List<Rejoin> rejoin = new List<Rejoin>();
private static float rejoinUntil = -1f;
private static readonly MethodInfo createPlayer = AccessTools.Method(typeof(ControllerHandler), "CreatePlayer", (Type[])null, (Type[])null);
private static int freeAt = -1;
private static AsyncOperation freeing;
private static float freeStart;
private static float freeWorst;
private Canvas canvas;
private RectTransform banner;
private CanvasGroup bannerGroup;
private TextMeshProUGUI bannerTitle;
private TextMeshProUGUI bannerSub;
private Image bannerBar;
private float bannerAt = -1f;
private AudioSource au;
public static bool Local
{
get
{
if (!MatchmakingHandler.IsNetworkMatch)
{
return !Compat.Rounds;
}
return false;
}
}
public static bool Active
{
get
{
if (Plugin.WinsNeeded > 0)
{
return Local;
}
return false;
}
}
public static int Target => Plugin.WinsNeeded;
public static int Wins(int id)
{
if (!wins.TryGetValue(id, out var value))
{
return 0;
}
return value;
}
public static bool RoundOver(GameManager gm)
{
if (Ending)
{
return false;
}
if (!Local)
{
return true;
}
if (GameManager.stillInMenu)
{
wins.Clear();
return true;
}
Controller val = null;
foreach (Controller item in gm.playersAlive)
{
if ((Object)(object)item != (Object)null)
{
val = item;
break;
}
}
if ((Object)(object)val == (Object)null)
{
return true;
}
int num = Wins(val.playerID) + 1;
wins[val.playerID] = num;
if (!Active || num < Target)
{
return true;
}
End(gm, val);
return false;
}
private static void End(GameManager gm, Controller winner)
{
Ending = true;
endAt = Time.unscaledTime + 5f;
GameManager.inFight = false;
CharacterStats component = ((Component)winner).GetComponent<CharacterStats>();
if ((Object)(object)component != (Object)null)
{
component.wins++;
}
WinCounterUI val = Object.FindObjectOfType<WinCounterUI>();
if ((Object)(object)val != (Object)null)
{
val.RefreshWinTexts();
}
Plugin.Log.LogInfo((object)("P" + (winner.playerID + 1) + " wins the match."));
if ((Object)(object)inst != (Object)null)
{
inst.ShowBanner(winner, gm);
}
}
public static void OnLobbyLoaded()
{
wins.Clear();
if (Ending)
{
TimeHandler.managerTime = 1f;
}
Ending = false;
if ((Object)(object)inst != (Object)null)
{
inst.HideBanner();
}
if (rejoin.Count > 0)
{
rejoinUntil = Time.unscaledTime + 6f;
}
freeAt = 2;
}
private static void TickFree()
{
if (freeing != null)
{
freeWorst = Mathf.Max(freeWorst, Time.unscaledDeltaTime);
if (!freeing.isDone)
{
return;
}
Plugin.Log.LogDebug((object)("Unused assets freed in " + ((Time.realtimeSinceStartup - freeStart) * 1000f).ToString("0") + " ms (longest frame " + (freeWorst * 1000f).ToString("0") + " ms)."));
freeing = null;
}
if (freeAt >= 0 && --freeAt <= 0)
{
freeAt = -1;
freeStart = Time.realtimeSinceStartup;
freeWorst = 0f;
freeing = Resources.UnloadUnusedAssets();
}
}
private static void BackToLobby()
{
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Invalid comparison between Unknown and I4
rejoin.Clear();
ControllerHandler instance = ControllerHandler.Instance;
if ((Object)(object)instance != (Object)null)
{
foreach (Controller player in instance.players)
{
CharacterActions val = (((Object)(object)player != (Object)null) ? player.PlayerActions : null);
if (val != null && !player.isAI && !Compat.IsBotDevice(((PlayerActionSet)val).Device))
{
if ((int)val.InputType == 1)
{
rejoin.Add(new Rejoin
{
Id = player.playerID,
Keyboard = true
});
}
else if (((PlayerActionSet)val).Device != null)
{
rejoin.Add(new Rejoin
{
Id = player.playerID,
Type = ((object)((PlayerActionSet)val).Device).GetType().Name,
Name = ((PlayerActionSet)val).Device.Name,
Sort = ((PlayerActionSet)val).Device.SortOrder
});
}
}
}
}
rejoin.Sort((Rejoin x, Rejoin y) => x.Id.CompareTo(y.Id));
TimeHandler.managerTime = 1f;
GameManager.Instance.RestartGame();
}
private static bool Uses(ControllerHandler ch, InputDevice d)
{
foreach (Controller player in ch.players)
{
if ((Object)(object)player != (Object)null && player.PlayerActions != null && ((PlayerActionSet)player.PlayerActions).Device == d)
{
return true;
}
}
return false;
}
private static bool HasKeyboard(ControllerHandler ch)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Invalid comparison between Unknown and I4
foreach (Controller player in ch.players)
{
if ((Object)(object)player != (Object)null && player.PlayerActions != null && (int)player.PlayerActions.InputType == 1)
{
return true;
}
}
return false;
}
private static void TickRejoin()
{
if (rejoinUntil < 0f)
{
return;
}
ControllerHandler instance = ControllerHandler.Instance;
if ((Object)(object)instance == (Object)null || (object)createPlayer == null || !InputManager.IsSetup)
{
return;
}
for (int i = 0; i < Match.rejoin.Count; i++)
{
Rejoin rejoin = Match.rejoin[i];
InputDevice val = null;
bool flag = false;
if (rejoin.Keyboard)
{
flag = HasKeyboard(instance);
}
else
{
foreach (InputDevice device in InputManager.Devices)
{
if (device != null && ((object)device).GetType().Name == rejoin.Type && device.Name == rejoin.Name && device.SortOrder == rejoin.Sort)
{
if (Uses(instance, device))
{
flag = true;
}
else
{
val = device;
}
break;
}
}
}
if (flag)
{
Match.rejoin.RemoveAt(i--);
continue;
}
if (!rejoin.Keyboard && val == null)
{
if (Time.unscaledTime < rejoinUntil)
{
return;
}
Match.rejoin.RemoveAt(i--);
continue;
}
if (instance.players.Count < rejoin.Id && Time.unscaledTime < rejoinUntil)
{
return;
}
try
{
createPlayer.Invoke(instance, new object[2]
{
rejoin.Keyboard ? null : val,
rejoin.Keyboard
});
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Couldn't bring P" + (rejoin.Id + 1) + " back: " + ex.Message));
}
Match.rejoin.RemoveAt(i--);
}
rejoinUntil = -1f;
Plugin.Log.LogInfo((object)"Players are back in the lobby.");
}
private void Awake()
{
inst = this;
}
private void LateUpdate()
{
TickRejoin();
TickFree();
if ((Object)(object)canvas == (Object)null)
{
Build();
}
Ui.Attach(canvas);
if (PauseManager.isPaused)
{
if (Ending)
{
endAt += Time.unscaledDeltaTime;
}
if (bannerAt >= 0f)
{
bannerAt += Time.unscaledDeltaTime;
}
}
if (Ending)
{
TimeHandler.managerTime = Mathf.MoveTowards(TimeHandler.managerTime, 0.25f, Time.unscaledDeltaTime * 1.5f);
if (Time.unscaledTime >= endAt)
{
Ending = false;
BackToLobby();
}
}
AnimateBanner();
}
private void ShowBanner(Controller winner, GameManager gm)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: 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_0079: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)canvas == (Object)null)
{
Build();
}
Color color = Ui.PlayerColor(winner);
((TMP_Text)bannerTitle).text = "P" + (winner.playerID + 1) + " WINS THE MATCH";
((Graphic)bannerTitle).color = color;
((TMP_Text)bannerSub).text = "FIRST TO " + Target;
((Graphic)bannerBar).color = color;
bannerAt = Time.unscaledTime;
if (gm.winClips != null && gm.winClips.Length != 0)
{
au.PlayOneShot(gm.winClips[Random.Range(0, gm.winClips.Length)]);
}
}
private void HideBanner()
{
bannerAt = -1f;
if ((Object)(object)bannerGroup != (Object)null)
{
bannerGroup.alpha = 0f;
}
}
private void AnimateBanner()
{
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
if (bannerAt < 0f)
{
bannerGroup.alpha = 0f;
return;
}
float num = Time.unscaledTime - bannerAt;
if (num > 5.5f)
{
bannerAt = -1f;
bannerGroup.alpha = 0f;
return;
}
float num2 = Mathf.Clamp01(num / 0.45f);
float num3 = 1f + Mathf.Sin(num2 * (float)Math.PI) * 0.12f * (1f - num2);
float num4 = Mathf.Lerp(0.6f, 1f, 1f - (1f - num2) * (1f - num2) * (1f - num2)) * num3;
((Transform)banner).localScale = new Vector3(num4, num4, 1f);
bannerGroup.alpha = (PauseManager.isPaused ? 0f : Mathf.Min(Mathf.Clamp01(num / 0.2f), Mathf.Clamp01((5f - num) / 0.4f)));
((Graphic)bannerBar).rectTransform.sizeDelta = new Vector2(Mathf.Lerp(0f, 760f, Mathf.Clamp01((num - 0.15f) / 0.5f)), 8f);
}
private void Build()
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
canvas = Ui.MakeCanvas("MatchTargetCanvas", 7);
au = ((Component)this).gameObject.AddComponent<AudioSource>();
au.playOnAwake = false;
banner = Ui.Rect(((Component)canvas).transform, "Banner");
banner.sizeDelta = new Vector2(900f, 220f);
banner.anchoredPosition = new Vector2(0f, 60f);
bannerGroup = ((Component)banner).gameObject.AddComponent<CanvasGroup>();
bannerGroup.alpha = 0f;
Ui.Fill(((Graphic)Ui.Box((Transform)(object)banner, "Back", Ui.WithAlpha(Ui.Panel, 0.92f), Vector2.zero, Vector2.zero, rounded: true)).rectTransform, 0f);
bannerTitle = Ui.Text((Transform)(object)banner, "Title", "", 92f, Color.white, (TextAlignmentOptions)514);
((TMP_Text)bannerTitle).rectTransform.anchoredPosition = new Vector2(0f, 26f);
((TMP_Text)bannerTitle).rectTransform.sizeDelta = new Vector2(880f, 120f);
bannerSub = Ui.Text((Transform)(object)banner, "Sub", "", 34f, Ui.Grey, (TextAlignmentOptions)514);
((TMP_Text)bannerSub).rectTransform.anchoredPosition = new Vector2(0f, -58f);
((TMP_Text)bannerSub).rectTransform.sizeDelta = new Vector2(880f, 50f);
bannerBar = Ui.Box((Transform)(object)banner, "Bar", Color.white, new Vector2(0f, -24f), new Vector2(0f, 8f));
}
}
internal class Bar : MonoBehaviour
{
private sealed class Chip
{
public int Id;
public RectTransform Rt;
public TextMeshProUGUI Number;
public TextMeshProUGUI Pattern;
public Image Track;
public Image Fill;
public int Shown = -1;
public float PopAt = -10f;
public float FillNow;
public Controller Owner;
public Transform Head;
public Transform Torso;
}
private const float ChipWidth = 112f;
private static readonly FieldInfo texts = AccessTools.Field(typeof(WinCounterUI), "mPlayerWinTexts");
private Canvas canvas;
private RectTransform root;
private CanvasGroup group;
private TextMeshProUGUI label;
private Image crown;
private Image pill;
private Sprite crownSprite;
private Color crownColour = new Color(1f, 0.972f, 0f);
private readonly List<Chip> chips = new List<Chip>();
private readonly List<int> ids = new List<int>(4);
private readonly Vector3[] corners = (Vector3[])(object)new Vector3[4];
private int labelTarget = -1;
private WinDisplay wasShown = (WinDisplay)(-1);
private WinCounterUI counter;
private float counterSearchAt;
private static Func<Controller, Material, Material> paintText;
private static bool paintLooked;
public static WinDisplay Shown
{
get
{
WinDisplay value = Plugin.Display.Value;
if (value == WinDisplay.Bar && (MatchmakingHandler.IsNetworkMatch || Compat.RoundsMatch))
{
return WinDisplay.Corners;
}
return value;
}
}
public static bool Replacing => Shown != WinDisplay.Corners;
private void LateUpdate()
{
if ((Object)(object)canvas == (Object)null)
{
Build();
}
Ui.Attach(canvas);
if ((Object)(object)counter == (Object)null && Time.unscaledTime >= counterSearchAt)
{
counterSearchAt = Time.unscaledTime + 1f;
counter = Object.FindObjectOfType<WinCounterUI>();
if ((Object)(object)counter != (Object)null)
{
FindCrown();
if (Replacing)
{
Hide(counter);
}
}
}
WinDisplay shown = Shown;
if (shown != wasShown)
{
wasShown = shown;
if ((Object)(object)counter != (Object)null)
{
counter.ToggleWinCounterVisibility(true);
}
}
ControllerHandler instance = ControllerHandler.Instance;
bool flag = shown == WinDisplay.Bar && (Object)(object)counter != (Object)null && !GameManager.stillInMenu && (Object)(object)instance != (Object)null && !PauseManager.isPaused;
float num = ((!flag) ? 0f : (PlayerBehind() ? 0.3f : 1f));
group.alpha = Mathf.MoveTowards(group.alpha, num, Time.unscaledDeltaTime * 5f);
if ((!(group.alpha <= 0f) || flag) && !((Object)(object)instance == (Object)null))
{
Layout(instance);
}
}
private bool PlayerBehind()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: 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_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
Camera main = Camera.main;
if ((Object)(object)main == (Object)null)
{
return false;
}
((Graphic)pill).rectTransform.GetWorldCorners(corners);
Camera obj = (((int)canvas.renderMode == 0) ? null : canvas.worldCamera);
Vector2 val = RectTransformUtility.WorldToScreenPoint(obj, corners[0]);
Vector2 val2 = RectTransformUtility.WorldToScreenPoint(obj, corners[2]);
Rect r = Rect.MinMaxRect(val.x - 20f, val.y - 30f, val2.x + 20f, val2.y + 20f);
for (int i = 0; i < chips.Count; i++)
{
Chip chip = chips[i];
if (!((Object)(object)chip.Owner == (Object)null) && (OnScreenIn(main, r, chip.Head) || OnScreenIn(main, r, chip.Torso)))
{
return true;
}
}
return false;
}
private static bool OnScreenIn(Camera cam, Rect r, Transform part)
{
//IL_001a: 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_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: 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_0033: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)part == (Object)null || !((Component)part).gameObject.activeInHierarchy)
{
return false;
}
Vector3 val = cam.WorldToScreenPoint(part.position);
return ((Rect)(ref r)).Contains(new Vector2(val.x, val.y));
}
private Chip FindChip(int id)
{
for (int i = 0; i < chips.Count; i++)
{
if (chips[i].Id == id)
{
return chips[i];
}
}
return null;
}
public static void Hide(WinCounterUI c)
{
TextMeshProUGUI[] array = (((object)texts != null) ? (texts.GetValue(c) as TextMeshProUGUI[]) : null);
if (array == null)
{
return;
}
TextMeshProUGUI[] array2 = array;
foreach (TextMeshProUGUI val in array2)
{
if ((Object)(object)val != (Object)null)
{
((Component)val).gameObject.SetActive(false);
}
}
}
private void FindCrown()
{
//IL_00ca: 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)
if ((Object)(object)crownSprite != (Object)null)
{
return;
}
Image val = null;
Image[] componentsInChildren = ((Component)counter).GetComponentsInChildren<Image>(true);
foreach (Image val2 in componentsInChildren)
{
if ((Object)(object)val2.sprite != (Object)null && (((Object)val2).name.ToLowerInvariant().Contains("crown") || ((Object)val2.sprite).name.ToLowerInvariant().Contains("crown")))
{
val = val2;
break;
}
}
if ((Object)(object)val == (Object)null)
{
componentsInChildren = ((Component)counter).GetComponentsInChildren<Image>(true);
foreach (Image val3 in componentsInChildren)
{
if ((Object)(object)val3.sprite != (Object)null)
{
val = val3;
break;
}
}
}
if (!((Object)(object)val == (Object)null))
{
crownSprite = val.sprite;
crownColour = ((Graphic)val).color;
crown.sprite = crownSprite;
crown.preserveAspect = true;
}
}
private void Layout(ControllerHandler ch)
{
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Unknown result type (might be due to invalid IL or missing references)
//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
//IL_0555: Unknown result type (might be due to invalid IL or missing references)
//IL_0564: Unknown result type (might be due to invalid IL or missing references)
//IL_0569: Unknown result type (might be due to invalid IL or missing references)
//IL_056e: Unknown result type (might be due to invalid IL or missing references)
//IL_057c: Unknown result type (might be due to invalid IL or missing references)
//IL_0581: Unknown result type (might be due to invalid IL or missing references)
//IL_059a: Unknown result type (might be due to invalid IL or missing references)
//IL_05ab: Unknown result type (might be due to invalid IL or missing references)
//IL_0391: Unknown result type (might be due to invalid IL or missing references)
//IL_0388: Unknown result type (might be due to invalid IL or missing references)
//IL_0396: Unknown result type (might be due to invalid IL or missing references)
//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
//IL_0403: Unknown result type (might be due to invalid IL or missing references)
//IL_045a: Unknown result type (might be due to invalid IL or missing references)
//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
List<Controller> players = ch.players;
ids.Clear();
for (int i = 0; i < players.Count; i++)
{
Controller val = players[i];
if ((Object)(object)val != (Object)null && !ids.Contains(val.playerID))
{
ids.Add(val.playerID);
}
}
for (int num = chips.Count - 1; num >= 0; num--)
{
if (!ids.Contains(chips[num].Id))
{
Object.Destroy((Object)(object)((Component)chips[num].Rt).gameObject);
chips.RemoveAt(num);
}
}
bool flag = false;
for (int j = 0; j < ids.Count; j++)
{
if (FindChip(ids[j]) == null)
{
chips.Add(MakeChip(ids[j]));
flag = true;
}
}
if (flag)
{
SortChips();
}
int num2 = (Match.Active ? Match.Target : 0);
if (num2 != labelTarget)
{
labelTarget = num2;
((TMP_Text)label).text = ((num2 > 0) ? ("FIRST\nTO " + num2) : "");
}
float num3 = ((num2 > 0) ? 74f : 0f);
float num4 = (float)(-(chips.Count - 1)) * 112f * 0.5f;
((Graphic)pill).rectTransform.sizeDelta = new Vector2((float)chips.Count * 112f + num3 + 28f, 96f);
((Graphic)pill).rectTransform.anchoredPosition = new Vector2((0f - num3) * 0.5f, 0f);
((TMP_Text)label).rectTransform.anchoredPosition = new Vector2(num4 - 56f - num3 * 0.5f + 2f, -6f);
int num5 = 0;
int num6 = 0;
int id = -1;
foreach (Chip chip2 in chips)
{
int num7 = Match.Wins(chip2.Id);
if (num7 > num5)
{
num5 = num7;
num6 = 1;
id = chip2.Id;
}
else if (num7 == num5 && num7 > 0)
{
num6++;
}
}
float unscaledTime = Time.unscaledTime;
for (int k = 0; k < chips.Count; k++)
{
Chip chip = chips[k];
int num8 = Match.Wins(chip.Id);
chip.Rt.anchoredPosition = new Vector2(num4 + (float)k * 112f, 0f);
if (num8 != chip.Shown)
{
if (chip.Shown >= 0 && num8 > chip.Shown)
{
chip.PopAt = unscaledTime;
}
chip.Shown = num8;
((TMP_Text)chip.Number).text = num8.ToString();
}
Controller val2 = null;
for (int l = 0; l < players.Count; l++)
{
Controller val3 = players[l];
if ((Object)(object)val3 != (Object)null && val3.playerID == chip.Id)
{
val2 = val3;
}
}
if ((Object)(object)val2 != (Object)(object)chip.Owner)
{
SetOwner(chip, val2);
}
Color val4 = (((Object)(object)val2 != (Object)null) ? Ui.PlayerColor(val2) : Ui.SlotColor(chip.Id));
Material val5 = (((Object)(object)val2 != (Object)null) ? PatternedText(val2, ((TMP_Text)chip.Number).fontSharedMaterial) : null);
((Graphic)chip.Number).color = (Color)(((Object)(object)val5 != (Object)null) ? new Color(val4.r, val4.g, val4.b, 0f) : val4);
ShowPattern(chip, val5);
((Graphic)chip.Fill).color = val4;
float num9 = Mathf.Clamp01((unscaledTime - chip.PopAt) / 0.45f);
float num10 = 1f + Mathf.Sin(num9 * (float)Math.PI) * 0.45f * (1f - num9);
((Transform)((TMP_Text)chip.Number).rectTransform).localScale = new Vector3(num10, num10, 1f);
bool flag2 = num2 > 0;
((Behaviour)chip.Track).enabled = flag2;
((Behaviour)chip.Fill).enabled = flag2;
if (flag2)
{
chip.FillNow = Mathf.Lerp(chip.FillNow, Mathf.Clamp01((float)num8 / (float)num2), 1f - Mathf.Exp((0f - Time.unscaledDeltaTime) * 8f));
((Graphic)chip.Fill).rectTransform.sizeDelta = new Vector2(((Graphic)chip.Track).rectTransform.sizeDelta.x * chip.FillNow, ((Graphic)chip.Track).rectTransform.sizeDelta.y);
}
}
bool flag3 = num6 == 1 && (Object)(object)crownSprite != (Object)null;
((Behaviour)crown).enabled = flag3;
if (flag3)
{
Vector2 val6 = FindChip(id).Rt.anchoredPosition + new Vector2(0f, 30f);
RectTransform rectTransform = ((Graphic)crown).rectTransform;
rectTransform.anchoredPosition = Vector2.Lerp(rectTransform.anchoredPosition, val6, 1f - Mathf.Exp((0f - Time.unscaledDeltaTime) * 12f));
((Graphic)crown).color = crownColour;
}
}
private static Material PatternedText(Controller player, Material font)
{
if (!paintLooked)
{
paintLooked = true;
if (Chainloader.PluginInfos.TryGetValue("stickfight.paintcan", out var value) && (Object)(object)value.Instance != (Object)null)
{
MethodInfo methodInfo = ((object)value.Instance).GetType().Assembly.GetType("PaintCan.PaintCanApi")?.GetMethod("PatternedText", BindingFlags.Static | BindingFlags.Public);
if ((object)methodInfo != null)
{
paintText = (Func<Controller, Material, Material>)Delegate.CreateDelegate(typeof(Func<Controller, Material, Material>), methodInfo);
}
}
}
if (paintText == null)
{
return null;
}
return paintText(player, font);
}
private static void ShowPattern(Chip c, Material pattern)
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)pattern == (Object)null)
{
if ((Object)(object)c.Pattern != (Object)null && ((Behaviour)c.Pattern).enabled)
{
((Behaviour)c.Pattern).enabled = false;
}
return;
}
if ((Object)(object)c.Pattern == (Object)null)
{
c.Pattern = Ui.Text((Transform)(object)((TMP_Text)c.Number).rectTransform, "Pattern", ((TMP_Text)c.Number).text, ((TMP_Text)c.Number).fontSize, Color.white, (TextAlignmentOptions)514);
RectTransform rectTransform = ((TMP_Text)c.Pattern).rectTransform;
rectTransform.anchorMin = Vector2.zero;
rectTransform.anchorMax = Vector2.one;
Vector2 offsetMin = (rectTransform.offsetMax = Vector2.zero);
rectTransform.offsetMin = offsetMin;
((Transform)rectTransform).localScale = Vector3.one;
}
((Behaviour)c.Pattern).enabled = true;
if ((Object)(object)((TMP_Text)c.Pattern).fontSharedMaterial != (Object)(object)pattern)
{
((TMP_Text)c.Pattern).fontSharedMaterial = pattern;
}
((Graphic)c.Pattern).color = Color.white;
if (((TMP_Text)c.Pattern).text != ((TMP_Text)c.Number).text)
{
((TMP_Text)c.Pattern).text = ((TMP_Text)c.Number).text;
}
}
private static void SetOwner(Chip c, Controller owner)
{
c.Owner = owner;
Head val = (((Object)(object)owner != (Object)null) ? ((Component)owner).GetComponentInChildren<Head>(true) : null);
Torso val2 = (((Object)(object)owner != (Object)null) ? ((Component)owner).GetComponentInChildren<Torso>(true) : null);
c.Head = (((Object)(object)val != (Object)null) ? ((Component)val).transform : null);
c.Torso = (((Object)(object)val2 != (Object)null) ? ((Component)val2).transform : null);
}
private void SortChips()
{
for (int i = 1; i < chips.Count; i++)
{
Chip chip = chips[i];
int num = i - 1;
while (num >= 0 && chips[num].Id > chip.Id)
{
chips[num + 1] = chips[num];
num--;
}
chips[num + 1] = chip;
}
}
private Chip MakeChip(int id)
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: 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_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
Chip obj = new Chip
{
Id = id,
Rt = Ui.Rect((Transform)(object)root, "P" + (id + 1))
};
obj.Rt.sizeDelta = new Vector2(112f, 90f);
obj.Number = Ui.Text((Transform)(object)obj.Rt, "Number", "0", 50f, Ui.SlotColor(id), (TextAlignmentOptions)514);
((TMP_Text)obj.Number).rectTransform.sizeDelta = new Vector2(112f, 56f);
((TMP_Text)obj.Number).rectTransform.anchoredPosition = new Vector2(0f, -6f);
obj.Track = Ui.Box((Transform)(object)obj.Rt, "Track", new Color(1f, 1f, 1f, 0.18f), new Vector2(0f, -36f), new Vector2(56f, 5f));
obj.Fill = Ui.Box((Transform)(object)((Graphic)obj.Track).rectTransform, "Fill", Color.white, Vector2.zero, new Vector2(0f, 5f));
RectTransform rectTransform = ((Graphic)obj.Fill).rectTransform;
Vector2 val = default(Vector2);
((Vector2)(ref val))..ctor(0f, 0.5f);
rectTransform.anchorMax = val;
rectTransform.anchorMin = val;
rectTransform.pivot = new Vector2(0f, 0.5f);
rectTransform.anchoredPosition = Vector2.zero;
return obj;
}
private void Build()
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
canvas = Ui.MakeCanvas("MatchTargetBar", 3);
root = Ui.Rect(((Component)canvas).transform, "Bar");
RectTransform obj = root;
RectTransform obj2 = root;
Vector2 val = default(Vector2);
((Vector2)(ref val))..ctor(0.5f, 1f);
obj2.anchorMax = val;
obj.anchorMin = val;
root.anchoredPosition = new Vector2(0f, -60f);
root.sizeDelta = new Vector2(10f, 10f);
group = ((Component)root).gameObject.AddComponent<CanvasGroup>();
group.alpha = 0f;
group.blocksRaycasts = false;
pill = Ui.Box((Transform)(object)root, "Area", Color.clear, Vector2.zero, new Vector2(300f, 96f));
label = Ui.Text((Transform)(object)root, "Label", "", 22f, new Color(1f, 1f, 1f, 0.6f), (TextAlignmentOptions)514);
((TMP_Text)label).rectTransform.sizeDelta = new Vector2(80f, 60f);
((TMP_Text)label).lineSpacing = -31f;
crown = Ui.Box((Transform)(object)root, "Crown", Color.white, new Vector2(0f, 30f), new Vector2(30f, 22f));
((Behaviour)crown).enabled = false;
}
}
[HarmonyPatch(typeof(GameManager), "AllButOnePlayersDied")]
internal static class RoundOverPatch
{
[HarmonyPriority(0)]
private static bool Prefix(GameManager __instance, bool __runOriginal)
{
if (!__runOriginal)
{
return false;
}
return Match.RoundOver(__instance);
}
}
[HarmonyPatch(typeof(GameManager), "OnLevelFinishedLoading")]
internal static class SceneLoadedLeak
{
private static readonly FieldInfo field = AccessTools.Field(typeof(SceneManager), "sceneLoaded");
private static void Postfix(GameManager __instance)
{
if ((object)field == null || !(field.GetValue(null) is Delegate obj))
{
return;
}
Delegate obj2 = null;
bool flag = false;
Delegate[] invocationList = obj.GetInvocationList();
foreach (Delegate obj3 in invocationList)
{
object? target = obj3.Target;
GameManager val = (GameManager)((target is GameManager) ? target : null);
if (obj3.Target is GameManager && obj3.Method.Name == "OnLevelFinishedLoading" && (val == __instance || (Object)(object)val == (Object)null))
{
flag = true;
}
else
{
obj2 = Delegate.Combine(obj2, obj3);
}
}
if (flag)
{
field.SetValue(null, obj2);
}
}
}
[HarmonyPatch(typeof(Crown), "SetNewKing")]
internal static class LeaderCrown
{
private static bool Prefix(Crown __instance, ref Controller character, bool win)
{
if (!Match.Active || GameManager.stillInMenu || (Object)(object)character == (Object)null)
{
return true;
}
if (!win)
{
return false;
}
ControllerHandler instance = ControllerHandler.Instance;
if ((Object)(object)instance == (Object)null)
{
return true;
}
int num = -1;
Controller val = null;
foreach (Controller player in instance.players)
{
if (!((Object)(object)player == (Object)null))
{
int num2 = Match.Wins(player.playerID);
if (num2 > num || (num2 == num && (Object)(object)val != (Object)null && player.playerID < val.playerID))
{
num = num2;
val = player;
}
}
}
Controller crownBarrer = __instance.crownBarrer;
if ((Object)(object)crownBarrer == (Object)(object)character)
{
return true;
}
if ((Object)(object)crownBarrer != (Object)null && instance.players.Contains(crownBarrer) && Match.Wins(crownBarrer.playerID) >= num)
{
return false;
}
if (Match.Wins(character.playerID) >= num)
{
return true;
}
character = val;
return (Object)(object)val != (Object)null;
}
}
[HarmonyPatch(typeof(GameManager), "KillPlayer")]
internal static class NoCrownSteals
{
private static readonly FieldRef<GameManager, Crown> crown = AccessTools.FieldRefAccess<GameManager, Crown>("crown");
private static void Prefix(GameManager __instance, Controller playerToKill, out CharacterStats __state)
{
__state = null;
if (Match.Active && !GameManager.stillInMenu && !((Object)(object)playerToKill == (Object)null))
{
Controller damager = playerToKill.damager;
Crown val = crown.Invoke(__instance);
if ((Object)(object)damager != (Object)null && !damager.isAI && (Object)(object)val != (Object)null && (Object)(object)val.crownBarrer == (Object)(object)playerToKill)
{
__state = ((Component)damager).GetComponent<CharacterStats>();
}
}
}
private static void Postfix(CharacterStats __state)
{
if ((Object)(object)__state != (Object)null && __state.crownSteals > 0)
{
__state.crownSteals--;
}
}
}
[HarmonyPatch(typeof(WinCounterUI), "RefreshWinTexts")]
internal static class RefreshPatch
{
private static void Postfix(WinCounterUI __instance)
{
if (Bar.Replacing)
{
Bar.Hide(__instance);
}
}
}
[HarmonyPatch(typeof(WinCounterUI), "ToggleWinCounterVisibility")]
internal static class TogglePatch
{
private static void Prefix(ref bool isVisible)
{
isVisible = Bar.Shown == WinDisplay.Corners;
}
private static void Postfix(WinCounterUI __instance)
{
if (Bar.Replacing)
{
Bar.Hide(__instance);
}
}
}
[HarmonyPatch(typeof(OptionsButton))]
internal static class ShowWinsRow
{
private static readonly string[] Labels = new string[3] { "BAR", "CORNERS", "OFF" };
private static OptionsButton row;
private static bool Is(OptionsButton b)
{
if ((Object)(object)b != (Object)null && (Object)(object)((Component)b).transform.parent != (Object)null)
{
return ((Object)((Component)b).transform.parent).name == "Show Wins";
}
return false;
}
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void AfterStart(OptionsButton __instance)
{
if (Is(__instance))
{
row = __instance;
__instance.values = (string[])Labels.Clone();
Refresh();
}
}
[HarmonyPrefix]
[HarmonyPatch("MoveIndexRight")]
private static bool BeforeRight(OptionsButton __instance)
{
if (Is(__instance))
{
return Step(1);
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("MoveIndexLeft")]
private static bool BeforeLeft(OptionsButton __instance)
{
if (Is(__instance))
{
return Step(-1);
}
return true;
}
private static bool Step(int dir)
{
int num = Labels.Length;
Plugin.Display.Value = (WinDisplay)(((int)(Plugin.Display.Value + dir) % num + num) % num);
return false;
}
public static void Refresh()
{
if (!((Object)(object)row == (Object)null))
{
TextMeshProUGUI componentInChildren = ((Component)row).GetComponentInChildren<TextMeshProUGUI>(true);
int num = Mathf.Clamp((int)Plugin.Display.Value, 0, Labels.Length - 1);
if ((Object)(object)componentInChildren != (Object)null)
{
((TMP_Text)componentInChildren).text = Labels[num];
}
}
}
}
}