Patch_Chunk_GeneratePlatforms.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using HarmonyLib;
  2. using GadgetCore.API;
  3. using UnityEngine;
  4. using System.Collections;
  5. namespace First.Patches
  6. {
  7. [HarmonyPatch(typeof(Chunk))]
  8. [HarmonyPatch("GeneratePlatforms")]
  9. [HarmonyGadget("First")]
  10. public static class Patch_Chunk_GeneratePlatforms
  11. {
  12. [HarmonyPrefix]
  13. public static bool Prefix(Chunk __instance)
  14. {
  15. int type = UnityEngine.Random.Range(0, 4);
  16. if (type < 3)
  17. {
  18. for (int i = 0; i < 5; i++)
  19. {
  20. if (UnityEngine.Random.Range(0, 2) == 0)
  21. {
  22. Network.Instantiate(Resources.Load("plat/plat1"), GetPlatPos(i, __instance.transform.position), Quaternion.identity, 0);
  23. }
  24. }
  25. }
  26. else
  27. {
  28. for (int i = 0; i < 5; i++)
  29. {
  30. if (UnityEngine.Random.Range(0, 2) == 0)
  31. {
  32. Network.Instantiate(Resources.Load("plat/platMove"), GetPlatPos(i, __instance.transform.position), Quaternion.identity, 0);
  33. }
  34. }
  35. }
  36. // Add code to run before `MethodName` is called.
  37. return false; // Return false to prevent the vanilla method from running.
  38. }
  39. // Token: 0x0600013F RID: 319 RVA: 0x0001AB44 File Offset: 0x00018F44
  40. private static Vector3 GetPlatPos(int i, Vector3 position)
  41. {
  42. Vector3 result = new Vector3(0f, 0f, 0f);
  43. float num = (float)UnityEngine.Random.Range(-10, 11) * 0.7f;
  44. float num2 = (float)UnityEngine.Random.Range(-7, 8) * 0.7f;
  45. switch (i)
  46. {
  47. case 0:
  48. result = new Vector3(position.x - 16f + num, position.y + 16f + num2, 5f);
  49. break;
  50. case 1:
  51. result = new Vector3(position.x + 16f + num, position.y + 16f + num2, 5f);
  52. break;
  53. case 2:
  54. result = new Vector3(position.x + 16f + num, position.y - 16f + num2, 5f);
  55. break;
  56. case 3:
  57. result = new Vector3(position.x - 16f + num, position.y - 16f + num2, 5f);
  58. break;
  59. case 4:
  60. result = new Vector3(position.x + num * 2f, position.y + num2, 5f);
  61. break;
  62. }
  63. return result;
  64. }
  65. /*
  66. [HarmonyPostfix]
  67. public static void Postfix(ClassName __instance)
  68. {
  69. // Add code to run after `MethodName` is called.
  70. }
  71. */
  72. }
  73. }