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 FreyrsPrayPal v0.2.0
FreyrsPrayPal.dll
Decompiled 2 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("FreyrsPrayPal")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.2.0.0")] [assembly: AssemblyInformationalVersion("0.2.0+08d4dd30c599505ac2c1dee72ceac662b489ec00")] [assembly: AssemblyProduct("FreyrsPrayPal")] [assembly: AssemblyTitle("FreyrsPrayPal")] [assembly: AssemblyVersion("0.2.0.0")] namespace FreyrsPrayPal; [HarmonyPatch(typeof(Container))] internal static class ContainerPatches { [HarmonyPostfix] [HarmonyPatch("GetHoverText")] private static void GetHoverText(Container __instance, ref string __result) { PrayPal component = ((Component)__instance).GetComponent<PrayPal>(); if (Object.op_Implicit((Object)(object)component)) { __result = __result.Replace(Localization.instance.Localize("$piece_container_open"), Localization.instance.Localize("$piece_praypal_pray")); string statusText = component.GetStatusText(); if (statusText != null) { __result = __result + "\n" + statusText; } } } [HarmonyPostfix] [HarmonyPatch("RPC_OpenResponse")] private static void RPC_OpenResponse(Container __instance, bool granted) { PrayPal component = ((Component)__instance).GetComponent<PrayPal>(); if (granted && Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)Player.m_localPlayer)) { if (!component.HasInfluence) { component.Say("$msg_praypal_noinfluence"); } else if (component.IsBlocked()) { component.Say("$msg_praypal_taken"); } } } } internal static class DevCommands { public const bool DestroyUnlocked = false; } [HarmonyPatch(typeof(EnvMan))] internal static class EnvManPatches { private static string s_lastLog; public static string GetEventWeather() { string envOverride = RandEventSystem.instance.GetEnvOverride(); if (!string.IsNullOrEmpty(envOverride)) { return envOverride; } return PersistentEventSystem.instance.GetEnvironmentOverride(); } [HarmonyPrefix] [HarmonyPatch("GetEnvironmentOverride")] private static bool GetEnvironmentOverride(EnvMan __instance, ref string __result) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer) || ((Character)localPlayer).InInterior() || !string.IsNullOrEmpty(EnvZone.GetEnvironment())) { return true; } PrayPal activeAt = PrayPal.GetActiveAt(((Component)localPlayer).transform.position); if ((Object)(object)activeAt == (Object)null) { Log("Resetting env to normal scheduled biome weather"); return true; } if (!string.IsNullOrEmpty(__instance.m_debugEnv)) { Log("Env command weather \"" + __instance.m_debugEnv + "\" overrides PrayPal"); return true; } string envOverride = RandEventSystem.instance.GetEnvOverride(); if (((Character)localPlayer).InIntro() || !string.IsNullOrEmpty(envOverride)) { Log("Intro or raid weather \"" + envOverride + "\" overrides PrayPal"); return true; } string environmentOverride = PersistentEventSystem.instance.GetEnvironmentOverride(); if (!string.IsNullOrEmpty(environmentOverride)) { Log("Event weather \"" + environmentOverride + "\" overrides PrayPal"); __result = environmentOverride; return false; } __result = activeAt.CurrentWeather(); Log(activeAt.InMood ? ("Setting Angry-Weather \"" + __result + "\"") : ("Setting Paid Weather \"" + __result + "\"")); return false; } private static void Log(string message) { if (message != s_lastLog) { s_lastLog = message; Logger.LogInfo((object)message); } } } internal static class FreyrCarving { public const string PrefabName = "FreyrCarving"; private const string BasePrefab = "Resin"; private const string FloatingSource = "Wood"; private const string ModelAsset = "FreyrCarving_Model"; private const string BodyName = "FreyrCarving_Body"; private const string Dropper = "Greydwarf_Shaman"; private const float DropChance = 0.5f; private const int MaxStackSize = 10; private static readonly Quaternion IconRotation = Quaternion.Inverse(Quaternion.Euler(0f, -50f, 0f) * Quaternion.Euler(-75f, 0f, 0f)); private const float IconDistance = 0.75f; public static void Register(AssetBundle bundle, GameObject prayPal) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown //IL_0087: Expected O, but got Unknown //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Expected O, but got Unknown //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: 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_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Expected O, but got Unknown GameObject val = PrefabManager.Instance.CreateClonedPrefab("FreyrCarving", "Resin"); ReplaceVisual(val, bundle, prayPal); val.GetComponent<ItemDrop>().m_itemData.m_shared.m_maxStackSize = 10; ItemManager.Instance.AddItem(new CustomItem(val, false, new ItemConfig { Name = "$item_freyrcarving", Description = "$item_freyrcarving_description", Icon = RenderManager.Instance.Render(new RenderRequest(val) { Rotation = IconRotation, DistanceMultiplier = 0.75f }) })); PrefabManager.Instance.GetPrefab("Greydwarf_Shaman").GetComponent<CharacterDrop>().m_drops.Add(new Drop { m_prefab = val, m_amountMin = 1, m_amountMax = 1, m_chance = 0.5f, m_levelMultiplier = false }); } private static void ReplaceVisual(GameObject prefab, AssetBundle bundle, GameObject prayPal) { //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Expected O, but got Unknown //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) Object.DestroyImmediate((Object)(object)prefab.GetComponent<MeshRenderer>()); Object.DestroyImmediate((Object)(object)prefab.GetComponent<MeshFilter>()); Collider[] components = prefab.GetComponents<Collider>(); for (int i = 0; i < components.Length; i++) { Object.DestroyImmediate((Object)(object)components[i]); } for (int num = prefab.transform.childCount - 1; num >= 0; num--) { Object.DestroyImmediate((Object)(object)((Component)prefab.transform.GetChild(num)).gameObject); } GameObject val = Object.Instantiate<GameObject>(bundle.LoadAsset<GameObject>("FreyrCarving_Model"), prefab.transform, false); ((Object)val).name = "FreyrCarving_Model"; Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(true); for (int i = 0; i < componentsInChildren.Length; i++) { ((Component)componentsInChildren[i]).gameObject.layer = prefab.layer; } Material val2 = new Material(((Renderer)Array.Find(prayPal.GetComponentsInChildren<MeshRenderer>(true), (MeshRenderer renderer) => ((Object)renderer).name == "PrayPal_Body")).sharedMaterial) { name = "FreyrCarving_Wood" }; val2.SetTexture("_MainTex", (Texture)(object)bundle.LoadAsset<Texture2D>("FreyrCarving_Wood")); val2.SetTexture("_BumpMap", (Texture)(object)bundle.LoadAsset<Texture2D>("FreyrCarving_Wood_Normal")); Transform obj = val.transform.Find("FreyrCarving_Body"); ((Renderer)((Component)obj).GetComponent<MeshRenderer>()).sharedMaterial = val2; Bounds bounds = ((Component)obj).GetComponent<MeshFilter>().sharedMesh.bounds; BoxCollider obj2 = prefab.AddComponent<BoxCollider>(); obj2.center = ((Bounds)(ref bounds)).center; obj2.size = ((Bounds)(ref bounds)).size; Floating component = PrefabManager.Instance.GetPrefab("Wood").GetComponent<Floating>(); Floating obj3 = prefab.AddComponent<Floating>(); obj3.m_waterLevelOffset = component.m_waterLevelOffset; obj3.m_forceDistance = component.m_forceDistance; obj3.m_force = component.m_force; obj3.m_balanceForceFraction = component.m_balanceForceFraction; obj3.m_damping = component.m_damping; obj3.m_impactEffects = component.m_impactEffects; } } [HarmonyPatch] internal static class InventoryPatches { [HarmonyPrefix] [HarmonyPatch(typeof(InventoryGrid), "DropItem")] private static bool DropItem(InventoryGrid __instance, Inventory fromInventory, ItemData item, Vector2i pos, ref bool __result) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) Inventory inventory = __instance.GetInventory(); ItemData itemAt = inventory.GetItemAt(pos.x, pos.y); if ((PrayPal.IsBowl(inventory) && !PrayPal.IsAcceptedOffering(item)) || (PrayPal.IsBowl(fromInventory) && itemAt != null && itemAt != item && !PrayPal.IsAcceptedOffering(itemAt))) { __result = false; return false; } return true; } [HarmonyPostfix] [HarmonyPatch(typeof(Inventory), "ContainsItemByName")] private static void ContainsItemByName(Inventory __instance, string name, ref bool __result) { if (__result && PrayPal.IsBowl(__instance)) { ItemData item = __instance.GetAllItems().Find((ItemData i) => i.m_shared.m_name == name); __result = PrayPal.IsAcceptedOffering(item); } } [HarmonyPrefix] [HarmonyPatch(typeof(Inventory), "MoveItemToThis", new Type[] { typeof(Inventory), typeof(ItemData) })] private static bool MoveItemToThis(Inventory __instance, ItemData item) { if (PrayPal.IsBowl(__instance)) { return PrayPal.IsAcceptedOffering(item); } return true; } } [HarmonyPatch(typeof(Player))] internal static class PlayerPatches { private static bool s_removing; [HarmonyPrefix] [HarmonyPatch("RemovePiece")] private static void RemovePiecePrefix() { s_removing = true; } [HarmonyFinalizer] [HarmonyPatch("RemovePiece")] private static void RemovePieceFinalizer() { s_removing = false; } [HarmonyPostfix] [HarmonyPatch("CheckCanRemovePiece")] private static void CheckCanRemovePiece(Player __instance, Piece piece, ref bool __result) { PrayPal component = ((Component)piece).GetComponent<PrayPal>(); if ((s_removing & __result) && Object.op_Implicit((Object)(object)component) && component.RefusesRemoval()) { component.Say("$msg_praypal_noremove"); __result = false; } } } [BepInPlugin("de.evabs.valheim.freyrspraypal", "Freyr's PrayPal", "0.2.0")] [BepInDependency("com.jotunn.jotunn", "2.27.1")] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { public enum TextStyle { Wacky, Immersive } public const string PluginGuid = "de.evabs.valheim.freyrspraypal"; public const string PluginName = "Freyr's PrayPal"; public const string PluginVersion = "0.2.0"; private const string BundleName = "freyrspraypal"; public static ConfigEntry<bool> FreezingMoodWeather; public static ConfigEntry<TextStyle> Style; private void Awake() { //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_002c: Expected O, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) FreezingMoodWeather = ((BaseUnityPlugin)this).Config.Bind<bool>("Weather", "FreezingMoodWeather", true, new ConfigDescription("Freyr's mood may also bring freezing weather (snow, snow storm, twilight). Freezing drains health and can kill.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); Style = ((BaseUnityPlugin)this).Config.Bind<TextStyle>("Texts", "Style", TextStyle.Wacky, "Wacky: playful texts, the piece is called Freyr's PrayPal. Immersive: lore-friendly texts, the piece is called Freyr's Idol. Takes effect after restarting the game."); AddLocalizations(); PrefabManager.OnVanillaPrefabsAvailable += AddPrayPal; new Harmony("de.evabs.valheim.freyrspraypal").PatchAll(); } private static void AddPrayPal() { PrefabManager.OnVanillaPrefabsAvailable -= AddPrayPal; AssetBundle obj = AssetUtils.LoadAssetBundleFromResources("freyrspraypal"); FreyrCarving.Register(obj, PrayPalPiece.Register(obj)); obj.Unload(false); } private static void AddLocalizations() { Dictionary<string, string> dictionary = new Dictionary<string, string> { { "piece_praypal", "Freyr's PrayPal" }, { "piece_praypal_description", "A small idol of Freyr. Make an offering, and he may grant you sunny skies." }, { "piece_praypal_pray", "Make Offering" }, { "item_freyrcarving", "Freyr Carving" }, { "item_freyrcarving_description", "A fragment of a Freyr idol. Even the Greydwarfs could not extinguish its power." }, { "msg_praypal_noinfluence", "Freyr has no power in these lands" }, { "msg_praypal_unworthy", "Freyr mocks the offering" }, { "msg_praypal_sunny_day", "Freyr is of sunny disposition today" }, { "msg_praypal_sunny_days", "Freyr is of sunny disposition for another {0} days" }, { "msg_praypal_disrespected", "Freyr is feeling disrespected today" }, { "msg_praypal_wrath", "Freyr is furious today" }, { "msg_praypal_inactive", "Freyr is tending to personal matters" }, { "msg_praypal_taken", "Freyr is already weathering elsewhere" }, { "msg_praypal_overpowered", "Freyr cannot wield his powers at this time" }, { "msg_praypal_noremove", "Freyr is unimpressed by your tiny hammer" }, { "msg_praypal_wrath_begins", "Freyr is raising a storm" }, { "msg_praypal_busy", "Freyr is too busy to rage right now" } }; Dictionary<string, string> dictionary2 = new Dictionary<string, string> { { "piece_praypal", "Freyrs PrayPal" }, { "piece_praypal_description", "Ein kleiner Götze Freyrs. Bring ein Opfer dar, und er schenkt dir vielleicht sonnigen Himmel." }, { "piece_praypal_pray", "Opfer darbringen" }, { "item_freyrcarving", "Freyr-Schnitzerei" }, { "item_freyrcarving_description", "Ein Bruchstück eines Freyr-Idols. Nicht einmal die Greydwarfs konnten seine Macht auslöschen." }, { "msg_praypal_noinfluence", "Freyr hat in diesen Landen keine Macht" }, { "msg_praypal_unworthy", "Freyr verspottet die Opfergabe" }, { "msg_praypal_sunny_day", "Freyr hat heute ein sonniges Gemüt" }, { "msg_praypal_sunny_days", "Freyr ist noch {0} Tage sonnig gestimmt" }, { "msg_praypal_disrespected", "Freyr fühlt sich heute missachtet" }, { "msg_praypal_wrath", "Freyr ist heute mächtig böse" }, { "msg_praypal_inactive", "Freyr kümmert sich um persönliche Angelegenheiten" }, { "msg_praypal_taken", "Freyr wettert bereits woanders" }, { "msg_praypal_overpowered", "Freyr kann seine Kräfte jetzt nicht entfalten" }, { "msg_praypal_noremove", "Freyr ist nicht beeindruckt von deinem winzigen Hammer" }, { "msg_praypal_wrath_begins", "Freyr entfesselt einen Sturm" }, { "msg_praypal_busy", "Freyr ist beschäftigt und kann gerade nicht wüten" } }; if (Style.Value == TextStyle.Immersive) { dictionary["piece_praypal"] = "Freyr's Idol"; dictionary["msg_praypal_unworthy"] = "Freyr deems the offering unworthy"; dictionary["msg_praypal_sunny_day"] = "Freyr looks kindly upon you today"; dictionary["msg_praypal_sunny_days"] = "Freyr looks kindly upon you for another {0} days"; dictionary["msg_praypal_disrespected"] = "Freyr is displeased today"; dictionary["msg_praypal_wrath"] = "Freyr's wrath rages in the skies today"; dictionary["msg_praypal_inactive"] = "Freyr is awaiting an offering"; dictionary["msg_praypal_taken"] = "Freyr already commands the skies nearby"; dictionary["msg_praypal_noremove"] = "Freyr resists your destructive hammer"; dictionary["msg_praypal_busy"] = "Freyr spares you this time, his gaze is elsewhere"; dictionary2["piece_praypal"] = "Freyrs Idol"; dictionary2["msg_praypal_unworthy"] = "Die Opfergabe ist Freyrs unwürdig"; dictionary2["msg_praypal_sunny_day"] = "Freyr ist dir heute wohlgesonnen"; dictionary2["msg_praypal_sunny_days"] = "Freyr ist dir noch {0} Tage wohlgesonnen"; dictionary2["msg_praypal_disrespected"] = "Freyr ist heute ungnädig"; dictionary2["msg_praypal_wrath"] = "Freyrs Zorn wütet heute am Himmel"; dictionary2["msg_praypal_inactive"] = "Freyr erwartet eine Opfergabe"; dictionary2["msg_praypal_taken"] = "Freyr herrscht gerade über einen nahen Himmel"; dictionary2["msg_praypal_noremove"] = "Freyr widersteht deinem zerstörenden Hammer"; dictionary2["msg_praypal_busy"] = "Freyr verschont dich diesmal, sein Blick ruht anderswo"; } CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); string text = "English"; localization.AddTranslation(ref text, dictionary); text = "German"; localization.AddTranslation(ref text, dictionary2); } } internal sealed class PrayPal : MonoBehaviour, IPlaced { private static readonly Dictionary<Biome, string> FairWeather = new Dictionary<Biome, string> { { (Biome)1, "Clear" }, { (Biome)8, "DeepForest Mist" }, { (Biome)4, "Snow" }, { (Biome)16, "Heath clear" }, { (Biome)512, "Mistlands_clear" }, { (Biome)64, "Twilight_Clear" }, { (Biome)256, "Clear" } }; private static readonly string[] MoodWeather = new string[14] { "Misty", "LightRain", "Rain", "SwampRain", "nofogts", "Mistlands_rain", "Mistlands_thunder", "Ashlands_ashrain", "Ashlands_ashrain_clear", "Ashlands_storm", "Ashlands_meteorshower", "Ashlands_misty", "Ashlands_CinderRain", "Ashlands_SeaStorm" }; private static readonly string[] FreezingMoodWeather = new string[4] { "Snow", "SnowStorm", "Twilight_Clear", "Twilight_Snow" }; public const string BowlName = "$piece_praypal"; private static readonly List<PrayPal> s_influencing = new List<PrayPal>(); private const float WeatherRadius = 184f; private const string PaidDayKey = "FreyrsPrayPal_PaidDay"; private const string WeatherKey = "FreyrsPrayPal_Weather"; private const string StartedAtKey = "FreyrsPrayPal_StartedAt"; private const string PrepaidDaysKey = "FreyrsPrayPal_PrepaidDays"; private const string UnworthyRpc = "FreyrsPrayPal_Unworthy"; private const string WrathRpc = "FreyrsPrayPal_Wrath"; private const string BusyRpc = "FreyrsPrayPal_Busy"; private const string WrathStorm = "Twilight_SnowStorm"; private const string WrathStormWithoutFreezing = "ThunderStorm"; private const int GoldPerDay = 10; private static readonly Vector3 SpeechOffset = new Vector3(0f, 1.3f, 0f); private const float SpeechCullDistance = 20f; private const float SpeechSeconds = 4f; private static readonly Color FairGlow = new Color(0.3f, 1.8f, 0.3f); private static readonly Color MoodGlow = new Color(2f, 0f, 0f); private const string FairText = "#66E066"; private const string MoodText = "#FF5A4A"; private const string InactiveText = "#9A9A9A"; private ZNetView m_nview; private Container m_container; private Material m_glow; private string m_fairWeather; public bool HasInfluence => m_fairWeather != null; public bool InMood => !string.IsNullOrEmpty(m_nview.GetZDO().GetString("FreyrsPrayPal_Weather", "")); private bool InWrath { get { string text = m_nview.GetZDO().GetString("FreyrsPrayPal_Weather", ""); if (!(text == "Twilight_SnowStorm")) { return text == "ThunderStorm"; } return true; } } public static string FairWeatherAt(Vector3 position) { //IL_000a: 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) FairWeather.TryGetValue(WorldGenerator.instance.GetBiome(position), out var value); return value; } public static bool IsBowl(Inventory inventory) { if (inventory != null) { return inventory.GetName() == "$piece_praypal"; } return false; } public static bool IsAcceptedOffering(ItemData item) { //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_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 ItemType itemType = item.m_shared.m_itemType; if ((int)itemType != 1) { return (int)itemType == 2; } return true; } private void Awake() { //IL_002d: Unknown result type (might be due to invalid IL or missing references) m_nview = ((Component)this).GetComponent<ZNetView>(); m_container = ((Component)this).GetComponent<Container>(); if (m_nview.GetZDO() == null) { return; } m_fairWeather = FairWeatherAt(((Component)this).transform.position); if (HasInfluence) { s_influencing.Add(this); m_nview.Register("FreyrsPrayPal_Unworthy", (Action<long>)RPC_Unworthy); m_nview.Register("FreyrsPrayPal_Wrath", (Action<long>)RPC_Wrath); m_nview.Register("FreyrsPrayPal_Busy", (Action<long>)RPC_Busy); m_glow = ((Renderer)Array.Find(((Component)this).GetComponentsInChildren<MeshRenderer>(), (MeshRenderer renderer) => ((Object)renderer).name == "PrayPal_Eyes")).material; ((MonoBehaviour)this).InvokeRepeating("PayForToday", 1f, 1f); ((MonoBehaviour)this).InvokeRepeating("UpdateGlow", 0f, 1f); } } private void OnDestroy() { s_influencing.Remove(this); } public void OnPlaced() { if (!HasInfluence) { Say("$msg_praypal_noinfluence"); } else if (!string.IsNullOrEmpty(EnvManPatches.GetEventWeather())) { Say("$msg_praypal_overpowered"); } } public void Say(string text) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) Chat.instance.SetNpcText(((Component)this).gameObject, SpeechOffset, 20f, 4f, "", text, false); } public static PrayPal GetActiveAt(Vector3 position) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) PrayPal prayPal = null; foreach (PrayPal item in s_influencing) { if (item.m_nview.IsValid() && item.Covers(position) && item.IsPaidForToday() && ((Object)(object)prayPal == (Object)null || item.StartedBefore(prayPal))) { prayPal = item; } } return prayPal; } public void Strike(Player attacker) { if (!m_nview.IsValid() || !m_nview.IsOwner() || !HasInfluence) { return; } if (IsBlocked()) { m_nview.InvokeRPC(((Character)attacker).GetOwner(), "FreyrsPrayPal_Busy", Array.Empty<object>()); return; } string text = (Plugin.FreezingMoodWeather.Value ? "Twilight_SnowStorm" : "ThunderStorm"); if (!IsPaidForToday() || !(m_nview.GetZDO().GetString("FreyrsPrayPal_Weather", "") == text)) { SetToday(text); m_nview.InvokeRPC(ZNetView.Everybody, "FreyrsPrayPal_Wrath", Array.Empty<object>()); } } public bool RefusesRemoval() { if (IsPaidForToday()) { return InMood; } return false; } public bool IsBlocked() { //IL_006d: Unknown result type (might be due to invalid IL or missing references) if (!m_nview.IsValid() || IsPaidForToday()) { return false; } bool flag = m_nview.GetZDO().GetInt("FreyrsPrayPal_PaidDay", int.MinValue) == CurrentDay() - 1; foreach (PrayPal item in s_influencing) { if ((Object)(object)item != (Object)(object)this && item.m_nview.IsValid() && item.Covers(((Component)this).transform.position) && item.KeepsRunning() && (!flag || item.StartedBefore(this))) { return true; } } return false; } private bool KeepsRunning() { if (IsPaidForToday()) { return true; } ZDO zDO = m_nview.GetZDO(); if (zDO.GetInt("FreyrsPrayPal_PaidDay", int.MinValue) == CurrentDay() - 1) { if (zDO.GetInt("FreyrsPrayPal_PrepaidDays", 0) <= 0) { return m_container.GetInventory().GetAllItems().Exists(IsAcceptedOffering); } return true; } return false; } private bool StartedBefore(PrayPal other) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) ZDO zDO = m_nview.GetZDO(); ZDO zDO2 = other.m_nview.GetZDO(); long num = zDO.GetLong("FreyrsPrayPal_StartedAt", 0L); long num2 = zDO2.GetLong("FreyrsPrayPal_StartedAt", 0L); if (num >= num2) { if (num == num2) { return ((ZDOID)(ref zDO.m_uid)).CompareTo(zDO2.m_uid) < 0; } return false; } return true; } public string GetStatusText() { if (!m_nview.IsValid()) { return null; } if (!HasInfluence) { return Colored("#9A9A9A", "$msg_praypal_noinfluence"); } if (IsBlocked()) { return Colored("#9A9A9A", "$msg_praypal_taken"); } if (!IsPaidForToday()) { return Colored("#9A9A9A", "$msg_praypal_inactive"); } if (InWrath) { return Colored("#FF5A4A", "$msg_praypal_wrath"); } if (InMood) { return Colored("#FF5A4A", "$msg_praypal_disrespected"); } int num = m_nview.GetZDO().GetInt("FreyrsPrayPal_PrepaidDays", 0) + 1; if (num != 1) { return Colored("#66E066", string.Format(Localization.instance.Localize("$msg_praypal_sunny_days"), num)); } return Colored("#66E066", "$msg_praypal_sunny_day"); } private static string Colored(string color, string text) { return "<color=" + color + ">" + Localization.instance.Localize(text) + "</color>"; } private bool Covers(Vector3 position) { //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_000c: 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_0012: 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_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Component)this).transform.position - position; return val.x * val.x + val.z * val.z <= 33856f; } private bool IsPaidForToday() { if (m_nview.IsValid()) { return m_nview.GetZDO().GetInt("FreyrsPrayPal_PaidDay", int.MinValue) == CurrentDay(); } return false; } public string CurrentWeather() { if (!InMood) { return m_fairWeather; } return m_nview.GetZDO().GetString("FreyrsPrayPal_Weather", ""); } private void PayForToday() { //IL_0037: Unknown result type (might be due to invalid IL or missing references) if (!m_nview.IsValid()) { return; } if (!m_nview.GetZDO().HasOwner()) { if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && Covers(((Component)Player.m_localPlayer).transform.position)) { m_nview.ClaimOwnership(); } } else { if (!m_nview.IsOwner() || m_container.IsInUse() || IsPaidForToday() || IsBlocked()) { return; } ZDO zDO = m_nview.GetZDO(); int num = zDO.GetInt("FreyrsPrayPal_PrepaidDays", 0); string today; if (num > 0) { zDO.Set("FreyrsPrayPal_PrepaidDays", num - 1); today = ""; } else { Inventory inventory = m_container.GetInventory(); int num2 = TakeValuables(inventory); if (num2 >= 10) { zDO.Set("FreyrsPrayPal_PrepaidDays", num2 / 10 - 1); today = ""; } else { if (num2 == 0) { ItemData val = inventory.GetAllItemsInGridOrder().Find(IsAcceptedOffering); if (val == null) { return; } inventory.RemoveOneItem(val); } today = RollMoodWeather(m_fairWeather, zDO.GetString("FreyrsPrayPal_Weather", "")); m_nview.InvokeRPC(ZNetView.Everybody, "FreyrsPrayPal_Unworthy", Array.Empty<object>()); } } SetToday(today); } } private void SetToday(string weather) { ZDO zDO = m_nview.GetZDO(); int num = CurrentDay(); int num2 = zDO.GetInt("FreyrsPrayPal_PaidDay", int.MinValue); if (num2 != num && num2 != num - 1) { zDO.Set("FreyrsPrayPal_StartedAt", (long)(ZNet.instance.GetTimeSeconds() * 1000.0)); } zDO.Set("FreyrsPrayPal_Weather", weather); zDO.Set("FreyrsPrayPal_PaidDay", num); } public static string RollMoodWeather(string fairWeather, string previousWeather) { List<string> list = new List<string>(MoodWeather); if (Plugin.FreezingMoodWeather.Value) { list.AddRange(FreezingMoodWeather); } list.Remove(fairWeather); list.Remove(previousWeather); EnvSetup currentEnvironment = EnvMan.instance.GetCurrentEnvironment(); if (currentEnvironment != null) { list.Remove(currentEnvironment.m_name); } return list[Random.Range(0, list.Count)]; } private static int TakeValuables(Inventory inventory) { int num = 0; foreach (ItemData item in inventory.GetAllItemsInGridOrder()) { int value = item.m_shared.m_value; if (value > 0 && IsAcceptedOffering(item)) { int num2 = (10 - num + value - 1) / value; int num3 = Mathf.Min(item.m_stack, num2); inventory.RemoveItem(item, num3); num += num3 * value; if (num >= 10) { break; } } } return num; } private void RPC_Unworthy(long sender) { MessageInArea("$msg_praypal_unworthy"); } private void RPC_Wrath(long sender) { MessageInArea("$msg_praypal_wrath_begins"); } private void RPC_Busy(long sender) { Say("$msg_praypal_busy"); } private void MessageInArea(string message) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && Covers(((Component)Player.m_localPlayer).transform.position)) { ((Character)Player.m_localPlayer).Message((MessageType)2, message, 0, (Sprite)null, false); } } private static int CurrentDay() { double timeSeconds = ZNet.instance.GetTimeSeconds(); int day = EnvMan.instance.GetDay(timeSeconds); if (!(timeSeconds < EnvMan.instance.GetMorningStartSec(day))) { return day; } return day - 1; } private void UpdateGlow() { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) if (m_nview.IsValid()) { if (!IsPaidForToday()) { m_glow.DisableKeyword("_EMISSION"); return; } m_glow.SetColor("_EmissionColor", InMood ? MoodGlow : FairGlow); m_glow.EnableKeyword("_EMISSION"); } } } internal static class PrayPalPiece { public const string PrefabName = "PrayPal"; public const string EmblemName = "PrayPal_Emblem"; public const string EyesName = "PrayPal_Eyes"; public const string BodyName = "PrayPal_Body"; private const float Health = 2000f; private const string ModelChild = "new"; private const string IdolAsset = "PrayPal_Model"; private const string WardStoneMaterial = "Guardstone_Oden_mat"; private const string WardGlowMaterial = "Guardstone_OdenGlow_mat"; public static GameObject Register(AssetBundle bundle) { //IL_00ce: 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) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Expected O, but got Unknown //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Expected O, but got Unknown //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Expected O, but got Unknown //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Expected O, but got Unknown Container component = PrefabManager.Instance.GetPrefab("piece_chest_wood").GetComponent<Container>(); GameObject val = PrefabManager.Instance.CreateClonedPrefab("PrayPal", "guard_stone"); Object.DestroyImmediate((Object)(object)val.GetComponent<PrivateArea>()); Object.DestroyImmediate((Object)(object)val.GetComponent<LODGroup>()); for (int num = val.transform.childCount - 1; num >= 0; num--) { Transform child = val.transform.GetChild(num); if (((Object)child).name != "new") { Object.DestroyImmediate((Object)(object)((Component)child).gameObject); } } AddIdol(val.transform.Find("new"), bundle); val.GetComponent<ZNetView>().m_distant = true; val.GetComponent<WearNTear>().m_health = 2000f; Piece component2 = val.GetComponent<Piece>(); ((StaticTarget)component2).m_primaryTarget = false; ((StaticTarget)component2).m_randomTarget = false; component2.m_icon = RenderManager.Instance.Render(val, Quaternion.identity); Container obj = val.AddComponent<Container>(); obj.m_name = "$piece_praypal"; obj.m_width = 4; obj.m_height = 1; obj.m_bkg = component.m_bkg; obj.m_privacy = component.m_privacy; obj.m_checkGuardStone = component.m_checkGuardStone; obj.m_openEffects = component.m_openEffects; obj.m_closeEffects = component.m_closeEffects; obj.m_discoverStat = component.m_discoverStat; val.AddComponent<PrayPal>(); PieceManager instance = PieceManager.Instance; PieceConfig val2 = new PieceConfig(); val2.Name = "$piece_praypal"; val2.Description = "$piece_praypal_description"; val2.PieceTable = PieceTables.Hammer; val2.Category = PieceCategories.Misc; val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[2] { new RequirementConfig("FreyrCarving", 4, 0, true), new RequirementConfig("Resin", 10, 0, true) }; instance.AddPiece(new CustomPiece(val, false, val2)); return val; } private static void AddIdol(Transform model, AssetBundle bundle) { //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Expected O, but got Unknown //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) Material[] sharedMaterials = ((Renderer)((Component)model).GetComponentInChildren<MeshRenderer>()).sharedMaterials; for (int num = model.childCount - 1; num >= 0; num--) { Object.DestroyImmediate((Object)(object)((Component)model.GetChild(num)).gameObject); } GameObject val = Object.Instantiate<GameObject>(bundle.LoadAsset<GameObject>("PrayPal_Model"), model, false); ((Object)val).name = "PrayPal_Model"; Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(true); for (int i = 0; i < componentsInChildren.Length; i++) { ((Component)componentsInChildren[i]).gameObject.layer = ((Component)model).gameObject.layer; } Material val2 = CopyMaterial(sharedMaterials, "Guardstone_Oden_mat", "PrayPal_Wood"); val2.SetTexture("_MainTex", (Texture)(object)bundle.LoadAsset<Texture2D>("PrayPal_Wood")); val2.SetTexture("_BumpMap", (Texture)(object)bundle.LoadAsset<Texture2D>("PrayPal_Wood_Normal")); Material val3 = CopyMaterial(sharedMaterials, "Guardstone_OdenGlow_mat", "PrayPal_Emblem"); val3.SetTexture("_MainTex", (Texture)(object)bundle.LoadAsset<Texture2D>("PrayPal_Emblem")); val3.SetTexture("_EmissionMap", (Texture)null); val3.SetColor("_EmissionColor", Color.black); val3.SetTexture("_BumpMap", (Texture)null); val3.DisableKeyword("_NORMALMAP"); val3.DisableKeyword("_EMISSION"); Material val4 = new Material(val3) { name = "PrayPal_Eyes" }; val4.SetTexture("_MainTex", (Texture)(object)bundle.LoadAsset<Texture2D>("PrayPal_Eyes")); val4.SetTexture("_EmissionMap", (Texture)(object)bundle.LoadAsset<Texture2D>("PrayPal_Eyes_Glow")); Transform obj = val.transform.Find("PrayPal_Body"); ((Renderer)((Component)obj).GetComponent<MeshRenderer>()).sharedMaterial = val2; Bounds bounds = ((Component)obj).GetComponent<MeshFilter>().sharedMesh.bounds; CapsuleCollider obj2 = ((Component)obj).gameObject.AddComponent<CapsuleCollider>(); obj2.center = ((Bounds)(ref bounds)).center; obj2.height = ((Bounds)(ref bounds)).size.y; obj2.radius = Mathf.Max(((Bounds)(ref bounds)).size.x, ((Bounds)(ref bounds)).size.z) / 2f; ((Renderer)((Component)val.transform.Find("PrayPal_Emblem")).GetComponent<MeshRenderer>()).sharedMaterial = val3; ((Renderer)((Component)val.transform.Find("PrayPal_Eyes")).GetComponent<MeshRenderer>()).sharedMaterial = val4; } private static Material CopyMaterial(Material[] materials, string sourceName, string name) { //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_002c: Expected O, but got Unknown return new Material(Array.Find(materials, (Material material) => ((Object)material).name.StartsWith(sourceName))) { name = name }; } } [HarmonyPatch(typeof(WearNTear))] internal static class WearNTearPatches { [HarmonyPostfix] [HarmonyPatch("RPC_Damage")] private static void RPC_Damage(WearNTear __instance, HitData hit) { PrayPal component = ((Component)__instance).GetComponent<PrayPal>(); if (Object.op_Implicit((Object)(object)component)) { Character attacker = hit.GetAttacker(); Player val = (Player)(object)((attacker is Player) ? attacker : null); if (val != null) { component.Strike(val); } } } }