Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of EvuMiscCompat v0.3.2
EvuMiscCompat.Core.dll
Decompiled 18 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using Microsoft.CodeAnalysis; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")] [assembly: AssemblyCompany("evu")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright (c) 2026 imevul")] [assembly: AssemblyDescription("Compatibility fixes for other Valheim mods.")] [assembly: AssemblyFileVersion("0.3.2.0")] [assembly: AssemblyInformationalVersion("0.3.2+277d558c90ecd0fca68171f34c283ba2fded4116")] [assembly: AssemblyProduct("EvuMiscCompat")] [assembly: AssemblyTitle("EvuMiscCompat.Core")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/EvuMods/EvuMiscCompat")] [assembly: AssemblyVersion("0.3.2.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] internal sealed class IsReadOnlyAttribute : Attribute { } [CompilerGenerated] [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] [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] [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 EvuMiscCompat.Core { public enum IlOpKind { Other, Ldarg0, Ldarg1, Ldarg2, LdcI4_3, BneUn, Call, Brtrue } public readonly struct IlOp : IEquatable<IlOp> { public IlOpKind Kind { get; } public string? Name { get; } public IlOp(IlOpKind kind, string? name = null) { Kind = kind; Name = name; } public bool Equals(IlOp other) { if (Kind == other.Kind) { return Name == other.Name; } return false; } public override bool Equals(object? obj) { if (obj is IlOp other) { return Equals(other); } return false; } public override int GetHashCode() { return ((int)Kind * 397) ^ (Name?.GetHashCode() ?? 0); } } public static class DualWieldWindow { public const string OffhandMethod = "CheckDualOneHandedWeaponEquip"; public static List<IlOp> Repair(IReadOnlyList<IlOp> code) { List<IlOp> list = new List<IlOp>(code.Count + 5); for (int i = 0; i < code.Count; i++) { list.Add(code[i]); if (IsOneHandedBranch(code, i) && !HasOffhandFallthrough(code, i)) { string name = code[i].Name; list.Add(new IlOp(IlOpKind.Ldarg0)); list.Add(new IlOp(IlOpKind.Ldarg1)); list.Add(new IlOp(IlOpKind.Ldarg2)); list.Add(new IlOp(IlOpKind.Call, "CheckDualOneHandedWeaponEquip")); list.Add(new IlOp(IlOpKind.Brtrue, name)); } } return list; } private static bool IsOneHandedBranch(IReadOnlyList<IlOp> code, int index) { if (code[index].Kind != IlOpKind.BneUn) { return false; } if (index < 1 || code[index - 1].Kind != IlOpKind.LdcI4_3) { return false; } if (!IsVanillaWindow(code, index)) { return IsTrinketsWindow(code, index); } return true; } private static bool IsVanillaWindow(IReadOnlyList<IlOp> code, int branch) { if (branch >= 4 && code[branch - 4].Kind == IlOpKind.Ldarg1 && code[branch - 3].Kind == IlOpKind.Other) { return code[branch - 2].Kind == IlOpKind.Other; } return false; } private static bool IsTrinketsWindow(IReadOnlyList<IlOp> code, int branch) { if (branch >= 7 && code[branch - 7].Kind == IlOpKind.Ldarg1 && code[branch - 6].Kind == IlOpKind.Other && code[branch - 5].Kind == IlOpKind.Other && code[branch - 4].Kind == IlOpKind.Ldarg0 && code[branch - 3].Kind == IlOpKind.Ldarg1) { return code[branch - 2].Kind == IlOpKind.Call; } return false; } private static bool HasOffhandFallthrough(IReadOnlyList<IlOp> code, int branch) { if (branch + 5 >= code.Count) { return false; } if (code[branch + 1].Kind == IlOpKind.Ldarg0 && code[branch + 2].Kind == IlOpKind.Ldarg1 && code[branch + 3].Kind == IlOpKind.Ldarg2 && code[branch + 4].Kind == IlOpKind.Call && code[branch + 4].Name == "CheckDualOneHandedWeaponEquip" && code[branch + 5].Kind == IlOpKind.Brtrue) { return code[branch + 5].Name == code[branch].Name; } return false; } } public enum ConfirmationMode { Always, OnNearbyActivity, Never } public enum ResetDecision { Refuse, Confirm, Allow } public readonly struct CooldownDecision { public bool Allowed { get; } public int RemainingSeconds { get; } public CooldownDecision(bool allowed, int remainingSeconds) { Allowed = allowed; RemainingSeconds = remainingSeconds; } } public static class LocationResetRules { public const string CommandName = "resetdungeon"; public static bool IsResetDungeonCommand(string text) { if (string.IsNullOrWhiteSpace(text)) { return false; } string text2 = text.Trim(); if (text2[0] == '/') { text2 = text2.Substring(1).TrimStart(Array.Empty<char>()); } return text2.Equals("resetdungeon", StringComparison.OrdinalIgnoreCase); } public static bool TryParseConfirmation(string text, out ConfirmationMode mode) { if (string.IsNullOrWhiteSpace(text)) { mode = ConfirmationMode.Always; return false; } string text2 = text.Trim(); if (text2.Equals("Always", StringComparison.OrdinalIgnoreCase)) { mode = ConfirmationMode.Always; return true; } if (text2.Equals("Never", StringComparison.OrdinalIgnoreCase)) { mode = ConfirmationMode.Never; return true; } if (text2.Equals("On nearby activity", StringComparison.OrdinalIgnoreCase) || text2.Equals("OnNearbyActivity", StringComparison.OrdinalIgnoreCase)) { mode = ConfirmationMode.OnNearbyActivity; return true; } mode = ConfirmationMode.Always; return false; } public static ResetDecision Decide(bool playersInArea, bool nearbyActivity, ConfirmationMode mode) { if (playersInArea) { return ResetDecision.Refuse; } if (mode == ConfirmationMode.Always) { return ResetDecision.Confirm; } if (mode == ConfirmationMode.OnNearbyActivity && nearbyActivity) { return ResetDecision.Confirm; } return ResetDecision.Allow; } public static CooldownDecision CheckCooldown(DateTimeOffset? lastStartedUtc, DateTimeOffset now, int cooldownMinutes) { if (cooldownMinutes <= 0 || !lastStartedUtc.HasValue) { return new CooldownDecision(allowed: true, 0); } TimeSpan timeSpan = TimeSpan.FromMinutes(cooldownMinutes); TimeSpan timeSpan2 = now - lastStartedUtc.Value; if (timeSpan2 >= timeSpan) { return new CooldownDecision(allowed: true, 0); } int num = (int)Math.Ceiling((timeSpan - timeSpan2).TotalSeconds); if (num < 1) { num = 1; } return new CooldownDecision(allowed: false, num); } public static float ClampSearchRadius(float radius) { if (radius < 1f) { return 1f; } if (radius > 100f) { return 100f; } return radius; } } public sealed class CooldownLedger { private readonly Dictionary<long, DateTimeOffset> _started = new Dictionary<long, DateTimeOffset>(); public CooldownDecision TryStart(long playerId, DateTimeOffset now, int cooldownMinutes) { DateTimeOffset? lastStartedUtc = null; if (_started.TryGetValue(playerId, out var value)) { lastStartedUtc = value; } CooldownDecision result = LocationResetRules.CheckCooldown(lastStartedUtc, now, cooldownMinutes); if (result.Allowed) { _started[playerId] = now; } return result; } } }
EvuMiscCompat.dll
Decompiled 18 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using EvuMiscCompat.Core; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: AssemblyCompany("evu")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright (c) 2026 imevul")] [assembly: AssemblyDescription("Compatibility fixes for other Valheim mods.")] [assembly: AssemblyFileVersion("0.3.2.0")] [assembly: AssemblyInformationalVersion("0.3.2+277d558c90ecd0fca68171f34c283ba2fded4116")] [assembly: AssemblyProduct("EvuMiscCompat")] [assembly: AssemblyTitle("EvuMiscCompat")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/EvuMods/EvuMiscCompat")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.3.2.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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] [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 EvuMiscCompat { [HarmonyPatch(typeof(Humanoid), "EquipItem")] internal static class DualWieldEquipRepair { [HarmonyTranspiler] [HarmonyPriority(0)] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) MethodInfo methodInfo = FindOffhand(); List<CodeInstruction> list = new List<CodeInstruction>(instructions); if (methodInfo == null) { return list; } List<IlOp> list2 = new List<IlOp>(list.Count); for (int i = 0; i < list.Count; i++) { list2.Add(Map(list[i])); } List<IlOp> list3 = DualWieldWindow.Repair((IReadOnlyList<IlOp>)list2); if (list3.Count == list2.Count) { return list; } List<CodeInstruction> list4 = new List<CodeInstruction>(list3.Count); object branch = null; int num = 0; for (int j = 0; j < list3.Count; j++) { if (num < list.Count) { IlOp val = Map(list[num]); if (((IlOp)(ref val)).Equals(list3[j])) { list4.Add(list[num]); if (list[num].opcode == OpCodes.Bne_Un) { branch = list[num].operand; } num++; continue; } } list4.Add(Emit(list3[j], branch, methodInfo)); } if (num != list.Count) { Plugin.Log.LogWarning((object)"Dual Wield offhand repair did not consume Humanoid.EquipItem. Left the method unchanged."); return list; } Plugin.Log.LogInfo((object)"Restored Dual Wield offhand equip on Humanoid.EquipItem."); return list4; } private static MethodInfo? FindOffhand() { Type type = AccessTools.TypeByName("DualWield.DualWield"); if (type == null) { return null; } Type type2 = AccessTools.Inner(type, "Patch_Humanoid_EquipItem"); if (type2 == null) { return null; } return AccessTools.DeclaredMethod(type2, "CheckDualOneHandedWeaponEquip", (Type[])null, (Type[])null); } private static IlOp Map(CodeInstruction instruction) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0062: 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_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) if (instruction.opcode == OpCodes.Ldarg_0) { return new IlOp((IlOpKind)1, (string)null); } if (instruction.opcode == OpCodes.Ldarg_1) { return new IlOp((IlOpKind)2, (string)null); } if (instruction.opcode == OpCodes.Ldarg_2) { return new IlOp((IlOpKind)3, (string)null); } if (instruction.opcode == OpCodes.Ldc_I4_3) { return new IlOp((IlOpKind)4, (string)null); } if (instruction.opcode == OpCodes.Bne_Un) { return new IlOp((IlOpKind)5, OperandName(instruction.operand)); } if (instruction.opcode == OpCodes.Brtrue) { return new IlOp((IlOpKind)7, OperandName(instruction.operand)); } if (instruction.opcode == OpCodes.Call && instruction.operand is MethodInfo methodInfo) { return new IlOp((IlOpKind)6, methodInfo.Name); } return new IlOp((IlOpKind)0, (string)null); } private static CodeInstruction Emit(IlOp op, object? branch, MethodInfo offhand) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected I4, but got Unknown //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Expected O, but got Unknown IlOpKind kind = ((IlOp)(ref op)).Kind; return (CodeInstruction)((kind - 1) switch { 0 => (object)new CodeInstruction(OpCodes.Ldarg_0, (object)null), 1 => (object)new CodeInstruction(OpCodes.Ldarg_1, (object)null), 2 => (object)new CodeInstruction(OpCodes.Ldarg_2, (object)null), 5 => (object)new CodeInstruction(OpCodes.Call, (object)offhand), 6 => (object)new CodeInstruction(OpCodes.Brtrue, branch), _ => (object)new CodeInstruction(OpCodes.Nop, (object)null), }); } private static string? OperandName(object? operand) { return operand?.ToString(); } } internal static class LocationResetPlayer { private sealed class Rules { public bool Enabled { get; } public int CooldownMinutes { get; } public ConfirmationMode Confirmation { get; } public float SearchRadius { get; } public Rules(bool enabled, int cooldownMinutes, ConfirmationMode confirmation, float searchRadius) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) Enabled = enabled; CooldownMinutes = cooldownMinutes; Confirmation = confirmation; SearchRadius = searchRadius; } } private sealed class DungeonCandidate { public LocationProxy Proxy { get; } public int Hash { get; } public string Name { get; } public bool Sky { get; } public Vector3 Entrance { get; } public float GroundRadius { get; } public float SkyRadius { get; } public DungeonGenerator? Generator { get; } public bool PlayersInArea { get; set; } public bool NearbyActivity { get; set; } public bool Grave { get; set; } public bool PlayerPiece { get; set; } public bool Terrain { get; set; } public DungeonCandidate(LocationProxy proxy, int hash, string name, bool sky, Vector3 entrance, float groundRadius, float skyRadius, DungeonGenerator? generator) { //IL_0024: 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) Proxy = proxy; Hash = hash; Name = name; Sky = sky; Entrance = entrance; GroundRadius = groundRadius; SkyRadius = skyRadius; Generator = generator; } } private const string PluginGuid = "com.orianaventure.mod.LocationReset"; private const string DungeonSplitterGuid = "dungeon_splitter"; private const string PolicyRpc = "EvuMiscCompat.DungeonReset.Policy"; private const string PolicyRequestRpc = "EvuMiscCompat.DungeonReset.PolicyRequest"; private const string ConsumeRpc = "EvuMiscCompat.DungeonReset.Consume"; private const string ConsumedRpc = "EvuMiscCompat.DungeonReset.Consumed"; private const float SkyHeight = 4000f; private static readonly CooldownLedger Ledger = new CooldownLedger(); private static Plugin _plugin = null; private static ConfigEntry<bool> _enabled = null; private static ConfigEntry<int> _cooldownMinutes = null; private static ConfigEntry<string> _confirmation = null; private static ConfigEntry<float> _searchRadius = null; private static MethodInfo? _tryReset; private static PropertyInfo? _instance; private static bool _rpc; private static bool _policyRequested; private static bool _policyMissing; private static bool _popup; private static bool _closing; private static float _pendingSince; private static Rules? _remote; private static DungeonCandidate? _pending; internal static bool ResetReady { get; private set; } internal static void Bind(Plugin plugin) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Expected O, but got Unknown //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Expected O, but got Unknown _plugin = plugin; _enabled = ((BaseUnityPlugin)plugin).Config.Bind<bool>("Location reset", "Enabled", true, "Allow players to reset the nearest dungeon from chat with resetdungeon. Turn this off to leave dungeon resets to Venture Location Reset's admin console command."); _cooldownMinutes = ((BaseUnityPlugin)plugin).Config.Bind<int>("Location reset", "Cooldown minutes", 10, new ConfigDescription("Minutes a player must wait between force resets. 0 disables the limit.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1440), Array.Empty<object>())); _confirmation = ((BaseUnityPlugin)plugin).Config.Bind<string>("Location reset", "Require confirmation", "On nearby activity", new ConfigDescription("Always asks before every reset. On nearby activity asks when a grave, player-built piece, or terrain change is in the reset area. Never skips the dialog. A player inside the area always blocks the reset.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Always", "On nearby activity", "Never" }), Array.Empty<object>())); _searchRadius = ((BaseUnityPlugin)plugin).Config.Bind<float>("Location reset", "Search radius", 20f, new ConfigDescription("How close a player must be to a dungeon entrance, in meters.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 100f), Array.Empty<object>())); BindReset(); } internal static bool TryConsume(string text) { if (!LocationResetRules.IsResetDungeonCommand(text)) { return false; } if (!ResetReady) { return false; } if (_popup && !UnifiedPopup.IsVisible()) { _popup = false; } if (_pending != null && Time.time - _pendingSince > 5f) { _pending = null; } if (_popup || _pending != null) { Say("A dungeon reset is already pending."); return true; } if (!TryRules(out Rules rules, out string unavailable)) { Say(unavailable); return true; } if (!rules.Enabled) { Say("Player dungeon reset is turned off."); return true; } Run(rules); return true; } internal static void EnsureRpc() { if (!_rpc && ZRoutedRpc.instance != null) { ZRoutedRpc.instance.Register<bool, int, int, float>("EvuMiscCompat.DungeonReset.Policy", (Method<bool, int, int, float>)OnPolicy); ZRoutedRpc.instance.Register("EvuMiscCompat.DungeonReset.PolicyRequest", (Action<long>)OnPolicyRequest); ZRoutedRpc.instance.Register("EvuMiscCompat.DungeonReset.Consume", (Action<long>)OnConsume); ZRoutedRpc.instance.Register<bool, int>("EvuMiscCompat.DungeonReset.Consumed", (Action<long, bool, int>)OnConsumed); _rpc = true; } } internal static void SendPolicy(long peerId) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected I4, but got Unknown EnsureRpc(); if (ZRoutedRpc.instance != null) { Rules rules = LocalRules(); ZRoutedRpc.instance.InvokeRoutedRPC(peerId, "EvuMiscCompat.DungeonReset.Policy", new object[4] { rules.Enabled, rules.CooldownMinutes, (int)rules.Confirmation, rules.SearchRadius }); } } internal static void RequestPolicy() { EnsureRpc(); if (!((Object)(object)ZNet.instance == (Object)null) && !ZNet.instance.IsServer() && ZRoutedRpc.instance != null && _remote == null && !_policyRequested) { _policyRequested = true; ZRoutedRpc.instance.InvokeRoutedRPC("EvuMiscCompat.DungeonReset.PolicyRequest", Array.Empty<object>()); ((MonoBehaviour)_plugin).StartCoroutine(PolicyTimeout()); } } private static void BindReset() { ResetReady = false; if (!Chainloader.PluginInfos.TryGetValue("com.orianaventure.mod.LocationReset", out var value) || (Object)(object)value.Instance == (Object)null) { Plugin.Log.LogInfo((object)"Venture Location Reset is not loaded. Player dungeon reset is idle."); return; } Type? type = ((object)value.Instance).GetType().Assembly.GetType("VentureValheim.LocationReset.LocationReset"); _instance = type?.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public); _tryReset = type?.GetMethod("TryReset", new Type[3] { typeof(LocationProxy), typeof(int), typeof(bool) }); ResetReady = _instance != null && _tryReset != null; if (ResetReady) { Plugin.Log.LogInfo((object)"Player dungeon reset is available."); } else { Plugin.Log.LogWarning((object)"Venture Location Reset is loaded, but TryReset could not be found."); } } private static IEnumerator PolicyTimeout() { yield return (object)new WaitForSeconds(5f); if (_remote == null) { _policyMissing = true; _policyRequested = false; } } private static bool TryRules(out Rules rules, out string unavailable) { if ((Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsServer()) { if (_remote == null) { RequestPolicy(); rules = LocalRules(); unavailable = (_policyMissing ? "This server does not allow player dungeon resets." : "Still waiting on the server for dungeon reset rules."); return false; } rules = _remote; unavailable = ""; return true; } rules = LocalRules(); unavailable = ""; return true; } private static Rules LocalRules() { //IL_002f: 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) ConfirmationMode confirmation = default(ConfirmationMode); if (!LocationResetRules.TryParseConfirmation(_confirmation.Value, ref confirmation)) { confirmation = (ConfirmationMode)1; } return new Rules(_enabled.Value, Math.Max(0, _cooldownMinutes.Value), confirmation, LocationResetRules.ClampSearchRadius(_searchRadius.Value)); } private static void OnPolicy(long sender, bool enabled, int cooldownMinutes, int confirmation, float searchRadius) { if (confirmation < 0 || confirmation > 2) { confirmation = 1; } _remote = new Rules(enabled, Math.Max(0, cooldownMinutes), (ConfirmationMode)confirmation, LocationResetRules.ClampSearchRadius(searchRadius)); _policyMissing = false; } private static void OnPolicyRequest(long sender) { if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer()) { SendPolicy(sender); } } private static void OnConsume(long sender) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer()) { Rules rules = LocalRules(); if (!rules.Enabled) { Reply(sender, allowed: false, -1); return; } CooldownDecision val = Ledger.TryStart(sender, DateTimeOffset.UtcNow, rules.CooldownMinutes); Reply(sender, ((CooldownDecision)(ref val)).Allowed, ((CooldownDecision)(ref val)).RemainingSeconds); } } private static void OnConsumed(long sender, bool allowed, int remainingSeconds) { DungeonCandidate pending = _pending; _pending = null; if (pending != null) { if (!allowed) { Say((remainingSeconds < 0) ? "Player dungeon reset is turned off." : RemainingText(remainingSeconds)); } else if (PlayersInArea(pending)) { Say("A player is in the reset area."); } else { Finish(pending); } } } private static void Reply(long sender, bool allowed, int remainingSeconds) { if (ZRoutedRpc.instance != null) { ZRoutedRpc.instance.InvokeRoutedRPC(sender, "EvuMiscCompat.DungeonReset.Consumed", new object[2] { allowed, remainingSeconds }); } } private static void Run(Rules rules) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Invalid comparison between Unknown and I4 Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || (Object)(object)ZoneSystem.instance == (Object)null) { Say("Dungeon reset is not available yet."); return; } DungeonCandidate dungeonCandidate = FindNearest(((Component)localPlayer).transform.position, rules.SearchRadius); if (dungeonCandidate == null) { Say("No dungeon is close enough to reset."); return; } if (dungeonCandidate.Sky && Chainloader.PluginInfos.ContainsKey("dungeon_splitter")) { Say("Sky dungeons cannot be reset while Dungeon Splitter is installed."); return; } if (!OwnsGenerator(dungeonCandidate.Generator)) { Say("This dungeon is not loaded on your client yet."); return; } Scan(dungeonCandidate); ResetDecision val = LocationResetRules.Decide(dungeonCandidate.PlayersInArea, dungeonCandidate.NearbyActivity, rules.Confirmation); if ((int)val == 0) { Say("A player is in the reset area."); } else if ((int)val == 1) { Ask(dungeonCandidate, rules); } else { StartReset(dungeonCandidate, rules); } } private static void Ask(DungeonCandidate target, Rules rules) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_0061: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown if (!UnifiedPopup.IsAvailable()) { Say("The confirmation dialog is not available."); return; } _popup = true; _closing = false; UnifiedPopup.Push((PopupBase)new YesNoPopup("Reset dungeon?", PopupBody(target), (PopupButtonCallback)delegate { Answer(target, rules, accepted: true); }, (PopupButtonCallback)delegate { Answer(target, rules, accepted: false); }, false, false)); HideCover(); } private static void Answer(DungeonCandidate target, Rules rules, bool accepted) { if (!_closing) { _closing = true; ((MonoBehaviour)_plugin).StartCoroutine(AnswerNextFrame(target, rules, accepted)); } } private static IEnumerator AnswerNextFrame(DungeonCandidate target, Rules rules, bool accepted) { yield return null; _popup = false; _closing = false; if (UnifiedPopup.IsVisible()) { UnifiedPopup.Pop(); } if (accepted) { Confirm(target, rules); } } private static void HideCover() { GameObject val = (((Object)(object)UnifiedPopup.instance != (Object)null) ? UnifiedPopup.instance.fullScreenBackgroundCover : null); if ((Object)(object)val != (Object)null) { val.SetActive(false); } } private static void Confirm(DungeonCandidate target, Rules rules) { _popup = false; if (!OwnsGenerator(target.Generator)) { Say("This dungeon is not loaded on your client yet."); } else if (PlayersInArea(target)) { Say("A player is in the reset area."); } else { StartReset(target, rules); } } private static void StartReset(DungeonCandidate target, Rules rules) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ZNet.instance == (Object)null) { Say("Dungeon reset is not available yet."); } else if (ZNet.instance.IsServer()) { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null)) { CooldownDecision val = Ledger.TryStart(localPlayer.GetPlayerID(), DateTimeOffset.UtcNow, rules.CooldownMinutes); if (!((CooldownDecision)(ref val)).Allowed) { Say(RemainingText(((CooldownDecision)(ref val)).RemainingSeconds)); } else { Finish(target); } } } else if (ZRoutedRpc.instance == null) { Say("Dungeon reset is not available yet."); } else { _pending = target; _pendingSince = Time.time; ZRoutedRpc.instance.InvokeRoutedRPC("EvuMiscCompat.DungeonReset.Consume", Array.Empty<object>()); } } private static void Finish(DungeonCandidate target) { //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)target.Proxy == (Object)null || _tryReset == null || _instance == null) { Say("The dungeon reset failed."); return; } object value = _instance.GetValue(null); if (value == null) { Say("The dungeon reset failed."); return; } try { _tryReset.Invoke(value, new object[3] { target.Proxy, target.Hash, true }); } catch (Exception ex) { Plugin.Log.LogError((object)ex); Say("The dungeon reset failed."); return; } Say("Resetting " + target.Name + "."); Plugin.Log.LogInfo((object)("Player reset " + target.Name + " at " + ((object)target.Entrance/*cast due to .constrained prefix*/).ToString() + ".")); } private static DungeonCandidate? FindNearest(Vector3 playerPosition, float radius) { //IL_0004: 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) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) DungeonCandidate dungeonCandidate = null; float num = radius; Scene activeScene = SceneManager.GetActiveScene(); GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects(); for (int i = 0; i < rootGameObjects.Length; i++) { LocationProxy component = rootGameObjects[i].GetComponent<LocationProxy>(); if ((Object)(object)component == (Object)null) { continue; } Vector3 position = ((Component)component).transform.position; if (!InRange(playerPosition, position, radius)) { continue; } float num2 = HorizontalDistance(playerPosition, position); if (dungeonCandidate == null || !(num2 >= num)) { DungeonCandidate dungeonCandidate2 = Inspect(component, position); if (dungeonCandidate2 != null) { dungeonCandidate = dungeonCandidate2; num = num2; } } } return dungeonCandidate; } private static DungeonCandidate? Inspect(LocationProxy proxy, Vector3 entrance) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) int num = LocationHash(proxy); if (num == 0 || (Object)(object)ZoneSystem.instance == (Object)null) { return null; } ZoneLocation location = ZoneSystem.instance.GetLocation(num); if (location == null || !location.m_prefab.IsValid) { return null; } bool flag = false; if (!location.m_prefab.IsLoaded) { location.m_prefab.Load(); flag = true; } try { GameObject asset = location.m_prefab.Asset; if ((Object)(object)asset == (Object)null) { return null; } Location component = asset.GetComponent<Location>(); if ((Object)(object)component == (Object)null) { return null; } DungeonGenerator generator = component.m_generator; bool flag2 = component.m_hasInterior || ((Object)(object)generator != (Object)null && ((Component)generator).transform.position.y > 4000f); if (!flag2 && (Object)(object)generator == (Object)null) { return null; } Vector3 val = (((Object)(object)generator != (Object)null) ? ((Component)generator).transform.localPosition : Vector3.zero); float num2 = location.m_exteriorRadius; float num3 = location.m_interiorRadius; DungeonGenerator val2 = FindGenerator(entrance + val, Mathf.Max(num2, num3)); if ((Object)(object)val2 != (Object)null) { if (flag2) { num3 = DungeonRadius(val2); } else { num2 += 5f; } } string name = (string.IsNullOrEmpty(location.m_prefabName) ? "dungeon" : location.m_prefabName); return new DungeonCandidate(proxy, num, name, flag2, entrance, num2, num3, val2); } finally { if (flag) { location.m_prefab.Release(); } } } private static int LocationHash(LocationProxy proxy) { ZNetView nview = proxy.m_nview; if ((Object)(object)nview == (Object)null || !nview.IsValid()) { return 0; } ZDO zDO = nview.GetZDO(); if (zDO == null) { return 0; } return zDO.GetInt(ZDOVars.s_location, 0); } private static DungeonGenerator? FindGenerator(Vector3 center, float radius) { //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_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) Scene activeScene = SceneManager.GetActiveScene(); GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects(); for (int i = 0; i < rootGameObjects.Length; i++) { DungeonGenerator component = rootGameObjects[i].GetComponent<DungeonGenerator>(); if ((Object)(object)component != (Object)null && InRange(center, rootGameObjects[i].transform.position, radius)) { return component; } } return null; } private static float DungeonRadius(DungeonGenerator generator) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) Vector3 zoneSize = generator.m_zoneSize; float num = zoneSize.x / 2f; float num2 = zoneSize.z / 2f; return Mathf.Sqrt(num * num + num2 * num2); } private static void Scan(DungeonCandidate target) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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_003c: 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_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) bool playersInArea = false; bool flag = false; bool flag2 = false; bool flag3 = false; Player localPlayer = Player.m_localPlayer; Scene activeScene = SceneManager.GetActiveScene(); GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects(); foreach (GameObject val in rootGameObjects) { Vector3 position = val.transform.position; bool flag4 = position.y >= 4000f; bool num; if (!flag4) { num = InRange(target.Entrance, position, target.GroundRadius); } else { if (!target.Sky) { continue; } num = InRange(target.Entrance, position, target.SkyRadius); } if (!num) { continue; } Player component = val.GetComponent<Player>(); if ((Object)(object)component != (Object)null) { if (flag4 || (Object)(object)component != (Object)(object)localPlayer) { playersInArea = true; } continue; } if ((Object)(object)val.GetComponent<TombStone>() != (Object)null) { flag = true; continue; } Piece component2 = val.GetComponent<Piece>(); if ((Object)(object)component2 != (Object)null && component2.GetCreator() != 0L) { flag2 = true; } } List<TerrainModifier> allInstances = TerrainModifier.GetAllInstances(); if (allInstances != null) { for (int j = 0; j < allInstances.Count; j++) { TerrainModifier val2 = allInstances[j]; if ((Object)(object)val2 != (Object)null && InRange(target.Entrance, ((Component)val2).transform.position, target.GroundRadius)) { flag3 = true; } } } target.PlayersInArea = playersInArea; target.NearbyActivity = flag || flag2 || flag3; target.Grave = flag; target.PlayerPiece = flag2; target.Terrain = flag3; } private static bool PlayersInArea(DungeonCandidate target) { Scan(target); return target.PlayersInArea; } private static bool OwnsGenerator(DungeonGenerator? generator) { if ((Object)(object)generator == (Object)null) { return true; } ZNetView nview = generator.m_nview; if ((Object)(object)nview != (Object)null && nview.IsValid()) { return nview.IsOwner(); } return false; } private static bool InRange(Vector3 center, Vector3 position, float radius) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) float num = center.x - position.x; float num2 = center.z - position.z; return num * num + num2 * num2 <= radius * radius; } private static float HorizontalDistance(Vector3 a, Vector3 b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) float num = a.x - b.x; float num2 = a.z - b.z; return Mathf.Sqrt(num * num + num2 * num2); } private static string PopupBody(DungeonCandidate target) { string text = "Reset " + target.Name + "?"; List<string> list = new List<string>(); if (target.Grave) { list.Add("graves"); } if (target.PlayerPiece) { list.Add("player-built pieces"); } if (target.Terrain) { list.Add("terrain changes"); } if (list.Count == 0) { return text; } return text + "\n\nThis will remove " + Join(list) + " in the reset area."; } private static string Join(List<string> parts) { if (parts.Count == 1) { return parts[0]; } if (parts.Count == 2) { return parts[0] + " and " + parts[1]; } return string.Join(", ", parts.GetRange(0, parts.Count - 1)) + ", and " + parts[parts.Count - 1]; } private static string RemainingText(int seconds) { if (seconds < 60) { return "You can reset a dungeon again in " + seconds + ((seconds == 1) ? " second." : " seconds."); } int num = (seconds + 59) / 60; return "You can reset a dungeon again in " + num + ((num == 1) ? " minute." : " minutes."); } private static void Say(string text) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { ((Character)localPlayer).Message((MessageType)2, text, 0, (Sprite)null, false); } Plugin.Log.LogInfo((object)text); } } [HarmonyPatch(typeof(Chat), "InputText")] internal static class LocationResetChatPatch { private static readonly FieldInfo InputField = typeof(Terminal).GetField("m_input", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static bool Prefix(Chat __instance) { object obj = InputField?.GetValue(__instance); PropertyInfo propertyInfo = obj?.GetType().GetProperty("text"); if (!(propertyInfo?.GetValue(obj) is string text) || !LocationResetPlayer.TryConsume(text)) { return true; } propertyInfo.SetValue(obj, string.Empty); return false; } } [HarmonyPatch(typeof(ZNet), "Awake")] internal static class LocationResetRpcPatch { private static void Postfix() { LocationResetPlayer.EnsureRpc(); } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] internal static class LocationResetPolicyRequestPatch { private static void Postfix() { LocationResetPlayer.RequestPolicy(); } } [HarmonyPatch(typeof(ZoneSystem), "OnNewPeer")] internal static class LocationResetPolicyPatch { private static void Postfix(long peerID) { if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer()) { LocationResetPlayer.SendPolicy(peerID); } } } [BepInPlugin("evu.evumisccompat", "EvuMiscCompat", "0.3.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { internal static ManualLogSource Log { get; private set; } private void Awake() { Log = ((BaseUnityPlugin)this).Logger; LocationResetPlayer.Bind(this); Harmony.CreateAndPatchAll(typeof(Plugin).Assembly, "evu.evumisccompat"); ((BaseUnityPlugin)this).Logger.LogInfo((object)"EvuMiscCompat loaded."); } } internal static class PluginInfo { public const string Guid = "evu.evumisccompat"; public const string Name = "EvuMiscCompat"; public const string Version = "0.3.2"; } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }