using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("aurora")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("Seasonal Easter event mod for Valheim - Egg Hunt of Idunn")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("AuroraEasterEvent")] [assembly: AssemblyTitle("AuroraEasterEvent")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace AuroraEasterEvent { public static class EggConfig { public static ConfigEntry PaintedEggDropRate; public static ConfigEntry SilverEggDropRate; public static ConfigEntry GoldenEggDropRate; public static ConfigEntry NestSpawnChance; public static ConfigEntry NestMaxPerZone; public static ConfigEntry AnnounceGoldenEggs; public static void Initialize(ConfigFile config) { PaintedEggDropRate = config.Bind("Drops", "PaintedEggDropRate", 15f, "Percent chance for Painted Egg to drop from monsters (Meadows/BlackForest)"); SilverEggDropRate = config.Bind("Drops", "SilverEggDropRate", 8f, "Percent chance for Silver Egg to drop from monsters (Swamp/Mountain)"); GoldenEggDropRate = config.Bind("Drops", "GoldenEggDropRate", 3f, "Percent chance for Golden Egg to drop from monsters (Plains/Mistlands/Ashlands)"); NestSpawnChance = config.Bind("Nests", "NestSpawnChance", 0.05f, "Chance per zone for an egg nest to spawn (0.0-1.0)"); NestMaxPerZone = config.Bind("Nests", "NestMaxPerZone", 1, "Maximum egg nests per zone"); AnnounceGoldenEggs = config.Bind("General", "AnnounceGoldenEggs", true, "Broadcast server message when a player finds a Golden Egg"); } } [HarmonyPatch] public static class EggDrops { private static readonly Dictionary _lastAttackers = new Dictionary(); [HarmonyPatch(typeof(Character), "RPC_Damage")] [HarmonyPostfix] public static void TrackAttacker(Character __instance, HitData hit) { //IL_0024: 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_0045: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)__instance == (Object)null) && hit != null && !__instance.IsPlayer() && hit.m_attacker != ZDOID.None) { ZNetScene instance = ZNetScene.instance; GameObject val = ((instance != null) ? instance.FindInstance(hit.m_attacker) : null); Player val2 = ((val != null) ? val.GetComponent() : null); if ((Object)(object)val2 != (Object)null) { _lastAttackers[((Object)__instance).GetInstanceID()] = val2.GetPlayerID(); } } } [HarmonyPatch(typeof(Character), "OnDeath")] [HarmonyPostfix] public static void OnMonsterDeath(Character __instance) { //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || __instance.IsPlayer()) { return; } int instanceID = ((Object)__instance).GetInstanceID(); if (!_lastAttackers.TryGetValue(instanceID, out var value)) { return; } _lastAttackers.Remove(instanceID); Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && localPlayer.GetPlayerID() == value) { ZNet instance = ZNet.instance; if (instance != null && instance.IsServer()) { ProcessEggDrop(localPlayer, ((Component)__instance).transform.position); } else { EggRPC.Instance?.ReportMonsterKill(((Component)__instance).transform.position); } } } public static void ProcessEggDrop(Player player, Vector3 monsterPos) { //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_0010: 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_0013: 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_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Invalid comparison between Unknown and I4 //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Invalid comparison between Unknown and I4 //IL_001d: 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_0036: Expected I4, but got Unknown //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Invalid comparison between Unknown and I4 //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Invalid comparison between Unknown and I4 //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Invalid comparison between Unknown and I4 //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Invalid comparison between Unknown and I4 //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) Biome val = Heightmap.FindBiome(monsterPos); int num = -1; float num2 = 0f; Biome val2 = val; Biome val3 = val2; if ((int)val3 <= 16) { switch (val3 - 1) { case 0: goto IL_0062; case 1: case 3: goto IL_0077; case 2: goto IL_00a1; } if ((int)val3 == 8) { goto IL_0062; } if ((int)val3 == 16) { goto IL_008c; } } else if ((int)val3 == 32 || (int)val3 == 64 || (int)val3 == 512) { goto IL_008c; } goto IL_00a1; IL_008c: num = 2; num2 = EggConfig.GoldenEggDropRate.Value / 100f; goto IL_00b6; IL_0077: num = 1; num2 = EggConfig.SilverEggDropRate.Value / 100f; goto IL_00b6; IL_00b6: if (num < 0 || Random.value > num2) { return; } Inventory inventory = ((Humanoid)player).GetInventory(); GameObject eggPrefab = EggItems.GetEggPrefab(num); if ((Object)(object)eggPrefab == (Object)null) { return; } if (((inventory != null) ? new bool?(inventory.AddItem(eggPrefab, 1)) : null).HasValue) { string text = EggItems.DisplayNames[num]; string text2 = num switch { 1 => "#c0c0ff", 0 => "#88ff88", _ => "#ffd700", }; MessageHud instance = MessageHud.instance; if (instance != null) { instance.ShowMessage((MessageType)1, "You found a " + text + "!", 0, (Sprite)null, false); } EggStats.RecordEggFound(player.GetPlayerID(), player.GetPlayerName(), num); if (num != 2 || !EggConfig.AnnounceGoldenEggs.Value) { return; } string playerName = player.GetPlayerName(); string text3 = "" + playerName + " found a Golden Egg! The gods smile upon them!"; { foreach (Player allPlayer in Player.GetAllPlayers()) { ((Character)allPlayer).Message((MessageType)2, text3, 0, (Sprite)null); } return; } } try { GameObject val4 = Object.Instantiate(eggPrefab, ((Component)player).transform.position + Vector3.up * 0.5f, Quaternion.identity); val4.SetActive(true); return; } catch { return; } IL_00a1: num = 0; num2 = EggConfig.PaintedEggDropRate.Value / 200f; goto IL_00b6; IL_0062: num = 0; num2 = EggConfig.PaintedEggDropRate.Value / 100f; goto IL_00b6; } } public class EggHUD : MonoBehaviour { private GUIStyle _bgStyle; private GUIStyle _labelStyle; private GUIStyle _countStyle; private GUIStyle _buttonStyle; private Texture2D _bgTex; private bool _stylesInit = false; private bool _showLeaderboard = false; public static EggHUD Instance { get; private set; } private void Awake() { Instance = this; } private void InitStyles() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown //IL_0039: 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_0065: Expected O, but got Unknown //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Expected O, but got Unknown //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Expected O, but got Unknown //IL_016e: Unknown result type (might be due to invalid IL or missing references) if (!_stylesInit) { _bgTex = new Texture2D(1, 1); _bgTex.SetPixel(0, 0, new Color(0.08f, 0.06f, 0.04f, 0.75f)); _bgTex.Apply(); _bgStyle = new GUIStyle(GUI.skin.box); _bgStyle.normal.background = _bgTex; _labelStyle = new GUIStyle(GUI.skin.label); _labelStyle.fontSize = 13; _labelStyle.normal.textColor = new Color(0.9f, 0.85f, 0.7f); _labelStyle.fontStyle = (FontStyle)1; _labelStyle.richText = true; _countStyle = new GUIStyle(GUI.skin.label); _countStyle.fontSize = 12; _countStyle.normal.textColor = Color.white; _countStyle.alignment = (TextAnchor)5; _countStyle.richText = true; _buttonStyle = new GUIStyle(GUI.skin.button); _buttonStyle.fontSize = 11; _buttonStyle.normal.textColor = new Color(0.9f, 0.85f, 0.7f); _stylesInit = true; } } private void OnGUI() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Invalid comparison between Unknown and I4 //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_02b6: Unknown result type (might be due to invalid IL or missing references) //IL_0330: Unknown result type (might be due to invalid IL or missing references) //IL_0365: Unknown result type (might be due to invalid IL or missing references) //IL_03f1: Unknown result type (might be due to invalid IL or missing references) //IL_042b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Player.m_localPlayer == (Object)null || ((Object)(object)Minimap.instance != (Object)null && (int)Minimap.instance.m_mode == 2)) { return; } InitStyles(); Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory(); if (inventory == null) { return; } int[] array = new int[3]; foreach (ItemData allItem in inventory.GetAllItems()) { string text = allItem.m_shared?.m_name ?? ""; for (int i = 0; i < 3; i++) { if (text == $"$aurora_egg_{i}") { array[i] += allItem.m_stack; } } } int num = array[0] + array[1] + array[2]; if (num == 0) { return; } float num2 = 160f; float num3 = 80f; if (num > 0) { num3 += 22f; } float num4 = (float)Screen.width - num2 - 15f; float num5 = 200f; GUI.Box(new Rect(num4, num5, num2, num3), "", _bgStyle); GUI.Label(new Rect(num4 + 8f, num5 + 4f, num2 - 16f, 20f), "Egg Hunt", _labelStyle); string[] array2 = new string[3] { "#88ff88", "#c0c0ff", "#ffd700" }; for (int j = 0; j < 3; j++) { float num6 = num5 + 24f + (float)(j * 18); GUI.Label(new Rect(num4 + 12f, num6, 100f, 18f), "" + EggItems.DisplayNames[j] + "", _countStyle); GUI.Label(new Rect(num4 + num2 - 45f, num6, 35f, 18f), $"x{array[j]}", _countStyle); } if (num <= 0) { return; } if (GUI.Button(new Rect(num4 + 4f, num5 + num3 - 20f, num2 - 8f, 18f), _showLeaderboard ? "Hide Leaderboard" : "Leaderboard", _buttonStyle)) { _showLeaderboard = !_showLeaderboard; } if (_showLeaderboard) { List leaderboard = EggStats.GetLeaderboard(); int num7 = Mathf.Min(leaderboard.Count, 5); float num8 = 20 + num7 * 18; GUI.Box(new Rect(num4, num5 + num3 + 2f, num2, num8), "", _bgStyle); GUI.Label(new Rect(num4 + 8f, num5 + num3 + 4f, num2 - 16f, 16f), "Top Egg Hunters", _labelStyle); for (int k = 0; k < num7; k++) { PlayerEggStats playerEggStats = leaderboard[k]; float num9 = num5 + num3 + 22f + (float)(k * 18); string text2 = k switch { 2 => "#3", 1 => "#2", 0 => "#1", _ => $"#{k + 1}", }; GUI.Label(new Rect(num4 + 8f, num9, num2 - 50f, 18f), text2 + " " + playerEggStats.PlayerName, _countStyle); GUI.Label(new Rect(num4 + num2 - 45f, num9, 35f, 18f), $"{EggStats.GetPlayerTotalEggs(playerEggStats)}", _countStyle); } } } } public static class EggItems { public static readonly string[] PrefabNames = new string[3] { "aurora_egg_painted", "aurora_egg_silver", "aurora_egg_golden" }; public static readonly string[] DisplayNames = new string[3] { "Painted Egg", "Silver Egg", "Golden Egg" }; public static readonly string[] Descriptions = new string[3] { "A colorful painted egg blessed by Idunn. Trade it at a checkpoint for rewards.", "A shimmering silver egg radiating gentle warmth. Idunn's favor flows within.", "A radiant golden egg pulsing with divine energy. Extremely rare and valuable." }; private static readonly GameObject[] _eggPrefabs = (GameObject[])(object)new GameObject[3]; private static GameObject _prefabRoot; private static bool _itemsCreated = false; private static bool _registered = false; private static readonly string[] CloneTemplates = new string[3] { "DragonEgg", "DragonEgg", "DragonEgg" }; private static void CreateEggPrefabs(ObjectDB objectDB) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_015c: Unknown result type (might be due to invalid IL or missing references) if (_itemsCreated) { return; } _prefabRoot = new GameObject("AuroraEasterEggPrefabs"); _prefabRoot.SetActive(false); Object.DontDestroyOnLoad((Object)(object)_prefabRoot); for (int i = 0; i < 3; i++) { try { GameObject itemPrefab = objectDB.GetItemPrefab(CloneTemplates[i]); if ((Object)(object)itemPrefab == (Object)null) { itemPrefab = objectDB.GetItemPrefab("Amber"); } if ((Object)(object)itemPrefab == (Object)null) { Plugin.Log.LogWarning((object)("EggItems: No template found for " + PrefabNames[i])); continue; } GameObject val = Object.Instantiate(itemPrefab, _prefabRoot.transform); ((Object)val).name = PrefabNames[i]; val.SetActive(true); ItemDrop component = val.GetComponent(); if (component?.m_itemData?.m_shared != null) { SharedData shared = component.m_itemData.m_shared; shared.m_name = $"$aurora_egg_{i}"; shared.m_description = $"$aurora_egg_{i}_desc"; shared.m_maxStackSize = 999; shared.m_weight = 0.5f; shared.m_maxQuality = 1; shared.m_questItem = false; shared.m_teleportable = true; shared.m_itemType = (ItemType)1; component.m_itemData.m_dropPrefab = val; _eggPrefabs[i] = val; Plugin.Log.LogInfo((object)("EggItems: Created " + PrefabNames[i] + " from " + ((Object)itemPrefab).name)); } } catch (Exception ex) { Plugin.Log.LogError((object)("EggItems: Failed to create " + PrefabNames[i] + ": " + ex.Message)); } } if ((Object)(object)_eggPrefabs[0] != (Object)null || (Object)(object)_eggPrefabs[1] != (Object)null || (Object)(object)_eggPrefabs[2] != (Object)null) { _itemsCreated = true; } } public static void RegisterInObjectDB(ObjectDB objectDB) { if (_registered || objectDB?.m_items == null || objectDB.m_items.Count == 0) { return; } CreateEggPrefabs(objectDB); int num = 0; BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; int i; for (i = 0; i < 3; i++) { if (!((Object)(object)_eggPrefabs[i] == (Object)null)) { if (!objectDB.m_items.Exists((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == PrefabNames[i])) { objectDB.m_items.Add(_eggPrefabs[i]); } num++; } } if (num < 3) { return; } string[] array = new string[2] { "m_itemByHash", "m_itemsByHash" }; foreach (string name in array) { FieldInfo field = typeof(ObjectDB).GetField(name, bindingAttr); if (field == null || !(field.GetValue(objectDB) is Dictionary dictionary)) { continue; } GameObject[] eggPrefabs = _eggPrefabs; foreach (GameObject val in eggPrefabs) { if ((Object)(object)val != (Object)null) { dictionary[StringExtensionMethods.GetStableHashCode(((Object)val).name)] = val; } } break; } _registered = true; Plugin.Log.LogInfo((object)"EggItems: All eggs registered in ObjectDB"); } public static void RegisterInZNetScene(ZNetScene zNetScene) { if ((Object)(object)zNetScene == (Object)null) { return; } BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; Dictionary dictionary = null; string[] array = new string[2] { "m_namedPrefabs", "m_prefabsByHash" }; foreach (string name in array) { FieldInfo field = typeof(ZNetScene).GetField(name, bindingAttr); if (!(field == null)) { dictionary = field.GetValue(zNetScene) as Dictionary; if (dictionary != null) { break; } } } if (dictionary == null) { return; } GameObject[] eggPrefabs = _eggPrefabs; foreach (GameObject val in eggPrefabs) { if (!((Object)(object)val == (Object)null)) { int stableHashCode = StringExtensionMethods.GetStableHashCode(((Object)val).name); if (!dictionary.ContainsKey(stableHashCode)) { dictionary[stableHashCode] = val; } } } } public static void RegisterLocalization() { Localization instance = Localization.instance; if (instance == null) { return; } BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; Dictionary dictionary = null; string[] array = new string[2] { "m_translations", "m_words" }; foreach (string name in array) { FieldInfo field = typeof(Localization).GetField(name, bindingAttr); if (!(field == null)) { dictionary = field.GetValue(instance) as Dictionary; if (dictionary != null) { break; } } } if (dictionary != null) { for (int j = 0; j < 3; j++) { dictionary[$"aurora_egg_{j}"] = DisplayNames[j]; dictionary[$"aurora_egg_{j}_desc"] = Descriptions[j]; } } } public static GameObject GetEggPrefab(int tier) { if (tier < 0 || tier >= 3) { return null; } return _eggPrefabs[tier]; } public static void FixDropPrefab(ItemData item) { if (item == null || (Object)(object)item.m_dropPrefab != (Object)null) { return; } string text = item.m_shared?.m_name ?? ""; for (int i = 0; i < 3; i++) { if (text == $"$aurora_egg_{i}") { item.m_dropPrefab = _eggPrefabs[i]; break; } } } } [HarmonyPatch] public static class EggItemPatches { [HarmonyPatch(typeof(ObjectDB), "Awake")] [HarmonyPostfix] public static void ObjectDB_Awake(ObjectDB __instance) { EggItems.RegisterInObjectDB(__instance); EggItems.RegisterLocalization(); } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] [HarmonyPostfix] public static void ObjectDB_CopyOtherDB(ObjectDB __instance) { EggItems.RegisterInObjectDB(__instance); EggItems.RegisterLocalization(); } [HarmonyPatch(typeof(ZNetScene), "Awake")] [HarmonyPostfix] public static void ZNetScene_Awake(ZNetScene __instance) { EggItems.RegisterInZNetScene(__instance); } [HarmonyPatch(typeof(Humanoid), "DropItem")] [HarmonyPrefix] public static void DropItem_Fix(ItemData item) { EggItems.FixDropPrefab(item); } [HarmonyPatch(typeof(Player), "OnSpawned")] [HarmonyPostfix] public static void Player_OnSpawned(Player __instance) { if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return; } Inventory inventory = ((Humanoid)__instance).GetInventory(); if (inventory == null) { return; } foreach (ItemData allItem in inventory.GetAllItems()) { EggItems.FixDropPrefab(allItem); } } } [HarmonyPatch] public static class EggNests { private static readonly HashSet _nestedZones = new HashSet(); [HarmonyPatch(typeof(ZoneSystem), "SpawnZone")] [HarmonyPostfix] public static void OnZoneSpawn(ZoneSystem __instance, Vector2i zoneID, GameObject root) { //IL_0023: 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_005e: 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) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: 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_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: 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_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Invalid comparison between Unknown and I4 //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Invalid comparison between Unknown and I4 //IL_0110: 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_0129: Expected I4, but got Unknown //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Invalid comparison between Unknown and I4 //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Invalid comparison between Unknown and I4 //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Invalid comparison between Unknown and I4 //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) ZNet instance = ZNet.instance; if (instance == null || !instance.IsServer() || _nestedZones.Contains(zoneID)) { return; } float value = EggConfig.NestSpawnChance.Value; if (Random.value > value) { return; } _nestedZones.Add(zoneID); Vector3 zonePos = ZoneSystem.GetZonePos(zoneID); int num = 5; Vector3 val = default(Vector3); float num4 = default(float); for (int i = 0; i < num; i++) { float num2 = Random.Range(-30f, 30f); float num3 = Random.Range(-30f, 30f); ((Vector3)(ref val))..ctor(zonePos.x + num2, 0f, zonePos.z + num3); if (!ZoneSystem.instance.GetGroundHeight(val, ref num4) || num4 < ZoneSystem.instance.m_waterLevel + 0.5f) { continue; } val.y = num4 + 0.2f; Biome val2 = Heightmap.FindBiome(val); Biome val3 = val2; Biome val4 = val3; int num5; if ((int)val4 <= 8) { switch (val4 - 1) { default: if ((int)val4 != 8) { break; } goto case 0; case 0: num5 = 0; goto IL_0161; case 1: case 3: num5 = 1; goto IL_0161; case 2: break; } } else if ((int)val4 == 16 || (int)val4 == 32 || (int)val4 == 512) { num5 = 2; goto IL_0161; } num5 = 0; goto IL_0161; IL_0161: GameObject eggPrefab = EggItems.GetEggPrefab(num5); if ((Object)(object)eggPrefab == (Object)null) { continue; } try { GameObject val5 = Object.Instantiate(eggPrefab, val, Quaternion.identity); val5.SetActive(true); ItemDrop component = val5.GetComponent(); if ((Object)(object)component != (Object)null) { int stack = num5 switch { 1 => Random.Range(1, 4), 0 => Random.Range(2, 6), _ => 1, }; component.m_itemData.m_stack = stack; } Plugin.Log.LogInfo((object)$"EggNest: Spawned {EggItems.DisplayNames[num5]} x{(component?.m_itemData?.m_stack).GetValueOrDefault(1)} at {val} in zone {zoneID}"); break; } catch (Exception ex) { Plugin.Log.LogWarning((object)("EggNest: Failed to spawn: " + ex.Message)); break; } } } } public class EggRPC : MonoBehaviour { private const string RPC_MonsterKill = "AuroraEaster_MonsterKill"; private const string RPC_SyncStats = "AuroraEaster_SyncStats"; public static EggRPC Instance { get; private set; } private void Awake() { if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this) { Object.Destroy((Object)(object)this); } else { Instance = this; } } private void Start() { if (ZRoutedRpc.instance != null) { ZRoutedRpc.instance.Register("AuroraEaster_MonsterKill", (Action)RPC_OnMonsterKill); ZRoutedRpc.instance.Register("AuroraEaster_SyncStats", (Action)RPC_OnSyncStats); Plugin.Log.LogInfo((object)"EggRPC: Registered RPCs"); } } public void ReportMonsterKill(Vector3 monsterPos) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) ZRoutedRpc instance = ZRoutedRpc.instance; if (instance != null) { instance.InvokeRoutedRPC(GetServerPeerID(), "AuroraEaster_MonsterKill", new object[1] { monsterPos }); } } private void RPC_OnMonsterKill(long sender, Vector3 monsterPos) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) if (!ZNet.instance.IsServer()) { return; } ZNetPeer peer = ZNet.instance.GetPeer(sender); if (peer == null) { return; } foreach (Player allPlayer in Player.GetAllPlayers()) { if (allPlayer.GetPlayerID() == sender || ((Character)allPlayer).GetOwner() == sender) { EggDrops.ProcessEggDrop(allPlayer, monsterPos); break; } } } private void RPC_OnSyncStats(long sender, string json) { if (!ZNet.instance.IsServer()) { EggStats.LoadFromJson(json); } } public void BroadcastStats() { if (ZNet.instance.IsServer()) { string text = EggStats.SaveToJson(); ZRoutedRpc instance = ZRoutedRpc.instance; if (instance != null) { instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "AuroraEaster_SyncStats", new object[1] { text }); } } } private long GetServerPeerID() { if (ZNet.instance.IsServer()) { return ZNet.GetUID(); } return ZNet.instance.GetServerPeer()?.m_uid ?? 0; } } [Serializable] public class PlayerEggStats { public long PlayerId; public string PlayerName; public int PaintedEggs; public int SilverEggs; public int GoldenEggs; } [Serializable] public class EggStatsData { public List Players = new List(); public int TotalPaintedFound; public int TotalSilverFound; public int TotalGoldenFound; } public static class EggStats { private static EggStatsData _data = new EggStatsData(); private static float _saveTimer = 0f; private static bool _dirty = false; public static EggStatsData Data => _data; public static int GetPlayerTotalEggs(PlayerEggStats p) { return p.PaintedEggs + p.SilverEggs + p.GoldenEggs; } public static int GetTotalEggsFound() { return _data.TotalPaintedFound + _data.TotalSilverFound + _data.TotalGoldenFound; } public static void RecordEggFound(long playerId, string playerName, int tier) { PlayerEggStats playerEggStats = _data.Players.Find((PlayerEggStats p) => p.PlayerId == playerId); if (playerEggStats == null) { playerEggStats = new PlayerEggStats { PlayerId = playerId, PlayerName = playerName }; _data.Players.Add(playerEggStats); } playerEggStats.PlayerName = playerName; switch (tier) { case 0: playerEggStats.PaintedEggs++; _data.TotalPaintedFound++; break; case 1: playerEggStats.SilverEggs++; _data.TotalSilverFound++; break; case 2: playerEggStats.GoldenEggs++; _data.TotalGoldenFound++; break; } _dirty = true; } public static List GetLeaderboard() { List list = new List(_data.Players); list.Sort(delegate(PlayerEggStats a, PlayerEggStats b) { int num = b.GoldenEggs.CompareTo(a.GoldenEggs); if (num != 0) { return num; } num = b.SilverEggs.CompareTo(a.SilverEggs); return (num != 0) ? num : GetPlayerTotalEggs(b).CompareTo(GetPlayerTotalEggs(a)); }); return list; } public static void UpdateSave() { if (!_dirty) { return; } ZNet instance = ZNet.instance; if (instance != null && instance.IsServer()) { _saveTimer += Time.deltaTime; if (!(_saveTimer < 30f)) { _saveTimer = 0f; Save(); EggRPC.Instance?.BroadcastStats(); } } } public static void Save() { ZNet instance = ZNet.instance; if (instance == null || !instance.IsServer()) { return; } try { string text = Path.Combine(Paths.ConfigPath, "AuroraEasterEvent"); if (!Directory.Exists(text)) { Directory.CreateDirectory(text); } string path = Path.Combine(text, "egg_stats.json"); string contents = JsonUtility.ToJson((object)_data, true); File.WriteAllText(path, contents); _dirty = false; Plugin.Log.LogInfo((object)$"EggStats: Saved ({_data.Players.Count} players, {GetTotalEggsFound()} total eggs)"); } catch (Exception ex) { Plugin.Log.LogError((object)("EggStats: Save failed: " + ex.Message)); } } public static void Load() { try { string path = Path.Combine(Paths.ConfigPath, "AuroraEasterEvent", "egg_stats.json"); if (!File.Exists(path)) { Plugin.Log.LogInfo((object)"EggStats: No existing stats file, starting fresh"); return; } string text = File.ReadAllText(path); _data = JsonUtility.FromJson(text) ?? new EggStatsData(); Plugin.Log.LogInfo((object)$"EggStats: Loaded ({_data.Players.Count} players, {GetTotalEggsFound()} total eggs)"); } catch (Exception ex) { Plugin.Log.LogError((object)("EggStats: Load failed: " + ex.Message)); _data = new EggStatsData(); } } public static string SaveToJson() { return JsonUtility.ToJson((object)_data); } public static void LoadFromJson(string json) { try { _data = JsonUtility.FromJson(json) ?? new EggStatsData(); } catch { } } } [HarmonyPatch] public static class EggCommands { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__0_0; public static ConsoleEvent <>9__0_1; internal void b__0_0(ConsoleEventArgs args) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { args.Context.AddString("No local player."); return; } string text = ((args.Length >= 2) ? args[1].ToLower() : "painted"); int result; int num = ((args.Length < 3 || !int.TryParse(args[2], out result)) ? 1 : result); int num2; switch (text) { case "painted": num2 = 0; break; case "silver": num2 = 1; break; case "golden": case "gold": num2 = 2; break; default: num2 = 0; break; } GameObject eggPrefab = EggItems.GetEggPrefab(num2); if ((Object)(object)eggPrefab == (Object)null) { args.Context.AddString("Egg prefab not found."); return; } Inventory inventory = ((Humanoid)localPlayer).GetInventory(); if (inventory != null) { inventory.AddItem(eggPrefab, num); } args.Context.AddString($"Spawned {num}x {EggItems.DisplayNames[num2]}"); } internal void b__0_1(ConsoleEventArgs args) { //IL_0031: 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_0037: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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_0045: 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_005e: Expected I4, but got Unknown //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Invalid comparison between Unknown and I4 //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { args.Context.AddString("No local player."); return; } Vector3 position = ((Component)localPlayer).transform.position; Biome val = Heightmap.FindBiome(position); Biome val2 = val; Biome val3 = val2; int num; switch (val3 - 1) { default: if ((int)val3 == 8) { goto case 0; } goto case 2; case 0: num = 0; break; case 1: case 3: num = 1; break; case 2: num = 2; break; } GameObject eggPrefab = EggItems.GetEggPrefab(num); if ((Object)(object)eggPrefab == (Object)null) { args.Context.AddString("No egg prefab."); return; } GameObject val4 = Object.Instantiate(eggPrefab, position + Vector3.up * 0.3f, Quaternion.identity); val4.SetActive(true); ItemDrop component = val4.GetComponent(); if ((Object)(object)component != (Object)null) { component.m_itemData.m_stack = num switch { 1 => 3, 0 => 5, _ => 1, }; } args.Context.AddString("Spawned " + EggItems.DisplayNames[num] + " nest at your position."); } } [HarmonyPatch(typeof(Terminal), "InitTerminal")] [HarmonyPostfix] public static void AddCommands() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown //IL_006b: 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_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown object obj = <>c.<>9__0_0; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { Player localPlayer2 = Player.m_localPlayer; if ((Object)(object)localPlayer2 == (Object)null) { args.Context.AddString("No local player."); } else { string text = ((args.Length >= 2) ? args[1].ToLower() : "painted"); int result; int num2 = ((args.Length < 3 || !int.TryParse(args[2], out result)) ? 1 : result); int num3; switch (text) { case "painted": num3 = 0; break; case "silver": num3 = 1; break; case "golden": case "gold": num3 = 2; break; default: num3 = 0; break; } GameObject eggPrefab2 = EggItems.GetEggPrefab(num3); if ((Object)(object)eggPrefab2 == (Object)null) { args.Context.AddString("Egg prefab not found."); } else { Inventory inventory = ((Humanoid)localPlayer2).GetInventory(); if (inventory != null) { inventory.AddItem(eggPrefab2, num2); } args.Context.AddString($"Spawned {num2}x {EggItems.DisplayNames[num3]}"); } } }; <>c.<>9__0_0 = val; obj = (object)val; } new ConsoleCommand("spawneggs", "Spawn eggs: spawneggs [amount]", (ConsoleEvent)obj, true, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj2 = <>c.<>9__0_1; if (obj2 == null) { ConsoleEvent val2 = delegate(ConsoleEventArgs args) { //IL_0031: 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_0037: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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_0045: 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_005e: Expected I4, but got Unknown //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Invalid comparison between Unknown and I4 //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { args.Context.AddString("No local player."); } else { Vector3 position = ((Component)localPlayer).transform.position; Biome val3 = Heightmap.FindBiome(position); Biome val4 = val3; Biome val5 = val4; int num; switch (val5 - 1) { default: if ((int)val5 == 8) { goto case 0; } goto case 2; case 0: num = 0; break; case 1: case 3: num = 1; break; case 2: num = 2; break; } GameObject eggPrefab = EggItems.GetEggPrefab(num); if ((Object)(object)eggPrefab == (Object)null) { args.Context.AddString("No egg prefab."); } else { GameObject val6 = Object.Instantiate(eggPrefab, position + Vector3.up * 0.3f, Quaternion.identity); val6.SetActive(true); ItemDrop component = val6.GetComponent(); if ((Object)(object)component != (Object)null) { component.m_itemData.m_stack = num switch { 1 => 3, 0 => 5, _ => 1, }; } args.Context.AddString("Spawned " + EggItems.DisplayNames[num] + " nest at your position."); } } }; <>c.<>9__0_1 = val2; obj2 = (object)val2; } new ConsoleCommand("spawnnest", "Force spawn an egg nest at your position", (ConsoleEvent)obj2, true, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } } [BepInPlugin("aurora.easter.event", "Aurora Easter Event - Egg Hunt of Idunn", "1.0.0")] [BepInProcess("valheim.exe")] [BepInProcess("valheim_server.exe")] public class Plugin : BaseUnityPlugin { private Harmony _harmony; private GameObject _hudObj; private GameObject _rpcObj; public static Plugin Instance { get; private set; } public static ManualLogSource Log { get; private set; } private void Awake() { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; Log.LogInfo((object)"Aurora Easter Event loading..."); EggConfig.Initialize(((BaseUnityPlugin)this).Config); _harmony = new Harmony("aurora.easter.event"); _harmony.PatchAll(typeof(Plugin).Assembly); _hudObj = new GameObject("AuroraEasterHUD"); Object.DontDestroyOnLoad((Object)(object)_hudObj); _hudObj.AddComponent(); _rpcObj = new GameObject("AuroraEasterRPC"); Object.DontDestroyOnLoad((Object)(object)_rpcObj); _rpcObj.AddComponent(); EggStats.Load(); Log.LogInfo((object)"Aurora Easter Event loaded! Happy hunting!"); } private void Update() { EggStats.UpdateSave(); } private void OnApplicationQuit() { EggStats.Save(); } private void OnDestroy() { EggStats.Save(); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } if ((Object)(object)_hudObj != (Object)null) { Object.Destroy((Object)(object)_hudObj); } if ((Object)(object)_rpcObj != (Object)null) { Object.Destroy((Object)(object)_rpcObj); } } } }