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 ZenRaids v1.1.1
plugins/ZenRaids.dll
Decompiled 2 weeks agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using Jotunn.Utils; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.SceneManagement; using Zen; using Zen.Lib; using Zen.Lib.Config; using ZenRaids.Compatibility; using ZenRaids.SpawnProtect; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("ZenRaids")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ZenRaids")] [assembly: AssemblyCopyright("Copyright \ufffd 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")] [assembly: AssemblyFileVersion("0.0.1.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.1.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ZenRaids { [BepInPlugin("ZenDragon.ZenRaids", "ZenRaids", "1.1.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] internal class Plugin : ZenMod<Plugin> { public const string PluginName = "ZenRaids"; public const string PluginVersion = "1.1.1"; public const string PluginGUID = "ZenDragon.ZenRaids"; protected override void Setup() { ((ZenMod)this).RunOnServer = true; RaidRules.SetupConsole(); base.ConfigSync += ItemDespawn.ProtectExplicitItems; base.ConfigSync += RaidRules.SetupEvents; } protected override void TitleScene(bool isFirstBoot) { } protected override void WorldStart() { RaidRules.SetupEvents(); Farming.Check(); ItemDespawn.InitAnimalFoods(); } protected override void Shutdown() { } protected override void HotRestore() { LitArea.SetupFX(); } protected override HelpInfo? GetHelpInfo() { //IL_002c: 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_00ad: Expected O, but got Unknown StringBuilder stringBuilder = new StringBuilder(); if (RaidRules.Configs.MinPlayerCount.Value > 1) { stringBuilder.AppendLine(HelpInfo.Format<int>(RaidRules.Configs.MinPlayerCount, true, true, true)); } if ((int)RaidRules.Configs.NoRaidBiomes.Value != 0) { stringBuilder.AppendLine(HelpInfo.Format<Biome>(RaidRules.Configs.NoRaidBiomes, true, true, true)); } if (Configs.FireMustBeLit.Value) { stringBuilder.AppendLine(HelpInfo.Format<bool>(Configs.FireMustBeLit, false, true, true)); if (Configs.PerimeterRangeVisible.Value > 0) { stringBuilder.AppendLine(HelpInfo.Format<int>(Configs.PerimeterRangeVisible, false, true, true)); stringBuilder.AppendLine(HelpInfo.Format<KeyCode>(Configs.PerimeterRangeHideKey, true, true, true)); } } return new HelpInfo("Raids", stringBuilder.ToString()); } } [HarmonyPatch] internal static class RaidRules { public static class Configs { public static readonly ConfigEntry<StringList> NeverActivatedRaids; public static readonly ConfigEntry<StringList> NeverDeactivatedRaids; public static readonly ConfigEntry<bool> IgnoreConditionKnownItems; public static readonly ConfigEntry<Biome> NoRaidBiomes; public static readonly ConfigEntry<StringList> NoRaidBiomesExceptions; public static readonly ConfigEntry<int> MinPlayerCount; public static readonly ConfigEntry<int> RaidThresholdLimit; public static readonly ConfigEntry<bool> RaidThresholdOptimization; public static readonly ConfigEntry<int> RaidChanceBase; public static readonly ConfigEntry<float> RaidChanceBonusByPlayer; public static readonly ConfigEntry<bool> AppendGlobalKeysToPlayerKeys; public static readonly ConfigEntry<StringList> AllowedBiomes; public static readonly ConfigEntry<StringList> GlobalKeysActivate; public static readonly ConfigEntry<StringList> GlobalKeysDeactivate; public static readonly ConfigEntry<StringList> PlayerKeysActivateAll; public static readonly ConfigEntry<StringList> PlayerKeysActivateAny; public static readonly ConfigEntry<StringList> PlayerKeysDeactivate; public static readonly ConfigEntry<StringList> PlayerKnownItemsActivate; public static readonly ConfigEntry<StringList> PlayerKnownItemsDeactivate; static Configs() { //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Expected O, but got Unknown //IL_00b4: Expected O, but got Unknown //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Expected O, but got Unknown //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Expected O, but got Unknown //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Expected O, but got Unknown //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Expected O, but got Unknown //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Expected O, but got Unknown //IL_025c: Expected O, but got Unknown //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Expected O, but got Unknown //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Expected O, but got Unknown //IL_0291: Expected O, but got Unknown MinPlayerCount = Config.Define<int>(true, "Raids General", "Min Player Count", 1, Config.AcceptRange<int>(1, 10), "Minimum number of players required to be online to trigger a raid."); RaidChanceBase = Config.Define<int>(true, "Raids General", "Raid Chance", -1, Config.AcceptRange<int>(-1, 100), "The base chance of triggering raids. Vanilla: 20\r\nSet to -1 to disable this config option and use vanilla values instead.\r\nNote: if this is set to 0 then raids will never trigger, also if global key eventrate is set to 0 then raids will never trigger."); RaidChanceBonusByPlayer = Config.Define<float>(true, "Raids General", "Raid Chance Bonus By Player", 0f, Config.AcceptRange<float>(-10f, 10f), "Alter the odds of triggering a raid based on the number of players logged on to the server.\r\nPositive numbers increase the odds of triggering a raid based on the number of players.\r\nNegative numbers decrease the odds.\r\nFormula: RandValue(0-100) <= (RaidChance + (PlayerCount - 1) * Bonus) / RaidRate\r\nRaidChance in vanilla is 20%, RaidRate is set via global key eventrate\r\nExample: +3 would increase the odds by 3% by every player logged on if more than 1 player is logged in.\r\nSo 5 players logged on would change the odds to: 20% + 3% x 4 players = 32%\r\nA single player logged on would have a 20% + 3% x 0 players = 20%"); NoRaidBiomes = Config.Define<Biome>(true, "Raids General", "No Raid Biomes", (Biome)1, "No Raids allowed in these biomes"); StringList val = new StringList(); ((List<string>)val).Add("army_eikthyr"); NoRaidBiomesExceptions = Config.Define<StringList>(true, "Raids General", "No Raid Biomes Exeption Raids", val, "These raids are allowed even in NoRaidBiomes. Comma separated list of raid names."); IgnoreConditionKnownItems = Config.Define<bool>(true, "Raids General", "Ignore Condition - Known Items", true, "For per player events: Ignore item knowledge as a raid condition. (Vanilla: false)\r\nIn vanilla, knowledge of specific items flags you for raids based on that knowledge. \r\nIf this option is true then it doesn't matter what items you know, per player raids will only be based on player keys.\r\nThis prevents accidentally getting flagged by just picking up the wrong item.\r\n[restart required for changes to take effect]"); NeverActivatedRaids = Config.Define<StringList>(true, "Raids General", "Never Activated Raids", StringList.Empty, "Comma separated list of raid names.\r\nThese raids have their activate condition removed so they are never in rotation to be triggered.\r\n[restart required for changes to take effect]"); NeverDeactivatedRaids = Config.Define<StringList>(true, "Raids General", "Never Deactivated Raids", StringList.Empty, "Comma separated list of raid names.\r\nOnce activated, these raids have their disable condition removed so they are always in rotation to be triggered.\r\n[restart required for changes to take effect]"); RaidThresholdLimit = Config.Define<int>(true, "Raids General", "Raid Threshold - Limit", 3, Config.AcceptRange<int>(1, 20), "Number of base pieces the player needs to be near to trigger raids (Vanilla: 3)\r\nLower numbers increase odds of raids being triggered."); RaidThresholdOptimization = Config.Define<bool>(true, "Raids General", "Raid Threshold - Optimization", true, "Stop counting base pieces once the threshold is reached.\r\nSaves framerate and cpu cycles since no processing is wasted counting beyond the required limit."); AppendGlobalKeysToPlayerKeys = Config.Define<bool>(true, "Raid Keys", "Append Global Keys To Player Keys", true, "Append any global keys to the player keys list for triggering a raid.\r\nThis can be useful when using modded content that did not consider raid to be per player progression.\r\n[restart required for changes to take effect]"); AllowedBiomes = Config.Define<StringList>(true, "Raid Keys", "Allowed Biomes", StringList.Empty, "Comma separated list of raidname and biomes it is allowed to spawn in.\r\nSyntax: raidname:biome1|biome2|biome3, raidname:NONE, raidname:ALL, etc...\r\nSpecify NONE to disable all biomes for a given raid.\r\nSpecifiy ALL to allow all biomes for a given raid.\r\nPossible biomes: " + GeneralExtensions.Join<string>((IEnumerable<string>)Enum.GetNames(typeof(Biome)), (Func<string, string>)null, ", ") + "\r\nIf raid name is not defined then vanilla values are used for that raid instead.\r\nConsole command: zen_raidrules to view current raid conditions.\r\n[restart required for changes to take effect]"); GlobalKeysActivate = Config.Define<StringList>(true, "Raid Keys", "Global Keys - Activate", StringList.Empty, "Set global keys to activate raids.\r\nComma separated list of raid name and keys separated by vertical bar.\r\nSyntax: raidname:key1|key2|key3, raidname:key1|key2, raidname:NONE, etc...\r\nSpecify NONE to clear all global keys for a given raid.\r\nIf raid name is not defined then vanilla values are used for that raid instead.\r\nConsole command: zen_raidrules to view current raid conditions.\r\n[restart required for changes to take effect]"); GlobalKeysDeactivate = Config.Define<StringList>(true, "Raid Keys", "Global Keys - Deactivate", StringList.Empty, "Set global keys to deactivate raids.\r\nComma separated list of raid name and keys separated by vertical bar.\r\nSyntax: raidname:key1|key2|key3, raidname:key1|key2, raidname:NONE, etc...\r\nSpecify NONE to clear all global keys for a given raid.\r\nIf raid name is not defined then vanilla values are used for that raid instead.\r\nConsole command: zen_raidrules to view current raid conditions.\r\n[restart required for changes to take effect]"); PlayerKeysActivateAll = Config.Define<StringList>(true, "Raid Keys", "Player Keys All - Activate", StringList.Empty, "PlayerEvents: player key to enable a raid, ALL keys must be set.\r\nComma separated list of raid name and keys separated by vertical bar.\r\nSyntax: raidname:key1|key2|key3, raidname:key1|key2, raidname:NONE, etc...\r\nSpecify NONE to clear the player keys for a given raid.\r\nIf raid name is not defined then vanilla values are used for that raid instead.\r\nConsole command: zen_raidrules to view current raid conditions.\r\n[restart required for changes to take effect]"); StringList val2 = new StringList(); ((List<string>)val2).Add("army_charred:GP_Queen"); ((List<string>)val2).Add("army_charredspawners:GP_Queen"); ((List<string>)val2).Add("army_goblin:GP_Moder"); ((List<string>)val2).Add("army_moder:GP_Bonemass"); ((List<string>)val2).Add("army_gjall:GP_Yagluth"); PlayerKeysActivateAny = Config.Define<StringList>(true, "Raid Keys", "Player Keys Any - Activate", val2, "PlayerEvents: player key to activate a raid, ANY key must be set.\r\nComma separated list of raid name and keys separated by vertical bar.\r\nSyntax: raidname:key1|key2|key3, raidname:key1|key2, raidname:NONE, etc...\r\nSpecify NONE to clear the player keys for a given raid.\r\nIf raid name is not defined then vanilla values are used for that raid instead.\r\nConsole command: zen_raidrules to view current raid conditions.\r\n[restart required for changes to take effect]"); StringList val3 = new StringList(); ((List<string>)val3).Add("army_charred:GP_Fader"); ((List<string>)val3).Add("army_charredspawners:GP_Fader"); PlayerKeysDeactivate = Config.Define<StringList>(true, "Raid Keys", "Player Keys - Deactivate", val3, "PlayerEvents: player key to disable a raid, ALL conditions must be true.\r\nComma separated list of raid name and keys separated by vertical bar.\r\nSyntax: raidname:key1|key2|key3, raidname:key1|key2, raidname:NONE, etc...\r\nSpecify NONE to clear all player keys for a given raid.\r\nIf raid name is not defined then vanilla values are used for that raid instead.\r\nConsole command: zen_raidrules to view current raid conditions.\r\n[restart required for changes to take effect]"); PlayerKnownItemsActivate = Config.Define<StringList>(true, "Raid Keys", "Player Known Items - Activate", StringList.Empty, "PlayerEvents: known items that will trigger the raid.\r\nComma separated list of raid name and item prefab names separated by vertical bar.\r\nSyntax: raidname:prefab1|prefab2|prefab3, raidname:prefab1|prefab2, raidname:NONE, etc...\r\nSpecify NONE to clear all required known items for a given raid.\r\nIf raid name is not defined then vanilla values are used for that raid instead.\r\nConsole command: zen_raidrules to view current raid conditions.\r\n[restart required for changes to take effect]"); PlayerKnownItemsDeactivate = Config.Define<StringList>(true, "Raid Keys", "Player Known Items - Deactivate", StringList.Empty, "PlayerEvents: known items that will disable the raid.\r\nComma separated list of raid name and item prefab names separated by vertical bar.\r\nSyntax: raidname:prefab1|prefab2|prefab3, raidname:prefab1|prefab2, raidname:NONE, etc...\r\nSpecify NONE to clear all required not-known items for a given raid.\r\nIf raid name is not defined then vanilla values are used for that raid instead.\r\nConsole command: zen_raidrules to view current raid conditions.\r\n[restart required for changes to take effect]"); } } private const string ConsoleCmd = "raidrules"; private static void CmdRaidRules(string[] args) { if (!Object.op_Implicit((Object)(object)RandEventSystem.instance)) { Console.instance.Print("RandEventSystem not initialized"); return; } string text = ((args.Length > 1) ? args[1] : null); foreach (RandomEvent @event in RandEventSystem.instance.m_events) { if (text == null) { if (@event.m_name.StartsWith("boss_")) { continue; } } else if (text.ToLower() != "all" && @event.m_name != text) { continue; } string text2 = "=======================================================\r\nRaid: " + @event.m_name + "\r\n- Global Keys Activate: " + GeneralExtensions.Join<string>((IEnumerable<string>)@event.m_requiredGlobalKeys, (Func<string, string>)null, ", ") + "\r\n- Global Keys Deactivate: " + GeneralExtensions.Join<string>((IEnumerable<string>)@event.m_notRequiredGlobalKeys, (Func<string, string>)null, ", ") + "\r\n- Player Keys All Activate: " + GeneralExtensions.Join<string>((IEnumerable<string>)@event.m_altRequiredPlayerKeysAll, (Func<string, string>)null, ", ") + "\r\n- Player Keys Any Activate: " + GeneralExtensions.Join<string>((IEnumerable<string>)@event.m_altRequiredPlayerKeysAny, (Func<string, string>)null, ", ") + "\r\n- Player Keys Deactivate: " + GeneralExtensions.Join<string>((IEnumerable<string>)@event.m_altNotRequiredPlayerKeys, (Func<string, string>)null, ", ") + "\r\n- Known Items Activate: " + GeneralExtensions.Join<ItemDrop>((IEnumerable<ItemDrop>)@event.m_altRequiredKnownItems, (Func<ItemDrop, string>)((ItemDrop i) => ItemDataExt.GetPrefabName(i)), ", ") + "\r\n- Known Items Deactivate: " + GeneralExtensions.Join<ItemDrop>((IEnumerable<ItemDrop>)@event.m_altRequiredNotKnownItems, (Func<ItemDrop, string>)((ItemDrop i) => ItemDataExt.GetPrefabName(i)), ", "); Console.instance.Print(text2); if (Logging<Plugin>.IsEnabled) { Logging<Plugin>.Message((object)text2, 0); } } } public static void SetupConsole() { ZenMod<Plugin>.Terminal.CreateCommand("raidrules", "Print the current raid conditions for all or a single raid.", true, (Action<string[]>)CmdRaidRules); } private static void ClientUpdateEvents() { if (Object.op_Implicit((Object)(object)Player.m_localPlayer)) { Logging<Plugin>.Info("Update client raid events", 0); Player.m_localPlayer.UpdateEvents(); } } public static void SetupEvents() { //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_005f: Unknown result type (might be due to invalid IL or missing references) Logging<Plugin>.Message((object)"Init raid event keys", 0); bool flag = default(bool); foreach (RandomEvent raid in RandEventSystem.instance.m_events) { InterpolatedString<Plugin> val = new InterpolatedString<Plugin>(21, 1, ref flag); if (flag) { val.AppendLiteral("Set configs for raid "); val.AppendFormatted(raid.m_name); } Logging<Plugin>.Info(val, 0); SetConfigKeys(raid); SetAllowedBiomes(raid); if (Configs.AppendGlobalKeysToPlayerKeys.Value) { IEnumerable<string> collection = raid.m_requiredGlobalKeys.Where((string key) => !raid.m_altRequiredPlayerKeysAll.Contains(key)); raid.m_altRequiredPlayerKeysAll.AddRange(collection); IEnumerable<string> collection2 = raid.m_notRequiredGlobalKeys.Where((string key) => !raid.m_altNotRequiredPlayerKeys.Contains(key)); raid.m_altNotRequiredPlayerKeys.AddRange(collection2); } if (Configs.IgnoreConditionKnownItems.Value) { raid.m_altRequiredKnownItems.Clear(); raid.m_altRequiredNotKnownItems.Clear(); } if (Configs.NeverActivatedRaids.Value.Contains(raid.m_name, true)) { SuppressRaid(raid); } if (Configs.NeverDeactivatedRaids.Value.Contains(raid.m_name, true)) { KeepRaidForever(raid); } } ClientUpdateEvents(); } private static void SetAllowedBiomes(RandomEvent raid) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) bool flag = default(bool); foreach (KeyValuePair<string, string> item in from kvp in Configs.AllowedBiomes.Value.ToDictionary(':') where kvp.Key == raid.m_name select kvp) { InterpolatedString<Plugin> val = new InterpolatedString<Plugin>(17, 2, ref flag); if (flag) { val.AppendFormatted(raid.m_name); val.AppendLiteral(" allowed biomes: "); val.AppendFormatted(item.Value); } Logging<Plugin>.Info(val, 0); if (item.Value.ToUpper() == "ALL") { raid.m_biome = (Biome)895; continue; } if (item.Value.ToUpper() == "NONE") { raid.m_biome = (Biome)0; continue; } raid.m_biome = ((IEnumerable<string>)item.Value.Split(new char[1] { '|' })).Select((Func<string, Biome>)((string biome) => (Biome)Enum.Parse(typeof(Biome), biome.Trim()))).Aggregate((Biome a, Biome b) => (Biome)(a | b)); } } private static void SetConfigKeys(RandomEvent raid) { SetKeys<string>(Configs.GlobalKeysActivate, raid.m_requiredGlobalKeys); SetKeys<string>(Configs.GlobalKeysDeactivate, raid.m_notRequiredGlobalKeys); SetKeys<string>(Configs.PlayerKeysActivateAll, raid.m_altRequiredPlayerKeysAll); SetKeys<string>(Configs.PlayerKeysActivateAny, raid.m_altRequiredPlayerKeysAny); SetKeys<string>(Configs.PlayerKeysDeactivate, raid.m_altNotRequiredPlayerKeys); SetKeys<ItemDrop>(Configs.PlayerKnownItemsActivate, raid.m_altRequiredKnownItems); SetKeys<ItemDrop>(Configs.PlayerKnownItemsDeactivate, raid.m_altRequiredNotKnownItems); void SetKeys<T>(ConfigEntry<StringList> config, List<T> list) where T : notnull { //IL_0047: 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_0098: Unknown result type (might be due to invalid IL or missing references) bool flag = default(bool); foreach (KeyValuePair<string, string> item in from kvp in config.Value.ToDictionary(':') where kvp.Key == raid.m_name select kvp) { InterpolatedString<Plugin> val = new InterpolatedString<Plugin>(4, 3, ref flag); if (flag) { val.AppendFormatted(((ConfigEntryBase)config).Definition.Key); val.AppendLiteral(" "); val.AppendFormatted(item.Key); val.AppendLiteral(" = "); val.AppendFormatted(item.Value); } Logging<Plugin>.Info(val, 0); list.Clear(); if (!(item.Value.ToUpper() == "NONE")) { if (list is List<string> list2) { list2.AddRange(item.Value.Split(new char[1] { '|' })); } else if (list is List<ItemDrop> list3) { IEnumerable<ItemDrop> source = item.Value.Split(new char[1] { '|' }).Select(delegate(string prefabName) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefabName); return (itemPrefab == null) ? null : itemPrefab.GetComponent<ItemDrop>(); }); list3.AddRange(source.Where((ItemDrop item) => (Object)(object)item != (Object)null)); } } } } } private static void KeepRaidForever(RandomEvent raid) { raid.m_notRequiredGlobalKeys.Clear(); raid.m_altNotRequiredPlayerKeys.Clear(); raid.m_altRequiredNotKnownItems.Clear(); } private static void SuppressRaid(RandomEvent raid) { raid.m_requiredGlobalKeys.Clear(); raid.m_altRequiredPlayerKeysAll.Clear(); raid.m_altRequiredPlayerKeysAny.Clear(); raid.m_altRequiredKnownItems.Clear(); } [HarmonyTranspiler] [HarmonyPatch(typeof(RandEventSystem), "UpdateRandomEvent")] private static IEnumerable<CodeInstruction> RandEventSystem_UpdateRandomEvent(IEnumerable<CodeInstruction> codes) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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 //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Expected O, but got Unknown CodeMatch[] array = (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.DeclaredField(typeof(RandEventSystem), "m_eventChance"), (string)null) }; Func<float, float> func = GetChance; return new CodeMatcher(codes, (ILGenerator)null).MatchEndForward(array).ThrowIfInvalid("Unable to match IL sequence").Advance(1) .Insert((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Call, (object)func.Method) }) .InstructionEnumeration(); static float GetChance(float defaultChance) { float num = Configs.RaidChanceBase.Value; if (num == 0f) { return -1f; } if (num < 0f) { num = defaultChance; } return num + (float)(Player.GetAllPlayers().Count - 1) * Configs.RaidChanceBonusByPlayer.Value; } } [HarmonyPrefix] [HarmonyPatch(typeof(RandEventSystem), "StartRandomEvent")] private static void RandEventSystem_StartRandomEvent(ref bool __runOriginal) { int nrOfPlayers = ZNet.instance.GetNrOfPlayers(); int value = Configs.MinPlayerCount.Value; __runOriginal = nrOfPlayers >= value; if (!__runOriginal) { Logging<Plugin>.Message((object)$"Not enough players online for raid. Min player count: {value}, currently online: {nrOfPlayers}", 0); } } [HarmonyPostfix] [HarmonyPatch(typeof(RandEventSystem), "InValidBiome")] private static void RandEventSystem_InValidBiome(RandEventSystem __instance, RandomEvent ev, Vector3 point, ref bool __result) { //IL_0005: 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_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: 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) //IL_0067: Unknown result type (might be due to invalid IL or missing references) Biome biome = WorldGenerator.instance.GetBiome(point); if (((Enum)Configs.NoRaidBiomes.Value).HasFlag((Enum)(object)biome)) { if (Configs.NoRaidBiomesExceptions.Value.Contains(ev.m_name, true)) { Logging<Plugin>.Message((object)("Exception, raid " + ev.m_name + " allowed in Value"), 0); return; } Logging<Plugin>.Message((object)string.Format("{0} {1} suppressed raid: {2}", "NoRaidBiomes", biome, ev.m_name), 0); __result = false; } } [HarmonyTranspiler] [HarmonyPatch(typeof(RandEventSystem), "CheckBase")] private static IEnumerable<CodeInstruction> RandEventSystem_CheckBase(IEnumerable<CodeInstruction> codes) { Func<int> intercept = GetRaidThreshold; return Transpilers.Manipulator(codes, (Func<CodeInstruction, bool>)((CodeInstruction c) => c.opcode == OpCodes.Ldc_I4_3), (Action<CodeInstruction>)delegate(CodeInstruction c) { c.opcode = OpCodes.Call; c.operand = intercept.Method; }); static int GetRaidThreshold() { return Configs.RaidThresholdLimit.Value; } } [HarmonyPostfix] [HarmonyPatch(typeof(RandEventSystem), "GetPossibleRandomEvents")] private static void Debug_RandEventSystem_GetPossibleRandomEvents(RandEventSystem __instance, List<KeyValuePair<RandomEvent, Vector3>> __result) { //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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) Logging<Plugin>.Message((object)$"Possible random events: {__result.Count}", 0); if (!Logging<Plugin>.IsEnabled) { return; } bool flag = default(bool); foreach (KeyValuePair<RandomEvent, Vector3> item in __result) { InterpolatedString<Plugin> val = new InterpolatedString<Plugin>(11, 2, ref flag); if (flag) { val.AppendLiteral("Event: "); val.AppendFormatted(item.Key.m_name); val.AppendLiteral(" at "); val.AppendFormatted<Vector3>(item.Value); } Logging<Plugin>.Info(val, 0); } } [HarmonyPostfix] [HarmonyPatch(typeof(RandEventSystem), "PlayerIsReadyForEvent")] private static void RandEventSystem_PlayerIsReadyForEvent(Player player, ref bool __result) { if (PlayerExt.IsGodMode(player)) { __result = false; if (Logging<Plugin>.IsEnabled) { Logging<Plugin>.Message((object)"God mode enabled, blocking raid triggers for admin player", 0); } } } private static void Debug_RandEventSystem_HaveGlobalKeys(RandEventSystem __instance, RandomEvent ev, List<PlayerEventData> players, bool __result) { //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) if (!Logging<Plugin>.IsEnabled) { return; } Logging<Plugin>.Message((object)$"DEBUG INFO: result: {__result}", 0); Logging<Plugin>.Message((object)("\r\n-------------------------------------------------------------------\r\nEvent: " + ev.m_name + "\r\n\r\nGlobalKeys: " + GeneralExtensions.Join<string>((IEnumerable<string>)ev.m_requiredGlobalKeys, (Func<string, string>)null, ", ") + "\r\nGlobalKeysNot: " + GeneralExtensions.Join<string>((IEnumerable<string>)ev.m_notRequiredGlobalKeys, (Func<string, string>)null, ", ") + "\r\n\r\nKnownItems: " + GeneralExtensions.Join<ItemDrop>((IEnumerable<ItemDrop>)ev.m_altRequiredKnownItems, (Func<ItemDrop, string>)((ItemDrop i) => ((Object)i).name), ", ") + "\r\nKnownItemsNot: " + GeneralExtensions.Join<ItemDrop>((IEnumerable<ItemDrop>)ev.m_altRequiredNotKnownItems, (Func<ItemDrop, string>)((ItemDrop i) => ((Object)i).name), ", ") + "\r\n\r\nPlayerKeysAll: " + GeneralExtensions.Join<string>((IEnumerable<string>)ev.m_altRequiredPlayerKeysAll, (Func<string, string>)null, ", ") + "\r\nPlayerKeysAny:" + GeneralExtensions.Join<string>((IEnumerable<string>)ev.m_altRequiredPlayerKeysAny, (Func<string, string>)null, ", ") + "\r\nPlayerKeysNot: " + GeneralExtensions.Join<string>((IEnumerable<string>)ev.m_altNotRequiredPlayerKeys, (Func<string, string>)null, ", ") + "\r\n-------------------------------------------------------------------\r\n"), 0); foreach (PlayerEventData player in players) { Logging<Plugin>.Message((object)($"base value: {player.baseValue} possible events: " + GeneralExtensions.Join<string>((IEnumerable<string>)player.possibleEvents, (Func<string, string>)null, ", ")), 0); } } } } namespace ZenRaids.SpawnProtect { internal static class Configs { public static readonly ConfigEntry<bool> FireMustBeLit; public static readonly ConfigEntry<int> PerimeterRangeVisible; public static readonly ConfigEntry<KeyCode> PerimeterRangeHideKey; public static readonly ConfigEntry<float> LightRangePercent; public static readonly ConfigEntry<StringList> OverrideMaxFuel; public static readonly ConfigEntry<StringList> ProtectFromDespawn; public const float SmelterProtectionRadius = 5f; public static readonly Type[] BasePieceTypes; internal static readonly Dictionary<string, float> OverrideRange; static Configs() { //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Expected O, but got Unknown //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Expected O, but got Unknown //IL_01cb: Expected O, but got Unknown //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Expected O, but got Unknown //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Expected O, but got Unknown //IL_0200: Expected O, but got Unknown BasePieceTypes = new Type[8] { typeof(Smelter), typeof(CraftingStation), typeof(Fermenter), typeof(PrivateArea), typeof(ShieldGenerator), typeof(StationExtension), typeof(CookingStation), typeof(Incinerator) }; OverrideRange = new Dictionary<string, float> { { "piece_walltorch", 12f }, { "piece_brazierfloor01", 15f }, { "piece_brazierfloor02", 15f }, { "piece_brazierceiling01", 15f }, { "piece_groundtorch_green", 15f }, { "piece_groundtorch_blue", 15f } }; FireMustBeLit = Config.Define<bool>(true, "Spawn Protection", "Fire Must Be Lit", true, "Workbenches and other objects will no longer protect against monster spawns. (Vanilla: false)\r\nInstead sources of fire (Fireplaces/Torches) must be lit for spawn protection. \r\nSee the detailed explanation in the readme or on thunderstore.\r\n[If this is off then vanilla behavior applies]\r\n[logout required for changes to take effect]"); PerimeterRangeVisible = Config.Define<int>(true, "Spawn Protection", "Perimeter Range - Visible", 35, Config.AcceptRange<int>(0, 100), "Visualize the perimeter of the light protection radius by equipping the build hammer and selecting a fire source piece from the build menu.\r\nMonsters will not spawn within the perimeter.\r\n[distance from the player that light rings are visible]\r\n[set to 0 to disable this feature]"); PerimeterRangeHideKey = Config.Define<KeyCode>(false, "Spawn Protection", "Perimeter Range - Hide Key", (KeyCode)308, "Hold down this button to hide the perimeter visualization rings."); LightRangePercent = Config.Define<float>(true, "Spawn Protection", "Light Range Percent", 1f, Config.AcceptRange<float>(0f, 3f), "When \"" + ((ConfigEntryBase)FireMustBeLit).Definition.Key + "\" is enabled this adjusts the light radius size to use for spawn protection.\r\nNote: Setting this to 0 will disable all spawn protection.\r\n[logout requried for changes to take effect]"); StringList val = new StringList(); ((List<string>)val).Add("piece_walltorch:3"); ((List<string>)val).Add("piece_groundtorch_wood:3"); OverrideMaxFuel = Config.Define<StringList>(true, "Spawn Protection", "Fuel Override", val, "When \"" + ((ConfigEntryBase)FireMustBeLit).Definition.Key + "\" is enabled overrides the prefab max fuel for the specified light sources.\r\nComma separated list of prefab names and max fuel values.\r\nNOTE: The Sconce is reduced from vanilla (6) because: \r\nit burns at half the rate of a wood torch, it protects more area than a wood torch, \r\nit costs copper, not bronze or iron, it produces no smoke, and it's immune to rain.\r\nThe Standing Wood Torch is changed to 3 to provide more utility to other torches.\r\n[logout requried for changes to take effect]"); StringList val2 = new StringList(); ((List<string>)val2).Add("ChickenEgg"); ((List<string>)val2).Add("AsksvinEgg"); ProtectFromDespawn = Config.Define<StringList>(true, "Spawn Protection", "Protect From Despawn", val2, "Fires protect items from despawning. If the fire goes out items on the ground will eventually despawn.\r\nList of items that never despawn because they need to be on the ground. Put your important items in a chest."); } } internal static class FireplaceExt { public static bool IsPlacementGhost(this Fireplace? fireplace) { if (Object.op_Implicit((Object)(object)fireplace)) { return Player.IsPlacementGhost(((Component)fireplace).gameObject); } return false; } public static bool IsValid(this Fireplace fireplace) { if (Object.op_Implicit((Object)(object)fireplace.m_playerBaseObject)) { if (!fireplace.IsPlacementGhost()) { if (Object.op_Implicit((Object)(object)fireplace.m_piece)) { return fireplace.m_piece.IsPlacedByPlayer(); } return false; } return true; } return false; } private static bool TryGetFlameNode(Fireplace fire, out GameObject obj) { if (Object.op_Implicit((Object)(object)fire.m_enabledObjectHigh)) { return Object.op_Implicit((Object)(object)(obj = fire.m_enabledObjectHigh)); } if (Object.op_Implicit((Object)(object)fire.m_enabledObject)) { return Object.op_Implicit((Object)(object)(obj = fire.m_enabledObject)); } return Object.op_Implicit((Object)(object)(obj = null)); } public static bool TryGetLightRange(this Fireplace fireplace, out float range) { range = -1f; if (!TryGetFlameNode(fireplace, out GameObject obj)) { return false; } LightLod componentInChildren = obj.GetComponentInChildren<LightLod>(); if (!Object.op_Implicit((Object)(object)componentInChildren)) { return false; } string key = (Object.op_Implicit((Object)(object)fireplace.m_nview) ? fireplace.m_nview.GetPrefabName() : Utils.GetPrefabName(((Object)fireplace).name)); if (Configs.OverrideRange.TryGetValue(key, out range)) { return true; } if (Object.op_Implicit((Object)(object)componentInChildren.m_light)) { range = (componentInChildren.m_lightLod ? componentInChildren.m_baseRange : componentInChildren.m_light.range); return true; } Logging<Plugin>.Debug("LightLod never initialized. Getting the Light component range directly", 0); Light val = default(Light); if (((Component)componentInChildren).TryGetComponent<Light>(ref val)) { range = val.range; return true; } Logging<Plugin>.Debug("No Light component found", 0); return false; } } [HarmonyPatch] internal static class ItemDespawn { private static readonly HashSet<string> AnimalFoods = new HashSet<string>(); private static readonly HashSet<Character> TamesInZone = new HashSet<Character>(); private static bool FiresMustBeLit => Configs.FireMustBeLit.Value; private static bool NeedsProtection(this ItemDrop itemDrop) { if (itemDrop.m_autoDestroy && TamesInZone.Count > 0) { return AnimalFoods.Contains(ItemDataExt.GetPrefabName(itemDrop)); } return false; } public static void InitAnimalFoods() { AnimalFoods.Clear(); MonsterAI val = default(MonsterAI); foreach (GameObject prefab in ZNetScene.instance.m_prefabs) { if (!prefab.TryGetComponent<MonsterAI>(ref val)) { continue; } foreach (ItemDrop consumeItem in val.m_consumeItems) { AnimalFoods.Add(((Object)consumeItem).name); } } } public static void ProtectExplicitItems() { ItemDrop val = default(ItemDrop); foreach (string item in (List<string>)(object)Configs.ProtectFromDespawn.Value) { if (GlobalStatic.TryGetPrefab<ItemDrop>(item, ref val, false)) { val.m_autoDestroy = false; } else { Logging<Plugin>.Warning((object)("Item prefab not found: " + item), 0); } } } [HarmonyPostfix] [HarmonyPatch(typeof(Character), "Awake")] private static void Character_Awake(Character __instance) { if (FiresMustBeLit && __instance.IsTamed()) { TamesInZone.Add(__instance); } } [HarmonyTranspiler] [HarmonyPatch(typeof(Character), "SetTamed")] [HarmonyPriority(200)] private static IEnumerable<CodeInstruction> Character_SetTamed(IEnumerable<CodeInstruction> codes) { MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(ZNetView), "InvokeRPC", new Type[2] { typeof(string), typeof(object[]) }, (Type[])null); Action<ZNetView, string, object[]> action = InvokeRPCIntercept; return Transpilers.MethodReplacer(codes, (MethodBase)methodInfo, (MethodBase)action.Method); static void InvokeRPCIntercept(ZNetView nview, string rpcName, object[] args) { if (!FiresMustBeLit) { nview.InvokeRPC(rpcName, args); } else { nview.InvokeRPC(ZNetView.Everybody, rpcName, args); } } } [HarmonyPostfix] [HarmonyPatch(typeof(Character), "RPC_SetTamed")] private static void Character_RPC_SetTamed(Character __instance, bool tamed) { if (FiresMustBeLit) { if (tamed) { TamesInZone.Add(__instance); } else { TamesInZone.Remove(__instance); } } } [HarmonyPostfix] [HarmonyPatch(typeof(Character), "OnDestroy")] private static void Character_OnDestroy(Character __instance) { TamesInZone.Remove(__instance); } [HarmonyPrefix] [HarmonyPatch(typeof(ItemDrop), "SlowUpdate")] private static void ItemDrop_SlowUpdate(ItemDrop __instance) { if (FiresMustBeLit && __instance.NeedsProtection()) { __instance.m_autoDestroy = false; } } } [HarmonyPatch] internal class LitArea : MonoBehaviour { private const string LitAreaName = "LitAreaMarker"; private static GameObject _prefabAreaMarker; private static GameObject _prefabPulse; private Fireplace _fireplace; private GameObject _litArea; private GameObject _litPulse; private Light[] _allLights; internal static void SetupFX() { _prefabAreaMarker = ((Component)GlobalStatic.GetPrefab("piece_workbench", false).transform.Find("AreaMarker")).gameObject; _prefabPulse = ((Component)GlobalStatic.GetPrefab("guard_stone", false).transform.Find("WayEffect/pulse (2)")).gameObject; } public static void Init(Fireplace fireplace) { if (fireplace.IsValid() && fireplace.TryGetLightRange(out var range)) { ((Component)fireplace).gameObject.AddComponent<LitArea>().SetupLightRange(range); } } private void Awake() { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) _fireplace = ((Component)this).GetComponent<Fireplace>(); _fireplace.m_playerBaseObject.SetActive(true); _litArea = Object.Instantiate<GameObject>(_prefabAreaMarker, ((Component)this).transform, false); ((Object)_litArea).name = "LitAreaMarker"; _litArea.SetActive(false); ((Component)_litArea.GetComponentInChildren<ParticleSystem>()).gameObject.SetActive(false); _litArea.transform.localPosition = Vector3.zero; _litPulse = Object.Instantiate<GameObject>(_prefabPulse, ((Component)this).transform, false); ((Object)_litPulse).name = "LitAreaMarker_Pulse"; _litPulse.SetActive(false); _litPulse.transform.localPosition = Vector3.zero; GameObject obj = Object.Instantiate<GameObject>(((Component)_prefabPulse.transform.parent.Find("sfx")).gameObject, _litPulse.transform, false); ((Object)obj).name = "LitAreaMarker_SFX"; obj.SetActive(true); obj.transform.localPosition = Vector3.zero; AudioSource component = obj.GetComponent<AudioSource>(); component.minDistance = 0f; component.maxDistance = 30f; component.pitch = 1.7f; _allLights = ((Component)this).GetComponentsInChildren<Light>(true); Array.Sort(_allLights, (Light a, Light b) => Mathf.RoundToInt(b.range) - Mathf.RoundToInt(a.range)); SlowUpdate.Handler += UpdateState; } private void SetupLightRange(float lightRange) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) lightRange *= Configs.LightRangePercent.Value; bool flag = default(bool); InterpolatedString<Plugin> val = new InterpolatedString<Plugin>(18, 3, ref flag); if (flag) { val.AppendLiteral("Light Radius: "); val.AppendFormatted<float>(lightRange, "F2"); val.AppendLiteral(" - "); val.AppendFormatted(GameObjectExt.GetPrefabName(((Component)_fireplace).gameObject)); val.AppendLiteral(" "); val.AppendFormatted<Vector3>(MathExt.XZY(((Component)_fireplace).transform.position)); } Logging<Plugin>.Info(val, 0); _litArea.GetComponent<CircleProjector>().m_radius = lightRange; Vector3 lossyScale = _litArea.transform.lossyScale; _litPulse.transform.localScale = Vector3.one * (lightRange / ((Vector3)(ref lossyScale)).magnitude); if (_fireplace.IsPlacementGhost()) { return; } Collider collider = _fireplace.m_playerBaseObject.GetComponent<EffectArea>().m_collider; SphereCollider val2 = (SphereCollider)(object)((collider is SphereCollider) ? collider : null); if (val2 == null) { CapsuleCollider val3 = (CapsuleCollider)(object)((collider is CapsuleCollider) ? collider : null); if (val3 != null) { val3.radius = lightRange; } else { Logging<Plugin>.Error((object)(((Object)_fireplace).name + " PlayerBase object has no sphere or capsule collider"), (ushort)0); } } else { val2.radius = lightRange; } } private void OnDestroy() { SlowUpdate.Handler -= UpdateState; } private void UpdateState() { if (!Configs.FireMustBeLit.Value) { return; } if (_fireplace.IsPlacementGhost()) { _litArea.SetActive(true); _litPulse.SetActive(false); return; } bool flag = IsLit(); GameObject playerBaseObject = _fireplace.m_playerBaseObject; if (playerBaseObject.activeSelf != flag) { playerBaseObject.SetActive(flag); } bool visibleFX = false; Player localPlayer = Player.m_localPlayer; if (flag && Object.op_Implicit((Object)(object)localPlayer) && Object.op_Implicit((Object)(object)localPlayer.m_placementGhost)) { int value = Configs.PerimeterRangeVisible.Value; bool num = value > 0 && MathExt.DistanceToXZ((MonoBehaviour)(object)localPlayer, (MonoBehaviour)(object)this) <= (float)value; LitArea component = localPlayer.m_placementGhost.GetComponent<LitArea>(); visibleFX = num && Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component._fireplace.m_playerBaseObject); } SetVisibleFX(visibleFX); } private bool IsLit() { if (_allLights.Length == 0) { return false; } if (_allLights.All((Light light) => ((Behaviour)light).isActiveAndEnabled)) { return true; } if (_allLights.All((Light light) => Mathf.Approximately(light.range, _allLights[0].range))) { return _allLights.Any((Light light) => ((Behaviour)light).isActiveAndEnabled); } return ((Behaviour)_allLights[0]).isActiveAndEnabled; } private void SetVisibleFX(bool isVisible) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) if (ZInput.GetKey(Configs.PerimeterRangeHideKey.Value, true)) { isVisible = false; } if (_litArea.activeSelf != isVisible) { _litArea.SetActive(isVisible); _litPulse.SetActive(isVisible); } } [HarmonyPostfix] [HarmonyPatch(typeof(CircleProjector), "Start")] private static void CircleProjector_Start(CircleProjector __instance) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) if (((Object)__instance).name != "LitAreaMarker") { return; } foreach (GameObject segment in __instance.m_segments) { segment.transform.localScale = new Vector3(0.05f, 0.25f, __instance.m_radius / 20f); ((Renderer)segment.GetComponent<MeshRenderer>()).material.color = UIColor.op_Implicit(UIColor.Orange); } } } [HarmonyPatch] internal static class Patches { [HarmonyPostfix] [HarmonyPatch(typeof(ZNetScene), "Awake")] private static void ZNetScene_Awake(ZNetScene __instance) { if (!Configs.FireMustBeLit.Value) { return; } LitArea.SetupFX(); Smelter val = default(Smelter); foreach (GameObject prefab in __instance.m_prefabs) { if (prefab.TryGetComponent<Smelter>(ref val)) { EffectArea val2 = ((IEnumerable<EffectArea>)((Component)val).GetComponentsInChildren<EffectArea>()).FirstOrDefault((Func<EffectArea, bool>)((EffectArea effect) => ((Enum)effect.m_type).HasFlag((Enum)(object)(Type)4))); if (Object.op_Implicit((Object)(object)val2)) { SetRadius(((Component)val2).GetComponent<Collider>(), 5f); } } } } private static void SetRadius(Collider collider, float radius) { SphereCollider val = (SphereCollider)(object)((collider is SphereCollider) ? collider : null); if (val == null) { CapsuleCollider val2 = (CapsuleCollider)(object)((collider is CapsuleCollider) ? collider : null); if (val2 != null) { val2.radius = radius; } else { Logging<Plugin>.Error((object)("Unsupported collider shape, unable to set radius, not sphere or capsule: " + ((Object)((Component)collider).transform.parent).name + "/" + ((Object)collider).name), (ushort)0); } } else { val.radius = radius; } } [HarmonyPostfix] [HarmonyPatch(typeof(EffectArea), "Awake")] private static void PlayerBaseEffectArea_Awake(EffectArea __instance) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) if (!Configs.FireMustBeLit.Value || !((Enum)__instance.m_type).HasFlag((Enum)(object)(Type)4) || Object.op_Implicit((Object)(object)((Component)__instance).GetComponentInParent<Smelter>())) { return; } Piece piece = ((Component)__instance).GetComponentInParent<Piece>(); Timing.EndOfFrame((MonoBehaviour)(object)__instance, (Action)delegate { if (Object.op_Implicit((Object)(object)piece) && piece.IsPlacedByPlayer()) { ((Component)__instance).gameObject.SetActive(false); } }); } [HarmonyPrefix] [HarmonyPatch(typeof(EffectArea), "GetBaseValue")] private static bool EffectArea_GetBaseValue(Vector3 p, float radius, ref int __result) { //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) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) if (!Configs.FireMustBeLit.Value) { return true; } Dictionary<string, bool> cache = new Dictionary<string, bool>(); int num = 0; bool flag = false; bool flag2 = default(bool); InterpolatedString<Plugin> val; foreach (Piece s_allPiece in Piece.s_allPieces) { if (!InRange(s_allPiece) || !IsBasePiece(s_allPiece)) { continue; } num++; if (RaidRules.Configs.RaidThresholdOptimization.Value && num >= RaidRules.Configs.RaidThresholdLimit.Value) { val = new InterpolatedString<Plugin>(39, 1, ref flag2); if (flag2) { val.AppendLiteral("Scan stopped, raid threshold reached: "); val.AppendFormatted<int>(num); val.AppendLiteral("+"); } Logging<Plugin>.Debug(val, 0); flag = true; break; } } string text = (flag ? "+ or more... (Limit reached)" : string.Empty); val = new InterpolatedString<Plugin>(20, 2, ref flag2); if (flag2) { val.AppendLiteral("Nearby base pieces: "); val.AppendFormatted<int>(num); val.AppendFormatted(text); } Logging<Plugin>.Info(val, 0); __result = num; return false; bool InRange(Piece? piece) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)piece)) { return MathExt.InRange((MonoBehaviour)(object)piece, p, radius); } return false; } bool IsBasePiece(Piece? piece) { if (!Object.op_Implicit((Object)(object)piece)) { return false; } if (!piece.IsPlacedByPlayer()) { return false; } string prefabName = GameObjectExt.GetPrefabName(((Component)piece).gameObject); if (cache.TryGetValue(prefabName, out var value)) { if (value) { Logging<Plugin>.Debug(prefabName, 0); } return value; } Bed val2 = default(Bed); if (((Component)piece).TryGetComponent<Bed>(ref val2)) { if (val2.GetOwner() == Game.instance.GetPlayerProfile().GetPlayerID()) { Logging<Plugin>.Debug(((Object)val2).name, 0); return true; } return false; } Type[] basePieceTypes = Configs.BasePieceTypes; Component val3 = default(Component); foreach (Type type in basePieceTypes) { if (((Component)piece).TryGetComponent(type, ref val3)) { Logging<Plugin>.Debug(((Object)val3).name, 0); return cache[prefabName] = true; } } return cache[prefabName] = false; } } [HarmonyPostfix] [HarmonyPatch(typeof(Fireplace), "Awake")] [HarmonyPriority(0)] private static void Fireplace_Awake(Fireplace __instance) { FixPlayerBaseObject(__instance); if (Configs.FireMustBeLit.Value) { SetupMaxFuel(__instance); } } [HarmonyPostfix] [HarmonyPatch(typeof(Fireplace), "Start")] private static void Fireplace_Start(Fireplace __instance) { if (Configs.FireMustBeLit.Value) { LitArea.Init(__instance); } } private static void SetupMaxFuel(Fireplace fireplace) { string prefabName = fireplace.m_nview.GetPrefabName(); if (Configs.OverrideMaxFuel.Value.ToDictionary(':').TryGetValue(prefabName, out var value)) { if (float.TryParse(value, out var result)) { fireplace.m_maxFuel = result; } else { Logging<Plugin>.Warning((object)("Unable to parse fuel value: " + prefabName + ":" + value), 0); } } } private static void FixPlayerBaseObject(Fireplace fireplace) { //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_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_004a: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)fireplace.m_playerBaseObject)) { return; } Scene scene = fireplace.m_playerBaseObject.scene; if (!((Scene)(ref scene)).isLoaded) { bool flag = default(bool); InterpolatedString<Plugin> val = new InterpolatedString<Plugin>(55, 1, ref flag); if (flag) { val.AppendFormatted(((Object)fireplace).name); val.AppendLiteral(" playerBaseObject is pointing to prefab, nulling to fix"); } Logging<Plugin>.Info(val, 0); fireplace.m_playerBaseObject = null; } } } [HarmonyPatch] internal static class SlowUpdate { private const float Interval = 0.2f; private static float _timer; public static event Action? Handler; private static void Tick() { _timer += Time.deltaTime; if (!(_timer < 0.2f)) { _timer -= 0.2f; SlowUpdate.Handler?.Invoke(); } } [HarmonyPostfix] [HarmonyPatch(typeof(Game), "Start")] private static void Game_Start() { _timer = 0f; } [HarmonyPostfix] [HarmonyPatch(typeof(Game), "Update")] private static void Game_Update() { Tick(); } } } namespace ZenRaids.Compatibility { internal static class Farming { private const string FarmingGUID = "org.bepinex.plugins.farming"; private static bool IsLoaded() { return Chainloader.PluginInfos.ContainsKey("org.bepinex.plugins.farming"); } public static void Check() { if (Configs.FireMustBeLit.Value && IsLoaded()) { Logging<Plugin>.Warning((object)"Farming mod installed, light perimeter rings may not display correctly when placing light sources.", 0); } } } }