main.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include "FreeShop.hpp"
  2. #include "DownloadQueue.hpp"
  3. #include "TitleKeys.hpp"
  4. #include "Config.hpp"
  5. #include "States/BrowseState.hpp"
  6. #include "States/SleepState.hpp"
  7. #include "States/SyncState.hpp"
  8. #ifndef EMULATION
  9. #include <3ds.h>
  10. #include "MCU/Mcu.hpp"
  11. #endif
  12. #ifndef EMULATION
  13. namespace {
  14. aptHookCookie cookie;
  15. void aptHookFunc(APT_HookType hookType, void *param)
  16. {
  17. switch (hookType) {
  18. case APTHOOK_ONSUSPEND:
  19. if (FreeShop::SleepState::isSleeping && R_SUCCEEDED(gspLcdInit()))
  20. {
  21. GSPLCD_PowerOnBacklight(GSPLCD_SCREEN_BOTH);
  22. gspLcdExit();
  23. }
  24. if (FreeShop::SleepState::isSleeping && R_SUCCEEDED(FreeShop::MCU::getInstance().mcuInit())) {
  25. FreeShop::MCU::getInstance().dimLeds(0xFF);
  26. FreeShop::MCU::getInstance().mcuExit();
  27. }
  28. // Fall through
  29. case APTHOOK_ONSLEEP:
  30. FreeShop::DownloadQueue::getInstance().suspend();
  31. break;
  32. case APTHOOK_ONRESTORE:
  33. case APTHOOK_ONWAKEUP:
  34. FreeShop::SleepState::isSleeping = false;
  35. FreeShop::SleepState::clock.restart();
  36. FreeShop::BrowseState::clockDownloadInactivity.restart();
  37. FreeShop::DownloadQueue::getInstance().resume();
  38. FreeShop::g_browseState->wokeUp();
  39. break;
  40. case APTHOOK_ONEXIT:
  41. FreeShop::SyncState::exitRequired = true;
  42. break;
  43. default:
  44. break;
  45. }
  46. }
  47. }
  48. #endif
  49. int main(int argc, char** argv)
  50. {
  51. #ifndef NDEBUG
  52. // Console for reading stdout
  53. cpp3ds::Console::enable(cpp3ds::BottomScreen, cpp3ds::Color::Black);
  54. #endif
  55. cpp3ds::Service::enable(cpp3ds::Audio);
  56. cpp3ds::Service::enable(cpp3ds::Config);
  57. cpp3ds::Service::enable(cpp3ds::Network);
  58. cpp3ds::Service::enable(cpp3ds::SSL);
  59. cpp3ds::Service::enable(cpp3ds::Httpc);
  60. cpp3ds::Service::enable(cpp3ds::AM);
  61. #ifndef EMULATION
  62. aptHook(&cookie, aptHookFunc, nullptr);
  63. AM_InitializeExternalTitleDatabase(false);
  64. aptSetSleepAllowed(true);
  65. #endif
  66. srand(time(NULL));
  67. auto game = new FreeShop::FreeShop();
  68. game->run();
  69. FreeShop::FreeShop::prepareToCloseApp();
  70. #ifndef EMULATION
  71. nimsExit();
  72. amExit();
  73. ptmuExit();
  74. acExit();
  75. ptmSysmExit();
  76. newsExit();
  77. if (FreeShop::g_requestShutdown) {
  78. //Init the services and turn off the console
  79. ptmSysmInit();
  80. PTMSYSM_ShutdownAsync(0);
  81. ptmSysmExit();
  82. }
  83. #endif
  84. delete game;
  85. return 0;
  86. }