Decompiled source of BackroomsCompat v0.1.0

plugins/BackroomsCompat.dll

Decompiled 12 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BackroomsCompat")]
[assembly: AssemblyDescription("Backrooms 与当前游戏版本的兼容补丁")]
[assembly: AssemblyCompany("cn_xc")]
[assembly: AssemblyProduct("BackroomsCompat")]
[assembly: AssemblyCopyright("Copyright (c) 2026 cn_xc")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.1.0.0")]
namespace BackroomsCompat;

[BepInPlugin("cn_xc.BackroomsCompat", "BackroomsCompat", "0.1.0")]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	internal static bool _loggedOnce;

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		try
		{
			new Harmony("cn_xc.BackroomsCompat").PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"BackroomsCompat 0.1.0 已加载(LevelPathTruck 兜底 + 空音源保护)");
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("补丁挂载失败: " + ex.Message));
		}
	}
}
[HarmonyPatch(typeof(EnemyDirector), "FirstSpawnPointAdd")]
internal static class PatchFirstSpawnPoint
{
	private static bool Prefix(EnemyDirector __instance, EnemyParent _enemyParent)
	{
		try
		{
			LevelGenerator instance = LevelGenerator.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return true;
			}
			if ((Object)(object)instance.LevelPathTruck != (Object)null)
			{
				return true;
			}
			if ((Object)(object)_enemyParent == (Object)null)
			{
				return false;
			}
			List<LevelPoint> list = SemiFunc.LevelPointsGetAll();
			if (list == null)
			{
				return false;
			}
			LevelPoint val = null;
			foreach (LevelPoint item in list)
			{
				if (!((Object)(object)item == (Object)null) && !item.Truck)
				{
					val = item;
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				foreach (LevelPoint item2 in list)
				{
					if ((Object)(object)item2 != (Object)null)
					{
						val = item2;
						break;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				try
				{
					FieldInfo field = ((object)_enemyParent).GetType().GetField("firstSpawnPoint", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null)
					{
						field.SetValue(_enemyParent, val);
					}
				}
				catch
				{
				}
				if (!Plugin._loggedOnce)
				{
					Plugin._loggedOnce = true;
					Plugin.Log.LogWarning((object)("关卡缺少 LevelPathTruck,已用兜底刷新点:" + ((Object)val).name));
				}
			}
			return false;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("兜底失败: " + ex.Message));
			return false;
		}
	}
}
[HarmonyPatch(typeof(Sound), "PlayLoop")]
internal static class PatchSoundPlayLoop
{
	private static bool Prefix(Sound __instance)
	{
		try
		{
			if (__instance == null)
			{
				return false;
			}
			FieldInfo field = ((object)__instance).GetType().GetField("Source", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			object obj = ((field != null) ? field.GetValue(__instance) : null);
			if (obj == null)
			{
				return false;
			}
			Object val = (Object)((obj is Object) ? obj : null);
			if (val != null && val == (Object)null)
			{
				return false;
			}
		}
		catch
		{
			return false;
		}
		return true;
	}
}