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 Teams Roulette v0.3.14
plugins/TeamsRoulette.dll
Decompiled 2 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using SoftReferenceableAssets; using Splatform; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace PerfectTeamsRoulette { [BepInPlugin("com.perfectmods.perfectteamsroulette", "Teams Roulette", "0.3.14")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { private sealed class DamageSource { public ZDOID Attacker; } [Serializable] private sealed class Group { public string Name; public string Leader; public List<string> Members = new List<string>(); } [Serializable] private sealed class GroupFile { public List<Group> Groups = new List<Group>(); } private sealed class GroupListPopup : WarningPopup { [CompilerGenerated] private static class <>O { public static PopupButtonCallback <0>__Pop; } public readonly string[] Names; public readonly int Offset; public GroupListPopup(string[] names, int offset) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown object obj = <>O.<0>__Pop; if (obj == null) { PopupButtonCallback val = UnifiedPopup.Pop; <>O.<0>__Pop = val; obj = (object)val; } ((WarningPopup)this)..ctor("Список команд", "", (PopupButtonCallback)obj, false); Names = names; Offset = offset; } } [CompilerGenerated] private static class <>O { public static Func<string, bool> <0>__ValidGroupName; public static PopupButtonCallback <1>__Pop; } private static readonly ConditionalWeakTable<StatusEffect, DamageSource> DamageSources = new ConditionalWeakTable<StatusEffect, DamageSource>(); private static HitData _incomingHit; private static StatusEffect _tickingEffect; private const string TeamReport = "PTR_TeamReport_4"; private const string TeamUpdate = "PTR_TeamUpdate_3"; private const string AbilityRequest = "PTR_AbilityRequest_3"; private const string AbilityEffect = "PTR_AbilityEffect_3"; private const string CooldownUpdate = "PTR_CooldownUpdate_3"; private const string KillReport = "PTR_KillReport_3"; private const string HealEffect = "PTR_HealEffect_3"; private static readonly Dictionary<(string Account, long Profile), long> Cooldowns = new Dictionary<(string, long), long>(); private static readonly Dictionary<long, long> TeamProfiles = new Dictionary<long, long>(); private static readonly HashSet<ZDOID> RewardedKills = new HashSet<ZDOID>(); private static int _session; internal const int CloudDurationSeconds = 10; private const string GroupRequest = "PTR_GroupRequest_1"; private const string GroupReply = "PTR_GroupReply_1"; private const string GroupTags = "PTR_GroupTags_1"; private const int CreateGroup = 1; private const int SearchGroups = 2; private const int JoinGroup = 3; private const int LeaveGroup = 4; private static GroupFile _groups; private static string _groupsPath; private static readonly Dictionary<long, string> GroupNames = new Dictionary<long, string>(); private static string _ownGroup; private static bool _groupLeader; private static YesNoPopup _groupMenuPopup; private static GameObject _groupRows; internal static Plugin Instance; internal static ConfigEntry<KeyCode> AbilityKey; internal static ConfigEntry<float> PoisonDamage; internal static readonly Dictionary<long, Team> RemoteTeams = new Dictionary<long, Team>(); private Sprite[] _mapIcons; private readonly Dictionary<Image, Color> _localMarkerColors = new Dictionary<Image, Color>(); private bool _cloudEffectWarningIssued; private SoftReference<GameObject> _blobEffect = new SoftReference<GameObject>(new AssetID(3415906257u, 1427547377u, 2829533878u, 248755859u)); private bool _blobEffectLoaded; private readonly Harmony _harmony = new Harmony("com.perfectmods.perfectteamsroulette"); private RouletteUI _ui; private Player _lastPlayer; private ZDOID _rosterCharacter; private float _spawnAt; private readonly SpawnGate _spawnGate = new SpawnGate(); private Player _spawnPlayer; private bool _spawnWaitLogged; private float _nextTempleCheck; private float _nextTeamEffectCheck; private float _nextBroadcast; private float _nextClean; private float _wolfBuffEnd; private float _draugrGuardEnd; private long _worldId; private static readonly FieldInfo PlayerPinsField = AccessTools.Field(typeof(Minimap), "m_playerPins"); private static readonly FieldInfo PlayerInfosField = AccessTools.Field(typeof(Minimap), "m_tempPlayerInfo"); private static readonly FieldInfo AllPinsField = AccessTools.Field(typeof(Minimap), "m_pins"); private static readonly FieldInfo PinUpdateField = AccessTools.Field(typeof(Minimap), "m_pinUpdateRequired"); private bool _mapWarningIssued; private const string RollRequest = "PTR_Roll_4"; private const string RosterResult = "PTR_RosterResult_4"; private static readonly Dictionary<string, Team> Roster = new Dictionary<string, Team>(StringComparer.Ordinal); private static string _rosterPath; internal bool MenuVisible { get { if ((Object)(object)_ui != (Object)null) { return _ui.IsOpen; } return false; } } internal static bool IsSpinning { get { if ((Object)(object)Instance != (Object)null) { return Instance.MenuVisible; } return false; } } internal static Team LocalTeam { get { if (!((Object)(object)Player.m_localPlayer != (Object)null)) { return Team.None; } return GetTeam(Player.m_localPlayer); } } private static void EndIncomingDamage(HitData __state) { _incomingHit = __state; } private static void TrackPoison(SE_Poison __instance, float __0, float ___m_damageLeft) { if (__0 >= ___m_damageLeft) { RecordDamageSource((StatusEffect)(object)__instance); } } private static void TrackBurning(SE_Burning __instance, bool __result) { if (__result) { RecordDamageSource((StatusEffect)(object)__instance); } } private static void RecordDamageSource(StatusEffect effect) { //IL_001b: 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) //IL_0020: Unknown result type (might be due to invalid IL or missing references) DamageSources.GetOrCreateValue(effect).Attacker = _incomingHit?.m_attacker ?? ZDOID.None; } private static void BeginDamageTick(StatusEffect __instance, out StatusEffect __state) { __state = _tickingEffect; _tickingEffect = __instance; } private static void EndDamageTick(StatusEffect __state) { _tickingEffect = __state; } private static void BeforeAppliedDamage(Character __instance, HitData hit, out float __state) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Invalid comparison between Unknown and I4 //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Invalid comparison between Unknown and I4 //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) __state = (__instance.IsOwner() ? __instance.GetHealth() : 0f); if (!(__state <= 0f) && hit != null) { Player val = (Player)(object)((__instance is Player) ? __instance : null); if (val != null && GetTeam(val) == Team.Slimes) { hit.m_damage.m_poison = 0f; } if (!hit.HaveAttacker() && (Object)(object)_tickingEffect != (Object)null && ((int)hit.m_hitType == 7 || (int)hit.m_hitType == 5) && DamageSources.TryGetValue(_tickingEffect, out var value)) { hit.m_attacker = value.Attacker; } } } private static void AfterAppliedDamage(Character __instance, HitData hit, float __state) { //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) if (!(__state <= 0f) && hit != null && hit.HaveAttacker() && !(__instance.GetHealth() > 0f) && RemoteTeams.TryGetValue(((ZDOID)(ref hit.m_attacker)).UserID, out var value) && value == Team.Draugr) { Instance?.ReportKill(__instance.GetZDOID(), hit.m_attacker); } } private static void ResetSession() { //IL_0060: 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) _session++; RemoteTeams.Clear(); _groups = null; _groupsPath = null; GroupNames.Clear(); _ownGroup = null; _groupLeader = false; _groupMenuPopup = null; _rosterPath = null; Roster.Clear(); if ((Object)(object)Instance != (Object)null) { Instance._rosterCharacter = ZDOID.None; } Cooldowns.Clear(); TeamProfiles.Clear(); RewardedKills.Clear(); TeamCommands.Reset(); RequestMapRefresh(); } private static void PeerDisconnected(ZNetPeer __0) { if (ZNet.instance.IsServer()) { TeamProfiles.Remove(__0.m_uid); SendGroupTags(); if (RemoteTeams.Remove(__0.m_uid)) { RequestMapRefresh(); SendTeamUpdate(__0.m_uid, Team.None); } TeamCommands.PeerDisconnected(__0); } else { ResetSession(); } } private static void RegisterGameplayPeer(ZNetPeer peer) { //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Expected O, but got Unknown if (ZNet.instance.IsServer()) { float nextMapSnapshot = 0f; string syncedGroupAccount = null; peer.m_rpc.Register<long>("PTR_TeamReport_4", (Action<ZRpc, long>)delegate(ZRpc rpc, long cooldown) { //IL_013d: Unknown result type (might be due to invalid IL or missing references) if (peer.IsReady()) { if (Time.unscaledTime >= nextMapSnapshot) { nextMapSnapshot = Time.unscaledTime + 5f; foreach (KeyValuePair<long, Team> remoteTeam in RemoteTeams) { rpc.Invoke("PTR_TeamUpdate_3", new object[2] { remoteTeam.Key, (int)remoteTeam.Value }); } } if (TryCharacter(peer.m_uid, out var id, out var zdo) && LoadRoster()) { string text = GroupAccount(peer.m_uid); if (text != null && text != syncedGroupAccount && SendGroupTags()) { syncedGroupAccount = text; } string text2 = Account(peer.m_uid); if (!string.IsNullOrEmpty(text2)) { Roster.TryGetValue(text2, out var value); SyncRosterTeam(peer.m_uid, zdo, value); SendRosterResult(peer.m_uid, id, value, roll: false); (string, long) key = (text2, zdo.GetLong(ZDOVars.s_playerID, 0L)); long num = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); if (key.Item2 != 0L && cooldown > num && cooldown <= num + 1200) { Cooldowns.TryGetValue(key, out var value2); Cooldowns[key] = Math.Max(value2, cooldown); } } } } }); peer.m_rpc.Register<ZDOID>("PTR_Roll_4", (Action<ZRpc, ZDOID>)delegate(ZRpc rpc, ZDOID id) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) ResolveRoll(peer.m_uid, id); }); peer.m_rpc.Register("PTR_AbilityRequest_3", (Method)delegate { Instance?.ActivateAbility(peer.m_uid); }); peer.m_rpc.Register<ZDOID, ZDOID>("PTR_KillReport_3", (Action<ZRpc, ZDOID, ZDOID>)delegate(ZRpc rpc, ZDOID victim, ZDOID attacker) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) Instance?.AcceptKill(peer.m_uid, victim, attacker); }); return; } peer.m_rpc.Register<ZDOID, int, bool>("PTR_RosterResult_4", (Action<ZRpc, ZDOID, int, bool>)delegate(ZRpc rpc, ZDOID id, int team, bool roll) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) if (rpc == ZNet.instance.GetServerRPC()) { ReceiveRosterResult(id, (Team)team, roll); } }); peer.m_rpc.Register<long, int>("PTR_TeamUpdate_3", (Action<ZRpc, long, int>)delegate(ZRpc rpc, long uid, int value) { if (rpc == ZNet.instance.GetServerRPC()) { UpdateRemoteTeam(uid, (Team)value); } }); peer.m_rpc.Register<int, ZDOID, Vector3, float>("PTR_AbilityEffect_3", (Method<int, ZDOID, Vector3, float>)delegate(ZRpc rpc, int team, ZDOID caster, Vector3 position, float damage) { //IL_0018: 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) if (rpc == ZNet.instance.GetServerRPC()) { Instance?.PlayAbility((Team)team, caster, position, damage); } }); peer.m_rpc.Register<long, bool>("PTR_CooldownUpdate_3", (Action<ZRpc, long, bool>)delegate(ZRpc rpc, long until, bool notify) { if (rpc == ZNet.instance.GetServerRPC()) { StoreCooldown(until, notify); } }); peer.m_rpc.Register<ZDOID>("PTR_HealEffect_3", (Action<ZRpc, ZDOID>)delegate(ZRpc rpc, ZDOID killer) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) if (rpc == ZNet.instance.GetServerRPC()) { HealKiller(killer); } }); } private static void UpdateRemoteTeam(long uid, Team team) { Team value; if (team == Team.None) { if (RemoteTeams.Remove(uid)) { RequestMapRefresh(); } } else if (!RemoteTeams.TryGetValue(uid, out value) || value != team) { RemoteTeams[uid] = team; RequestMapRefresh(); } } internal static bool PublishAssignment(long uid, ZDOID character, Team team) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) if (!TryCharacter(uid, out var id, out var zdo) || id != character || !SaveAssignment(Account(uid), team)) { return false; } SyncRosterTeam(uid, zdo, team); return true; } private static void PublishTeam(long uid, Team team) { UpdateRemoteTeam(uid, team); SendTeamUpdate(uid, team); } private static void SendTeamUpdate(long uid, Team team) { foreach (ZNetPeer peer in ZNet.instance.GetPeers()) { if (peer.IsReady()) { peer.m_rpc.Invoke("PTR_TeamUpdate_3", new object[2] { uid, (int)team }); } } } private void BroadcastTeam() { //IL_005b: Unknown result type (might be due to invalid IL or missing references) ZNet instance = ZNet.instance; if ((Object)(object)instance == (Object)null) { return; } if (instance.IsServer()) { long uID = ZNet.GetUID(); if (TryCharacter(uID, out var id, out var zdo) && LoadRoster()) { string text = Account(uID); if (!string.IsNullOrEmpty(text)) { Roster.TryGetValue(text, out var value); SyncRosterTeam(uID, zdo, value); ReceiveRosterResult(id, value, roll: false); } } } else { ZRpc serverRPC = instance.GetServerRPC(); if (serverRPC != null) { serverRPC.Invoke("PTR_TeamReport_4", new object[1] { ReadCooldown() }); } } } private static bool TryCharacter(long uid, out ZDOID id, out ZDO zdo) { //IL_003d: 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_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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) ZNet instance = ZNet.instance; ZNetPeer val = ((uid == ZNet.GetUID()) ? null : instance.GetPeer(uid)); id = ((uid == ZNet.GetUID()) ? instance.LocalPlayerCharacterID : ((val != null && val.IsReady()) ? val.m_characterID : ZDOID.None)); object obj; if (!((ZDOID)(ref id)).IsNone()) { ZDOMan instance2 = ZDOMan.instance; obj = ((instance2 != null) ? instance2.GetZDO(id) : null); } else { obj = null; } zdo = (ZDO)obj; if (zdo != null) { return zdo.GetOwner() == uid; } return false; } private static float ReadHealth(ZDO character) { return character.GetFloat(ZDOVars.s_health, character.GetFloat(ZDOVars.s_maxHealth, 1f)); } private static long ReadCooldown() { string text = CooldownKey(); Player localPlayer = Player.m_localPlayer; if (text == null || !((Object)(object)localPlayer != (Object)null) || !localPlayer.m_customData.TryGetValue(text, out var value) || !long.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result)) { return 0L; } return result; } private static void StoreCooldown(long until, bool notify = true) { Player localPlayer = Player.m_localPlayer; string text = CooldownKey(); if (!((Object)(object)localPlayer == (Object)null) && text != null) { localPlayer.m_customData[text] = until.ToString(CultureInfo.InvariantCulture); long num = until - DateTimeOffset.UtcNow.ToUnixTimeSeconds(); if (notify && num > 0) { ((Character)localPlayer).Message((MessageType)2, "Способность: осталось " + num / 60 + " мин " + num % 60 + " сек", 0, (Sprite)null, false); } } } private void UseAbility() { ZNet instance = ZNet.instance; if ((Object)(object)instance == (Object)null) { return; } if (instance.IsServer()) { ActivateAbility(ZNet.GetUID()); return; } ZRpc serverRPC = instance.GetServerRPC(); if (serverRPC != null) { serverRPC.Invoke("PTR_AbilityRequest_3", Array.Empty<object>()); } } private void ActivateAbility(long uid) { //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_016e: 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) //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) ZNet instance = ZNet.instance; if ((Object)(object)instance == (Object)null || !instance.IsServer() || !TryCharacter(uid, out var id, out var zdo) || ReadHealth(zdo) <= 0f || !RemoteTeams.TryGetValue(uid, out var value)) { return; } long num = zdo.GetLong(ZDOVars.s_playerID, 0L); if (num == 0L || (uid != ZNet.GetUID() && (!TeamProfiles.TryGetValue(uid, out var value2) || value2 != num))) { return; } (string, long) key = ((uid == ZNet.GetUID()) ? string.Empty : instance.GetPeer(uid).m_socket.GetHostName(), num); Cooldowns.TryGetValue(key, out var value3); long num2 = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); if (uid == ZNet.GetUID()) { value3 = Math.Max(value3, Math.Min(ReadCooldown(), num2 + 1200)); } if (value3 > num2) { if (uid == ZNet.GetUID()) { StoreCooldown(value3); return; } ZNetPeer peer = instance.GetPeer(uid); if (peer != null) { peer.m_rpc.Invoke("PTR_CooldownUpdate_3", new object[2] { value3, true }); } return; } value3 = num2 + 1200; Cooldowns[key] = value3; Vector3 val = ((uid == ZNet.GetUID() && (Object)(object)Player.m_localPlayer != (Object)null) ? ((Component)Player.m_localPlayer).transform.position : zdo.GetPosition()); float num3 = PoisonDamage.Value; if (float.IsNaN(num3) || float.IsInfinity(num3) || num3 < 0f) { num3 = 0f; } foreach (ZNetPeer peer3 in instance.GetPeers()) { if (peer3.IsReady() && (value != Team.Draugr || peer3.m_uid == uid)) { peer3.m_rpc.Invoke("PTR_AbilityEffect_3", new object[4] { (int)value, id, val, num3 }); } } PlayAbility(value, id, val, num3); if (uid == ZNet.GetUID()) { string text = CooldownKey(); if (text != null) { Player.m_localPlayer.m_customData[text] = value3.ToString(CultureInfo.InvariantCulture); } return; } ZNetPeer peer2 = instance.GetPeer(uid); if (peer2 != null) { peer2.m_rpc.Invoke("PTR_CooldownUpdate_3", new object[2] { value3, false }); } } private void PlayAbility(Team team, ZDOID caster, Vector3 center, float damage) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; bool flag = (Object)(object)localPlayer != (Object)null && ((Character)localPlayer).GetZDOID() == caster; if (team == Team.Slimes) { if (flag) { TeamEffects.Ability(localPlayer, team); } ((MonoBehaviour)this).StartCoroutine(CloudDamage(caster, center, damage, _session)); } else if ((Object)(object)localPlayer != (Object)null && !((Character)localPlayer).IsDead() && LocalTeam == team) { if (team == Team.Wolves && (flag || Vector3.Distance(((Component)localPlayer).transform.position, center) <= 20f)) { _wolfBuffEnd = Time.time + 12f; TeamEffects.Ability(localPlayer, team); } else if (team == Team.Draugr && flag) { _draugrGuardEnd = Time.time + 10f; TeamEffects.Ability(localPlayer, team); } } } private IEnumerator CloudDamage(ZDOID caster, Vector3 center, float damage, int session) { //IL_000e: 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_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) DamageModifier val5 = default(DamageModifier); for (int second = 0; second < 10; second++) { if (session != _session) { break; } ZDOMan instance = ZDOMan.instance; ZDO val = ((instance != null) ? instance.GetZDO(caster) : null); if ((val != null && ReadHealth(val) <= 0f) || (RemoteTeams.TryGetValue(((ZDOID)(ref caster)).UserID, out var value) && value != Team.Slimes)) { break; } CloudVisual(center); Character[] array = Character.GetAllCharacters().ToArray(); foreach (Character val2 in array) { if (damage <= 0f || (Object)(object)val2 == (Object)null || !val2.IsOwner() || val2.IsDead() || val2.GetZDOID() == caster || Vector3.Distance(((Component)val2).transform.position, center) > 5f) { continue; } Player val3 = (Player)(object)((val2 is Player) ? val2 : null); if (val3 == null || (GetTeam(val3) != Team.Slimes && ((Character)val3).IsPVPEnabled())) { HitData val4 = new HitData(); val4.m_attacker = caster; val4.m_point = val2.GetCenterPoint(); val4.m_damage.m_poison = damage; val4.m_hitType = (HitType)7; val4.ApplyResistance(val2.GetDamageModifiers((WeakSpot)null), ref val5); if (val2 is Player) { val4.ApplyArmor(val2.GetBodyArmor()); } else if (Game.m_worldLevel > 0) { val4.ApplyArmor((float)(Game.m_worldLevel * Game.instance.m_worldLevelEnemyBaseAC)); } val2.ApplyDamage(val4, true, false, val5); } } yield return (object)new WaitForSeconds(1f); } } private void ReportKill(ZDOID victim, ZDOID attacker) { //IL_001e: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) ZNet instance = ZNet.instance; if ((Object)(object)instance == (Object)null) { return; } if (instance.IsServer()) { AcceptKill(ZNet.GetUID(), victim, attacker); return; } ZRpc serverRPC = instance.GetServerRPC(); if (serverRPC != null) { serverRPC.Invoke("PTR_KillReport_3", new object[2] { victim, attacker }); } } private void AcceptKill(long reporter, ZDOID victim, ZDOID attacker) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: 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) if (((ZDOID)(ref victim)).IsNone() || ((ZDOID)(ref attacker)).IsNone() || victim == attacker || RewardedKills.Contains(victim)) { return; } ZDOMan instance = ZDOMan.instance; ZDO val = ((instance != null) ? instance.GetZDO(victim) : null); if (val != null && val.GetOwner() == reporter && TryCharacter(((ZDOID)(ref attacker)).UserID, out var id, out var _) && !(id != attacker) && RemoteTeams.TryGetValue(((ZDOID)(ref attacker)).UserID, out var value) && value == Team.Draugr) { if (val.GetFloat(ZDOVars.s_health, 1f) <= 0f) { RewardKill(victim, attacker); } else { ((MonoBehaviour)this).StartCoroutine(ConfirmKill(victim, attacker, reporter, _session)); } } } private IEnumerator ConfirmKill(ZDOID victim, ZDOID attacker, long reporter, int session) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000e: 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) for (int i = 0; i < 10; i++) { if (session != _session) { break; } yield return (object)new WaitForSecondsRealtime(0.2f); ZDOMan instance = ZDOMan.instance; ZDO val = ((instance != null) ? instance.GetZDO(victim) : null); if (val == null || val.GetOwner() != reporter) { break; } if (!(val.GetFloat(ZDOVars.s_health, 1f) > 0f)) { RewardKill(victim, attacker); break; } } } private static void RewardKill(ZDOID victim, ZDOID attacker) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0039: 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_007f: Unknown result type (might be due to invalid IL or missing references) if (!TryCharacter(((ZDOID)(ref attacker)).UserID, out var id, out var _) || id != attacker || !RemoteTeams.TryGetValue(((ZDOID)(ref attacker)).UserID, out var value) || value != Team.Draugr || !RewardedKills.Add(victim)) { return; } if (((ZDOID)(ref attacker)).UserID == ZNet.GetUID()) { HealKiller(attacker); return; } ZNetPeer peer = ZNet.instance.GetPeer(((ZDOID)(ref attacker)).UserID); if (peer != null) { peer.m_rpc.Invoke("PTR_HealEffect_3", new object[1] { attacker }); } } private static void HealKiller(ZDOID attacker) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && ((Character)localPlayer).GetZDOID() == attacker && !((Character)localPlayer).IsDead() && LocalTeam == Team.Draugr) { ((Character)localPlayer).Heal(10f, true); } } private static bool LoadGroups() { if (!TryGetWorldId(out var id)) { return false; } string text = Path.Combine(Paths.ConfigPath, "TeamsRoulette", id + ".groups.json"); if (_groupsPath == text && _groups != null) { return true; } try { _groups = (File.Exists(text) ? JsonUtility.FromJson<GroupFile>(File.ReadAllText(text)) : new GroupFile()); _groupsPath = text; return _groups?.Groups != null; } catch (Exception ex) { Instance.LogWarning("Groups load failed: " + ex.Message); return false; } } private static bool SaveGroups() { string text = _groupsPath + ".tmp"; try { Directory.CreateDirectory(Path.GetDirectoryName(_groupsPath)); File.WriteAllText(text, JsonUtility.ToJson((object)_groups, true)); if (File.Exists(_groupsPath)) { File.Replace(text, _groupsPath, null); } else { File.Move(text, _groupsPath); } return true; } catch (Exception ex) { _groups = null; Instance.LogWarning("Groups save failed: " + ex.Message); return false; } } private static void RegisterGroupPeer(ZNetPeer peer) { if (ZNet.instance.IsServer()) { peer.m_rpc.Register<int, string>("PTR_GroupRequest_1", (Action<ZRpc, int, string>)delegate(ZRpc rpc, int action, string value) { if (peer.IsReady()) { HandleGroupRequest(peer.m_uid, action, value); } }); return; } peer.m_rpc.Register<int, string>("PTR_GroupReply_1", (Action<ZRpc, int, string>)delegate(ZRpc rpc, int action, string value) { if (rpc == ZNet.instance.GetServerRPC()) { ShowGroupReply(action, value); } }); peer.m_rpc.Register<string>("PTR_GroupTags_1", (Action<ZRpc, string>)delegate(ZRpc rpc, string tags) { if (rpc == ZNet.instance.GetServerRPC()) { ReadGroupTags(tags); } }); } private unsafe static string GroupAccount(long uid) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: 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) //IL_0057: 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_0066: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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_0084: 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) if (!TryCharacter(uid, out var id, out var zdo)) { return null; } if (uid == ZNet.GetUID()) { PlatformUserID userId = UserInfo.GetLocalUser().UserId; if (((PlatformUserID)(ref userId)).IsValid) { return ((object)(*(PlatformUserID*)(&userId))/*cast due to .constrained prefix*/).ToString(); } } else { foreach (PlayerInfo player in ZNet.instance.GetPlayerList()) { if (player.m_characterID == id) { PlatformUserID id2 = player.m_userInfo.m_id; if (((PlatformUserID)(ref id2)).IsValid) { id2 = player.m_userInfo.m_id; return ((object)(*(PlatformUserID*)(&id2))/*cast due to .constrained prefix*/).ToString(); } } } } long num = zdo.GetLong(ZDOVars.s_playerID, 0L); if (num != 0L) { return "profile:" + num.ToString(CultureInfo.InvariantCulture); } return null; } private static void MigrateSteamGroupKey(string account) { if (!account.StartsWith("Steam_", StringComparison.Ordinal)) { return; } string text = account.Substring("Steam_".Length); if (!ulong.TryParse(text, out var _) || FindGroup(account) != null) { return; } Group obj = FindGroup(text); if (obj != null) { obj.Members[obj.Members.IndexOf(text)] = account; if (obj.Leader == text) { obj.Leader = account; } SaveGroups(); } } private static Group FindGroup(string account) { return _groups.Groups.Find((Group group) => group.Members.Contains(account)); } private static bool SendGroupTags() { if (!LoadGroups()) { return false; } ZNet instance = ZNet.instance; List<string> list = new List<string>(); foreach (long item in (from peer in instance.GetPeers() where peer.IsReady() select peer.m_uid).Append(ZNet.GetUID())) { string text = GroupAccount(item); if (text != null) { MigrateSteamGroupKey(text); if (!LoadGroups()) { return false; } Group obj = FindGroup(text); if (obj != null) { list.Add(item + "\t" + obj.Name + "\t" + ((obj.Leader == text) ? "1" : "0")); } } } string text2 = string.Join("\n", list); ReadGroupTags(text2); foreach (ZNetPeer peer in instance.GetPeers()) { if (peer.IsReady()) { peer.m_rpc.Invoke("PTR_GroupTags_1", new object[1] { text2 }); } } return true; } private static void ReadGroupTags(string payload) { GroupNames.Clear(); _ownGroup = null; _groupLeader = false; string[] array = payload.Split('\n'); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split('\t'); if (array2.Length == 3 && long.TryParse(array2[0], out var result)) { GroupNames[result] = array2[1]; if (result == ZNet.GetUID()) { _ownGroup = array2[1]; _groupLeader = array2[2] == "1"; } } } } private static bool ValidGroupName(string value) { string text = value?.Trim(); if (!string.IsNullOrEmpty(text) && text.Length <= 32) { return text.All((char c) => char.IsLetterOrDigit(c) || c == ' ' || c == '-' || c == '_'); } return false; } private static void HandleGroupRequest(long uid, int action, string value) { string text = GroupAccount(uid); string text2 = ((text == null && action != 2) ? "Данные персонажа ещё загружаются. Повтори попытку." : ChangeGroup(text, action, value)); int num = ((action == 2) ? 2 : 0); if (uid == ZNet.GetUID()) { ShowGroupReply(num, text2); return; } ZNetPeer peer = ZNet.instance.GetPeer(uid); if (peer != null) { peer.m_rpc.Invoke("PTR_GroupReply_1", new object[2] { num, text2 }); } } private static string ChangeGroup(string account, int action, string value) { if (!LoadGroups()) { if (action != 2) { return "Список команд недоступен."; } return ""; } string name = (value ?? "").Trim(); if (action == 2) { return string.Join("\n", _groups.Groups.Select((Group group) => group.Name).OrderBy<string, string>((string groupName) => groupName, StringComparer.OrdinalIgnoreCase)); } MigrateSteamGroupKey(account); if (!LoadGroups()) { return "Список команд недоступен."; } Group obj = FindGroup(account); if (action == 3 && obj != null && string.Equals(obj.Name, name, StringComparison.OrdinalIgnoreCase)) { SendGroupTags(); return "Ты уже в этой команде."; } if (action == 4) { if (obj == null) { return "Ты ещё не в команде."; } obj.Members.Remove(account); if (obj.Members.Count == 0) { _groups.Groups.Remove(obj); } else if (obj.Leader == account) { obj.Leader = obj.Members[0]; } } else { if (obj != null) { return "Сначала выйди из текущей команды."; } if (!ValidGroupName(name)) { return "Введи название до 32 символов."; } Group obj2 = _groups.Groups.Find((Group group) => string.Equals(group.Name, name, StringComparison.OrdinalIgnoreCase)); if (action == 1) { if (obj2 != null) { return "Команда с таким названием уже есть."; } obj2 = new Group { Name = name, Leader = account }; _groups.Groups.Add(obj2); } else if (action != 3 || obj2 == null) { return "Команда не найдена."; } obj2.Members.Add(account); } if (!SaveGroups()) { return "Не удалось сохранить команды."; } SendGroupTags(); return action switch { 1 => "Команда создана.", 4 => "Ты вышел из команды.", _ => "Ты вступил в команду.", }; } private static void RequestGroup(int action, string value = "") { ZNet instance = ZNet.instance; if ((Object)(object)instance == (Object)null) { return; } if (instance.IsServer()) { HandleGroupRequest(ZNet.GetUID(), action, value); return; } ZRpc serverRPC = instance.GetServerRPC(); if (serverRPC != null) { serverRPC.Invoke("PTR_GroupRequest_1", new object[2] { action, value }); } } private static void OpenGroupMenu() { if (!UnifiedPopup.IsAvailable() || UnifiedPopup.IsVisible()) { return; } if (_ownGroup != null) { Choice(_ownGroup, (_groupLeader ? "Ты лидер команды. " : "") + "Выйти из команды?", delegate { RequestGroup(4); }, delegate { }); return; } Choice("Команды", "Создай свою команду или найди команду других игроков.", delegate { Entry("Создать команду", "Введи название команды.", ValidGroupName, delegate(string name) { RequestGroup(1, name); }); }, delegate { RequestGroup(2); }, useGroupLabels: true); } private static void Choice(string title, string body, Action yes, Action no, bool useGroupLabels = false) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_0035: Expected O, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown YesNoPopup val = new YesNoPopup(title, body, (PopupButtonCallback)delegate { _groupMenuPopup = null; UnifiedPopup.Pop(); yes(); }, (PopupButtonCallback)delegate { _groupMenuPopup = null; UnifiedPopup.Pop(); no(); }, false, false); if (useGroupLabels) { _groupMenuPopup = val; } UnifiedPopup.Push((PopupBase)(object)val); } private static void LabelGroupMenu(YesNoPopup popup, TMP_Text ___buttonRightText, TMP_Text ___buttonLeftText) { if (popup == _groupMenuPopup) { ___buttonRightText.text = "Создать команду"; ___buttonLeftText.text = "Поиск команд"; } } private static void Entry(string title, string body, Func<string, bool> valid, Action<string> submit) { //IL_003d: 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) //IL_0054: Expected O, but got Unknown //IL_0054: Expected O, but got Unknown //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown object obj = <>O.<1>__Pop; if (obj == null) { PopupButtonCallback val = UnifiedPopup.Pop; <>O.<1>__Pop = val; obj = (object)val; } UnifiedPopup.Push((PopupBase)new TextEntryPopup(title, body, "", (PopupButtonCallback)obj, (ValidateTextEntry)((string value) => valid(value)), (RetrieveTextEntryResult)delegate(string value) { if (valid(value)) { UnifiedPopup.Pop(); submit(value); } }, false)); } private static void ShowGroupReply(int action, string text) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown if ((Object)(object)Player.m_localPlayer == (Object)null || !UnifiedPopup.IsAvailable()) { return; } if (action == 2 && !string.IsNullOrEmpty(text)) { ShowGroupList(text.Split('\n')); return; } string obj = ((action == 2) ? "Команды не найдены." : text); object obj2 = <>O.<1>__Pop; if (obj2 == null) { PopupButtonCallback val = UnifiedPopup.Pop; <>O.<1>__Pop = val; obj2 = (object)val; } UnifiedPopup.Push((PopupBase)new WarningPopup("Команды", obj, (PopupButtonCallback)obj2, false)); } private static void ShowGroupList(string[] names) { UnifiedPopup.Push((PopupBase)(object)new GroupListPopup(names, 0)); } private static void ClearGroupRows() { if (!((Object)(object)_groupRows == (Object)null)) { _groupRows.SetActive(false); Object.Destroy((Object)(object)_groupRows); _groupRows = null; } } private static void ConfigureGroupList(WarningPopup popup, Button ___buttonCenter, TMP_Text ___bodyText) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown //IL_006d: 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_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Expected O, but got Unknown //IL_0119: 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_0131: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Expected O, but got Unknown //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_02ab: Expected O, but got Unknown //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Expected O, but got Unknown GroupListPopup list = popup as GroupListPopup; if (list == null) { return; } _groupRows = new GameObject("PTR_GroupRows", new Type[1] { typeof(RectTransform) }); RectTransform val = (RectTransform)_groupRows.transform; ((Transform)val).SetParent((Transform)(object)___bodyText.rectTransform, false); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 1f); val.anchorMax = val2; val.anchorMin = val2; val.pivot = new Vector2(0.5f, 1f); val.anchoredPosition = Vector2.zero; val.sizeDelta = new Vector2(250f, 128f); string[] array = list.Names.Skip(list.Offset).Take(3).ToArray(); for (int i = 0; i < array.Length; i++) { string name = array[i]; Button obj = Object.Instantiate<Button>(___buttonCenter, (Transform)(object)val, false); RectTransform val3 = (RectTransform)((Component)obj).transform; ((Vector2)(ref val2))..ctor(0.5f, 1f); val3.anchorMax = val2; val3.anchorMin = val2; val3.pivot = new Vector2(0.5f, 1f); val3.anchoredPosition = new Vector2(0f, (float)(-i) * 35f); val3.sizeDelta = new Vector2(242f, 30f); TextMeshProUGUI componentInChildren = ((Component)obj).GetComponentInChildren<TextMeshProUGUI>(true); RectTransform rectTransform = ((TMP_Text)componentInChildren).rectTransform; ((Transform)rectTransform).SetParent((Transform)(object)val3, false); ((Transform)rectTransform).SetAsLastSibling(); rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.one; rectTransform.offsetMin = new Vector2(10f, 2f); rectTransform.offsetMax = new Vector2(-10f, -2f); ((Transform)rectTransform).localScale = Vector3.one; ((Transform)rectTransform).localRotation = Quaternion.identity; ((TMP_Text)componentInChildren).font = ___bodyText.font; ((TMP_Text)componentInChildren).fontSharedMaterial = ___bodyText.fontSharedMaterial; ((Graphic)componentInChildren).color = Color.white; componentInChildren.canvasRenderer.SetAlpha(1f); ((TMP_Text)componentInChildren).alignment = (TextAlignmentOptions)514; ((TMP_Text)componentInChildren).margin = Vector4.zero; ((TMP_Text)componentInChildren).richText = false; ((Graphic)componentInChildren).raycastTarget = false; ((TMP_Text)componentInChildren).enableWordWrapping = false; ((TMP_Text)componentInChildren).overflowMode = (TextOverflowModes)1; ((TMP_Text)componentInChildren).fontSize = 18f; ((TMP_Text)componentInChildren).fontSizeMin = 11f; ((TMP_Text)componentInChildren).fontSizeMax = 18f; ((TMP_Text)componentInChildren).enableAutoSizing = true; ((TMP_Text)componentInChildren).text = name; ((Behaviour)componentInChildren).enabled = true; ((Component)componentInChildren).gameObject.SetActive(true); obj.onClick = new ButtonClickedEvent(); ((UnityEvent)obj.onClick).AddListener((UnityAction)delegate { UnifiedPopup.Pop(); RequestGroup(3, name); }); } if (list.Offset + 3 < list.Names.Length) { ((Component)___buttonCenter).GetComponentInChildren<TMP_Text>().text = "Далее"; ((UnityEventBase)___buttonCenter.onClick).RemoveAllListeners(); ((UnityEvent)___buttonCenter.onClick).AddListener((UnityAction)delegate { UnifiedPopup.Pop(); UnifiedPopup.Push((PopupBase)(object)new GroupListPopup(list.Names, list.Offset + 3)); }); } else { ((Component)___buttonCenter).GetComponentInChildren<TMP_Text>().text = "Закрыть"; } } private static void AddGroupToHoverName(Player __instance, ref string __result) { //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) Dictionary<long, string> groupNames = GroupNames; ZDOID zDOID = ((Character)__instance).GetZDOID(); if (groupNames.TryGetValue(((ZDOID)(ref zDOID)).UserID, out var value)) { __result = __result + "\n<color=#FFFFFF><size=50%>" + value + "</size></color>"; } } internal Sprite TeamIcon(Team team) { if (!((Object)(object)_ui != (Object)null)) { return null; } return _ui.GetTeamIcon(team); } internal void LogWarning(string text) { ((BaseUnityPlugin)this).Logger.LogWarning((object)text); } internal static Color TeamColor(Team team) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_001d: 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) return (Color)(team switch { Team.Wolves => Color.white, Team.Slimes => new Color(0.34f, 0.94f, 0.36f), _ => new Color(0.93f, 0.21f, 0.19f), }); } internal static string TeamName(Team team) { return team switch { Team.Wolves => "ВОЛКИ", Team.Slimes => "СЛИЗНИ", _ => "ДРАУГРЫ", }; } private void Awake() { //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Invalid comparison between Unknown and I4 Instance = this; AbilityKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "AbilityKey", (KeyCode)96, "Клавиша способности: BackQuote = ` (Ё), F8 = F8. Личная настройка игрока; перезарядка 20 минут. None отключает клавишу."); AbilityKey.SettingChanged += delegate { TeamEffects.RefreshKeyDescriptions(); }; PoisonDamage = ((BaseUnityPlugin)this).Config.Bind<float>("Balance", "PoisonCloudDamagePerSecond", 5f, "Базовый урон ядом за один секундный тик облака, до учёта сопротивления и брони. Используется значение сервера."); _ui = ((Component)this).gameObject.AddComponent<RouletteUI>(); if ((int)SystemInfo.graphicsDeviceType != 4) { _mapIcons = (Sprite[])(object)new Sprite[3] { RouletteUI.ReadIcon("MapSlimes"), RouletteUI.ReadIcon("MapWolves"), RouletteUI.ReadIcon("MapDraugr") }; } InstallHooks(); TeamCommands.Register(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Teams Roulette 0.3.14 loaded"); } private void OnDestroy() { _harmony.UnpatchSelf(); if (_blobEffectLoaded) { _blobEffect.Release(); } if (_mapIcons != null) { Sprite[] mapIcons = _mapIcons; foreach (Sprite val in mapIcons) { if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val.texture); Object.Destroy((Object)(object)val); } } } if ((Object)(object)Instance == (Object)(object)this) { Instance = null; } } private void Hook(Type type, string name, string prefix = null, string postfix = null, Type firstParam = null, string finalizer = null, int priority = 400) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0096: 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) try { MethodInfo methodInfo = AccessTools.GetDeclaredMethods(type).FirstOrDefault((MethodInfo m) => m.Name == name && (firstParam == null || (m.GetParameters().Length != 0 && m.GetParameters()[0].ParameterType == firstParam))); if (methodInfo == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Hook not found: " + type.Name + "." + name)); return; } HarmonyMethod val = ((prefix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Plugin).GetMethod(prefix, BindingFlags.Static | BindingFlags.NonPublic))); HarmonyMethod val2 = ((postfix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Plugin).GetMethod(postfix, BindingFlags.Static | BindingFlags.NonPublic))); if (val2 != null) { val2.priority = priority; } HarmonyMethod val3 = ((finalizer == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Plugin).GetMethod(finalizer, BindingFlags.Static | BindingFlags.NonPublic))); _harmony.Patch((MethodBase)methodInfo, val, val2, (HarmonyMethod)null, val3, (HarmonyMethod)null); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Hook failed: " + type.Name + "." + name + ": " + ex.Message)); } } private void InstallHooks() { Hook(typeof(ZNet), "Awake", null, "ResetSession"); Hook(typeof(ZNet), "OnNewConnection", null, "RegisterTeamCommands", typeof(ZNetPeer)); Hook(typeof(ZNet), "Disconnect", null, "PeerDisconnected", typeof(ZNetPeer)); Hook(typeof(ObjectDB), "Awake", null, "ObjectDBReady"); Hook(typeof(ObjectDB), "CopyOtherDB", null, "ObjectDBReady"); Hook(typeof(UnifiedPopup), "ResetUI", "ClearGroupRows"); Hook(typeof(UnifiedPopup), "Hide", "ClearGroupRows"); Hook(typeof(UnifiedPopup), "ShowWarning", null, "ConfigureGroupList"); Hook(typeof(UnifiedPopup), "ShowYesNo", null, "LabelGroupMenu"); Hook(typeof(Player), "GetHoverName", null, "AddGroupToHoverName"); Hook(typeof(Player), "OnSpawned", null, "PlayerSpawned"); Hook(typeof(Player), "TakeInput", "TakeInput"); Hook(typeof(PlayerController), "TakeInput", "ControllerTakeInput"); Hook(typeof(Player), "SetMouseLook", "BlockMouseLook"); Hook(typeof(Player), "PlayerAttackInput", "BlockAttackInput"); Hook(typeof(GameCamera), "UpdateMouseCapture", "BlockCamera"); Hook(typeof(Minimap), "UpdatePins", null, "UpdatePlayerPins", null, null, 0); Hook(typeof(Minimap), "Start", null, "MapStart", null, null, 0); Hook(typeof(Skills), "RaiseSkill", "RaiseSkill"); Hook(typeof(Skills), "GetSkillLevel", null, "GetSkillLevel"); Hook(typeof(Player), "GetRunSpeedFactor", null, "RunSpeed"); Hook(typeof(SEMan), "ApplyStatusEffectSpeedMods", null, "WolfSpeed"); Hook(typeof(SEMan), "AddStatusEffect", "BlockNegativeStatus", null, typeof(int)); Hook(typeof(SEMan), "ModifyRunStaminaDrain", null, "RunDrain"); Hook(typeof(SEMan), "ModifyHealthRegen", null, "FoodRegen"); Hook(typeof(SEMan), "ModifySwimStaminaUsage", null, "SwimDrain"); Hook(typeof(Character), "Jump", "JumpBefore", null, null, "JumpAfter"); Hook(typeof(Character), "Damage", "OutgoingDamage", null, typeof(HitData)); Hook(typeof(Character), "ApplyDamage", "BeforeAppliedDamage", "AfterAppliedDamage", typeof(HitData)); Hook(typeof(SE_Poison), "AddDamage", "TrackPoison"); Hook(typeof(SE_Burning), "AddFireDamage", null, "TrackBurning"); Hook(typeof(SE_Burning), "AddSpiritDamage", null, "TrackBurning"); Hook(typeof(SE_Poison), "UpdateStatusEffect", "BeginDamageTick", null, null, "EndDamageTick"); Hook(typeof(SE_Burning), "UpdateStatusEffect", "BeginDamageTick", null, null, "EndDamageTick"); Hook(typeof(Character), "RPC_Damage", "IncomingDamage", null, typeof(long), "EndIncomingDamage"); } private static void ObjectDBReady(ObjectDB __instance) { try { TeamEffects.Register(__instance); } catch (Exception ex) { Plugin instance = Instance; if (instance != null) { ((BaseUnityPlugin)instance).Logger.LogWarning((object)("Team effect registration failed: " + ex)); } } } private static bool TryGetTemplePosition(out Vector3 position) { //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) position = Vector3.zero; if ((Object)(object)ZoneSystem.instance == (Object)null || (Object)(object)ZNet.instance == (Object)null) { return false; } return ZoneSystem.instance.GetLocationIcon("StartTemple", ref position); } private static bool TryGetWorldId(out long id) { id = 0L; ZNet instance = ZNet.instance; if ((Object)(object)instance == (Object)null) { return false; } World world = instance.GetWorld(); if (world == null) { return false; } id = world.m_uid; return id != 0; } private static string WorldKey() { if (!TryGetWorldId(out var id)) { return null; } return "PerfectTeamsRoulette.team.v1." + id.ToString(CultureInfo.InvariantCulture); } private static string CooldownKey() { if (!TryGetWorldId(out var id)) { return null; } return "PerfectTeamsRoulette.cooldown.v1." + id.ToString(CultureInfo.InvariantCulture); } internal static Team GetTeam(Player player) { if ((Object)(object)player == (Object)null) { return Team.None; } if ((Object)(object)player == (Object)(object)Player.m_localPlayer) { string text = WorldKey(); if (text != null && player.m_customData != null && player.m_customData.TryGetValue(text, out var value) && int.TryParse(value, out var result) && result >= 1 && result <= 3) { return (Team)result; } return Team.None; } try { ZNetView component = ((Component)player).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid() && component.GetZDO() != null) { long userID = ((ZDOID)(ref component.GetZDO().m_uid)).UserID; if (RemoteTeams.TryGetValue(userID, out var value2)) { return value2; } } } catch { } return Team.None; } private static void RegisterTeamCommands(ZNetPeer __0) { TeamCommands.RegisterPeer(__0); RegisterGameplayPeer(__0); RegisterGroupPeer(__0); } internal bool SetLocalTeam(Team selected, bool replace = false, bool keepWheel = false) { Player localPlayer = Player.m_localPlayer; string text = WorldKey(); if ((Object)(object)localPlayer == (Object)null || text == null || localPlayer.m_customData == null || selected == Team.None) { return false; } Team team = GetTeam(localPlayer); if (team == selected) { return replace; } if (!replace && team != Team.None) { return false; } Dictionary<string, string> customData = localPlayer.m_customData; int num = (int)selected; customData[text] = num.ToString(CultureInfo.InvariantCulture); _spawnGate.Cancel(); if (replace) { if (!keepWheel && (Object)(object)_ui != (Object)null && _ui.IsOpen) { _ui.Close(); } _wolfBuffEnd = (_draugrGuardEnd = 0f); TeamEffects.ClearAbility(localPlayer, team); } TeamEffects.Ensure(localPlayer, selected); TintOwnMarker(); RequestMapRefresh(); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Selected team " + selected.ToString() + " for world " + WorldKey())); return true; } private void QueueSpawnCheck(Player player) { _spawnPlayer = player; _spawnGate.Start(); _spawnAt = Time.unscaledTime + 1f; _nextTempleCheck = 0f; _spawnWaitLogged = false; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Spawn check queued; waiting for world, intro completion and StartTemple data."); } private void CheckSpawn(Player player, bool worldReady) { //IL_004b: 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_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: 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_0085: 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_0091: Unknown result type (might be due to invalid IL or missing references) if (!_spawnGate.Pending || Time.unscaledTime < _spawnAt || Time.unscaledTime < _nextTempleCheck) { return; } _nextTempleCheck = Time.unscaledTime + 0.5f; bool flag = ((Character)player).InIntro() || ((Character)player).InCutscene(); Vector3 position = Vector3.zero; bool templeReady = worldReady && !flag && TryGetTemplePosition(out position); Vector3 position2 = ((Component)player).transform.position; SpawnDecision spawnDecision = _spawnGate.Evaluate(worldReady, flag, LocalTeam != Team.None, templeReady, position2.x, position2.z, position.x, position.z); if (spawnDecision == SpawnDecision.Waiting) { if (!_spawnWaitLogged) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Spawn check waiting: worldReady=" + worldReady + "; intro=" + flag + "; templeReady=" + templeReady)); _spawnWaitLogged = true; } } else { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Spawn check result: " + spawnDecision.ToString() + "; role=" + (ZNet.instance.IsServer() ? "host/server" : "client"))); if (spawnDecision == SpawnDecision.Open && (Object)(object)_ui != (Object)null) { _ui.Open(); } } } private void Update() { //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; long id; bool flag = TryGetWorldId(out id); bool flag2 = flag && _worldId != 0L && id != _worldId; if ((Object)(object)localPlayer != (Object)(object)_lastPlayer || flag2) { _lastPlayer = localPlayer; _nextBroadcast = 0f; _nextClean = 0f; _nextTeamEffectCheck = 0f; _wolfBuffEnd = (_draugrGuardEnd = 0f); RequestMapRefresh(); if ((Object)(object)_ui != (Object)null && _ui.IsOpen) { _ui.Close(); } if ((Object)(object)localPlayer == (Object)null) { _spawnGate.Cancel(); _spawnPlayer = null; } else if ((Object)(object)_spawnPlayer != (Object)(object)localPlayer || flag2) { QueueSpawnCheck(localPlayer); } } if (flag) { _worldId = id; } else if ((Object)(object)ZNet.instance == (Object)null) { _worldId = 0L; } TeamCommands.ExpireAssignments(); if ((Object)(object)localPlayer == (Object)null || !flag) { return; } if (Time.unscaledTime >= _nextBroadcast) { _nextBroadcast = Time.unscaledTime + 2f; BroadcastTeam(); TintOwnMarker(); } if (!MenuVisible && !((Character)localPlayer).IsDead() && Input.GetKeyDown((KeyCode)106) && !IsUiBlocking()) { OpenGroupMenu(); } if (((Character)localPlayer).IsDead() || _rosterCharacter != ((Character)localPlayer).GetZDOID()) { return; } CheckSpawn(localPlayer, flag); if (LocalTeam != Team.None && Time.unscaledTime >= _nextTeamEffectCheck) { _nextTeamEffectCheck = Time.unscaledTime + 1f; TeamEffects.Ensure(localPlayer, LocalTeam); } if (LocalTeam != Team.None) { if (Time.unscaledTime >= _nextClean) { _nextClean = Time.unscaledTime + 0.4f; CleanImmunities(); } if (!MenuVisible && (int)AbilityKey.Value != 0 && Input.GetKeyDown(AbilityKey.Value) && !((Character)localPlayer).IsDead() && !IsUiBlocking()) { UseAbility(); } } } private static bool IsUiBlocking() { if ((Object)(object)Chat.instance != (Object)null && (Chat.instance.HasFocus() || ((Object)(object)((Terminal)Chat.instance).m_input != (Object)null && ((Component)((Terminal)Chat.instance).m_input).gameObject.activeInHierarchy))) { return true; } if (Minimap.IsOpen() || Minimap.InTextInput()) { return true; } EventSystem current = EventSystem.current; GameObject val = ((current != null) ? current.currentSelectedGameObject : null); if ((Object)(object)val != (Object)null) { TMP_InputField componentInParent = val.GetComponentInParent<TMP_InputField>(); if (componentInParent == null || !componentInParent.isFocused) { InputField componentInParent2 = val.GetComponentInParent<InputField>(); if (componentInParent2 == null || !componentInParent2.isFocused) { goto IL_0098; } } return true; } goto IL_0098; IL_0098: if (!UnifiedPopup.IsVisible() && !Console.IsVisible() && !Menu.IsVisible() && !TextInput.IsVisible()) { if ((Object)(object)InventoryGui.instance != (Object)null) { return InventoryGui.IsVisible(); } return false; } return true; } private void CleanImmunities() { if ((Object)(object)Player.m_localPlayer == (Object)null) { return; } SEMan sEMan = ((Character)Player.m_localPlayer).GetSEMan(); if (sEMan != null) { if (LocalTeam == Team.Slimes) { sEMan.RemoveStatusEffect(StringExtensionMethods.GetStableHashCode("Poison"), true); } if (LocalTeam == Team.Wolves) { sEMan.RemoveStatusEffect(StringExtensionMethods.GetStableHashCode("Cold"), true); } if (LocalTeam == Team.Draugr) { sEMan.RemoveStatusEffect(StringExtensionMethods.GetStableHashCode("Wet"), true); } } } private static void PlayerSpawned(Player __instance) { if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && !((Object)(object)Instance == (Object)null)) { Instance.QueueSpawnCheck(__instance); if (LocalTeam != Team.None) { TeamEffects.Ensure(__instance, LocalTeam); } } } private static bool TakeInput(Player __instance, ref bool __result) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && IsSpinning) { __result = false; return false; } return true; } private static bool ControllerTakeInput(Player ___m_character, ref bool __result) { if ((Object)(object)___m_character == (Object)(object)Player.m_localPlayer && IsSpinning) { __result = false; return false; } return true; } private static void BlockMouseLook(Player __instance, ref Vector2 __0) { //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) if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && IsSpinning) { __0 = Vector2.zero; } } private static bool BlockAttackInput(Player __instance, ref float ___m_queuedAttackTimer, ref float ___m_queuedSecondAttackTimer) { if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || !IsSpinning) { return true; } ___m_queuedAttackTimer = 0f; ___m_queuedSecondAttackTimer = 0f; return false; } private static bool BlockCamera() { if (!IsSpinning) { return true; } RouletteUI.ShowCursor(); return false; } private static void MapStart(Minimap __instance) { if (!((Object)(object)Instance == (Object)null)) { Instance._localMarkerColors.Clear(); Instance.TintOwnMarker(); } } private void TintOwnMarker() { Minimap instance = Minimap.instance; if (!((Object)(object)instance == (Object)null)) { Team localTeam = LocalTeam; TintLocalMarker(instance.m_smallMarker, localTeam); TintLocalMarker(instance.m_largeMarker, localTeam); } } private void TintLocalMarker(RectTransform marker, Team team) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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_0043: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)marker == (Object)null) { return; } Image[] componentsInChildren = ((Component)marker).GetComponentsInChildren<Image>(true); foreach (Image val in componentsInChildren) { if (!_localMarkerColors.TryGetValue(val, out var value)) { value = ((Graphic)val).color; _localMarkerColors[val] = value; } ((Graphic)val).color = ((team == Team.None) ? value : TeamColor(team)); } } private void ApplyMapIcon(Image image, Team team) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)image == (Object)null) && _mapIcons != null) { Sprite val = ((team == Team.None) ? null : _mapIcons[(int)(team - 1)]); if ((Object)(object)val != (Object)null) { image.overrideSprite = val; ((Graphic)image).color = Color.white; } else if ((Object)(object)image.overrideSprite != (Object)null && Array.IndexOf(_mapIcons, image.overrideSprite) >= 0) { image.overrideSprite = null; } } } private static void RequestMapRefresh() { if ((Object)(object)Minimap.instance != (Object)null) { PinUpdateField?.SetValue(Minimap.instance, true); } } private static void UpdatePlayerPins(Minimap __instance) { //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_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: 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_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || (Object)(object)Instance == (Object)null || Instance._mapIcons == null) { return; } try { IList list = PlayerPinsField?.GetValue(__instance) as IList; IList list2 = PlayerInfosField?.GetValue(__instance) as IList; if (list != null && list2 != null) { int num = Mathf.Min(list.Count, list2.Count); for (int i = 0; i < num; i++) { object obj = list[i]; object obj2 = list2[i]; if (obj != null && obj2 != null) { FieldInfo fieldInfo = AccessTools.Field(obj2.GetType(), "m_characterID"); if (!(fieldInfo == null) && fieldInfo.GetValue(obj2) is ZDOID val) { ColorRemotePin(obj, ((ZDOID)(ref val)).UserID); } } } } else { if (!(AllPinsField?.GetValue(__instance) is IList list3) || (Object)(object)ZNet.instance == (Object)null) { return; } List<PlayerInfo> list4 = new List<PlayerInfo>(); ZNet.instance.GetOtherPublicPlayers(list4); HashSet<long> hashSet = new HashSet<long>(); { foreach (object item in list3) { if (item == null || !string.Equals(ReadField(item, "m_type")?.ToString(), "Player", StringComparison.Ordinal) || !(ReadField(item, "m_pos") is Vector3 val2)) { continue; } float num2 = 1225f; long num3 = 0L; foreach (PlayerInfo item2 in list4) { ZDOID characterID = item2.m_characterID; long userID = ((ZDOID)(ref characterID)).UserID; if (!hashSet.Contains(userID)) { Vector3 val3 = item2.m_position - val2; float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude; if (sqrMagnitude < num2) { num2 = sqrMagnitude; num3 = userID; } } } if (num3 != 0L) { hashSet.Add(num3); ColorRemotePin(item, num3); } } return; } } } catch (Exception ex) { if ((Object)(object)Instance != (Object)null && !Instance._mapWarningIssued) { Instance._mapWarningIssued = true; ((BaseUnityPlugin)Instance).Logger.LogWarning((object)("Could not apply team map icons: " + ex.Message)); } } } private static object ReadField(object source, string name) { if (source != null) { return AccessTools.Field(source.GetType(), name)?.GetValue(source); } return null; } private static void ColorRemotePin(object pin, long userId) { //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) object obj = ReadField(pin, "m_iconElement"); Image val = (Image)((obj is Image) ? obj : null); if ((Object)(object)val == (Object)null) { return; } RemoteTeams.TryGetValue(userId, out var value); Instance.ApplyMapIcon(val, value); object obj2 = ReadField(pin, "m_NamePinData"); object obj3 = ((obj2 == null) ? null : (AccessTools.Property(obj2.GetType(), "PinNameText")?.GetValue(obj2) ?? ReadField(obj2, "PinNameText"))); if (obj3 != null) { PropertyInfo propertyInfo = AccessTools.Property(obj3.GetType(), "color"); if (propertyInfo != null && propertyInfo.CanWrite && propertyInfo.PropertyType == typeof(Color)) { propertyInfo.SetValue(obj3, (value == Team.None || value == Team.Draugr) ? Color.white : TeamColor(value)); } } } private unsafe static bool Matches(SkillType type, string name) { return ((object)(*(SkillType*)(&type))/*cast due to .constrained prefix*/).ToString() == name; } private static void RaiseSkill(Skills __instance, SkillType __0, ref float __1) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_006f: 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) if (!((Object)(object)__instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)__instance != (Object)(object)((Character)Player.m_localPlayer).GetSkills())) { Team localTeam = LocalTeam; if ((localTeam == Team.Slimes && (Matches(__0, "Jump") || Matches(__0, "Swim"))) || (localTeam == Team.Wolves && (Matches(__0, "Run") || Matches(__0, "Sneak"))) || (localTeam == Team.Draugr && Matches(__0, "Bows"))) { __1 *= 1.3f; } } } private static void GetSkillLevel(Skills __instance, SkillType __0, ref float __result) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance != (Object)null && (Object)(object)Player.m_localPlayer != (Object)null && (Object)(object)__instance == (Object)(object)((Character)Player.m_localPlayer).GetSkills() && LocalTeam == Team.Draugr && Matches(__0, "Bows")) { __result = Mathf.Min(100f, __result + 10f); } } private static void RunSpeed(Player __instance, ref float __result) { if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && LocalTeam == Team.Wolves) { __result *= 1.1f; } } private static void WolfSpeed(SEMan __instance, ref float __0) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && __instance == ((Character)localPlayer).GetSEMan() && LocalTeam == Team.Wolves && (Object)(object)Instance != (Object)null && Time.time < Instance._wolfBuffEnd) { __0 *= 1.15f; } } private static bool BlockNegativeStatus(SEMan __instance, int __0) { if (__instance == null || (Object)(object)Player.m_localPlayer == (Object)null || __instance != ((Character)Player.m_localPlayer).GetSEMan()) { return true; } Team localTeam = LocalTeam; if (localTeam == Team.Slimes && __0 == StringExtensionMethods.GetStableHashCode("Poison")) { return false; } if (localTeam == Team.Wolves && __0 == StringExtensionMethods.GetStableHashCode("Cold")) { return false; } if (localTeam == Team.Draugr && __0 == StringExtensionMethods.GetStableHashCode("Wet")) { return false; } return true; } private static void RunDrain(SEMan __instance, ref float __1, bool __3) { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && __instance == ((Character)localPlayer).GetSEMan()) { Team localTeam = LocalTeam; if (localTeam == Team.Wolves) { __1 *= 0.85f; } if (localTeam == Team.Slimes && __3) { __1 *= 1.1f; } } } private static void FoodRegen(SEMan __instance, ref float __0) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && __instance == ((Character)localPlayer).GetSEMan() && LocalTeam == Team.Draugr) { __0 *= 0.8f; } } private static void SwimDrain(SEMan __instance, ref float __1) { if (__instance != null && (Object)(object)Player.m_localPlayer != (Object)null && __instance == ((Character)Player.m_localPlayer).GetSEMan() && LocalTeam == Team.Slimes) { __1 *= 0.75f; } } private static void JumpBefore(Character __instance, out float? __state) { __state = null; if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && LocalTeam == Team.Slimes) { __state = __instance.m_jumpForce; __instance.m_jumpForce *= Mathf.Sqrt(1.15f); } } private static void JumpAfter(Character __instance, float? __state) { if (__state.HasValue) { __instance.m_jumpForce = __state.Value; } } private static void OutgoingDamage(Character __instance, HitData hit) { //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Invalid comparison between Unknown and I4 //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Invalid comparison between Unknown and I4 //IL_0054: 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) if (hit == null || (Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)hit.GetAttacker() != (Object)(object)Player.m_localPlayer || (Object)(object)__instance == (Object)(object)Player.m_localPlayer) { return; } Team localTeam = LocalTeam; if (localTeam == Team.Slimes && !hit.m_ranged && !Matches(hit.m_skill, "Bows") && !Matches(hit.m_skill, "Crossbows") && !Matches(hit.m_skill, "ElementalMagic") && Random.value < 0.08f) { hit.m_damage.m_poison += 8f; } if (localTeam == Team.Wolves) { float num = (((int)hit.m_skill == 8 || (int)hit.m_skill == 14) ? 0.85f : 1f); float maxHealth = __instance.GetMaxHealth(); if (maxHealth > 0f && __instance.GetHealth() / maxHealth < 0.3f) { num *= 1.1f; } if (num != 1f) { ((DamageTypes)(ref hit.m_damage)).Modify(num); } } } private static void IncomingDamage(Character __instance, HitData hit, out HitData __state) { __state = _incomingHit; _incomingHit = hit; if (hit == null) { return; } Player val = (Player)(object)((__instance is Player) ? __instance : null); if (val == null) { return; } Team team = GetTeam(val); if (team == Team.Slimes) { hit.m_damage.m_poison = 0f; } if (team == Team.Draugr) { float num = 0.95f; if ((Object)(object)val == (Object)(object)Player.m_localPlayer && (Object)(object)Instance != (Object)null && Time.time < Instance._draugrGuardEnd) { num *= 0.8f; } hit.m_damage.m_blunt *= num; hit.m_damage.m_slash *= num; hit.m_damage.m_pierce *= num; hit.m_damage.m_chop *= num; hit.m_damage.m_pickaxe *= num; } } private void CloudVisual(Vector3 center) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) if ((int)SystemInfo.graphicsDeviceType == 4) { return; } ZNetScene instance = ZNetScene.instance; GameObject val = ((instance != null) ? instance.GetPrefab("vfx_blob_attack") : null); if ((Object)(object)val == (Object)null && _blobEffect.IsValid) { if (!_blobEffectLoaded) { _blobEffect.Load(); _blobEffectLoaded = true; } val = _blobEffect.Asset; } if ((Object)(object)val == (Object)null) { if (!_cloudEffectWarningIssued) { _cloudEffectWarningIssued = true; ((BaseUnityPlugin)this).Logger.LogWarning((object)"Could not load the Valheim prefab vfx_blob_attack."); } return; } bool forceDisableInit = ZNetView.m_forceDisableInit; ZNetView.m_forceDisableInit = true; GameObject val2; try { val2 = Object.Instantiate<GameObject>(val, center, Quaternion.identity); } finally { ZNetView.m_forceDisableInit = forceDisableInit; } Object.Destroy((Object)(object)val2, 12f); } private static bool LoadRoster() { if (!TryGetWorldId(out var id)) { return false; } string text = Path.Combine(Paths.ConfigPath, "TeamsRoulette", id + ".roster"); if (_rosterPath == text) { return true; } try { Dictionary<string, Team> dictionary = new Dictionary<string, Team>(StringComparer.Ordinal); if (File.Exists(text)) { foreach (string item in File.ReadLines(text)) { string[] array = item.Split('\t'); if (array.Length != 2 || !int.TryParse(array[1], out var result) || result < 1 || result > 3) { throw new InvalidDataException("Invalid roster row."); } dictionary.Add(Encoding.UTF8.GetString(Convert.FromBase64String(array[0])), (Team)result); } } Roster.Clear(); foreach (KeyValuePair<string, Team> item2 in dictionary) { Roster.Add(item2.Key, item2.Value); } _rosterPath = text; return true; } catch (Exception ex) { Instance.LogWarning("Roster load failed: " + ex.Message); return false; } } private static string Account(long uid) { if (uid != ZNet.GetUID()) { ZNetPeer peer = ZNet.instance.GetPeer(uid); if (peer == null) { return null; } return peer.m_socket.GetHostName(); } return ((object)Unsafe.As<PlatformUserID, PlatformUserID>(ref UserInfo.GetLocalUser().UserId)/*cast due to .constrained prefix*/).ToString(); } private static bool SaveAssignment(string account, Team team) { if (string.IsNullOrEmpty(account) || !LoadRoster()) { return false; } Team value; bool flag = Roster.TryGetValue(account, out value); if (flag && value == team) { return true; } Roster[account] = team; string text = _rosterPath + ".tmp"; try { Directory.CreateDirectory(Path.GetDirectoryName(_rosterPath)); File.WriteAllLines(text, Roster.Select((KeyValuePair<string, Team> entry) => Convert.ToBase64String(Encoding.UTF8.GetBytes(entry.Key)) + "\t" + (int)entry.Value)); if (File.Exists(_rosterPath)) { File.Replace(text, _rosterPath, null); } else { File.Move(text, _rosterPath); } return true; } catch (Exception ex) { if (flag) { Roster[account] = value; } else { Roster.Remove(account); } Instance.LogWarning("Roster save failed: " + ex.Message); return false; } } internal static Team PickTeam(IEnumerable<Team> roster, Func<int, int> randomIndex) { int[] counts = new int[3]; foreach (Team item in roster) { counts[(int)(item - 1)]++; } int minimum = counts.Min(); int[] array = (from index in Enumerable.Range(0, counts.Length) where counts[index] == minimum select index).ToArray(); return (Team)(array[randomIndex(array.Length)] + 1); } internal void RequestRoll() { //IL_0040: 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) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || (Object)(object)ZNet.instance == (Object)null) { _ui?.FinishRequest(Team.None); return; } if (ZNet.instance.IsServer()) { ResolveRoll(ZNet.GetUID(), ((Character)localPlayer).GetZDOID()); return; } ZRpc serverRPC = ZNet.instance.GetServerRPC(); if (serverRPC != null) { serverRPC.Invoke("PTR_Roll_4", new object[1] { ((Character)localPlayer).GetZDOID() }); } else { _ui?.FinishRequest(Team.None); } } private static void ResolveRoll(long uid, ZDOID requested) { //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_002f: 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_007b: 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_0095: 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_00a4: 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) Team value = Team.None; string text = Account(uid); if (!TeamCommands.IsAssigning(uid) && !string.IsNullOrEmpty(text) && TryCharacter(uid, out var id, out var zdo) && id == requested && ReadHealth(zdo) > 0f && LoadRoster()) { if (!Roster.TryGetValue(text, out value) && TryGetTemplePosition(out var position)) { Vector3 val = ((uid == ZNet.GetUID()) ? ((Component)Player.m_localPlayer).transform.position : zdo.GetPosition()); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(val.x - position.x, val.z - position.z); if (((Vector2)(ref val2)).sqrMagnitude <= 1225f) { value = PickTeam(Roster.Values, (int count) => Random.Range(0, count)); if (!SaveAssignment(text, value)) { value = Team.None; } } } if (value != Team.None) { SyncRosterTeam(uid, zdo, value); } } SendRosterResult(uid, requested, value, roll: true); } private static void SyncRosterTeam(long uid, ZDO character, Team team) { TeamProfiles[uid] = character.GetLong(ZDOVars.s_playerID, 0L); RemoteTeams.TryGetValue(uid, out var value); if (value != team) { PublishTeam(uid, team); } } private static void SendRosterResult(long uid, ZDOID character, Team team, bool roll) { //IL_0008: 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 (uid == ZNet.GetUID()) { ReceiveRosterResult(character, team, roll); return; } ZNetPeer peer = ZNet.instance.GetPeer(uid); if (peer != null) { peer.m_rpc.Invoke("PTR_RosterResult_4", new object[3] { character, (int)team, roll }); } } private static void ReceiveRosterResult(ZDOID character, Team team, bool roll) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && !(((Character)localPlayer).GetZDOID() != character) && !((Object)(object)Instance == (Object)null)) { Instance._rosterCharacter = character; if ((Object)(object)Instance._ui != (Object)null && Instance._ui.IsOpen && (roll || team != Team.None)) { Instance._ui.FinishRequest(team); } else if (team != Team.None) { Instance.SetLocalTeam(team, replace: true); } else if (!roll && LocalTeam != Team.None) { Team localTeam = LocalTeam; localPlayer.m_customData.Remove(WorldKey()); TeamEffects.ClearAbility(localPlayer, localTeam); TeamEffects.Ensure(localPlayer, Team.None); Instance._wolfBuffEnd = (Instance._draugrGuardEnd = 0f); Instance.QueueSpawnCheck(localPlayer); Instance.TintOwnMarker(); } } } } internal enum Team { None, Slimes, Wolves, Draugr } internal sealed class RouletteUI : MonoBehaviour { private GameObject _root; private RectTransform _wheel; private Button _button; private Team _chosen; private bool _rolling; private float _requestDeadline; private float _start; private float _from; private float _to; private float _completeAt; private float _closeAt; private Font _font; private Sprite[] _icons; private const float RollSeconds = 5f; private static readonly Color Gold = new Color(0.97f, 0.77f, 0.43f, 1f); internal bool IsOpen => (Object)(object)_root != (Object)null; private void Awake() { _icons = (Sprite[])(object)new Sprite[3] { ReadIcon("Slimes"), ReadIcon("Wolves"), ReadIcon("Draugr") }; } private static Font ResolveGameFont() { Font[] array = Resources.FindObjectsOfTypeAll<Font>(); foreach (Font val in array) { if ((Object)(object)val != (Object)null && ((Object)val).name == "AveriaSansLibre-Bold") { return val; } } Font val2 = Resources.Load<Font>("Fonts/Averia_Sans_Libre/AveriaSansLibre-Bold"); if ((Object)(object)val2 != (Object)null) { return val2; } Debug.LogWarning((object)"[PerfectTeamsRoulette] AveriaSansLibre-Bold not found; using Arial fallback."); Font builtinResource = Resources.GetBuiltinResource<Font>("Arial.ttf"); if (!((Object)(object)builtinResource != (Object)null)) { return Font.CreateDynamicFontFromOSFont("Arial", 18); } return builtinResource; } internal Sprite GetTeamIcon(Team team) { if (team < Team.Slimes || team > Team.Draugr) { return null; } return _icons[(int)(team - 1)]; } internal static Sprite ReadIcon(string name) { //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) try { string name2 = "PerfectTeamsRoulette." + name + ".png"; using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name2); if (stream == null) { return null; } byte[] array = new byte[stream.Length]; int num; for (int i = 0; i < array.Length; i += num) { if ((num = stream.Read(array, i, array.Length - i)) <= 0) { break; } } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); ((Object)val).name = "PTR_" + name; if (!ImageConversion.LoadImage(val, array, false)) { return null; } ((Texture)val).wrapMode = (TextureWrapMode)1; return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f); } catch (Exception ex) { Debug.LogWarning((object)("[PerfectTeamsRoulette] Icon " + name + " load failed: " + ex.Message)); return null; } } internal void Open() { if (!((Object)(object)_root != (Object)null)) { _font = ResolveGameFont(); _chosen = Team.None; _requestDeadline = 0f; _rolling = false; _closeAt = 0f; Build(); ShowCursor(); } } internal void Close() { _requestDeadline = 0f; _rolling = false; if ((Object)(object)_root != (Object)null) { Object.Destroy((Object)(object)_root); } _root = null; _wheel = null; _button = null; if (!InventoryGui.IsVisible() && !Menu.IsVisible()) { Cursor.visible = false; Cursor.lockState = (CursorLockMode)1; } } private void OnDestroy() { if ((Object)(object)_root != (Object)null) { Object.Destroy((Object)(object)_root); } } internal static void ShowCursor() { Cursor.lockState = (CursorLockMode)0; Cursor.visible = true; } private void LateUpdate() { //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_root == (Object)null) { return; } ShowCursor(); if (_requestDeadline > 0f && Time.unscaledTime >= _requestDeadline) { FinishRequest(Team.None); } if (!_rolling) { if (_closeAt > 0f && Time.unscaledTime >= _closeAt) { Close(); } return; } float num = Mathf.Clamp01((Time.unscaledTime - _start) / 5f); float num2 = 1f - Mathf.Pow(1f - num, 4f); ((Transform)_wheel).localEulerAngles = new Vector3(0f, 0f, Mathf.LerpUnclamped(_from, _to, num2)); if (!(num < 1f) && !(Time.unscaledTime < _completeAt)) { _requestDeadline = 0f; _rolling = false; ((Transform)_wheel).localEulerAngles = new Vector3(0f, 0f, _to); Plugin.Instance.SetLocalTeam(_chosen, replace: true, keepWheel: true); _closeAt = Time.unscaledTime + 0.85f; } } private void StartRoll() { if (!_rolling) { if (_chosen != Team.None) { Close(); } else if (!(_requestDeadline > 0f)) { _requestDeadline = Time.unscaledTime + 10f; ((Selectable)_button).interactable = false; Plugin.Instance.RequestRoll(); } } } internal void FinishRequest(Team team) { //IL_0083: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_root == (Object)null || _rolling || _chosen != Team.None) { return; } _requestDeadline = 0f; if (team == Team.None) { ((Selectable)_button).interactable = true; Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)2, "Класс не назначен. Повторите попытку у стартовых камней.", 0, (Sprite)null, false); } } else { _chosen = team; _start = Time.unscaledTime; _completeAt = _start + 5f + 0.25f; _from = Mathf.Repeat(((Transform)_wheel).localEulerAngles.z, 360f); float num = (float)(_chosen - 1) * 120f; _to = _from + 2160f + Mathf.Repeat(num - _from, 360f); _rolling = true; ((Selectable)_button).interactable = false; } } private void Build() { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown //IL_0083: 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: Expected O, but got Unknown //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0152: 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_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0168: 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_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_02bf: Unknown result type (might be due to invalid IL or missing references) //IL_02ce: Unknown result type (might be due to invalid IL or missing references) //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_0311: Unknown result type (might be due to invalid IL or missing references) //IL_0331: Unknown result type (might be due to invalid IL or missing references) //IL_0351: Unknown result type (might be due to invalid IL or missing references) //IL_0371: Unknown result type (might be due to invalid IL or missing references) //IL_038d: Unknown result type (might be due to invalid IL or missing refere