Decompiled source of Breakables v1.0.0

Breakables.dll

Decompiled 12 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BreakablesScripts;
using HarmonyLib;
using Landfall.TABS;
using Landfall.TABS.GameMode;
using LevelCreator;
using TFBGames;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Breakables")]
[assembly: AssemblyDescription("Breakables")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("GeeztJeez")]
[assembly: AssemblyProduct("Breakables")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7acfaef0-7669-4401-8bff-5a9a02e18c75")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Breakables
{
	[BepInPlugin("GeeztJeez.Breakables", "Breakables", "1.0.0")]
	internal class Loader : BaseUnityPlugin
	{
		private Transform camTransform;

		public GameObject baseBrickObject;

		public AssetBundle assetsBundle;

		private bool buildMode;

		private float currentScale = 5f;

		private readonly float minScale = 5f;

		private readonly float maxScale = 100f;

		private GameObject indicationInstance;

		public GameObject indicationObject;

		public static bool DebugEnabled;

		public static string BreakablesFolder;

		public static string ConfigFilePath;

		public static bool EnableMapCreatorBreakables;

		public static readonly Dictionary<string, float> BreakableObjects;

		public static GameObject breakParticleObject;

		private SoundPlayer SoundPlayer => ServiceLocator.GetService<SoundPlayer>();

		private void Awake()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			try
			{
				BreakablesFolder = Path.Combine(Application.dataPath, "../Breakables");
				ConfigFilePath = Path.Combine(BreakablesFolder, "config.txt");
				CreateConfig();
				LoadConfig();
				assetsBundle = GetBundle("breakablesassetbundles");
				baseBrickObject = (GameObject)assetsBundle.LoadAsset("DestructibleBrick");
				breakParticleObject = (GameObject)assetsBundle.LoadAsset("BreakMeshParticleObject");
				baseBrickObject.AddComponent<DestructibleObjectBrickBehaviour>();
				indicationObject = (GameObject)assetsBundle.LoadAsset("IndicationBrick");
				ApplyHarmony();
				((MonoBehaviour)this).StartCoroutine(Call());
			}
			catch (Exception ex)
			{
				LogError("Fatal error, mod loading failed: " + ex);
				LogWarning("Please contact Geezt Jeez or try reloading the game for proper installation...");
			}
		}

		private IEnumerator Call()
		{
			yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)Object.FindObjectOfType<ServiceLocator>() != (Object)null));
			yield return (object)new WaitUntil((Func<bool>)(() => ServiceLocator.GetService<ISaveLoaderService>() != null));
			Debug.Log((object)"[Breakables] Loading...");
			SLMALoader.GetInstance();
			new Harmony("Breakables").PatchAll();
			SceneManager.sceneLoaded += SceneLoaded;
			Debug.Log((object)"[Breakables] Loaded Successfully!");
		}

		private void SceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			Log($"Enable Map Creator Breakables: {EnableMapCreatorBreakables}");
			if (((Scene)(ref scene)).name == "LevelScene" && EnableMapCreatorBreakables)
			{
				((MonoBehaviour)this).StartCoroutine(BreakableScanner.WaitForSceneReady(scene));
			}
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= SceneLoaded;
		}

		public Transform GetCamera()
		{
			if ((Object)(object)camTransform != (Object)null)
			{
				return camTransform;
			}
			PlayerCamerasManager service = ServiceLocator.GetService<PlayerCamerasManager>();
			MainCam val = ((service != null) ? service.GetMainCam((Player)0) : null);
			camTransform = (((Object)(object)val != (Object)null) ? ((Component)val).transform : null);
			return camTransform;
		}

		public void SpawnBrick(GameObject prefab, float scale, Vector3 position, Quaternion rotation)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: 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_01ac: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)prefab == (Object)null)
			{
				LogError("[Breakables] PREFAB is null.");
				return;
			}
			SoundPlayer.PlaySoundEffect("UI/Unit Placed", 1f, GetCamera().position, (MaterialType)0, (Transform)null, 3f);
			GameObject val = Object.Instantiate<GameObject>(prefab, position, rotation);
			Rigidbody[] componentsInChildren = val.GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody obj in componentsInChildren)
			{
				obj.mass *= scale;
				obj.drag *= scale;
				obj.angularDrag *= scale;
			}
			DestructibleObjectBrickBehaviour componentInChildren = val.GetComponentInChildren<DestructibleObjectBrickBehaviour>();
			componentInChildren.scaleMultiplier = scale;
			componentInChildren.damageThreshold *= scale;
			Material val2 = CreateDarkenedMaterialHSV(((Renderer)val.GetComponentInChildren<MeshRenderer>()).material, 0.1f, 0.6f);
			ParticleSystemRenderer[] componentsInChildren2 = val.GetComponentsInChildren<ParticleSystemRenderer>(true);
			foreach (ParticleSystemRenderer obj2 in componentsInChildren2)
			{
				((Renderer)obj2).material = val2;
				((Renderer)obj2).materials[0] = val2;
				((Renderer)obj2).sharedMaterial = val2;
				((Renderer)obj2).sharedMaterials[0] = val2;
			}
			MeshRenderer[] componentsInChildren3 = val.GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer obj3 in componentsInChildren3)
			{
				((Renderer)obj3).material = val2;
				((Renderer)obj3).materials[0] = val2;
			}
			val.transform.localScale = Vector3.one * scale;
			DestructibleObject component = val.GetComponent<DestructibleObject>();
			if ((Object)(object)component == (Object)null)
			{
				LogError("No DestructibleObject found on this GameObject!");
				return;
			}
			Type typeFromHandle = typeof(DestructibleObject);
			componentInChildren.objectsToActivate = GetField<GameObject[]>(typeFromHandle, component, "m_objectsToActivate");
			componentInChildren.objectsToDisable = GetField<GameObject[]>(typeFromHandle, component, "m_objectsToDisable");
			Object.Destroy((Object)(object)val.GetComponent<DestructibleObject>());
			Log("[Breakables] Spawned brick at " + position);
		}

		public void DestroyBrick(GameObject go)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)go) && (Object)(object)((Component)go.transform.root).GetComponentInChildren<DestructibleObjectBrickBehaviour>() != (Object)null)
			{
				SoundPlayer.PlaySoundEffect("UI/Unit Removed", 1f, GetCamera().position, (MaterialType)0, (Transform)null, 3f);
				Object.Destroy((Object)(object)((Component)go.transform.root).gameObject);
				Log("[Breakables] Brick destroyed.");
			}
		}

		private void Update()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Invalid comparison between Unknown and I4
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: 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_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_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			GameModeService service = ServiceLocator.GetService<GameModeService>();
			if ((Object)(object)service == (Object)null || service.CurrentGameMode == null || service.CurrentGameMode.GameStateManager == null || (int)service.CurrentGameMode.GameStateManager.GameState > 0)
			{
				return;
			}
			Transform camera = GetCamera();
			if (!Object.op_Implicit((Object)(object)camera))
			{
				return;
			}
			if (Input.GetKeyDown((KeyCode)289))
			{
				SoundPlayer.PlaySoundEffect("UI/Click", 1f, GetCamera().position, (MaterialType)0, (Transform)null, 3f);
				buildMode = !buildMode;
				if (buildMode)
				{
					if ((Object)(object)indicationInstance == (Object)null && (Object)(object)indicationObject != (Object)null)
					{
						indicationInstance = Object.Instantiate<GameObject>(indicationObject);
						indicationInstance.transform.localScale = Vector3.one * currentScale;
					}
				}
				else if (Object.op_Implicit((Object)(object)indicationInstance))
				{
					Object.Destroy((Object)(object)indicationInstance);
					indicationInstance = null;
				}
			}
			else
			{
				if (!buildMode)
				{
					return;
				}
				float axis = Input.GetAxis("Mouse ScrollWheel");
				if (Mathf.Abs(axis) > 0.01f)
				{
					currentScale += axis * 10f;
					currentScale = Mathf.Clamp(currentScale, minScale, maxScale);
					if (Object.op_Implicit((Object)(object)indicationInstance))
					{
						indicationInstance.transform.localScale = Vector3.one * currentScale;
					}
				}
				float num = currentScale;
				Vector3 position = camera.position + camera.forward * 2f * num * 0.25f;
				Quaternion rotation = Quaternion.Euler(0f, camera.eulerAngles.y, 0f);
				if (Object.op_Implicit((Object)(object)indicationInstance))
				{
					indicationInstance.transform.position = position;
					indicationInstance.transform.rotation = rotation;
				}
				if (Input.GetMouseButtonDown(0))
				{
					SpawnBrick(baseBrickObject, currentScale, position, rotation);
				}
				RaycastHit val = default(RaycastHit);
				if (Input.GetMouseButtonDown(1) && Physics.Raycast(camera.position, camera.forward, ref val, 9999f))
				{
					DestroyBrick(((Component)((RaycastHit)(ref val)).collider).gameObject);
				}
			}
		}

		public static AssetBundle GetBundle(string assetBundleName)
		{
			Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(assetBundleName);
			if (manifestResourceStream == null)
			{
				LogError("[LoadBundle] Failed to find resource: " + assetBundleName);
				return null;
			}
			if (!manifestResourceStream.CanRead)
			{
				LogError("[LoadBundle] Resource stream is not readable: " + assetBundleName);
				return null;
			}
			return AssetBundle.LoadFromStream(manifestResourceStream);
		}

		private void ApplyHarmony()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				new Harmony("Breakables").PatchAll(Assembly.GetExecutingAssembly());
				Log("Harmony patched successfully!");
			}
			catch (Exception ex)
			{
				LogError("Harmony patch failed: " + ex);
				Log("Please contact Geezt Jeez or try reloading the game for proper installation...");
			}
		}

		private T GetField<T>(Type t, object obj, string fieldName)
		{
			FieldInfo field = t.GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				LogError("Field not found: " + fieldName);
				return default(T);
			}
			return (T)field.GetValue(obj);
		}

		public static Material CreateDarkenedMaterialHSV(Material baseMat, float minOffset, float maxOffset)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)baseMat == (Object)null)
			{
				return null;
			}
			Material val = new Material(baseMat);
			float num = Random.Range(minOffset, maxOffset);
			bool flag = false;
			bool flag2 = false;
			Color val2;
			if (val.HasProperty("_Color"))
			{
				val2 = val.color;
				flag = true;
			}
			else if (val.HasProperty("_BaseColor"))
			{
				val2 = val.GetColor("_BaseColor");
				flag2 = true;
			}
			else
			{
				val2 = Color.white;
			}
			float num2 = default(float);
			float num3 = default(float);
			float num4 = default(float);
			Color.RGBToHSV(val2, ref num2, ref num3, ref num4);
			num4 *= 1f - num;
			val2 = Color.HSVToRGB(num2, num3, num4);
			if (flag)
			{
				val.color = val2;
			}
			if (flag2)
			{
				val.SetColor("_BaseColor", val2);
			}
			return val;
		}

		public static void LoadConfig()
		{
			EnableMapCreatorBreakables = false;
			DebugEnabled = false;
			try
			{
				BreakableObjects.Clear();
				string[] array = File.ReadAllLines(ConfigFilePath);
				for (int i = 0; i < array.Length; i++)
				{
					string text = array[i].Trim();
					if (string.IsNullOrWhiteSpace(text) || text.StartsWith("#"))
					{
						continue;
					}
					string[] array2 = text.Split(new char[1] { '=' }, 2);
					if (array2.Length != 2)
					{
						continue;
					}
					string text2 = array2[0].Trim();
					string text3 = array2[1].Trim();
					if (!(text2 == "EnableMapCreatorBreakables"))
					{
						if (!(text2 == "DebugEnabled"))
						{
							if (float.TryParse(text3, out var result))
							{
								BreakableObjects[text2] = result;
								Log($"Registered breakable '{text2}' ({result} HP)");
							}
						}
						else
						{
							bool.TryParse(text3, out DebugEnabled);
						}
					}
					else
					{
						bool.TryParse(text3, out EnableMapCreatorBreakables);
					}
				}
				Log($"EnableMapCreatorBreakables={EnableMapCreatorBreakables}");
				Log($"DebugEnabled={DebugEnabled}");
			}
			catch (Exception arg)
			{
				LogError($"Failed loading config:\n{arg}");
			}
		}

		public static void Log(string message)
		{
			if (DebugEnabled)
			{
				Debug.Log((object)("[Breakables] " + message));
			}
		}

		public static void LogWarning(string message)
		{
			if (DebugEnabled)
			{
				Debug.LogWarning((object)("[Breakables] " + message));
			}
		}

		public static void LogError(string message)
		{
			Debug.LogError((object)("[Breakables] " + message));
		}

		public static void CreateConfig()
		{
			if (!Directory.Exists(BreakablesFolder))
			{
				Directory.CreateDirectory(BreakablesFolder);
			}
			if (!File.Exists(ConfigFilePath))
			{
				File.WriteAllLines(ConfigFilePath, new string[10] { "EnableMapCreatorBreakables=true", "DebugEnabled=false", "", "# Format:", "# ObjectName=Health", "", "Barrel=300", "Crate=180", "Plank=120", "Box=200" });
			}
		}

		static Loader()
		{
			BreakableObjects = new Dictionary<string, float>(StringComparer.OrdinalIgnoreCase);
		}
	}
}
namespace BreakablesScripts
{
	public class DestructibleObjectBrickBehaviour : Damagable
	{
		public float damageThreshold = 200f;

		public float forceExplosion = 200f;

		public float currentDamage;

		public float scaleMultiplier = 1f;

		public GameObject[] objectsToActivate;

		public GameObject[] objectsToDisable;

		public override void TakeDamage(float damage, Vector3 direction, Unit unit, DamageType damageType = (DamageType)0)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).GetComponentInChildren<ParticleSystem>().Play();
			if ((int)damageType != 3)
			{
				currentDamage += damage;
				if (currentDamage >= damageThreshold)
				{
					Destruct(direction * forceExplosion);
				}
			}
		}

		private void Destruct(Vector3 force)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			Object.Destroy((Object)(object)((Component)this).GetComponent<Rigidbody>());
			((Component)this).GetComponentInChildren<ParticleSystem>().Play();
			for (int i = 0; i < objectsToActivate.Length; i++)
			{
				objectsToActivate[i].SetActive(true);
				Rigidbody[] componentsInChildren = objectsToActivate[i].GetComponentsInChildren<Rigidbody>(true);
				if (componentsInChildren != null)
				{
					for (int j = 0; j < componentsInChildren.Length; j++)
					{
						Vector3 val = force * Random.Range(-1f, 1f) / scaleMultiplier;
						componentsInChildren[j].AddForce(val, (ForceMode)1);
						RemoveAfterSeconds obj = ((Component)componentsInChildren[j]).gameObject.AddComponent<RemoveAfterSeconds>();
						obj.shrink = true;
						obj.seconds = Random.Range(5f, 8f);
					}
				}
			}
			RemoveAfterSeconds obj2 = ((Component)this).gameObject.AddComponent<RemoveAfterSeconds>();
			obj2.shrink = true;
			obj2.seconds = 10f;
			for (int k = 0; k < objectsToDisable.Length; k++)
			{
				objectsToDisable[k].SetActive(false);
			}
		}
	}
	public class GenericBreakableBehaviour : Damagable
	{
		public float maxHealth = 100f;

		public float minimumDamage;

		public GameObject destructionPrefab;

		public bool destroyOriginal = true;

		private float currentDamage;

		private bool destroyed;

		public Material material;

		public MeshRenderer meshRenderer;

		public override void TakeDamage(float damage, Vector3 direction, Unit unit, DamageType damageType = (DamageType)0)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			if (!destroyed && !(damage < minimumDamage))
			{
				SpawnParticles(direction);
				currentDamage += damage;
				if (currentDamage >= maxHealth)
				{
					Break(direction);
				}
			}
		}

		private void Break(Vector3 direction)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			destroyed = true;
			SpawnParticles(direction);
			if (destroyOriginal)
			{
				if (Object.op_Implicit((Object)(object)meshRenderer))
				{
					((Renderer)meshRenderer).enabled = false;
				}
				MeshCollider componentInChildren = ((Component)this).GetComponentInChildren<MeshCollider>();
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					Object.Destroy((Object)(object)componentInChildren);
				}
				Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					Object.Destroy((Object)(object)componentsInChildren[i]);
				}
			}
		}

		public void Awake()
		{
			meshRenderer = ((Component)this).GetComponentInChildren<MeshRenderer>();
			if (Object.op_Implicit((Object)(object)meshRenderer))
			{
				material = ((Renderer)meshRenderer).material;
			}
		}

		public void SpawnParticles(Vector3 direction)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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)
			if (!Object.op_Implicit((Object)(object)destructionPrefab) || !Object.op_Implicit((Object)(object)meshRenderer))
			{
				return;
			}
			GameObject obj = destructionPrefab;
			Bounds bounds = ((Renderer)meshRenderer).bounds;
			ParticleSystem componentInChildren = Object.Instantiate<GameObject>(obj, ((Bounds)(ref bounds)).center, Quaternion.identity).GetComponentInChildren<ParticleSystem>();
			if (Object.op_Implicit((Object)(object)componentInChildren))
			{
				ParticleSystemRenderer component = ((Component)componentInChildren).GetComponent<ParticleSystemRenderer>();
				if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)material))
				{
					((Renderer)component).material = material;
				}
				EmitFromSurface(componentInChildren, 40, direction);
				componentInChildren.Play();
			}
		}

		private void EmitFromSurface(ParticleSystem ps, int count, Vector3 direction)
		{
			//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_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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0064: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			MeshCollider componentInChildren = ((Component)this).GetComponentInChildren<MeshCollider>();
			if ((Object)(object)componentInChildren == (Object)null)
			{
				return;
			}
			Bounds bounds = ((Collider)componentInChildren).bounds;
			Vector3 val = ((Bounds)(ref bounds)).extents;
			float magnitude = ((Vector3)(ref val)).magnitude;
			RaycastHit val3 = default(RaycastHit);
			for (int i = 0; i < count; i++)
			{
				Vector3 val2 = ((Bounds)(ref bounds)).center + Random.onUnitSphere * magnitude * 2f;
				val = ((Bounds)(ref bounds)).center - val2;
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				if (((Collider)componentInChildren).Raycast(new Ray(val2, normalized), ref val3, magnitude * 4f))
				{
					EmitParams val4 = default(EmitParams);
					((EmitParams)(ref val4)).position = ((RaycastHit)(ref val3)).point + ((RaycastHit)(ref val3)).normal * 0.01f;
					((EmitParams)(ref val4)).velocity = ((RaycastHit)(ref val3)).normal * Random.Range(1.5f, 4f) + ((Vector3)(ref direction)).normalized * Random.Range(1f, 3f) + Random.insideUnitSphere * 0.5f;
					((EmitParams)(ref val4)).rotation3D = Random.insideUnitSphere * 360f;
					((EmitParams)(ref val4)).startSize = Random.Range(0.8f, 1.2f);
					ps.Emit(val4, 1);
				}
			}
		}
	}
}
namespace Breakables
{
	public static class BreakableScanner
	{
		public static IEnumerator Scan()
		{
			yield return null;
			int num = 0;
			MeshRenderer[] array = Object.FindObjectsOfType<MeshRenderer>();
			for (int i = 0; i < array.Length; i++)
			{
				if (((Component)array[i]).gameObject.layer == LayerMask.NameToLayer("Map") && TryConvert(((Component)array[i]).gameObject))
				{
					num++;
				}
			}
			Loader.Log($"Converted {num} objects.");
		}

		private static bool TryConvert(GameObject obj)
		{
			if ((Object)(object)obj == (Object)null)
			{
				return false;
			}
			if ((Object)(object)obj.GetComponent<GenericBreakableBehaviour>() != (Object)null)
			{
				return false;
			}
			foreach (KeyValuePair<string, float> breakableObject in Loader.BreakableObjects)
			{
				if (((Object)obj).name.IndexOf(breakableObject.Key, StringComparison.OrdinalIgnoreCase) >= 0)
				{
					GenericBreakableBehaviour genericBreakableBehaviour = obj.AddComponent<GenericBreakableBehaviour>();
					genericBreakableBehaviour.destructionPrefab = Loader.breakParticleObject;
					genericBreakableBehaviour.maxHealth = breakableObject.Value;
					Loader.Log("Made '" + ((Object)obj).name + "' breakable.");
					if ((Object)(object)obj.GetComponentInChildren<GenericBreakableBehaviour>() != (Object)null)
					{
						Rigidbody obj2 = obj.AddComponent<Rigidbody>();
						obj2.isKinematic = false;
						obj2.mass = 1000f;
					}
					return true;
				}
			}
			return false;
		}

		public static IEnumerator WaitForSceneReady(Scene scene)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			if (!(((Scene)(ref scene)).name != "LevelScene"))
			{
				yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)Object.FindObjectOfType<SpawnLevel>() != (Object)null));
				yield return (object)new WaitUntil((Func<bool>)(() => (int)SpawnLevel.GetSpawnLevelState == 4));
				yield return (object)new WaitUntil((Func<bool>)(() => SpawnLevel.finishedPathfindingScan));
				yield return null;
				yield return (object)new WaitForSeconds(0.25f);
				Loader.Log("Scanning breakables...");
				yield return Scan();
				Loader.Log("Breakable scan complete.");
			}
		}
	}
}