using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
[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("HermitPaintings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HermitPaintings")]
[assembly: AssemblyTitle("HermitPaintings")]
[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 HermitPaintings
{
[BepInPlugin("HermitPaintings", "HermitPaintings", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(LoadingUI), "LevelAnimationComplete")]
public class PatchLoadingUI
{
[HarmonyPostfix]
private static void Postfix()
{
//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)
((BaseUnityPlugin)Instance).Logger.LogInfo((object)"Replacing all materials containing 'painting' with custom images...");
Scene activeScene = SceneManager.GetActiveScene();
foreach (GameObject item in ((Scene)(ref activeScene)).GetRootGameObjects().ToList())
{
MeshRenderer[] componentsInChildren = item.GetComponentsInChildren<MeshRenderer>();
foreach (MeshRenderer val in componentsInChildren)
{
Material[] sharedMaterials = ((Renderer)val).sharedMaterials;
for (int j = 0; j < sharedMaterials.Length; j++)
{
if ((Object)(object)sharedMaterials[j] != (Object)null && ((Object)sharedMaterials[j]).name.ToLower().Contains("painting") && loadedMaterials.Count > 0)
{
int index = random.Next(loadedMaterials.Count);
sharedMaterials[j] = loadedMaterials[index];
}
}
((Renderer)val).sharedMaterials = sharedMaterials;
}
}
}
}
private readonly Harmony harmony = new Harmony("ch.gabzdev.randompaintingswap");
public static List<Material> loadedMaterials = new List<Material>();
public static Random random;
public static Plugin Instance { get; private set; }
private void Awake()
{
Instance = this;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Random Painting Swap is loaded!");
SeedRandom();
LoadEmbeddedImages("HermitPaintings.Images");
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
private void SeedRandom()
{
string text = DateTime.UtcNow.ToString("yyyyMMdd");
int hashCode = text.GetHashCode();
random = new Random(hashCode);
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Random generator seeded with {hashCode} (UTC time {text}).");
}
private void LoadEmbeddedImages(string namespacePrefix)
{
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Expected O, but got Unknown
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
foreach (string text in manifestResourceNames)
{
if (text.StartsWith(namespacePrefix) && (text.EndsWith(".png") || text.EndsWith(".jpg") || text.EndsWith(".jpeg")))
{
using Stream stream = executingAssembly.GetManifestResourceStream(text);
if (stream != null)
{
byte[] array = new byte[stream.Length];
stream.Read(array, 0, array.Length);
Texture2D val = new Texture2D(2, 2);
if (ImageConversion.LoadImage(val, array))
{
Material item = new Material(Shader.Find("Standard"))
{
mainTexture = (Texture)(object)val
};
loadedMaterials.Add(item);
((BaseUnityPlugin)this).Logger.LogInfo((object)("✅ Loaded embedded image: " + text));
}
else
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("❌ Failed to decode image: " + text));
}
}
}
else if (text.EndsWith(".webp"))
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("❌ Skipping unsupported format (.webp): " + text));
}
}
((BaseUnityPlugin)this).Logger.LogInfo((object)$"\ud83c\udf89 Total embedded images loaded: {loadedMaterials.Count}");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "HermitPaintings";
public const string PLUGIN_NAME = "HermitPaintings";
public const string PLUGIN_VERSION = "1.0.0";
}
}