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 Custom Raids v1.8.1
Valheim.CustomRaids.dll
Decompiled 2 months ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using CreatureLevelControl; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using Valheim.CustomRaids.Configuration; using Valheim.CustomRaids.Configuration.ConfigTypes; using Valheim.CustomRaids.Core; using Valheim.CustomRaids.Core.Cache; using Valheim.CustomRaids.Core.Configuration; using Valheim.CustomRaids.Core.Network; using Valheim.CustomRaids.Debug; using Valheim.CustomRaids.Integrations; using Valheim.CustomRaids.Patches; using Valheim.CustomRaids.PreConfiguredRaids; using Valheim.CustomRaids.Raids; using Valheim.CustomRaids.Raids.Actions; using Valheim.CustomRaids.Raids.Conditions; using Valheim.CustomRaids.Raids.Managers; using Valheim.CustomRaids.Resetter; using Valheim.CustomRaids.Spawns.Caches; using Valheim.CustomRaids.Spawns.Conditions; using Valheim.CustomRaids.Spawns.Conditions.ModSpecific; using Valheim.CustomRaids.Spawns.Conditions.ModSpecific.CLLC; using Valheim.CustomRaids.Spawns.Modifiers; using Valheim.CustomRaids.Spawns.Modifiers.General; using Valheim.CustomRaids.Spawns.Modifiers.ModSpecific; using Valheim.CustomRaids.Spawns.Modifiers.ModSpecific.CLLC; using Valheim.CustomRaids.Spawns.Modifiers.ModSpecific.ST; using Valheim.CustomRaids.TerminalCommands; using Valheim.CustomRaids.Utilities; using Valheim.CustomRaids.Utilities.Extensions; using Valheim.CustomRaids.World; using Valheim.CustomRaids.World.Queries; using Valheim.CustomRaids.World.Zone; using VentureValheim.Progression; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("A Sharp Pen")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.8.1.0")] [assembly: AssemblyInformationalVersion("1.8.1+7e469c0ec05fba39d2eb9bc8a740da6566f24cbc")] [assembly: AssemblyProduct("Valheim.CustomRaids")] [assembly: AssemblyTitle("Valheim.CustomRaids")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.8.1.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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Valheim.CustomRaids { [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("asharppen.valheim.custom_raids", "Custom Raids", "1.8.1")] public class CustomRaidPlugin : BaseUnityPlugin { public const string ModId = "asharppen.valheim.custom_raids"; public const string PluginName = "Custom Raids"; public const string Version = "1.8.1"; private void Awake() { //IL_004f: Unknown result type (might be due to invalid IL or missing references) Log.Logger = ((BaseUnityPlugin)this).Logger; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading configurations..."); ConfigurationManager.GeneralConfig = ConfigurationManager.LoadGeneralConfigurations(); if (ConfigurationManager.GeneralConfig.GeneratePresetRaids.Value) { new Ragnarok().CreateConfigIfMissing(); new DeathsquitoSeason().CreateConfigIfMissing(); } new Harmony("asharppen.valheim.custom_raids").PatchAll(); LoadCommands(); } private static void LoadCommands() { ListPlayerReadyEventsCommand.Register(); ExplainPlayerReadyEventCommand.Register(); } } } namespace Valheim.CustomRaids.World { internal interface IZone { int Width { get; } Biome Biome { get; } Vector2i ZoneId { get; } Vector3 ZonePos { get; } Biome[] BiomeCorners { get; } BiomeArea BiomeArea { get; } bool HasBiome(Biome biome); Vector2i WorldToZoneCoordinate(Vector3 worldCoordinate); float Height(Vector3 worldCoordinate); float Height(Vector2i zoneLocalCoordinate); float OceanDepth(Vector3 worldCoordinate); float OceanDepth(Vector2i zoneLocalCoordinate); float Tilt(Vector3 worldCoordinate); } internal class ZoneHeightmap : IZone { private Heightmap Heightmap { get; } public int Width { get; } public Biome Biome { get; } public Vector2i ZoneId { get; } public Vector3 ZonePos { get; } public Biome[] BiomeCorners { get; } public BiomeArea BiomeArea { get; } public ZoneHeightmap(Heightmap heightmap) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_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_002a: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_006b: Unknown result type (might be due to invalid IL or missing references) Heightmap = heightmap; ZonePos = ((Component)heightmap).transform.position; ZoneId = ZonePos.GetZoneId(); Width = heightmap.m_width; Biome = heightmap.GetBiome(ZonePos, 0.02f, false); BiomeCorners = heightmap.m_cornerBiomes.ToArray(); BiomeArea = heightmap.GetBiomeArea(); } public bool HasBiome(Biome biome) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return Heightmap.HaveBiome(biome); } public float Height(Vector3 worldCoordinate) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) float result = default(float); Heightmap.GetHeight(worldCoordinate, ref result); return result; } public float Height(Vector2i zoneLocalCoordinate) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) return Heightmap.GetHeight(zoneLocalCoordinate.x, zoneLocalCoordinate.y); } public float OceanDepth(Vector3 worldCoordinate) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return Heightmap.GetOceanDepth(worldCoordinate); } public float OceanDepth(Vector2i zoneLocalCoordinate) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) Vector3 worldCoordinate = Heightmap.CalcVertex(zoneLocalCoordinate.x, zoneLocalCoordinate.y); return OceanDepth(worldCoordinate); } public float Tilt(Vector3 worldCoordinate) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: 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_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) RaycastHit val = default(RaycastHit); if (Physics.Raycast(worldCoordinate + Vector3.up * 5000f, Vector3.down, ref val, 10000f, ZoneSystem.instance.m_terrainRayMask)) { Vector3 normal = ((RaycastHit)(ref val)).normal; return 90f - Mathf.Asin(normal.y) * 57.29578f; } return 0f; } public Vector2i WorldToZoneCoordinate(Vector3 worldCoordinate) { //IL_0006: 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) int num = default(int); int num2 = default(int); Heightmap.WorldToVertex(worldCoordinate, ref num, ref num2); return new Vector2i(num, num2); } } internal class ZoneManager { [HarmonyPatch] private static class PatchHeightmap { [HarmonyPatch(typeof(Heightmap), "Regenerate")] [HarmonyPostfix] private static void Record(Heightmap __instance) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: 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 (__instance.m_isDistantLod) { Vector2i zoneId = ((Component)__instance).gameObject.transform.position.GetZoneId(); HeightmapsLoaded[zoneId] = new ZoneHeightmap(__instance); } } [HarmonyPatch(typeof(Heightmap), "OnDestroy")] [HarmonyPostfix] private static void RemoveRecord(Heightmap __instance) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) Vector2i zoneId = ((Component)__instance).gameObject.transform.position.GetZoneId(); HeightmapsLoaded.Remove(zoneId); } } private static Dictionary<Vector2i, ZoneHeightmap> HeightmapsLoaded; private static Dictionary<Vector2i, ZoneSimulated> SimulatedCache; static ZoneManager() { HeightmapsLoaded = new Dictionary<Vector2i, ZoneHeightmap>(); SimulatedCache = new Dictionary<Vector2i, ZoneSimulated>(); StateResetter.Subscribe(delegate { SimulatedCache = new Dictionary<Vector2i, ZoneSimulated>(); }); } public static IZone GetZone(Vector2i zoneId) { //IL_0005: 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_0027: 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) if (HeightmapsLoaded.TryGetValue(zoneId, out var value)) { return value; } if (SimulatedCache.TryGetValue(zoneId, out var value2)) { return value2; } return SimulatedCache[zoneId] = new ZoneSimulated(zoneId); } } internal class ZoneSimulated : IZone { private BiomeArea? _biomeArea; private float[] _oceanDepthCorners; public int Width { get; } = 64; public Biome Biome { get; } public Vector2i ZoneId { get; } public Vector3 ZonePos { get; } public Biome[] BiomeCorners { get; } public BiomeArea BiomeArea { get { //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_0045: 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_0038: 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) BiomeArea valueOrDefault = _biomeArea.GetValueOrDefault(); if (!_biomeArea.HasValue) { valueOrDefault = (BiomeArea)((!BiomeCorners.All((Biome x) => (int)BiomeCorners[0] == (int)x)) ? 1 : 2); _biomeArea = valueOrDefault; return valueOrDefault; } return valueOrDefault; } } private float[] OceanDepthCorners => _oceanDepthCorners ?? (_oceanDepthCorners = CalculateOceanDepths()); private static Vector2i North { get; } = new Vector2i(0, 1); private static Vector2i South { get; } = new Vector2i(0, -1); private static Vector2i West { get; } = new Vector2i(-1, 0); private static Vector2i East { get; } = new Vector2i(1, 0); public ZoneSimulated(Vector2i zoneId) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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_0048: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Invalid comparison between Unknown and I4 //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: 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_008f: Invalid comparison between Unknown and I4 //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Invalid comparison between Unknown and I4 //IL_009d: 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) ZoneId = zoneId; if (((Object)(object)ZoneSystem.instance).IsNotNull()) { ZonePos = ZoneSystem.GetZonePos(ZoneId); } else { ZonePos = new Vector3((float)(zoneId.x * Width), 0f, (float)(zoneId.y * Width)); } BiomeCorners = CalculateCornerBiomes(ZonePos); Biome val = BiomeCorners[0]; if ((int)val == (int)BiomeCorners[1] && (int)val == (int)BiomeCorners[2] && (int)val == (int)BiomeCorners[3]) { Biome = val; } else { Biome = GetBiome(ZonePos); } } public bool HasBiome(Biome biome) { //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) return BiomeCorners.Any((Biome x) => (x & biome) > 0); } public Vector2i WorldToZoneCoordinate(Vector3 worldCoordinate) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //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_000c: 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) Vector3 val = worldCoordinate - ZonePos; int num = Mathf.FloorToInt(val.x + 0.5f) + Width / 2; int num2 = Mathf.FloorToInt(val.z + 0.5f) + Width / 2; return new Vector2i(num, num2); } public float Height(Vector3 worldCoordinate) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) return Height(WorldToZoneCoordinate(worldCoordinate)); } public float Height(Vector2i zoneLocalCoordinate) { //IL_0000: 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_000f: 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_003d: 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_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Invalid comparison between Unknown and I4 //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Invalid comparison between Unknown and I4 //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Invalid comparison between Unknown and I4 //IL_00bd: Unknown result type (might be due to invalid IL or missing references) int y = zoneLocalCoordinate.y; int x = zoneLocalCoordinate.x; Vector3 val = ZonePos + new Vector3((float)Width * -0.5f, 0f, (float)Width * -0.5f); float num = val.z + (float)y; float num2 = Mathf.SmoothStep(0f, 1f, (float)y / (float)Width); float num3 = val.x + (float)x; float num4 = Mathf.SmoothStep(0f, 1f, (float)x / (float)Width); WorldGenerator instance = WorldGenerator.instance; Biome val2 = BiomeCorners[0]; Color val3 = default(Color); if ((int)val2 == (int)BiomeCorners[1] && (int)val2 == (int)BiomeCorners[2] && (int)val2 == (int)BiomeCorners[3]) { return instance.GetBiomeHeight(val2, num3, num, ref val3, false); } float biomeHeight = instance.GetBiomeHeight(val2, num3, num, ref val3, false); float biomeHeight2 = instance.GetBiomeHeight(BiomeCorners[1], num3, num, ref val3, false); float biomeHeight3 = instance.GetBiomeHeight(BiomeCorners[2], num3, num, ref val3, false); float biomeHeight4 = instance.GetBiomeHeight(BiomeCorners[3], num3, num, ref val3, false); float num5 = Mathf.Lerp(biomeHeight, biomeHeight2, num4); float num6 = Mathf.Lerp(biomeHeight3, biomeHeight4, num4); return Mathf.Lerp(num5, num6, num2); } public float OceanDepth(Vector3 worldCoordinate) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) return OceanDepth(WorldToZoneCoordinate(worldCoordinate)); } public float OceanDepth(Vector2i zoneLocalCoordinate) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) float num = (float)zoneLocalCoordinate.x / (float)Width; float num2 = (float)zoneLocalCoordinate.y / (float)Width; float num3 = Mathf.Lerp(OceanDepthCorners[3], OceanDepthCorners[2], num); float num4 = Mathf.Lerp(OceanDepthCorners[0], OceanDepthCorners[1], num); return Mathf.Lerp(num3, num4, num2); } private Biome[] CalculateCornerBiomes(Vector3 pos) { //IL_0000: 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_002a: 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_0040: 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_0052: Expected I4, but got Unknown //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Expected I4, but got Unknown //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Expected I4, but got Unknown //IL_009b: 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_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Expected I4, but got Unknown Vector3 val = pos + new Vector3((float)Width * -0.5f, 0f, (float)Width * -0.5f); WorldGenerator instance = WorldGenerator.instance; return (Biome[])(object)new Biome[4] { (Biome)(int)instance.GetBiome(val.x, val.z, 0.02f, false), (Biome)(int)instance.GetBiome(val.x + (float)Width, val.z, 0.02f, false), (Biome)(int)instance.GetBiome(val.x, val.z + (float)Width, 0.02f, false), (Biome)(int)instance.GetBiome(val.x + (float)Width, val.z + (float)Width, 0.02f, false) }; } private float[] CalculateOceanDepths() { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) float[] array = new float[4]; float num = (Object.op_Implicit((Object)(object)ZoneSystem.instance) ? ZoneSystem.instance.m_waterLevel : 30f); array[0] = Mathf.Max(0f, num - this.Height(new Vector2i(0, Width))); array[1] = Mathf.Max(0f, num - this.Height(new Vector2i(Width, Width))); array[2] = Mathf.Max(0f, num - this.Height(new Vector2i(Width, 0))); array[3] = Mathf.Max(0f, num - this.Height(new Vector2i(0, 0))); return array; } public float Tilt(Vector3 worldCoordinate) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //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_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: 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_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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_0021: 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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_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_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_008b: 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_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: 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_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0103: 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_010c: 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_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) Vector2i val = WorldToZoneCoordinate(worldCoordinate); Vector2i zoneLocalCoordinate = val + North; Vector2i zoneLocalCoordinate2 = val + South; Vector2i zoneLocalCoordinate3 = val + West; Vector2i zoneLocalCoordinate4 = val + East; float num = Height(val); float num2 = Height(zoneLocalCoordinate); float num3 = Height(zoneLocalCoordinate2); float num4 = Height(zoneLocalCoordinate3); float num5 = Height(zoneLocalCoordinate4); Vector3 normalized = default(Vector3); ((Vector3)(ref normalized))..ctor((float)North.x, num2 - num, (float)North.y); Vector3 normalized2 = default(Vector3); ((Vector3)(ref normalized2))..ctor((float)South.x, num3 - num, (float)South.y); Vector3 normalized3 = default(Vector3); ((Vector3)(ref normalized3))..ctor((float)West.x, num4 - num, (float)West.y); Vector3 normalized4 = default(Vector3); ((Vector3)(ref normalized4))..ctor((float)East.x, num5 - num, (float)East.y); normalized = ((Vector3)(ref normalized)).normalized; normalized2 = ((Vector3)(ref normalized2)).normalized; normalized3 = ((Vector3)(ref normalized3)).normalized; normalized4 = ((Vector3)(ref normalized4)).normalized; float num6 = AngleByCross(normalized, normalized4); float num7 = AngleByCross(normalized4, normalized2); float num8 = AngleByCross(normalized2, normalized3); float num9 = AngleByCross(normalized3, normalized); return (num6 + num8 + num9 + num7) / 4f; static float AngleByCross(Vector3 p1, Vector3 p2) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //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_000d: 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) Vector3 val2 = Vector3.Cross(p1, p2); return Mathf.Abs(Vector3.Angle(Vector2.op_Implicit(Vector2.up), val2)); } } public Biome GetBiome(Vector3 pos) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) (float x, float z) tuple = WorldCoordToNormalizedZoneCoord(pos); float item = tuple.x; float item2 = tuple.z; Dictionary<Biome, float> dictionary = new Dictionary<Biome, float>(4); AddWeight(dictionary, BiomeCorners[0], Distance(item, item2, 0f, 0f)); AddWeight(dictionary, BiomeCorners[1], Distance(item, item2, 1f, 0f)); AddWeight(dictionary, BiomeCorners[2], Distance(item, item2, 0f, 1f)); AddWeight(dictionary, BiomeCorners[3], Distance(item, item2, 1f, 1f)); return dictionary.OrderBy((KeyValuePair<Biome, float> v) => v.Value).First().Key; static void AddWeight(Dictionary<Biome, float> weights, Biome key, float weight) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) if (weights.TryGetValue(key, out var value)) { weights[key] = value + weight; } else { weights[key] = weight; } } static float Distance(float x1, float z1, float x2, float z2) { float num = x1 - x2; float num2 = z1 - z2; return Mathf.Sqrt(num * num + num2 * num2); } } private (float x, float z) WorldCoordToNormalizedZoneCoord(Vector3 pos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //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_000c: Unknown result type (might be due to invalid IL or missing references) Vector3 val = pos - ZonePos; float item = val.x / (float)Width + 0.5f; float item2 = val.z / (float)Width + 0.5f; return (item, item2); } } } namespace Valheim.CustomRaids.World.Zone { public static class ZoneUtils { public static List<Vector2i> GetZonesInSquare(int minX, int minZ, int maxX, int maxZ) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) List<Vector2i> list = new List<Vector2i>(); int num = Zonify(minX); int num2 = Zonify(maxX); int num3 = Zonify(minZ); int num4 = Zonify(maxZ); for (int i = num; i <= num2; i++) { for (int j = num3; j <= num4; j++) { list.Add(new Vector2i(i, j)); } } return list; } public static Vector2i GetZone(Vector3 pos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) return ZoneSystem.GetZone(pos); } public static Vector2i GetZone(int x, int z) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) return new Vector2i(Zonify(x), Zonify(z)); } public static int GetZoneIndex(Vector2i zone) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) return ZDOMan.instance.SectorToIndex(zone); } public static int Zonify(int coordinate) { return Mathf.FloorToInt((float)(coordinate + 32) / 64f); } } } namespace Valheim.CustomRaids.World.Queries { public abstract class BaseZdoQuery { private bool initialized; protected Vector3 Center { get; } protected int Range { get; } protected List<Vector2i> ZoneIds { get; private set; } protected List<ZDO> Zdos { get; private set; } protected int MinX { get; private set; } protected int MinZ { get; private set; } protected int MaxX { get; private set; } protected int MaxZ { get; private set; } protected BaseZdoQuery(Vector3 center, int range) { //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) Center = center; Range = range; Initialize(); } protected virtual void Initialize() { //IL_000a: 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_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) if (initialized) { return; } (int, int) range = GetRange((int)Center.x, Range); MinX = range.Item1; MaxX = range.Item2; range = GetRange((int)Center.z, Range); MinZ = range.Item1; MaxZ = range.Item2; ZoneIds = ZoneUtils.GetZonesInSquare(MinX, MinZ, MaxX, MaxZ); Zdos = new List<ZDO>(); foreach (Vector2i zoneId in ZoneIds) { ZDOMan.instance.FindObjects(zoneId, Zdos); } initialized = true; } protected static (int min, int max) GetRange(int center, int range) { return (center - range, center + range); } protected bool IsWithinRangeManhattan(ZDO zdo) { if (zdo.m_position.x < (float)MinX || zdo.m_position.x > (float)MaxX) { return false; } if (zdo.m_position.z < (float)MinZ || zdo.m_position.z > (float)MaxZ) { return false; } return true; } protected bool IsWithinRange(ZDO zdo) { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) if (zdo.m_position.x < (float)MinX || zdo.m_position.x > (float)MaxX) { return false; } if (zdo.m_position.z < (float)MinZ || zdo.m_position.z > (float)MaxZ) { return false; } return zdo.m_position.WithinHorizontalDistance(Center, Range); } } public class ZdoPrefabQuery : BaseZdoQuery { private Dictionary<int, int> CachedPrefabResults = new Dictionary<int, int>(); public ZdoPrefabQuery(Vector3 center, int range) : base(center, range) { }//IL_000c: Unknown result type (might be due to invalid IL or missing references) public int CountEntities(int prefabHash, Predicate<ZDO> condition = null) { Initialize(); if (CachedPrefabResults.TryGetValue(prefabHash, out var value)) { return value; } int num = 0; num = ((condition != null) ? base.Zdos.Count((ZDO x) => IsWithinRange(x, prefabHash) && condition(x)) : base.Zdos.Count((ZDO x) => IsWithinRange(x, prefabHash))); CachedPrefabResults[prefabHash] = num; return num; } public bool HasAny(int prefabHash) { Initialize(); if (CachedPrefabResults.TryGetValue(prefabHash, out var value)) { return value > 0; } return base.Zdos.Any((ZDO x) => IsWithinRange(x, prefabHash)); } private bool IsWithinRange(ZDO zdo, int prefabId) { if (zdo.m_prefab != prefabId) { return false; } return IsWithinRange(zdo); } } } namespace Valheim.CustomRaids.Utilities { internal static class FileUtils { public static string PrepareWriteDebugFile(string filename, string fileDescription) { string path = "Debug"; if (ConfigurationManager.GeneralConfig?.DebugFileFolder != null) { path = Path.Combine(ConfigurationManager.GeneralConfig.DebugFileFolder.Value.SplitBySlash()); } string text = Path.Combine(Paths.BepInExRootPath, path, filename); EnsureDirectoryExistsForFile(text); Log.LogInfo("Writing " + fileDescription + " to file " + text + "."); return text; } public static void EnsureDirectoryExistsForFile(string filePath) { string directoryName = Path.GetDirectoryName(filePath); if (!Directory.Exists(directoryName)) { Log.LogTrace("Creating missing folders in path."); Directory.CreateDirectory(directoryName); } } } internal static class PlayerUtils { public static List<Player> GetPlayersInRadius(Vector3 point, float range) { //IL_0021: 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) List<Player> list = new List<Player>(); foreach (Player allPlayer in Player.GetAllPlayers()) { if (Utils.DistanceXZ(((Component)allPlayer).transform.position, point) < range) { list.Add(allPlayer); } } return list; } public static List<ZDO> GetPlayerZdosInRadius(Vector3 point, float range) { //IL_0021: 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) List<ZDO> list = new List<ZDO>(); foreach (ZDO allCharacterZDO in ZNet.instance.GetAllCharacterZDOS()) { if (Utils.DistanceXZ(allCharacterZDO.GetPosition(), point) < range) { list.Add(allCharacterZDO); } } return list; } } } namespace Valheim.CustomRaids.Utilities.Extensions { internal static class CodeMatcherExtensions { internal static CodeMatcher Print(this CodeMatcher codeMatcher, int before, int after) { return codeMatcher; } } internal static class EnumExtensions { public static List<TEnum> Split<TEnum>(this TEnum enumVal) where TEnum : struct, Enum { int num = Convert.ToInt32(enumVal); List<TEnum> list = new List<TEnum>(); foreach (TEnum value in Enum.GetValues(typeof(TEnum))) { if ((num & Convert.ToInt32(value)) > 0) { list.Add(value); } } return list; } public static List<Biome> Split(this Biome biomeMask) { //IL_0023: 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_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Invalid comparison between Unknown and I4 //IL_0042: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Invalid comparison between Unknown and I4 //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Invalid comparison between Unknown and I4 //IL_0049: 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) List<Biome> list = new List<Biome>(); foreach (Biome value in Enum.GetValues(typeof(Biome))) { if ((int)value == 895) { if ((int)biomeMask == 895) { list.Add(value); } } else if ((biomeMask & value) > 0) { list.Add(value); } } return list; } } internal static class StringExtensions { private static char[] Comma = new char[1] { ',' }; private static readonly char[] Slash = new char[2] { '/', '\\' }; public static List<string> SplitByComma(this string value, bool toUpper = false) { if (string.IsNullOrEmpty(value)) { return new List<string>(0); } string[] array = value.Split(Comma, StringSplitOptions.RemoveEmptyEntries); if (array == null || array.Length == 0) { return new List<string>(0); } return array.Select(Clean).ToList(); string Clean(string x) { string text = x.Trim(); if (toUpper) { return text.ToUpperInvariant(); } return text; } } public static string[] SplitBySlash(this string value, bool toUpper = false) { return value.SplitBy(Slash, toUpper).ToArray(); } public static IEnumerable<string> SplitBy(this string value, char[] chars, bool toUpper = false) { string[] array = value.Split(chars, StringSplitOptions.RemoveEmptyEntries); if (array == null || array.Length == 0) { return Enumerable.Empty<string>(); } return array.Select(Clean); string Clean(string x) { string text = x.Trim(); if (toUpper) { return text.ToUpperInvariant(); } return text; } } } internal static class UnityObjectExtensions { public static bool IsNull(this Object obj) { if (obj == (Object)null || !Object.op_Implicit(obj)) { return true; } return false; } public static bool IsNotNull(this Object obj) { if (obj != (Object)null && Object.op_Implicit(obj)) { return true; } return false; } } internal static class Vector3Extensions { public static Vector2i GetZoneId(this Vector3 position) { //IL_0000: 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_000e: Unknown result type (might be due to invalid IL or missing references) return GetZone((int)position.x, (int)position.z); } private static Vector2i GetZone(int x, int z) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) return new Vector2i(Zonify(x), Zonify(z)); } private static int Zonify(int coordinate) { return Mathf.FloorToInt((float)(coordinate + 32) / 64f); } public static bool WithinHorizontalDistance(this Vector3 pos1, Vector3 pos2, float distance) { //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 = pos1.x - pos2.x; float num2 = pos1.z - pos2.z; return num * num + num2 * num2 < distance * distance; } } } namespace Valheim.CustomRaids.TerminalCommands { internal class ExplainPlayerReadyEventCommand { [CompilerGenerated] private static class <>O { public static ConsoleOptionsFetcher <0>__GetEventNames; } [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__1_0; public static Func<RandomEvent, string> <>9__3_0; internal void <Register>b__1_0(ConsoleEventArgs args) { Command(args.Context, args.Args); } internal string <GetEventNames>b__3_0(RandomEvent x) { return x.m_name; } } public const string CommandName = "customraids:explain_player_event"; internal static void Register() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown object obj = <>c.<>9__1_0; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { Command(args.Context, args.Args); }; <>c.<>9__1_0 = val; obj = (object)val; } object obj2 = <>O.<0>__GetEventNames; if (obj2 == null) { ConsoleOptionsFetcher val2 = GetEventNames; <>O.<0>__GetEventNames = val2; obj2 = (object)val2; } new ConsoleCommand("customraids:explain_player_event", "Explain why event is ready or not for current player. This is only for the player-based part of event requirements.", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)obj2, false, false, false); } private static void Command(Terminal context, string[] args) { try { if (args == null || args.Length == 0) { context.AddString("Must specify an event name."); return; } if (((Object)(object)Player.m_localPlayer).IsNull()) { Log.LogTrace("customraids:explain_player_event: local player is null. Skipping command."); return; } RandomEvent val = ((IEnumerable<RandomEvent>)RandEventSystem.instance.m_events).FirstOrDefault((Func<RandomEvent, bool>)((RandomEvent x) => x.m_name == args[1])); if (val == null) { context.AddString("No such event '" + args[1] + "' is present."); return; } if (!val.m_enabled) { context.AddString("Event is disabled."); } List<string> list = Explain(val); Log.LogTrace("customraids:explain_player_event: " + GeneralExtensions.Join<string>((IEnumerable<string>)list, (Func<string, string>)null, "\n")); foreach (string item in list) { context.AddString(item); } } catch (Exception e) { Log.LogError("Error while attempting to execute terminal command 'customraids:explain_player_event'.", e); } } private static List<string> GetEventNames() { if (((Object)(object)RandEventSystem.instance).IsNull()) { return new List<string>(); } return RandEventSystem.instance.m_events.Select((RandomEvent x) => x.m_name).ToList(); } private static List<string> Explain(RandomEvent randEvent) { List<string> list = new List<string>(); Player localPlayer = Player.m_localPlayer; bool flag = true; bool flag2 = true; bool flag3 = false; bool flag4 = false; List<ItemDrop> altRequiredNotKnownItems = randEvent.m_altRequiredNotKnownItems; if (altRequiredNotKnownItems != null && altRequiredNotKnownItems.Count > 0) { list.Add("Must not know items: "); foreach (ItemDrop altRequiredNotKnownItem in randEvent.m_altRequiredNotKnownItems) { if (localPlayer.IsMaterialKnown(altRequiredNotKnownItem.m_itemData.m_shared.m_name)) { list.Add(" [ ] " + ((Object)altRequiredNotKnownItem).name); flag = false; } else { list.Add(" [X] " + ((Object)altRequiredNotKnownItem).name); } } } List<string> altNotRequiredPlayerKeys = randEvent.m_altNotRequiredPlayerKeys; if (altNotRequiredPlayerKeys != null && altNotRequiredPlayerKeys.Count > 0) { list.Add("Must not have keys:"); foreach (string altNotRequiredPlayerKey in randEvent.m_altNotRequiredPlayerKeys) { if (((Humanoid)localPlayer).HaveUniqueKey(altNotRequiredPlayerKey)) { list.Add(" [ ] " + altNotRequiredPlayerKey); flag2 = false; } else { list.Add(" [X] " + altNotRequiredPlayerKey); } } } List<ItemDrop> altRequiredKnownItems = randEvent.m_altRequiredKnownItems; if (altRequiredKnownItems != null && altRequiredKnownItems.Count > 0) { list.Add("Must know one of items: "); foreach (ItemDrop altRequiredKnownItem in randEvent.m_altRequiredKnownItems) { if (localPlayer.IsMaterialKnown(altRequiredKnownItem.m_itemData.m_shared.m_name)) { list.Add(" [X] " + ((Object)altRequiredKnownItem).name); flag3 = true; } else { list.Add(" [ ] " + ((Object)altRequiredKnownItem).name); } } } List<string> altRequiredPlayerKeysAny = randEvent.m_altRequiredPlayerKeysAny; if (altRequiredPlayerKeysAny != null && altRequiredPlayerKeysAny.Count > 0) { list.Add("Must have one of keys (ignored if a required known item is present):"); foreach (string item in randEvent.m_altRequiredPlayerKeysAny) { if (((Humanoid)localPlayer).HaveUniqueKey(item)) { list.Add(" [X] " + item); flag4 = true; } else { list.Add(" [ ] " + item); } } } if (!flag) { list.Add("Event disabled due to knowing item in \"must not know items\" list."); } else if (!flag2) { list.Add("Event disabled due to having key in \"must not have keys\" list."); } else if (flag3) { list.Add("Event enabled due to knowing item in \"must know one of items\" list."); } else if (flag4) { list.Add("Event enabled due to having key in \"must know have one of keys\" list."); } else if (!flag3 && !flag4 && randEvent.m_altRequiredKnownItems.Count == 0 && randEvent.m_altRequiredPlayerKeysAny.Count == 0) { list.Add("Event enabled due to having fulfilled all requirements."); } else { list.Add("Event disabled due to not having fulfilled all requirements."); } return list; } } internal class ListPlayerKeysCommand { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__1_0; internal void <Register>b__1_0(ConsoleEventArgs args) { ListPlayerKeys(args.Context); } } public const string CommandName = "customraids:list_player_keys"; internal static void Register() { //IL_0032: 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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown object obj = <>c.<>9__1_0; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { ListPlayerKeys(args.Context); }; <>c.<>9__1_0 = val; obj = (object)val; } new ConsoleCommand("customraids:list_player_keys", "List player-specific key entries", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } private static void ListPlayerKeys(Terminal context) { try { if (((Object)(object)Player.m_localPlayer).IsNull()) { Log.LogTrace("customraids:list_player_keys: local player is null. Skipping command."); return; } string text = GeneralExtensions.Join<string>((IEnumerable<string>)Player.m_localPlayer.GetUniqueKeys(), (Func<string, string>)null, ", "); Log.LogTrace("customraids:list_player_keys: " + text); context.AddString(text); } catch (Exception e) { Log.LogError("Error while attempting to execute terminal command 'customraids:list_player_keys'.", e); } } } internal class ListPlayerKnownItemsCommand { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__1_0; internal void <Register>b__1_0(ConsoleEventArgs args) { Command(args.Context); } } public const string CommandName = "customraids:list_player_known_items"; internal static void Register() { //IL_0032: 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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown object obj = <>c.<>9__1_0; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { Command(args.Context); }; <>c.<>9__1_0 = val; obj = (object)val; } new ConsoleCommand("customraids:list_player_known_items", "List player-specific known item entries", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } private static void Command(Terminal context) { try { if (((Object)(object)Player.m_localPlayer).IsNull()) { Log.LogTrace("customraids:list_player_known_items: local player is null. Skipping command."); return; } string text = GeneralExtensions.Join<string>((IEnumerable<string>)Player.m_localPlayer.m_knownMaterial, (Func<string, string>)null, ", "); Log.LogTrace("customraids:list_player_known_items: " + text); context.AddString(text); } catch (Exception e) { Log.LogError("Error while attempting to execute terminal command 'customraids:list_player_known_items'.", e); } } } internal class ListPlayerReadyEventsCommand { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__1_0; internal void <Register>b__1_0(ConsoleEventArgs args) { Command(args.Context); } } public const string CommandName = "customraids:list_player_events"; internal static void Register() { //IL_0032: 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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown object obj = <>c.<>9__1_0; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { Command(args.Context); }; <>c.<>9__1_0 = val; obj = (object)val; } new ConsoleCommand("customraids:list_player_events", "List events ready for current player", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } private static void Command(Terminal context) { try { if (((Object)(object)Player.m_localPlayer).IsNull()) { Log.LogTrace("customraids:list_player_events: local player is null. Skipping command."); return; } List<string> readyEvents = Player.m_localPlayer.m_readyEvents; string text = " " + ((readyEvents != null) ? GeneralExtensions.Join<string>((IEnumerable<string>)readyEvents, (Func<string, string>)null, "\n ") : null); Log.LogTrace("customraids:list_player_events: \n" + text); context.AddString(text); } catch (Exception e) { Log.LogError("Error while attempting to execute terminal command 'customraids:list_player_events'.", e); } } } internal class UpdatePlayerReadyEventsCommand { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__1_0; internal void <Register>b__1_0(ConsoleEventArgs args) { Command(args.Context); } } public const string CommandName = "customraids:update_player_events"; internal static void Register() { //IL_0032: 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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown object obj = <>c.<>9__1_0; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { Command(args.Context); }; <>c.<>9__1_0 = val; obj = (object)val; } new ConsoleCommand("customraids:update_player_events", "Update list of events ready for current player.", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } private static void Command(Terminal context) { try { if (((Object)(object)Player.m_localPlayer).IsNull()) { Log.LogTrace("customraids:update_player_events: local player is null. Skipping command."); return; } Player.m_localPlayer.UpdateEvents(); List<string> readyEvents = Player.m_localPlayer.m_readyEvents; string text = " " + ((readyEvents != null) ? GeneralExtensions.Join<string>((IEnumerable<string>)readyEvents, (Func<string, string>)null, "\n ") : null); Log.LogTrace("customraids:update_player_events: \n" + text); context.AddString(text); } catch (Exception e) { Log.LogError("Error while attempting to execute terminal command 'customraids:update_player_events'.", e); } } } } namespace Valheim.CustomRaids.Spawns { public static class SpawnConditionManager { private static HashSet<ISpawnCondition> Conditions; static SpawnConditionManager() { Conditions = new HashSet<ISpawnCondition>(); Conditions.Add(Valheim.CustomRaids.Spawns.Conditions.ConditionDistanceToCenter.Instance); Conditions.Add(ConditionNearbyPlayersCarryItem.Instance); Conditions.Add(ConditionNearbyPlayersCarryValue.Instance); Conditions.Add(ConditionNearbyPlayersNoise.Instance); Conditions.Add(ConditionNotGlobalKeys.Instance); Conditions.Add(Valheim.CustomRaids.Spawns.Conditions.ConditionWorldAge.Instance); Conditions.Add(ConditionLoaderCLLC.ConditionWorldLevel); } public static bool Filter(SpawnSystem spawnSystem, SpawnData spawner) { SpawnConfiguration config = SpawnDataCache.Get(spawner)?.SpawnConfig; if (config == null) { return false; } return Conditions.Any(delegate(ISpawnCondition x) { try { return x?.ShouldFilter(spawnSystem, spawner, config) ?? false; } catch (Exception e) { Log.LogError("Error while attempting to check spawn condition " + x.GetType().Name + ".", e); return false; } }); } } public class SpawnContext { public SpawnSystem SpawnSystem { get; set; } public GameObject Spawn { get; set; } public SpawnData Spawner { get; set; } public SpawnConfiguration Config { get; set; } public RaidEventConfiguration RaidConfig { get; set; } } public static class SpawnModificationManager { private static HashSet<ISpawnModifier> SpawnModifiers; static SpawnModificationManager() { SpawnModifiers = new HashSet<ISpawnModifier>(); SpawnModifiers.Add(SpawnModifierSetFaction.Instance); SpawnModifiers.Add(SpawnModifierLoaderCLLC.BossAffix); SpawnModifiers.Add(SpawnModifierLoaderCLLC.ExtraEffect); SpawnModifiers.Add(SpawnModifierLoaderCLLC.Infusion); SpawnModifiers.Add(SpawnModifierLoaderCLLC.SetLevel); SpawnModifiers.Add(SpawnModifierLoaderSpawnThat.SetRelentless); SpawnModifiers.Add(SpawnModifierLoaderSpawnThat.SetTemplateId); SpawnModifiers.Add(SpawnModifierLoaderSpawnThat.SetTryDespawnOnAlert); } public static void ApplyModifiers(SpawnSystem spawnSystem, GameObject spawn, SpawnData spawner) { if (!Object.op_Implicit((Object)(object)spawnSystem) || spawnSystem == null || !Object.op_Implicit((Object)(object)spawn) || spawn == null || spawner == null) { return; } SpawnDataCache spawnDataCache = SpawnDataCache.Get(spawner); if (spawnDataCache == null || spawnDataCache.SpawnConfig == null) { return; } Log.LogTrace("Applying modifiers to spawn " + ((Object)spawn).name); foreach (ISpawnModifier spawnModifier in SpawnModifiers) { spawnModifier?.Modify(new SpawnContext { SpawnSystem = spawnSystem, Spawner = spawner, Spawn = spawn, Config = spawnDataCache.SpawnConfig, RaidConfig = spawnDataCache.RaidConfig }); } } } } namespace Valheim.CustomRaids.Spawns.Patches { [HarmonyPatch(typeof(Character))] public static class CharacterSetFactionPatch { [HarmonyPatch("Awake")] [HarmonyPostfix] private static void AssignFaction(Character __instance, ZNetView ___m_nview) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) ZDO val = ((___m_nview != null) ? ___m_nview.GetZDO() : null); if (val != null) { int @int = val.GetInt("faction", -1); if (@int >= 0) { __instance.m_faction = (Faction)@int; } } } } [HarmonyPatch(typeof(SpawnSystem))] public static class OnSpawnPatch { private static GameObject _spawnReference; [HarmonyPatch("Spawn")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> GetSpawnReference(IEnumerable<CodeInstruction> instructions) { //IL_0002: 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_0022: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Stloc_0, (object)null, (string)null) }).Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_0, (object)null) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate<Action<GameObject>>((Action<GameObject>)StoreReference) }) .InstructionEnumeration(); } private static void StoreReference(GameObject spawn) { _spawnReference = spawn; } [HarmonyPatch("Spawn")] [HarmonyPostfix] private static void ModifySpawn(SpawnSystem __instance, SpawnData critter, bool eventSpawner) { try { if (eventSpawner && !((Object)(object)_spawnReference).IsNull()) { SpawnModificationManager.ApplyModifiers(__instance, _spawnReference, critter); } } catch (Exception e) { Log.LogError("Error while attempting to modify event spawn.", e); } } } [HarmonyPatch(typeof(SpawnSystem))] public static class PreSpawnFilterPatch { [HarmonyPatch("UpdateSpawnList")] [HarmonyPrefix] private static void FilterSpawners(SpawnSystem __instance, ref List<SpawnData> spawners, bool eventSpawners) { if (!eventSpawners) { return; } List<SpawnData> list = new List<SpawnData>(); for (int i = 0; i < spawners.Count; i++) { try { if (SpawnConditionManager.Filter(__instance, spawners[i])) { continue; } } catch (Exception e) { SpawnData obj = spawners[i]; object obj2; if (obj == null) { obj2 = null; } else { GameObject prefab = obj.m_prefab; obj2 = ((prefab != null) ? ((Object)prefab).name : null); } Log.LogError("Error while checking if spawn template " + (string?)obj2 + " should be filtered.", e); } list.Add(spawners[i]); } spawners = list; } } } namespace Valheim.CustomRaids.Spawns.Modifiers { public interface ISpawnModifier { void Modify(SpawnContext context); } } namespace Valheim.CustomRaids.Spawns.Modifiers.ModSpecific { internal static class SpawnModifierLoaderCLLC { public static bool InstalledCLLC { get; } = (object)Type.GetType("CreatureLevelControl.API, CreatureLevelControl") != null; public static SpawnModifierBossAffix BossAffix { get { if (InstalledCLLC) { return SpawnModifierBossAffix.Instance; } return null; } } public static SpawnModifierExtraEffect ExtraEffect { get { if (InstalledCLLC) { return SpawnModifierExtraEffect.Instance; } return null; } } public static SpawnModifierInfusion Infusion { get { if (InstalledCLLC) { return SpawnModifierInfusion.Instance; } return null; } } public static SpawnModifierSetLevel SetLevel { get { if (InstalledCLLC) { return SpawnModifierSetLevel.Instance; } return null; } } } public static class SpawnModifierLoaderSpawnThat { public static bool InstalledSpawnThat { get; } = Chainloader.PluginInfos.ContainsKey("asharppen.valheim.spawn_that"); public static SpawnModifierSetRelentless SetRelentless { get { if (InstalledSpawnThat) { return SpawnModifierSetRelentless.Instance; } return null; } } public static SpawnModifierSetTemplateId SetTemplateId { get { if (InstalledSpawnThat) { return SpawnModifierSetTemplateId.Instance; } return null; } } public static SpawnModifierSetTryDespawnOnAlert SetTryDespawnOnAlert { get { if (InstalledSpawnThat) { return SpawnModifierSetTryDespawnOnAlert.Instance; } return null; } } } } namespace Valheim.CustomRaids.Spawns.Modifiers.ModSpecific.ST { public class SpawnModifierSetRelentless : ISpawnModifier { private static SpawnModifierSetRelentless _instance; public static SpawnModifierSetRelentless Instance => _instance ?? (_instance = new SpawnModifierSetRelentless()); public void Modify(SpawnContext context) { if (context != null && context.Config != null && Object.op_Implicit((Object)(object)context.Spawn) && context.Spawn != null && context.Config.TryGet("SpawnThat", out var value) && value is SpawnConfigSpawnThat spawnConfigSpawnThat && spawnConfigSpawnThat.SetRelentless.Value) { Log.LogTrace("Setting relentless"); ZDO zdo = ZdoCache.GetZdo(context.Spawn); if (zdo == null) { Log.LogDebug("Unable to find zdo."); } else { zdo.Set("spawnthat_relentless", true); } } } } public class SpawnModifierSetTemplateId : ISpawnModifier { private static SpawnModifierSetTemplateId _instance; public static SpawnModifierSetTemplateId Instance => _instance ?? (_instance = new SpawnModifierSetTemplateId()); public void Modify(SpawnContext context) { if (context != null && context.Config != null && Object.op_Implicit((Object)(object)context.Spawn) && context.Spawn != null && context.Config.TryGet("SpawnThat", out var value) && value is SpawnConfigSpawnThat spawnConfigSpawnThat && !string.IsNullOrWhiteSpace(spawnConfigSpawnThat.TemplateId.Value)) { ZDO zdo = ZdoCache.GetZdo(context.Spawn); if (zdo != null) { Log.LogTrace("Setting template id " + spawnConfigSpawnThat.TemplateId.Value); zdo.Set("spawn_template_id", spawnConfigSpawnThat.TemplateId.Value); } } } } public class SpawnModifierSetTryDespawnOnAlert : ISpawnModifier { private static SpawnModifierSetTryDespawnOnAlert _instance; public static SpawnModifierSetTryDespawnOnAlert Instance => _instance ?? (_instance = new SpawnModifierSetTryDespawnOnAlert()); public void Modify(SpawnContext context) { if (context != null && context.Config != null && Object.op_Implicit((Object)(object)context.Spawn) && context.Spawn != null && context.Config.TryGet("SpawnThat", out var value) && value is SpawnConfigSpawnThat spawnConfigSpawnThat && spawnConfigSpawnThat.SetTryDespawnOnAlert.Value) { ZDO zdo = ZdoCache.GetZdo(context.Spawn); if (zdo != null) { zdo.Set("spawnthat_despawn_on_alert", true); } } } } } namespace Valheim.CustomRaids.Spawns.Modifiers.ModSpecific.CLLC { internal class SpawnModifierBossAffix : ISpawnModifier { private static SpawnModifierBossAffix _instance; public static SpawnModifierBossAffix Instance => _instance ?? (_instance = new SpawnModifierBossAffix()); public void Modify(SpawnContext context) { //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) if (context.Spawn != null && context.Config.TryGet("CreatureLevelAndLootControl", out var value) && value is SpawnConfigCLLC spawnConfigCLLC && spawnConfigCLLC.SetBossAffix.Value.Length > 0) { Character component = ComponentCache.GetComponent<Character>(context.Spawn); if (component != null && component.IsBoss() && Enum.TryParse<BossAffix>(spawnConfigCLLC.SetBossAffix.Value, ignoreCase: true, out BossAffix result)) { Log.LogTrace($"Setting boss affix {result} for {((Object)context.Spawn).name}."); API.SetAffixBoss(component, result); } } } } internal class SpawnModifierExtraEffect : ISpawnModifier { private static SpawnModifierExtraEffect _instance; public static SpawnModifierExtraEffect Instance => _instance ?? (_instance = new SpawnModifierExtraEffect()); public void Modify(SpawnContext context) { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)context.Spawn) && context.Spawn != null && context.Config != null && context.Config.TryGet("CreatureLevelAndLootControl", out var value) && value is SpawnConfigCLLC spawnConfigCLLC && spawnConfigCLLC.SetExtraEffect.Value.Length > 0) { Character component = ComponentCache.GetComponent<Character>(context.Spawn); if (component != null && Enum.TryParse<CreatureExtraEffect>(spawnConfigCLLC.SetExtraEffect.Value, ignoreCase: true, out CreatureExtraEffect result)) { Log.LogTrace($"Setting extra effect {result} for {((Object)context.Spawn).name}."); API.SetExtraEffectCreature(component, result); } } } } internal class SpawnModifierInfusion : ISpawnModifier { private static SpawnModifierInfusion _instance; public static SpawnModifierInfusion Instance => _instance ?? (_instance = new SpawnModifierInfusion()); public void Modify(SpawnContext context) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)context.Spawn) && context.Spawn != null && context.Config.TryGet("CreatureLevelAndLootControl", out var value) && value is SpawnConfigCLLC spawnConfigCLLC && spawnConfigCLLC.SetInfusion.Value.Length > 0) { Character component = ComponentCache.GetComponent<Character>(context.Spawn); if (component != null && Enum.TryParse<CreatureInfusion>(spawnConfigCLLC.SetInfusion.Value, ignoreCase: true, out CreatureInfusion result)) { Log.LogTrace($"Setting infusion {result} for {((Object)context.Spawn).name}."); API.SetInfusionCreature(component, result); } } } } internal class SpawnModifierSetLevel : ISpawnModifier { private static SpawnModifierSetLevel _instance; public static SpawnModifierSetLevel Instance => _instance ?? (_instance = new SpawnModifierSetLevel()); public void Modify(SpawnContext context) { if (context.Spawn == null || !context.Config.TryGet("CreatureLevelAndLootControl", out var value) || !(value is SpawnConfigCLLC spawnConfigCLLC) || !spawnConfigCLLC.UseDefaultLevels.Value) { return; } Character component = ComponentCache.GetComponent<Character>(context.Spawn); if (component == null) { return; } int num = context.Config.MinLevel.Value; for (int i = 0; i < context.Config.MaxLevel.Value - context.Config.MinLevel.Value; i++) { if (Random.Range(0, 100) > 10) { break; } num++; } component.SetLevel(num); } } } namespace Valheim.CustomRaids.Spawns.Modifiers.General { public class SpawnModifierSetFaction : ISpawnModifier { private static SpawnModifierSetFaction _instance; public static SpawnModifierSetFaction Instance => _instance ?? (_instance = new SpawnModifierSetFaction()); public void Modify(SpawnContext context) { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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_00b9: Expected I4, but got Unknown if (context.Spawn == null) { return; } Character component = ComponentCache.GetComponent<Character>(context.Spawn); if (component != null) { string text = null; if (!string.IsNullOrWhiteSpace(context.Config.Faction.Value)) { text = context.Config.Faction.Value; } else if (!string.IsNullOrWhiteSpace(context.RaidConfig.Faction.Value)) { text = context.RaidConfig.Faction.Value; } Faction result = (Faction)8; if (!string.IsNullOrWhiteSpace(text) && !Enum.TryParse<Faction>(text.Trim(), ignoreCase: true, out result)) { Log.LogWarning("Failed to parse faction '" + text + "', defaulting to Boss."); } component.m_faction = result; ZdoCache.GetZdo(context.Spawn).Set("faction", (int)result); } } } } namespace Valheim.CustomRaids.Spawns.Conditions { public class ConditionDistanceToCenter : ISpawnCondition { private static ConditionDistanceToCenter _instance; public static ConditionDistanceToCenter Instance => _instance ?? (_instance = new ConditionDistanceToCenter()); public bool ShouldFilter(SpawnSystem spawnSystem, SpawnData spawner, SpawnConfiguration spawnConfig) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)spawnSystem) || spawnSystem == null || spawner == null || spawnConfig == null) { return false; } if (IsValid(((Component)spawnSystem).transform.position, spawnConfig)) { return false; } Log.LogTrace("Filtering spawn [" + spawnConfig.SectionKey + "] due to condition distance to center."); return true; } public bool IsValid(Vector3 position, SpawnConfiguration config) { float magnitude = ((Vector3)(ref position)).magnitude; if (magnitude < config.ConditionDistanceToCenterMin.Value) { return false; } if (config.ConditionDistanceToCenterMax.Value > 0f && magnitude > config.ConditionDistanceToCenterMax.Value) { return false; } return true; } } public class ConditionNearbyPlayersCarryItem : ISpawnCondition { private static ConditionNearbyPlayersCarryItem _instance; public static ConditionNearbyPlayersCarryItem Instance => _instance ?? (_instance = new ConditionNearbyPlayersCarryItem()); public bool ShouldFilter(SpawnSystem spawner, SpawnData spawn, SpawnConfiguration config) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)spawner) && Object.op_Implicit((Object)(object)((Component)spawner).transform) && spawner != null && config != null) { Transform transform = ((Component)spawner).transform; if (((transform != null) ? new Vector3?(transform.position) : null).HasValue) { if (IsValid(((Component)spawner).transform.position, config)) { return false; } Log.LogTrace("Filtering spawn [" + config.SectionKey + "] due to not finding any required items on nearby players."); return true; } } return false; } public bool IsValid(Vector3 pos, SpawnConfiguration config) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) if ((config.DistanceToTriggerPlayerConditions?.Value ?? 0f) <= 0f) { return true; } if (string.IsNullOrWhiteSpace(config.ConditionNearbyPlayerCarriesItem?.Value)) { return true; } List<Player> playersInRadius = PlayerUtils.GetPlayersInRadius(pos, config.DistanceToTriggerPlayerConditions.Value); HashSet<string> hashSet = config.ConditionNearbyPlayerCarriesItem?.Value?.SplitByComma(toUpper: true)?.ToHashSet(); if (hashSet == null || !hashSet.Any()) { return true; } foreach (Player item in playersInRadius) { if (((Object)(object)item).IsNull()) { continue; } Inventory inventory = ((Humanoid)item).GetInventory(); foreach (ItemData item2 in ((inventory != null) ? inventory.GetAllItems() : null) ?? new List<ItemData>(0)) { GameObject val = item2?.m_dropPrefab; if (!((Object)(object)val).IsNull()) { string text = ((Object)val).name.Trim().ToUpperInvariant(); if (!string.IsNullOrWhiteSpace(text) && hashSet.Contains(text)) { return true; } } } } return false; } } public class ConditionNearbyPlayersCarryValue : ISpawnCondition { private static ConditionNearbyPlayersCarryValue _instance; public static ConditionNearbyPlayersCarryValue Instance => _instance ?? (_instance = new ConditionNearbyPlayersCarryValue()); public bool ShouldFilter(SpawnSystem spawner, SpawnData spawn, SpawnConfiguration config) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)spawner) && Object.op_Implicit((Object)(object)((Component)spawner).transform) && spawner != null && config != null) { Transform transform = ((Component)spawner).transform; if (((transform != null) ? new Vector3?(transform.position) : null).HasValue) { if (Isvalid(((Component)spawner).transform.position, config)) { return false; } Log.LogTrace($"Filtering spawn [{config.SectionKey}] due to condition nearby players carry value {config.ConditionNearbyPlayersCarryValue.Value}."); return true; } } return false; } public bool Isvalid(Vector3 pos, SpawnConfiguration config) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) if ((config.DistanceToTriggerPlayerConditions?.Value ?? 0f) <= 0f) { return true; } if ((config.ConditionNearbyPlayersCarryValue?.Value ?? 0) <= 0) { return true; } List<Player> playersInRadius = PlayerUtils.GetPlayersInRadius(pos, config.DistanceToTriggerPlayerConditions.Value); int num = 0; foreach (Player item in playersInRadius) { if (((Object)(object)item).IsNull()) { continue; } Inventory inventory = ((Humanoid)item).GetInventory(); IEnumerable<ItemData> enumerable = ((inventory != null) ? inventory.GetAllItems() : null); foreach (ItemData item2 in enumerable ?? Enumerable.Empty<ItemData>()) { num += ((item2 != null) ? item2.GetValue() : 0); } } return num >= config.ConditionNearbyPlayersCarryValue.Value; } } public class ConditionNearbyPlayersNoise : ISpawnCondition { private static ConditionNearbyPlayersNoise _instance; public static ConditionNearbyPlayersNoise Instance => _instance ?? (_instance = new ConditionNearbyPlayersNoise()); public bool ShouldFilter(SpawnSystem spawner, SpawnData spawn, SpawnConfiguration config) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)spawner) && Object.op_Implicit((Object)(object)((Component)spawner).transform) && spawner != null && config != null) { Transform transform = ((Component)spawner).transform; if (((transform != null) ? new Vector3?(transform.position) : null).HasValue) { if (IsValid(((Component)spawner).transform.position, config)) { return false; } Log.LogTrace($"Filtering spawn [{config.SectionKey}] due to not having any nearby players emitting noise of {config.ConditionNearbyPlayersNoiseThreshold.Value} or higher."); return true; } } return false; } public bool IsValid(Vector3 pos, SpawnConfiguration config) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) if ((config.DistanceToTriggerPlayerConditions?.Value ?? 0f) <= 0f) { return true; } if ((config.ConditionNearbyPlayersNoiseThreshold?.Value ?? 0f) == 0f) { return true; } foreach (ZDO item in PlayerUtils.GetPlayerZdosInRadius(pos, config.DistanceToTriggerPlayerConditions.Value)) { if (item != null && item.GetFloat("noise", 0f) >= config.ConditionNearbyPlayersNoiseThreshold.Value) { return true; } } return false; } } public class ConditionNotGlobalKeys : ISpawnCondition { private static ConditionNotGlobalKeys _instance; public static ConditionNotGlobalKeys Instance => _instance ?? (_instance = new ConditionNotGlobalKeys()); public bool ShouldFilter(SpawnSystem spawner, SpawnData spawn, SpawnConfiguration config) { if (IsValid(config)) { return false; } Log.LogTrace("Filtering spawn [" + config.SectionKey + "] due to finding a global key from RequiredNotGlobalKey."); return true; } public bool IsValid(SpawnConfiguration config) { if (!string.IsNullOrEmpty(config.RequiredNotGlobalKey?.Value)) { List<string> list = config.RequiredNotGlobalKey.Value.SplitByComma(); if (list.Count > 0) { foreach (string item in list) { if (ZoneSystem.instance.GetGlobalKey(item)) { return false; } } } } return true; } } public class ConditionWorldAge : ISpawnCondition { private static ConditionWorldAge _instance; public static ConditionWorldAge Instance => _instance ?? (_instance = new ConditionWorldAge()); public bool ShouldFilter(SpawnSystem spawner, SpawnData spawn, SpawnConfiguration config) { if (IsValid(config)) { return false; } Log.LogTrace("Filtering spawn [" + config.SectionKey + "] due to world age."); return true; } public bool IsValid(SpawnConfiguration config) { int day = EnvMan.instance.GetDay(ZNet.instance.GetTimeSeconds()); if (config.ConditionWorldAgeDaysMin.Value > 0f && config.ConditionWorldAgeDaysMin.Value > (float)day) { return false; } if (config.ConditionWorldAgeDaysMax.Value > 0f && config.ConditionWorldAgeDaysMax.Value < (float)day) { return false; } return true; } } public interface ISpawnCondition { bool ShouldFilter(SpawnSystem spawnSystem, SpawnData spawn, SpawnConfiguration config); } } namespace Valheim.CustomRaids.Spawns.Conditions.ModSpecific { internal static class ConditionLoaderCLLC { public static bool InstalledCLLC { get; } = (object)Type.GetType("CreatureLevelControl.API, CreatureLevelControl") != null; public static ConditionWorldLevel ConditionWorldLevel { get { if (InstalledCLLC) { return ConditionWorldLevel.Instance; } return null; } } } } namespace Valheim.CustomRaids.Spawns.Conditions.ModSpecific.CLLC { public class ConditionWorldLevel : ISpawnCondition { private static ConditionWorldLevel _instance; public static ConditionWorldLevel Instance => _instance ?? (_instance = new ConditionWorldLevel()); public bool ShouldFilter(SpawnSystem spawner, SpawnData spawn, SpawnConfiguration spawnerConfig) { if (spawnerConfig.TryGet("CreatureLevelAndLootControl", out var value) && value is SpawnConfigCLLC spawnConfigCLLC) { int worldLevel = API.GetWorldLevel(); if (spawnConfigCLLC.ConditionWorldLevelMin.Value >= 0 && worldLevel < spawnConfigCLLC.ConditionWorldLevelMin.Value) { Log.LogTrace($"Filtering spawn [{spawnConfigCLLC.SectionKey}] due to CLLC world level being too low. {worldLevel} < {spawnConfigCLLC.ConditionWorldLevelMin}."); return true; } if (spawnConfigCLLC.ConditionWorldLevelMax.Value >= 0 && worldLevel > spawnConfigCLLC.ConditionWorldLevelMax.Value) { Log.LogTrace($"Filtering spawn [{spawnConfigCLLC.SectionKey}] due to CLLC world level being too high. {worldLevel} > {spawnConfigCLLC.ConditionWorldLevelMax}."); return true; } } return false; } } } namespace Valheim.CustomRaids.Spawns.Caches { public class SpawnDataCache { private static ConditionalWeakTable<SpawnData, SpawnDataCache> SpawnDataTable = new ConditionalWeakTable<SpawnData, SpawnDataCache>(); public RaidEventConfiguration RaidConfig { get; set; } public SpawnConfiguration SpawnConfig { get; set; } public static SpawnDataCache Get(SpawnData spawnData) { if (SpawnDataTable.TryGetValue(spawnData, out var value)) { return value; } return null; } public static SpawnDataCache GetOrCreate(SpawnData spawnData) { return SpawnDataTable.GetOrCreateValue(spawnData); } public SpawnDataCache SetSpawnConfig(SpawnConfiguration config) { SpawnConfig = config; return this; } public SpawnDataCache SetRaidConfig(RaidEventConfiguration config) { RaidConfig = config; return this; } } } namespace Valheim.CustomRaids.Resetter { [HarmonyPatch(typeof(FejdStartup))] internal static class LifecycleManager { internal static GameState State { get; set; } [HarmonyPatch("OnWorldStart")] [HarmonyPrefix] private static void ResetState() { State = GameState.Singleplayer; Log.LogDebug("OnWorldStart: Resetting configurations"); StateResetter.Reset(); ConfigurationManager.LoadAllConfigurations(); RandEventSystemWaitPatch.Wait = false; } [HarmonyPatch("JoinServer")] [HarmonyPrefix] private static void ResetStateMultiplayer() { State = GameState.Multiplayer; Log.LogDebug("JoinServer: Resetting configurations"); StateResetter.Reset(); } [HarmonyPatch("ParseServerArguments")] [HarmonyPrefix] private static void ResetStateServer() { State = GameState.Dedicated; Log.LogDebug("ParseServerArguments: Resetting configurations"); StateResetter.Reset(); ConfigurationManager.LoadAllConfigurations(); RandEventSystemWaitPatch.Wait = false; } } internal enum GameState { Invalid, Singleplayer, Multiplayer, Dedicated } public static class StateResetter { private static HashSet<Action> OnResetActions = new HashSet<Action>(); public static void Subscribe(Action onReset) { OnResetActions.Add(onReset); } public static void Unsubscribe(Action onReset) { OnResetActions.Remove(onReset); } internal static void Reset() { Log.LogDebug("Resetting mod state."); foreach (Action onResetAction in OnResetActions) { onResetAction(); } } } } namespace Valheim.CustomRaids.Raids { public class Raid { public string Name { get; set; } public List<IRaidCondition> Conditions { get; set; } = new List<IRaidCondition>(0); public List<IRaidAction> OnStopActions { get; set; } = new List<IRaidAction>(0); public Raid(string raidName) { Name = raidName; } } public class RaidContext { public RandomEvent RandomEvent { get; set; } public Vector3 Position { get; set; } public long? PlayerUserId { get; set; } public long? PlayerProfileId { get; set; } public long? IdentifyPlayerByPos(Vector3 pos) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) foreach (ZNetPeer peer in ZNet.instance.GetPeers()) { if (peer.m_refPos == pos) { ZDO zDO = ZDOMan.instance.GetZDO(peer.m_characterID); PlayerProfileId = ((zDO != null) ? new long?(zDO.GetLong(ZDOVars.s_playerID, 0L)) : null); PlayerUserId = ((ZDOID)(ref peer.m_characterID)).UserID; return (PlayerProfileId != 0) ? PlayerProfileId : null; } } return null; } } public static class RandomEventCache { public static ConditionalWeakTable<RandomEvent, RandomEventData> EventTable = new ConditionalWeakTable<RandomEvent, RandomEventData>(); public static void Initialize(RandomEvent randomEvent, RaidEventConfiguration config) { EventTable.GetOrCreateValue(randomEvent).Config = config; } public static RandomEventData Get(RandomEvent randomEvent) { return EventTable.GetOrCreateValue(randomEvent); } public static RaidEventConfiguration GetConfig(RandomEvent randomEvent) { if (EventTable.TryGetValue(randomEvent, out var value)) { return value.Config; } return null; } } public class RandomEventData { public RaidEventConfiguration Config; public double LastChecked; } } namespace Valheim.CustomRaids.Raids.Managers { internal static class RaidActionManager { public static void ExecuteOnStopRandomEventActions() { ExecuteOnStopActions(RandEventSystem.instance.m_randomEvent); } public static void ExecuteOnStopForcedEventActions() { ExecuteOnStopActions(RandEventSystem.instance.m_forcedEvent); } public static void ExecuteOnStopActions(RandomEvent randomEvent) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) RaidContext context = new RaidContext { RandomEvent = randomEvent, Position = randomEvent.m_pos }; if (randomEvent == null) { return; } try { if (!RaidManager.TryGetRaid(randomEvent, out var raid)) { return; } foreach (IRaidAction onStopAction in raid.OnStopActions) { if (onStopAction != null) { try { Log.LogTrace("Executing on-stop raid action: " + onStopAction.GetType().Name); onStopAction.Execute(context); } catch (Exception e) { Log.LogError("Error while attempting to execute raid on-stop action '" + onStopAction.GetType().Name + "' for random event '" + randomEvent.m_name + "'.", e); } } } } catch (Exception e2) { Log.LogError("Error while attempting to look up raid configuration for random event '" + randomEvent?.m_name + "'.", e2); } } } public static class RaidConditionManager { public static void RegisterCondition(string raidName, IRaidCondition condition) { if (RaidManager.TryGetRaid(raidName, out var raid)) { raid.Conditions.Add(condition); return; } Log.LogWarning("Attempted to register condition '" + condition.GetType().Name + "' for raid '" + raidName + "' before it was registered."); } public static bool HasValidConditions(RandomEvent randomEvent, Vector3 raidPosition) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) RaidContext raidContext = new RaidContext { RandomEvent = randomEvent, Position = raidPosition }; if (RaidManager.TryGetRaid(randomEvent, out var raid) && !raid.Conditions.All(delegate(IRaidCondition x) { try { return x.IsValid(raidContext); } catch (Exception e) { Log.LogWarning("Error during check of raid condition '" + x.GetType().Name + "'. Ignoring condition.", e); return true; } })) { return false; } return true; } } public static class RaidConfigManager { private static bool _isConfigured; static RaidConfigManager() { StateResetter.Subscribe(delegate { _isConfigured = false; }); } public static void ApplyConfigs() { if (_isConfigured) { return; } try { RandEventSystem instance = RandEventSystem.instance; Log.LogDebug("Applying configurations to RandEventSystem."); if (ConfigurationManager.GeneralConfig == null) { Log.LogWarning("No configuration loaded yet. Skipping application of raid changes."); return; } GeneralConfiguration generalConfig = ConfigurationManager.GeneralConfig; if (generalConfig != null && (generalConfig.WriteDefaultEventDataToDisk?.Value).GetValueOrDefault()) { EventsWriter.WriteToFile(instance.m_events, "custom_raids.raids.before_changes.txt"); } if (ConfigurationManager.GeneralConfig?.EventCheckInterval != null) { instance.m_eventIntervalMin = ConfigurationManager.GeneralConfig.EventCheckInterval.Value; } if (ConfigurationManager.GeneralConfig?.EventTriggerChance != null) { instance.m_eventChance = ConfigurationManager.GeneralConfig.EventTriggerChance.Value; } GeneralConfiguration generalConfig2 = ConfigurationManager.GeneralConfig; if (generalConfig2 != null && (generalConfig2.RemoveAllExistingRaids?.Value).GetValueOrDefault()) { Log.LogDebug("Removing default raids."); instance.m_events?.RemoveAll((RandomEvent x) => x.m_random); } if (ConfigurationManager.RaidConfig?.Subsections == null) { return; } Log.LogDebug($"Found {ConfigurationManager.RaidConfig.Subsections.Count} raid configurations to apply."); foreach (RaidEventConfiguration value in ConfigurationManager.RaidConfig.Subsections.Values) { GeneralConfiguration generalConfig3 = ConfigurationManager.GeneralConfig; if (generalConfig3 != null && (generalConfig3.OverrideExisting?.Value).GetValueOrDefault() && (instance.m_events?.Count ?? 0) > 0) { for (int num = instance.m_events.Count - 1; num >= 0; num--) { string text = instance.m_events[num].m_name.ToUpperInvariant().Trim(); string text2 = value.Name.Value.ToUpperInvariant().Trim(); if (text == text2) { Log.LogDebug("Overriding existing event " + instance.m_events[num].m_name + " with configured"); instance.m_events.RemoveAt(num); } } } ConfigurationEntry<bool> enabled = value.Enabled; if (enabled == null || !enabled.Value) { continue; } Log.LogDebug($"Adding raid '{value.Name}' to possible raids"); try { if (instance.m_events == null) { instance.m_events = new List<RandomEvent>(); } if ((value?.Subsections?.Count).GetValueOrDefault() != 0) { RandomEvent val = CreateEvent(value); RandomEventCache.Initialize(val, value); StoreRaid(val, value); instance.m_events.Add(val); } } catch (Exception ex) { Log.LogWarning($"Failed to create possible raid {value.Name}: " + ex.Message); } } if (ConfigurationManager.GeneralConfig.WritePostChangeEventDataToDisk.Value) { EventsWriter.WriteToFile(instance.m_events, "custom_raids.raids.after_changes.txt", "random events (raids) after configuration"); } } catch (Exception e) { Log.LogError("Error during application of raid configurations.", e); } _isConfigured = true; } private static Biome GetBiome(RaidEventConfiguration config) { //IL_0021: 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_0053: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) string value = config.Biomes.Value; if (string.IsNullOrEmpty(value)) { return (Biome)int.MaxValue; } List<Biome> list = new List<Biome>(); Biome val = (Biome)0; foreach (string item in value.SplitByComma()) { if (Enum.TryParse<Biome>(item.Trim(), ignoreCase: true, out Biome result)) { list.Add(result); val |= result; } else { Log.LogWarning("Unable to parse biome '" + item + "'"); } } return val; } private static RandomEvent CreateEvent(RaidEventConfiguration raidEvent) { //IL_0096: 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_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_0291: Unknown result type (might be due to invalid IL or missing references) //IL_02a3: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Expected O, but got Unknown //IL_0460: Unknown result type (might be due to invalid IL or missing references) //IL_0465: Unknown result type (might be due to invalid IL or missing references) //IL_047b: Unknown result type (might be due to invalid IL or missing references) //IL_0491: Unknown result type (might be due to invalid IL or missing references) //IL_04a7: Unknown result type (might be due to invalid IL or missing references) //IL_04bd: Unknown result type (might be due to invalid IL or missing references) //IL_04d3: Unknown result type (might be due to invalid IL or missing references) //IL_04e9: Unknown result type (might be due to invalid IL or missing references) //IL_04ff: Unknown result type (might be due to invalid IL or missing references) //IL_0506: Unknown result type (might be due to invalid IL or missing references) //IL_051c: Unknown result type (might be due to invalid IL or missing references) //IL_0523: Unknown result type (might be due to invalid IL or missing references) //IL_052a: Unknown result type (might be due to invalid IL or missing references) //IL_052f: Unknown result type (might be due to invalid IL or missing references) //IL_0534: Unknown result type (might be due to invalid IL or missing references) //IL_054a: Unknown result type (might be due to invalid IL or missing references) //IL_0551: Unknown result type (might be due to invalid IL or missing references) //IL_0558: Unknown result type (might be due to invalid IL or missing references) //IL_0560: Unknown result type (might be due to invalid IL or missing references) //IL_056c: Unknown result type (might be due to invalid IL or missing references) //IL_0578: Unknown result type (might be due to invalid IL or missing references) //IL_0583: Unknown result type (might be due to invalid IL or missing references) //IL_058f: Expected O, but got Unknown List<SpawnData> list = new List<SpawnData>(); foreach (SpawnConfiguration value in raidEvent.Subsections.Values) { GameObject prefab = ZNetScene.instance.GetPrefab(value.PrefabName.Value); if (prefab == null) { Log.LogWarning("Unable to find spawn " + value.PrefabName.Value); continue; } List<string> requiredEnvironments = value.RequiredEnvironments?.Value?.SplitByComma(); SpawnData val = new SpawnData { m_name = value.Name.Value, m_enabled = value.Enabled.Value, m_prefab = prefab, m_maxSpawned = value.MaxSpawned.Value, m_spawnInterval = value.SpawnInterval.Value, m_spawnChance = value.SpawnChancePerInterval.Value, m_spawnDistance = value.SpawnDistance.Value, m_spawnRadiusMin = value.SpawnRadiusMin.Value, m_spawnRadiusMax = value.SpawnRadiusMax.Value, m_groupSizeMin = value.GroupSizeMin.Value, m_groupSizeMax = value.GroupSizeMax.Value, m_huntPlayer = value.HuntPlayer.Value, m_maxLevel = value.MaxLevel.Value, m_minLevel = value.MinLevel.Value, m_groundOffset = value.GroundOffset.Value, m_groupRadius = value.GroupRadius.Value, m_inForest = value.InForest.Value