using 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 TMPro;
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: AssemblyVersion("0.0.0.0")]
public class ConfigJson
{
public bool pinless;
}
public enum HorizontalAnchor
{
LEFT,
CENTER,
RIGHT
}
public enum VerticalAnchor
{
TOP,
CENTER,
BOTTOM
}
namespace ShowWeight
{
[BepInPlugin("fiote.mods.showweight", "ShowWeight", "0.0.1")]
public class ShowWeight : BaseUnityPlugin
{
public static bool debug = true;
public static ConfigFile configFile;
public static GameObject goWeight;
public static TextMeshProUGUI txtWeight;
public static ConfigEntry<int> configTextOffsetX;
public static ConfigEntry<int> configTextOffsetY;
public static ConfigEntry<int> configTextFontSize;
public static ConfigEntry<HorizontalAnchor> configHorizontalAnchor;
public static ConfigEntry<VerticalAnchor> configVerticalAnchor;
private void Awake()
{
Bar();
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "fiote.mods.showweight");
Debug("Awake");
SetupConfig();
Bar();
}
private void SetupConfig()
{
Line();
Debug("SetupConfig()");
configFile = ((BaseUnityPlugin)this).Config;
((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 2696, "NexusMods ID for updates.");
configHorizontalAnchor = ((BaseUnityPlugin)this).Config.Bind<HorizontalAnchor>("Anchoring", "HorizontalAnchor", HorizontalAnchor.LEFT, "Adjust the weight's text horizontal anchor.");
configVerticalAnchor = ((BaseUnityPlugin)this).Config.Bind<VerticalAnchor>("Anchoring", "VerticalAnchor", VerticalAnchor.BOTTOM, "Adjust the weight's text vertical anchor.");
configTextOffsetX = ((BaseUnityPlugin)this).Config.Bind<int>("Text", "OffsetX", 40, "Adjust the weight's text horizontal position (left/right).");
configTextOffsetY = ((BaseUnityPlugin)this).Config.Bind<int>("Text", "OffsetY", 20, "Adjust the weight's text vertical position (down/up).");
configTextFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("Text", "FontSize", 20, "Adjust the weight's text font size.");
configFile.SettingChanged += delegate
{
Recreate();
};
}
public static void Recreate()
{
Line();
Debug("Recreate()");
CreateWeightText(null);
}
public static void CreateWeightText(Hud hud)
{
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Expected O, but got Unknown
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_0197: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: 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_021f: Unknown result type (might be due to invalid IL or missing references)
Line();
Debug("CreateWeightText()");
if ((Object)(object)hud == (Object)null)
{
hud = Hud.instance;
}
GameObject val = hud?.m_rootObject;
if (!((Object)(object)val == (Object)null))
{
if ((Object)(object)goWeight != (Object)null)
{
Object.Destroy((Object)(object)goWeight);
}
goWeight = new GameObject("ShowWeightText", new Type[1] { typeof(RectTransform) });
goWeight.transform.SetParent(val.transform, false);
Transform transform = goWeight.transform;
RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
val2.sizeDelta = new Vector2(200f, 30f);
((Transform)val2).localPosition = Vector2.op_Implicit(new Vector2((float)configTextOffsetX.Value, (float)configTextOffsetY.Value));
Vector2 val3 = default(Vector2);
((Vector2)(ref val3))..ctor(0.5f, 0.5f);
switch (configHorizontalAnchor.Value)
{
case HorizontalAnchor.LEFT:
val3.x = 0f;
break;
case HorizontalAnchor.CENTER:
val3.x = 0.5f;
break;
case HorizontalAnchor.RIGHT:
val3.x = 1f;
break;
}
switch (configVerticalAnchor.Value)
{
case VerticalAnchor.TOP:
val3.y = 1f;
break;
case VerticalAnchor.CENTER:
val3.y = 0.5f;
break;
case VerticalAnchor.BOTTOM:
val3.y = 0f;
break;
}
val2.anchorMin = val3;
val2.anchorMax = val3;
val2.pivot = val3;
txtWeight = goWeight.AddComponent<TextMeshProUGUI>();
((TMP_Text)txtWeight).fontSize = configTextFontSize.Value;
TextMeshProUGUI obj = txtWeight;
object font;
if (hud == null)
{
font = null;
}
else
{
TMP_Text healthText = hud.m_healthText;
font = ((healthText != null) ? healthText.font : null);
}
((TMP_Text)obj).font = (TMP_FontAsset)font;
((TMP_Text)txtWeight).text = "...";
((TMP_Text)txtWeight).alignment = ConvertAnchorToAlignment(configHorizontalAnchor.Value, configVerticalAnchor.Value);
UpdateTexts();
Line();
}
}
public static void InventoryChanged(Inventory inventory)
{
if (!((Object)(object)Player.m_localPlayer == (Object)null) && inventory == ((Humanoid)Player.m_localPlayer).GetInventory())
{
UpdateTexts();
}
}
public static void UpdateTexts()
{
if (!((Object)(object)Player.m_localPlayer == (Object)null))
{
Player localPlayer = Player.m_localPlayer;
int num = Mathf.CeilToInt(((Humanoid)localPlayer).GetInventory().GetTotalWeight());
int num2 = Mathf.CeilToInt(localPlayer.GetMaxCarryWeight());
float num3 = (float)num / (float)num2;
((TMP_Text)txtWeight).text = "Weight: " + num + "/" + num2;
}
}
private static TextAlignmentOptions ConvertAnchorToAlignment(HorizontalAnchor horizontalAnchor, VerticalAnchor verticalAnchor)
{
//IL_0039: 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_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
switch (horizontalAnchor)
{
case HorizontalAnchor.LEFT:
switch (verticalAnchor)
{
case VerticalAnchor.TOP:
return (TextAlignmentOptions)257;
case VerticalAnchor.CENTER:
return (TextAlignmentOptions)4097;
case VerticalAnchor.BOTTOM:
return (TextAlignmentOptions)1025;
}
break;
case HorizontalAnchor.CENTER:
switch (verticalAnchor)
{
case VerticalAnchor.TOP:
return (TextAlignmentOptions)258;
case VerticalAnchor.CENTER:
return (TextAlignmentOptions)4098;
case VerticalAnchor.BOTTOM:
return (TextAlignmentOptions)1026;
}
break;
case HorizontalAnchor.RIGHT:
switch (verticalAnchor)
{
case VerticalAnchor.TOP:
return (TextAlignmentOptions)260;
case VerticalAnchor.CENTER:
return (TextAlignmentOptions)4100;
case VerticalAnchor.BOTTOM:
return (TextAlignmentOptions)1028;
}
break;
}
return (TextAlignmentOptions)257;
}
public static void Bar()
{
Debug("=============================================================");
}
public static void Line()
{
Debug("-------------------------------------------------------------");
}
public static void Debug(string message)
{
if (debug)
{
Log(message);
}
}
public static void Log(string message)
{
Debug.Log((object)("[ShowWeight] " + message));
}
public static void Error(string message)
{
Debug.LogError((object)("[ShowWeight] " + message));
}
}
[HarmonyPatch(typeof(Console), "InputText")]
public static class Console_InputText_Patch
{
public class ConsoleValue
{
public string value;
public float floatvalue;
public int intvalue;
public bool boolvalue;
public ConsoleValue(string value)
{
this.value = value.ToLower();
bool flag = float.TryParse(value, out floatvalue);
intvalue = (flag ? Mathf.RoundToInt(floatvalue) : 0);
boolvalue = value == "1" || value == "yes" || value == "on";
}
}
public static Dictionary<string, ConsoleValue> vars = new Dictionary<string, ConsoleValue>
{
{
"x",
new ConsoleValue("20")
},
{
"y",
new ConsoleValue("-10")
},
{
"f",
new ConsoleValue("20")
}
};
private static bool Prefix(Console __instance)
{
string text = ((TMP_InputField)((Terminal)__instance).m_input).text;
string[] array = text.Split(new char[1] { '=' });
if (array.Length == 2)
{
string text2 = array[0];
string value = array[1];
ConsoleValue consoleValue = new ConsoleValue(value);
string[] array2 = text2.Split(new char[1] { '.' });
if (array2[0] != "sw")
{
vars[text2] = consoleValue;
ShowWeight.Recreate();
return true;
}
string text3 = array2[1];
if (text3 == "h")
{
Enum.TryParse<HorizontalAnchor>(consoleValue.value.ToUpper(), out var result);
ShowWeight.configHorizontalAnchor.Value = result;
ShowWeight.Log("HORIZONTAL ANCHOR config changed to " + result);
}
if (text3 == "v")
{
Enum.TryParse<VerticalAnchor>(consoleValue.value.ToUpper(), out var result2);
ShowWeight.configVerticalAnchor.Value = result2;
ShowWeight.Log("VERTICAL ANCHOR config changed to " + result2);
}
if (text3 == "fontsize")
{
ShowWeight.configTextFontSize.Value = consoleValue.intvalue;
ShowWeight.Log("FONTSIZE config changed to " + consoleValue.intvalue);
}
if (text3 == "x")
{
ShowWeight.configTextOffsetX.Value = consoleValue.intvalue;
ShowWeight.Log("OFFSETX config changed to " + consoleValue.intvalue);
}
if (text3 == "y")
{
ShowWeight.configTextOffsetY.Value = consoleValue.intvalue;
ShowWeight.Log("OFFSETY config changed to " + consoleValue.intvalue);
}
ShowWeight.configFile.Save();
ShowWeight.Recreate();
return false;
}
return true;
}
}
}
namespace ShowWeight.Patches
{
[HarmonyPatch(typeof(Hud), "Awake")]
public static class Hud_Awake_Patch
{
public static void Postfix(Hud __instance)
{
ShowWeight.CreateWeightText(__instance);
}
}
[HarmonyPatch(typeof(Inventory), "UpdateTotalWeight")]
public static class Inventory_UpdateTotalWeight_Patch
{
public static void Postfix(Inventory __instance)
{
ShowWeight.InventoryChanged(__instance);
}
}
}