Please disclose if your mod was created primarily 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 SuperWax v5.2.0
plugins/SuperWax.dll
Decompiled a week agousing System; using System.Diagnostics; using System.IO; 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 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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("SuperWax")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("SuperWax")] [assembly: AssemblyTitle("SuperWax")] [assembly: AssemblyVersion("1.0.0.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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] [Microsoft.CodeAnalysis.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; } } } namespace SuperWax { [BepInPlugin("com.jasterlee.superwax", "SuperWax", "5.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class SuperWax : BaseUnityPlugin { public class WaxEffect : MonoBehaviour { private void Start() { Apply(); ((MonoBehaviour)this).InvokeRepeating("Tick", 1f, 2f); } private void Apply() { MeshRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<MeshRenderer>(); foreach (MeshRenderer val in componentsInChildren) { Material[] materials = ((Renderer)val).materials; foreach (Material val2 in materials) { if (val2.HasProperty("_Metallic")) { val2.SetFloat("_Metallic", ShineMetallic.Value); } if (val2.HasProperty("_Glossiness")) { val2.SetFloat("_Glossiness", ShineGlossiness.Value); } } } } private void Tick() { WearNTear component = ((Component)this).GetComponent<WearNTear>(); if (Object.op_Implicit((Object)(object)component)) { Traverse.Create((object)component).Field("m_noWeatherDamage").SetValue((object)true); Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(true); foreach (Collider val in componentsInChildren) { ((Component)val).tag = "roof"; } } } } private readonly Harmony harmony = new Harmony("com.jasterlee.superwax"); public const string ZdoKey = "Jasterlee_Waxed_Final_v4"; public static string ItemPrefabName = "Beewax"; public static ConfigEntry<float> ShineGlossiness = null; public static ConfigEntry<float> ShineMetallic = null; private void Awake() { ShineGlossiness = ((BaseUnityPlugin)this).Config.Bind<float>("Visuals", "Glossiness", 0.4f, "Wax glossiness (dimmer for subtle shine)"); ShineMetallic = ((BaseUnityPlugin)this).Config.Bind<float>("Visuals", "Metallic", 0.08f, "Metallic reflection (dimmer for subtle shine)"); harmony.PatchAll(); PrefabManager.OnPrefabsRegistered += AddCustomContent; } private void AddCustomContent() { //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Expected O, but got Unknown //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Expected O, but got Unknown //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Expected O, but got Unknown //IL_02b7: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Expected O, but got Unknown //IL_0300: Unknown result type (might be due to invalid IL or missing references) //IL_0306: Expected O, but got Unknown //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_032b: Expected O, but got Unknown //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) PrefabManager.OnPrefabsRegistered -= AddCustomContent; try { string resourceName = "SuperWax.beewax_bundle"; AssetBundle val = LoadAssetBundle(resourceName); if ((Object)(object)val == (Object)null) { Logger.LogError((object)"[SuperWax] Failed to load bundle!"); return; } GameObject val2 = val.LoadAsset<GameObject>("assets/beewax_model_v1.prefab"); if ((Object)(object)val2 == (Object)null) { Logger.LogError((object)"[SuperWax] Prefab 'assets/beewax_model_v1.prefab' not found!"); val.Unload(true); return; } Texture2D tex; Sprite val3 = LoadEmbeddedSprite("SuperWax.beewax_icon.png", out tex); ItemConfig val4 = new ItemConfig(); val4.Name = "Beewax"; val4.Description = "Pure beeswax. Permanent waterproofing for wood."; val4.CraftingStation = "piece_workbench"; val4.Amount = 2; val4.Icons = (Sprite[])(object)((!((Object)(object)val3 != (Object)null)) ? null : new Sprite[1] { val3 }); ItemConfig val5 = val4; val5.AddRequirement(new RequirementConfig("Honey", 2, 0, true)); val5.AddRequirement(new RequirementConfig("Resin", 4, 0, true)); CustomItem val6 = new CustomItem(ItemPrefabName, "Honey", val5); if ((Object)(object)val6.ItemDrop != (Object)null) { val6.ItemDrop.m_itemData.m_shared.m_food = 10f; val6.ItemDrop.m_itemData.m_shared.m_foodStamina = 42f; Transform val7 = ((Component)val6.ItemDrop).gameObject.transform.Find("model"); if ((Object)(object)val7 != (Object)null) { Object.DestroyImmediate((Object)(object)((Component)val7).gameObject); } GameObject val8 = Object.Instantiate<GameObject>(val2, ((Component)val6.ItemDrop).gameObject.transform); ((Object)val8).name = "model"; val8.transform.localPosition = Vector3.zero; val8.transform.localRotation = Quaternion.identity; val8.transform.localScale = Vector3.one; Renderer[] componentsInChildren = val8.GetComponentsInChildren<Renderer>(true); foreach (Renderer val9 in componentsInChildren) { Material[] materials = val9.materials; foreach (Material val10 in materials) { if (val10.HasProperty("_Metallic")) { val10.SetFloat("_Metallic", ShineMetallic.Value); } if (val10.HasProperty("_Glossiness")) { val10.SetFloat("_Glossiness", ShineGlossiness.Value); } } } ItemManager.Instance.AddItem(val6); Logger.LogInfo((object)"[SuperWax] Beewax registered successfully!"); } PieceConfig val11 = new PieceConfig(); val11.Name = "Apply Super Wax"; val11.PieceTable = "_HammerPieceTable"; val11.Category = "Misc"; val11.Icon = val3; val11.Requirements = (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig(ItemPrefabName, 1, 0, true) }; PieceConfig val12 = val11; PieceManager.Instance.AddPiece(new CustomPiece("BeewaxTool", "piece_repair", val12)); val.Unload(false); } catch (Exception ex) { Logger.LogError((object)("[SuperWax] Error registering: " + ex.Message + "\n" + ex.StackTrace)); } } private AssetBundle LoadAssetBundle(string resourceName) { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName); if (stream == null) { Logger.LogError((object)("Resource not found: " + resourceName)); return null; } return AssetBundle.LoadFromStream(stream); } private Sprite? LoadEmbeddedSprite(string name, out Texture2D? tex) { //IL_0036: 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) tex = LoadEmbeddedTexture(name); if ((Object)(object)tex == (Object)null) { return null; } return Sprite.Create(tex, new Rect(0f, 0f, (float)((Texture)tex).width, (float)((Texture)tex).height), new Vector2(0.5f, 0.5f), 100f); } private Texture2D? LoadEmbeddedTexture(string path) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(path); if (stream == null) { return null; } byte[] array = new byte[stream.Length]; stream.Read(array, 0, array.Length); Texture2D val = new Texture2D(2, 2); return ImageConversion.LoadImage(val, array) ? val : null; } } [HarmonyPatch(typeof(Player), "UpdatePlacement")] public static class Player_Patch { [HarmonyPrefix] private static bool Prefix(Player __instance) { //IL_0071: 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_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Invalid comparison between Unknown and I4 //IL_018f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return true; } Piece selectedPiece = __instance.GetSelectedPiece(); if ((Object)(object)selectedPiece == (Object)null || ((Object)((Component)selectedPiece).gameObject).name != "BeewaxTool") { return true; } if (Input.GetMouseButtonDown(0) && !InventoryGui.IsVisible()) { RaycastHit val = default(RaycastHit); if (Physics.Raycast(((Component)GameCamera.instance).transform.position, ((Component)GameCamera.instance).transform.forward, ref val, 15f, LayerMask.GetMask(new string[1] { "piece" }))) { ZNetView componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<ZNetView>(); WearNTear componentInParent2 = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<WearNTear>(); if ((Object)(object)componentInParent != (Object)null && componentInParent.IsValid() && (Object)(object)componentInParent2 != (Object)null && ((int)componentInParent2.m_materialType == 0 || (int)componentInParent2.m_materialType == 3)) { if (componentInParent.GetZDO().GetBool("Jasterlee_Waxed_Final_v4", false)) { ((Character)__instance).Message((MessageType)2, "Already waxed!", 0, (Sprite)null); return false; } if (((Humanoid)__instance).GetInventory().HaveItem(SuperWax.ItemPrefabName, true)) { componentInParent.ClaimOwnership(); componentInParent.GetZDO().Set("Jasterlee_Waxed_Final_v4", true); ((Humanoid)__instance).GetInventory().RemoveItem(SuperWax.ItemPrefabName, 1, -1, true); ((Component)componentInParent).gameObject.AddComponent<SuperWax.WaxEffect>(); TriggerEffects(((RaycastHit)(ref val)).point); GameObject visual = ((Character)__instance).GetVisual(); if (visual != null) { visual.SendMessageUpwards("SetTrigger", (object)"attack", (SendMessageOptions)1); } ((Character)__instance).Message((MessageType)2, "Piece waxed!", 0, (Sprite)null); return false; } ((Character)__instance).Message((MessageType)2, "You need Beewax to apply!", 0, (Sprite)null); return false; } ((Character)__instance).Message((MessageType)2, "Can only wax wood pieces", 0, (Sprite)null); return false; } return false; } return true; } private static void TriggerEffects(Vector3 pos) { //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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)ZNetScene.instance == (Object)null)) { GameObject prefab = ZNetScene.instance.GetPrefab("vfx_HitSparks"); GameObject prefab2 = ZNetScene.instance.GetPrefab("sfx_build_hammer_wood"); if (Object.op_Implicit((Object)(object)prefab)) { Object.Instantiate<GameObject>(prefab, pos, Quaternion.identity); } if (Object.op_Implicit((Object)(object)prefab2)) { Object.Instantiate<GameObject>(prefab2, pos, Quaternion.identity); } } } } [HarmonyPatch(typeof(WearNTear), "Awake")] public static class Persistence_Patch { private static void Postfix(WearNTear __instance) { ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); if (Object.op_Implicit((Object)(object)component) && component.IsValid() && component.GetZDO().GetBool("Jasterlee_Waxed_Final_v4", false)) { ((Component)__instance).gameObject.AddComponent<SuperWax.WaxEffect>(); } } } }