using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using ControlValley;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyTestMod;
using Microsoft.CodeAnalysis;
using ReservedItemSlotCore;
using ReservedItemSlotCore.Data;
using Unity.Netcode;
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: AssemblyCompany("Cera CCPack Patches")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+381f5ac173659b0d65c6f1a752432f7757651c7a")]
[assembly: AssemblyProduct("Cera CCPack Patches")]
[assembly: AssemblyTitle("Cera CCPack Patches")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace Cera_CCPack_Patches
{
public static class PluginInfo
{
public const string PLUGIN_NAME = "Cera's CCPack Patches";
public const string PLUGIN_GUID = "ceradona.ccpackpatches";
public const string PLUGIN_VERSION = "0.0.1";
}
[BepInPlugin("ceradona.ccpackpatches", "Cera's CCPack Patches", "0.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource PluginLogger { get; private protected set; }
private void Awake()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
PluginLogger = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Awake, attempting to patch!");
Harmony val = new Harmony("ceradona.ccpackpatches");
try
{
val.PatchAll(typeof(TimeOfDayPatch));
((BaseUnityPlugin)this).Logger.Log((LogLevel)16, (object)"TimeOfDayPatch");
if (Chainloader.PluginInfos.ContainsKey("FlipMods.ReservedItemSlotCore"))
{
val.PatchAll(typeof(ReservedItemSlotPatch));
((BaseUnityPlugin)this).Logger.Log((LogLevel)16, (object)"ReservedItemSlotPatch");
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"Patched successfully!");
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Failed to patch: " + ex));
}
}
}
public static class Reflectors
{
public static void CallStaticNonPublic(Assembly assembly, string type, string func, object[] vals)
{
assembly.GetType(type).GetMethod(func, BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, vals);
}
public static void CallStaticNonPublic(Type type, string func, object[] vals)
{
type.GetMethod(func, BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, vals);
}
}
public class ReservedItemSlotPatch
{
public static Dictionary<string, string> ItemNameTransforms = new Dictionary<string, string>
{
{ "flashlight", "Flashlight" },
{ "proflashlight", "Pro-flashlight" },
{ "walkietalkie", "Walkie-talkie" }
};
[HarmonyPostfix]
[HarmonyPatch(typeof(CrowdDelegates), "GiveItem")]
public static void GiveItem(ControlClient client, CrowdRequest req, ref CrowdResponse __result)
{
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Expected O, but got Unknown
if (__result.status != 3)
{
return;
}
string item = req.code.Split(new char[1] { '_' })[1];
Plugin.PluginLogger.LogInfo((object)("Give effect retrying, checking for reserved item slot for " + item + " first."));
int giveId = StartOfRound.Instance.allItemsList.itemsList.IndexOf(StartOfRound.Instance.allItemsList.itemsList.Find((Item z) => ((Object)z).name.ToLower().Equals(item.ToLower())));
if (!ReservedPlayerData.localPlayerData.HasEmptySlotForReservedItem(ItemNameTransforms[item]))
{
return;
}
Plugin.PluginLogger.LogInfo((object)"Give effect can target reserved slot, trying to do so.");
ReservedPlayerData localPlayer = ReservedPlayerData.localPlayerData;
PlayerControllerB playerController = localPlayer.playerController;
TestMod.ActionQueue.Enqueue(delegate
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: Unknown result type (might be due to invalid IL or missing references)
//IL_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_025c: Expected O, but got Unknown
Object.FindObjectOfType<Terminal>();
GameObject obj = Object.Instantiate<GameObject>(StartOfRound.Instance.allItemsList.itemsList[giveId].spawnPrefab, ((Component)localPlayer.playerController).transform.position, Quaternion.identity, TestMod.currentStart.propsContainer);
GrabbableObject component = obj.GetComponent<GrabbableObject>();
component.fallTime = 0f;
component.SetScrapValue(component.scrapValue = Random.Range(0, 100));
obj.GetComponent<NetworkObject>().Spawn(false);
GrabbableObject component2 = obj.GetComponent<GrabbableObject>();
CrowdDelegates.setProperty((object)playerController, "currentlyGrabbingObject", (object)component2);
NetworkObject networkObject = ((NetworkBehaviour)component2).NetworkObject;
if (networkObject != null && networkObject.IsSpawned)
{
component2.InteractItem();
playerController.playerBodyAnimator.SetBool("GrabInvalidated", false);
playerController.playerBodyAnimator.SetBool("GrabValidated", true);
playerController.playerBodyAnimator.SetBool("cancelHolding", false);
playerController.playerBodyAnimator.ResetTrigger("Throw");
playerController.playerBodyAnimator.ResetTrigger("SwitchHoldAnimation");
playerController.playerBodyAnimator.ResetTrigger("SwitchHoldAnimationTwoHanded");
ReservedItemData grabbingReservedItemData = default(ReservedItemData);
SessionManager.TryGetUnlockedItemData(component, ref grabbingReservedItemData);
localPlayer.grabbingReservedItemData = grabbingReservedItemData;
localPlayer.grabbingReservedItem = component;
localPlayer.previousHotbarIndex = Mathf.Clamp(localPlayer.currentItemSlot, 0, localPlayer.itemSlots.Length - 1);
if ((Object)(object)localPlayer.previouslyHeldItem != (Object)null)
{
playerController.playerBodyAnimator.ResetTrigger(localPlayer.previouslyHeldItem.itemProperties.pocketAnim);
}
playerController.twoHanded = (Object)(object)localPlayer.previouslyHeldItem != (Object)null && localPlayer.previouslyHeldItem.itemProperties.twoHanded;
playerController.twoHandedAnimation = (Object)(object)localPlayer.previouslyHeldItem != (Object)null && localPlayer.previouslyHeldItem.itemProperties.twoHandedAnimation;
CrowdDelegates.callFunc((object)playerController, "GrabObjectServerRpc", (object)new NetworkObjectReference(networkObject));
Coroutine val = (Coroutine)CrowdDelegates.getProperty((object)playerController, "grabObjectCoroutine");
if (val != null)
{
((MonoBehaviour)playerController).StopCoroutine(val);
}
CrowdDelegates.setProperty((object)playerController, "grabObjectCoroutine", (object)((MonoBehaviour)playerController).StartCoroutine("GrabObject"));
}
});
__result = new CrowdResponse(req.GetReqID(), (Status)0, "");
}
}
[HarmonyPatch]
public class TimeOfDayPatch
{
[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
[HarmonyPatch(typeof(TimeOfDay), "RoundUpToNearestTen")]
public static int RoundUpToNearestTen(object instance, float x)
{
return 0;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(TimeOfDay), "SyncGlobalTimeOnNetwork")]
public static void SyncGlobalTimeOnNetwork(TimeOfDay __instance, ref float ___nextTimeSync)
{
if (((NetworkBehaviour)__instance).IsServer && ___nextTimeSync - (float)RoundUpToNearestTen(__instance, __instance.globalTime) > 15f)
{
Plugin.PluginLogger.LogInfo((object)"Had to enforce a time sync due to rollback!");
___nextTimeSync = RoundUpToNearestTen(__instance, __instance.globalTime + 10f);
__instance.SyncTimeClientRpc(__instance.globalTime, (int)__instance.timeUntilDeadline);
}
}
}
}