using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using API;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CellMenu;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using ShooterBugFix;
using ShooterBugFix.Patches;
using UnityEngine;
using UnityEngine.Analytics;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ShooterBugFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+4cb5e150a8db3206afb774c23057102776a0dc19")]
[assembly: AssemblyProduct("ShooterBugFix")]
[assembly: AssemblyTitle("ShooterBugFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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;
}
}
}
public static class Module
{
public const string GUID = "randomuserhi.ShooterBugFix";
public const string Name = "ShooterBugFix";
public const string Version = "0.0.1";
}
namespace ShooterBugFix
{
public static class ConfigManager
{
private static ConfigEntry<bool> debug;
private static ConfigEntry<float> interval;
private static ConfigEntry<float> maxDistance;
private static ConfigEntry<string> cullCommand;
public static bool Debug => debug.Value;
public static float Interval => interval.Value;
public static float MaxDistance => maxDistance.Value;
public static string CullCommand => cullCommand.Value;
static ConfigManager()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "ShooterBugFix.cfg"), true);
debug = val.Bind<bool>("Debug", "enable", false, "Enables debug messages when true.");
interval = val.Bind<float>("Settings", "interval", 3600f, "Time in seconds between out-of-bound collider checks.");
maxDistance = val.Bind<float>("Settings", "maxDistance", 10000f, "How far an object has to be from world origin before it gets destroyed.");
cullCommand = val.Bind<string>("Settings", "cullCommand", "cull", "Command to manually trigger a cull - It is not case-sensitive and will trim white space from start and end of command string.");
}
}
[BepInPlugin("randomuserhi.ShooterBugFix", "ShooterBugFix", "0.0.1")]
internal class Entry : BasePlugin
{
public class CullBehaviour : MonoBehaviour
{
public static float time;
public static bool asked;
private void Start()
{
APILogger.Debug("ShooterBugFix Behaviour Started!");
}
private void Update()
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Invalid comparison between Unknown and I4
if (time < ConfigManager.Interval)
{
time += Time.deltaTime;
return;
}
bool flag = false;
DRAMA_State currentStateEnum = DramaManager.CurrentStateEnum;
if (currentStateEnum - 5 <= 3)
{
flag = true;
}
if (!flag)
{
Cull.CullFarObjects();
}
else if (!asked)
{
Cull.AddLog("<color=yellow>You should perform a cull operation to prevent shooter bug.</color>");
Cull.AddLog("<color=yellow>Type '" + ConfigManager.CullCommand + "' (not case sensitive) in chat to perform a cull.</color>");
time = 0f;
}
}
}
private static CullBehaviour? behaviour;
private Harmony? harmony;
public override void Load()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
APILogger.Debug("Loaded ShooterBugFix 0.0.1");
harmony = new Harmony("randomuserhi.ShooterBugFix");
harmony.PatchAll();
APILogger.Debug("Debug is " + (ConfigManager.Debug ? "Enabled" : "Disabled"));
ClassInjector.RegisterTypeInIl2Cpp<CullBehaviour>();
RundownManager.OnExpeditionGameplayStarted += Action.op_Implicit((Action)Start);
}
private static void Start()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)behaviour == (Object)null)
{
behaviour = new GameObject("ShooterBugObject").AddComponent<CullBehaviour>();
}
}
}
}
namespace ShooterBugFix.Patches
{
[HarmonyPatch(typeof(GameDataInit))]
internal class GameDataInit_Patches
{
[HarmonyPatch("Initialize")]
[HarmonyWrapSafe]
[HarmonyPostfix]
public static void Initialize_Postfix()
{
Analytics.enabled = false;
}
}
[HarmonyPatch]
internal static class Cull
{
public static void AddLog(string log)
{
GuiManager.PlayerLayer.m_gameEventLog.AddLogItem("<color=green>" + log + "</color>", (eGameEventChatLogType)2);
CM_PageLoadout.Current.m_gameEventLog.AddLogItem("<color=green>" + log + "</color>", (eGameEventChatLogType)2);
}
public static void CullFarObjects()
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
Entry.CullBehaviour.time = 0f;
int num = 0;
long num2 = ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds();
float num3 = ConfigManager.MaxDistance * ConfigManager.MaxDistance;
foreach (Collider item in Object.FindObjectsOfType<Collider>())
{
Vector3 position = ((Component)item).transform.position;
if (((Vector3)(ref position)).sqrMagnitude > num3)
{
APILogger.Debug("Culled " + ((Object)((Component)item).gameObject).name + " as it strayed too far from world origin.");
Object.Destroy((Object)(object)((Component)item).gameObject);
num++;
}
}
long value = ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds() - num2;
AddLog($"Culled {num} far objects, took {value}ms to complete.");
APILogger.Debug($"Took {value}ms to complete culling {num} far objects.");
}
[HarmonyPatch(typeof(PlayerChatManager), "PostMessage")]
[HarmonyPrefix]
private static void Prefix_PostMessage(PlayerChatManager __instance)
{
if (__instance.m_currentValue.ToLower().Trim().ToLower() == ConfigManager.CullCommand)
{
CullFarObjects();
__instance.m_currentValue = "";
}
}
[HarmonyPatch(typeof(RundownManager), "EndGameSession")]
[HarmonyPostfix]
private static void EndGameSession()
{
CullFarObjects();
}
}
}
namespace API
{
internal static class APILogger
{
private static readonly ManualLogSource logger;
static APILogger()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Expected O, but got Unknown
logger = new ManualLogSource("Rand-API");
Logger.Sources.Add((ILogSource)(object)logger);
}
private static string Format(string module, object msg)
{
return $"[{module}]: {msg}";
}
public static void Info(string module, object data)
{
logger.LogMessage((object)Format(module, data));
}
public static void Verbose(string module, object data)
{
}
public static void Log(object data)
{
logger.LogDebug((object)Format("ShooterBugFix", data));
}
public static void Debug(object data)
{
if (ConfigManager.Debug)
{
Log(data);
}
}
public static void Warn(object data)
{
logger.LogWarning((object)Format("ShooterBugFix", data));
}
public static void Error(object data)
{
logger.LogError((object)Format("ShooterBugFix", data));
}
}
}