Decompiled source of ThumbnailFix v0.1.0

BepInEx/plugins/CastleStory_ThumbnailFix.dll

Decompiled 6 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Brix.Assets;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("CastleStory_ThumbnailFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("CastleStory: Thumbnail Fix Plugin")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+fc13c15f79e0a2e10e91e2c4daf5fe61c9a95104")]
[assembly: AssemblyProduct("CastleStory_ThumbnailFix")]
[assembly: AssemblyTitle("CastleStory_ThumbnailFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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 CastleStory_ThumbnailFix
{
	[HarmonyPatch]
	public class Asset_MapPatch
	{
		[HarmonyPatch(typeof(Asset_Map), "Disk_WriteThumbnail")]
		private static bool Prefix(Asset_Map __instance)
		{
			if ((Object)(object)((Asset_Base<Asset_Map>)(object)__instance).thumbnail != (Object)null)
			{
				string value = Traverse.Create((object)__instance).Method("GetThumbnailPath", new object[0]).GetValue<string>();
				ResizeTexture(((Asset_Base<Asset_Map>)(object)__instance).thumbnail);
				File.WriteAllBytes(value, ((Asset_Base<Asset_Map>)(object)__instance).thumbnail.EncodeToJPG(40));
			}
			return false;
		}

		private static void ResizeTexture(Texture2D texture)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			RenderTexture val = (RenderTexture.active = RenderTexture.GetTemporary(640, 480, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)0));
			Graphics.Blit((Texture)(object)texture, val);
			texture.Resize(640, 480, texture.format, false);
			((Texture)texture).filterMode = (FilterMode)1;
			texture.ReadPixels(new Rect(Vector2.zero, new Vector2(640f, 480f)), 0, 0);
			texture.Apply();
			RenderTexture.ReleaseTemporary(val);
		}
	}
	[BepInPlugin("CastleStory_ThumbnailFix", "CastleStory_ThumbnailFix", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("com.wasikuss.castlestory.thumbnailfix").PatchAll();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "CastleStory_ThumbnailFix";

		public const string PLUGIN_NAME = "CastleStory_ThumbnailFix";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}