weebo.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #include "weebo_i.h"
  2. #define TAG "weebo"
  3. #define WEEBO_KEY_RETAIL_FILENAME "key_retail"
  4. uint8_t original[NTAG215_SIZE];
  5. uint8_t plain_base[NFC3D_AMIIBO_SIZE];
  6. uint8_t modified[NTAG215_SIZE];
  7. void calculate_pwd(uint8_t* uid, uint8_t* pwd) {
  8. pwd[0] = uid[1] ^ uid[3] ^ 0xAA;
  9. pwd[1] = uid[2] ^ uid[4] ^ 0x55;
  10. pwd[2] = uid[3] ^ uid[5] ^ 0xAA;
  11. pwd[3] = uid[4] ^ uid[6] ^ 0x55;
  12. }
  13. bool weebo_custom_event_callback(void* context, uint32_t event) {
  14. furi_assert(context);
  15. Weebo* weebo = context;
  16. return scene_manager_handle_custom_event(weebo->scene_manager, event);
  17. }
  18. bool weebo_back_event_callback(void* context) {
  19. furi_assert(context);
  20. Weebo* weebo = context;
  21. return scene_manager_handle_back_event(weebo->scene_manager);
  22. }
  23. void weebo_tick_event_callback(void* context) {
  24. furi_assert(context);
  25. Weebo* weebo = context;
  26. scene_manager_handle_tick_event(weebo->scene_manager);
  27. }
  28. Weebo* weebo_alloc() {
  29. Weebo* weebo = malloc(sizeof(Weebo));
  30. weebo->view_dispatcher = view_dispatcher_alloc();
  31. weebo->scene_manager = scene_manager_alloc(&weebo_scene_handlers, weebo);
  32. view_dispatcher_set_event_callback_context(weebo->view_dispatcher, weebo);
  33. view_dispatcher_set_custom_event_callback(weebo->view_dispatcher, weebo_custom_event_callback);
  34. view_dispatcher_set_navigation_event_callback(
  35. weebo->view_dispatcher, weebo_back_event_callback);
  36. view_dispatcher_set_tick_event_callback(
  37. weebo->view_dispatcher, weebo_tick_event_callback, 100);
  38. weebo->nfc = nfc_alloc();
  39. // Nfc device
  40. weebo->nfc_device = nfc_device_alloc();
  41. nfc_device_set_loading_callback(weebo->nfc_device, weebo_show_loading_popup, weebo);
  42. // Open GUI record
  43. weebo->gui = furi_record_open(RECORD_GUI);
  44. view_dispatcher_attach_to_gui(
  45. weebo->view_dispatcher, weebo->gui, ViewDispatcherTypeFullscreen);
  46. // Open Notification record
  47. weebo->notifications = furi_record_open(RECORD_NOTIFICATION);
  48. // Submenu
  49. weebo->submenu = submenu_alloc();
  50. view_dispatcher_add_view(
  51. weebo->view_dispatcher, WeeboViewMenu, submenu_get_view(weebo->submenu));
  52. // Popup
  53. weebo->popup = popup_alloc();
  54. view_dispatcher_add_view(weebo->view_dispatcher, WeeboViewPopup, popup_get_view(weebo->popup));
  55. // Loading
  56. weebo->loading = loading_alloc();
  57. view_dispatcher_add_view(
  58. weebo->view_dispatcher, WeeboViewLoading, loading_get_view(weebo->loading));
  59. // Text Input
  60. weebo->text_input = text_input_alloc();
  61. view_dispatcher_add_view(
  62. weebo->view_dispatcher, WeeboViewTextInput, text_input_get_view(weebo->text_input));
  63. // Number Input
  64. weebo->number_input = number_input_alloc();
  65. view_dispatcher_add_view(
  66. weebo->view_dispatcher, WeeboViewNumberInput, number_input_get_view(weebo->number_input));
  67. // TextBox
  68. weebo->text_box = text_box_alloc();
  69. view_dispatcher_add_view(
  70. weebo->view_dispatcher, WeeboViewTextBox, text_box_get_view(weebo->text_box));
  71. weebo->text_box_store = furi_string_alloc();
  72. // Custom Widget
  73. weebo->widget = widget_alloc();
  74. view_dispatcher_add_view(
  75. weebo->view_dispatcher, WeeboViewWidget, widget_get_view(weebo->widget));
  76. weebo->storage = furi_record_open(RECORD_STORAGE);
  77. weebo->dialogs = furi_record_open(RECORD_DIALOGS);
  78. weebo->load_path = furi_string_alloc();
  79. return weebo;
  80. }
  81. void weebo_free(Weebo* weebo) {
  82. furi_assert(weebo);
  83. nfc_free(weebo->nfc);
  84. // Nfc device
  85. nfc_device_free(weebo->nfc_device);
  86. // Submenu
  87. view_dispatcher_remove_view(weebo->view_dispatcher, WeeboViewMenu);
  88. submenu_free(weebo->submenu);
  89. // Popup
  90. view_dispatcher_remove_view(weebo->view_dispatcher, WeeboViewPopup);
  91. popup_free(weebo->popup);
  92. // Loading
  93. view_dispatcher_remove_view(weebo->view_dispatcher, WeeboViewLoading);
  94. loading_free(weebo->loading);
  95. // TextInput
  96. view_dispatcher_remove_view(weebo->view_dispatcher, WeeboViewTextInput);
  97. text_input_free(weebo->text_input);
  98. // NumberInput
  99. view_dispatcher_remove_view(weebo->view_dispatcher, WeeboViewNumberInput);
  100. number_input_free(weebo->number_input);
  101. // TextBox
  102. view_dispatcher_remove_view(weebo->view_dispatcher, WeeboViewTextBox);
  103. text_box_free(weebo->text_box);
  104. furi_string_free(weebo->text_box_store);
  105. // Custom Widget
  106. view_dispatcher_remove_view(weebo->view_dispatcher, WeeboViewWidget);
  107. widget_free(weebo->widget);
  108. // View Dispatcher
  109. view_dispatcher_free(weebo->view_dispatcher);
  110. // Scene Manager
  111. scene_manager_free(weebo->scene_manager);
  112. // GUI
  113. furi_record_close(RECORD_GUI);
  114. weebo->gui = NULL;
  115. // Notifications
  116. furi_record_close(RECORD_NOTIFICATION);
  117. weebo->notifications = NULL;
  118. furi_string_free(weebo->load_path);
  119. furi_record_close(RECORD_STORAGE);
  120. furi_record_close(RECORD_DIALOGS);
  121. free(weebo);
  122. }
  123. void weebo_text_store_set(Weebo* weebo, const char* text, ...) {
  124. va_list args;
  125. va_start(args, text);
  126. vsnprintf(weebo->text_store, sizeof(weebo->text_store), text, args);
  127. va_end(args);
  128. }
  129. void weebo_text_store_clear(Weebo* weebo) {
  130. memset(weebo->text_store, 0, sizeof(weebo->text_store));
  131. }
  132. static const NotificationSequence weebo_sequence_blink_start_blue = {
  133. &message_blink_start_10,
  134. &message_blink_set_color_blue,
  135. &message_do_not_reset,
  136. NULL,
  137. };
  138. static const NotificationSequence weebo_sequence_blink_stop = {
  139. &message_blink_stop,
  140. NULL,
  141. };
  142. void weebo_blink_start(Weebo* weebo) {
  143. notification_message(weebo->notifications, &weebo_sequence_blink_start_blue);
  144. }
  145. void weebo_blink_stop(Weebo* weebo) {
  146. notification_message(weebo->notifications, &weebo_sequence_blink_stop);
  147. }
  148. void weebo_show_loading_popup(void* context, bool show) {
  149. Weebo* weebo = context;
  150. if(show) {
  151. // Raise timer priority so that animations can play
  152. furi_timer_set_thread_priority(FuriTimerThreadPriorityElevated);
  153. view_dispatcher_switch_to_view(weebo->view_dispatcher, WeeboViewLoading);
  154. } else {
  155. // Restore default timer priority
  156. furi_timer_set_thread_priority(FuriTimerThreadPriorityNormal);
  157. }
  158. }
  159. int32_t weebo_app(void* p) {
  160. UNUSED(p);
  161. Weebo* weebo = weebo_alloc();
  162. scene_manager_next_scene(weebo->scene_manager, WeeboSceneStart);
  163. view_dispatcher_run(weebo->view_dispatcher);
  164. weebo_free(weebo);
  165. return 0;
  166. }