using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using JetBrains.Annotations; using Microsoft.CodeAnalysis; using ServerSync; using TMPro; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("TouchGrass")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("sighsorry")] [assembly: AssemblyProduct("TouchGrass")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")] [assembly: AssemblyFileVersion("1.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace TouchGrass { [BepInPlugin("sighsorry.TouchGrass", "TouchGrass", "1.0.0")] public class TouchGrassPlugin : BaseUnityPlugin { public enum Toggle { On = 1, Off = 0 } public enum FatigueStatusEffectDisplay { Off, Detailed } public enum TrainingDummyDamageType { Blunt, Slash, Pierce, Fire, Frost, Lightning, Poison, Spirit } public enum TrainingMeterDisplay { Off, Detailed } [CompilerGenerated] private sealed class d__43 : IEnumerable, IEnumerable, IEnumerator, IDisposable, IEnumerator { private int <>1__state; private SkillType <>2__current; private int <>l__initialThreadId; private IEnumerator <>7__wrap1; SkillType IEnumerator.Current { [DebuggerHidden] get { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return <>2__current; } } [DebuggerHidden] public d__43(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 1) { try { } finally { <>m__Finally1(); } } <>7__wrap1 = null; <>1__state = -2; } private bool MoveNext() { //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_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Invalid comparison between Unknown and I4 //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) try { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>7__wrap1 = Enum.GetValues(typeof(SkillType)).GetEnumerator(); <>1__state = -3; break; case 1: <>1__state = -3; break; } while (<>7__wrap1.MoveNext()) { SkillType val = (SkillType)<>7__wrap1.Current; if (((int)val != 0 && (int)val != 999) || 1 == 0) { <>2__current = val; <>1__state = 1; return true; } } <>m__Finally1(); <>7__wrap1 = null; return false; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<>7__wrap1 is IDisposable disposable) { disposable.Dispose(); } } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; return this; } return new d__43(0); } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)this).GetEnumerator(); } } internal const string ModName = "TouchGrass"; internal const string ModVersion = "1.0.0"; internal const string Author = "sighsorry"; private const string ModGUID = "sighsorry.TouchGrass"; private static string ConfigFileName = "sighsorry.TouchGrass.cfg"; private static string ConfigFileFullPath; internal static string ConnectionError; private readonly Harmony _harmony = new Harmony("sighsorry.TouchGrass"); public static readonly ManualLogSource TouchGrassLogger; private static readonly ConfigSync ConfigSync; private FileSystemWatcher? _watcher; private readonly object _reloadLock = new object(); private DateTime _lastConfigReloadTime; private const long RELOAD_DELAY = 10000000L; private static ConfigEntry _serverConfigLocked; internal static ConfigEntry _locationFullEfficiencySeconds; internal static ConfigEntry _locationFadeSeconds; internal static ConfigEntry _locationMinimumMultiplier; internal static ConfigEntry _stationaryRadius; internal static ConfigEntry _fatigueStationarySkillGains; internal static ConfigEntry _fatigueStatusEffectDisplay; internal static ConfigEntry _trainingDummyHealth; internal static ConfigEntry _trainingDummyCrowdingRadius; internal static ConfigEntry _trainingDummyCrowdingMaxCount; internal static ConfigEntry _archeryTargetSkillMultiplier; internal static ConfigEntry _localTrainingDummyDamageType; internal static ConfigEntry _localTrainingDummyDamageAmount; internal static ConfigEntry _trainingMeterDisplay; internal static ConfigEntry _trainingMeterWindowSeconds; internal static readonly Dictionary> _skillGainRates; internal static readonly Dictionary> _skillReductionRates; public void Awake() { //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Expected O, but got Unknown //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Expected O, but got Unknown //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Expected O, but got Unknown //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Expected O, but got Unknown //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Expected O, but got Unknown //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Expected O, but got Unknown //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Expected O, but got Unknown //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Expected O, but got Unknown //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_029d: Expected O, but got Unknown //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02f2: Expected O, but got Unknown bool saveOnConfigSet = ((BaseUnityPlugin)this).Config.SaveOnConfigSet; ((BaseUnityPlugin)this).Config.SaveOnConfigSet = false; _serverConfigLocked = config("1 - General", "Lock Configuration", Toggle.On, "If on, the configuration is locked and can be changed by server admins only."); ConfigSync.AddLockingConfigEntry(_serverConfigLocked); _locationFullEfficiencySeconds = config("2 - Skill Gate", "Location Full Efficiency Seconds", 120f, new ConfigDescription("Stationary farmable skill gains stay at full value for this many chained seconds before fading.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 3600f), Array.Empty())); _locationFadeSeconds = config("2 - Skill Gate", "Location Fade Seconds", 180f, new ConfigDescription("After full-efficiency time, stationary farmable skill gains fade to the minimum multiplier over this many seconds.", (AcceptableValueBase)(object)new AcceptableValueRange(1f, 7200f), Array.Empty())); _locationMinimumMultiplier = config("2 - Skill Gate", "Location Minimum Multiplier", 0.1f, new ConfigDescription("Lowest multiplier applied to repeated stationary farmable skill gains.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 1f), Array.Empty())); _stationaryRadius = config("2 - Skill Gate", "Stationary XZ Radius", 4f, new ConfigDescription("Radius on the X/Z plane. If farmable skill gains keep happening without leaving this radius, location efficiency fades.", (AcceptableValueBase)(object)new AcceptableValueRange(0.5f, 50f), Array.Empty())); _fatigueStationarySkillGains = config("2 - Skill Gate", "Fatigue Stationary Skill Gains", Toggle.On, "If on, repeated farmable skill gains within the stationary X/Z radius share one global fading multiplier instead of being blocked outright. Affected skills: " + SkillNameFormatter.FormatList(SkillEarnGate.GetLocationFatigueSkillTypes()) + "."); _fatigueStatusEffectDisplay = config("2 - Skill Gate", "Fatigue Status Effect Display", FatigueStatusEffectDisplay.Detailed, "Controls the local player's fatigue status effect display. Detailed shows the status effect icon and static compendium details; Off hides it."); _archeryTargetSkillMultiplier = config("1 - General", "Archery Target Skill Multiplier", 1f, new ConfigDescription("Multiplier applied to skill experience awarded by piece_ArcheryTarget. 0 disables archery target skill gain.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 10f), Array.Empty())); _trainingDummyHealth = config("3 - Training Dummy", "Training Dummy Health", 2500f, new ConfigDescription("Max health applied to piece_TrainingDummy.", (AcceptableValueBase)(object)new AcceptableValueRange(1f, 100000f), Array.Empty())); _trainingDummyCrowdingRadius = config("3 - Training Dummy", "Training Dummy Crowding Radius", 4f, new ConfigDescription("XZ radius used to discourage placing too many training dummies in one spot. 0 disables the crowding check.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 50f), Array.Empty())); _trainingDummyCrowdingMaxCount = config("3 - Training Dummy", "Training Dummy Crowding Max Count", 4, new ConfigDescription("Maximum existing training dummies allowed inside the crowding radius. 4 means the 5th placement is discouraged. 0 disables the crowding check.", (AcceptableValueBase)(object)new AcceptableValueRange(0, 100), Array.Empty())); _localTrainingDummyDamageType = config("3 - Training Dummy", "Training Dummy Damage Type", TrainingDummyDamageType.Blunt, "Damage type used by local training dummy damage tests.", synchronizedSetting: false); _localTrainingDummyDamageAmount = config("3 - Training Dummy", "Training Dummy Damage", 1f, new ConfigDescription("Damage amount used by local training dummy damage tests.", (AcceptableValueBase)(object)new AcceptableValueRange(1f, 500f), Array.Empty()), synchronizedSetting: false); _trainingMeterDisplay = config("3 - Training Dummy", "Training Meter Display", TrainingMeterDisplay.Detailed, "Controls the integrated client-side training HUD for piece_TrainingDummy damage, incoming hits, and skill gains.", synchronizedSetting: false); _trainingMeterWindowSeconds = config("3 - Training Dummy", "Training Meter Window Seconds", 15f, new ConfigDescription("Rolling time window used by the training HUD.", (AcceptableValueBase)(object)new AcceptableValueRange(5f, 300f), Array.Empty()), synchronizedSetting: false); BindTrainingObjectConfigEvents(); BindPerSkillModifierConfigs(); Assembly executingAssembly = Assembly.GetExecutingAssembly(); _harmony.PatchAll(executingAssembly); SetupWatcher(); ((BaseUnityPlugin)this).Config.Save(); if (saveOnConfigSet) { ((BaseUnityPlugin)this).Config.SaveOnConfigSet = saveOnConfigSet; } } private void OnDestroy() { SaveWithRespectToConfigSet(); _watcher?.Dispose(); } private void OnGUI() { TrainingMeter.OnGUI(); } private void SetupWatcher() { _watcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName); _watcher.Changed += ReadConfigValues; _watcher.Created += ReadConfigValues; _watcher.Renamed += ReadConfigValues; _watcher.IncludeSubdirectories = true; _watcher.SynchronizingObject = ThreadingHelper.SynchronizingObject; _watcher.EnableRaisingEvents = true; } private void ReadConfigValues(object sender, FileSystemEventArgs e) { DateTime now = DateTime.Now; if (now.Ticks - _lastConfigReloadTime.Ticks < 10000000) { return; } lock (_reloadLock) { if (!File.Exists(ConfigFileFullPath)) { TouchGrassLogger.LogWarning((object)"Config file does not exist. Skipping reload."); return; } try { TouchGrassLogger.LogDebug((object)"Reloading configuration..."); SaveWithRespectToConfigSet(reload: true); TouchGrassLogger.LogInfo((object)"Configuration reload complete."); } catch (Exception ex) { TouchGrassLogger.LogError((object)("Error reloading configuration: " + ex.Message)); } } _lastConfigReloadTime = now; } private void SaveWithRespectToConfigSet(bool reload = false) { bool saveOnConfigSet = ((BaseUnityPlugin)this).Config.SaveOnConfigSet; ((BaseUnityPlugin)this).Config.SaveOnConfigSet = false; if (reload) { ((BaseUnityPlugin)this).Config.Reload(); } ((BaseUnityPlugin)this).Config.Save(); TrainingObjectTuning.ApplyAll(); if (saveOnConfigSet) { ((BaseUnityPlugin)this).Config.SaveOnConfigSet = saveOnConfigSet; } } private void BindPerSkillModifierConfigs() { //IL_0011: 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) //IL_002a: 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_005b: Expected O, but got Unknown //IL_0065: 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_0096: Expected O, but got Unknown foreach (SkillType configurableSkillType in GetConfigurableSkillTypes()) { SkillType current = configurableSkillType; string name = ((object)(SkillType)(ref current)).ToString(); _skillGainRates[current] = config("4 - Skill Gain Rate", name, 1f, new ConfigDescription("Multiplier applied to this skill's gained experience. Vanilla equivalent is 1. 0 disables gains for this skill, 2 doubles them.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 10f), Array.Empty())); _skillReductionRates[current] = config("5 - Skill Reduction Rate", name, 1f, new ConfigDescription("Multiplier applied to this skill's death skill loss. Vanilla equivalent is 1. 0 disables death loss for this skill, 2 doubles it.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 10f), Array.Empty())); } } private void BindTrainingObjectConfigEvents() { _trainingDummyHealth.SettingChanged += delegate { TrainingObjectTuning.ApplyAll(); }; _archeryTargetSkillMultiplier.SettingChanged += delegate { TrainingObjectTuning.ApplyAll(); }; } [IteratorStateMachine(typeof(d__43))] private static IEnumerable GetConfigurableSkillTypes() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__43(-2); } private ConfigEntry config(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown ConfigDescription val = new ConfigDescription(description.Description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]"), description.AcceptableValues, description.Tags); ConfigEntry val2 = ((BaseUnityPlugin)this).Config.Bind(group, name, value, val); ConfigSync.AddConfigEntry(val2).SynchronizedConfig = synchronizedSetting; return val2; } private ConfigEntry config(string group, string name, T value, string description, bool synchronizedSetting = true) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty()), synchronizedSetting); } static TouchGrassPlugin() { string configPath = Paths.ConfigPath; char directorySeparatorChar = Path.DirectorySeparatorChar; ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName; ConnectionError = ""; TouchGrassLogger = Logger.CreateLogSource("TouchGrass"); ConfigSync = new ConfigSync("sighsorry.TouchGrass") { DisplayName = "TouchGrass", CurrentVersion = "1.0.0", MinimumRequiredVersion = "1.0.0" }; _serverConfigLocked = null; _locationFullEfficiencySeconds = null; _locationFadeSeconds = null; _locationMinimumMultiplier = null; _stationaryRadius = null; _fatigueStationarySkillGains = null; _fatigueStatusEffectDisplay = null; _trainingDummyHealth = null; _trainingDummyCrowdingRadius = null; _trainingDummyCrowdingMaxCount = null; _archeryTargetSkillMultiplier = null; _localTrainingDummyDamageType = null; _localTrainingDummyDamageAmount = null; _trainingMeterDisplay = null; _trainingMeterWindowSeconds = null; _skillGainRates = new Dictionary>(); _skillReductionRates = new Dictionary>(); } } [HarmonyPatch(typeof(Skills), "RaiseSkill")] internal static class SkillsRaiseSkillPatch { private static bool Prefix(Skills __instance, SkillType skillType, ref float factor) { //IL_0004: 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) float sourceFactor = factor; bool flag = SkillEarnGate.AdjustSkillGain(__instance, skillType, ref factor); TrainingMeter.RecordSkillGain(__instance, skillType, sourceFactor, flag ? factor : 0f); return flag; } } [HarmonyPatch(typeof(Skills), "LowerAllSkills")] internal static class SkillsLowerAllSkillsPatch { private static bool Prefix(Skills __instance, float factor) { return SkillEarnGate.AdjustSkillReduction(__instance, factor); } } [HarmonyPatch(typeof(Character), "RPC_Damage")] internal static class CharacterRPCDamagePatch { private static void Prefix(Character __instance, HitData hit, out TrainingMeter.IncomingDamageState __state) { TrainingDummyDamageTest.OverrideLocalIncomingDamage(__instance, hit); __state = TrainingMeter.BeforeIncomingDamage(__instance, hit); } private static void Postfix(Character __instance, TrainingMeter.IncomingDamageState __state) { TrainingMeter.AfterIncomingDamage(__instance, __state); } } [HarmonyPatch(typeof(Character), "Awake")] internal static class CharacterAwakePatch { private static void Postfix(Character __instance) { TrainingDummyRegistry.Register(__instance); TrainingObjectTuning.ApplyTrainingDummy(__instance); } } [HarmonyPatch(typeof(Character), "OnDestroy")] internal static class CharacterOnDestroyPatch { private static void Prefix(Character __instance) { TrainingDummyRegistry.Unregister(__instance); } } [HarmonyPatch(typeof(Character), "Damage")] internal static class CharacterDamagePatch { private static void Prefix(Character __instance, HitData hit) { TrainingMeter.RecordOutgoingDamage(__instance, hit); } } [HarmonyPatch(typeof(Player), "TryPlacePiece")] internal static class PlayerTryPlacePiecePatch { private static bool Prefix(Player __instance, Piece piece, ref bool __result) { if (TrainingDummyCrowding.CanPlace(__instance, piece)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(Humanoid), "BlockAttack")] internal static class HumanoidBlockAttackPatch { private static void Postfix(Humanoid __instance, HitData hit) { TrainingMeter.RecordBlockResult(__instance, hit); } } [HarmonyPatch(typeof(ArcheryTarget), "Start")] internal static class ArcheryTargetStartPatch { private static void Postfix(ArcheryTarget __instance) { TrainingObjectTuning.ApplyArcheryTarget(__instance); } } [HarmonyPatch(typeof(ZNetScene), "Awake")] internal static class ZNetSceneAwakePatch { private static void Postfix(ZNetScene __instance) { TrainingObjectTuning.ApplyPrefabTuning(__instance); } } [HarmonyPatch(typeof(Piece), "SetCreator")] internal static class PieceSetCreatorPatch { private static void Postfix(Piece __instance) { TrainingDummyDamageTest.StampPlacedDamageProfile(__instance); } } internal static class SkillEarnGate { internal readonly struct FatigueSnapshot { internal static readonly FatigueSnapshot Empty = new FatigueSnapshot(1f); internal readonly float FinalMultiplier; internal readonly float GlobalMultiplier; public FatigueSnapshot(float globalMultiplier) { FinalMultiplier = globalMultiplier; GlobalMultiplier = globalMultiplier; } } private struct LocationFatigueState { internal bool HasGain; internal bool HasAnchor; internal float LastGainTime; internal float ActiveSeconds; internal float AnchorX; internal float AnchorZ; internal void SetAnchor(Vector3 position) { //IL_0008: 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) HasAnchor = true; AnchorX = position.x; AnchorZ = position.z; } internal void ClearGain() { HasGain = false; LastGainTime = 0f; ActiveSeconds = 0f; } internal void Clear() { HasAnchor = false; AnchorX = 0f; AnchorZ = 0f; ClearGain(); } } private const float TrainingChainGrace = 10f; private static readonly SkillType[] LocationFatigueSkillOrder; private static readonly HashSet LocationFatigueSkills; private static LocationFatigueState _locationFatigue; internal static bool AdjustSkillGain(Skills skills, SkillType skillType, ref float factor) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)skills == (Object)null || (Object)(object)skills.m_player != (Object)(object)Player.m_localPlayer) { return true; } if ((int)skillType == 0) { return true; } float sourceFactor = factor; factor *= GetPerSkillGainRate(skillType); if (ShouldApplyLocationFatigue(skillType, sourceFactor)) { factor *= GetLocationMultiplier(skills.m_player); } return factor > 0.0001f; } internal static bool AdjustSkillReduction(Skills skills, float factor) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)skills == (Object)null || (Object)(object)skills.m_player != (Object)(object)Player.m_localPlayer) { return true; } foreach (KeyValuePair skillDatum in skills.m_skillData) { float num = Mathf.Clamp01(factor * GetPerSkillReductionRate(skillDatum.Key)); Skill value = skillDatum.Value; value.m_level -= skillDatum.Value.m_level * num; skillDatum.Value.m_accumulator = 0f; } ((Character)skills.m_player).Message((MessageType)1, "$msg_skills_lowered", 0, (Sprite)null); return false; } internal static IReadOnlyList GetLocationFatigueSkillTypes() { return LocationFatigueSkillOrder; } private static bool ShouldApplyLocationFatigue(SkillType skillType, float sourceFactor) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Invalid comparison between Unknown and I4 if (TouchGrassPlugin._fatigueStationarySkillGains.Value != TouchGrassPlugin.Toggle.On || !LocationFatigueSkills.Contains(skillType)) { return false; } if ((int)skillType == 108) { return IsNormalDodgeGain(sourceFactor); } return true; } private static float GetPerSkillGainRate(SkillType skillType) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) return GetPerSkillConfigValue(TouchGrassPlugin._skillGainRates, skillType, 1f); } private static float GetPerSkillReductionRate(SkillType skillType) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) return GetPerSkillConfigValue(TouchGrassPlugin._skillReductionRates, skillType, 1f); } private static float GetPerSkillConfigValue(IReadOnlyDictionary> configs, SkillType skillType, float fallback) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) if (!configs.TryGetValue(skillType, out ConfigEntry value)) { return fallback; } return value.Value; } private static float GetLocationMultiplier(Player player) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)player == (Object)null) { return 1f; } float time = Time.time; if (!IsInsideStationaryRadius(((Component)player).transform.position)) { ResetLocationFatigue(); FatigueStatusEffectManager.Update(player); return 1f; } float result = RecordLocationFatigueGain(ref _locationFatigue, time); FatigueStatusEffectManager.Update(player); return result; } private static float RecordLocationFatigueGain(ref LocationFatigueState state, float now) { if (state.HasGain) { float num = Mathf.Max(0f, now - state.LastGainTime); if (num <= 10f) { state.ActiveSeconds += num; } } state.HasGain = true; state.LastGainTime = now; state.ActiveSeconds = Mathf.Min(GetMaxTrackedActiveSeconds(), state.ActiveSeconds); return ComputeLocationMultiplier(state.ActiveSeconds); } private static void ResetLocationFatigue() { _locationFatigue.ClearGain(); } private static bool IsInsideStationaryRadius(Vector3 position) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) float value = TouchGrassPlugin._stationaryRadius.Value; if (value <= 0f) { return false; } if (!_locationFatigue.HasAnchor) { _locationFatigue.SetAnchor(position); return false; } float num = position.x - _locationFatigue.AnchorX; float num2 = position.z - _locationFatigue.AnchorZ; if (num * num + num2 * num2 > value * value) { _locationFatigue.SetAnchor(position); return false; } return true; } private static float ComputeLocationMultiplier(float activeSeconds) { float value = TouchGrassPlugin._locationFullEfficiencySeconds.Value; if (activeSeconds <= value) { return 1f; } float num = Mathf.Max(1f, TouchGrassPlugin._locationFadeSeconds.Value); float num2 = Mathf.Clamp01(TouchGrassPlugin._locationMinimumMultiplier.Value); float num3 = Mathf.Clamp01((activeSeconds - value) / num); return Mathf.Lerp(1f, num2, num3); } private static bool IsNormalDodgeGain(float sourceFactor) { return sourceFactor <= 0.11f; } internal static bool TryGetFatigueSnapshot(out FatigueSnapshot snapshot) { snapshot = FatigueSnapshot.Empty; if (TouchGrassPlugin._fatigueStationarySkillGains.Value != TouchGrassPlugin.Toggle.On || TouchGrassPlugin._fatigueStatusEffectDisplay.Value == TouchGrassPlugin.FatigueStatusEffectDisplay.Off || !_locationFatigue.HasGain) { return false; } float num = ComputeLocationMultiplier(_locationFatigue.ActiveSeconds); if (num >= 0.999f) { return false; } snapshot = new FatigueSnapshot(num); return true; } private static float GetMaxTrackedActiveSeconds() { return Mathf.Max(1f, TouchGrassPlugin._locationFullEfficiencySeconds.Value + TouchGrassPlugin._locationFadeSeconds.Value); } static SkillEarnGate() { SkillType[] array = new SkillType[20]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); LocationFatigueSkillOrder = (SkillType[])(object)array; LocationFatigueSkills = new HashSet(LocationFatigueSkillOrder); } } internal static class FatigueStatusEffectManager { private const string EffectObjectName = "TouchGrass_Fatigue"; private static TouchGrassFatigueStatusEffect? _prototype; private static int EffectHash => ((StatusEffect)Prototype).NameHash(); private static TouchGrassFatigueStatusEffect Prototype { get { if ((Object)(object)_prototype != (Object)null) { return _prototype; } _prototype = ScriptableObject.CreateInstance(); ((Object)_prototype).name = "TouchGrass_Fatigue"; ((StatusEffect)_prototype).m_name = "TouchGrass Fatigue"; ((StatusEffect)_prototype).m_category = "TouchGrass"; ((StatusEffect)_prototype).m_icon = CreateIcon(); ((StatusEffect)_prototype).m_startMessage = ""; ((StatusEffect)_prototype).m_stopMessage = ""; Object.DontDestroyOnLoad((Object)(object)_prototype); return _prototype; } } internal static void Update(Player player) { if ((Object)(object)player == (Object)null || ((Character)player).GetSEMan() == null) { return; } if (!SkillEarnGate.TryGetFatigueSnapshot(out var _)) { Remove(player); return; } SEMan sEMan = ((Character)player).GetSEMan(); if ((Object)(object)sEMan.GetStatusEffect(EffectHash) == (Object)null) { sEMan.AddStatusEffect((StatusEffect)(object)Prototype, false, 0, 0f); } } internal static void Remove(Player player) { if (player != null) { SEMan sEMan = ((Character)player).GetSEMan(); if (sEMan != null) { sEMan.RemoveStatusEffect(EffectHash, true); } } } private static Sprite CreateIcon() { //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) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: 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_0153: Unknown result type (might be due to invalid IL or missing references) //IL_01db: 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_0192: 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) Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false) { filterMode = (FilterMode)0, wrapMode = (TextureWrapMode)1 }; Color32[] array = (Color32[])(object)new Color32[1024]; Color32 val2 = default(Color32); ((Color32)(ref val2))..ctor((byte)0, (byte)0, (byte)0, (byte)0); Color32 val3 = default(Color32); ((Color32)(ref val3))..ctor((byte)89, (byte)162, (byte)105, byte.MaxValue); Color32 val4 = default(Color32); ((Color32)(ref val4))..ctor((byte)26, (byte)54, (byte)41, byte.MaxValue); Color32 val5 = default(Color32); ((Color32)(ref val5))..ctor((byte)202, (byte)231, (byte)179, byte.MaxValue); Vector2 val6 = default(Vector2); ((Vector2)(ref val6))..ctor(15.5f, 15.5f); for (int i = 0; i < 32; i++) { for (int j = 0; j < 32; j++) { float num = Vector2.Distance(new Vector2((float)j, (float)i), val6); array[i * 32 + j] = ((num <= 14.5f) ? val4 : val2); if (num <= 12.5f) { array[i * 32 + j] = val3; } } } for (int k = 8; k <= 23; k++) { int num2 = 15 + Mathf.RoundToInt((float)(k - 16) * 0.15f); array[k * 32 + num2] = val5; array[k * 32 + num2 + 1] = val5; } for (int l = 8; l <= 16; l++) { int num3 = 16 - l; for (int m = 16; m <= 16 + num3; m++) { array[l * 32 + m] = val5; } } for (int n = 14; n <= 22; n++) { int num4 = n - 14; for (int num5 = 14 - num4; num5 <= 14; num5++) { array[n * 32 + num5] = val5; } } val.SetPixels32(array); val.Apply(false, true); Object.DontDestroyOnLoad((Object)(object)val); Sprite obj = Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f), 32f); Object.DontDestroyOnLoad((Object)(object)obj); return obj; } } internal class TouchGrassFatigueStatusEffect : StatusEffect { public override bool CanAdd(Character character) { return (Object)(object)character == (Object)(object)Player.m_localPlayer; } public override bool IsDone() { SkillEarnGate.FatigueSnapshot snapshot; if (!((StatusEffect)this).IsDone()) { return !SkillEarnGate.TryGetFatigueSnapshot(out snapshot); } return true; } public override string GetIconText() { if (!SkillEarnGate.TryGetFatigueSnapshot(out var snapshot)) { return ""; } return $"{Mathf.RoundToInt(snapshot.FinalMultiplier * 100f)}%"; } public override string GetTooltipString() { return "Touch the grass Bro!"; } } internal static class SkillNameFormatter { internal static string FormatList(IReadOnlyList skillTypes) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < skillTypes.Count; i++) { if (i > 0) { stringBuilder.Append(", "); } stringBuilder.Append(Format(skillTypes[i])); } return stringBuilder.ToString(); } internal static string Format(SkillType skillType) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Invalid comparison between Unknown and I4 string text = "$skill_" + ((object)(SkillType)(ref skillType)).ToString().ToLowerInvariant(); if (Localization.instance != null) { string text2 = Localization.instance.Localize(text); if (!string.IsNullOrWhiteSpace(text2) && text2 != text) { return text2; } } if ((int)skillType != 11) { return ((object)(SkillType)(ref skillType)).ToString(); } return "Fists"; } } internal static class TrainingDummyDamageTest { private readonly struct DamageProfile { internal readonly TouchGrassPlugin.TrainingDummyDamageType DamageType; internal readonly float Amount; public DamageProfile(TouchGrassPlugin.TrainingDummyDamageType damageType, float amount) { DamageType = damageType; Amount = amount; } } private const string TrainingDummyLocalizationKey = "$piece_trainingdummy"; private static readonly int PieceTrainingDummyPrefabHash = StringExtensionMethods.GetStableHashCode("piece_TrainingDummy"); private static readonly int TrainingDummyPrefabHash = StringExtensionMethods.GetStableHashCode("TrainingDummy"); private const string DummyDamageProfileVersionKey = "TouchGrass_DummyDamageProfileVersion"; private const string DummyDamageTypeKey = "TouchGrass_DummyDamageType"; private const string DummyDamageAmountKey = "TouchGrass_DummyDamageAmount"; private const int DummyDamageProfileVersion = 1; internal static void OverrideLocalIncomingDamage(Character victim, HitData hit) { //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) if (hit != null && !((Object)(object)victim == (Object)null) && !((Object)(object)victim != (Object)(object)Player.m_localPlayer)) { Character attacker = hit.GetAttacker(); if (IsTrainingDummy(attacker) && (TryGetStampedDamageProfile(attacker, out var profile) || TryGetLocalDamageProfile(out profile))) { hit.m_damage = BuildDamageTypes(profile.DamageType, profile.Amount); } } } internal static void StampPlacedDamageProfile(Piece piece) { if ((Object)(object)piece == (Object)null || !IsTrainingDummy(piece) || !TryGetLocalDamageProfile(out var profile)) { return; } ZNetView val = (((Object)(object)piece.m_nview != (Object)null) ? piece.m_nview : ((Component)piece).GetComponent()); if (!((Object)(object)val == (Object)null) && val.IsValid() && val.IsOwner()) { ZDO zDO = val.GetZDO(); if (zDO != null && piece.GetCreator() != 0L && zDO.GetInt("TouchGrass_DummyDamageType", -1) < 0) { zDO.Set("TouchGrass_DummyDamageProfileVersion", 1); zDO.Set("TouchGrass_DummyDamageType", (int)profile.DamageType); zDO.Set("TouchGrass_DummyDamageAmount", profile.Amount); } } } internal static bool IsTrainingDummy(Character attacker) { if ((Object)(object)attacker == (Object)null) { return false; } if (attacker.m_name == "$piece_trainingdummy") { return true; } if (HasTrainingDummyPrefab(attacker)) { return true; } return IsTrainingDummyPrefabName(Utils.GetPrefabName(((Component)attacker).gameObject)); } internal static bool IsTrainingDummy(Piece piece) { if ((Object)(object)piece == (Object)null) { return false; } if (piece.m_name == "$piece_trainingdummy") { return true; } ZNetView val = (((Object)(object)piece.m_nview != (Object)null) ? piece.m_nview : ((Component)piece).GetComponent()); if ((Object)(object)val != (Object)null && val.IsValid() && val.GetZDO() != null && IsTrainingDummyPrefabHash(val.GetZDO().GetPrefab())) { return true; } return IsTrainingDummyPrefabName(Utils.GetPrefabName(((Component)piece).gameObject)); } internal static bool HasTrainingDummyPrefab(Character character) { if ((Object)(object)character == (Object)null) { return false; } ZNetView val = (((Object)(object)character.m_nview != (Object)null) ? character.m_nview : ((Component)character).GetComponent()); if ((Object)(object)val == (Object)null) { return false; } if (val.IsValid() && val.GetZDO() != null && IsTrainingDummyPrefabHash(val.GetZDO().GetPrefab())) { return true; } return IsTrainingDummyPrefabName(val.GetPrefabName()); } internal static bool HasTrainingDummyZdoPrefab(Character character) { if ((Object)(object)character == (Object)null) { return false; } ZNetView val = (((Object)(object)character.m_nview != (Object)null) ? character.m_nview : ((Component)character).GetComponent()); if ((Object)(object)val != (Object)null && val.IsValid() && val.GetZDO() != null) { return IsTrainingDummyPrefabHash(val.GetZDO().GetPrefab()); } return false; } private static bool TryGetStampedDamageProfile(Character attacker, out DamageProfile profile) { profile = default(DamageProfile); ZNetView component = ((Component)attacker).GetComponent(); if ((Object)(object)component == (Object)null || !component.IsValid()) { return false; } ZDO zDO = component.GetZDO(); if (zDO == null) { return false; } int @int = zDO.GetInt("TouchGrass_DummyDamageType", -1); if (!Enum.IsDefined(typeof(TouchGrassPlugin.TrainingDummyDamageType), @int)) { return false; } float @float = zDO.GetFloat("TouchGrass_DummyDamageAmount", 0f); if (@float <= 0f) { return false; } profile = new DamageProfile((TouchGrassPlugin.TrainingDummyDamageType)@int, @float); return true; } private static bool TryGetLocalDamageProfile(out DamageProfile profile) { profile = new DamageProfile(TouchGrassPlugin._localTrainingDummyDamageType.Value, TouchGrassPlugin._localTrainingDummyDamageAmount.Value); return true; } private static bool IsTrainingDummyPrefabName(string prefabName) { if (string.IsNullOrEmpty(prefabName)) { return false; } if (!string.Equals(prefabName, "TrainingDummy", StringComparison.OrdinalIgnoreCase)) { return string.Equals(prefabName, "piece_TrainingDummy", StringComparison.OrdinalIgnoreCase); } return true; } private static bool IsTrainingDummyPrefabHash(int prefabHash) { if (prefabHash != PieceTrainingDummyPrefabHash) { return prefabHash == TrainingDummyPrefabHash; } return true; } private static DamageTypes BuildDamageTypes(TouchGrassPlugin.TrainingDummyDamageType damageType, float amount) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) amount = Mathf.Clamp(amount, 1f, 500f); DamageTypes result = default(DamageTypes); switch (damageType) { case TouchGrassPlugin.TrainingDummyDamageType.Blunt: result.m_blunt = amount; break; case TouchGrassPlugin.TrainingDummyDamageType.Slash: result.m_slash = amount; break; case TouchGrassPlugin.TrainingDummyDamageType.Pierce: result.m_pierce = amount; break; case TouchGrassPlugin.TrainingDummyDamageType.Fire: result.m_fire = amount; break; case TouchGrassPlugin.TrainingDummyDamageType.Frost: result.m_frost = amount; break; case TouchGrassPlugin.TrainingDummyDamageType.Lightning: result.m_lightning = amount; break; case TouchGrassPlugin.TrainingDummyDamageType.Poison: result.m_poison = amount; break; case TouchGrassPlugin.TrainingDummyDamageType.Spirit: result.m_spirit = amount; break; default: result.m_blunt = amount; break; } return result; } } internal static class TrainingObjectTuning { private static readonly string[] TrainingDummyPrefabNames = new string[2] { "piece_TrainingDummy", "TrainingDummy" }; internal static void ApplyAll() { ApplyPrefabTuning(); ApplyLoadedTrainingDummies(); ApplyLoadedArcheryTargets(); } internal static void ApplyPrefabTuning(ZNetScene? scene = null) { if (scene == null) { scene = ZNetScene.instance; } if ((Object)(object)scene == (Object)null) { return; } string[] trainingDummyPrefabNames = TrainingDummyPrefabNames; foreach (string text in trainingDummyPrefabNames) { GameObject prefab = scene.GetPrefab(text); if (!((Object)(object)prefab == (Object)null)) { Character componentInChildren = prefab.GetComponentInChildren(true); if ((Object)(object)componentInChildren != (Object)null) { ApplyTrainingDummy(componentInChildren); } } } GameObject prefab2 = scene.GetPrefab("piece_ArcheryTarget"); if ((Object)(object)prefab2 != (Object)null) { ArcheryTarget componentInChildren2 = prefab2.GetComponentInChildren(true); if ((Object)(object)componentInChildren2 != (Object)null) { ApplyArcheryTarget(componentInChildren2); } } } internal static void ApplyTrainingDummy(Character character) { if (!((Object)(object)character == (Object)null) && TrainingDummyDamageTest.IsTrainingDummy(character)) { float trainingDummyHealth = GetTrainingDummyHealth(); ZNetView nview = character.m_nview; bool flag = (Object)(object)nview != (Object)null && nview.IsValid(); float num = Mathf.Max(0.001f, flag ? character.GetMaxHealth() : character.m_health); float num2 = Mathf.Max(0f, flag ? character.GetHealth() : num); float num3 = Mathf.Clamp01(num2 / num); bool flag2 = num2 >= num - 0.01f; character.m_health = trainingDummyHealth; if (!((Object)(object)nview == (Object)null) && nview.IsValid() && nview.IsOwner()) { character.SetMaxHealth(trainingDummyHealth); character.SetHealth(flag2 ? trainingDummyHealth : Mathf.Clamp(trainingDummyHealth * num3, 0f, trainingDummyHealth)); } } } internal static void ApplyArcheryTarget(ArcheryTarget archeryTarget) { if (!((Object)(object)archeryTarget == (Object)null)) { archeryTarget.m_raiseSkillMultiplier = GetArcheryTargetSkillMultiplier(); } } private static void ApplyLoadedTrainingDummies() { foreach (Character loadedDummy in TrainingDummyRegistry.GetLoadedDummies()) { ApplyTrainingDummy(loadedDummy); } } private static void ApplyLoadedArcheryTargets() { ArcheryTarget[] array = Object.FindObjectsByType((FindObjectsSortMode)0); for (int i = 0; i < array.Length; i++) { ApplyArcheryTarget(array[i]); } } private static float GetTrainingDummyHealth() { return Mathf.Clamp(TouchGrassPlugin._trainingDummyHealth?.Value ?? 2500f, 1f, 100000f); } private static float GetArcheryTargetSkillMultiplier() { return Mathf.Clamp(TouchGrassPlugin._archeryTargetSkillMultiplier?.Value ?? 1f, 0f, 10f); } } internal static class TrainingDummyRegistry { private static readonly HashSet LoadedDummies = new HashSet(); internal static void Register(Character character) { if (!((Object)(object)character == (Object)null) && TrainingDummyDamageTest.HasTrainingDummyZdoPrefab(character)) { LoadedDummies.Add(character); } } internal static void Unregister(Character character) { if (!((Object)(object)character == (Object)null)) { LoadedDummies.Remove(character); } } internal static IReadOnlyCollection GetLoadedDummies() { LoadedDummies.RemoveWhere((Character character) => (Object)(object)character == (Object)null); return LoadedDummies; } } internal static class TrainingDummyCrowding { private const string CrowdedMessage = "Too crowded Bro!"; internal static bool CanPlace(Player player, Piece piece) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)player == (Object)null || (Object)(object)piece == (Object)null || !TrainingDummyDamageTest.IsTrainingDummy(piece) || (Object)(object)player.m_placementGhost == (Object)null) { return true; } if (!IsCrowded(player.m_placementGhost.transform.position)) { return true; } ((Character)player).Message((MessageType)2, "Too crowded Bro!", 0, (Sprite)null); return false; } private static bool IsCrowded(Vector3 position) { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0086: 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) float num = Mathf.Clamp(TouchGrassPlugin._trainingDummyCrowdingRadius?.Value ?? 4f, 0f, 50f); int num2 = Mathf.Clamp(TouchGrassPlugin._trainingDummyCrowdingMaxCount?.Value ?? 4, 0, 100); if (num <= 0f || num2 <= 0) { return false; } float num3 = num * num; int num4 = 0; foreach (Character loadedDummy in TrainingDummyRegistry.GetLoadedDummies()) { if ((Object)(object)loadedDummy == (Object)null) { continue; } Vector3 position2 = ((Component)loadedDummy).transform.position; float num5 = position2.x - position.x; float num6 = position2.z - position.z; if (!(num5 * num5 + num6 * num6 > num3)) { num4++; if (num4 >= num2) { return true; } } } return false; } } internal static class TrainingMeter { internal sealed class IncomingDamageState { internal bool IsTrainingDummyHit; internal bool WasBlocking; internal float Time; internal float Health; internal float RawDamage; internal float BlockedDamage; internal string RawDamageType = ""; internal DamageTypes DamageAfterBlock; } private readonly struct OutgoingDamageEvent { internal readonly float Time; internal readonly float ImpactDamage; internal readonly float StatusDamage; public OutgoingDamageEvent(float time, float impactDamage, float statusDamage) { Time = time; ImpactDamage = impactDamage; StatusDamage = statusDamage; } } private readonly struct IncomingDamageEvent { internal readonly float Time; internal readonly float RawDamage; internal readonly string RawDamageType; internal readonly float BlockedDamage; internal readonly float ResistReduction; internal readonly float ArmorReduction; internal readonly float FinalDamage; internal readonly float StatusDamage; internal readonly string StatusDamageType; public IncomingDamageEvent(float time, float rawDamage, string rawDamageType, float blockedDamage, float resistReduction, float armorReduction, float finalDamage, float statusDamage, string statusDamageType) { Time = time; RawDamage = rawDamage; RawDamageType = rawDamageType; BlockedDamage = blockedDamage; ResistReduction = resistReduction; ArmorReduction = armorReduction; FinalDamage = finalDamage; StatusDamage = statusDamage; StatusDamageType = statusDamageType; } } private readonly struct SkillGainEvent { internal readonly float Time; internal readonly SkillType SkillType; internal readonly float SourceExp; internal readonly float FinalExp; internal readonly float Efficiency; public SkillGainEvent(float time, SkillType skillType, float sourceExp, float finalExp, float efficiency) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) Time = time; SkillType = skillType; SourceExp = sourceExp; FinalExp = finalExp; Efficiency = efficiency; } } private readonly struct DamageReductionBreakdown { internal readonly float ResistReduction; internal readonly float ArmorReduction; internal readonly float FinalDamage; internal readonly float StatusDamage; internal readonly string StatusDamageType; public DamageReductionBreakdown(float resistReduction, float armorReduction, float finalDamage, float statusDamage, string statusDamageType) { ResistReduction = resistReduction; ArmorReduction = armorReduction; FinalDamage = finalDamage; StatusDamage = statusDamage; StatusDamageType = statusDamageType; } } private const float HugeDamageThreshold = 1E+09f; private const string HudTitle = "TouchGrass Training Meter"; private const float HudPaddingX = 10f; private const float HudPaddingY = 8f; private const float HudLineSpacing = 2f; private const float HudHeaderSpacing = 4f; private const float HudHeightSafetyPadding = 8f; private const float HudHeightHoldSeconds = 0.35f; private const float HudScale = 1.6f; private const float HudBaseWidth = 420f; private const float DefaultHudAnchorX = 0.02f; private const float DefaultHudAnchorY = 0.86f; private static readonly List OutgoingDamageEvents = new List(); private static readonly List IncomingDamageEvents = new List(); private static readonly List SkillGainEvents = new List(); private static readonly HashSet DisplayedSkillTypes = new HashSet { (SkillType)1, (SkillType)2, (SkillType)3, (SkillType)4, (SkillType)5, (SkillType)6, (SkillType)7, (SkillType)8, (SkillType)14, (SkillType)11, (SkillType)12, (SkillType)13, (SkillType)9, (SkillType)10 }; private static float _lastTrainingDummyInteractionTime = -9999f; private static float _lastHudHeight; private static float _lastHudHeightHoldUntil = -9999f; private static Vector2 _hudPosition; private static Vector2 _hudDragOffset; private static bool _hudPositionInitialized; private static bool _isDraggingHud; private static IncomingDamageState? _activeIncomingDamageState; private static GUIStyle? _boxStyle; private static GUIStyle? _headerStyle; private static GUIStyle? _labelStyle; private static Texture2D? _backgroundTexture; private static float _styleScale = -1f; internal static void RecordOutgoingDamage(Character target, HitData hit) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) if (IsEnabled() && !((Object)(object)target == (Object)null) && hit != null && TrainingDummyDamageTest.IsTrainingDummy(target) && !((Object)(object)hit.GetAttacker() != (Object)(object)Player.m_localPlayer)) { float statusDamage = GetStatusDamage(hit.m_damage); float num = Mathf.Max(0f, ((DamageTypes)(ref hit.m_damage)).GetTotalDamage() - statusDamage); if ((!(num <= 0f) || !(statusDamage <= 0f)) && !(num + statusDamage > 1E+09f)) { float time = Time.time; MarkTrainingDummyInteraction(time); OutgoingDamageEvents.Add(new OutgoingDamageEvent(time, num, statusDamage)); Prune(time); } } } internal static IncomingDamageState BeforeIncomingDamage(Character victim, HitData hit) { //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) IncomingDamageState incomingDamageState = new IncomingDamageState(); if (!IsEnabled() || (Object)(object)victim == (Object)null || hit == null) { return incomingDamageState; } if ((Object)(object)victim != (Object)(object)Player.m_localPlayer) { return incomingDamageState; } _activeIncomingDamageState = null; if (!TrainingDummyDamageTest.IsTrainingDummy(hit.GetAttacker())) { return incomingDamageState; } _ = Player.m_localPlayer; float time = Time.time; MarkTrainingDummyInteraction(time); incomingDamageState.IsTrainingDummyHit = true; incomingDamageState.Time = time; incomingDamageState.Health = victim.GetHealth(); incomingDamageState.WasBlocking = hit.m_blockable && victim.IsBlocking(); incomingDamageState.RawDamage = ((DamageTypes)(ref hit.m_damage)).GetTotalDamage(); incomingDamageState.RawDamageType = GetDamageTypeText(hit.m_damage); incomingDamageState.DamageAfterBlock = ((DamageTypes)(ref hit.m_damage)).Clone(); _activeIncomingDamageState = incomingDamageState; return incomingDamageState; } internal static void AfterIncomingDamage(Character victim, IncomingDamageState state) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) if (state != null && state.IsTrainingDummyHit && !((Object)(object)victim == (Object)null) && !((Object)(object)victim != (Object)(object)Player.m_localPlayer)) { _activeIncomingDamageState = null; DamageReductionBreakdown damageReductionBreakdown = ComputeIncomingBreakdown(Player.m_localPlayer, state.DamageAfterBlock); IncomingDamageEvents.Add(new IncomingDamageEvent(state.Time, state.RawDamage, state.RawDamageType, state.BlockedDamage, damageReductionBreakdown.ResistReduction, damageReductionBreakdown.ArmorReduction, damageReductionBreakdown.FinalDamage, damageReductionBreakdown.StatusDamage, damageReductionBreakdown.StatusDamageType)); Prune(Time.time); } } internal static void RecordBlockResult(Humanoid blocker, HitData hit) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) if (_activeIncomingDamageState != null && _activeIncomingDamageState.IsTrainingDummyHit && !((Object)(object)blocker == (Object)null) && !((Object)(object)blocker != (Object)(object)Player.m_localPlayer) && hit != null) { _activeIncomingDamageState.DamageAfterBlock = ((DamageTypes)(ref hit.m_damage)).Clone(); _activeIncomingDamageState.BlockedDamage = Mathf.Max(0f, _activeIncomingDamageState.RawDamage - ((DamageTypes)(ref hit.m_damage)).GetTotalDamage()); } } internal static void RecordSkillGain(Skills skills, SkillType skillType, float sourceFactor, float finalFactor) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) if (!IsEnabled() || (Object)(object)skills == (Object)null || (Object)(object)skills.m_player != (Object)(object)Player.m_localPlayer || (int)skillType == 0 || !DisplayedSkillTypes.Contains(skillType)) { return; } float time = Time.time; if (IsTrainingSessionActive(time)) { float num = ComputeSkillExperience(skills, skillType, sourceFactor); float num2 = ComputeSkillExperience(skills, skillType, Mathf.Max(0f, finalFactor)); if (!(num <= 0f) || !(num2 <= 0f)) { float efficiency = ((num > 0f) ? Mathf.Clamp01(num2 / num) : 1f); SkillGainEvents.Add(new SkillGainEvent(time, skillType, num, num2, efficiency)); Prune(time); } } } internal static void OnGUI() { //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Expected O, but got Unknown //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Expected O, but got Unknown //IL_0159: Unknown result type (might be due to invalid IL or missing references) if (!IsEnabled() || (Object)(object)Player.m_localPlayer == (Object)null) { StopHudDrag(); return; } float time = Time.time; Prune(time); if (!IsTrainingSessionActive(time)) { StopHudDrag(); return; } List list = BuildHudLines(time); if (list.Count == 0) { StopHudDrag(); return; } float num = 1.6f; EnsureStyles(num); GUIStyle headerStyle = _headerStyle; GUIStyle labelStyle = _labelStyle; float num2 = 10f * num; float num3 = 8f * num; float num4 = 2f * num; float num5 = 4f * num; float hudWidth = GetHudWidth(); float num6 = hudWidth - num2 * 2f; float stableHudHeight = GetStableHudHeight(GetHudHeight(list, num6, headerStyle, labelStyle, num3, num4, num5, num), time); Rect val = GetHudRect(hudWidth, stableHudHeight); val = HandleHudDrag(val); GUI.Box(val, GUIContent.none, _boxStyle); float num7 = ((Rect)(ref val)).x + num2; float num8 = ((Rect)(ref val)).y + num3; float num9 = Mathf.Ceil(headerStyle.CalcHeight(new GUIContent("TouchGrass Training Meter"), num6)); GUI.Label(new Rect(num7, num8, num6, num9), "TouchGrass Training Meter", headerStyle); num8 += num9 + num5; foreach (string item in list) { float num10 = Mathf.Ceil(labelStyle.CalcHeight(new GUIContent(item), num6)); GUI.Label(new Rect(num7, num8, num6, num10), item, labelStyle); num8 += num10 + num4; } } private static List BuildHudLines(float now) { //IL_0461: Unknown result type (might be due to invalid IL or missing references) float num = now - GetWindowSeconds(); float num2 = now; float num3 = 0f; float num4 = 0f; float num5 = 0f; int num6 = 0; int num7 = 0; OutgoingDamageEvent? outgoingDamageEvent = null; IncomingDamageEvent? incomingDamageEvent = null; SkillGainEvent? skillGainEvent = null; foreach (OutgoingDamageEvent outgoingDamageEvent2 in OutgoingDamageEvents) { if (!(outgoingDamageEvent2.Time < num)) { num2 = Mathf.Min(num2, outgoingDamageEvent2.Time); num3 = Mathf.Max(num3, outgoingDamageEvent2.Time); num4 += outgoingDamageEvent2.ImpactDamage; num5 += outgoingDamageEvent2.StatusDamage; num6++; if (!outgoingDamageEvent.HasValue || outgoingDamageEvent2.Time > outgoingDamageEvent.Value.Time) { outgoingDamageEvent = outgoingDamageEvent2; } } } foreach (IncomingDamageEvent incomingDamageEvent2 in IncomingDamageEvents) { if (!(incomingDamageEvent2.Time < num)) { num2 = Mathf.Min(num2, incomingDamageEvent2.Time); num3 = Mathf.Max(num3, incomingDamageEvent2.Time); num7++; if (!incomingDamageEvent.HasValue || incomingDamageEvent2.Time > incomingDamageEvent.Value.Time) { incomingDamageEvent = incomingDamageEvent2; } } } foreach (SkillGainEvent skillGainEvent2 in SkillGainEvents) { if (!(skillGainEvent2.Time < num)) { num2 = Mathf.Min(num2, skillGainEvent2.Time); num3 = Mathf.Max(num3, skillGainEvent2.Time); if (!skillGainEvent.HasValue || skillGainEvent2.Time > skillGainEvent.Value.Time) { skillGainEvent = skillGainEvent2; } } } if (num6 == 0 && num7 == 0 && !skillGainEvent.HasValue) { return new List(); } if (num3 <= 0f) { num3 = now; } float num8 = Mathf.Max(1f, Mathf.Min(GetWindowSeconds(), now - num2)); float value = num4 / num8; float value2 = ((num6 > 0) ? (num4 / (float)num6) : 0f); List list = new List(); if (num6 > 0) { if (num5 > 0f) { list.Add("ToDummy: Status | Attempt | DPH | Hits | DPS | Time"); list.Add($"ToDummy: {FormatFloat(num5)} | {FormatFloat(num4)} | {FormatFloat(value2)} | {num6} | {FormatFloat(value)} | {FormatFloat(num8)}s"); } else { list.Add("ToDummy: Attempt | DPH | Hits | DPS | Time"); list.Add($"ToDummy: {FormatFloat(num4)} | {FormatFloat(value2)} | {num6} | {FormatFloat(value)} | {FormatFloat(num8)}s"); } } if (incomingDamageEvent.HasValue) { IncomingDamageEvent value3 = incomingDamageEvent.Value; string text = "Raw - Blocked - Resist - Armor = Final"; string text2 = string.Concat(FormatFloat(value3.RawDamage) + "(" + value3.RawDamageType + ") - " + FormatFloat(value3.BlockedDamage) + " - " + FormatSubtractedSigned(value3.ResistReduction) + " - " + FormatFloat(value3.ArmorReduction), " = ", FormatFloat(value3.FinalDamage)); if (value3.StatusDamage > 0f) { list.Add("FromDummy: " + text + " | Status"); list.Add("FromDummy: " + text2 + " | " + FormatFloat(value3.StatusDamage) + "(" + value3.StatusDamageType + ")"); } else { list.Add("FromDummy: " + text); list.Add("FromDummy: " + text2); } } if (skillGainEvent.HasValue) { SkillGainEvent value4 = skillGainEvent.Value; list.Add("Skill: " + FormatSkill(value4.SkillType) + " +" + FormatFloat(value4.FinalExp) + " / +" + FormatFloat(value4.SourceExp) + " exp (" + FormatPercent(value4.Efficiency) + ")"); } return list; } private static void MarkTrainingDummyInteraction(float now) { _lastTrainingDummyInteractionTime = now; } private static bool IsTrainingSessionActive(float now) { return now - _lastTrainingDummyInteractionTime <= GetWindowSeconds(); } private static bool IsEnabled() { if (TouchGrassPlugin._trainingMeterDisplay != null) { return TouchGrassPlugin._trainingMeterDisplay.Value != TouchGrassPlugin.TrainingMeterDisplay.Off; } return false; } private static float GetWindowSeconds() { return Mathf.Clamp(TouchGrassPlugin._trainingMeterWindowSeconds?.Value ?? 15f, 5f, 300f); } private static float GetHudWidth() { return Mathf.Clamp(672f, 240f, (float)Screen.width); } private static Rect GetHudRect(float width, float height) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: 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_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) if (!_hudPositionInitialized) { _hudPosition = new Vector2(0.02f * (float)Screen.width, 0.13999999f * (float)Screen.height); _hudPositionInitialized = true; } _hudPosition = ClampHudPosition(_hudPosition, width, height); return new Rect(_hudPosition.x, _hudPosition.y, width, height); } private static Rect HandleHudDrag(Rect rect) { //IL_0009: 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_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected I4, but got Unknown //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0078: 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_0082: 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_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) Event current = Event.current; if (current == null) { return rect; } if (_isDraggingHud && !Input.GetMouseButton(0)) { StopHudDrag(); } EventType type = current.type; switch ((int)type) { case 0: if (current.button == 0 && ((Rect)(ref rect)).Contains(current.mousePosition)) { _isDraggingHud = true; _hudDragOffset = current.mousePosition - new Vector2(((Rect)(ref rect)).x, ((Rect)(ref rect)).y); current.Use(); } break; case 3: if (current.button == 0 && _isDraggingHud) { _hudPosition = ClampHudPosition(current.mousePosition - _hudDragOffset, ((Rect)(ref rect)).width, ((Rect)(ref rect)).height); ((Rect)(ref rect)).position = _hudPosition; current.Use(); } break; case 1: if (current.button == 0 && _isDraggingHud) { _isDraggingHud = false; current.Use(); } break; } if (_isDraggingHud) { ((Rect)(ref rect)).position = _hudPosition; } return rect; } private static void StopHudDrag() { _isDraggingHud = false; } private static Vector2 ClampHudPosition(Vector2 position, float width, float height) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) position.x = Mathf.Clamp(position.x, 0f, Mathf.Max(0f, (float)Screen.width - width)); position.y = Mathf.Clamp(position.y, 0f, Mathf.Max(0f, (float)Screen.height - height)); return position; } private static float GetHudHeight(List lines, float contentWidth, GUIStyle headerStyle, GUIStyle labelStyle, float paddingY, float lineSpacing, float headerSpacing, float scale) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown float num = paddingY * 2f; num += Mathf.Ceil(headerStyle.CalcHeight(new GUIContent("TouchGrass Training Meter"), contentWidth)) + headerSpacing; foreach (string line in lines) { num += Mathf.Ceil(labelStyle.CalcHeight(new GUIContent(line), contentWidth)) + lineSpacing; } return num + 8f * scale; } private static float GetStableHudHeight(float desiredHeight, float now) { if (desiredHeight >= _lastHudHeight) { _lastHudHeight = desiredHeight; _lastHudHeightHoldUntil = now + 0.35f; return desiredHeight; } if (now <= _lastHudHeightHoldUntil) { return _lastHudHeight; } _lastHudHeight = desiredHeight; _lastHudHeightHoldUntil = now + 0.35f; return desiredHeight; } private static void Prune(float now) { float oldest = now - GetWindowSeconds(); OutgoingDamageEvents.RemoveAll((OutgoingDamageEvent e) => e.Time < oldest); IncomingDamageEvents.RemoveAll((IncomingDamageEvent e) => e.Time < oldest); SkillGainEvents.RemoveAll((SkillGainEvent e) => e.Time < oldest); } private static float ComputeSkillExperience(Skills skills, SkillType skillType, float factor) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (factor <= 0f) { return 0f; } Skill skill = skills.GetSkill(skillType); if (skill == null || skill.m_level >= 100f) { return 0f; } return skill.m_info.m_increseStep * factor * Game.m_skillGainRate; } private static DamageReductionBreakdown ComputeIncomingBreakdown(Player player, DamageTypes damageAfterBlock) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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) HitData val = new HitData { m_damage = ((DamageTypes)(ref damageAfterBlock)).Clone() }; float totalDamage = ((DamageTypes)(ref val.m_damage)).GetTotalDamage(); DamageModifier val2 = default(DamageModifier); val.ApplyResistance(((Character)player).GetDamageModifiers((WeakSpot)null), ref val2); float totalDamage2 = ((DamageTypes)(ref val.m_damage)).GetTotalDamage(); val.ApplyArmor(((Character)player).GetBodyArmor()); float totalDamage3 = ((DamageTypes)(ref val.m_damage)).GetTotalDamage(); float statusDamage = GetStatusDamage(val.m_damage); float num = Mathf.Max(0f, totalDamage3 - statusDamage); if (num <= 0.1f) { num = 0f; } return new DamageReductionBreakdown(totalDamage - totalDamage2, Mathf.Max(0f, totalDamage2 - totalDamage3), num, statusDamage, GetStatusDamageTypeText(val.m_damage)); } private static float GetStatusDamage(DamageTypes damage) { //IL_0005: 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_0026: Unknown result type (might be due to invalid IL or missing references) return Mathf.Max(0f, damage.m_fire) + Mathf.Max(0f, damage.m_poison) + Mathf.Max(0f, damage.m_spirit); } private static string GetStatusDamageTypeText(DamageTypes damage) { //IL_001d: 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_0041: Unknown result type (might be due to invalid IL or missing references) string name = "Status"; float value = 0f; UseIfHigher("Fire", damage.m_fire); UseIfHigher("Poison", damage.m_poison); UseIfHigher("Spirit", damage.m_spirit); if (!(value > 0f)) { return ""; } return name; void UseIfHigher(string candidateName, float candidateValue) { if (candidateValue > value) { name = candidateName; value = candidateValue; } } } private static string GetDamageTypeText(DamageTypes damage) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001e: 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_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_008a: 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) string name = "Generic"; float value = damage.m_damage; UseIfHigher("Blunt", damage.m_blunt); UseIfHigher("Slash", damage.m_slash); UseIfHigher("Pierce", damage.m_pierce); UseIfHigher("Fire", damage.m_fire); UseIfHigher("Frost", damage.m_frost); UseIfHigher("Lightning", damage.m_lightning); UseIfHigher("Poison", damage.m_poison); UseIfHigher("Spirit", damage.m_spirit); if (!(value > 0f)) { return "None"; } return name; void UseIfHigher(string candidateName, float candidateValue) { if (candidateValue > value) { name = candidateName; value = candidateValue; } } } private static string FormatSkill(SkillType skillType) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) if ((int)skillType == 0) { return "-"; } return SkillNameFormatter.Format(skillType); } private static string FormatFloat(float value) { if (value >= 100f) { return value.ToString("0"); } if (!(value >= 10f)) { return value.ToString("0.00"); } return value.ToString("0.0"); } private static string FormatPercent(float value) { return $"{Mathf.RoundToInt(Mathf.Clamp01(value) * 100f)}%"; } private static string FormatSigned(float value) { if (!(value >= 0f)) { return "- " + FormatFloat(Mathf.Abs(value)); } return "+ " + FormatFloat(value); } private static string FormatSubtractedSigned(float value) { if (!(value >= 0f)) { return "(" + FormatSigned(value) + ")"; } return FormatFloat(value); } private static void EnsureStyles(float scale) { //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Expected O, but got Unknown //IL_00de: Expected O, but got Unknown //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Expected O, but got Unknown //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0160: 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_0173: Expected O, but got Unknown //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown //IL_005f: Unknown result type (might be due to invalid IL or missing references) if (_boxStyle == null || _headerStyle == null || _labelStyle == null || !Mathf.Approximately(_styleScale, scale)) { _styleScale = scale; if ((Object)(object)_backgroundTexture == (Object)null) { _backgroundTexture = new Texture2D(1, 1, (TextureFormat)4, false); _backgroundTexture.SetPixel(0, 0, new Color(0.04f, 0.06f, 0.05f, 0.82f)); _backgroundTexture.Apply(false, true); Object.DontDestroyOnLoad((Object)(object)_backgroundTexture); } GUIStyle val = new GUIStyle(GUI.skin.box); val.normal.background = _backgroundTexture; val.border = new RectOffset(Mathf.RoundToInt(8f * scale), Mathf.RoundToInt(8f * scale), Mathf.RoundToInt(8f * scale), Mathf.RoundToInt(8f * scale)); _boxStyle = val; _headerStyle = new GUIStyle(GUI.skin.label) { fontSize = Mathf.Max(8, Mathf.RoundToInt(14f * scale)), richText = false }; _headerStyle.normal.textColor = new Color(0.82f, 1f, 0.78f, 1f); _labelStyle = new GUIStyle(GUI.skin.label) { fontSize = Mathf.Max(8, Mathf.RoundToInt(13f * scale)), richText = false, wordWrap = true }; _labelStyle.normal.textColor = Color.white; } } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] public static class RegisterAndCheckVersion { private static void Prefix(ZNetPeer peer, ref ZNet __instance) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown TouchGrassPlugin.TouchGrassLogger.LogDebug((object)"Registering version RPC handler"); peer.m_rpc.Register("TouchGrass_VersionCheck", (Action)RpcHandlers.RPC_TouchGrass_Version); TouchGrassPlugin.TouchGrassLogger.LogInfo((object)"Invoking version check"); ZPackage val = new ZPackage(); val.Write("1.0.0"); peer.m_rpc.Invoke("TouchGrass_VersionCheck", new object[1] { val }); } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] public static class VerifyClient { private static bool Prefix(ZRpc rpc, ZPackage pkg, ref ZNet __instance) { if (!__instance.IsServer() || RpcHandlers.ValidatedPeers.Contains(rpc)) { return true; } TouchGrassPlugin.TouchGrassLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") never sent version or couldn't due to previous disconnect, disconnecting")); rpc.Invoke("Error", new object[1] { 3 }); return false; } private static void Postfix(ZNet __instance) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "TouchGrassRequestAdminSync", new object[1] { (object)new ZPackage() }); } } [HarmonyPatch(typeof(FejdStartup), "ShowConnectError")] public class ShowConnectionError { private static void Postfix(FejdStartup __instance) { if (__instance.m_connectionFailedPanel.activeSelf) { __instance.m_connectionFailedError.fontSizeMax = 25f; __instance.m_connectionFailedError.fontSizeMin = 15f; TMP_Text connectionFailedError = __instance.m_connectionFailedError; connectionFailedError.text = connectionFailedError.text + "\n" + TouchGrassPlugin.ConnectionError; } } } [HarmonyPatch(typeof(ZNet), "Disconnect")] public static class RemoveDisconnectedPeerFromVerified { private static void Prefix(ZNetPeer peer, ref ZNet __instance) { if (__instance.IsServer()) { TouchGrassPlugin.TouchGrassLogger.LogInfo((object)("Peer (" + peer.m_rpc.m_socket.GetHostName() + ") disconnected, removing from validated list")); RpcHandlers.ValidatedPeers.Remove(peer.m_rpc); } } } public static class RpcHandlers { public static readonly List ValidatedPeers = new List(); public static void RPC_TouchGrass_Version(ZRpc rpc, ZPackage pkg) { string text = pkg.ReadString(); TouchGrassPlugin.TouchGrassLogger.LogInfo((object)("Version check, local: 1.0.0, remote: " + text)); if (text != "1.0.0") { TouchGrassPlugin.ConnectionError = "TouchGrass Installed: 1.0.0\n Needed: " + text; if (ZNet.instance.IsServer()) { TouchGrassPlugin.TouchGrassLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") has incompatible version, disconnecting...")); rpc.Invoke("Error", new object[1] { 3 }); } } else if (!ZNet.instance.IsServer()) { TouchGrassPlugin.TouchGrassLogger.LogInfo((object)"Received same version from server!"); } else { TouchGrassPlugin.TouchGrassLogger.LogInfo((object)("Adding peer (" + rpc.m_socket.GetHostName() + ") to validated list")); ValidatedPeers.Add(rpc); } } } } namespace ServerSync { [PublicAPI] internal abstract class OwnConfigEntryBase { public object? LocalBaseValue; public bool SynchronizedConfig = true; public abstract ConfigEntryBase BaseConfig { get; } } [PublicAPI] internal class SyncedConfigEntry : OwnConfigEntryBase { public readonly ConfigEntry SourceConfig; public override ConfigEntryBase BaseConfig => (ConfigEntryBase)(object)SourceConfig; public T Value { get { return SourceConfig.Value; } set { SourceConfig.Value = value; } } public SyncedConfigEntry(ConfigEntry sourceConfig) { SourceConfig = sourceConfig; base..ctor(); } public void AssignLocalValue(T value) { if (LocalBaseValue == null) { Value = value; } else { LocalBaseValue = value; } } } internal abstract class CustomSyncedValueBase { public object? LocalBaseValue; public readonly string Identifier; public readonly Type Type; private object? boxedValue; protected bool localIsOwner; public readonly int Priority; public object? BoxedValue { get { return boxedValue; } set { boxedValue = value; this.ValueChanged?.Invoke(); } } public event Action? ValueChanged; protected CustomSyncedValueBase(ConfigSync configSync, string identifier, Type type, int priority) { Priority = priority; Identifier = identifier; Type = type; configSync.AddCustomValue(this); localIsOwner = configSync.IsSourceOfTruth; configSync.SourceOfTruthChanged += delegate(bool truth) { localIsOwner = truth; }; } } [PublicAPI] internal sealed class CustomSyncedValue : CustomSyncedValueBase { public T Value { get { return (T)base.BoxedValue; } set { base.BoxedValue = value; } } public CustomSyncedValue(ConfigSync configSync, string identifier, T value = default(T), int priority = 0) : base(configSync, identifier, typeof(T), priority) { Value = value; } public void AssignLocalValue(T value) { if (localIsOwner) { Value = value; } else { LocalBaseValue = value; } } } internal class ConfigurationManagerAttributes { [UsedImplicitly] public bool? ReadOnly = false; } [PublicAPI] internal class ConfigSync { [HarmonyPatch(typeof(ZRpc), "HandlePackage")] private static class SnatchCurrentlyHandlingRPC { public static ZRpc? currentRpc; [HarmonyPrefix] private static void Prefix(ZRpc __instance) { currentRpc = __instance; } } [HarmonyPatch(typeof(ZNet), "Awake")] internal static class RegisterRPCPatch { [HarmonyPostfix] private static void Postfix(ZNet __instance) { isServer = __instance.IsServer(); foreach (ConfigSync configSync2 in configSyncs) { ZRoutedRpc.instance.Register(configSync2.Name + " ConfigSync", (Action)configSync2.RPC_FromOtherClientConfigSync); if (isServer) { configSync2.InitialSyncDone = true; Debug.Log((object)("Registered '" + configSync2.Name + " ConfigSync' RPC - waiting for incoming connections")); } } if (isServer) { ((MonoBehaviour)__instance).StartCoroutine(WatchAdminListChanges()); } static void SendAdmin(List peers, bool isAdmin) { ZPackage package = ConfigsToPackage(null, null, new PackageEntry[1] { new PackageEntry { section = "Internal", key = "lockexempt", type = typeof(bool), value = isAdmin } }); ConfigSync configSync = configSyncs.First(); if (configSync != null) { ((MonoBehaviour)ZNet.instance).StartCoroutine(configSync.sendZPackage(peers, package)); } } static IEnumerator WatchAdminListChanges() { MethodInfo listContainsId = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); SyncedList adminList = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance); List CurrentList = new List(adminList.GetList()); while (true) { yield return (object)new WaitForSeconds(30f); if (!adminList.GetList().SequenceEqual(CurrentList)) { CurrentList = new List(adminList.GetList()); List adminPeer = ZNet.instance.GetPeers().Where(delegate(ZNetPeer p) { string hostName = p.m_rpc.GetSocket().GetHostName(); return ((object)listContainsId == null) ? adminList.Contains(hostName) : ((bool)listContainsId.Invoke(ZNet.instance, new object[2] { adminList, hostName })); }).ToList(); List nonAdminPeer = ZNet.instance.GetPeers().Except(adminPeer).ToList(); SendAdmin(nonAdminPeer, isAdmin: false); SendAdmin(adminPeer, isAdmin: true); } } } } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] private static class RegisterClientRPCPatch { [HarmonyPostfix] private static void Postfix(ZNet __instance, ZNetPeer peer) { if (__instance.IsServer()) { return; } foreach (ConfigSync configSync in configSyncs) { peer.m_rpc.Register(configSync.Name + " ConfigSync", (Action)configSync.RPC_FromServerConfigSync); } } } private class ParsedConfigs { public readonly Dictionary configValues = new Dictionary(); public readonly Dictionary customValues = new Dictionary(); } [HarmonyPatch(typeof(ZNet), "Shutdown")] private class ResetConfigsOnShutdown { [HarmonyPostfix] private static void Postfix() { ProcessingServerUpdate = true; foreach (ConfigSync configSync in configSyncs) { configSync.resetConfigsFromServer(); configSync.IsSourceOfTruth = true; configSync.InitialSyncDone = false; } ProcessingServerUpdate = false; } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] private class SendConfigsAfterLogin { private class BufferingSocket : ZPlayFabSocket, ISocket { public volatile bool finished = false; public volatile int versionMatchQueued = -1; public readonly List Package = new List(); public readonly ISocket Original; public BufferingSocket(ISocket original) { Original = original; ((ZPlayFabSocket)this)..ctor(); } public bool IsConnected() { return Original.IsConnected(); } public ZPackage Recv() { return Original.Recv(); } public int GetSendQueueSize() { return Original.GetSendQueueSize(); } public int GetCurrentSendRate() { return Original.GetCurrentSendRate(); } public bool IsHost() { return Original.IsHost(); } public void Dispose() { Original.Dispose(); } public bool GotNewData() { return Original.GotNewData(); } public void Close() { Original.Close(); } public string GetEndPointString() { return Original.GetEndPointString(); } public void GetAndResetStats(out int totalSent, out int totalRecv) { Original.GetAndResetStats(ref totalSent, ref totalRecv); } public void GetConnectionQuality(out float localQuality, out float remoteQuality, out int ping, out float outByteSec, out float inByteSec) { Original.GetConnectionQuality(ref localQuality, ref remoteQuality, ref ping, ref outByteSec, ref inByteSec); } public ISocket Accept() { return Original.Accept(); } public int GetHostPort() { return Original.GetHostPort(); } public bool Flush() { return Original.Flush(); } public string GetHostName() { return Original.GetHostName(); } public void VersionMatch() { if (finished) { Original.VersionMatch(); } else { versionMatchQueued = Package.Count; } } public void Send(ZPackage pkg) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown int pos = pkg.GetPos(); pkg.SetPos(0); int num = pkg.ReadInt(); if ((num == StringExtensionMethods.GetStableHashCode("PeerInfo") || num == StringExtensionMethods.GetStableHashCode("RoutedRPC") || num == StringExtensionMethods.GetStableHashCode("ZDOData")) && !finished) { ZPackage val = new ZPackage(pkg.GetArray()); val.SetPos(pos); Package.Add(val); } else { pkg.SetPos(pos); Original.Send(pkg); } } } [HarmonyPriority(800)] [HarmonyPrefix] private static void Prefix(ref Dictionary? __state, ZNet __instance, ZRpc rpc) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Invalid comparison between Unknown and I4 if (!__instance.IsServer()) { return; } BufferingSocket bufferingSocket = new BufferingSocket(rpc.GetSocket()); AccessTools.DeclaredField(typeof(ZRpc), "m_socket").SetValue(rpc, bufferingSocket); object? obj = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc }); ZNetPeer val = (ZNetPeer)((obj is ZNetPeer) ? obj : null); if (val != null && (int)ZNet.m_onlineBackend > 0) { FieldInfo fieldInfo = AccessTools.DeclaredField(typeof(ZNetPeer), "m_socket"); object? value = fieldInfo.GetValue(val); ZPlayFabSocket val2 = (ZPlayFabSocket)((value is ZPlayFabSocket) ? value : null); if (val2 != null) { typeof(ZPlayFabSocket).GetField("m_remotePlayerId").SetValue(bufferingSocket, val2.m_remotePlayerId); } fieldInfo.SetValue(val, bufferingSocket); } if (__state == null) { __state = new Dictionary(); } __state[Assembly.GetExecutingAssembly()] = bufferingSocket; } [HarmonyPostfix] private static void Postfix(Dictionary __state, ZNet __instance, ZRpc rpc) { ZRpc rpc2 = rpc; ZNet __instance2 = __instance; Dictionary __state2 = __state; ZNetPeer peer; if (__instance2.IsServer()) { object obj = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance2, new object[1] { rpc2 }); peer = (ZNetPeer)((obj is ZNetPeer) ? obj : null); if (peer == null) { SendBufferedData(); } else { ((MonoBehaviour)__instance2).StartCoroutine(sendAsync()); } } void SendBufferedData() { if (rpc2.GetSocket() is BufferingSocket bufferingSocket) { AccessTools.DeclaredField(typeof(ZRpc), "m_socket").SetValue(rpc2, bufferingSocket.Original); object? obj2 = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance2, new object[1] { rpc2 }); ZNetPeer val = (ZNetPeer)((obj2 is ZNetPeer) ? obj2 : null); if (val != null) { AccessTools.DeclaredField(typeof(ZNetPeer), "m_socket").SetValue(val, bufferingSocket.Original); } } BufferingSocket bufferingSocket2 = __state2[Assembly.GetExecutingAssembly()]; bufferingSocket2.finished = true; for (int i = 0; i < bufferingSocket2.Package.Count; i++) { if (i == bufferingSocket2.versionMatchQueued) { bufferingSocket2.Original.VersionMatch(); } bufferingSocket2.Original.Send(bufferingSocket2.Package[i]); } if (bufferingSocket2.Package.Count == bufferingSocket2.versionMatchQueued) { bufferingSocket2.Original.VersionMatch(); } } IEnumerator sendAsync() { foreach (ConfigSync configSync in configSyncs) { List entries = new List(); if (configSync.CurrentVersion != null) { entries.Add(new PackageEntry { section = "Internal", key = "serverversion", type = typeof(string), value = configSync.CurrentVersion }); } MethodInfo listContainsId = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); SyncedList adminList = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance); entries.Add(new PackageEntry { section = "Internal", key = "lockexempt", type = typeof(bool), value = (((object)listContainsId == null) ? ((object)adminList.Contains(rpc2.GetSocket().GetHostName())) : listContainsId.Invoke(ZNet.instance, new object[2] { adminList, rpc2.GetSocket().GetHostName() })) }); ZPackage package = ConfigsToPackage(configSync.allConfigs.Select((OwnConfigEntryBase c) => c.BaseConfig), configSync.allCustomValues, entries, partial: false); yield return ((MonoBehaviour)__instance2).StartCoroutine(configSync.sendZPackage(new List { peer }, package)); } SendBufferedData(); } } } private class PackageEntry { public string section = null; public string key = null; public Type type = null; public object? value; } [HarmonyPatch(typeof(ConfigEntryBase), "GetSerializedValue")] private static class PreventSavingServerInfo { [HarmonyPrefix] private static bool Prefix(ConfigEntryBase __instance, ref string __result) { OwnConfigEntryBase ownConfigEntryBase = configData(__instance); if (ownConfigEntryBase == null || isWritableConfig(ownConfigEntryBase)) { return true; } __result = TomlTypeConverter.ConvertToString(ownConfigEntryBase.LocalBaseValue, __instance.SettingType); return false; } } [HarmonyPatch(typeof(ConfigEntryBase), "SetSerializedValue")] private static class PreventConfigRereadChangingValues { [HarmonyPrefix] private static bool Prefix(ConfigEntryBase __instance, string value) { OwnConfigEntryBase ownConfigEntryBase = configData(__instance); if (ownConfigEntryBase == null || ownConfigEntryBase.LocalBaseValue == null) { return true; } try { ownConfigEntryBase.LocalBaseValue = TomlTypeConverter.ConvertToValue(value, __instance.SettingType); } catch (Exception ex) { Debug.LogWarning((object)$"Config value of setting \"{__instance.Definition}\" could not be parsed and will be ignored. Reason: {ex.Message}; Value: {value}"); } return false; } } private class InvalidDeserializationTypeException : Exception { public string expected = null; public string received = null; public string field = ""; } public static bool ProcessingServerUpdate; public readonly string Name; public string? DisplayName; public string? CurrentVersion; public string? MinimumRequiredVersion; public bool ModRequired = false; private bool? forceConfigLocking; private bool isSourceOfTruth = true; private static readonly HashSet configSyncs; private readonly HashSet allConfigs = new HashSet(); private HashSet allCustomValues = new HashSet(); private static bool isServer; private static bool lockExempt; private OwnConfigEntryBase? lockedConfig = null; private const byte PARTIAL_CONFIGS = 1; private const byte FRAGMENTED_CONFIG = 2; private const byte COMPRESSED_CONFIG = 4; private readonly Dictionary> configValueCache = new Dictionary>(); private readonly List> cacheExpirations = new List>(); private static long packageCounter; public bool IsLocked { get { bool? flag = forceConfigLocking; bool num; if (!flag.HasValue) { if (lockedConfig == null) { goto IL_0052; } num = ((IConvertible)lockedConfig.BaseConfig.BoxedValue).ToInt32(CultureInfo.InvariantCulture) != 0; } else { num = flag.GetValueOrDefault(); } if (!num) { goto IL_0052; } int result = ((!lockExempt) ? 1 : 0); goto IL_0053; IL_0053: return (byte)result != 0; IL_0052: result = 0; goto IL_0053; } set { forceConfigLocking = value; } } public bool IsAdmin => lockExempt || isSourceOfTruth; public bool IsSourceOfTruth { get { return isSourceOfTruth; } private set { if (value != isSourceOfTruth) { isSourceOfTruth = value; this.SourceOfTruthChanged?.Invoke(value); } } } public bool InitialSyncDone { get; private set; } = false; public event Action? SourceOfTruthChanged; private event Action? lockedConfigChanged; static ConfigSync() { ProcessingServerUpdate = false; configSyncs = new HashSet(); lockExempt = false; packageCounter = 0L; RuntimeHelpers.RunClassConstructor(typeof(VersionCheck).TypeHandle); } public ConfigSync(string name) { Name = name; configSyncs.Add(this); new VersionCheck(this); } public SyncedConfigEntry AddConfigEntry(ConfigEntry configEntry) { ConfigEntry configEntry2 = configEntry; OwnConfigEntryBase ownConfigEntryBase = configData((ConfigEntryBase)(object)configEntry2); SyncedConfigEntry syncedEntry = ownConfigEntryBase as SyncedConfigEntry; if (syncedEntry == null) { syncedEntry = new SyncedConfigEntry(configEntry2); AccessTools.DeclaredField(typeof(ConfigDescription), "k__BackingField").SetValue(((ConfigEntryBase)configEntry2).Description, new object[1] { new ConfigurationManagerAttributes() }.Concat(((ConfigEntryBase)configEntry2).Description.Tags ?? Array.Empty()).Concat(new SyncedConfigEntry[1] { syncedEntry }).ToArray()); configEntry2.SettingChanged += delegate { if (!ProcessingServerUpdate && syncedEntry.SynchronizedConfig) { Broadcast(ZRoutedRpc.Everybody, (ConfigEntryBase)configEntry2); } }; allConfigs.Add(syncedEntry); } return syncedEntry; } public SyncedConfigEntry AddLockingConfigEntry(ConfigEntry lockingConfig) where T : IConvertible { if (lockedConfig != null) { throw new Exception("Cannot initialize locking ConfigEntry twice"); } lockedConfig = AddConfigEntry(lockingConfig); lockingConfig.SettingChanged += delegate { this.lockedConfigChanged?.Invoke(); }; return (SyncedConfigEntry)lockedConfig; } internal void AddCustomValue(CustomSyncedValueBase customValue) { CustomSyncedValueBase customValue2 = customValue; if (allCustomValues.Select((CustomSyncedValueBase v) => v.Identifier).Concat(new string[1] { "serverversion" }).Contains(customValue2.Identifier)) { throw new Exception("Cannot have multiple settings with the same name or with a reserved name (serverversion)"); } allCustomValues.Add(customValue2); allCustomValues = new HashSet(allCustomValues.OrderByDescending((CustomSyncedValueBase v) => v.Priority)); customValue2.ValueChanged += delegate { if (!ProcessingServerUpdate) { Broadcast(ZRoutedRpc.Everybody, customValue2); } }; } private void RPC_FromServerConfigSync(ZRpc rpc, ZPackage package) { lockedConfigChanged += serverLockedSettingChanged; IsSourceOfTruth = false; if (HandleConfigSyncRPC(0L, package, clientUpdate: false)) { InitialSyncDone = true; } } private void RPC_FromOtherClientConfigSync(long sender, ZPackage package) { HandleConfigSyncRPC(sender, package, clientUpdate: true); } private bool HandleConfigSyncRPC(long sender, ZPackage package, bool clientUpdate) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Expected O, but got Unknown //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Expected O, but got Unknown try { if (isServer && IsLocked) { ZRpc? currentRpc = SnatchCurrentlyHandlingRPC.currentRpc; object obj; if (currentRpc == null) { obj = null; } else { ISocket socket = currentRpc.GetSocket(); obj = ((socket != null) ? socket.GetHostName() : null); } string text = (string)obj; if (text != null) { MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); SyncedList val = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance); if (!(((object)methodInfo == null) ? val.Contains(text) : ((bool)methodInfo.Invoke(ZNet.instance, new object[2] { val, text })))) { return false; } } } cacheExpirations.RemoveAll(delegate(KeyValuePair kv) { if (kv.Key < DateTimeOffset.Now.Ticks) { configValueCache.Remove(kv.Value); return true; } return false; }); byte b = package.ReadByte(); if ((b & 2u) != 0) { long num = package.ReadLong(); string text2 = sender.ToString() + num; if (!configValueCache.TryGetValue(text2, out SortedDictionary value)) { value = new SortedDictionary(); configValueCache[text2] = value; cacheExpirations.Add(new KeyValuePair(DateTimeOffset.Now.AddSeconds(60.0).Ticks, text2)); } int key = package.ReadInt(); int num2 = package.ReadInt(); value.Add(key, package.ReadByteArray()); if (value.Count < num2) { return false; } configValueCache.Remove(text2); package = new ZPackage(value.Values.SelectMany((byte[] a) => a).ToArray()); b = package.ReadByte(); } ProcessingServerUpdate = true; if ((b & 4u) != 0) { byte[] buffer = package.ReadByteArray(); MemoryStream stream = new MemoryStream(buffer); MemoryStream memoryStream = new MemoryStream(); using (DeflateStream deflateStream = new DeflateStream(stream, CompressionMode.Decompress)) { deflateStream.CopyTo(memoryStream); } package = new ZPackage(memoryStream.ToArray()); b = package.ReadByte(); } if ((b & 1) == 0) { resetConfigsFromServer(); } ParsedConfigs parsedConfigs = ReadConfigsFromPackage(package); ConfigFile val2 = null; bool saveOnConfigSet = false; foreach (KeyValuePair configValue in parsedConfigs.configValues) { if (!isServer && configValue.Key.LocalBaseValue == null) { configValue.Key.LocalBaseValue = configValue.Key.BaseConfig.BoxedValue; } if (val2 == null) { val2 = configValue.Key.BaseConfig.ConfigFile; saveOnConfigSet = val2.SaveOnConfigSet; val2.SaveOnConfigSet = false; } configValue.Key.BaseConfig.BoxedValue = configValue.Value; } if (val2 != null) { val2.SaveOnConfigSet = saveOnConfigSet; val2.Save(); } foreach (KeyValuePair customValue in parsedConfigs.customValues) { if (!isServer) { CustomSyncedValueBase key2 = customValue.Key; if (key2.LocalBaseValue == null) { key2.LocalBaseValue = customValue.Key.BoxedValue; } } customValue.Key.BoxedValue = customValue.Value; } Debug.Log((object)string.Format("Received {0} configs and {1} custom values from {2} for mod {3}", parsedConfigs.configValues.Count, parsedConfigs.customValues.Count, (isServer || clientUpdate) ? $"client {sender}" : "the server", DisplayName ?? Name)); if (!isServer) { serverLockedSettingChanged(); } return true; } finally { ProcessingServerUpdate = false; } } private ParsedConfigs ReadConfigsFromPackage(ZPackage package) { ParsedConfigs parsedConfigs = new ParsedConfigs(); Dictionary dictionary = allConfigs.Where((OwnConfigEntryBase c) => c.SynchronizedConfig).ToDictionary((OwnConfigEntryBase c) => c.BaseConfig.Definition.Section + "_" + c.BaseConfig.Definition.Key, (OwnConfigEntryBase c) => c); Dictionary dictionary2 = allCustomValues.ToDictionary((CustomSyncedValueBase c) => c.Identifier, (CustomSyncedValueBase c) => c); int num = package.ReadInt(); for (int i = 0; i < num; i++) { string text = package.ReadString(); string text2 = package.ReadString(); string text3 = package.ReadString(); Type type = Type.GetType(text3); if (text3 == "" || type != null) { object obj; try { obj = ((text3 == "") ? null : ReadValueWithTypeFromZPackage(package, type)); } catch (InvalidDeserializationTypeException ex) { Debug.LogWarning((object)("Got unexpected struct internal type " + ex.received + " for field " + ex.field + " struct " + text3 + " for " + text2 + " in section " + text + " for mod " + (DisplayName ?? Name) + ", expecting " + ex.expected)); continue; } OwnConfigEntryBase value2; if (text == "Internal") { CustomSyncedValueBase value; if (text2 == "serverversion") { if (obj?.ToString() != CurrentVersion) { Debug.LogWarning((object)("Received server version is not equal: server version = " + (obj?.ToString() ?? "null") + "; local version = " + (CurrentVersion ?? "unknown"))); } } else if (text2 == "lockexempt") { if (obj is bool flag) { lockExempt = flag; } } else if (dictionary2.TryGetValue(text2, out value)) { if ((text3 == "" && (!value.Type.IsValueType || Nullable.GetUnderlyingType(value.Type) != null)) || GetZPackageTypeString(value.Type) == text3) { parsedConfigs.customValues[value] = obj; continue; } Debug.LogWarning((object)("Got unexpected type " + text3 + " for internal value " + text2 + " for mod " + (DisplayName ?? Name) + ", expecting " + value.Type.AssemblyQualifiedName)); } } else if (dictionary.TryGetValue(text + "_" + text2, out value2)) { Type type2 = configType(value2.BaseConfig); if ((text3 == "" && (!type2.IsValueType || Nullable.GetUnderlyingType(type2) != null)) || GetZPackageTypeString(type2) == text3) { parsedConfigs.configValues[value2] = obj; continue; } Debug.LogWarning((object)("Got unexpected type " + text3 + " for " + text2 + " in section " + text + " for mod " + (DisplayName ?? Name) + ", expecting " + type2.AssemblyQualifiedName)); } else { Debug.LogWarning((object)("Received unknown config entry " + text2 + " in section " + text + " for mod " + (DisplayName ?? Name) + ". This may happen if client and server versions of the mod do not match.")); } continue; } Debug.LogWarning((object)("Got invalid type " + text3 + ", abort reading of received configs")); return new ParsedConfigs(); } return parsedConfigs; } private static bool isWritableConfig(OwnConfigEntryBase config) { OwnConfigEntryBase config2 = config; ConfigSync configSync = configSyncs.FirstOrDefault((ConfigSync cs) => cs.allConfigs.Contains(config2)); if (configSync == null) { return true; } return configSync.IsSourceOfTruth || !config2.SynchronizedConfig || config2.LocalBaseValue == null || (!configSync.IsLocked && (config2 != configSync.lockedConfig || lockExempt)); } private void serverLockedSettingChanged() { foreach (OwnConfigEntryBase allConfig in allConfigs) { configAttribute(allConfig.BaseConfig).ReadOnly = !isWritableConfig(allConfig); } } private void resetConfigsFromServer() { ConfigFile val = null; bool saveOnConfigSet = false; foreach (OwnConfigEntryBase item in allConfigs.Where((OwnConfigEntryBase config) => config.LocalBaseValue != null)) { if (val == null) { val = item.BaseConfig.ConfigFile; saveOnConfigSet = val.SaveOnConfigSet; val.SaveOnConfigSet = false; } item.BaseConfig.BoxedValue = item.LocalBaseValue; item.LocalBaseValue = null; } if (val != null) { val.SaveOnConfigSet = saveOnConfigSet; } foreach (CustomSyncedValueBase item2 in allCustomValues.Where((CustomSyncedValueBase config) => config.LocalBaseValue != null)) { item2.BoxedValue = item2.LocalBaseValue; item2.LocalBaseValue = null; } lockedConfigChanged -= serverLockedSettingChanged; serverLockedSettingChanged(); } private IEnumerator distributeConfigToPeers(ZNetPeer peer, ZPackage package) { ZNetPeer peer2 = peer; ZRoutedRpc rpc = ZRoutedRpc.instance; if (rpc == null) { yield break; } byte[] data = package.GetArray(); if (data != null && data.LongLength > 250000) { int fragments = (int)(1 + (data.LongLength - 1) / 250000); long packageIdentifier = ++packageCounter; int fragment = 0; while (fragment < fragments) { foreach (bool item in waitForQueue()) { yield return item; } if (peer2.m_socket.IsConnected()) { ZPackage fragmentedPackage = new ZPackage(); fragmentedPackage.Write((byte)2); fragmentedPackage.Write(packageIdentifier); fragmentedPackage.Write(fragment); fragmentedPackage.Write(fragments); fragmentedPackage.Write(data.Skip(250000 * fragment).Take(250000).ToArray()); SendPackage(fragmentedPackage); if (fragment != fragments - 1) { yield return true; } int num = fragment + 1; fragment = num; continue; } break; } yield break; } foreach (bool item2 in waitForQueue()) { yield return item2; } SendPackage(package); void SendPackage(ZPackage pkg) { string text = Name + " ConfigSync"; if (isServer) { peer2.m_rpc.Invoke(text, new object[1] { pkg }); } else { rpc.InvokeRoutedRPC(peer2.m_server ? 0 : peer2.m_uid, text, new object[1] { pkg }); } } IEnumerable waitForQueue() { float timeout = Time.time + 30f; while (peer2.m_socket.GetSendQueueSize() > 20000) { if (Time.time > timeout) { Debug.Log((object)$"Disconnecting {peer2.m_uid} after 30 seconds config sending timeout"); peer2.m_rpc.Invoke("Error", new object[1] { (object)(ConnectionStatus)5 }); ZNet.instance.Disconnect(peer2); break; } yield return false; } } } private IEnumerator sendZPackage(long target, ZPackage package) { if (!Object.op_Implicit((Object)(object)ZNet.instance)) { return Enumerable.Empty().GetEnumerator(); } List list = (List)AccessTools.DeclaredField(typeof(ZRoutedRpc), "m_peers").GetValue(ZRoutedRpc.instance); if (target != ZRoutedRpc.Everybody) { list = list.Where((ZNetPeer p) => p.m_uid == target).ToList(); } return sendZPackage(list, package); } private IEnumerator sendZPackage(List peers, ZPackage package) { ZPackage package2 = package; if (!Object.op_Implicit((Object)(object)ZNet.instance)) { yield break; } byte[] rawData = package2.GetArray(); if (rawData != null && rawData.LongLength > 10000) { ZPackage compressedPackage = new ZPackage(); compressedPackage.Write((byte)4); MemoryStream output = new MemoryStream(); using (DeflateStream deflateStream = new DeflateStream(output, CompressionLevel.Optimal)) { deflateStream.Write(rawData, 0, rawData.Length); } compressedPackage.Write(output.ToArray()); package2 = compressedPackage; } List> writers = (from peer in peers where peer.IsReady() select peer into p select distributeConfigToPeers(p, package2)).ToList(); writers.RemoveAll((IEnumerator writer) => !writer.MoveNext()); while (writers.Count > 0) { yield return null; writers.RemoveAll((IEnumerator writer) => !writer.MoveNext()); } } private void Broadcast(long target, params ConfigEntryBase[] configs) { if (!IsLocked || isServer) { ZPackage package = ConfigsToPackage(configs); ZNet instance = ZNet.instance; if (instance != null) { ((MonoBehaviour)instance).StartCoroutine(sendZPackage(target, package)); } } } private void Broadcast(long target, params CustomSyncedValueBase[] customValues) { if (!IsLocked || isServer) { ZPackage package = ConfigsToPackage(null, customValues); ZNet instance = ZNet.instance; if (instance != null) { ((MonoBehaviour)instance).StartCoroutine(sendZPackage(target, package)); } } } private static OwnConfigEntryBase? configData(ConfigEntryBase config) { return config.Description.Tags?.OfType().SingleOrDefault(); } public static SyncedConfigEntry? ConfigData(ConfigEntry config) { return ((ConfigEntryBase)config).Description.Tags?.OfType>().SingleOrDefault(); } private static T configAttribute(ConfigEntryBase config) { return config.Description.Tags.OfType().First(); } private static Type configType(ConfigEntryBase config) { return configType(config.SettingType); } private static Type configType(Type type) { return type.IsEnum ? Enum.GetUnderlyingType(type) : type; } private static ZPackage ConfigsToPackage(IEnumerable? configs = null, IEnumerable? customValues = null, IEnumerable? packageEntries = null, bool partial = true) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown List list = configs?.Where((ConfigEntryBase config) => configData(config).SynchronizedConfig).ToList() ?? new List(); List list2 = customValues?.ToList() ?? new List(); ZPackage val = new ZPackage(); val.Write((byte)(partial ? 1 : 0)); val.Write(list.Count + list2.Count + (packageEntries?.Count() ?? 0)); foreach (PackageEntry item in packageEntries ?? Array.Empty()) { AddEntryToPackage(val, item); } foreach (CustomSyncedValueBase item2 in list2) { AddEntryToPackage(val, new PackageEntry { section = "Internal", key = item2.Identifier, type = item2.Type, value = item2.BoxedValue }); } foreach (ConfigEntryBase item3 in list) { AddEntryToPackage(val, new PackageEntry { section = item3.Definition.Section, key = item3.Definition.Key, type = configType(item3), value = item3.BoxedValue }); } return val; } private static void AddEntryToPackage(ZPackage package, PackageEntry entry) { package.Write(entry.section); package.Write(entry.key); package.Write((entry.value == null) ? "" : GetZPackageTypeString(entry.type)); AddValueToZPackage(package, entry.value); } private static string GetZPackageTypeString(Type type) { return type.AssemblyQualifiedName; } private static void AddValueToZPackage(ZPackage package, object? value) { Type type = value?.GetType(); if (value is Enum) { value = ((IConvertible)value).ToType(Enum.GetUnderlyingType(value.GetType()), CultureInfo.InvariantCulture); } else { if (value is ICollection collection) { package.Write(collection.Count); { foreach (object item in collection) { AddValueToZPackage(package, item); } return; } } if ((object)type != null && type.IsValueType && !type.IsPrimitive) { FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); package.Write(fields.Length); FieldInfo[] array = fields; foreach (FieldInfo fieldInfo in array) { package.Write(GetZPackageTypeString(fieldInfo.FieldType)); AddValueToZPackage(package, fieldInfo.GetValue(value)); } return; } } ZRpc.Serialize(new object[1] { value }, ref package); } private static object ReadValueWithTypeFromZPackage(ZPackage package, Type type) { if ((object)type != null && type.IsValueType && !type.IsPrimitive && !type.IsEnum) { FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); int num = package.ReadInt(); if (num != fields.Length) { throw new InvalidDeserializationTypeException { received = $"(field count: {num})", expected = $"(field count: {fields.Length})" }; } object uninitializedObject = FormatterServices.GetUninitializedObject(type); FieldInfo[] array = fields; foreach (FieldInfo fieldInfo in array) { string text = package.ReadString(); if (text != GetZPackageTypeString(fieldInfo.FieldType)) { throw new InvalidDeserializationTypeException { received = text, expected = GetZPackageTypeString(fieldInfo.FieldType), field = fieldInfo.Name }; } fieldInfo.SetValue(uninitializedObject, ReadValueWithTypeFromZPackage(package, fieldInfo.FieldType)); } return uninitializedObject; } if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<, >)) { int num2 = package.ReadInt(); IDictionary dictionary = (IDictionary)Activator.CreateInstance(type); Type type2 = typeof(KeyValuePair<, >).MakeGenericType(type.GenericTypeArguments); FieldInfo field = type2.GetField("key", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field2 = type2.GetField("value", BindingFlags.Instance | BindingFlags.NonPublic); for (int j = 0; j < num2; j++) { object obj = ReadValueWithTypeFromZPackage(package, type2); dictionary.Add(field.GetValue(obj), field2.GetValue(obj)); } return dictionary; } if (type != typeof(List) && type.IsGenericType) { Type type3 = typeof(ICollection<>).MakeGenericType(type.GenericTypeArguments[0]); if ((object)type3 != null && type3.IsAssignableFrom(type)) { int num3 = package.ReadInt(); object obj2 = Activator.CreateInstance(type); MethodInfo method = type3.GetMethod("Add"); for (int k = 0; k < num3; k++) { method.Invoke(obj2, new object[1] { ReadValueWithTypeFromZPackage(package, type.GenericTypeArguments[0]) }); } return obj2; } } ParameterInfo parameterInfo = (ParameterInfo)FormatterServices.GetUninitializedObject(typeof(ParameterInfo)); AccessTools.DeclaredField(typeof(ParameterInfo), "ClassImpl").SetValue(parameterInfo, type); List source = new List(); ZRpc.Deserialize(new ParameterInfo[2] { null, parameterInfo }, package, ref source); return source.First(); } } [PublicAPI] [HarmonyPatch] internal class VersionCheck { private static readonly HashSet versionChecks; private static readonly Dictionary notProcessedNames; public string Name; private string? displayName; private string? currentVersion; private string? minimumRequiredVersion; public bool ModRequired = true; private string? ReceivedCurrentVersion; private string? ReceivedMinimumRequiredVersion; private readonly List ValidatedClients = new List(); private ConfigSync? ConfigSync; public string DisplayName { get { return displayName ?? Name; } set { displayName = value; } } public string CurrentVersion { get { return currentVersion ?? "0.0.0"; } set { currentVersion = value; } } public string MinimumRequiredVersion { get { return minimumRequiredVersion ?? (ModRequired ? CurrentVersion : "0.0.0"); } set { minimumRequiredVersion = value; } } private static void PatchServerSync() { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Expected O, but got Unknown Patches patchInfo = PatchProcessor.GetPatchInfo((MethodBase)AccessTools.DeclaredMethod(typeof(ZNet), "Awake", (Type[])null, (Type[])null)); if (patchInfo != null && patchInfo.Postfixes.Count((Patch p) => p.PatchMethod.DeclaringType == typeof(ConfigSync.RegisterRPCPatch)) > 0) { return; } Harmony val = new Harmony("org.bepinex.helpers.ServerSync"); foreach (Type item in from t in typeof(ConfigSync).GetNestedTypes(BindingFlags.NonPublic).Concat(new Type[1] { typeof(VersionCheck) }) where t.IsClass select t) { val.PatchAll(item); } } static VersionCheck() { versionChecks = new HashSet(); notProcessedNames = new Dictionary(); typeof(ThreadingHelper).GetMethod("StartSyncInvoke").Invoke(ThreadingHelper.Instance, new object[1] { new Action(PatchServerSync) }); } public VersionCheck(string name) { Name = name; ModRequired = true; versionChecks.Add(this); } public VersionCheck(ConfigSync configSync) { ConfigSync = configSync; Name = ConfigSync.Name; versionChecks.Add(this); } public void Initialize() { ReceivedCurrentVersion = null; ReceivedMinimumRequiredVersion = null; if (ConfigSync != null) { Name = ConfigSync.Name; DisplayName = ConfigSync.DisplayName; CurrentVersion = ConfigSync.CurrentVersion; MinimumRequiredVersion = ConfigSync.MinimumRequiredVersion; ModRequired = ConfigSync.ModRequired; } } private bool IsVersionOk() { if (ReceivedMinimumRequiredVersion == null || ReceivedCurrentVersion == null) { return !ModRequired; } bool flag = new Version(CurrentVersion) >= new Version(ReceivedMinimumRequiredVersion); bool flag2 = new Version(ReceivedCurrentVersion) >= new Version(MinimumRequiredVersion); return flag && flag2; } private string ErrorClient() { if (ReceivedMinimumRequiredVersion == null) { return DisplayName + " is not installed on the server."; } return (new Version(CurrentVersion) >= new Version(ReceivedMinimumRequiredVersion)) ? (DisplayName + " may not be higher than version " + ReceivedCurrentVersion + ". You have version " + CurrentVersion + ".") : (DisplayName + " needs to be at least version " + ReceivedMinimumRequiredVersion + ". You have version " + CurrentVersion + "."); } private string ErrorServer(ZRpc rpc) { return "Disconnect: The client (" + rpc.GetSocket().GetHostName() + ") doesn't have the correct " + DisplayName + " version " + MinimumRequiredVersion; } private string Error(ZRpc? rpc = null) { return (rpc == null) ? ErrorClient() : ErrorServer(rpc); } private static VersionCheck[] GetFailedClient() { return versionChecks.Where((VersionCheck check) => !check.IsVersionOk()).ToArray(); } private static VersionCheck[] GetFailedServer(ZRpc rpc) { ZRpc rpc2 = rpc; return versionChecks.Where((VersionCheck check) => check.ModRequired && !check.ValidatedClients.Contains(rpc2)).ToArray(); } private static void Logout() { Game.instance.Logout(true, true); AccessTools.DeclaredField(typeof(ZNet), "m_connectionStatus").SetValue(null, (object)(ConnectionStatus)3); } private static void DisconnectClient(ZRpc rpc) { rpc.Invoke("Error", new object[1] { 3 }); } private static void CheckVersion(ZRpc rpc, ZPackage pkg) { CheckVersion(rpc, pkg, null); } private static void CheckVersion(ZRpc rpc, ZPackage pkg, Action? original) { string text = pkg.ReadString(); string text2 = pkg.ReadString(); string text3 = pkg.ReadString(); bool flag = false; foreach (VersionCheck versionCheck in versionChecks) { if (!(text != versionCheck.Name)) { Debug.Log((object)("Received " + versionCheck.DisplayName + " version " + text3 + " and minimum version " + text2 + " from the " + (ZNet.instance.IsServer() ? "client" : "server") + ".")); versionCheck.ReceivedMinimumRequiredVersion = text2; versionCheck.ReceivedCurrentVersion = text3; if (ZNet.instance.IsServer() && versionCheck.IsVersionOk()) { versionCheck.ValidatedClients.Add(rpc); } flag = true; } } if (flag) { return; } pkg.SetPos(0); if (original != null) { original(rpc, pkg); if (pkg.GetPos() == 0) { notProcessedNames.Add(text, text3); } } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] [HarmonyPrefix] private static bool RPC_PeerInfo(ZRpc rpc, ZNet __instance) { VersionCheck[] array = (__instance.IsServer() ? GetFailedServer(rpc) : GetFailedClient()); if (array.Length == 0) { return true; } VersionCheck[] array2 = array; foreach (VersionCheck versionCheck in array2) { Debug.LogWarning((object)versionCheck.Error(rpc)); } if (__instance.IsServer()) { DisconnectClient(rpc); } else { Logout(); } return false; } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] [HarmonyPrefix] private static void RegisterAndCheckVersion(ZNetPeer peer, ZNet __instance) { //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Expected O, but got Unknown notProcessedNames.Clear(); IDictionary dictionary = (IDictionary)typeof(ZRpc).GetField("m_functions", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(peer.m_rpc); if (dictionary.Contains(StringExtensionMethods.GetStableHashCode("ServerSync VersionCheck"))) { object obj = dictionary[StringExtensionMethods.GetStableHashCode("ServerSync VersionCheck")]; Action action = (Action)obj.GetType().GetField("m_action", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(obj); peer.m_rpc.Register("ServerSync VersionCheck", (Action)delegate(ZRpc rpc, ZPackage pkg) { CheckVersion(rpc, pkg, action); }); } else { peer.m_rpc.Register("ServerSync VersionCheck", (Action)CheckVersion); } foreach (VersionCheck versionCheck in versionChecks) { versionCheck.Initialize(); if (versionCheck.ModRequired || __instance.IsServer()) { Debug.Log((object)("Sending " + versionCheck.DisplayName + " version " + versionCheck.CurrentVersion + " and minimum version " + versionCheck.MinimumRequiredVersion + " to the " + (__instance.IsServer() ? "client" : "server") + ".")); ZPackage val = new ZPackage(); val.Write(versionCheck.Name); val.Write(versionCheck.MinimumRequiredVersion); val.Write(versionCheck.CurrentVersion); peer.m_rpc.Invoke("ServerSync VersionCheck", new object[1] { val }); } } } [HarmonyPatch(typeof(ZNet), "Disconnect")] [HarmonyPrefix] private static void RemoveDisconnected(ZNetPeer peer, ZNet __instance) { if (!__instance.IsServer()) { return; } foreach (VersionCheck versionCheck in versionChecks) { versionCheck.ValidatedClients.Remove(peer.m_rpc); } } [HarmonyPatch(typeof(FejdStartup), "ShowConnectError")] [HarmonyPostfix] private static void ShowConnectionError(FejdStartup __instance) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_01de: 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_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) if (!__instance.m_connectionFailedPanel.activeSelf || (int)ZNet.GetConnectionStatus() != 3) { return; } bool flag = false; VersionCheck[] failedClient = GetFailedClient(); if (failedClient.Length != 0) { string text = string.Join("\n", failedClient.Select((VersionCheck check) => check.Error())); TMP_Text connectionFailedError = __instance.m_connectionFailedError; connectionFailedError.text = connectionFailedError.text + "\n" + text; flag = true; } foreach (KeyValuePair item in notProcessedNames.OrderBy, string>((KeyValuePair kv) => kv.Key)) { if (!__instance.m_connectionFailedError.text.Contains(item.Key)) { TMP_Text connectionFailedError2 = __instance.m_connectionFailedError; connectionFailedError2.text = connectionFailedError2.text + "\nServer expects you to have " + item.Key + " (Version: " + item.Value + ") installed."; flag = true; } } if (flag) { RectTransform component = ((Component)__instance.m_connectionFailedPanel.transform.Find("Image")).GetComponent(); Vector2 sizeDelta = component.sizeDelta; sizeDelta.x = 675f; component.sizeDelta = sizeDelta; __instance.m_connectionFailedError.ForceMeshUpdate(false, false); float num = __instance.m_connectionFailedError.renderedHeight + 105f; RectTransform component2 = ((Component)((Component)component).transform.Find("ButtonOk")).GetComponent(); component2.anchoredPosition = new Vector2(component2.anchoredPosition.x, component2.anchoredPosition.y - (num - component.sizeDelta.y) / 2f); sizeDelta = component.sizeDelta; sizeDelta.y = num; component.sizeDelta = sizeDelta; } } } }