using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("WeedKillerFixes")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Fixes some major issues with weed killer")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+6460b95f64a34da825901c137ae0f252bcb89b13")]
[assembly: AssemblyProduct("WeedKillerFixes")]
[assembly: AssemblyTitle("WeedKillerFixes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace WeedKillerFixes
{
[BepInPlugin("butterystancakes.lethalcompany.weedkillerfixes", "Weed Killer Fixes", "1.1.1")]
public class Plugin : BaseUnityPlugin
{
private const string PLUGIN_GUID = "butterystancakes.lethalcompany.weedkillerfixes";
private const string PLUGIN_NAME = "Weed Killer Fixes";
private const string PLUGIN_VERSION = "1.1.1";
internal static ManualLogSource Logger;
private void Awake()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
new Harmony("butterystancakes.lethalcompany.weedkillerfixes").PatchAll();
Logger.LogInfo((object)"Weed Killer Fixes v1.1.1 loaded");
}
}
[HarmonyPatch]
internal class WeedKillerFixesPatches
{
private static MoldSpreadManager moldSpreadManager;
private static VehicleController vehicleController;
private static readonly MethodInfo MOLD_SPREAD_MANAGER_INSTANCE = AccessTools.DeclaredPropertyGetter(typeof(WeedKillerFixesPatches), "MoldSpreadManager");
private static readonly FieldInfo VEHICLE_CONTROLLER_INSTANCE = AccessTools.Field(typeof(WeedKillerFixesPatches), "vehicleController");
private static MoldSpreadManager MoldSpreadManager
{
get
{
if ((Object)(object)moldSpreadManager == (Object)null)
{
moldSpreadManager = Object.FindAnyObjectByType<MoldSpreadManager>();
}
return moldSpreadManager;
}
}
[HarmonyPatch(typeof(SprayPaintItem), "TrySprayingWeedKillerBottle")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> SprayPaintItem_Trans_TrySprayingWeedKillerBottle(IEnumerable<CodeInstruction> instructions)
{
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Expected O, but got Unknown
List<CodeInstruction> list = instructions.ToList();
MethodInfo methodInfo = AccessTools.Method(typeof(GameObject), "CompareTag", (Type[])null, (Type[])null);
MethodInfo methodInfo2 = AccessTools.DeclaredPropertyGetter(typeof(Time), "deltaTime");
for (int i = 2; i < list.Count - 3; i++)
{
if (list[i].opcode == OpCodes.Call)
{
string text = list[i].operand.ToString();
if (text.Contains("Raycast") && list[i - 2].opcode == OpCodes.Ldc_I4)
{
list[i - 2].operand = (int)list[i - 2].operand & ~(1 << LayerMask.NameToLayer("Room"));
Plugin.Logger.LogDebug((object)"Transpiler (SprayPaintItem.TrySprayingWeedKillerBottle): Simplify layer mask");
}
else if ((MethodInfo)list[i].operand == methodInfo2)
{
list[i].opcode = OpCodes.Ldfld;
list[i].operand = AccessTools.Field(typeof(SprayPaintItem), "sprayIntervalSpeed");
list.Insert(i, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
Plugin.Logger.LogDebug((object)"Transpiler (SprayPaintItem.TrySprayingWeedKillerBottle): Fix addVehicleHPInterval time");
}
else if (text.Contains("VehicleController"))
{
list[i].opcode = OpCodes.Ldsfld;
list[i].operand = VEHICLE_CONTROLLER_INSTANCE;
Plugin.Logger.LogDebug((object)"Transpiler (SprayPaintItem.TrySprayingWeedKillerBottle): Cache Cruiser script");
}
}
else if (list[i].opcode == OpCodes.Ldstr && (string)list[i].operand == "MoldSporeCollider" && list[i + 1].opcode == OpCodes.Callvirt && (MethodInfo)list[i + 1].operand == methodInfo)
{
list[i].operand = "MoldSpore";
Plugin.Logger.LogDebug((object)"Transpiler (SprayPaintItem.TrySprayingWeedKillerBottle): Fix wrong tag being checked");
}
}
return list;
}
[HarmonyPatch(typeof(SprayPaintItem), "KillWeedClientRpc")]
[HarmonyPatch(typeof(SprayPaintItem), "LateUpdate")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> CacheMoldSpreadManager(IEnumerable<CodeInstruction> instructions, MethodBase __originalMethod)
{
List<CodeInstruction> list = instructions.ToList();
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Call)
{
string text = list[i].operand.ToString();
if (text.Contains("FindObjectOfType") && text.Contains("MoldSpreadManager"))
{
list[i].operand = MOLD_SPREAD_MANAGER_INSTANCE;
Plugin.Logger.LogDebug((object)$"Transpiler ({__originalMethod.DeclaringType}.{__originalMethod.Name}): Cache weed script");
}
}
}
return instructions;
}
[HarmonyPatch(typeof(VehicleController), "Awake")]
[HarmonyPostfix]
private static void VehicleController_Post_Awake(VehicleController __instance)
{
if ((Object)(object)vehicleController == (Object)null)
{
vehicleController = __instance;
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "WeedKillerFixes";
public const string PLUGIN_NAME = "WeedKillerFixes";
public const string PLUGIN_VERSION = "1.1.1";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}