Decompiled source of Blahaj v1.0.0

Blahaj/Blahaj.dll

Decompiled 4 hours ago
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 Microsoft.CodeAnalysis;
using MonoMod.RuntimeDetour;
using TeamCherry.Localization;
using UnityEngine;

[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("Blahaj")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Blahaj")]
[assembly: AssemblyTitle("Blahaj")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace Blahaj
{
	[BepInPlugin("me.cometcake575.blahaj", "Blahaj", "1.0.0")]
	public class BlahajPlugin : BaseUnityPlugin
	{
		private delegate string ToStringOrig(ref LocalisedString self, bool allowBlankText);

		public const string Id = "me.cometcake575.blahaj";

		public static string Name => "Blahaj";

		public static string Version => "1.0.0";

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin " + Name + " (me.cometcake575.blahaj) has loaded!"));
			SetupLangHook();
			SetupTexHook();
		}

		private static void SetupTexHook()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			Sprite icon = LoadSpriteResource("blahaj_icon", (FilterMode)1);
			Sprite journal = LoadSpriteResource("blahaj_journal", (FilterMode)1, default(Vector4), 64f);
			using Stream stream = executingAssembly.GetManifestResourceStream("Blahaj.blahaj.png");
			if (stream == null)
			{
				return;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Texture2D tex = new Texture2D(2, 2);
			ImageConversion.LoadImage(tex, array, true);
			((Texture)tex).wrapMode = (TextureWrapMode)1;
			new Hook((MethodBase)typeof(EnemyDeathEffects).GetMethod("Awake", BindingFlags.Instance | BindingFlags.NonPublic), (Delegate)(Action<Action<EnemyDeathEffects>, EnemyDeathEffects>)delegate(Action<EnemyDeathEffects> orig, EnemyDeathEffects self)
			{
				orig(self);
				if (Object.op_Implicit((Object)(object)self.journalRecord) && ((Object)self.journalRecord).name == "Bone Worm BlueBlood")
				{
					((Renderer)((Component)self).GetComponent<MeshRenderer>()).sharedMaterial.mainTexture = (Texture)(object)tex;
					self.journalRecord.iconSprite = icon;
					self.journalRecord.enemySprite = journal;
				}
			});
		}

		private static void SetupLangHook()
		{
			Hook(typeof(LocalisedString), "ToString", (<>F{00000008}<ToStringOrig, LocalisedString, bool, string>)delegate(ToStringOrig orig, ref LocalisedString self, bool allowBlankText)
			{
				if (self.Sheet == "Journal")
				{
					string key = self.Key;
					if (1 == 0)
					{
					}
					string result = key switch
					{
						"NAME_BONE_WORM_BLUEBLOOD" => "BLÅHAJ", 
						"DESC_BONE_WORM_BLUEBLOOD" => "Big and safe to have by your side if you want to discover the world below the surface of the ocean.", 
						"NOTE_BONE_WORM_BLUEBLOOD" => "The blue shark can swim very far, dive really deep and hear noises from almost 250 metres away.", 
						_ => orig(ref self, allowBlankText), 
					};
					if (1 == 0)
					{
					}
					return result;
				}
				return orig(ref self, allowBlankText);
			}, typeof(bool));
		}

		public static void Hook(Type type, string name, Delegate target, params Type[] types)
		{
			//IL_002c: 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)
			if (Extensions.IsNullOrEmpty<Type>((ICollection<Type>)types))
			{
				new Hook((MethodBase)type.GetMethod(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic), target);
			}
			else
			{
				new Hook((MethodBase)type.GetMethod(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, types, null), target);
			}
		}

		private static Sprite LoadSpriteResource(string spritePath, FilterMode filterMode = 1, Vector4 border = default(Vector4), float ppu = 100f)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			string name = "Blahaj." + spritePath + ".png";
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			using Stream stream = executingAssembly.GetManifestResourceStream(name);
			if (stream == null)
			{
				return null;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, array, true);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), ppu, 0u, (SpriteMeshType)1, border);
			((Texture)val2.texture).filterMode = filterMode;
			return val2;
		}
	}
}