using System;
using System.Collections.Generic;
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 EnemyValuableTweaks;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Unity.VisualScripting;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("BLOKBUSTR")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+8e5ab2dea6ee7e7b545f65f6a305000ef3b5faf4")]
[assembly: AssemblyProduct("EnemyValuableTweaks")]
[assembly: AssemblyTitle("EnemyValuableTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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.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;
}
}
[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;
}
}
}
public class EnemyValuableSynchronizer : MonoBehaviourPun
{
public EnemyValuable enemyValuable;
public PhotonView photonView;
public void SetExplosion(bool state)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
if (!SemiFunc.IsNotMasterClient())
{
if (!SemiFunc.IsMultiplayer())
{
SetExplosionRPC(state);
global::EnemyValuableTweaks.EnemyValuableTweaks.LogDebugGeneral($"Set hasExplosion = {state}");
}
else
{
photonView.RPC("SetExplosionRPC", (RpcTarget)0, new object[1] { state });
global::EnemyValuableTweaks.EnemyValuableTweaks.LogDebugGeneral($"Called SetExplosionRPC on clients (hasExplosion = {state})");
}
}
}
[PunRPC]
public void SetExplosionRPC(bool state, PhotonMessageInfo info = default(PhotonMessageInfo))
{
enemyValuable.hasExplosion = state;
global::EnemyValuableTweaks.EnemyValuableTweaks.LogDebugGeneral($"Received SetExplosionRPC from host (hasExplosion = {state})");
}
}
namespace EnemyValuableTweaks
{
[HarmonyPatch(typeof(EnemyValuable))]
internal static class EnemyValuablePatch
{
private static readonly Dictionary<object, float> OrbAdditionalCheckDelay = new Dictionary<object, float>();
private static readonly Dictionary<object, float> OrbGrabTimers = new Dictionary<object, float>();
private static readonly Dictionary<object, float> OrbSafeAreaTimers = new Dictionary<object, float>();
[HarmonyPostfix]
[HarmonyPatch("Start")]
public static void StartPostfix(EnemyValuable __instance)
{
EnemyValuableTweaks.Logger.LogInfo((object)$"New EnemyValuable has spawned (InstanceID {((Object)__instance).GetInstanceID()} | ViewID {__instance.impactDetector.photonView.ViewID})");
__instance.indestructibleTimer = EnemyValuableTweaks.configTimerLength.Value;
EnemyValuableSynchronizer enemyValuableSynchronizer = ComponentHolderProtocol.AddComponent<EnemyValuableSynchronizer>((Object)(object)__instance);
enemyValuableSynchronizer.enemyValuable = __instance;
enemyValuableSynchronizer.photonView = __instance.impactDetector.photonView;
}
[HarmonyPostfix]
[HarmonyPatch("Update")]
public static void UpdatePostfix(EnemyValuable __instance)
{
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_0196: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
if (__instance.indestructibleTimer < 0f)
{
MakeDestructible(__instance);
}
if (!__instance.impactDetector.destroyDisable)
{
return;
}
if (!EnemyValuableTweaks.configEnableTimer.Value)
{
__instance.indestructibleTimer = 60f;
}
else
{
EnemyValuableTweaks.LogDebugTimers($"Time remaining: {__instance.indestructibleTimer}");
}
if (EnemyValuableTweaks.configAdditionalChecksDelay.Value > 0f)
{
if (!OrbAdditionalCheckDelay.ContainsKey(__instance))
{
OrbAdditionalCheckDelay[__instance] = EnemyValuableTweaks.configAdditionalChecksDelay.Value;
}
if (OrbAdditionalCheckDelay[__instance] > 0f)
{
OrbAdditionalCheckDelay[__instance] -= Time.deltaTime;
EnemyValuableTweaks.LogDebugTimers($"Delaying additional checks for: {OrbAdditionalCheckDelay[__instance]} ({((Object)__instance).GetInstanceID()})");
return;
}
}
if (EnemyValuableTweaks.configEnableVelocityCheck.Value)
{
Vector3 velocity = __instance.impactDetector.rb.velocity;
Vector3 previousVelocity = __instance.impactDetector.previousVelocity;
float num = Mathf.Max(new float[6]
{
Mathf.Abs(velocity.x),
Mathf.Abs(velocity.y),
Mathf.Abs(velocity.z),
Mathf.Abs(previousVelocity.x),
Mathf.Abs(previousVelocity.y),
Mathf.Abs(previousVelocity.z)
});
EnemyValuableTweaks.LogDebugTimers($"curVel: {velocity} | prevVel: {previousVelocity} | combined: {num}");
if (num < EnemyValuableTweaks.configVelocityThreshold.Value)
{
MakeDestructible(__instance);
return;
}
}
if (EnemyValuableTweaks.configEnablePlayerHold.Value)
{
if (__instance.impactDetector.physGrabObject.playerGrabbing.Count > 0)
{
if (EnemyValuableTweaks.configPlayerHoldTime.Value == 0f)
{
MakeDestructible(__instance);
return;
}
if (!OrbGrabTimers.ContainsKey(__instance))
{
OrbGrabTimers[__instance] = EnemyValuableTweaks.configPlayerHoldTime.Value;
EnemyValuableTweaks.LogDebugTimers($"Player grabbed ({((Object)__instance).GetInstanceID()})");
}
HandleTimerDictionaries(OrbGrabTimers, __instance);
}
else if (OrbGrabTimers.Remove(__instance))
{
EnemyValuableTweaks.LogDebugTimers($"Player let go ({((Object)__instance).GetInstanceID()})");
}
}
if (!EnemyValuableTweaks.configEnableSafeAreaCheck.Value)
{
return;
}
if (__instance.impactDetector.inCart)
{
if (EnemyValuableTweaks.configSafeAreaTime.Value == 0f)
{
MakeDestructible(__instance);
return;
}
if (!OrbSafeAreaTimers.ContainsKey(__instance))
{
OrbSafeAreaTimers[__instance] = EnemyValuableTweaks.configSafeAreaTime.Value;
EnemyValuableTweaks.LogDebugTimers($"Placed in safe area ({((Object)__instance).GetInstanceID()})");
}
HandleTimerDictionaries(OrbSafeAreaTimers, __instance);
}
else if (OrbSafeAreaTimers.Remove(__instance))
{
EnemyValuableTweaks.LogDebugTimers($"Removed from safe area ({((Object)__instance).GetInstanceID()})");
}
}
private static void HandleTimerDictionaries(Dictionary<object, float> d, EnemyValuable i)
{
EnemyValuableTweaks.LogDebugTimers($"Dictionary time remaining: {d[i]} {((Object)i).GetInstanceID()}");
d[i] -= Time.deltaTime;
if (d[i] <= 0f)
{
MakeDestructible(i);
d.Remove(i);
}
}
private static void MakeDestructible(EnemyValuable i)
{
i.indestructibleTimer = 0f;
i.impactDetector.destroyDisable = false;
OrbAdditionalCheckDelay.Remove(i);
EnemyValuableTweaks.Logger.LogInfo((object)$"Made EnemyValuable destructible (InstanceID {((Object)i).GetInstanceID()} | ViewID {i.impactDetector.photonView.ViewID})");
if (SemiFunc.IsNotMasterClient())
{
EnemyValuableTweaks.LogDebugGeneral("Is client, skipping probability calculations");
return;
}
EnemyValuableTweaks.LogDebugGeneral("Is host or singleplayer, calculating probability and sending to clients if multiplayer");
EnemyValuableSynchronizer component = ((Component)i).GetComponent<EnemyValuableSynchronizer>();
if ((Object)(object)component == (Object)null)
{
EnemyValuableTweaks.Logger.LogError((object)"EnemyValuableSynchronizer component not found!");
return;
}
float num = ((SemiFunc.MoonLevel() > 3) ? EnemyValuableTweaks.configSuperMoonExplosionProbability.Value : ((SemiFunc.MoonLevel() > 2) ? EnemyValuableTweaks.configFullMoonExplosionProbability.Value : ((SemiFunc.MoonLevel() > 1) ? EnemyValuableTweaks.configHalfMoonExplosionProbability.Value : ((SemiFunc.MoonLevel() <= 0) ? EnemyValuableTweaks.configInitialExplosionProbability.Value : EnemyValuableTweaks.configCrescentMoonExplosionProbability.Value))));
float num2 = num;
float num3 = num2;
if (!(num3 <= 0f))
{
if (num3 >= 1f)
{
component.SetExplosion(state: true);
EnemyValuableTweaks.LogDebugGeneral("Probability is 1, EnemyValuable will always explode");
return;
}
double num4 = new Random().NextDouble();
component.SetExplosion(num4 < (double)num);
EnemyValuableTweaks.LogDebugGeneral($"MoonLevel: {SemiFunc.MoonLevel()} | rng: {num4} | probability: {num} | hasExplosion: {i.hasExplosion}");
}
else
{
component.SetExplosion(state: false);
EnemyValuableTweaks.LogDebugGeneral("Probability is 0, EnemyValuable will never explode");
}
}
}
[BepInPlugin("BLOKBUSTR.EnemyValuableTweaks", "EnemyValuableTweaks", "1.0.3")]
public class EnemyValuableTweaks : BaseUnityPlugin
{
public static ConfigEntry<bool> configEnableTimer;
public static ConfigEntry<float> configTimerLength;
public static ConfigEntry<float> configAdditionalChecksDelay;
public static ConfigEntry<bool> configEnableVelocityCheck;
public static ConfigEntry<float> configVelocityThreshold;
public static ConfigEntry<bool> configEnablePlayerHold;
public static ConfigEntry<float> configPlayerHoldTime;
public static ConfigEntry<bool> configEnableSafeAreaCheck;
public static ConfigEntry<float> configSafeAreaTime;
public static ConfigEntry<float> configInitialExplosionProbability;
public static ConfigEntry<float> configCrescentMoonExplosionProbability;
public static ConfigEntry<float> configHalfMoonExplosionProbability;
public static ConfigEntry<float> configFullMoonExplosionProbability;
public static ConfigEntry<float> configSuperMoonExplosionProbability;
private static ConfigEntry<bool> _configEnableDebugTimerLogs;
private static ConfigEntry<bool> _configEnableDebugGeneralLogs;
internal static EnemyValuableTweaks Instance { get; private set; }
internal static ManualLogSource Logger => Instance._logger;
private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;
internal Harmony? Harmony { get; set; }
private void Awake()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Expected O, but got Unknown
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Expected O, but got Unknown
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Expected O, but got Unknown
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Expected O, but got Unknown
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Expected O, but got Unknown
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Expected O, but got Unknown
//IL_0192: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: Expected O, but got Unknown
//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
//IL_01d9: Expected O, but got Unknown
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_0216: Expected O, but got Unknown
//IL_0249: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Expected O, but got Unknown
//IL_0286: Unknown result type (might be due to invalid IL or missing references)
//IL_0290: Expected O, but got Unknown
//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
//IL_02cd: Expected O, but got Unknown
//IL_0300: Unknown result type (might be due to invalid IL or missing references)
//IL_030a: Expected O, but got Unknown
//IL_032b: Unknown result type (might be due to invalid IL or missing references)
//IL_0335: Expected O, but got Unknown
//IL_0356: Unknown result type (might be due to invalid IL or missing references)
//IL_0360: Expected O, but got Unknown
configEnableTimer = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - Timer", "EnableTimer", true, new ConfigDescription("Whether to enable the main timer that automatically disables indestructibility once expired.", (AcceptableValueBase)null, Array.Empty<object>()));
configTimerLength = ((BaseUnityPlugin)this).Config.Bind<float>("1 - Timer", "TimerLength", 10f, new ConfigDescription("Time in seconds until the orb loses indestructibility. Vanilla default is 5 seconds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 60f), Array.Empty<object>()));
configAdditionalChecksDelay = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Additional Checks", "AdditionalChecksDelay", 5f, new ConfigDescription("Time in seconds before all following checks activate after the orb has initially spawned. Will not work if greater than TimerLength. Additional checks take precedence over the main timer, meaning they will cut off the timer early if any one of their conditions have been satisfied.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 60f), Array.Empty<object>()));
configEnableVelocityCheck = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Velocity", "EnableVelocityCheck", true, new ConfigDescription("Automatically disables indestructibility when the orb slows down to the specified velocity threshold.", (AcceptableValueBase)null, Array.Empty<object>()));
configVelocityThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Velocity", "VelocityThreshold", 0.01f, new ConfigDescription("The minimum threshold for the velocity check.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
configEnablePlayerHold = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Player Hold", "EnablePlayerHold", true, new ConfigDescription("Automatically disables indestructibility when the orb is grabbed by a player.", (AcceptableValueBase)null, Array.Empty<object>()));
configPlayerHoldTime = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Player Hold", "PlayerHoldTime", 1f, new ConfigDescription("Time in seconds that a player must continue holding onto the orb before indestructibility is disabled. Resets when the player lets go, so that it will not prematurely become destructible if the player gets distracted by something else. Can be set to 0 to immediately disable indestructibility.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
configEnableSafeAreaCheck = ((BaseUnityPlugin)this).Config.Bind<bool>("5 - Safe Areas", "EnableSafeAreaCheck", true, new ConfigDescription("Disables indestructibility if the orb has been placed inside a safe area, such as the C.A.R.T. or an extraction point.", (AcceptableValueBase)null, Array.Empty<object>()));
configSafeAreaTime = ((BaseUnityPlugin)this).Config.Bind<float>("5 - Safe Areas", "SafeAreaTime", 1f, new ConfigDescription("Time in seconds that the orb must remain in a safe area to disable indestructibility. Works very much like PlayerHoldTime.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
configInitialExplosionProbability = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Moon Phase Explosion Probability", "InitialExplosionProbability", 0f, new ConfigDescription("The probability of orbs exploding at the start of a new game, before any moon phases have even taken effect.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
configCrescentMoonExplosionProbability = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Moon Phase Explosion Probability", "CrescentMoonExplosionProbability", 0.01f, new ConfigDescription("The probability of orbs exploding during the Crescent Moon phase, beginning on Level 5.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
configHalfMoonExplosionProbability = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Moon Phase Explosion Probability", "HalfMoonExplosionProbability", 0.1f, new ConfigDescription("The probability of orbs exploding during the Half Moon phase, beginning on Level 10.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
configFullMoonExplosionProbability = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Moon Phase Explosion Probability", "FullMoonExplosionProbability", 0.35f, new ConfigDescription("The probability of orbs exploding during the Full Moon phase, beginning on Level 15.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
configSuperMoonExplosionProbability = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Moon Phase Explosion Probability", "SuperMoonExplosionProbability", 0.95f, new ConfigDescription("The probability of orbs exploding during the Super Moon phase, beginning on Level 20.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
_configEnableDebugTimerLogs = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableDebugTimerLogs", false, new ConfigDescription("Enable debug logs for this mod's timers. \"Debug\" or \"All\" must be included in Logging.Console.LogLevels in the BepInEx config to be able to see these logs. Note that this will create a lot of spam in the console, so please keep this disabled for normal gameplay!", (AcceptableValueBase)null, Array.Empty<object>()));
_configEnableDebugGeneralLogs = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableDebugGeneralLogs", false, new ConfigDescription("Enable debug logs for other calculations and logic performed by this mod.", (AcceptableValueBase)null, Array.Empty<object>()));
Instance = this;
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
Patch();
Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version}: it's tweakin' time!");
if (configEnableTimer.Value && configAdditionalChecksDelay.Value > configTimerLength.Value)
{
Logger.LogWarning((object)$"AdditionalChecksDelay ({configAdditionalChecksDelay.Value}) is greater than TimerLength ({configTimerLength.Value})! Please adjust your config.");
}
}
internal void Patch()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_0026: Expected O, but got Unknown
if (Harmony == null)
{
Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
Harmony val2 = val;
Harmony = val;
}
Harmony.PatchAll();
}
internal void Unpatch()
{
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
internal static void LogDebugTimers(string message)
{
if (_configEnableDebugTimerLogs.Value)
{
Logger.LogDebug((object)message);
}
}
internal static void LogDebugGeneral(string message)
{
if (_configEnableDebugGeneralLogs.Value)
{
Logger.LogDebug((object)message);
}
}
}
}