using System;
using System.Collections.Generic;
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.Logging;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Breakable_GlassV2")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("Breakable_GlassV2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace Breakable_GlassV2
{
[BepInPlugin("com.atomictyler.breakableglass", "Breakable Glass Mod (REWORKED)", "2.0.0")]
public class Plugin : BaseUnityPlugin
{
public class CollideCheck : MonoBehaviour
{
private void OnCollisionEnter(Collision collision)
{
Debug.Log((object)("Collided with " + ((Object)((Component)this).gameObject).name + " - Other: " + ((Object)collision.gameObject).name));
}
}
public class CollisionHandler : MonoBehaviour
{
private GameObject windowPart;
private GameObject knutPart;
private AudioClip warningSound;
public void Init(GameObject windowPart, GameObject knutPart, AudioClip sound)
{
this.windowPart = windowPart;
this.knutPart = knutPart;
warningSound = sound;
}
private void OnCollisionEnter(Collision collision)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)("Collided with " + ((Object)windowPart).name));
PlaySoundAndDisableColliders(((ContactPoint)(ref collision.contacts[0])).point);
MoveParticleToCollision(((ContactPoint)(ref collision.contacts[0])).point);
MoveParticleToCollisionGreen(((ContactPoint)(ref collision.contacts[0])).point);
}
private void MoveParticleToCollision(Vector3 collisionPoint)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
GameObject val = GameObject.Find("WindowSmashed");
if ((Object)(object)val != (Object)null)
{
val.transform.position = collisionPoint;
ParticleSystem component = val.GetComponent<ParticleSystem>();
if ((Object)(object)component != (Object)null)
{
component.Play();
}
}
}
private void MoveParticleToCollisionGreen(Vector3 collisionPoint)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
GameObject val = GameObject.Find("WindowSmashedGreen");
if ((Object)(object)val != (Object)null)
{
val.transform.position = collisionPoint;
ParticleSystem component = val.GetComponent<ParticleSystem>();
if ((Object)(object)component != (Object)null)
{
component.Play();
}
}
}
private void PlaySoundAndDisableColliders(Vector3 collisionPoint)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)warningSound != (Object)null)
{
AudioSource.PlayClipAtPoint(warningSound, collisionPoint);
}
DisableColliders(windowPart);
}
private void DisableColliders(GameObject part)
{
MeshCollider[] components = part.GetComponents<MeshCollider>();
MeshCollider[] array = components;
foreach (MeshCollider val in array)
{
Object.Destroy((Object)(object)val);
}
BoxCollider[] components2 = windowPart.GetComponents<BoxCollider>();
BoxCollider[] array2 = components2;
foreach (BoxCollider val2 in array2)
{
Object.Destroy((Object)(object)val2);
}
Object.Destroy((Object)(object)part.gameObject);
}
private void EnableColliders(GameObject part)
{
BoxCollider[] componentsInChildren = part.GetComponentsInChildren<BoxCollider>();
BoxCollider[] array = componentsInChildren;
foreach (BoxCollider val in array)
{
((Collider)val).enabled = true;
}
}
}
internal static ManualLogSource Logger;
private AudioClip warningSound;
public Vector3[] cubePositions = (Vector3[])(object)new Vector3[4]
{
new Vector3(-15.192f, 0.9976f, 8.526f),
new Vector3(-17.592f, 0.9976f, 6.126f),
new Vector3(-19.583f, 0.9976f, 7.026f),
new Vector3(-16.0703f, 0.7976f, 10.7333f)
};
public Vector3[] cubeRotations = (Vector3[])(object)new Vector3[4]
{
new Vector3(0f, 45f, 0f),
new Vector3(0f, 45f, 0f),
new Vector3(0f, 135f, 0f),
new Vector3(0f, 135f, 0f)
};
public Vector3[] cubeScales = (Vector3[])(object)new Vector3[4]
{
new Vector3(0.19f, 2.4f, 1f),
new Vector3(0.19f, 2.4f, 1f),
new Vector3(0.19f, 2.4f, 4.4f),
new Vector3(0.0809f, 2.3491f, 4.3527f)
};
private void OnEnable()
{
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnDisable()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
if (((Scene)(ref scene)).name == "SurfaceScene")
{
LoadEmbeddedSound();
GameObject[] array = FindParts("Windows");
if (array != null && array.Length != 0)
{
Debug.Log((object)$"Found {array.Length} Windows parts.");
AddCollisionListeners(array);
DisableCollidersForWindowParent(array);
}
else
{
Debug.LogError((object)"No Windows parts found.");
}
GameObject[] array2 = FindParts("Knuts");
if (array2 != null && array2.Length != 0)
{
Debug.Log((object)$"Found {array2.Length} Knut parts.");
DisableCollidersForKnutParent(array2);
}
else
{
Debug.LogError((object)"No Windows parts found.");
}
CreateCubes();
CreateParticle();
CreateParticleGreen();
}
}
private void CreateCubes()
{
//IL_0033: 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_005b: 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_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)"Creating cubes...");
for (int i = 0; i < cubePositions.Length; i++)
{
Debug.Log((object)$"Creating cube {i + 1} at position {cubePositions[i]}, rotation {cubeRotations[i]}, scale {cubeScales[i]}");
GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
val.transform.position = cubePositions[i];
val.transform.eulerAngles = cubeRotations[i];
val.transform.localScale = cubeScales[i];
MeshCollider val2 = val.AddComponent<MeshCollider>();
val2.convex = true;
}
Debug.Log((object)"Cubes created successfully.");
}
private void CreateParticle()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Expected O, but got Unknown
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("WindowSmashed");
ParticleSystem val2 = val.AddComponent<ParticleSystem>();
MainModule main = val2.main;
((MainModule)(ref main)).loop = false;
((MainModule)(ref main)).duration = 1f;
((MainModule)(ref main)).startSize = MinMaxCurve.op_Implicit(0.1f);
((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(2f);
((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(10f);
((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(5f);
((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.45490196f, 71f / 85f, 1f, 0.8f));
((MainModule)(ref main)).playOnAwake = false;
ShapeModule shape = val2.shape;
((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)2;
((ShapeModule)(ref shape)).radius = 1f;
((ShapeModule)(ref shape)).arc = 360f;
Material val3 = new Material(Shader.Find("Particles/Standard Unlit"));
val3.SetColor("_Color", new Color(0.45490196f, 71f / 85f, 1f, 0.8f));
ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
((Renderer)component).material = val3;
CollisionModule collision = val2.collision;
((CollisionModule)(ref collision)).enabled = true;
((CollisionModule)(ref collision)).type = (ParticleSystemCollisionType)1;
((CollisionModule)(ref collision)).mode = (ParticleSystemCollisionMode)0;
((CollisionModule)(ref collision)).dampen = MinMaxCurve.op_Implicit(0.5f);
((CollisionModule)(ref collision)).bounce = MinMaxCurve.op_Implicit(0.5f);
((CollisionModule)(ref collision)).lifetimeLoss = MinMaxCurve.op_Implicit(0.3f);
((CollisionModule)(ref collision)).enableDynamicColliders = true;
val.transform.position = new Vector3(100f, 1000f, 10000f);
val2.Stop();
}
private void CreateParticleGreen()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Expected O, but got Unknown
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("WindowSmashedGreen");
ParticleSystem val2 = val.AddComponent<ParticleSystem>();
MainModule main = val2.main;
((MainModule)(ref main)).loop = false;
((MainModule)(ref main)).duration = 1f;
((MainModule)(ref main)).startSize = MinMaxCurve.op_Implicit(0.1f);
((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(2f);
((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(10f);
((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(5f);
((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.20392157f, 2.6612904f, 1f, 0.8f));
((MainModule)(ref main)).playOnAwake = false;
ShapeModule shape = val2.shape;
((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)2;
((ShapeModule)(ref shape)).radius = 1f;
((ShapeModule)(ref shape)).arc = 360f;
Material val3 = new Material(Shader.Find("Particles/Standard Unlit"));
val3.SetColor("_Color", new Color(0.20392157f, 2.6612904f, 1f, 0.8f));
ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
((Renderer)component).material = val3;
CollisionModule collision = val2.collision;
((CollisionModule)(ref collision)).enabled = true;
((CollisionModule)(ref collision)).type = (ParticleSystemCollisionType)1;
((CollisionModule)(ref collision)).mode = (ParticleSystemCollisionMode)0;
((CollisionModule)(ref collision)).dampen = MinMaxCurve.op_Implicit(0.5f);
((CollisionModule)(ref collision)).bounce = MinMaxCurve.op_Implicit(0.5f);
((CollisionModule)(ref collision)).lifetimeLoss = MinMaxCurve.op_Implicit(0.3f);
((CollisionModule)(ref collision)).enableDynamicColliders = true;
val.transform.position = new Vector3(100f, 1000f, 10000f);
val2.Stop();
}
private void DisableCollidersForKnutParent(GameObject[] knutParts)
{
foreach (GameObject val in knutParts)
{
MeshCollider[] componentsInParent = val.GetComponentsInParent<MeshCollider>();
MeshCollider[] array = componentsInParent;
foreach (MeshCollider val2 in array)
{
Object.Destroy((Object)(object)val2);
}
}
}
private void DisableCollidersForWindowParent(GameObject[] windowParts)
{
foreach (GameObject val in windowParts)
{
MeshCollider[] componentsInParent = val.GetComponentsInParent<MeshCollider>();
MeshCollider[] array = componentsInParent;
foreach (MeshCollider val2 in array)
{
Object.Destroy((Object)(object)val2);
}
if ((Object)(object)val.GetComponent<MeshCollider>() == (Object)null)
{
val.AddComponent<MeshCollider>();
}
}
}
private void LoadEmbeddedSound()
{
warningSound = LoadEmbeddedWavSound("Breakable_GlassV2.Break.wav");
if ((Object)(object)warningSound == (Object)null)
{
Debug.LogError((object)"Failed to load warning sound.");
}
}
private AudioClip LoadEmbeddedWavSound(string resourceName)
{
Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
if (manifestResourceStream != null)
{
using (MemoryStream memoryStream = new MemoryStream())
{
manifestResourceStream.CopyTo(memoryStream);
byte[] audioData = memoryStream.ToArray();
return WavToAudioClip(audioData);
}
}
Debug.LogError((object)("Resource not found: " + resourceName));
return null;
}
private AudioClip WavToAudioClip(byte[] audioData)
{
AudioClip val = AudioClip.Create("WarningSound", audioData.Length, 1, 44100, false);
val.SetData(WavDataToFloatArray(audioData), 0);
return val;
}
private float[] WavDataToFloatArray(byte[] wavData)
{
float[] array = new float[wavData.Length / 2];
for (int i = 0; i < array.Length; i++)
{
array[i] = (float)(short)(wavData[i * 2] | (wavData[i * 2 + 1] << 8)) / 32768f;
}
return array;
}
private GameObject[] FindParts(string prefabName)
{
GameObject val = GameObject.Find("House");
if ((Object)(object)val == (Object)null)
{
Debug.LogError((object)"House object not found.");
return null;
}
Transform val2 = val.transform.Find(prefabName);
if ((Object)(object)val2 == (Object)null)
{
Debug.LogError((object)(prefabName + " prefab not found in House."));
return null;
}
Transform[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Transform>();
List<GameObject> list = new List<GameObject>();
Transform[] array = componentsInChildren;
foreach (Transform val3 in array)
{
if (((Object)val3).name.StartsWith("Splitmesh"))
{
Debug.Log((object)("Found matching part: " + ((Object)val3).name));
list.Add(((Component)val3).gameObject);
}
}
return list.ToArray();
}
private void AddCollisionListeners(GameObject[] windowsParts)
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
foreach (GameObject val in windowsParts)
{
if ((Object)(object)val.GetComponent<BoxCollider>() == (Object)null)
{
BoxCollider val2 = val.AddComponent<BoxCollider>();
Bounds bounds = val.GetComponent<Renderer>().bounds;
val2.size = ((Bounds)(ref bounds)).size;
}
if ((Object)(object)val.GetComponent<CollideCheck>() == (Object)null)
{
val.AddComponent<CollideCheck>();
}
GameObject val3 = FindCorrespondingKnut(val);
if ((Object)(object)val3 != (Object)null)
{
CollisionHandler collisionHandler = val.AddComponent<CollisionHandler>();
collisionHandler.Init(val, val3, warningSound);
}
else
{
Debug.LogWarning((object)("No corresponding Knut part found for " + ((Object)val).name));
}
}
}
private GameObject FindCorrespondingKnut(GameObject windowPart)
{
GameObject val = GameObject.Find("House");
if ((Object)(object)val == (Object)null)
{
Debug.LogError((object)"House object not found.");
return null;
}
Transform val2 = val.transform.Find("Knuts");
if ((Object)(object)val2 == (Object)null)
{
Debug.LogError((object)"Knuts prefab not found in House.");
return null;
}
string name = ((Object)windowPart).name;
Transform val3 = val2.Find(name);
return (val3 != null) ? ((Component)val3).gameObject : null;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "Breakable_GlassV2";
public const string PLUGIN_NAME = "My first plugin";
public const string PLUGIN_VERSION = "1.0.0";
}
}