using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BetterStoneHarvest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterStoneHarvest")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3d92cc92-c772-450b-9b6e-d511fab9b467")]
[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.lan.BetterStoneHarvest", "更好的挖矿收获", "1.2.2")]
public class BetterStoneHarvest : BaseUnityPlugin
{
private void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
Harmony val = new Harmony("com.lan.BetterStoneHarvest");
val.PatchAll(typeof(HarvestablePatch));
val.PatchAll(typeof(BetterStoneHarvest));
Debug.LogWarning((object)"更好的挖矿收获 --作者:她说缝上都不给我");
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Resource), "CheckIfHarvestedServer")]
private static void PostfixResetHealth(Resource __instance)
{
if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.outputItem == (Object)null) && ((NetworkBehaviour)__instance).IsOwner && (__instance.outputItem.itemName.Contains("stone") || __instance.outputItem.itemName.Contains("marble")))
{
((Harvestable)__instance).health = 1;
((Harvestable)__instance).ResetHealth();
}
}
}
[HarmonyPatch]
public static class HarvestablePatch
{
[HarmonyPrefix]
[HarmonyPatch(typeof(Resource), "SpawnResourcesServer")]
public static bool PrefixSpawnResourcesServer(Resource __instance)
{
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__instance == (Object)null)
{
return true;
}
if ((Object)(object)__instance.outputItem == (Object)null || __instance.outputItem.itemName == null)
{
return true;
}
if (!__instance.outputItem.itemName.Contains("stone") && !__instance.outputItem.itemName.Contains("marble"))
{
return true;
}
if (!((NetworkBehaviour)__instance).IsServer)
{
return true;
}
FieldInfo fieldInfo = AccessTools.Field(typeof(Resource), "isHarvested");
FieldInfo fieldInfo2 = AccessTools.Field(typeof(Resource), "id");
if (fieldInfo2 == null)
{
return true;
}
NetworkVariable<bool> val = (NetworkVariable<bool>)fieldInfo.GetValue(__instance);
if (val == null)
{
return true;
}
string text = (string)fieldInfo2.GetValue(__instance);
if (val.Value)
{
return true;
}
val.Value = true;
GameManager.Instance.AddToNewHarvestedResources(text, GameManager.Instance.GetCurrentDayRaw());
if ((Object)(object)NetworkManager.Singleton == (Object)null || (Object)(object)NetworkManager.Singleton.LocalClient.PlayerObject == (Object)null)
{
return true;
}
NetworkObject playerObject = NetworkManager.Singleton.ConnectedClients[default(ServerRpcParams).Receive.SenderClientId].PlayerObject;
PlayerInventory component = ((Component)playerObject).GetComponent<PlayerInventory>();
for (int i = 0; i <= __instance.amount; i++)
{
component.GiveItemServerRpc(__instance.outputItem.id, 1, 0, 0);
}
return false;
}
}