using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Jotunn;
using Jotunn.Managers;
using Jotunn.Utils;
using RestingRockFace.Components;
using RestingRockFace.Gui;
using RestingRockFace.Models;
using Splatform;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RestingRockFace")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RestingRockFace")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace RestingRockFace
{
[BepInPlugin("DeathWizsh.RestingRockFace", "RestingRockFace", "0.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class RestingRockFace : BaseUnityPlugin
{
public const string PluginGUID = "DeathWizsh.RestingRockFace";
public const string PluginName = "RestingRockFace";
public const string PluginVersion = "0.0.1";
public static RestingRockFace Instance;
private static readonly Harmony harmony = new Harmony("DeathWizsh.RestingRockFace");
public RockyGUI rockyGUI;
public void Awake()
{
Instance = this;
harmony.PatchAll(Assembly.GetExecutingAssembly());
PrefabManager.OnVanillaPrefabsAvailable += SetupRocky;
}
private void SetupRocky()
{
try
{
GameObject prefab = PrefabManager.Instance.GetPrefab("Placeable_HardRock");
Transform val = prefab.transform.Find("default");
prefab.AddComponent<RockyControls>();
PrefabManager.OnVanillaPrefabsAvailable -= SetupRocky;
}
catch (Exception ex)
{
Logger.LogError((object)("Could not update rocky: " + ex));
PrefabManager.OnVanillaPrefabsAvailable -= SetupRocky;
}
}
}
}
namespace RestingRockFace.Types
{
internal enum RockyFaceEnum
{
Dead = 5,
LookLeft = 8,
LookRight = 7,
NoFeeling = 2,
Nothing = 6,
Sad = 1,
Scream = 3,
Smile = 4,
SmileBig = 0
}
internal class RockyFaceTypes
{
public string Dead => "Dead";
public string LookLeft => "Look left";
public string LookRight => "Look right";
public string NoFeeling => "No feeling";
public string Nothing => "Nothing";
public string Sad => "Sad";
public string Scream => "Scream";
public string Smile => "Smile";
public string SmileBig => "Smile big";
}
}
namespace RestingRockFace.Models
{
internal class RockyGuiResult
{
public string name;
public int face;
public RockyGuiResult(string name, int face)
{
this.face = face;
this.name = name;
}
}
}
namespace RestingRockFace.Harmony
{
[HarmonyPatch]
public class PatchesRRF
{
[HarmonyPrefix]
[HarmonyPatch(typeof(Tameable), "Interact")]
public static bool Interact_Prefix(ref Tameable __instance, Humanoid user, bool hold, bool alt)
{
try
{
if ((Object)(object)__instance == (Object)null || hold || !alt)
{
return true;
}
if (((Object)((Component)__instance).gameObject).name != "Placeable_HardRock(Clone)")
{
return true;
}
RockyControls component = ((Component)__instance).gameObject.GetComponent<RockyControls>();
component.m_gui.ShowGUI();
return false;
}
catch (Exception ex)
{
Logger.LogError((object)("Somethign went wrong in GetText_Prefix: " + ex));
return true;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Pet), "SetFace")]
public static bool SetFace_Prefix(ref Tameable __instance, int index)
{
try
{
if ((Object)(object)__instance == (Object)null)
{
return true;
}
if (((Object)((Component)__instance).gameObject).name != "Placeable_HardRock(Clone)")
{
return true;
}
Logger.LogWarning((object)("Harmony SetFace: " + index));
RockyControls component = ((Component)__instance).gameObject.GetComponent<RockyControls>();
if ((Object)(object)component == (Object)null)
{
throw new Exception("RockyControls is null somehow");
}
if (component.m_face == 6)
{
return true;
}
return false;
}
catch (Exception ex)
{
Logger.LogError((object)("Somethign went wrong in SetFace_Prefix: " + ex));
return true;
}
}
}
}
namespace RestingRockFace.Gui
{
internal class RockyGUI
{
private GameObject panel;
public UnityEvent<RockyGuiResult> onAccept = new UnityEvent<RockyGuiResult>();
public UnityEvent onClose = new UnityEvent();
public UnityEvent onSelect = new UnityEvent();
private RockyControls rockyControls;
private RockyGuiResult currentForm;
private float panelWidth = 420f;
private float panelHeight = 230f;
private float fieldWidth = 385f;
private float fieldHeight = 30f;
private float labelHeight = 30f;
private float buttonWidth = 190f;
private float buttonHeight = 50f;
private float buttonYoffset = 42f;
public RockyGUI(RockyControls rockyControls)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
this.rockyControls = rockyControls;
}
public void ShowGUI()
{
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
Logger.LogWarning((object)"ShowGUI()");
if (GUIManager.Instance == null)
{
Logger.LogError((object)"GUIManager instance is null");
return;
}
if (!Object.op_Implicit((Object)(object)GUIManager.CustomGUIFront))
{
Logger.LogError((object)"GUIManager CustomGUI is null");
return;
}
if ((Object)(object)panel == (Object)null)
{
panel = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 0f), panelWidth, panelHeight, false);
}
currentForm = new RockyGuiResult(rockyControls.m_name, (rockyControls.m_face == -1) ? 2 : rockyControls.m_face);
panel.SetActive(false);
CreateGUI();
panel.SetActive(true);
GUIManager.BlockInput(true);
}
public void Close()
{
onClose.Invoke();
panel.SetActive(false);
GUIManager.BlockInput(false);
}
public void Accept()
{
onAccept.Invoke(currentForm);
onClose.Invoke();
panel.SetActive(false);
GUIManager.BlockInput(false);
}
public void SetName(string value)
{
Logger.LogWarning((object)("SetName(), " + value));
currentForm.name = value;
}
public void SetFace(int value)
{
Logger.LogWarning((object)("SetFace(), " + value));
currentForm.face = GetRockyFace(value);
}
public void UpdateGUI()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
foreach (Transform item in panel.transform)
{
Transform val = item;
Object.Destroy((Object)(object)((Component)val).gameObject);
}
CreateGUI();
}
private void CreateGUI()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: 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_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: 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_0122: 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_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
//IL_0298: Unknown result type (might be due to invalid IL or missing references)
//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
//IL_02f9: Expected O, but got Unknown
//IL_0319: Unknown result type (might be due to invalid IL or missing references)
//IL_0328: Unknown result type (might be due to invalid IL or missing references)
//IL_0338: Unknown result type (might be due to invalid IL or missing references)
//IL_0370: Unknown result type (might be due to invalid IL or missing references)
//IL_037a: Expected O, but got Unknown
GUIManager.Instance.CreateText("Name", panel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -30f), GUIManager.Instance.AveriaSerifBold, 20, GUIManager.Instance.ValheimOrange, true, Color.black, fieldWidth, labelHeight, false);
GameObject val = GUIManager.Instance.CreateInputField(panel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -60f), (ContentType)0, "Name", 18, fieldWidth, fieldHeight);
InputField component = val.GetComponent<InputField>();
component.text = currentForm.name;
((UnityEvent<string>)(object)component.onValueChanged).AddListener((UnityAction<string>)SetName);
component.characterLimit = 64;
GUIManager.Instance.CreateText("Face", panel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -100f), GUIManager.Instance.AveriaSerifBold, 20, GUIManager.Instance.ValheimOrange, true, Color.black, fieldWidth, labelHeight, false);
GameObject val2 = GUIManager.Instance.CreateDropDown(panel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -130f), 18, fieldWidth, fieldHeight);
Dropdown component2 = val2.GetComponent<Dropdown>();
((Component)component2).GetComponent<Dropdown>().AddOptions(new List<string> { "Dead", "LookLeft", "LookRight", "NoFeeling", "Nothing", "Sad", "Scream", "Smile", "SmileBig" });
component2.value = GetDropdownValue(currentForm.face);
((UnityEvent<int>)(object)component2.onValueChanged).AddListener((UnityAction<int>)SetFace);
GameObject val3 = GUIManager.Instance.CreateButton("Close", panel.transform, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(-100f, buttonYoffset), buttonWidth, buttonHeight);
val3.SetActive(true);
Button component3 = val3.GetComponent<Button>();
((UnityEvent)component3.onClick).AddListener(new UnityAction(Close));
GameObject val4 = GUIManager.Instance.CreateButton("Accept", panel.transform, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(100f, buttonYoffset), buttonWidth, buttonHeight);
val4.SetActive(true);
Button component4 = val4.GetComponent<Button>();
((UnityEvent)component4.onClick).AddListener(new UnityAction(Accept));
}
private int GetRockyFace(int value)
{
return value switch
{
0 => 5,
1 => 8,
2 => 7,
3 => 2,
5 => 1,
6 => 3,
7 => 4,
8 => 0,
_ => 6,
};
}
private int GetDropdownValue(int value)
{
return value switch
{
5 => 0,
8 => 1,
7 => 2,
2 => 3,
1 => 5,
3 => 6,
4 => 7,
0 => 8,
_ => 4,
};
}
}
}
namespace RestingRockFace.Components
{
internal class RockyControls : MonoBehaviour
{
public ZNetView m_netView;
public RockyGUI m_gui;
public Tameable m_tameable;
public MaterialVariation materialVar;
public Transform m_faceTransform;
private readonly int faceDataHash = StringExtensionMethods.GetStableHashCode("FaceData_RRF");
public string m_name;
public int m_face;
public void Awake()
{
m_netView = ((Component)this).gameObject.GetComponent<ZNetView>();
if (!((Object)(object)m_netView == (Object)null) && m_netView.GetZDO() != null)
{
m_netView.Register<string, string, int>("SetNameAndFace", (Action<long, string, string, int>)RPC_SetNameAndFace);
m_faceTransform = ((Component)this).gameObject.transform.Find("default");
materialVar = ((Component)m_faceTransform).gameObject.GetComponent<MaterialVariation>();
m_tameable = ((Component)this).gameObject.GetComponent<Tameable>();
m_gui = new RockyGUI(this);
m_gui.onAccept.AddListener((UnityAction<RockyGuiResult>)SetNameAndFace);
m_name = m_tameable.GetName();
m_face = m_netView.GetZDO().GetInt(faceDataHash, 6);
UpdateFace(m_face);
Logger.LogWarning((object)("Awake name: " + m_name));
Logger.LogWarning((object)("Awake face: " + m_face));
}
}
public void Start()
{
if (!((Object)(object)m_netView == (Object)null) && m_netView.GetZDO() != null)
{
Logger.LogWarning((object)("Start SetMaterial: " + (m_face != 6)));
if (m_face != 6)
{
materialVar.SetMaterial(m_face);
}
}
}
public void SetNameAndFace(RockyGuiResult result)
{
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
Logger.LogWarning((object)$"Result: {result.name}, {result.face}");
m_name = result.name;
m_face = result.face;
if (m_netView.IsValid())
{
PlatformUserID platformUserID = ((IUser)PlatformManager.DistributionPlatform.LocalUser).PlatformUserID;
m_netView.InvokeRPC("SetNameAndFace", new object[3]
{
result.name,
PlatformManager.DistributionPlatform.LocalUser.IsSignedIn ? ((object)(PlatformUserID)(ref platformUserID)).ToString() : "host",
result.face
});
}
}
public void RPC_SetNameAndFace(long sender, string name, string authorId, int face)
{
if (m_netView.IsValid() && m_netView.IsOwner())
{
m_netView.GetZDO().Set(ZDOVars.s_tamedName, name);
m_netView.GetZDO().Set(ZDOVars.s_tamedNameAuthor, authorId);
UpdateFace(face);
materialVar.SetMaterial(face);
}
}
public void UpdateFace(int face)
{
if (face == 6)
{
m_netView.GetZDO().RemoveInt(faceDataHash);
Logger.LogWarning((object)"UpdateFace: removed ZDO");
}
else
{
m_netView.GetZDO().Set(faceDataHash, face, false);
Logger.LogWarning((object)"UpdateFace: set ZDO");
}
}
}
}