Decompiled source of CeskeObrazky v1.1.0

paintingReplacement.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
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: AssemblyTitle("paintingReplacement")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("paintingReplacement")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9f5c247c-6f44-414e-b174-883360725c74")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace StinkyPaintingReplacement;

[BepInPlugin("LandoZor.PaintingReplacement", "Painting Replacement", "1.0.0")]
public class StinkyPaintingReplacementBase : BaseUnityPlugin
{
	[HarmonyPatch(typeof(LoadingUI), "LevelAnimationComplete")]
	public class LevelGenerator_PlayerSpawn_Patch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			Instance.logger.LogInfo((object)"Start Postfix");
			List<GameObject> list = new List<GameObject>();
			Scene activeScene = SceneManager.GetActiveScene();
			GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
			foreach (GameObject item in rootGameObjects)
			{
				list.Add(item);
			}
			foreach (GameObject item2 in list)
			{
				MeshRenderer[] componentsInChildren = item2.GetComponentsInChildren<MeshRenderer>();
				MeshRenderer[] array = componentsInChildren;
				foreach (MeshRenderer val in array)
				{
					Material[] sharedMaterials = ((Renderer)val).sharedMaterials;
					for (int k = 0; k < sharedMaterials.Length; k++)
					{
						Material val2 = sharedMaterials[k];
						if ((Object)(object)val2 != (Object)null && ReplacementMaterials.ContainsKey(((Object)val2).name))
						{
							sharedMaterials[k] = ReplacementMaterials[((Object)val2).name];
						}
					}
					((Renderer)val).sharedMaterials = sharedMaterials;
				}
			}
		}
	}

	private const string modUID = "LandoZor.PaintingReplacement";

	private const string modName = "Painting Replacement";

	private const string modVersion = "1.0.0";

	internal ManualLogSource logger;

	private readonly Harmony harmony = new Harmony("LandoZor.PaintingReplacement");

	public static Dictionary<string, Material> ReplacementMaterials = new Dictionary<string, Material>(StringComparer.OrdinalIgnoreCase);

	public static StinkyPaintingReplacementBase Instance { get; private set; }

	private void Awake()
	{
		Instance = this;
		logger = ((BaseUnityPlugin)this).Logger;
		logger.LogInfo((object)"Loading Stinky Painting Replacement mod...");
		Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		LoadMaterials();
		ApplyPatches();
		logger.LogInfo((object)"Successfully loaded assets for Stinky Painting Replacement mod!");
	}

	private void ApplyPatches()
	{
		harmony.PatchAll(Assembly.GetExecutingAssembly());
	}

	private void LoadMaterials()
	{
		string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "stinky_paintings");
		AssetBundle val = AssetBundle.LoadFromFile(text);
		if ((Object)(object)val == (Object)null)
		{
			logger.LogError((object)"Failed to load Material AssetBundle!");
			return;
		}
		Material[] array = val.LoadAllAssets<Material>();
		Material[] array2 = array;
		foreach (Material val2 in array2)
		{
			ReplacementMaterials[((Object)val2).name] = val2;
		}
		logger.LogInfo((object)$"Loaded {ReplacementMaterials.Count} materials.");
	}
}