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 WarRooster v1.0.2
WarRooster.dll
Decompiled 2 days agousing System; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("0.0.0.0")] namespace WarRooster; [BepInPlugin("yuri.WarRooster", "War Rooster", "1.0.0")] public class Plugin : BaseUnityPlugin { public class Aposta { public string nome; public int qtd; public int qualidade; public int variante; public float durabilidade; public long crafterId; public string crafterNome; public int mundo; } public class Contrato { public string id; public int estado; public bool souDesafiante; public long oponenteId; public string oponenteNome; public long criado; public bool pediuDevolucao; public bool pedidoRecebido; public long pedidoQuando; public string repetir; public string pendencia; public string aviso; public bool minhaPaga; public bool delesPaga; public Aposta minha; public Aposta deles; } [HarmonyPatch(typeof(Character), "Damage")] public static class DanoPatch { private static void Postfix(Character __instance, HitData hit) { if ((Object)(object)Inst != (Object)null) { Inst.AoDano(__instance, hit); } } } [HarmonyPatch(typeof(Player), "OnDeath")] public static class MortePatch { private static void Postfix(Player __instance) { if ((Object)(object)Inst != (Object)null) { Inst.AoMorrer(__instance); } } } public static Plugin Inst; private ConfigEntry<bool> Ligado; private ConfigEntry<KeyboardShortcut> Tecla; private Contrato contrato; private List<string> resolvidos = new List<string>(); private ZRoutedRpc rpcDono; private bool aberto; private Rect janela; private Vector2 scrollJogadores; private Vector2 scrollItens; private string selJogador; private long selUser; private uint selZid; private string selNome; private int selQual; private int selVar; private int selX; private int selY; private int selQtd; private long ultimoId; private string ultimoNome = ""; private float ultimoQuando; private float proximoPasso; private bool avisouCheio; private void Awake() { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Expected O, but got Unknown //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Expected O, but got Unknown //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Expected O, but got Unknown //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Expected O, but got Unknown //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Expected O, but got Unknown //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Expected O, but got Unknown //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Expected O, but got Unknown //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Expected O, but got Unknown Inst = this; Ligado = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Turns on War Rooster in this game. Both fighters need this mod."); Tecla = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "Key", new KeyboardShortcut((KeyCode)289, (KeyCode[])(object)new KeyCode[0]), "Opens the window to challenge someone to a 1v1."); Carregar(); Harmony val = new Harmony("yuri.WarRooster"); val.PatchAll(Assembly.GetExecutingAssembly()); BindingFlags bindingAttr = BindingFlags.Static | BindingFlags.NonPublic; val.Patch((MethodBase)AccessTools.Method(typeof(GameCamera), "UpdateMouseCapture", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin).GetMethod("SoltaCursor", bindingAttr)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin).GetMethod("SemJogo", bindingAttr)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.Method(typeof(ZInput), "GetMouseDelta", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Plugin).GetMethod("BloqueiaDelta", bindingAttr)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.Method(typeof(ZInput), "GetMouseScrollWheel", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Plugin).GetMethod("BloqueiaRoda", bindingAttr)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.Method(typeof(ZInput), "GetMouseButton", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Plugin).GetMethod("BloqueiaBool", bindingAttr)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.Method(typeof(ZInput), "GetMouseButtonDown", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Plugin).GetMethod("BloqueiaBool", bindingAttr)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.Method(typeof(ZInput), "GetMouseButtonUp", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Plugin).GetMethod("BloqueiaBool", bindingAttr)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); ((BaseUnityPlugin)this).Logger.LogInfo((object)"War Rooster 1.0.0"); } private static bool JanelaAberta() { return (Object)(object)Inst != (Object)null && Inst.aberto; } private static void SoltaCursor() { if (JanelaAberta()) { ZCursor.LockState = (CursorLockMode)0; ZCursor.Show(); } } private static void SemJogo(ref bool __result) { if (JanelaAberta()) { __result = false; } } private static bool BloqueiaBool(ref bool __result) { if (!JanelaAberta()) { return true; } __result = false; return false; } private static bool BloqueiaRoda(ref float __result) { if (!JanelaAberta()) { return true; } __result = 0f; return false; } private static bool BloqueiaDelta(ref Vector2 __result) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (!JanelaAberta()) { return true; } __result = Vector2.zero; return false; } private void Update() { //IL_0025: 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) RegistrarRpc(); if ((Object)(object)Player.m_localPlayer == (Object)null) { return; } KeyboardShortcut value = Tecla.Value; if (((KeyboardShortcut)(ref value)).IsDown() && !ConsoleAberto()) { aberto = !aberto; } if (contrato == null || Time.time < proximoPasso) { return; } if (contrato.estado == 1 && contrato.souDesafiante && Agora() - contrato.criado > 90) { proximoPasso = Time.time + 1f; CancelarEspera("Nobody accepted. Your bet came back."); return; } if (contrato.estado == 4) { proximoPasso = Time.time + 5f; Enviar(contrato.repetir, contrato.id, contrato.oponenteId, contrato.oponenteNome, null); return; } if (contrato.estado == 5 || contrato.estado == 6) { proximoPasso = Time.time + 1f; if (contrato.estado == 5) { TentarPagar(); } else { TentarDevolver(); } } if (contrato != null && contrato.pediuDevolucao && Agora() - contrato.pedidoQuando > 40) { contrato.pediuDevolucao = false; } } private void OnGUI() { //IL_0062: 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_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0089: 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_00a4: Expected O, but got Unknown //IL_009f: 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_00a9: 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_005d: Unknown result type (might be due to invalid IL or missing references) if (aberto) { if (((Rect)(ref janela)).width < 10f) { janela = new Rect(((float)Screen.width - 560f) / 2f, ((float)Screen.height - 640f) / 2f, 560f, 640f); } Color backgroundColor = GUI.backgroundColor; GUI.backgroundColor = new Color(0.42f, 0.1f, 0.1f); janela = GUI.Window(4545, janela, new WindowFunction(Desenhar), "War Rooster"); GUI.backgroundColor = backgroundColor; } } private void Desenhar(int id) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Invalid comparison between Unknown and I4 Player localPlayer = Player.m_localPlayer; if ((int)Event.current.type == 4 && (int)Event.current.keyCode == 27) { aberto = false; Event.current.Use(); GUI.DragWindow(); return; } if ((Object)(object)localPlayer == (Object)null) { GUILayout.Label("Enter the world to challenge someone.", (GUILayoutOption[])(object)new GUILayoutOption[0]); if (GUILayout.Button("Close", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) })) { aberto = false; } GUI.DragWindow(); return; } GUILayout.Label("Both fighters need this mod. The bet leaves the bag and does not stay on the body.", (GUILayoutOption[])(object)new GUILayoutOption[0]); if (((Character)localPlayer).IsPVPEnabled()) { GUILayout.Label("Your PvP is on. The other fighter needs it on too.", (GUILayoutOption[])(object)new GUILayoutOption[0]); } else { GUILayout.Label("PvP is off. Without it the hit does not land.", (GUILayoutOption[])(object)new GUILayoutOption[0]); } if (GUILayout.Button("Turn PvP on for both", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) })) { ForcarPvp(avisarOutro: true); } if (contrato != null && contrato.estado == 1) { DesenharEspera(); } else if (contrato != null && contrato.estado == 2) { DesenharConvite(localPlayer); } else if (contrato != null && contrato.estado == 3) { DesenharRinha(); } else if (contrato != null && contrato.estado == 4) { GUILayout.Label(contrato.oponenteNome + " won: " + TextoPremio(contrato.minha, contrato.deles) + ".", (GUILayoutOption[])(object)new GUILayoutOption[0]); } else if (contrato != null && contrato.estado == 5) { GUILayout.Label("You won: " + TextoPremio(contrato.minha, contrato.deles) + ". If the bag is full, make a free slot.", (GUILayoutOption[])(object)new GUILayoutOption[0]); } else if (contrato != null && contrato.estado == 6) { GUILayout.Label("Giving your bet back.", (GUILayoutOption[])(object)new GUILayoutOption[0]); } else { DesenharChamado(localPlayer); } GUILayout.Space(8f); if (GUILayout.Button("Close", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) })) { aberto = false; } GUI.DragWindow(); } private void DesenharEspera() { GUILayout.Label("Waiting for " + contrato.oponenteNome + " to accept.", (GUILayoutOption[])(object)new GUILayoutOption[0]); GUILayout.Label("Your bet: " + Texto(contrato.minha), (GUILayoutOption[])(object)new GUILayoutOption[0]); if (GUILayout.Button("Cancel", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) })) { CancelarEspera("Challenge cancelled. Your bet came back."); } } private void DesenharConvite(Player jogador) { //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_0076: 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) GUILayout.Label(contrato.oponenteNome + " challenged you to a 1v1.", (GUILayoutOption[])(object)new GUILayoutOption[0]); GUILayout.Label("They bet: " + Texto(contrato.deles), (GUILayoutOption[])(object)new GUILayoutOption[0]); GUILayout.Label("Pick what you bet. It can be coins, gems, a weapon, armor or another item.", (GUILayoutOption[])(object)new GUILayoutOption[0]); DesenharItens(jogador); Color backgroundColor = GUI.backgroundColor; GUI.backgroundColor = new Color(0.75f, 0.55f, 0.16f); if (GUILayout.Button("Accept and bet", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(34f) })) { Aceitar(jogador); } GUI.backgroundColor = backgroundColor; if (GUILayout.Button("Decline", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) })) { Recusar(); } } private void DesenharRinha() { GUILayout.Label("Fight against " + contrato.oponenteNome + ".", (GUILayoutOption[])(object)new GUILayoutOption[0]); GUILayout.Label("You bet: " + Texto(contrato.minha), (GUILayoutOption[])(object)new GUILayoutOption[0]); GUILayout.Label("They bet: " + Texto(contrato.deles), (GUILayoutOption[])(object)new GUILayoutOption[0]); GUILayout.Label("Whoever falls to the other loses. A fall, a creature or hunger do not count. Forfeit hands over the bet.", (GUILayoutOption[])(object)new GUILayoutOption[0]); if (contrato.pedidoRecebido) { GUILayout.Label(contrato.oponenteNome + " wants to return both bets.", (GUILayoutOption[])(object)new GUILayoutOption[0]); if (GUILayout.Button("Accept and return", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) })) { ConcordarDevolucao(); } } else if (contrato.pediuDevolucao) { GUILayout.Label("Return request sent.", (GUILayoutOption[])(object)new GUILayoutOption[0]); } else if (GUILayout.Button("Ask to return", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) })) { PedirDevolucao(); } GUILayout.Space(6f); if (GUILayout.Button("Forfeit", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) })) { Perder("desistir"); } } private void DesenharChamado(Player jogador) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: 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_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) if (!Ligado.Value) { GUILayout.Label("War Rooster is off in F1.", (GUILayoutOption[])(object)new GUILayoutOption[0]); return; } GUILayout.Label("Challenge someone. Coins are the currency. Gems are amber, ruby and silver. Without those, the item you are holding is used.", (GUILayoutOption[])(object)new GUILayoutOption[0]); scrollJogadores = GUILayout.BeginScrollView(scrollJogadores, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(120f) }); List<PlayerInfo> list = Gente(); if (list.Count == 0) { GUILayout.Label("Nobody else in this world.", (GUILayoutOption[])(object)new GUILayoutOption[0]); } for (int i = 0; i < list.Count; i++) { PlayerInfo val = list[i]; bool flag = val.m_name == selJogador && ((ZDOID)(ref val.m_characterID)).UserID == selUser && ((ZDOID)(ref val.m_characterID)).ID == selZid; Color backgroundColor = GUI.backgroundColor; if (flag) { GUI.backgroundColor = new Color(0.75f, 0.55f, 0.16f); } if (GUILayout.Button(val.m_name, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) })) { selJogador = val.m_name; selUser = ((ZDOID)(ref val.m_characterID)).UserID; selZid = ((ZDOID)(ref val.m_characterID)).ID; } GUI.backgroundColor = backgroundColor; } GUILayout.EndScrollView(); if (!string.IsNullOrEmpty(selJogador)) { GUILayout.Label("Against: " + selJogador, (GUILayoutOption[])(object)new GUILayoutOption[0]); } DesenharItens(jogador); Color backgroundColor2 = GUI.backgroundColor; GUI.backgroundColor = new Color(0.75f, 0.55f, 0.16f); if (GUILayout.Button("Challenge to a 1v1", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(34f) })) { Chamar(jogador); } GUI.backgroundColor = backgroundColor2; } private void DesenharItens(Player jogador) { //IL_000b: 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) //IL_002d: 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_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) List<ItemData> list = Itens(jogador); scrollItens = GUILayout.BeginScrollView(scrollItens, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(200f) }); if (list.Count == 0) { GUILayout.Label("Bag is empty.", (GUILayoutOption[])(object)new GUILayoutOption[0]); } for (int i = 0; i < list.Count; i++) { ItemData val = list[i]; bool flag = MesmoItem(val); string text = NomeBonito(val.m_shared.m_name); if (val.m_quality > 1) { text = text + " lv" + val.m_quality; } if (val.m_stack > 1) { text = text + " x" + val.m_stack; } if (val.m_equipped) { text += " (equipped)"; } Color backgroundColor = GUI.backgroundColor; if (flag) { GUI.backgroundColor = new Color(0.75f, 0.55f, 0.16f); } if (GUILayout.Button(text, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(24f) })) { selNome = NomeInterno(val); selQual = val.m_quality; selVar = val.m_variant; selX = val.m_gridPos.x; selY = val.m_gridPos.y; selQtd = val.m_stack; } GUI.backgroundColor = backgroundColor; } GUILayout.EndScrollView(); if (string.IsNullOrEmpty(selNome)) { return; } GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]); if (GUILayout.Button("-10", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(48f) })) { selQtd -= 10; } if (GUILayout.Button("-1", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) })) { selQtd--; } GUILayout.Label("Amount: " + selQtd, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(140f) }); if (GUILayout.Button("+1", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) })) { selQtd++; } if (GUILayout.Button("+10", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(48f) })) { selQtd += 10; } if (GUILayout.Button("All", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(56f) })) { ItemData val = AcharItem(jogador); if (val != null) { selQtd = val.m_stack; } } GUILayout.EndHorizontal(); ItemData val2 = AcharItem(jogador); if (val2 != null && selQtd > val2.m_stack) { selQtd = val2.m_stack; } if (selQtd < 1) { selQtd = 1; } } private void Chamar(Player jogador) { if (contrato != null) { return; } if (string.IsNullOrEmpty(selJogador)) { Avisar("Pick who you will challenge."); return; } if (!AcharJogador(selJogador, selUser, selZid, out var achado)) { Avisar("That player is no longer in the world."); return; } ItemData val = AcharItem(jogador); if (val == null || selQtd < 1 || selQtd > val.m_stack) { Avisar("Pick what you will bet."); return; } Aposta aposta = Copiar(val, selQtd); if (val.m_equipped) { ((Humanoid)jogador).UnequipItem(val, false); } if (!((Humanoid)jogador).GetInventory().RemoveItem(val, selQtd)) { Avisar("Could not split off the bet."); return; } contrato = new Contrato(); contrato.id = Guid.NewGuid().ToString("N"); contrato.estado = 1; contrato.souDesafiante = true; contrato.oponenteNome = achado.m_name; contrato.minha = aposta; contrato.criado = Agora(); Salvar(); EnviarAlvo("desafio", contrato.id, achado.m_name, ((ZDOID)(ref achado.m_characterID)).UserID, ((ZDOID)(ref achado.m_characterID)).ID, aposta); Avisar("Challenge sent to " + achado.m_name + "."); } private void Aceitar(Player jogador) { if (contrato == null || contrato.estado != 2) { return; } ItemData val = AcharItem(jogador); if (val == null || selQtd < 1 || selQtd > val.m_stack) { Avisar("Pick what you will bet."); return; } Aposta aposta = Copiar(val, selQtd); if (val.m_equipped) { ((Humanoid)jogador).UnequipItem(val, false); } if (!((Humanoid)jogador).GetInventory().RemoveItem(val, selQtd)) { Avisar("Could not split off the bet."); return; } contrato.minha = aposta; contrato.estado = 3; Salvar(); Enviar("aceitar", contrato.id, contrato.oponenteId, contrato.oponenteNome, aposta); ForcarPvp(avisarOutro: true); Avisar("Fight on against " + contrato.oponenteNome + "."); } private void ForcarPvp(bool avisarOutro) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return; } if (((Character)localPlayer).IsPVPEnabled()) { localPlayer.SetPVP(false); } localPlayer.SetPVP(true); if (!avisarOutro) { return; } if (contrato != null && !string.IsNullOrEmpty(contrato.oponenteNome)) { Enviar("pvp", string.IsNullOrEmpty(contrato.id) ? "pvp" : contrato.id, contrato.oponenteId, contrato.oponenteNome, null); } else { if (string.IsNullOrEmpty(selJogador)) { Avisar("PvP is on here. Pick the other fighter to turn it on for them too."); return; } EnviarAlvo("pvp", "pvp", selJogador, selUser, selZid, null); } Avisar("PvP is on for both."); } private void Recusar() { if (contrato != null && contrato.estado == 2) { Enviar("recusar", contrato.id, contrato.oponenteId, contrato.oponenteNome, null); string oponenteNome = contrato.oponenteNome; contrato = null; Salvar(); Avisar("You declined the challenge from " + oponenteNome + "."); } } private void PedirDevolucao() { if (contrato != null && contrato.estado == 3) { contrato.pediuDevolucao = true; contrato.pedidoQuando = Agora(); if (contrato.pedidoRecebido) { ConcordarDevolucao(); return; } Salvar(); Enviar("pedido", contrato.id, contrato.oponenteId, contrato.oponenteNome, null); Avisar("Asked to return the bets."); } } private void ConcordarDevolucao() { if (contrato != null && contrato.estado == 3) { contrato.aviso = "Bets returned."; contrato.pendencia = "devolvido"; contrato.estado = 6; Salvar(); TentarDevolver(); } } private void Perder(string verbo) { if (contrato != null && contrato.estado == 3) { contrato.estado = 4; contrato.repetir = verbo; Salvar(); Enviar(verbo, contrato.id, contrato.oponenteId, contrato.oponenteNome, null); proximoPasso = Time.time + 5f; aberto = true; Avisar(contrato.oponenteNome + " won: " + TextoPremio(contrato.minha, contrato.deles) + ".", guardar: true); } } private void CancelarEspera(string aviso) { if (contrato != null && contrato.estado == 1) { string id = contrato.id; long oponenteId = contrato.oponenteId; string oponenteNome = contrato.oponenteNome; Enviar("expirou", id, oponenteId, oponenteNome, null); contrato.aviso = aviso; contrato.pendencia = ""; contrato.estado = 6; Salvar(); TentarDevolver(); } } public void AoDano(Character vitima, HitData hit) { //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)vitima != (Object)(object)Player.m_localPlayer || hit == null || contrato == null || contrato.estado != 3) { return; } List<Player> allPlayers = Player.GetAllPlayers(); if (allPlayers == null) { return; } for (int i = 0; i < allPlayers.Count; i++) { Player val = allPlayers[i]; if (!((Object)(object)val == (Object)null) && !((Object)(object)val == (Object)(object)Player.m_localPlayer) && !(((Character)val).GetZDOID() != hit.m_attacker)) { ultimoId = val.GetPlayerID(); ultimoNome = val.GetPlayerName(); ultimoQuando = Time.time; break; } } } public void AoMorrer(Player vitima) { if ((Object)(object)vitima != (Object)(object)Player.m_localPlayer || contrato == null || contrato.estado != 3) { return; } bool flag = false; if (Time.time - ultimoQuando < 15f) { if (contrato.oponenteId != 0 && ultimoId == contrato.oponenteId) { flag = true; } else if (!string.IsNullOrEmpty(ultimoNome) && ultimoNome == contrato.oponenteNome) { flag = true; } } if (!flag) { Avisar("You fell, but not to your opponent. The fight goes on."); } else { Perder("morri"); } } private void RegistrarRpc() { if (ZRoutedRpc.instance != null && ZRoutedRpc.instance != rpcDono) { ZRoutedRpc.instance.Register<ZPackage>("WarRooster", (Action<long, ZPackage>)Receber); rpcDono = ZRoutedRpc.instance; } } private static void Receber(long remetente, ZPackage pkg) { if ((Object)(object)Inst != (Object)null) { Inst.Tratar(remetente, pkg); } } private void Tratar(long remetente, ZPackage pkg) { try { if ((Object)(object)Player.m_localPlayer == (Object)null || pkg == null) { return; } int num = pkg.ReadInt(); if (num != 1) { return; } string text = pkg.ReadString(); string id = pkg.ReadString(); long num2 = pkg.ReadLong(); string deNome = pkg.ReadString(); string text2 = pkg.ReadString(); long alvoUser = pkg.ReadLong(); uint alvoZid = pkg.ReadUInt(); Aposta aposta = null; if (pkg.ReadBool()) { aposta = LerAposta(pkg); } long playerID = Player.m_localPlayer.GetPlayerID(); if (num2 == playerID || text2 != Player.m_localPlayer.GetPlayerName()) { return; } switch (text) { case "desafio": ReceberDesafio(id, num2, deNome, alvoUser, alvoZid, aposta); break; case "aceitar": ReceberAceite(id, num2, deNome, aposta); break; case "recusar": ReceberRecusa(id, deNome); break; case "expirou": ReceberExpirou(id, num2, deNome); break; default: if (!(text == "desistir")) { if (text == "pedido") { ReceberPedido(id, num2); } else if (text == "devolvido" || text == "empate") { ReceberDevolucao(id, num2, text); } else if (text == "ack") { ReceberAck(id, num2); } else if (text == "pvp") { ForcarPvp(avisarOutro: false); } break; } goto case "morri"; case "morri": ReceberDerrota(text, id, num2, deNome); break; } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("War Rooster packet ignored: " + ex.Message)); } } private void ReceberDesafio(string id, long deId, string deNome, long alvoUser, uint alvoZid, Aposta aposta) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) ZDOID zDOID = ((Character)Player.m_localPlayer).GetZDOID(); if (((ZDOID)(ref zDOID)).UserID == alvoUser && ((ZDOID)(ref zDOID)).ID == alvoZid && aposta != null && aposta.qtd > 0) { if (!Ligado.Value || (contrato != null && (contrato.estado != 2 || !(contrato.id == id)))) { Enviar("recusar", id, deId, deNome, null); } else if (contrato == null || !(contrato.id == id)) { contrato = new Contrato(); contrato.id = id; contrato.estado = 2; contrato.souDesafiante = false; contrato.oponenteId = deId; contrato.oponenteNome = deNome; contrato.deles = aposta; contrato.criado = Agora(); Salvar(); aberto = true; Avisar(deNome + " challenged you to a 1v1."); } } } private void ReceberAceite(string id, long deId, string deNome, Aposta aposta) { if (contrato == null || contrato.id != id || contrato.estado != 1 || !contrato.souDesafiante || deNome != contrato.oponenteNome) { Enviar("expirou", id, deId, deNome, null); return; } if (aposta == null || aposta.qtd <= 0) { Enviar("expirou", id, deId, deNome, null); return; } contrato.oponenteId = deId; contrato.deles = aposta; contrato.estado = 3; Salvar(); aberto = true; ForcarPvp(avisarOutro: true); Avisar("Fight on against " + deNome + "."); } private void ReceberRecusa(string id, string deNome) { if (contrato != null && !(contrato.id != id) && contrato.estado == 1 && !(deNome != contrato.oponenteNome)) { CancelarEspera(deNome + " declined. Your bet came back."); } } private void ReceberExpirou(string id, long deId, string deNome) { if (contrato != null && !(contrato.id != id) && !contrato.souDesafiante && (deId == contrato.oponenteId || !(deNome != contrato.oponenteNome))) { if (contrato.estado == 2) { contrato = null; Salvar(); Avisar("The challenge expired."); } else if (contrato.estado == 3) { contrato.aviso = "The challenge expired. Your bet came back."; contrato.pendencia = ""; contrato.estado = 6; Salvar(); TentarDevolver(); } } } private void ReceberDerrota(string verbo, string id, long deId, string deNome) { if (JaResolvido(id)) { Enviar("ack", id, deId, deNome, null); } else if (contrato != null && !(contrato.id != id) && (deId == contrato.oponenteId || !(deNome != contrato.oponenteNome))) { if (contrato.estado == 4) { Empatar(); } else if (contrato.estado == 5) { TentarPagar(); } else if (contrato.estado == 3) { aberto = true; Avisar("You won: " + TextoPremio(contrato.minha, contrato.deles) + ".", guardar: true); Pagar(); } } } private void ReceberPedido(string id, long deId) { if (contrato != null && !(contrato.id != id) && contrato.estado == 3 && (deId == contrato.oponenteId || deId == 0)) { contrato.pedidoRecebido = true; aberto = true; if (contrato.pediuDevolucao) { ConcordarDevolucao(); } else { Avisar(contrato.oponenteNome + " wants to return the bets."); } } } private void ReceberDevolucao(string id, long deId, string verbo) { if (contrato != null && !(contrato.id != id) && (deId == contrato.oponenteId || deId == 0) && contrato.estado != 6 && contrato.estado != 5 && contrato.estado != 4 && (contrato.estado == 3 || contrato.estado == 1 || contrato.estado == 2)) { if (contrato.estado == 2) { contrato = null; Salvar(); Avisar("The challenge was cancelled."); } else { contrato.aviso = ((verbo == "empate") ? "Both fell. Your bet came back." : "Bets returned."); contrato.pendencia = ""; contrato.estado = 6; Salvar(); TentarDevolver(); } } } private void ReceberAck(string id, long deId) { if (contrato != null && !(contrato.id != id) && contrato.estado == 4 && (deId == contrato.oponenteId || deId == 0)) { Lembrar(id); contrato = null; Salvar(); } } private void Pagar() { if (contrato == null) { return; } if (JaResolvido(contrato.id)) { Enviar("ack", contrato.id, contrato.oponenteId, contrato.oponenteNome, null); return; } if (contrato.estado != 5) { contrato.estado = 5; contrato.minhaPaga = false; contrato.delesPaga = false; Salvar(); } TentarPagar(); } private void TentarPagar() { if (contrato == null || contrato.estado != 5) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return; } if (!contrato.minhaPaga) { contrato.minhaPaga = Entregar(localPlayer, contrato.minha); } if (!contrato.delesPaga) { contrato.delesPaga = Entregar(localPlayer, contrato.deles); } Salvar(); if (!contrato.minhaPaga || !contrato.delesPaga) { if (!avisouCheio) { avisouCheio = true; Avisar("Inventory full. Make a free slot and the bet goes in."); } return; } string id = contrato.id; long oponenteId = contrato.oponenteId; string oponenteNome = contrato.oponenteNome; string text = TextoPremio(contrato.minha, contrato.deles); Lembrar(id); contrato = null; avisouCheio = false; Salvar(); Enviar("ack", id, oponenteId, oponenteNome, null); Avisar("You won: " + text + ".", guardar: true); } private void Empatar() { if (contrato != null) { contrato.aviso = "Both fell. Your bet came back."; contrato.pendencia = "empate"; contrato.estado = 6; Salvar(); TentarDevolver(); } } private void TentarDevolver() { if (contrato == null || contrato.estado != 6) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return; } if (contrato.minha != null && !Entregar(localPlayer, contrato.minha)) { if (!avisouCheio) { avisouCheio = true; Avisar("Inventory full. Make a free slot and the bet comes back."); } return; } string pendencia = contrato.pendencia; string id = contrato.id; long oponenteId = contrato.oponenteId; string oponenteNome = contrato.oponenteNome; string aviso = contrato.aviso; Lembrar(id); contrato = null; avisouCheio = false; Salvar(); if (!string.IsNullOrEmpty(pendencia)) { Enviar(pendencia, id, oponenteId, oponenteNome, null); } if (!string.IsNullOrEmpty(aviso)) { Avisar(aviso); } } private bool Entregar(Player jogador, Aposta aposta) { if (aposta == null || aposta.qtd <= 0 || string.IsNullOrEmpty(aposta.nome)) { return true; } if ((Object)(object)ObjectDB.instance == (Object)null) { return false; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(aposta.nome); if ((Object)(object)itemPrefab == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Bet item does not exist: " + aposta.nome)); return false; } ItemDrop component = itemPrefab.GetComponent<ItemDrop>(); if ((Object)(object)component == (Object)null || component.m_itemData == null) { return false; } ItemData val = component.m_itemData.Clone(); val.m_stack = aposta.qtd; val.m_quality = aposta.qualidade; val.m_variant = aposta.variante; val.m_durability = aposta.durabilidade; val.m_crafterID = aposta.crafterId; val.m_crafterName = aposta.crafterNome; val.m_worldLevel = aposta.mundo; val.m_equipped = false; return ((Humanoid)jogador).GetInventory().AddItem(val); } private void Enviar(string verbo, string id, long paraId, string alvoNome, Aposta aposta) { long user = 0L; uint zid = 0u; EnviarPacote(verbo, id, alvoNome, user, zid, aposta); } private void EnviarAlvo(string verbo, string id, string alvoNome, long user, uint zid, Aposta aposta) { EnviarPacote(verbo, id, alvoNome, user, zid, aposta); } private void EnviarPacote(string verbo, string id, string alvoNome, long user, uint zid, Aposta aposta) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown if (ZRoutedRpc.instance != null && !((Object)(object)Player.m_localPlayer == (Object)null) && !string.IsNullOrEmpty(id)) { ZPackage val = new ZPackage(); val.Write(1); val.Write(verbo); val.Write(id); val.Write(Player.m_localPlayer.GetPlayerID()); val.Write(Player.m_localPlayer.GetPlayerName()); val.Write((alvoNome == null) ? "" : alvoNome); val.Write(user); val.Write(zid); val.Write(aposta != null); if (aposta != null) { EscreverAposta(val, aposta); } ZRoutedRpc.instance.InvokeRoutedRPC(0L, "WarRooster", new object[1] { val }); } } private static void EscreverAposta(ZPackage pkg, Aposta aposta) { pkg.Write((aposta.nome == null) ? "" : aposta.nome); pkg.Write(aposta.qtd); pkg.Write(aposta.qualidade); pkg.Write(aposta.variante); pkg.Write(aposta.durabilidade); pkg.Write(aposta.crafterId); pkg.Write((aposta.crafterNome == null) ? "" : aposta.crafterNome); pkg.Write(aposta.mundo); } private static Aposta LerAposta(ZPackage pkg) { Aposta aposta = new Aposta(); aposta.nome = pkg.ReadString(); aposta.qtd = pkg.ReadInt(); aposta.qualidade = pkg.ReadInt(); aposta.variante = pkg.ReadInt(); aposta.durabilidade = pkg.ReadSingle(); aposta.crafterId = pkg.ReadLong(); aposta.crafterNome = pkg.ReadString(); aposta.mundo = pkg.ReadInt(); return aposta; } private List<PlayerInfo> Gente() { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: 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_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) List<PlayerInfo> list = new List<PlayerInfo>(); if ((Object)(object)ZNet.instance == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null) { return list; } List<PlayerInfo> playerList = ZNet.instance.GetPlayerList(); if (playerList == null) { return list; } ZDOID zDOID = ((Character)Player.m_localPlayer).GetZDOID(); for (int i = 0; i < playerList.Count; i++) { PlayerInfo item = playerList[i]; if (!string.IsNullOrEmpty(item.m_name) && !(item.m_characterID == zDOID)) { list.Add(item); } } return list; } private bool AcharJogador(string nome, long user, uint zid, out PlayerInfo achado) { //IL_0003: 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_001c: 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_005b: Unknown result type (might be due to invalid IL or missing references) achado = default(PlayerInfo); List<PlayerInfo> list = Gente(); for (int i = 0; i < list.Count; i++) { PlayerInfo val = list[i]; if (val.m_name == nome && ((ZDOID)(ref val.m_characterID)).UserID == user && ((ZDOID)(ref val.m_characterID)).ID == zid) { achado = val; return true; } } return false; } private List<ItemData> Itens(Player jogador) { List<ItemData> list = new List<ItemData>(); if ((Object)(object)jogador == (Object)null || ((Humanoid)jogador).GetInventory() == null) { return list; } List<ItemData> allItems = ((Humanoid)jogador).GetInventory().GetAllItems(); if (allItems == null) { return list; } for (int i = 0; i < allItems.Count; i++) { ItemData val = allItems[i]; if (val != null && val.m_shared != null && val.m_stack > 0 && !val.m_shared.m_questItem) { list.Add(val); } } list.Sort(delegate(ItemData a, ItemData b) { int num = Peso(NomeInterno(a)).CompareTo(Peso(NomeInterno(b))); return (num != 0) ? num : NomeBonito(a.m_shared.m_name).CompareTo(NomeBonito(b.m_shared.m_name)); }); return list; } private static int Peso(string nome) { switch (nome) { case "Coins": return 0; default: if (!(nome == "SilverNecklace")) { return 2; } goto case "Ruby"; case "Ruby": case "Amber": case "AmberPearl": case "Silver": return 1; } } private ItemData AcharItem(Player jogador) { List<ItemData> list = Itens(jogador); for (int i = 0; i < list.Count; i++) { if (MesmoItem(list[i])) { return list[i]; } } return null; } private bool MesmoItem(ItemData item) { return item != null && NomeInterno(item) == selNome && item.m_quality == selQual && item.m_variant == selVar && item.m_gridPos.x == selX && item.m_gridPos.y == selY; } private static Aposta Copiar(ItemData item, int qtd) { Aposta aposta = new Aposta(); aposta.nome = NomeInterno(item); aposta.qtd = qtd; aposta.qualidade = item.m_quality; aposta.variante = item.m_variant; aposta.durabilidade = item.m_durability; aposta.crafterId = item.m_crafterID; aposta.crafterNome = ((item.m_crafterName == null) ? "" : item.m_crafterName); aposta.mundo = item.m_worldLevel; return aposta; } private static string NomeInterno(ItemData item) { if ((Object)(object)item.m_dropPrefab != (Object)null && !string.IsNullOrEmpty(((Object)item.m_dropPrefab).name)) { return ((Object)item.m_dropPrefab).name; } return item.m_shared.m_name; } private static string NomeBonito(string nome) { if (string.IsNullOrEmpty(nome)) { return ""; } if (Localization.instance == null) { return nome; } string text = Localization.instance.Localize(nome); if (text != nome) { return text; } if (!nome.StartsWith("$")) { string text2 = "$item_" + nome.ToLowerInvariant(); string text3 = Localization.instance.Localize(text2); if (text3 != text2) { return text3; } } return nome; } private static string Texto(Aposta aposta) { if (aposta == null || aposta.qtd <= 0) { return "nothing"; } string text = NomeBonito(aposta.nome); if (aposta.qualidade > 1) { text = text + " lv" + aposta.qualidade; } if (aposta.qtd > 1) { text = text + " x" + aposta.qtd; } return text; } private static string TextoPremio(Aposta minha, Aposta deles) { string text = Texto(minha); string text2 = Texto(deles); if (text == "nothing") { return text2; } if (text2 == "nothing") { return text; } return text + " and " + text2; } private void Avisar(string texto) { Avisar(texto, guardar: false); } private void Avisar(string texto, bool guardar) { ((BaseUnityPlugin)this).Logger.LogInfo((object)texto); if (!((Object)(object)MessageHud.instance == (Object)null)) { MessageHud.instance.ShowMessage((MessageType)2, texto, 0, (Sprite)null, true, guardar); if (guardar) { MessageHud.instance.ShowMessage((MessageType)1, texto, 0, (Sprite)null, true, true); } } } private bool JaResolvido(string id) { return resolvidos.Contains(id); } private void Lembrar(string id) { if (!string.IsNullOrEmpty(id) && !resolvidos.Contains(id)) { resolvidos.Insert(0, id); while (resolvidos.Count > 30) { resolvidos.RemoveAt(resolvidos.Count - 1); } } } private string Arquivo() { return Path.Combine(Paths.ConfigPath, "yuri.WarRooster.contrato"); } private void Salvar() { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown try { ZPackage val = new ZPackage(); val.Write(1); val.Write(resolvidos.Count); for (int i = 0; i < resolvidos.Count; i++) { val.Write(resolvidos[i]); } val.Write(contrato != null); if (contrato != null) { val.Write((contrato.id == null) ? "" : contrato.id); val.Write(contrato.estado); val.Write(contrato.souDesafiante); val.Write(contrato.oponenteId); val.Write((contrato.oponenteNome == null) ? "" : contrato.oponenteNome); val.Write(contrato.criado); val.Write(contrato.pediuDevolucao); val.Write(contrato.pedidoRecebido); val.Write(contrato.pedidoQuando); val.Write((contrato.repetir == null) ? "" : contrato.repetir); val.Write((contrato.pendencia == null) ? "" : contrato.pendencia); val.Write((contrato.aviso == null) ? "" : contrato.aviso); val.Write(contrato.minhaPaga); val.Write(contrato.delesPaga); val.Write(contrato.minha != null); if (contrato.minha != null) { EscreverAposta(val, contrato.minha); } val.Write(contrato.deles != null); if (contrato.deles != null) { EscreverAposta(val, contrato.deles); } } string text = Arquivo(); string text2 = text + ".tmp"; File.WriteAllBytes(text2, val.GetArray()); if (File.Exists(text)) { File.Delete(text); } File.Move(text2, text); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not save the contract: " + ex.Message)); } } private void Carregar() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown try { string path = Arquivo(); if (!File.Exists(path)) { return; } ZPackage val = new ZPackage(File.ReadAllBytes(path)); if (val.ReadInt() != 1) { return; } int num = val.ReadInt(); resolvidos.Clear(); for (int i = 0; i < num; i++) { resolvidos.Add(val.ReadString()); } if (!val.ReadBool()) { contrato = null; return; } contrato = new Contrato(); contrato.id = val.ReadString(); contrato.estado = val.ReadInt(); contrato.souDesafiante = val.ReadBool(); contrato.oponenteId = val.ReadLong(); contrato.oponenteNome = val.ReadString(); contrato.criado = val.ReadLong(); contrato.pediuDevolucao = val.ReadBool(); contrato.pedidoRecebido = val.ReadBool(); contrato.pedidoQuando = val.ReadLong(); contrato.repetir = val.ReadString(); contrato.pendencia = val.ReadString(); contrato.aviso = val.ReadString(); contrato.minhaPaga = val.ReadBool(); contrato.delesPaga = val.ReadBool(); if (val.ReadBool()) { contrato.minha = LerAposta(val); } if (val.ReadBool()) { contrato.deles = LerAposta(val); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Old contract ignored: " + ex.Message)); contrato = null; } } private static bool ConsoleAberto() { return (Object)(object)Console.instance != (Object)null && Console.IsVisible(); } private static long Agora() { return (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; } }