SplashTexts.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using UnityEngine;
  2. using GadgetCore.API;
  3. using UnityEngine.SceneManagement;
  4. using GadgetCore.API.ConfigMenu;
  5. using System;
  6. using System.Collections.Generic;
  7. namespace SplashTexts
  8. {
  9. [Gadget("SplashTexts")]
  10. public class SplashTexts : Gadget<SplashTexts>
  11. {
  12. public const string MOD_VERSION = "1.0"; // Set this to the version of your mod.
  13. public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.
  14. public override IGadgetConfigMenu GetConfigMenu() { return null; }
  15. public override string GetModDescription()
  16. {
  17. return "A mod that adds random splash texts to the main menu.";
  18. }
  19. protected override void Initialize()
  20. {
  21. Logger.Log("Platform Block v" + Info.Mod.Version);
  22. Core.logger = Logger;
  23. SceneManager.sceneLoaded += OnSceneLoaded;
  24. ChangeMenuText();
  25. }
  26. internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
  27. {
  28. if (scene.buildIndex == 0)
  29. {
  30. ChangeMenuText();
  31. }
  32. }
  33. private static Texture2D texture2D = GadgetCoreAPI.LoadTexture2D("roguelandsTitle.png");
  34. private static Texture2D texture2DL = GadgetCoreAPI.LoadTexture2D("roguelandsTitleL2.png");
  35. private static void ChangeMenuText()
  36. {
  37. try
  38. {
  39. var titleElement = GameObject.Find("MAIN").transform.Find("-").gameObject;
  40. var renderer = titleElement.GetComponent<Renderer>();
  41. if (Core.defaultTitleTexture == null)
  42. Core.defaultTitleTexture = renderer.material.mainTexture;
  43. if (random.Next(2) == 0)
  44. {
  45. renderer.material = new Material(Shader.Find("Unlit/Transparent"))
  46. {
  47. mainTexture = texture2DL
  48. };
  49. }
  50. else if (random.Next(2) == 0)
  51. {
  52. renderer.material = new Material(Shader.Find("Unlit/Transparent"))
  53. {
  54. mainTexture = texture2D
  55. };
  56. }
  57. else
  58. {
  59. renderer.material = new Material(Shader.Find("Unlit/Transparent"))
  60. {
  61. mainTexture = Core.defaultTitleTexture
  62. };
  63. }
  64. var text = GetText();
  65. var textElement = GameObject.Find("MAIN").transform.Find("-").Find("txtALPHA").gameObject;
  66. var textElementShadow = textElement.transform.Find("txt0").gameObject;
  67. textElement.GetComponent<TextMesh>().color = SpliceColor(ref text);
  68. var shadowText = SpliceShadow(ref text);
  69. textElement.GetComponent<TextMesh>().text = text;
  70. textElementShadow.GetComponent<TextMesh>().text = shadowText;
  71. }
  72. catch (Exception e) { Core.logger.LogConsole(e); }
  73. }
  74. private static System.Random random = new System.Random();
  75. private static string GetText()
  76. {
  77. List<string> texts = new List<string>();
  78. texts.Add("v1.5.1 Deluxe");
  79. texts.Add("#C#AAAAFF#Infinity Edition");
  80. texts.Add("Gadget Core " + GadgetCoreAPI.GetFullVersion() + " Edition");
  81. texts.Add("There are mods?");
  82. texts.Add("1 + 5 = 1#S#1 + 5 = 6");
  83. texts.Add("v1.5.1#S#v1.5");
  84. texts.Add("Magicite 2");
  85. texts.Add("I wouldn't talk to the guy with the pickaxe.");
  86. return texts[random.Next(texts.Count)];
  87. }
  88. private static Color SpliceColor(ref string s)
  89. {
  90. if (s.StartsWith("#C#"))
  91. {
  92. try
  93. {
  94. var ar = s.Split(new char[] { '#' }, 4);
  95. s = ar[3];
  96. if (ar[2].Length == 6)
  97. {
  98. var i1 = Convert.ToInt32(ar[2].Substring(0, 2), 16);
  99. var i2 = Convert.ToInt32(ar[2].Substring(2, 2), 16);
  100. var i3 = Convert.ToInt32(ar[2].Substring(4, 2), 16);
  101. return new Color(((float)i1) / 0xFF, ((float)i2) / 0xFF, ((float)i3) / 0xFF);
  102. }
  103. }
  104. catch { }
  105. }
  106. return new Color(((float)0xFF) / 0xFF, ((float)0xD7) / 0xFF, ((float)0x31) / 0xFF);
  107. }
  108. private static string SpliceShadow(ref string s)
  109. {
  110. if (s.Contains("#S#"))
  111. {
  112. try
  113. {
  114. var ar = s.Split(new string[] { "#S#" }, 2, StringSplitOptions.None);
  115. s = ar[0];
  116. return ar[1];
  117. }
  118. catch { }
  119. }
  120. return s;
  121. }
  122. }
  123. }