Patch_SpawnerScript_World.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. using GadgetCore.API;
  2. using HarmonyLib;
  3. using System.Collections;
  4. using System.Reflection;
  5. using UnityEngine;
  6. namespace WorldPlatforms.Patches
  7. {
  8. [HarmonyPatch(typeof(SpawnerScript))]
  9. [HarmonyPatch("World")]
  10. [HarmonyGadget("WorldPlatforms")]
  11. public static class Patch_SpawnerScript_World
  12. {
  13. [HarmonyPostfix]
  14. public static bool Prefix(SpawnerScript __instance, int[] s)
  15. {
  16. __instance.StartCoroutine(__instance.SpawnerScriptWorld(s));
  17. return false;
  18. }
  19. public static IEnumerator SpawnerScriptWorld(this SpawnerScript instance, int[] s)
  20. {
  21. if (GameScript.districtLevel == 0)
  22. {
  23. GameScript.districtLevel = 1;
  24. }
  25. var field = typeof(SpawnerScript).GetField("gameScript", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
  26. var gameScript = field.GetValue(instance) as GameScript;
  27. MenuScript.player.GetComponent<NetworkView>().RPC("Invis", RPCMode.All, new object[0]);
  28. gameScript.fadeObj.SendMessage("fadeOut2");
  29. yield return new WaitForSeconds(0.5f);
  30. MenuScript.player.SendMessage("Reset");
  31. GameScript.inInstance = true;
  32. instance.ship.SetActive(false);
  33. SpawnerScript.curBiome = s[0];
  34. SpawnerScript.lastBiome = s[0];
  35. instance.bg[0].GetComponent<Renderer>().material = (Material)Resources.Load("bg/b" + SpawnerScript.curBiome + "bg0");
  36. instance.bg[1].GetComponent<Renderer>().material = (Material)Resources.Load("bg/b" + SpawnerScript.curBiome + "bg1");
  37. instance.bg[2].GetComponent<Renderer>().material = (Material)Resources.Load("bg/b" + SpawnerScript.curBiome + "bg2");
  38. instance.bg[3].GetComponent<Renderer>().material = (Material)Resources.Load("bg/b" + SpawnerScript.curBiome + "bg3");
  39. //float[] pc = instance.GetParallaxColors(SpawnerScript.curBiome);
  40. //float[] lc = instance.GetLight(SpawnerScript.curBiome);
  41. //instance.mainLight.gameObject.SetActive(true);
  42. //instance.mainLight.GetComponent<Light>().color = new Color(lc[0], lc[1], lc[2], lc[3]);
  43. //instance.backLights.SetActive(true);
  44. //instance.backLights.GetComponent<Renderer>().material = (Material)Resources.Load("par/parallax" + SpawnerScript.curBiome);
  45. var fieldGridWidth = typeof(SpawnerScript).GetField("gridWidth", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
  46. var gridWidth = (int) fieldGridWidth.GetValue(instance);
  47. var fieldGridHeight = typeof(SpawnerScript).GetField("gridHeight", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
  48. var gridHeight = (int) fieldGridHeight.GetValue(instance);
  49. var fieldChunks = typeof(SpawnerScript).GetField("chunks", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
  50. var chunks = fieldChunks.GetValue(instance) as GameObject[];
  51. var fieldMidChunks = typeof(SpawnerScript).GetField("midChunks", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
  52. var midChunks = fieldMidChunks.GetValue(instance) as GameObject[];
  53. int[,] grid = new int[gridWidth,gridHeight];
  54. int b = 0;
  55. int temp = 1;
  56. int y = -64 * (gridHeight / 2);
  57. int num = 0;
  58. int midCounter = 0;
  59. for (int i = 0; i < gridWidth; i++)
  60. {
  61. for (b = 0; b <gridHeight; b++)
  62. {
  63. grid[i, b] = s[temp];
  64. temp++;
  65. }
  66. }
  67. chunks[num] = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("z/entrance"), new Vector3(224.5f, 0f, 5f), Quaternion.Euler(0f, 0f, 0f));
  68. num++;
  69. Texture2D texture2DSolid = GadgetCoreAPI.LoadTexture2D("midCoverChunk0.png", false);
  70. Texture2D texture2DNonSolid = GadgetCoreAPI.LoadTexture2D("midHiddenChunk0.png", false);
  71. for (int i = 0; i < gridWidth; i++)
  72. {
  73. for (b = 0; b <gridHeight; b++)
  74. {
  75. if (grid[i, b] > 0)
  76. {
  77. chunks[num] = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("z/chunk"), new Vector3((float)(300 + i * 128), (float)(y + b * 64), 5f), Quaternion.Euler(0f, 180f, 180f));
  78. int[] array = new int[4];
  79. if (b > 0 && grid[i, b + 1] > 0)
  80. {
  81. array[0] = 1;
  82. }
  83. if (i < gridWidth - 1 && grid[i + 1, b] > 0)
  84. {
  85. array[1] = 1;
  86. }
  87. if (b <gridHeight - 1 && grid[i, b - 1] > 0)
  88. {
  89. array[2] = 1;
  90. }
  91. if (i > 0 && grid[i - 1, b] > 0)
  92. {
  93. array[3] = 1;
  94. }
  95. chunks[num].SendMessage("InitializeSides", array);
  96. num++;
  97. if (SpawnerScript.curBiome != 8 && SpawnerScript.curBiome != 11)
  98. {
  99. GameObject gameObject = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("z/midChunk0"), new Vector3((float)(300 + i * 128), (float)(y + b * 64), 5f), Quaternion.Euler(0f, 180f, 180f));
  100. gameObject.layer = 23;
  101. BoxCollider colliderRight = gameObject.GetComponent<BoxCollider>();
  102. colliderRight.size = new Vector3(0.0625f, 0.375f, 5);
  103. colliderRight.center = new Vector3(0.71875f, 0, 5);
  104. BoxCollider colliderTop = gameObject.AddComponent<BoxCollider>();
  105. colliderTop.size = new Vector3(1.5f, 0.0625f, 5);
  106. colliderTop.center = new Vector3(0f, -0.15625f, 5);
  107. BoxCollider colliderBottom = gameObject.AddComponent<BoxCollider>();
  108. colliderBottom.size = new Vector3(1.5f, 0.0625f, 5);
  109. colliderBottom.center = new Vector3(0f, 0.15625f, 5);
  110. GameObject triggerObject = new GameObject("Hidden Trigger");
  111. triggerObject.transform.SetParent(gameObject.transform);
  112. triggerObject.transform.localScale = new Vector3(1.4375f, 0.25f, 5);
  113. triggerObject.transform.localPosition = new Vector3(-0.03125f, 0f, 5);
  114. BoxCollider trigger = triggerObject.AddComponent<BoxCollider>();
  115. trigger.gameObject.layer = 0;
  116. trigger.isTrigger = true;
  117. NonSolidWallScript script = trigger.gameObject.AddComponent<NonSolidWallScript>();
  118. script.InitVars(texture2DSolid, texture2DNonSolid, gameObject.GetComponent<Renderer>());
  119. midChunks[midCounter] = gameObject;
  120. midChunks[midCounter].gameObject.SendMessage("Init", chunks[num - 1]);
  121. midCounter++;
  122. /*
  123. if (grid[i, b] > 4)
  124. {
  125. midChunks[midCounter] = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("z/midChunk0"), new Vector3((float)(300 + i * 128), (float)(y + b * 64), 5f), Quaternion.Euler(0f, 180f, 180f));
  126. midChunks[midCounter].gameObject.SendMessage("Init", chunks[num - 1]);
  127. midCounter++;
  128. }
  129. else if (grid[i, b] > 2)
  130. {
  131. GameObject gameObject = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("z/midChunk0"), new Vector3((float)(300 + i * 128), (float)(y + b * 64), 5f), Quaternion.Euler(0f, 180f, 180f));
  132. BoxCollider collider = gameObject.GetComponent<BoxCollider>();
  133. collider.center = new Vector3(0.71875f, 0, 5);
  134. collider.size = new Vector3(0.0625f, 0.375f, 5);
  135. midChunks[midCounter] = gameObject;
  136. midChunks[midCounter].gameObject.SendMessage("Init", chunks[num - 1]);
  137. midCounter++;
  138. }
  139. else if (grid[i, b] > 0)
  140. {
  141. midChunks[midCounter] = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("z/midChunk1"), new Vector3((float)(300 + i * 128), (float)(y + b * 64), 5f), Quaternion.Euler(0f, 180f, 180f));
  142. midChunks[midCounter].gameObject.SendMessage("Init", chunks[num - 1]);
  143. midCounter++;
  144. }*/
  145. }
  146. }
  147. }
  148. }
  149. chunks[num - 1].SendMessage("AlmostEnd");
  150. chunks[num] = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("z/exit"), new Vector3(503.5f, chunks[num - 1].transform.position.y, 5f), Quaternion.Euler(0f, 0f, 180f));
  151. num++;
  152. if (Network.isServer)
  153. {
  154. //instance.SpawnObjectives(num - 1);
  155. chunks[num - 1].SendMessage("SpawnEndPortal");
  156. }
  157. gameScript.TeleportPlayer(0);
  158. yield return new WaitForSeconds(0.8f);
  159. instance.musicbox.SendMessage("PlayTune", SpawnerScript.curBiome);
  160. gameScript.fadeObj.SendMessage("fadeIn2");
  161. GameScript.wormBossCounter = 0;
  162. GameScript.hivemindCounter = 0;
  163. }
  164. }
  165. }