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 BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Construction.Anim;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Sons.Gameplay.GPS;
using TMPro;
using TheForest;
using TheForest.Items.Inventory;
using TheForest.Items.Special;
using TheForest.Utils;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("LogCarryAmount")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LogCarryAmount")]
[assembly: AssemblyTitle("LogCarryAmount")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LogCapacity;
[BepInPlugin("SmokyAce.LogCarryAmount", "LogCarryAmount", "1.4.1")]
public class LogCapacity : BasePlugin
{
public const string GUID = "SmokyAce.LogCarryAmount";
public const string NAME = "LogCarryAmount";
public const string VERSION = "1.4.1";
public const string AUTHOR = "ThirtyTwelve & SmokyAce";
internal static ConfigFile configFile;
internal static ConfigEntry<int> MaxLogCapacity;
internal static ConfigEntry<bool> ToggleMaxLogCapacity;
internal static ConfigEntry<bool> StoreLogs;
internal static ConfigEntry<KeyCode> StoreLogsKey;
internal static ConfigEntry<bool> ToggleUI;
internal static ConfigEntry<bool> LegacyLogHack;
internal static ConfigEntry<bool> LogToConsole;
internal static ConfigEntry<bool> ToggleLogCapacity;
internal static ConfigEntry<float> awaitGiveLog;
internal static ConfigEntry<float> UIPOSX;
internal static ConfigEntry<float> UIPOSY;
internal static ManualLogSource DLog;
private static bool loggedVisibilityFailure;
public override void Load()
{
//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_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Expected O, but got Unknown
Logger.Sources.Add((ILogSource)(object)DLog);
Harmony.CreateAndPatchAll(typeof(LogPatcher), (string)null);
Harmony.CreateAndPatchAll(typeof(MaxAmountPatch), (string)null);
ClassInjector.RegisterTypeInIl2Cpp<CustomComponent>();
GameObject val = new GameObject("CustomGameObject")
{
hideFlags = (HideFlags)61
};
val.AddComponent<CustomComponent>();
Object.DontDestroyOnLoad((Object)val);
((BasePlugin)this).Log.LogInfo((object)"Loaded LogCarryAmount 1.4.1 by ThirtyTwelve & SmokyAce");
}
static LogCapacity()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Expected O, but got Unknown
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Expected O, but got Unknown
//IL_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Expected O, but got Unknown
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Expected O, but got Unknown
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Expected O, but got Unknown
//IL_0210: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Expected O, but got Unknown
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_022e: Expected O, but got Unknown
configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "LogCarryAmount.cfg"), true);
MaxLogCapacity = configFile.Bind<int>("General", "LogCapacityAmount", 4, new ConfigDescription("Max amount of logs you can carry", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 100), Array.Empty<object>()));
ToggleMaxLogCapacity = configFile.Bind<bool>("General", "MaxLogCapacity", true, "Limits");
StoreLogs = configFile.Bind<bool>("General", "StoreLogs", false, "Makes it possible to store logs");
StoreLogsKey = configFile.Bind<KeyCode>("General", "StoreLogsKey", (KeyCode)262, "Key For Storing Logs");
ToggleUI = configFile.Bind<bool>("General", "LogCounterUI", true, "Log Counter On Screen");
LegacyLogHack = configFile.Bind<bool>("General", "Loghack method", false, "Different Log types not supported, Only recommended if experiencing problems");
LogToConsole = configFile.Bind<bool>("General", "ShowLogs", false, new ConfigDescription("Logs will be displayed in the console", (AcceptableValueBase)null, new object[1] { "Advanced" }));
ToggleLogCapacity = configFile.Bind<bool>("Advanced", "LogCapacity", true, new ConfigDescription("The entire Mod", (AcceptableValueBase)null, new object[1] { "Advanced" }));
awaitGiveLog = configFile.Bind<float>("Advanced", "AwaitLog", 0.8f, new ConfigDescription("Delay against voiding logs", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[1] { "Advanced" }));
UIPOSX = configFile.Bind<float>("UIPos, WIP requires relaunch", "X Position", 540f, new ConfigDescription("defines the x position of logs UI", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-500f, 666f), new object[1] { "Advanced" }));
UIPOSY = configFile.Bind<float>("UIPos, WIP requires relaunch", "Y Position", 160f, new ConfigDescription("defines the z position of logs UI", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-50f, 590f), new object[1] { "Advanced" }));
DLog = new ManualLogSource("DLog");
}
internal static void SetLogVisibility(bool show)
{
try
{
GameObject gameObject = LocalPlayer.GameObject;
if ((Object)(object)gameObject == (Object)null || gameObject.transform.childCount <= 6)
{
return;
}
Transform child = gameObject.transform.GetChild(6);
if (child.childCount <= 8)
{
return;
}
LogVisibilityController component = ((Component)child.GetChild(8)).gameObject.GetComponent<LogVisibilityController>();
if ((Object)(object)component == (Object)null)
{
return;
}
for (int i = 0; i < 9; i++)
{
if (i < 4)
{
component.SetAdditionalLogVisibility(show);
}
else
{
if (i <= 4)
{
continue;
}
GameObject heldLogVisibilityOverride = component._heldLogVisibilityOverride;
if (!((Object)(object)heldLogVisibilityOverride == (Object)null) && heldLogVisibilityOverride.transform.childCount > i)
{
Transform child2 = heldLogVisibilityOverride.transform.GetChild(i);
if (child2.childCount > 1)
{
((Component)child2.GetChild(1)).gameObject.SetActive(show);
}
}
}
}
}
catch (Exception ex)
{
if (!loggedVisibilityFailure)
{
loggedVisibilityFailure = true;
DLog.LogWarning((object)("Could not update extra log visibility: " + ex.Message));
}
}
}
internal static void DLogInfo(string message, bool rateLimit)
{
if (LogToConsole.Value && (!rateLimit || Time.frameCount % 15 == 0))
{
DLog.LogInfo((object)message);
}
}
}
public class CustomComponent : MonoBehaviour
{
private static int bufferw;
private static bool infinitewood;
private static int helditem;
internal static GameObject panel;
internal static TextMeshProUGUI LogText;
private bool isLogsStored;
private bool shouldGiveLog;
private bool forceGiveLog;
private float timerGiveLog;
private bool loggedMissingController;
public CustomComponent(IntPtr ptr)
: base(ptr)
{
}
private void Update()
{
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
if (!LocalPlayer.IsInWorld || !LogCapacity.ToggleLogCapacity.Value)
{
return;
}
HeldOnlyItemController controller = GetController();
if ((Object)(object)controller == (Object)null)
{
if (!loggedMissingController)
{
loggedMissingController = true;
LogCapacity.DLog.LogWarning((object)"HeldOnlyItemController was not available. Carry changes are paused until it exists.");
}
return;
}
if (LogCapacity.LegacyLogHack.Value && (Object)(object)DebugConsole.Instance != (Object)null)
{
DebugConsole.Instance._loghack(infinitewood ? "on" : "off");
}
int heldCount = controller._heldCount;
if (LogCapacity.StoreLogs.Value && Input.GetKeyDown(LogCapacity.StoreLogsKey.Value))
{
StoreLog(controller, heldCount);
}
if (isLogsStored)
{
return;
}
switch (heldCount)
{
case 1:
if (infinitewood)
{
infinitewood = false;
}
LogCapacity.SetLogVisibility(show: false);
helditem = controller._heldItemId;
break;
case 2:
if (!LogCapacity.ToggleMaxLogCapacity.Value || bufferw + heldCount < LogCapacity.MaxLogCapacity.Value)
{
LogCapacity.DLogInfo("case2", rateLimit: false);
controller._heldCount = 1;
LogCapacity.SetLogVisibility(show: false);
bufferw++;
}
break;
default:
if (LogCapacity.LegacyLogHack.Value && !infinitewood && bufferw > 0 && !controller.HasItem)
{
infinitewood = true;
bufferw--;
}
else if (!LogCapacity.LegacyLogHack.Value && bufferw > 0 && heldCount < 1)
{
LogCapacity.DLogInfo("default", rateLimit: true);
shouldGiveLog = true;
}
break;
}
if (shouldGiveLog)
{
timerGiveLog += Time.deltaTime;
if (timerGiveLog >= LogCapacity.awaitGiveLog.Value || forceGiveLog)
{
GiveLog();
timerGiveLog = 0f;
shouldGiveLog = false;
forceGiveLog = false;
}
else if (AreEmpty())
{
forceGiveLog = true;
}
}
int num = bufferw + heldCount;
if (num >= 1)
{
if (LogCapacity.ToggleUI.Value && (Object)(object)LogText != (Object)null && (Object)(object)panel != (Object)null)
{
((TMP_Text)LogText).SetText(num + WoodType(helditem));
panel.SetActive(true);
}
LogCapacity.DLogInfo(num + WoodType(helditem), rateLimit: true);
}
else if ((Object)(object)panel != (Object)null)
{
panel.SetActive(false);
}
}
private void StoreLog(HeldOnlyItemController controller, int heldCount)
{
if (!isLogsStored)
{
isLogsStored = true;
LogCapacity.DLogInfo("In heldCount = " + heldCount, rateLimit: false);
bufferw += heldCount;
controller._heldCount = 1;
LogCapacity.SetLogVisibility(show: false);
PlayerInventory inventory = LocalPlayer.Inventory;
inventory.RemoveItem(helditem, 1, false, true, true, inventory.HeldOnlyItemController.HeldItem, true);
}
else if (isLogsStored)
{
isLogsStored = false;
}
}
private void GiveLog()
{
bufferw--;
LocalPlayer.Inventory.TryEquip(helditem, false, false, false);
}
private static bool AreEmpty()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Invalid comparison between Unknown and I4
PlayerInventory inventory = LocalPlayer.Inventory;
if (inventory.IsRightHandEmpty() && inventory.IsLeftHandEmpty() && inventory.HasRoomFor(helditem, 2) && !inventory.IsInventoryToggleBlocked() && !LocalPlayer.IsUnderwater)
{
return (int)inventory._currentEquipState == 2;
}
return false;
}
private static string WoodType(int itemId)
{
switch (itemId)
{
case 78:
case 406:
case 408:
case 409:
return " Logs";
case 395:
case 576:
case 577:
case 578:
return " Planks";
case 640:
return " Stones";
default:
return " null";
}
}
private static HeldOnlyItemController GetController()
{
PlayerInventory inventory = LocalPlayer.Inventory;
if ((Object)(object)inventory == (Object)null || inventory.HeldOnlyItemController == null)
{
return null;
}
return ((Il2CppObjectBase)inventory.HeldOnlyItemController).TryCast<HeldOnlyItemController>();
}
}
[HarmonyPatch(typeof(GPSTrackerSystem), "OnEnable")]
internal static class LogPatcher
{
[HarmonyPostfix]
private static void OnEnablePostfix()
{
LogCapacity.DLog.LogInfo((object)"IN From GPS OnEnablePostfix");
if ((Object)(object)CustomComponent.panel == (Object)null)
{
loadUI();
}
}
private static void loadUI()
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Expected O, but got Unknown
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
if (LogCapacity.LogToConsole.Value)
{
LogCapacity.DLog.LogInfo((object)"IN loadUI");
}
if (LogCapacity.ToggleUI.Value)
{
GameObject val = GameObject.Find("ToggleableHUD");
if (!((Object)(object)val == (Object)null))
{
CustomComponent.panel = new GameObject("LogCountUi");
CustomComponent.panel.transform.SetParent(val.transform);
CustomComponent.panel.transform.localPosition = new Vector3(0f, -460f, 0f);
GameObject val2 = new GameObject("LogCountText");
CustomComponent.LogText = val2.AddComponent<TextMeshProUGUI>();
((TMP_Text)CustomComponent.LogText).SetText("LogCount");
((TMP_Text)CustomComponent.LogText).fontSize = 36f;
val2.transform.SetParent(CustomComponent.panel.transform);
((Transform)((TMP_Text)CustomComponent.LogText).rectTransform).localPosition = new Vector3(LogCapacity.UIPOSX.Value, LogCapacity.UIPOSY.Value, 0f);
CustomComponent.panel.SetActive(false);
}
}
}
}
[HarmonyPatch(typeof(PlayerInventory), "GetMaxAmountOf")]
internal static class MaxAmountPatch
{
private static void Postfix(PlayerInventory __instance, int itemId, ref int __result)
{
if (LogCapacity.ToggleLogCapacity.Value && __result < 2)
{
IHeldOnlyItemController val = ((__instance != null) ? __instance.HeldOnlyItemController : null);
if (val != null && val.Controlling(itemId))
{
__result = 2;
}
}
}
}