using System;
using System.Collections;
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 GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[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("BuffedPresents")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2a84449dc2aca632c0a1f5b1eaa8758ff32eb579")]
[assembly: AssemblyProduct("BuffedPresents")]
[assembly: AssemblyTitle("BuffedPresents")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 BuffedPresents
{
public static class PluginInfo
{
public const string PLUGIN_GUID = "BuffedPresents";
public const string PLUGIN_NAME = "BuffedPresents";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace com.redcrowbar.buffedpresents
{
internal static class AccessExtensions
{
public static ManualLogSource ExtLogger = Logger.CreateLogSource("AccessExtentions");
public static object CallMethod(this object o, string methodName, params object[] args)
{
MethodInfo method = o.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic);
if (method != null)
{
ExtLogger.LogDebug((object)("Calling nonpublic method: " + methodName));
return method.Invoke(o, args);
}
ExtLogger.LogError((object)("Couldn't call nonpublic method: " + methodName));
return null;
}
public static T GetFieldValue<T>(object instance, string fieldName)
{
FieldInfo field = instance.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
if (field != null)
{
T val = (T)field.GetValue(instance);
ExtLogger.LogDebug((object)$"GetFieldValue: Field '{fieldName}' exists, returning {val}");
return val;
}
ExtLogger.LogError((object)("GetFieldValue: Field '" + fieldName + "' not found!"));
return default(T);
}
public static void SetFieldValue(object instance, string fieldName, object value)
{
FieldInfo field = instance.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
if (field != null)
{
field.SetValue(instance, value);
ExtLogger.LogDebug((object)$"SetFieldValue: Field '{fieldName}' exists, setting {value}");
}
else
{
ExtLogger.LogError((object)("SetFieldValue: Field '" + fieldName + "' not found."));
}
}
}
[BepInPlugin("com.redcrowbar.buffedpresents", "Buffed Presents", "0.0.5")]
[BepInIncompatibility("GiftBoxRevert")]
[BepInIncompatibility("LethalPresents")]
[BepInIncompatibility("ExplodingPresents")]
public class BuffedPresents : BaseUnityPlugin
{
public static ManualLogSource BPLogger = Logger.CreateLogSource("BuffedPresents");
public static BuffedPresents Instance;
public static ConfigEntry<bool> isEnabled;
public static ConfigEntry<float> buyableItemChance;
public static ConfigEntry<float> minValueMultiply;
public static ConfigEntry<float> maxValueMultiply;
public const string mainConfigDesc = "Settings (only HOST controls these)";
public const ushort targetGameVersion = 49;
public static bool versionWarning = true;
public static bool isDebugBuild = false;
public bool IsDebugBuild()
{
return isDebugBuild;
}
private void Awake()
{
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Expected O, but got Unknown
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Expected O, but got Unknown
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Expected O, but got Unknown
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
isEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings (only HOST controls these)", "Enabled", true, "Enable/disable the plugin");
buyableItemChance = ((BaseUnityPlugin)this).Config.Bind<float>("Settings (only HOST controls these)", "Percent chance present is a random buyable item", 50f, new ConfigDescription("The minimum multiplier to add to a present's value", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
minValueMultiply = ((BaseUnityPlugin)this).Config.Bind<float>("Settings (only HOST controls these)", "Min present value multiplier", 3f, new ConfigDescription("The min multiplier to add to a present's value, example: orig-value:50 x Multiplier 1.5 = new-value:75", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>()));
maxValueMultiply = ((BaseUnityPlugin)this).Config.Bind<float>("Settings (only HOST controls these)", "Max present value multiplier", 6f, new ConfigDescription("The max multiplier to add to a present's value, example: orig-value:50 x Multiplier 1.5 = new-value:75", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>()));
if (isEnabled.Value)
{
new Harmony("com.redcrowbar.buffedpresents").PatchAll(typeof(GiftBoxPatch));
}
}
private void Update()
{
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)HUDManager.Instance) || !isEnabled.Value)
{
return;
}
if (versionWarning && ((Component)GameNetworkManager.Instance).GetComponent<NetworkManager>().NetworkConfig.ProtocolVersion != 49)
{
BPLogger.LogWarning((object)$"WARNING: Game version is {((Component)GameNetworkManager.Instance).GetComponent<NetworkManager>().NetworkConfig.ProtocolVersion}, expected {(ushort)49}. You may encounter issues!");
versionWarning = false;
}
if (!IsDebugBuild() || StartOfRound.Instance.inShipPhase || !((ButtonControl)Keyboard.current.f8Key).wasPressedThisFrame)
{
return;
}
foreach (SpawnableItemWithRarity item in RoundManager.Instance.currentLevel.spawnableScrap)
{
if (item.spawnableItem.itemName.Contains("Gift"))
{
BPLogger.LogDebug((object)"Found GiftBox");
Transform spawnedScrapContainer = RoundManager.Instance.spawnedScrapContainer;
PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
Vector3 val = ((Component)localPlayerController).transform.position + ((Component)localPlayerController).transform.forward * 0.5f + Vector3.up * 0.5f;
((NetworkBehaviour)Object.Instantiate<GameObject>(item.spawnableItem.spawnPrefab, val, Quaternion.identity, spawnedScrapContainer).GetComponent<GiftBoxItem>()).NetworkObject.Spawn(false);
break;
}
}
}
}
public class GiftBoxPatch
{
public enum RpcExecStage
{
None,
Server,
Client
}
public static ManualLogSource PatchLogger = Logger.CreateLogSource("BuffedPresentsPatches");
public static bool CheckChance()
{
if (Mathf.Clamp(BuffedPresents.buyableItemChance.Value, 0f, 100f) / 100f > Random.Range(0f, 0.99f))
{
return true;
}
return false;
}
public static IEnumerator SetObjectToHitGroundSFX(GrabbableObject gObject)
{
yield return (object)new WaitForEndOfFrame();
PatchLogger.LogDebug((object)("Setting " + gObject.itemProperties.itemName + " hit ground to false"));
gObject.reachedFloorTarget = false;
gObject.hasHitGround = false;
gObject.fallTime = 0f;
}
[HarmonyPatch(typeof(GiftBoxItem), "OpenGiftBoxServerRpc")]
[HarmonyPrefix]
public static bool PrefixRpc(GiftBoxItem __instance)
{
//IL_029d: Unknown result type (might be due to invalid IL or missing references)
//IL_02be: Unknown result type (might be due to invalid IL or missing references)
//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
//IL_0300: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_0392: Unknown result type (might be due to invalid IL or missing references)
//IL_0397: Unknown result type (might be due to invalid IL or missing references)
//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0417: Unknown result type (might be due to invalid IL or missing references)
//IL_041c: Unknown result type (might be due to invalid IL or missing references)
//IL_0421: Unknown result type (might be due to invalid IL or missing references)
//IL_024d: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_0463: Unknown result type (might be due to invalid IL or missing references)
//IL_0469: Unknown result type (might be due to invalid IL or missing references)
if (!CheckChance())
{
NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
if (networkManager == null || !networkManager.IsListening)
{
return false;
}
if (AccessExtensions.GetFieldValue<RpcExecStage>(__instance, "__rpc_exec_stage") != RpcExecStage.Server && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = (FastBufferWriter)__instance.CallMethod("__beginSendServerRpc", 2878544999u, val, (object)(RpcDelivery)0);
__instance.CallMethod("__endSendServerRpc", val2, 2878544999u, val, (object)(RpcDelivery)0);
}
if (AccessExtensions.GetFieldValue<RpcExecStage>(__instance, "__rpc_exec_stage") != RpcExecStage.Server || (!networkManager.IsServer && !networkManager.IsHost))
{
return false;
}
GameObject val3 = null;
int num = 0;
Vector3 val4 = Vector3.zero;
if ((Object)(object)AccessExtensions.GetFieldValue<GameObject>(__instance, "objectInPresent") == (Object)null)
{
PatchLogger.LogError((object)"Error: There is no object in gift box!");
}
else
{
Transform val5 = ((((!((Object)(object)((GrabbableObject)__instance).playerHeldBy != (Object)null) || !((GrabbableObject)__instance).playerHeldBy.isInElevator) && !StartOfRound.Instance.inShipPhase) || !((Object)(object)RoundManager.Instance.spawnedScrapContainer != (Object)null)) ? StartOfRound.Instance.elevatorTransform : RoundManager.Instance.spawnedScrapContainer);
val4 = ((Component)__instance).transform.position + Vector3.up * 0.25f;
val3 = Object.Instantiate<GameObject>(AccessExtensions.GetFieldValue<GameObject>(__instance, "objectInPresent"), val4, Quaternion.identity, val5);
GrabbableObject component = val3.GetComponent<GrabbableObject>();
PlayerControllerB fieldValue = AccessExtensions.GetFieldValue<PlayerControllerB>(__instance, "previousPlayerHeldBy");
component.startFallingPosition = val4;
((MonoBehaviour)__instance).StartCoroutine(SetObjectToHitGroundSFX(component));
component.targetFloorPosition = component.GetItemFloorPosition(((Component)__instance).transform.position);
if ((Object)(object)fieldValue != (Object)null && fieldValue.isInHangarShipRoom)
{
fieldValue.SetItemInElevator(true, true, component);
}
num = AccessExtensions.GetFieldValue<int>(__instance, "objectInPresentValue");
num = Mathf.RoundToInt(Random.Range(BuffedPresents.minValueMultiply.Value, BuffedPresents.maxValueMultiply.Value) * (float)num);
component.SetScrapValue(num);
((NetworkBehaviour)component).NetworkObject.Spawn(false);
}
if ((Object)(object)val3 != (Object)null)
{
__instance.OpenGiftBoxClientRpc(NetworkObjectReference.op_Implicit(val3.GetComponent<NetworkObject>()), num, val4);
}
__instance.OpenGiftBoxNoPresentClientRpc();
return false;
}
NetworkManager networkManager2 = ((NetworkBehaviour)__instance).NetworkManager;
if (networkManager2 == null || !networkManager2.IsListening)
{
return false;
}
if (AccessExtensions.GetFieldValue<RpcExecStage>(__instance, "__rpc_exec_stage") != RpcExecStage.Server && (networkManager2.IsClient || networkManager2.IsHost))
{
ServerRpcParams val6 = default(ServerRpcParams);
FastBufferWriter val7 = (FastBufferWriter)__instance.CallMethod("__beginSendServerRpc", 2878544999u, val6, (object)(RpcDelivery)0);
__instance.CallMethod("__endSendServerRpc", val7, 2878544999u, val6, (object)(RpcDelivery)0);
}
if (AccessExtensions.GetFieldValue<RpcExecStage>(__instance, "__rpc_exec_stage") != RpcExecStage.Server || (!networkManager2.IsServer && !networkManager2.IsHost))
{
return false;
}
Transform val8 = ((((!((Object)(object)((GrabbableObject)__instance).playerHeldBy != (Object)null) || !((GrabbableObject)__instance).playerHeldBy.isInElevator) && !StartOfRound.Instance.inShipPhase) || !((Object)(object)RoundManager.Instance.spawnedScrapContainer != (Object)null)) ? StartOfRound.Instance.elevatorTransform : RoundManager.Instance.spawnedScrapContainer);
Vector3 val9 = ((Component)__instance).transform.position + Vector3.up * 0.25f;
Terminal val10 = Object.FindObjectOfType<Terminal>();
GameObject val11 = Object.Instantiate<GameObject>(val10.buyableItemsList[Random.Range(0, val10.buyableItemsList.Length)].spawnPrefab, val9, Quaternion.identity, val8);
GrabbableObject component2 = val11.GetComponent<GrabbableObject>();
PlayerControllerB fieldValue2 = AccessExtensions.GetFieldValue<PlayerControllerB>(__instance, "previousPlayerHeldBy");
component2.startFallingPosition = val9;
((MonoBehaviour)__instance).StartCoroutine(SetObjectToHitGroundSFX(component2));
component2.targetFloorPosition = component2.GetItemFloorPosition(((Component)__instance).transform.position);
if ((Object)(object)fieldValue2 != (Object)null && fieldValue2.isInHangarShipRoom)
{
fieldValue2.SetItemInElevator(true, true, component2);
}
((NetworkBehaviour)component2).NetworkObject.Spawn(false);
if ((Object)(object)val11 != (Object)null)
{
__instance.OpenGiftBoxClientRpc(NetworkObjectReference.op_Implicit(val11.GetComponent<NetworkObject>()), 0, val9);
}
__instance.OpenGiftBoxNoPresentClientRpc();
return false;
}
}
}