Decompiled source of Zylack v1.0.0

Mods\Zylack.dll

Decompiled 3 days ago
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 HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.Equipping;
using MelonLoader;
using UnityEngine;
using ZyklopMod;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "Zylack", "1.0.0", "Zyklop", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Zylack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Zylack")]
[assembly: AssemblyTitle("Zylack")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ZyklopMod
{
	public class Core : MelonMod
	{
		private Harmony _harmony;

		public static Core Instance { get; private set; }

		public static Instance Log => ((MelonBase)Instance).LoggerInstance;

		public override void OnInitializeMelon()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			Instance = this;
			Log.Msg("ZyklopMod yükleniyor...");
			_harmony = new Harmony("com.zyklop.zyklopmod");
			_harmony.PatchAll(typeof(Core).Assembly);
			Log.Msg("ZyklopMod yüklendi!");
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			Log.Msg($"Sahne yüklendi: {sceneName} (index: {buildIndex})");
			if (sceneName == "Main")
			{
				WallPoster.SpawnAll();
			}
		}

		public override void OnUpdate()
		{
			if (Input.GetKeyDown((KeyCode)288))
			{
				WallPoster.TryPlaceAtAim();
			}
			else if (Input.GetKeyDown((KeyCode)289))
			{
				WallPoster.RemoveLast();
			}
		}
	}
	public static class SoundManager
	{
		private const string ReloadResourceName = "ZyklopMod.Assets.reload.wav";

		private static AudioClip _reloadClip;

		private static AudioSource _source;

		private static bool _initAttempted;

		public static void PlayReload()
		{
			EnsureInitialized();
			if (!((Object)(object)_reloadClip == (Object)null) && !((Object)(object)_source == (Object)null))
			{
				_source.PlayOneShot(_reloadClip);
			}
		}

		private static void EnsureInitialized()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			if (_initAttempted)
			{
				return;
			}
			_initAttempted = true;
			byte[] array = LoadEmbedded("ZyklopMod.Assets.reload.wav");
			if (array != null)
			{
				_reloadClip = WavToAudioClip(array, "ZyklopModReloadClip");
				if (!((Object)(object)_reloadClip == (Object)null))
				{
					GameObject val = new GameObject("ZyklopMod_AudioSource");
					Object.DontDestroyOnLoad((Object)val);
					_source = val.AddComponent<AudioSource>();
					_source.spatialBlend = 0f;
					_source.playOnAwake = false;
					Core.Log.Msg("Reload sesi yüklendi.");
				}
			}
		}

		private static byte[] LoadEmbedded(string name)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
			if (stream == null)
			{
				Core.Log.Error("Embedded resource bulunamadı: " + name);
				return null;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			return array;
		}

		private static AudioClip WavToAudioClip(byte[] wav, string clipName)
		{
			if (wav.Length < 44 || wav[0] != 82 || wav[1] != 73 || wav[2] != 70 || wav[3] != 70 || wav[8] != 87 || wav[9] != 65 || wav[10] != 86 || wav[11] != 69)
			{
				Core.Log.Error("Geçersiz WAV dosyası (RIFF/WAVE header yok).");
				return null;
			}
			int num = wav[22] | (wav[23] << 8);
			int num2 = wav[24] | (wav[25] << 8) | (wav[26] << 16) | (wav[27] << 24);
			int num3 = wav[34] | (wav[35] << 8);
			if (num3 != 16)
			{
				Core.Log.Error($"Sadece 16-bit PCM WAV destekleniyor, dosya {num3}-bit. Audacity'de 'Signed 16-bit PCM' olarak export et.");
				return null;
			}
			int num4 = -1;
			int num5 = 0;
			int num6;
			for (int i = 12; i < wav.Length - 8; i += 8 + num6)
			{
				string obj = $"{wav[i]}{wav[i + 1]}{wav[i + 2]}{wav[i + 3]}";
				num6 = wav[i + 4] | (wav[i + 5] << 8) | (wav[i + 6] << 16) | (wav[i + 7] << 24);
				if (obj == "data")
				{
					num4 = i + 8;
					num5 = num6;
					break;
				}
			}
			if (num4 < 0)
			{
				Core.Log.Error("WAV data chunk bulunamadı.");
				return null;
			}
			int num7 = num5 / 2;
			int num8 = num7 / num;
			float[] array = new float[num7];
			for (int j = 0; j < num7; j++)
			{
				short num9 = (short)(wav[num4 + j * 2] | (wav[num4 + j * 2 + 1] << 8));
				array[j] = (float)num9 / 32768f;
			}
			AudioClip obj2 = AudioClip.Create(clipName, num8, num, num2, false);
			obj2.SetData(Il2CppStructArray<float>.op_Implicit(array), 0);
			Core.Log.Msg($"WAV çözüldü: {num}ch, {num2}Hz, {num8} samples");
			return obj2;
		}
	}
	public static class WallPoster
	{
		private const string ResourceName = "ZyklopMod.Assets.overlay.png";

		private const float SurfaceOffset = 0.01f;

		private const float PosterWidth = 0.8f;

		private const float PosterHeight = 1.2f;

		private const float RaycastDistance = 20f;

		private static readonly (Vector3 pos, Vector3 euler)[] FixedPositions = new(Vector3, Vector3)[7]
		{
			(new Vector3(-25.733f, 1.742f, 63.749f), new Vector3(0f, 359.9f, 0f)),
			(new Vector3(-63.064f, 1.668f, 52.808f), new Vector3(0f, 226.2f, 0f)),
			(new Vector3(-1.257f, 1.812f, 93.735f), new Vector3(0f, 0f, 0f)),
			(new Vector3(-20.01f, -1.714f, 139.173f), new Vector3(0f, 90f, 0f)),
			(new Vector3(-29.179f, -1.899f, 141.484f), new Vector3(0f, 0f, 0f)),
			(new Vector3(-29.04f, 2.09f, 24.108f), new Vector3(0f, 270f, 0f)),
			(new Vector3(-7.555f, 1.953f, -17.73f), new Vector3(0f, 60f, 0f))
		};

		private static Texture2D _texture;

		private static Shader _shader;

		private static readonly List<GameObject> _posters = new List<GameObject>();

		public static void SpawnAll()
		{
			//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_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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_texture == (Object)null) || LoadTexture())
			{
				ClearAll();
				(Vector3, Vector3)[] fixedPositions = FixedPositions;
				for (int i = 0; i < fixedPositions.Length; i++)
				{
					(Vector3, Vector3) tuple = fixedPositions[i];
					Vector3 item = tuple.Item1;
					Vector3 item2 = tuple.Item2;
					GameObject item3 = CreatePoster(item, Quaternion.Euler(item2));
					_posters.Add(item3);
				}
				Core.Log.Msg($"{_posters.Count} sabit poster yerleştirildi.");
			}
		}

		public static void TryPlaceAtAim()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_texture == (Object)null) || LoadTexture())
			{
				Camera main = Camera.main;
				if ((Object)(object)main == (Object)null)
				{
					Core.Log.Warning("Camera.main yok, poster yerleştirilemedi.");
					return;
				}
				RaycastHit val = default(RaycastHit);
				if (!Physics.Raycast(new Ray(((Component)main).transform.position, ((Component)main).transform.forward), ref val, 20f))
				{
					Core.Log.Msg("Raycast bir şeye isabet etmedi.");
					return;
				}
				GameObject val2 = CreatePoster(((RaycastHit)(ref val)).point + ((RaycastHit)(ref val)).normal * 0.01f, Quaternion.LookRotation(-((RaycastHit)(ref val)).normal));
				_posters.Add(val2);
				Vector3 position = val2.transform.position;
				Quaternion rotation = val2.transform.rotation;
				Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles;
				Instance log = Core.Log;
				DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(66, 10);
				defaultInterpolatedStringHandler.AppendLiteral("Poster yerleştirildi: hit='");
				Collider collider = ((RaycastHit)(ref val)).collider;
				defaultInterpolatedStringHandler.AppendFormatted((collider != null) ? ((Object)collider).name : null);
				defaultInterpolatedStringHandler.AppendLiteral("' ");
				defaultInterpolatedStringHandler.AppendLiteral("pos=(");
				defaultInterpolatedStringHandler.AppendFormatted(position.x, "F3");
				defaultInterpolatedStringHandler.AppendLiteral(", ");
				defaultInterpolatedStringHandler.AppendFormatted(position.y, "F3");
				defaultInterpolatedStringHandler.AppendLiteral(", ");
				defaultInterpolatedStringHandler.AppendFormatted(position.z, "F3");
				defaultInterpolatedStringHandler.AppendLiteral(") ");
				defaultInterpolatedStringHandler.AppendLiteral("euler=(");
				defaultInterpolatedStringHandler.AppendFormatted(eulerAngles.x, "F1");
				defaultInterpolatedStringHandler.AppendLiteral(", ");
				defaultInterpolatedStringHandler.AppendFormatted(eulerAngles.y, "F1");
				defaultInterpolatedStringHandler.AppendLiteral(", ");
				defaultInterpolatedStringHandler.AppendFormatted(eulerAngles.z, "F1");
				defaultInterpolatedStringHandler.AppendLiteral(") ");
				defaultInterpolatedStringHandler.AppendLiteral("normal=(");
				defaultInterpolatedStringHandler.AppendFormatted(((RaycastHit)(ref val)).normal.x, "F3");
				defaultInterpolatedStringHandler.AppendLiteral(", ");
				defaultInterpolatedStringHandler.AppendFormatted(((RaycastHit)(ref val)).normal.y, "F3");
				defaultInterpolatedStringHandler.AppendLiteral(", ");
				defaultInterpolatedStringHandler.AppendFormatted(((RaycastHit)(ref val)).normal.z, "F3");
				defaultInterpolatedStringHandler.AppendLiteral(")");
				log.Msg(defaultInterpolatedStringHandler.ToStringAndClear());
			}
		}

		public static void RemoveLast()
		{
			if (_posters.Count != 0)
			{
				GameObject obj = _posters[_posters.Count - 1];
				_posters.RemoveAt(_posters.Count - 1);
				Object.Destroy((Object)(object)obj);
				Core.Log.Msg($"Son poster kaldırıldı ({_posters.Count} kaldı).");
			}
		}

		private static void ClearAll()
		{
			foreach (GameObject poster in _posters)
			{
				if ((Object)(object)poster != (Object)null)
				{
					Object.Destroy((Object)(object)poster);
				}
			}
			_posters.Clear();
		}

		private static GameObject CreatePoster(Vector3 position, Quaternion rotation)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)5);
			((Object)obj).name = "ZyklopMod_WallPoster";
			Collider component = obj.GetComponent<Collider>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			Transform transform = obj.transform;
			transform.position = position;
			transform.rotation = rotation;
			transform.localScale = new Vector3(0.8f, 1.2f, 1f);
			MeshRenderer component2 = obj.GetComponent<MeshRenderer>();
			Shader shader = GetShader();
			if ((Object)(object)shader != (Object)null)
			{
				((Renderer)component2).material = new Material(shader);
			}
			((Renderer)component2).material.mainTexture = (Texture)(object)_texture;
			return obj;
		}

		private static Shader GetShader()
		{
			if ((Object)(object)_shader != (Object)null)
			{
				return _shader;
			}
			string[] array = new string[3] { "Universal Render Pipeline/Unlit", "Unlit/Texture", "Sprites/Default" };
			foreach (string text in array)
			{
				Shader val = Shader.Find(text);
				if ((Object)(object)val != (Object)null)
				{
					Core.Log.Msg("Poster shader: " + text);
					_shader = val;
					return val;
				}
			}
			Core.Log.Warning("Unlit shader bulunamadı, quad default material kullanılacak.");
			return null;
		}

		private static bool LoadTexture()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ZyklopMod.Assets.overlay.png"))
			{
				if (stream == null)
				{
					Core.Log.Error("Embedded resource bulunamadı: ZyklopMod.Assets.overlay.png");
					return false;
				}
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				_texture = new Texture2D(2, 2);
				ImageConversion.LoadImage(_texture, Il2CppStructArray<byte>.op_Implicit(array));
			}
			return true;
		}
	}
}
namespace ZyklopMod.Patches
{
	public static class ExamplePatches
	{
	}
	[HarmonyPatch(typeof(Equippable_RangedWeapon), "Reload")]
	public static class ReloadPatch
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			SoundManager.PlayReload();
		}
	}
}