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 BepInEx;
using BepInEx.Logging;
using HarmonyLib;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CaspersFreebiesPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CaspersFreebiesPlugin")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("84cf9172-d88c-457e-bee4-9775764b0e6d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.casper.caspersfreebies", "Caspers Freebies", "1.0.0")]
public class CaspersFreebiesPlugin : BaseUnityPlugin
{
private Harmony _harmony;
private static bool _enableFreeRecipes;
private static bool _enableAlwaysHasResources;
public static ManualLogSource Log = new ManualLogSource("CaspersFreebies");
public void Awake()
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
_enableFreeRecipes = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableFreeRecipes", false, "Enable unlocked recipes.").Value;
_enableAlwaysHasResources = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableAlwaysHasResources", true, "Enable always have resources and free crafting.").Value;
_harmony = new Harmony("com.casper.caspersfreebies");
Logger.Sources.Add((ILogSource)(object)Log);
if (_enableAlwaysHasResources)
{
_harmony.PatchAll(typeof(InventoryPatch));
_harmony.PatchAll(typeof(InventoryWrapperPatch));
_harmony.PatchAll(typeof(GameDefinesPatch));
Log.LogInfo((object)"Always Have Resources patches applied.");
}
if (_enableFreeRecipes)
{
_harmony.PatchAll(typeof(FreeRecipesPatch));
Log.LogInfo((object)"Free Recipes patch applied.");
}
Log.LogInfo((object)"Caspers Freebies plugin loaded.");
}
public void OnDestroy()
{
_harmony.UnpatchSelf();
Log.LogInfo((object)"Caspers Freebies plugin unloaded.");
}
}
[HarmonyPatch(typeof(Inventory))]
public static class InventoryPatch
{
[HarmonyPrefix]
[HarmonyPatch("HasResources", new Type[]
{
typeof(ResourceInfo),
typeof(int)
})]
public static bool Prefix_HasResourcesInfo(ref bool __result)
{
__result = true;
return false;
}
[HarmonyPrefix]
[HarmonyPatch("HasResources", new Type[]
{
typeof(int),
typeof(int),
typeof(List<NetworkInventorySlot>)
})]
public static bool Prefix_HasResourcesId(ref bool __result, int resId, int count, List<NetworkInventorySlot> deltas)
{
deltas?.Clear();
__result = true;
return false;
}
}
[HarmonyPatch(typeof(InventoryWrapper))]
public static class InventoryWrapperPatch
{
[HarmonyPrefix]
[HarmonyPatch("HasResources", new Type[]
{
typeof(ResourceInfo),
typeof(int)
})]
public static bool Prefix_HasResourcesInfoWrapper(ref bool __result)
{
__result = true;
return false;
}
[HarmonyPrefix]
[HarmonyPatch("HasResources", new Type[]
{
typeof(int),
typeof(int),
typeof(List<NetworkInventorySlot>)
})]
public static bool Prefix_HasResourcesIdWrapper(ref bool __result, int resId, int count, List<NetworkInventorySlot> deltas)
{
deltas?.Clear();
__result = true;
return false;
}
}
[HarmonyPatch(typeof(GameDefines))]
public static class GameDefinesPatch
{
[HarmonyPrefix]
[HarmonyPatch("IsResourceFreeToCraft", new Type[] { typeof(int) })]
public static bool Prefix_IsResourceFreeToCraft(ref bool __result)
{
__result = true;
return false;
}
[HarmonyPrefix]
[HarmonyPatch("IsResourceFreelyUnlocked", new Type[] { typeof(int) })]
public static bool Prefix_IsResourceFreelyUnlocked(ref bool __result)
{
__result = true;
return false;
}
}
[HarmonyPatch(typeof(GameDefines))]
public static class FreeRecipesPatch
{
[HarmonyPrefix]
[HarmonyPatch("IsRecipeFreelyUnlocked", new Type[] { typeof(int) })]
public static bool Prefix_IsRecipeFreelyUnlocked(ref bool __result)
{
__result = true;
return false;
}
}