Decompiled source of SMDCompany v1.3.3

SMD/SMD company mods - Decco.dll

Decompiled 2 years ago
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("SMD company mods - Decco")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SMD company mods - Decco")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("77072f23-4b00-4165-934b-8209cd4af620")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
public static class TextureUtil
{
	public static Texture2D PremultiplyAlpha(this Texture2D texture)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//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)
		Color[] pixels = texture.GetPixels();
		for (int i = 0; i < pixels.Length; i++)
		{
			pixels[i] = Premultiply(pixels[i]);
		}
		texture.SetPixels(pixels);
		return texture;
	}

	private static Color Premultiply(Color color)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		return new Color(color.r * color.a, color.g * color.a, color.b * color.a, color.a);
	}
}
namespace SMD_company_mods___Decco;

[BepInPlugin("cheeseVeg.SMDmods.ShipDecco", "SMD ShipDecco", "1.2.0")]
public class Plugin : BaseUnityPlugin
{
	public const string pluginGuid = "cheeseVeg.SMDmods.ShipDecco";

	public const string pluginName = "SMD ShipDecco";

	public const string pluginVersion = "1.2.0";

	public string logoFilePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\reLOGO.png";

	private string[] texturepaths = new string[8] { "/TipsPoster2.png", "/posters.png", "/manual1.png", "/manual2v2.png", "/manual3v2.png", "/manual4v2.png", "/LightSwitchTex.png", "/LightSwitchTex2.png" };

	private string[] hierarchypaths = new string[8] { "Environment/HangarShip/StickyNoteItem", "Environment/HangarShip/Plane.001", "Environment/HangarShip/ClipboardManual/Plane", "Environment/HangarShip/ClipboardManual/Plane.001", "Environment/HangarShip/ClipboardManual/Plane.002", "Environment/HangarShip/ClipboardManual/Plane.003", "Environment/HangarShip/LightSwitchContainer/LightSwitch", "Environment/HangarShip/LightSwitchContainer/LightSwitch/Switch" };

	private int[] materialnumber = new int[8] { 1, 1, 1, 1, 1, 1, 1, 1 };

	private Texture2D[] textures = (Texture2D[])(object)new Texture2D[8];

	private Texture2D[] gifPosterFrames = (Texture2D[])(object)new Texture2D[200];

	private static Plugin Instance;

	private Texture2D reLOGOtexture2D = new Texture2D(560, 249, (TextureFormat)62, false);

	private int totalFrameCount;

	private int reloadCheck;

	public void Awake()
	{
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Expected O, but got Unknown
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
		}
		else if ((Object)(object)Instance != (Object)(object)this)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
		for (int i = 0; i < texturepaths.Length; i++)
		{
			if (File.Exists(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + texturepaths[i]))
			{
				textures[i] = new Texture2D(2, 2);
				ImageConversion.LoadImage(textures[i], File.ReadAllBytes(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + texturepaths[i]));
			}
		}
		((MonoBehaviour)this).StartCoroutine(SMDtext());
	}

	public void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Expected O, but got Unknown
		if (!(((Scene)(ref scene)).name == "MainMenu") && !(((Scene)(ref scene)).name == "InitScene") && !(((Scene)(ref scene)).name == "InitSceneLaunchOptions"))
		{
			((MonoBehaviour)this).StartCoroutine(LoadTextures());
			LoadGifPosterImgs();
			((MonoBehaviour)this).StopCoroutine(RunGifPoster());
			((MonoBehaviour)this).StartCoroutine(RunGifPoster());
		}
		else if (((Scene)(ref scene)).name == "MainMenu")
		{
			((MonoBehaviour)this).StartCoroutine(LoadReLOGO(reLOGOtexture2D, new MenuManager()));
		}
	}

	private void LoadGifPosterImgs()
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Expected O, but got Unknown
		string text = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\_gifPosterDump__";
		DirectoryInfo directoryInfo = new DirectoryInfo(text);
		FileInfo[] files = directoryInfo.GetFiles();
		files = files.OrderBy((FileInfo file) => file.Name).ToArray();
		totalFrameCount = files.Length - 1;
		gifPosterFrames = (Texture2D[])(object)new Texture2D[totalFrameCount];
		for (int i = 0; i < totalFrameCount; i++)
		{
			gifPosterFrames[i] = new Texture2D(2, 2);
			byte[] array = File.ReadAllBytes(Path.Combine(text, files[i].Name));
			ImageConversion.LoadImage(gifPosterFrames[i], array);
			if (i == totalFrameCount)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Gif POSTER LOADED !\n - " + i + " Items Loaded"));
			}
		}
	}

	private IEnumerator LoadReLOGO(Texture2D tex, MenuManager __instance)
	{
		yield return (object)new WaitForSeconds(0.01f);
		if ((Object)(object)tex == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"The provided texture is null. -- RELOGO");
			yield return null;
		}
		else if (File.Exists(logoFilePath))
		{
			byte[] array = File.ReadAllBytes(logoFilePath);
			ImageConversion.LoadImage(tex, array);
			tex.PremultiplyAlpha();
			((Texture)tex).filterMode = (FilterMode)0;
			tex.Apply();
			Transform transform = GameObject.Find("HeaderImage").transform;
			if ((Object)(object)transform != (Object)null)
			{
				Image component = ((Component)transform).gameObject.GetComponent<Image>();
				if ((Object)(object)component != (Object)null)
				{
					Sprite sprite = Sprite.Create(tex, new Rect(0f, 0f, (float)((Texture)tex).width, (float)((Texture)tex).height), new Vector2(0.5f, 0.5f));
					component.sprite = sprite;
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Image component not found on HeaderImage GameObject.");
				}
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"HeaderImage GameObject not found in the scene hierarchy.");
			}
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Logo file not found at: " + logoFilePath));
		}
	}

	private IEnumerator SMDtext()
	{
		SceneManager.sceneLoaded += OnSceneLoaded;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"\r\n $$$$$$\\  $$\\      $$\\ $$$$$$$\\  \r\n$$  __$$\\ $$$\\    $$$ |$$  __$$\\ \r\n$$ /  \\__|$$$$\\  $$$$ |$$ |  $$ |\r\n\\$$$$$$\\  $$\\$$\\$$ $$ |$$ |  $$ |\r\n \\____$$\\ $$ \\$$$  $$ |$$ |  $$ |\r\n$$\\   $$ |$$ |\\$  /$$ |$$ |  $$ |\r\n\\$$$$$$  |$$ | \\_/ $$ |$$$$$$$  |\r\n \\______/ \\__|     \\__|\\_______/ \r\n                                 \r\n                                 \r\n                                 \r\n");
		yield return (object)new WaitForSeconds(0.1f);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"CREDITS TO CapyCat for the original MOD");
		yield return (object)new WaitForSeconds(0.1f);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Their script has been modified to fit the needs of COMPANY");
		yield return (object)new WaitForSeconds(0.3f);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"https://thunderstore.io/c/lethal-company/p/CapyCat/Solos_Poster_Changer/ \r\n We hope you enjoy youre time \r\n These mods do not effect gameplay \r\n They are completly cosmetic \r\n The exeption is ofcorse the extra maps which were added");
		yield return (object)new WaitForSeconds(0.2f);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Enjoy the SMD experiece :))");
		yield return (object)new WaitForSeconds(0.1f);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"- Sleepy Dre");
		yield return true;
	}

	private IEnumerator RunGifPoster()
	{
		if (reloadCheck != 0)
		{
			yield break;
		}
		MeshRenderer GIFRendComponent = GameObject.Find("Environment/HangarShip/Plane.001").GetComponent<MeshRenderer>();
		yield return (object)new WaitForSeconds(1f);
		reloadCheck = 1;
		for (int j = 0; j < 1000000; j++)
		{
			yield return (object)new WaitForSeconds(0.2f);
			for (int i = 0; i < totalFrameCount; i++)
			{
				((Renderer)GIFRendComponent).materials[1].mainTexture = (Texture)(object)gifPosterFrames[i];
				yield return (object)new WaitForSeconds(0.04f);
			}
			if (j == 999999)
			{
				reloadCheck = 0;
			}
		}
	}

	private IEnumerator LoadTextures()
	{
		yield return (object)new WaitForSeconds(1f);
		for (int i = 0; i < texturepaths.Length; i++)
		{
			GameObject val = GameObject.Find(hierarchypaths[i]);
			if (!((Object)(object)val != (Object)null))
			{
				continue;
			}
			Renderer component = val.GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				component.materials[materialnumber[i] - 1].mainTexture = (Texture)(object)textures[i];
				continue;
			}
			MeshRenderer component2 = val.GetComponent<MeshRenderer>();
			if ((Object)(object)component2 != (Object)null)
			{
				((Renderer)component2).materials[materialnumber[i] - 1].mainTexture = (Texture)(object)textures[i];
			}
		}
	}
}