using 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.0.1")]
[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.6f, "Wax glossiness (dimmer for subtle shine)");
ShineMetallic = ((BaseUnityPlugin)this).Config.Bind<float>("Visuals", "Metallic", 0.15f, "Metallic reflection (dimmer for subtle shine)");
harmony.PatchAll();
PrefabManager.OnPrefabsRegistered += AddCustomContent;
}
private void AddCustomContent()
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Expected O, but got Unknown
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Expected O, but got Unknown
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Expected O, but got Unknown
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Expected O, but got Unknown
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Expected O, but got Unknown
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Expected O, but got Unknown
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Expected O, but got Unknown
PrefabManager.OnPrefabsRegistered -= AddCustomContent;
try
{
string name = Assembly.GetExecutingAssembly().GetName().Name;
Texture2D tex;
Sprite val = LoadEmbeddedSprite(name + ".beewax_icon.png", out tex);
ItemConfig val2 = new ItemConfig();
val2.Name = "Beewax";
val2.Description = "Pure beeswax. Permanent waterproofing for wood.";
val2.CraftingStation = "piece_workbench";
val2.Amount = 2;
val2.Icons = (Sprite[])(object)((!((Object)(object)val != (Object)null)) ? null : new Sprite[1] { val });
ItemConfig val3 = val2;
val3.AddRequirement(new RequirementConfig("Honey", 2, 0, true));
val3.AddRequirement(new RequirementConfig("Resin", 4, 0, true));
CustomItem val4 = new CustomItem(ItemPrefabName, "Honey", val3);
if ((Object)(object)val4.ItemDrop != (Object)null)
{
ApplyWaxTint(((Component)val4.ItemDrop).gameObject);
ItemManager.Instance.AddItem(val4);
}
PieceConfig val5 = new PieceConfig();
val5.Name = "Apply Super Wax";
val5.PieceTable = "_HammerPieceTable";
val5.Category = "Misc";
val5.Icon = val;
val5.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
{
new RequirementConfig(ItemPrefabName, 1, 0, true)
};
PieceConfig val6 = val5;
PieceManager.Instance.AddPiece(new CustomPiece("BeewaxTool", "piece_repair", val6));
}
catch (Exception arg)
{
Logger.LogError((object)$"[SuperWax] Error in Content Registration: {arg}");
}
}
private void ApplyWaxTint(GameObject itemObj)
{
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)itemObj == (Object)null)
{
return;
}
Renderer[] componentsInChildren = itemObj.GetComponentsInChildren<Renderer>(true);
foreach (Renderer val in componentsInChildren)
{
Material[] materials = val.materials;
foreach (Material val2 in materials)
{
val2.color = new Color(0.85f, 0.48f, 0.28f);
if (val2.HasProperty("_Metallic"))
{
val2.SetFloat("_Metallic", ShineMetallic.Value);
}
if (val2.HasProperty("_Glossiness"))
{
val2.SetFloat("_Glossiness", ShineGlossiness.Value);
}
}
}
}
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_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Invalid comparison between Unknown and I4
//IL_018a: 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 || selectedPiece.m_name != "Apply Super Wax")
{
return true;
}
RaycastHit val = default(RaycastHit);
if (Input.GetMouseButtonDown(0) && !InventoryGui.IsVisible() && Physics.Raycast(((Component)GameCamera.instance).transform.position, ((Component)GameCamera.instance).transform.forward, ref val, 10f, 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))
{
((Character)__instance).Message((MessageType)2, "Can only wax wood pieces", 0, (Sprite)null);
return false;
}
if (componentInParent.GetZDO().GetBool("Jasterlee_Waxed_Final_v4", false))
{
((Character)__instance).Message((MessageType)2, "ITS WAXED ALREADY", 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;
}
}
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>();
}
}
}
}