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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.Movement;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Sparroh")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DiscWorldRework")]
[assembly: AssemblyTitle("DiscWorldRework")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 static class ConfigManager
{
private const float DebounceSeconds = 0.25f;
private static ConfigFile config;
private static ManualLogSource logger;
private static FileSystemWatcher configWatcher;
private static volatile bool reloadPending;
private static float lastReloadTime;
public static ConfigEntry<bool> EnableRework { get; private set; }
public static void Initialize(ConfigFile configFile, ManualLogSource log)
{
config = configFile;
logger = log;
EnableRework = config.Bind<bool>("General", "Enable Disc World Rework", true, "When enabled, Disc World guns fire full Photon Discs (damage, AOE, wave, bounce-chain, disc upgrades). When disabled, vanilla Disc World behavior is used.");
try
{
SetupFileWatcher();
}
catch (Exception ex)
{
logger.LogError((object)("Error setting up config file watcher: " + ex.Message));
}
}
public static void Tick()
{
if (!reloadPending || Time.unscaledTime - lastReloadTime < 0.25f)
{
return;
}
reloadPending = false;
lastReloadTime = Time.unscaledTime;
try
{
config.Reload();
logger.LogInfo((object)"Config reloaded from disk.");
}
catch (Exception ex)
{
logger.LogError((object)("Error reloading config: " + ex.Message));
}
}
public static void Dispose()
{
if (configWatcher != null)
{
configWatcher.EnableRaisingEvents = false;
configWatcher.Changed -= OnConfigFileChanged;
configWatcher.Created -= OnConfigFileChanged;
configWatcher.Renamed -= OnConfigFileChanged;
configWatcher.Dispose();
configWatcher = null;
}
}
private static void SetupFileWatcher()
{
configWatcher = new FileSystemWatcher(Paths.ConfigPath, "sparroh.discworldrework.cfg");
configWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite;
configWatcher.Changed += OnConfigFileChanged;
configWatcher.Created += OnConfigFileChanged;
configWatcher.Renamed += OnConfigFileChanged;
configWatcher.EnableRaisingEvents = true;
}
private static void OnConfigFileChanged(object sender, FileSystemEventArgs e)
{
reloadPending = true;
}
}
[HarmonyPatch(typeof(PhotonDisc), "OverrideWeaponFiring")]
internal static class DiscWorldOverrideWeaponFiringPatch
{
private static readonly FieldRef<PhotonDisc, GunData> GunDataField = AccessTools.FieldRefAccess<PhotonDisc, GunData>("gunData");
private static readonly FieldRef<PhotonDisc, PlayerLook> PlayerLookField = AccessTools.FieldRefAccess<PhotonDisc, PlayerLook>("playerLook");
private static uint _playPhotonDiscShoot;
private static bool Prefix(PhotonDisc __instance, ref FireParams fireParams)
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
if (!ConfigManager.EnableRework.Value)
{
return true;
}
if (!fireParams.allowFire || fireParams.source is PlateLauncher || fireParams.source.IsContinuous())
{
return false;
}
fireParams.allowFire = false;
ref GunData reference = ref GunDataField.Invoke(__instance);
Vector3 eulerAngles = ((Quaternion)(ref fireParams.rotation)).eulerAngles;
for (int i = 0; i < fireParams.numBullets; i++)
{
Vector2 spread = fireParams.source.GetSpread(i);
Quaternion val = Quaternion.Euler(eulerAngles.x + spread.y, eulerAngles.y + spread.x, eulerAngles.z);
IBullet obj = ((GrenadeGear)__instance).FireBulletCustom(fireParams.position, val, (ModifyBulletDataDelegate)null, (GearUpgradeFlags)0, reference.hitForce, (BulletData?)null, true);
PhotonDiscBullet val2 = (PhotonDiscBullet)(object)((obj is PhotonDiscBullet) ? obj : null);
if (val2 != null)
{
val2.DamageSource = (IDamageSource)(object)fireParams.source;
}
}
PlayerLook val3 = PlayerLookField.Invoke(__instance);
if ((Object)(object)val3 != (Object)null)
{
if (_playPhotonDiscShoot == 0)
{
_playPhotonDiscShoot = AkUnitySoundEngine.GetIDFromString("Play_Photon_Disc_Shoot");
}
AkUnitySoundEngine.SetSwitch(Global.Element_Switch, Global.GetEffect(reference.damageEffect).ElementSwitchID, ((Component)val3).gameObject);
AkUnitySoundEngine.PostEvent(_playPhotonDiscShoot, ((Component)val3).gameObject);
}
return false;
}
}
[HarmonyPatch(typeof(PhotonDisc), "OnFiredBullet")]
internal static class DiscWorldOnFiredBulletPatch
{
private static void Prefix(IBullet bullet)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
if (ConfigManager.EnableRework.Value && bullet != null)
{
GearUpgradeFlags upgradeFlags = bullet.UpgradeFlags;
if ((upgradeFlags & 4) != 0)
{
bullet.UpgradeFlags = (GearUpgradeFlags)(upgradeFlags & -5);
}
}
}
}
[HarmonyPatch(typeof(PhotonDiscBullet), "OnHit")]
internal static class DiscWorldBulletOnHitPatch
{
private static void Prefix(PhotonDiscBullet __instance)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
if (ConfigManager.EnableRework.Value)
{
GearUpgradeFlags upgradeFlags = ((SimpleProjectileBullet)__instance).UpgradeFlags;
if ((upgradeFlags & 4) != 0)
{
((SimpleProjectileBullet)__instance).UpgradeFlags = (GearUpgradeFlags)(upgradeFlags & -5);
}
}
}
}
[BepInPlugin("sparroh.discworldrework", "DiscWorldRework", "1.0.0")]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class DiscWorldReworkPlugin : BaseUnityPlugin
{
public const string PluginGUID = "sparroh.discworldrework";
public const string PluginName = "DiscWorldRework";
public const string PluginVersion = "1.0.0";
internal static ManualLogSource Log;
private Harmony _harmony;
private void Awake()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
ConfigManager.Initialize(((BaseUnityPlugin)this).Config, Log);
_harmony = new Harmony("sparroh.discworldrework");
try
{
_harmony.PatchAll();
Log.LogInfo((object)"Harmony patches applied.");
}
catch (Exception ex)
{
Log.LogError((object)("Error applying patches: " + ex.Message));
}
Log.LogInfo((object)"DiscWorldRework v1.0.0 loaded");
}
private void Update()
{
ConfigManager.Tick();
}
private void OnDestroy()
{
ConfigManager.Dispose();
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
namespace DiscWorldRework
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "DiscWorldRework";
public const string PLUGIN_NAME = "DiscWorldRework";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}