Pause.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #pragma once
  2. #include "../Constants.h"
  3. #include "EmulatorComponent.h"
  4. #include "PlayerData.h"
  5. #include "GameState.h"
  6. #include "../Utilities/Drawing.h"
  7. #include "Input/InputState.h"
  8. #include "Input/TouchSliderState.h"
  9. #include "Input/TouchPanelState.h"
  10. #include <string>
  11. #include <vector>
  12. #include <chrono>
  13. namespace TLAC::Components
  14. {
  15. class Pause : public EmulatorComponent
  16. {
  17. public:
  18. Pause();
  19. ~Pause();
  20. virtual const char* GetDisplayName() override;
  21. virtual void Initialize(ComponentsManager*) override;
  22. virtual void Update() override;
  23. virtual void UpdatePostInput() override;
  24. virtual void UpdateDraw2D() override;
  25. virtual void OnFocusLost() override;
  26. static bool pause; // set pause to change pause state
  27. static bool giveUp; // set give up to end current song
  28. static bool autoPause; // pause when window loses focus
  29. private:
  30. // this is a mess of static so that menuItems can work
  31. static bool isPauseKeyTapped();
  32. static bool isInGame();
  33. static std::vector<bool> streamPlayStates;
  34. static void InjectCode(void* address, const std::vector<uint8_t> data);
  35. static bool isPaused; // tracks internal state
  36. static void saveOldPatchOps();
  37. static std::vector<uint8_t> origAetMovOp;
  38. static uint8_t* aetMovPatchAddress;
  39. static std::vector<uint8_t> origFramespeedOp;
  40. static uint8_t* framespeedPatchAddress;
  41. static std::vector<uint8_t> origAgeageHairOp;
  42. static uint8_t* ageageHairPatchAddress;
  43. static bool hookedGiveUpFunc(void* cls);
  44. static void setSEVolume(int amount);
  45. static PlayerData* playerData;
  46. static InputState* inputState;
  47. static TouchSliderState* sliderState;
  48. static TouchPanelState* panelState;
  49. static ComponentsManager* componentsManager;
  50. static const JvsButtons allButtons = (JvsButtons)(JVS_START | JVS_TRIANGLE | JVS_SQUARE | JVS_CROSS | JVS_CIRCLE | JVS_L | JVS_R); // deliberately only has control panel buttons
  51. static JvsButtons filteredButtons;
  52. static int lastTouchType;
  53. static const int menuX = 640;
  54. static const int menuY = 360;
  55. static const int menuItemWidth = 150;
  56. static const int menuItemHeight = 36;
  57. static const int menuItemPadding = 12;
  58. static const int menuItemTotalHeight = menuItemHeight + menuItemPadding;
  59. static const int menuTextSize = 24;
  60. static const uint32_t bgLayer = 0x18;
  61. static const uint32_t contentLayer = 0x19; // same as startup screen
  62. static bool showUI;
  63. static int selResultAet1;
  64. static int selResultAet2;
  65. static int selResultAet3;
  66. static int selResultAet4;
  67. static int triangleAet;
  68. static int squareAet;
  69. static int crossAet;
  70. static int circleAet;
  71. enum menusets
  72. {
  73. MENUSET_MAIN = 0,
  74. MENUSET_SEVOL = 1,
  75. };
  76. struct menuItem
  77. {
  78. std::string name;
  79. void(*callback)();
  80. bool keyRepeat; // unimplemented
  81. menuItem(std::string _name, void(*_callback)(), bool _keyRepeat)
  82. {
  83. name = _name;
  84. callback = _callback;
  85. keyRepeat = _keyRepeat;
  86. }
  87. };
  88. struct menuSet
  89. {
  90. std::string name;
  91. std::vector<menuItem> items;
  92. };
  93. static int curMenuPos;
  94. static std::vector<std::pair<menusets, int>> menuHistory; // used for implementing back button in menus
  95. static menusets curMenuSet;
  96. static std::chrono::time_point<std::chrono::high_resolution_clock> menuItemMoveTime; // used for animation
  97. // static void mainmenu() { setMenuPos(MENUSET_MAIN, 0); menuHistory.resize(0); };
  98. static void menuback()
  99. {
  100. if (menuHistory.size() == 0)
  101. {
  102. // mainmenu();
  103. unpause();
  104. }
  105. else
  106. {
  107. std::pair<menusets, int> menuPos = menuHistory.back();
  108. menuHistory.pop_back();
  109. setMenuPos(menuPos.first, menuPos.second, false);
  110. }
  111. }
  112. static void unpause() { pause = false; };
  113. static void restart()
  114. {
  115. /*
  116. 140d0b510+2 = 0, 140d0b510+14 = 8 for restart
  117. also 140cdd8d0+8 (something less than 0x1a but idk what) -- controls a switch statement in FUN_1400fddc0
  118. 0x18: PV seems good, audio good, chart and score broken? -- timing resets, notes don't
  119. 0x14: PVs a little bugged (not major), chart and scoring fine, life still doesn't reset
  120. 0x10: life resets now, but old graphics don't clear
  121. 0x15: same as 0x14
  122. 0x16: doesn't actually reset????
  123. 0x17: crash
  124. 0x12: like 0x10 but life isn't cleared
  125. case 0x11 seems to clear life
  126. case 0x15 seems to clear score (maybe note data)
  127. case 0x18 seems to fix timing
  128. patch 0x15 at 1401038cd (was 0x12), 0x18 at 140103b94 (was 0x16)
  129. then call with 0x11
  130. hopefully it'll work
  131. percentage doesn't fully reset by the looks of it????
  132. rip
  133. (actually was hold and slide scores -- fixed by manually clearing them now)
  134. */
  135. // inject flow overrides to switch cases in FUN_1400fddc0
  136. InjectCode((void*)0x1401038cd, { 0x15 }); InjectCode((void*)0x140103b94, { 0x18 });
  137. // set parameters
  138. *(uint8_t*)PV_STATE_ADDRESS = 0; *(uint8_t*)PV_LOADING_STATE_ADDRESS = 8; *(int*)PV_INNER_LOADING_STATE_ADDRESS = 0x11;
  139. void(*doLoading)(uint64_t) = (void(*)(uint64_t))0x1400fddc0;
  140. // do loading until definitely done
  141. while (*(int*)PV_INNER_LOADING_STATE_ADDRESS < 0x18)
  142. {
  143. doLoading(0x140cdd8d0);
  144. }
  145. // for some reason the above doesn't reset all scoring stuff
  146. *(int*)0x140D0A9BC = 0; // total holds
  147. *(int*)0x140D0A9B8 = 0; // hold + multi
  148. *(int*)0x140D0A9C0 = 0; // slide
  149. *(uint8_t*)0x140D0A50C = 0; // not clear flag
  150. *(char*)0x140D0AA0F = 0; // chance time
  151. // revert patches and unpause
  152. InjectCode((void*)0x1401038cd, { 0x12 }); InjectCode((void*)0x140103b94, { 0x16 });
  153. unpause();
  154. }
  155. static void giveup() { giveUp = true; };
  156. static void sevolmenu() { setMenuPos(MENUSET_SEVOL, 1); };
  157. static void sevolplus() { setSEVolume(10); };
  158. static void sevolminus() { setSEVolume(-10); };
  159. // contents are in Pause.cpp because they can't be inline here for a static (const) array/vec
  160. static std::vector<menuSet> menu;
  161. static void setMenuPos(menusets set, int pos, bool updateHistory = true);
  162. static float getMenuAnimPos();
  163. static TLAC::Utilities::Drawing::Point getMenuItemCoords(menusets set, int pos);
  164. };
  165. }