using System;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Imui.Controls;
using Imui.Core;
using Imui.Rendering;
using Microsoft.CodeAnalysis;
using UnityEngine;
using WKLib.API;
using WKLib.API.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CustomMass")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+95b703fc0b33536719820ee652de67b2e75efbfe")]
[assembly: AssemblyProduct("Custom Mass")]
[assembly: AssemblyTitle("CustomMass")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 CustomMass
{
[BepInPlugin("CustomMass", "Custom Mass", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger;
public static WKLibAPI WkApi = WKLibAPI.Create("CustomMass", "CustomMass");
internal static ConfigFile Configuration = new ConfigFile(Path.Combine(Paths.ConfigPath, "CustomMass.cfg"), true);
internal static ConfigEntry<string> SelectedMassName;
internal static string ImagesPath = Path.Combine(Paths.PluginPath, "CustomMass", "images");
internal static CachedMassImage CachedMassImage = new CachedMassImage();
private void Awake()
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin CustomMass is loaded!");
new Harmony("CustomMass").PatchAll();
Logger.LogInfo((object)"Plugin CustomMass is patched!");
Logger.LogInfo((object)("Images path: " + ImagesPath));
SelectedMassName = Configuration.Bind<string>("General", "SelectedMassName", "default", "The name of the texture, or 'default'");
WkApi.AddToModList((ModTab)(object)new CustomMassModTab());
}
internal static string[] ValidMassTextures()
{
try
{
if (!Directory.Exists(ImagesPath))
{
Directory.CreateDirectory(ImagesPath);
Logger.LogInfo((object)("Created images directory: " + ImagesPath));
}
string[] files = Directory.GetFiles(ImagesPath, "*.png");
string[] array = new string[files.Length + 1];
array[0] = "default";
for (int i = 0; i < files.Length; i++)
{
array[i + 1] = Path.GetFileName(files[i]);
}
return array;
}
catch (Exception arg)
{
Logger.LogError((object)$"Failed to get valid mass textures: {arg}");
return new string[1] { "default" };
}
}
internal static Texture2D GetMassTexture()
{
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
if (SelectedMassName.Value == "default")
{
return null;
}
if (CachedMassImage.Name == SelectedMassName.Value)
{
return CachedMassImage.Texture;
}
string text = Path.Combine(ImagesPath, SelectedMassName.Value);
if (!File.Exists(text))
{
SelectedMassName.Value = "default";
Logger.LogWarning((object)("Mass texture file not found: " + text));
return null;
}
try
{
byte[] array = File.ReadAllBytes(text);
Texture2D val = new Texture2D(2, 2);
ImageConversion.LoadImage(val, array);
Logger.LogInfo((object)("Loaded mass texture: " + text));
CachedMassImage.Texture = val;
CachedMassImage.Name = SelectedMassName.Value;
return val;
}
catch (Exception ex)
{
Logger.LogError((object)("Failed to load mass texture: " + text));
Logger.LogError((object)ex);
SelectedMassName.Value = "default";
return null;
}
}
private void OnDestroy()
{
WkApi.Destroy();
}
}
[HarmonyPatch(typeof(DEN_DeathFloor), "Start")]
internal class DeathFloorPatch
{
private static void Prefix(DEN_DeathFloor __instance)
{
Texture2D massTexture = Plugin.GetMassTexture();
if ((Object)(object)massTexture != (Object)null)
{
__instance.corruptionTexture = massTexture;
}
Plugin.Logger.LogInfo((object)"Patched DEN_DeathFloor Start!");
}
}
[HarmonyPatch(typeof(CL_LocalizationManager), "GetLocalization")]
internal class DeathMessagePatch
{
private static bool Prefix(ref string __result, string groupid, string lineid)
{
if (groupid == "deathmessages" && lineid == "deathfloor" && Plugin.SelectedMassName.Value != "default")
{
string text = Plugin.SelectedMassName.Value;
if (text.EndsWith(".png"))
{
string text2 = text;
text = text2.Substring(0, text2.Length - 4);
}
text = text.ToUpper();
__result = "FUSED INTO THE " + text;
return false;
}
return true;
}
}
public class CustomMassModTab : ModTab
{
public override string DisplayName => "Custom Mass";
public override void DrawSubMenu(ImGui gui)
{
//IL_002c: 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_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
ImText.Text(gui, (ReadOnlySpan<char>)"Mass Texture:", false, (ImTextOverflow)0);
string[] array = Plugin.ValidMassTextures();
string value = Plugin.SelectedMassName.Value;
if (ImDropdown.BeginDropdown(gui, (ReadOnlySpan<char>)value, default(ImSize), (ImDropdownPreviewType)0))
{
for (int i = 0; i < array.Length; i++)
{
if (ImMenu.Menu(gui, (ReadOnlySpan<char>)array[i], value == array[i]))
{
Plugin.SelectedMassName.Value = array[i];
ImDropdown.CloseDropdown(gui);
}
}
ImDropdown.EndDropdown(gui);
}
ImText.Text(gui, (ReadOnlySpan<char>)"Takes effect on run start.", false, (ImTextOverflow)0);
if (ImButton.Button(gui, (ReadOnlySpan<char>)"Open Images Folder", default(ImSize), (ImButtonFlag)0))
{
Application.OpenURL("file://" + Plugin.ImagesPath.Replace("\\", "/"));
}
}
}
internal class CachedMassImage
{
internal Texture2D Texture;
internal string Name;
internal CachedMassImage()
{
Texture = null;
Name = "";
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "CustomMass";
public const string PLUGIN_NAME = "Custom Mass";
public const string PLUGIN_VERSION = "1.0.0";
}
}