using UnityEngine; using GadgetCore.API; using UnityEngine.SceneManagement; using GadgetCore.API.ConfigMenu; using System; using System.Collections.Generic; namespace SplashTexts { [Gadget("SplashTexts")] public class SplashTexts : Gadget { public const string MOD_VERSION = "1.0"; // Set this to the version of your mod. public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file. public override IGadgetConfigMenu GetConfigMenu() { return null; } public override string GetModDescription() { return "A mod that adds random splash texts to the main menu."; } protected override void Initialize() { Logger.Log("Platform Block v" + Info.Mod.Version); Core.logger = Logger; SceneManager.sceneLoaded += OnSceneLoaded; ChangeMenuText(); } internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if (scene.buildIndex == 0) { ChangeMenuText(); } } private static Texture2D texture2D = GadgetCoreAPI.LoadTexture2D("roguelandsTitle.png"); private static Texture2D texture2DL = GadgetCoreAPI.LoadTexture2D("roguelandsTitleL2.png"); private static void ChangeMenuText() { try { var titleElement = GameObject.Find("MAIN").transform.Find("-").gameObject; var renderer = titleElement.GetComponent(); if (Core.defaultTitleTexture == null) Core.defaultTitleTexture = renderer.material.mainTexture; if (random.Next(2) == 0) { renderer.material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = texture2DL }; } else if (random.Next(2) == 0) { renderer.material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = texture2D }; } else { renderer.material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = Core.defaultTitleTexture }; } var text = GetText(); var textElement = GameObject.Find("MAIN").transform.Find("-").Find("txtALPHA").gameObject; var textElementShadow = textElement.transform.Find("txt0").gameObject; textElement.GetComponent().color = SpliceColor(ref text); var shadowText = SpliceShadow(ref text); textElement.GetComponent().text = text; textElementShadow.GetComponent().text = shadowText; } catch (Exception e) { Core.logger.LogConsole(e); } } private static System.Random random = new System.Random(); private static string GetText() { List texts = new List(); texts.Add("v1.5.1 Deluxe"); texts.Add("#C#AAAAFF#Infinity Edition"); texts.Add("Gadget Core " + GadgetCoreAPI.GetFullVersion() + " Edition"); texts.Add("There are mods?"); texts.Add("1 + 5 = 1#S#1 + 5 = 6"); texts.Add("v1.5.1#S#v1.5"); texts.Add("Magicite 2"); texts.Add("I wouldn't talk to the guy with the pickaxe."); return texts[random.Next(texts.Count)]; } private static Color SpliceColor(ref string s) { if (s.StartsWith("#C#")) { try { var ar = s.Split(new char[] { '#' }, 4); s = ar[3]; if (ar[2].Length == 6) { var i1 = Convert.ToInt32(ar[2].Substring(0, 2), 16); var i2 = Convert.ToInt32(ar[2].Substring(2, 2), 16); var i3 = Convert.ToInt32(ar[2].Substring(4, 2), 16); return new Color(((float)i1) / 0xFF, ((float)i2) / 0xFF, ((float)i3) / 0xFF); } } catch { } } return new Color(((float)0xFF) / 0xFF, ((float)0xD7) / 0xFF, ((float)0x31) / 0xFF); } private static string SpliceShadow(ref string s) { if (s.Contains("#S#")) { try { var ar = s.Split(new string[] { "#S#" }, 2, StringSplitOptions.None); s = ar[0]; return ar[1]; } catch { } } return s; } } }