Pause.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. #include "Pause.h"
  2. #include "../Constants.h"
  3. #include "GameState.h"
  4. #include "ComponentsManager.h"
  5. #include "../Utilities/Drawing.h"
  6. #include "GL/glut.h"
  7. #include "detours.h"
  8. #include <windows.h>
  9. #include <vector>
  10. #include <chrono>
  11. #include "../FileSystem/ConfigFile.h"
  12. #include "../framework.h"
  13. namespace TLAC::Components
  14. {
  15. using TLAC::Utilities::Drawing;
  16. bool Pause::pause = false;
  17. bool Pause::isPaused = false;
  18. bool Pause::giveUp = false;
  19. bool Pause::autoPause = false;
  20. bool Pause::showUI = true;
  21. int Pause::selResultAet1 = 0;
  22. int Pause::selResultAet2 = 0;
  23. int Pause::selResultAet3 = 0;
  24. int Pause::selResultAet4 = 0;
  25. int Pause::triangleAet = 0;
  26. int Pause::squareAet = 0;
  27. int Pause::crossAet = 0;
  28. int Pause::circleAet = 0;
  29. int Pause::curMenuPos = 0;
  30. std::vector<std::pair<Pause::menusets, int>> Pause::menuHistory;
  31. Pause::menusets Pause::curMenuSet = MENUSET_MAIN;
  32. std::chrono::time_point<std::chrono::high_resolution_clock> Pause::menuItemMoveTime;
  33. std::vector<uint8_t> Pause::origAetMovOp;
  34. uint8_t* Pause::aetMovPatchAddress = (uint8_t*)0x1401703b3;
  35. std::vector<uint8_t> Pause::origFramespeedOp;
  36. uint8_t* Pause::framespeedPatchAddress = (uint8_t*)0x140192D50;
  37. std::vector<uint8_t> Pause::origAgeageHairOp;
  38. uint8_t* Pause::ageageHairPatchAddress = (uint8_t*)0x14054352c;
  39. std::vector<bool> Pause::streamPlayStates;
  40. bool(*divaGiveUpFunc)(void*) = (bool(*)(void* cls))GIVEUP_FUNC_ADDRESS;
  41. PlayerData* Pause::playerData;
  42. InputState* Pause::inputState;
  43. TouchSliderState* Pause::sliderState;
  44. TouchPanelState* Pause::panelState;
  45. ComponentsManager* Pause::componentsManager;
  46. JvsButtons Pause::filteredButtons;
  47. int Pause::lastTouchType = 0;
  48. std::vector<Pause::menuSet> Pause::menu = {
  49. {
  50. "PAUSED",
  51. {
  52. { "RESUME", unpause, false },
  53. { "RESTART", restart, false },
  54. { "SE VOLUME", sevolmenu, false },
  55. { "GIVE UP", giveup, false },
  56. }
  57. },
  58. {
  59. "SE VOLUME",
  60. {
  61. { "+", sevolplus, true },
  62. { "XX", menuback, false },
  63. { "-", sevolminus, true },
  64. }
  65. },
  66. };
  67. Pause::Pause()
  68. {
  69. }
  70. Pause::~Pause()
  71. {
  72. }
  73. const char* Pause::GetDisplayName()
  74. {
  75. return "pause";
  76. }
  77. void Pause::saveOldPatchOps()
  78. {
  79. origAetMovOp.resize(8);
  80. memcpy(origAetMovOp.data(), aetMovPatchAddress, 8);
  81. origFramespeedOp.resize(4);
  82. memcpy(origFramespeedOp.data(), framespeedPatchAddress, 4);
  83. origAgeageHairOp.resize(3);
  84. memcpy(origAgeageHairOp.data(), ageageHairPatchAddress, 3);
  85. }
  86. void Pause::Initialize(ComponentsManager* manager)
  87. {
  88. inputState = (InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS);
  89. playerData = (PlayerData*)PLAYER_DATA_ADDRESS;
  90. sliderState = (TouchSliderState*)SLIDER_CTRL_TASK_ADDRESS;
  91. panelState = (TouchPanelState*)TASK_TOUCH_ADDRESS;
  92. componentsManager = manager;
  93. TLAC::FileSystem::ConfigFile config(TLAC::framework::GetModuleDirectory(), "keyconfig.ini");
  94. config.OpenRead();
  95. autoPause = config.GetBooleanValue("autopause");
  96. saveOldPatchOps();
  97. DetourTransactionBegin();
  98. DetourUpdateThread(GetCurrentThread());
  99. DetourAttach(&(PVOID&)divaGiveUpFunc, hookedGiveUpFunc);
  100. DetourTransactionCommit();
  101. }
  102. void Pause::Update()
  103. {
  104. }
  105. // put these here because my local VS was being a bitch and compiling the place that uses them wrong when they were inline
  106. // updating VS would probably fix it, but this was quicker
  107. // -somewhatlurker
  108. int* resWidth = (int*)RESOLUTION_WIDTH_ADDRESS;
  109. int* resHeight = (int*)RESOLUTION_HEIGHT_ADDRESS;
  110. void Pause::UpdatePostInput()
  111. {
  112. if (pause)
  113. {
  114. // enter pause mode on state transition
  115. if (!isPaused)
  116. {
  117. ((void(*)())DSC_PAUSE_FUNC_ADDRESS)();
  118. saveOldPatchOps();
  119. InjectCode(aetMovPatchAddress, { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 });
  120. InjectCode(framespeedPatchAddress, { 0x0f, 0x57, 0xc0, 0xc3 }); // XORPS XMM0,XMM0; RET
  121. InjectCode(ageageHairPatchAddress, { 0x0f, 0x57, 0xdb }); // XORPS XMM3,XMM3
  122. uint64_t audioMixerAddr = *(uint64_t*)(AUDIO_MAIN_CLASS_ADDRESS + 0x70);
  123. uint64_t audioStreamsAddress = *(uint64_t*)(audioMixerAddr + 0x18);
  124. int nAudioStreams = *(uint64_t*)(audioMixerAddr + 0x20);
  125. for (int i = 0; i < nAudioStreams; i++)
  126. {
  127. uint32_t* playstate = (uint32_t*)(audioStreamsAddress + i * 0x50 + 0x18);
  128. if (i < streamPlayStates.size())
  129. streamPlayStates[i] = *playstate;
  130. else
  131. streamPlayStates.push_back(*playstate);
  132. *playstate = 0;
  133. }
  134. // block all buttons from being passed to game
  135. filteredButtons = allButtons;
  136. setMenuPos(MENUSET_MAIN, 0);
  137. menuHistory.resize(0);
  138. showUI = true;
  139. isPaused = true;
  140. }
  141. // always exit pause if key is tapped or no longer in game somehow
  142. if (isPauseKeyTapped() || !isInGame())
  143. {
  144. pause = false;
  145. }
  146. else
  147. {
  148. // note: use exact button comparisons instead of only single bits to avoid macros
  149. if (inputState->Tapped.Buttons == JVS_SQUARE)
  150. {
  151. showUI = !showUI;
  152. if (showUI)
  153. {
  154. menuItemMoveTime = std::chrono::high_resolution_clock::now(); // restart animations
  155. }
  156. else
  157. {
  158. // clear these from the screen too
  159. /*
  160. Drawing::destroyAetLayer(selResultAet1);
  161. Drawing::destroyAetLayer(selResultAet2);
  162. Drawing::destroyAetLayer(selResultAet3);
  163. Drawing::destroyAetLayer(selResultAet4);
  164. */
  165. Drawing::destroyAetLayer(triangleAet);
  166. Drawing::destroyAetLayer(squareAet);
  167. Drawing::destroyAetLayer(crossAet);
  168. Drawing::destroyAetLayer(circleAet);
  169. }
  170. }
  171. /* for testing `-ss` stuff
  172. if (inputState->Tapped.Buttons == JVS_TRIANGLE)
  173. {
  174. void** ScreenShotImplAddr = (void**)0x1412016d0;
  175. Drawing::MsString path; // just a small struct from TLAC::Utilities::Drawing::MsString
  176. path.SetCharBuf("blahblahblah");
  177. ((void(*)(void* impl, Drawing::MsString* path, int width, int height))0x140557210)(*ScreenShotImplAddr, &path, 1280, 720);
  178. }
  179. */
  180. // only process menu events when UI is visible
  181. if (showUI)
  182. {
  183. if (inputState->Tapped.Buttons == JVS_L)
  184. setMenuPos(curMenuSet, curMenuPos - 1);
  185. if (inputState->Tapped.Buttons == JVS_R)
  186. setMenuPos(curMenuSet, curMenuPos + 1);
  187. if (inputState->Tapped.Buttons == JVS_CROSS)
  188. {
  189. if (curMenuSet == MENUSET_MAIN)
  190. {
  191. pause = false;
  192. }
  193. else
  194. {
  195. menuback();
  196. }
  197. }
  198. if (inputState->Tapped.Buttons == JVS_CIRCLE)
  199. menu[curMenuSet].items[curMenuPos].callback();
  200. if (!componentsManager->IsDwGuiActive()) // not sure if this check is necessary, but it doesn't hurt
  201. {
  202. if (panelState->ContactType == 2 && lastTouchType != 2) // down and was not down before
  203. {
  204. for (int i = 0; i < menu[curMenuSet].items.size(); i++)
  205. {
  206. Drawing::Point itemCoords = getMenuItemCoords(curMenuSet, i);
  207. Drawing::Point touchCoords = { panelState->XPosition, panelState->YPosition };
  208. touchCoords.x *= 1280.0f / *resWidth; // convert to 720p coords
  209. touchCoords.y *= 720.0f / *resHeight;
  210. if (touchCoords.x >= itemCoords.x - menuItemWidth / 2 &&
  211. touchCoords.x <= itemCoords.x + menuItemWidth / 2 &&
  212. touchCoords.y >= itemCoords.y - menuItemHeight / 2 &&
  213. touchCoords.y <= itemCoords.y + menuItemHeight / 2)
  214. {
  215. setMenuPos(curMenuSet, i);
  216. menu[curMenuSet].items[i].callback();
  217. break;
  218. }
  219. }
  220. }
  221. }
  222. if (curMenuSet == MENUSET_SEVOL)
  223. {
  224. const char volformat[] = "%d";
  225. size_t size = snprintf(nullptr, 0, volformat, playerData->act_vol) + 1;
  226. char* buf = new char[size];
  227. snprintf(buf, size, volformat, playerData->act_vol);
  228. menu[MENUSET_SEVOL].items[1].name = buf;
  229. delete[] buf;
  230. }
  231. }
  232. }
  233. // no slider while paused
  234. // this is simpler than buttons because slider doesn't trigger on press, it triggers on movement
  235. // (therefore per-button blocking isn't needed)
  236. // SENSOR_SET_MODE_SECTIONS matches old behaviour
  237. sliderState->ResetSensors(TouchSliderState::SENSOR_SET_MODE_SECTIONS);
  238. }
  239. else
  240. {
  241. // exit pause mode on state transition
  242. if (isPaused)
  243. {
  244. ((void(*)())DSC_UNPAUSE_FUNC_ADDRESS)();
  245. InjectCode(aetMovPatchAddress, origAetMovOp);
  246. InjectCode(framespeedPatchAddress, origFramespeedOp);
  247. InjectCode(ageageHairPatchAddress, origAgeageHairOp);
  248. uint64_t audioMixerAddr = *(uint64_t*)(AUDIO_MAIN_CLASS_ADDRESS + 0x70);
  249. uint64_t audioStreamsAddress = *(uint64_t*)(audioMixerAddr + 0x18);
  250. int nAudioStreams = *(uint64_t*)(audioMixerAddr + 0x20);
  251. for (int i = 0; i < nAudioStreams; i++)
  252. {
  253. uint32_t* playstate = (uint32_t*)(audioStreamsAddress + i * 0x50 + 0x18);
  254. if (i < streamPlayStates.size())
  255. *playstate = streamPlayStates[i];
  256. }
  257. /*
  258. Drawing::destroyAetLayer(selResultAet1);
  259. Drawing::destroyAetLayer(selResultAet2);
  260. Drawing::destroyAetLayer(selResultAet3);
  261. Drawing::destroyAetLayer(selResultAet4);
  262. */
  263. Drawing::destroyAetLayer(triangleAet);
  264. Drawing::destroyAetLayer(squareAet);
  265. Drawing::destroyAetLayer(crossAet);
  266. Drawing::destroyAetLayer(circleAet);
  267. isPaused = false;
  268. }
  269. // buttons that have been tapped no longer need to be filtered (doing this with down broke retriggering)
  270. filteredButtons = (JvsButtons)(filteredButtons & ~inputState->Tapped.Buttons);
  271. // only enter pause if in game
  272. if (isInGame())
  273. {
  274. if (isPauseKeyTapped())
  275. {
  276. pause = true;
  277. }
  278. }
  279. else
  280. {
  281. // ensure giveUp isn't retained after already quitting
  282. giveUp = false;
  283. }
  284. }
  285. // swallow filtered button inputs
  286. inputState->Tapped.Buttons = (JvsButtons)(inputState->Tapped.Buttons & ~filteredButtons);
  287. inputState->DoubleTapped.Buttons = (JvsButtons)(inputState->DoubleTapped.Buttons & ~filteredButtons);
  288. inputState->Down.Buttons = (JvsButtons)(inputState->Down.Buttons & ~filteredButtons);
  289. inputState->Released.Buttons = (JvsButtons)(inputState->Released.Buttons & ~filteredButtons);
  290. inputState->IntervalTapped.Buttons = (JvsButtons)(inputState->IntervalTapped.Buttons & ~filteredButtons);
  291. lastTouchType = panelState->ContactType;
  292. }
  293. // returns the midpoint of a menu button
  294. Drawing::Point Pause::getMenuItemCoords(menusets set, int pos)
  295. {
  296. const float slant = 35.0f / 199.0f;
  297. int menuOriginY = menuY - (menuItemTotalHeight * menu[set].items.size() - menuItemPadding) / 2 + menuItemHeight / 2;
  298. if (set != MENUSET_MAIN)
  299. {
  300. menuOriginY += menuItemTotalHeight * 1.2 / 2;
  301. }
  302. int menuOriginX = menuX + (menuY - menuOriginY) * slant;
  303. Drawing::Point out;
  304. out.x = menuOriginX - (menuItemTotalHeight * pos * slant);
  305. out.y = menuOriginY + menuItemTotalHeight * pos;
  306. return out;
  307. }
  308. void Pause::UpdateDraw2D()
  309. {
  310. if (isPaused && showUI)
  311. {
  312. // setup draw objects
  313. Drawing::FontInfo fontInfo(0x11);
  314. Drawing::DrawParams dtParams(&fontInfo);
  315. dtParams.layer = bgLayer;
  316. Drawing::Point aetScale = { 0.65, 0.65 };
  317. Drawing::Point aetLoc = { (1280 - aetScale.x * 1280) / 2, (720 - aetScale.y * 720) / 2 };
  318. // get aspect ratio
  319. float aspect = *(float*)UI_ASPECT_RATIO;
  320. // bg rect
  321. float bgWidth = aspect * 720 + 2; // add a couple of pixels to protect against rounding errors
  322. float bgLeft = -(bgWidth - 1280) / 2; // 0,0 is in the corner of a 720p view.. half of the extra over 1280 wide is the horizontal offset to centre the bg
  323. Drawing::RectangleBounds rect;
  324. rect = { bgLeft, 0, bgWidth, 720 };
  325. dtParams.colour = 0xc0000000;
  326. dtParams.fillColour = dtParams.colour;
  327. Drawing::fillRectangle(&dtParams, rect);
  328. // pause icon
  329. /*
  330. const int pauseWidth = 80;
  331. const int pauseHeight = 110;
  332. const int pauseGap = 20;
  333. const int pausePosX = 32;
  334. const int pausePosY = 32;
  335. const int pausePartWidth = (pauseWidth - pauseGap) / 2;
  336. const int pauseX1 = pausePosX;
  337. const int pauseX2 = pausePosX + pausePartWidth + pauseGap;
  338. const int pauseY1 = pausePosY;
  339. dtParams.colour = 0x80ffffff;
  340. dtParams.fillColour = 0x80ffffff;
  341. rect = { pauseX1, pauseY1, pausePartWidth, pauseHeight };
  342. Drawing::fillRectangle(&dtParams, &rect);
  343. rect = { pauseX2, pauseY1, pausePartWidth, pauseHeight };
  344. Drawing::fillRectangle(&dtParams, &rect);
  345. */
  346. dtParams.layer = contentLayer;
  347. // bg box
  348. /*
  349. static int selResultFile = 0;
  350. if (selResultFile == 0)
  351. {
  352. //keyWinFile = Drawing::findAetFileId("AET_KEY_WIN_MAIN");
  353. selResultFile = Drawing::findAetFileId("AET_SEL_RESULT_MAIN");
  354. //printf("keyWinFile: %d\n", keyWinFile);
  355. }
  356. Drawing::destroyAetLayer(selResultAet1);
  357. Drawing::destroyAetLayer(selResultAet2);
  358. Drawing::destroyAetLayer(selResultAet3);
  359. Drawing::destroyAetLayer(selResultAet4);
  360. if (selResultFile != -1)
  361. {
  362. //keyWinAet = Drawing::createAetLayer(keyWinFile, dtParams.layer, CREATEAET_20000, "win_in", aetLoc, 0, nullptr, nullptr, 3.7, 3.7, aetScale, 0);
  363. aetScale = { 0.47f, 0.47f };
  364. aetLoc = { (1280 - aetScale.x * 1280) / 2, (720 - aetScale.y * 720) / 2 + 72 * aetScale.y };
  365. float animPos = 7.2;
  366. selResultAet1 = Drawing::createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0);
  367. selResultAet2 = Drawing::createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0);
  368. selResultAet3 = Drawing::createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0);
  369. selResultAet4 = Drawing::createAetLayer(selResultFile, dtParams.layer, CREATEAET_20000, "window_in", aetLoc, 0, nullptr, nullptr, animPos, animPos, aetScale, 0);
  370. }
  371. */
  372. dtParams.colour = 0xffffff00;
  373. Drawing::drawPolyline(&dtParams, {
  374. { 537, 255 },
  375. { 794, 255 },
  376. { 759, 454 },
  377. { 744, 466 },
  378. { 487, 466 },
  379. { 522, 267 },
  380. { 537, 255 },
  381. });
  382. Drawing::drawPolyline(&dtParams, {
  383. { 537 - .7f, 255 - 2 },
  384. { 794 + 2.38f, 255 - 2 },
  385. { 759 + 2.1f, 454 + 1.15f },
  386. { 744 + .7f, 466 + 2 },
  387. { 487 - 2.38f, 466 + 2 },
  388. { 522 - 2.1f, 267 - 1.15f },
  389. { 537 - .7f, 255 - 2 },
  390. });
  391. Drawing::drawPolyline(&dtParams, {
  392. { 548, 258 },
  393. { 768, 258 },
  394. { 774, 265 },
  395. { 770, 286 },
  396. { 764, 286 },
  397. { 737, 435 },
  398. { 743, 435 },
  399. { 739, 456 },
  400. { 733, 463 },
  401. { 513, 463 },
  402. { 507, 456 },
  403. { 511, 435 },
  404. { 517, 435 },
  405. { 544, 286 },
  406. { 538, 286 },
  407. { 542, 265 },
  408. { 548, 258 },
  409. });
  410. Drawing::Point menuCoords = getMenuItemCoords(curMenuSet, curMenuPos);
  411. // selection cursor
  412. const float selectBoxWidth = menuItemWidth;
  413. const float selectBoxHeight = menuItemHeight;
  414. const float selectBoxThickness = 2;
  415. float selectBoxX = menuCoords.x - selectBoxWidth / 2;
  416. float selectBoxY = menuCoords.y - menuItemHeight / 2;
  417. dtParams.colour = 0xc0ffff00;
  418. dtParams.fillColour = 0xc0ffff00;
  419. //rect = { selectBoxX, selectBoxY, selectBoxWidth, selectBoxHeight };
  420. //Drawing::drawRectangle(&dtParams, rect, selectBoxThickness);
  421. const float slant = 35.0f / 199.0f;
  422. Drawing::drawPolyline(&dtParams, {
  423. { selectBoxX + (selectBoxHeight - 8) * slant + 8 * 15 / 12, selectBoxY },
  424. { selectBoxX + selectBoxWidth, selectBoxY },
  425. { selectBoxX + selectBoxWidth - (selectBoxHeight - 8) * slant, selectBoxY + selectBoxHeight - 8 },
  426. { selectBoxX + selectBoxWidth - (selectBoxHeight - 8) * slant - 8 * 15 / 12, selectBoxY + selectBoxHeight },
  427. { selectBoxX, selectBoxY + selectBoxHeight },
  428. { selectBoxX + (selectBoxHeight - 8) * slant, selectBoxY + 8 },
  429. { selectBoxX + (selectBoxHeight - 8) * slant + 8 * 15 / 12, selectBoxY },
  430. });
  431. Drawing::drawPolyline(&dtParams, {
  432. { selectBoxX + (selectBoxHeight - 8) * slant + 8 * 15 / 12 - .7f, selectBoxY - 2 },
  433. { selectBoxX + selectBoxWidth + 2.38f, selectBoxY - 2 },
  434. { selectBoxX + selectBoxWidth - (selectBoxHeight - 8) * slant + 2.1f, selectBoxY + selectBoxHeight - 8 + 1.15f },
  435. { selectBoxX + selectBoxWidth - (selectBoxHeight - 8) * slant - 8 * 15 / 12 + .7f, selectBoxY + selectBoxHeight + 2 },
  436. { selectBoxX - 2.38f, selectBoxY + selectBoxHeight + 2 },
  437. { selectBoxX + (selectBoxHeight - 8) * slant - 2.1f, selectBoxY + 8 - 1.15f },
  438. { selectBoxX + (selectBoxHeight - 8) * slant + 8 * 15 / 12 - .7f, selectBoxY - 2 },
  439. });
  440. // menu
  441. fontInfo.setSize(menuTextSize, menuTextSize);
  442. if (curMenuSet != MENUSET_MAIN)
  443. {
  444. dtParams.textCurrentLoc = { menuX + 90 * slant, menuY - 90 };
  445. dtParams.lineOriginLoc.y = dtParams.textCurrentLoc.y;
  446. dtParams.colour = 0xffffffff;
  447. Drawing::drawText(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ALIGN_CENTRE | Drawing::DRAWTEXT_STROKE), menu[curMenuSet].name);
  448. }
  449. for (int i = 0; i < menu[curMenuSet].items.size(); i++)
  450. {
  451. menuCoords = getMenuItemCoords(curMenuSet, i);
  452. dtParams.textCurrentLoc = { menuCoords.x, menuCoords.y - menuTextSize / 2 };
  453. dtParams.lineOriginLoc = dtParams.textCurrentLoc;
  454. if (i == curMenuPos)
  455. {
  456. uint8_t alpha = (cosf(getMenuAnimPos() * 6.283185f) * 0.15 + 0.85) * 255;
  457. dtParams.colour = 0x00ffff00 | (alpha << 24);
  458. }
  459. else
  460. {
  461. dtParams.colour = 0xffffffff;
  462. }
  463. Drawing::drawText(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ALIGN_CENTRE), menu[curMenuSet].items[i].name);
  464. }
  465. // key legend
  466. Drawing::destroyAetLayer(triangleAet);
  467. Drawing::destroyAetLayer(squareAet);
  468. Drawing::destroyAetLayer(crossAet);
  469. Drawing::destroyAetLayer(circleAet);
  470. float textLeft;
  471. if (aspect > 16.0f / 9.0f)
  472. textLeft = 32;
  473. else
  474. textLeft = (1280 - bgWidth) / 2 + 32; // 0,0 is in the corner of a 720p view.. half of the difference to 1280 wide is the horizontal offset to the window corner
  475. fontInfo.setSize(18, 18);
  476. dtParams.textCurrentLoc = { textLeft, 720 - 40 };
  477. dtParams.lineOriginLoc = dtParams.textCurrentLoc;
  478. const float spriteSize = 18;
  479. const float halfSpriteSize = spriteSize / 2;
  480. aetLoc = { 0, dtParams.textCurrentLoc.y + halfSpriteSize }; // the aets are centered on their location, so fudge this a little
  481. aetScale = { spriteSize / 64, spriteSize / 64 }; // just approximated
  482. dtParams.colour = 0xffffffff;
  483. Drawing::drawTextW(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ENABLE_XADVANCE), L"↑↓/LR:Move ");
  484. aetLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize;
  485. squareAet = Drawing::createAetLayer(3, dtParams.layer, Drawing::CREATEAET_20000, "button_shikaku", aetLoc, 0, nullptr, nullptr, 0, 0, aetScale, nullptr);
  486. dtParams.textCurrentLoc.x += spriteSize;
  487. Drawing::drawTextW(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ENABLE_XADVANCE), L":Hide Menu ");
  488. aetLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize;
  489. crossAet = Drawing::createAetLayer(3, dtParams.layer, Drawing::CREATEAET_20000, "button_batsu", aetLoc, 0, nullptr, nullptr, 0, 0, aetScale, nullptr);
  490. dtParams.textCurrentLoc.x += spriteSize;
  491. if (menuHistory.size() == 0)
  492. Drawing::drawTextW(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ENABLE_XADVANCE), L":Close ");
  493. else
  494. Drawing::drawTextW(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ENABLE_XADVANCE), L":Back ");
  495. aetLoc.x = dtParams.textCurrentLoc.x + halfSpriteSize;
  496. circleAet = Drawing::createAetLayer(3, dtParams.layer, Drawing::CREATEAET_20000, "button_maru", aetLoc, 0, nullptr, nullptr, 0, 0, aetScale, nullptr);
  497. dtParams.textCurrentLoc.x += spriteSize;
  498. Drawing::drawTextW(&dtParams, (Drawing::drawTextFlags)(Drawing::DRAWTEXT_ENABLE_XADVANCE), L":Select");
  499. }
  500. }
  501. void Pause::OnFocusLost()
  502. {
  503. if (autoPause && isInGame())
  504. pause = true;
  505. }
  506. bool Pause::isPauseKeyTapped()
  507. {
  508. return inputState->Tapped.Buttons & JVS_START;
  509. }
  510. bool Pause::isInGame()
  511. {
  512. return *(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN && *(uint8_t*)PV_STATE_ADDRESS == 1;
  513. }
  514. bool Pause::hookedGiveUpFunc(void* cls)
  515. {
  516. if (giveUp)
  517. {
  518. giveUp = false;
  519. pause = false;
  520. return true;
  521. }
  522. else
  523. {
  524. if (divaGiveUpFunc(cls))
  525. {
  526. pause = false;
  527. return true;
  528. }
  529. }
  530. return false;
  531. }
  532. void Pause::setSEVolume(int amount)
  533. {
  534. playerData->act_vol += amount;
  535. if (playerData->act_vol < 0) playerData->act_vol = 0;
  536. if (playerData->act_vol > 100) playerData->act_vol = 100;
  537. playerData->act_slide_vol = playerData->act_vol;
  538. }
  539. void Pause::setMenuPos(menusets set, int pos, bool updateHistory)
  540. {
  541. menusets newMenuSet;
  542. if (set >= 0 && set < menu.size())
  543. newMenuSet = set;
  544. else
  545. newMenuSet = MENUSET_MAIN;
  546. if (updateHistory && newMenuSet != curMenuSet)
  547. menuHistory.push_back(std::pair<menusets, int>(curMenuSet, curMenuPos));
  548. curMenuSet = newMenuSet;
  549. if (pos < 0)
  550. pos = menu[curMenuSet].items.size() - 1;
  551. else if (pos >= menu[curMenuSet].items.size())
  552. pos = 0;
  553. curMenuPos = pos;
  554. menuItemMoveTime = std::chrono::high_resolution_clock::now(); // restart animations
  555. }
  556. float Pause::getMenuAnimPos()
  557. {
  558. const int duration = 1500000000; // 1.5s
  559. return (float)((std::chrono::high_resolution_clock::now() - menuItemMoveTime) % std::chrono::nanoseconds(duration)).count() / (float)duration;
  560. }
  561. void Pause::InjectCode(void* address, const std::vector<uint8_t> data)
  562. {
  563. const size_t byteCount = data.size() * sizeof(uint8_t);
  564. DWORD oldProtect;
  565. VirtualProtect(address, byteCount, PAGE_EXECUTE_READWRITE, &oldProtect);
  566. memcpy(address, data.data(), byteCount);
  567. VirtualProtect(address, byteCount, oldProtect, nullptr);
  568. }
  569. }