using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace LuckyBranchesNS;
[BepInPlugin("mennowar.mods.LuckyBranches", "LuckyBranches", "1.0.3")]
[BepInDependency("com.jotunn.jotunn", "2.23.2")]
public class LuckyBranches : BaseUnityPlugin
{
[HarmonyPatch(typeof(Pickable), "Interact")]
private static class PickPatch0
{
private static void Prefix(Humanoid character, bool repeat, bool alt)
{
if (repeat || (Object)(object)character == (Object)null)
{
return;
}
GameObject hoverObject = character.GetHoverObject();
if (!((Object)(object)hoverObject == (Object)null))
{
Pickable componentInParent = hoverObject.GetComponentInParent<Pickable>();
if ((Object)(object)componentInParent != (Object)null && !string.IsNullOrEmpty(((Object)componentInParent).name) && ((Object)componentInParent).name.ToUpper().StartsWith("PICKABLE_BRANCH"))
{
ProcessPickup(character.GetInventory());
}
}
}
}
public const string PluginId = "mennowar.mods.LuckyBranches";
public const string SharedName = "LuckyBranches";
public static ConfigEntry<bool> WriteDebugOutput;
public static ConfigEntry<bool> IsEnabled;
public static ConfigEntry<bool> IsMeadowsEnabled;
public static ConfigEntry<bool> IsBlackforestEnabled;
public static ConfigEntry<bool> IsSwampEnabled;
public static ConfigEntry<bool> ShowInfoText;
public static ConfigEntry<int> Chance;
public static ConfigEntry<int> Amount;
private static Random m_random = new Random();
private static ManualLogSource m_logSource = null;
private Harmony m_Harmony = new Harmony("mennowar.mods.LuckyBranches");
public static void Debug(string value)
{
if (WriteDebugOutput.Value)
{
if (m_logSource == null)
{
m_logSource = Logger.CreateLogSource("LuckyBranches");
}
if (m_logSource != null)
{
m_logSource.LogMessage((object)value);
}
}
}
private static void WriteStatus()
{
Debug(string.Format("{0} is {1} with a chance of {2} and amount of {3}", "LuckyBranches", IsEnabled.Value ? "Enabled" : "Disabled", Chance.Value, Amount.Value));
Debug("I will " + (ShowInfoText.Value ? "" : "<b>NOT</b>") + " show Notification");
Debug($"Add wood in Meadows: {IsMeadowsEnabled.Value}");
Debug($"Add wood in BF: {IsBlackforestEnabled.Value}");
Debug($"Add wood in Swamp: {IsSwampEnabled.Value}");
}
private void CreateConfigValues()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Expected O, but got Unknown
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Expected O, but got Unknown
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Expected O, but got Unknown
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Expected O, but got Unknown
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: 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_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Expected O, but got Unknown
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Expected O, but got Unknown
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Expected O, but got Unknown
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Expected O, but got Unknown
//IL_019c: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Expected O, but got Unknown
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Expected O, but got Unknown
//IL_01d7: 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_01e4: Expected O, but got Unknown
//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: Expected O, but got Unknown
((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
IsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "isEnabled", true, new ConfigDescription("Is this mod enabled?", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
Chance = ((BaseUnityPlugin)this).Config.Bind<int>("General", "dropChance", 30, new ConfigDescription("The Dropchance of special wood (% Value)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
Amount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "dropAmount", 2, new ConfigDescription("The amount of special wood that you will find", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
ShowInfoText = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "showMessage", true, new ConfigDescription("Display Infotext when special wood has been found?", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
WriteDebugOutput = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "writeDebug", true, new ConfigDescription("Write Debug Informations to the console?", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
IsMeadowsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Biomes", "meadowsEnabled", true, new ConfigDescription("Enable special wood finding in the Meadows?", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
IsBlackforestEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Biomes", "blackforestEnabled", true, new ConfigDescription("Enable special wood finding in the Black Forest?", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
IsSwampEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Biomes", "swampEnabled", true, new ConfigDescription("Enable special wood finding in the Swamp??", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
SynchronizationManager.OnConfigurationSynchronized += SynchronizationManager_OnConfigurationSynchronized;
}
private void Awake()
{
CreateConfigValues();
m_Harmony.PatchAll();
WriteStatus();
}
private void SynchronizationManager_OnConfigurationSynchronized(object sender, ConfigurationSynchronizationEventArgs e)
{
if (e.InitialSynchronization)
{
Logger.LogMessage((object)"Initial Config sync event received");
}
else
{
Logger.LogMessage((object)"Config sync event received");
}
WriteStatus();
}
public static void ProcessPickup(Inventory inventory)
{
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Invalid comparison between Unknown and I4
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Invalid comparison between Unknown and I4
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Invalid comparison between Unknown and I4
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Invalid comparison between Unknown and I4
if (!IsEnabled.Value || inventory == null)
{
return;
}
string text = string.Empty;
int num = m_random.Next(1, 100);
Debug($"Pickup Rolled a: {num}");
if (num <= Chance.Value && (Object)(object)Player.m_localPlayer != (Object)null)
{
Biome currentBiome = Player.m_localPlayer.GetCurrentBiome();
if ((IsMeadowsEnabled.Value && (int)currentBiome == 1) || (int)currentBiome == 4)
{
text = "FineWood";
}
else if (IsBlackforestEnabled.Value && (int)currentBiome == 8)
{
text = "RoundLog";
}
else if (IsSwampEnabled.Value && (int)currentBiome == 2)
{
text = "ElderBark";
}
inventory.AddItem(text, Amount.Value, 1, 0, 0L, string.Empty, false);
if ((Object)(object)Player.m_localPlayer != (Object)null && ShowInfoText != null && ShowInfoText.Value)
{
((Character)Player.m_localPlayer).Message((MessageType)1, $"You found {Amount.Value} {text} under the branches", 0, (Sprite)null);
}
}
}
}