Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of BrenoPics v1.0.0
CustomPaintings.dll
Decompiled 2 years agousing 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 BepInEx; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.SceneManagement; [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("Potatatatatata")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("Potatatatatata")] [assembly: AssemblyTitle("Potatatatatata")] [assembly: AssemblyVersion("0.0.0.0")] [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; } } } [BepInPlugin("ch.gabzdev.randompaintingswap", "CustomPaintings", "1.0.0")] public class Plugin : BaseUnityPlugin { [HarmonyPatch(typeof(LoadingUI), "LevelAnimationComplete")] public class PatchLoadingUI { [HarmonyPostfix] private static void Postfix() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: 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(); List<GameObject> list = ((Scene)(ref activeScene)).GetRootGameObjects().ToList(); foreach (GameObject item in list) { 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.Range(0, loadedMaterials.Count); sharedMaterials[j] = loadedMaterials[index]; } } ((Renderer)val).sharedMaterials = sharedMaterials; } } } } private const string IMAGE_FOLDER_NAME = "CustomPaintings"; private readonly Harmony harmony = new Harmony("ch.gabzdev.randompaintingswap"); public static List<Material> loadedMaterials = new List<Material>(); public static readonly HashSet<string> targetMaterials = new HashSet<string> { "Painting_H_Landscape", "Painting_V_Furman", "painting teacher01", "painting teacher02", "painting teacher03", "painting teacher04", "Painting_S_Tree" }; public static Plugin Instance { get; private set; } private void Awake() { Instance = this; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Random Painting Swap is loaded!"); harmony.PatchAll(Assembly.GetExecutingAssembly()); LoadImagesFromAllPlugins(); } private void LoadImagesFromAllPlugins() { string text = Path.Combine(Paths.PluginPath); if (!Directory.Exists(text)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Plugins directory not found: " + text)); return; } string[] directories = Directory.GetDirectories(text, "CustomPaintings", SearchOption.AllDirectories); if (directories.Length == 0) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"No 'CustomPaintings' folders found in plugins."); return; } string[] array = directories; foreach (string text2 in array) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Loading images from: " + text2)); LoadImagesFromDirectory(text2); } } private void LoadImagesFromDirectory(string directoryPath) { //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown if (!Directory.Exists(directoryPath)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Directory does not exist: " + directoryPath)); return; } string[] files = Directory.GetFiles(directoryPath, "*.png", SearchOption.AllDirectories); if (files.Length == 0) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("No images found in " + directoryPath)); return; } string[] array = files; foreach (string text in array) { Texture2D val = LoadTextureFromFile(text); if ((Object)(object)val != (Object)null) { Material item = new Material(Shader.Find("Standard")) { mainTexture = (Texture)(object)val }; loadedMaterials.Add(item); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Loaded image: " + Path.GetFileName(text))); } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Failed to load image: " + text)); } } ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Total images loaded: {loadedMaterials.Count}"); } private Texture2D LoadTextureFromFile(string filePath) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown byte[] array = File.ReadAllBytes(filePath); Texture2D val = new Texture2D(2, 2); if (ImageConversion.LoadImage(val, array)) { val.Apply(); return val; } return null; } }