| 649 | #define COIN_OFFSET 4 |
| 650 | |
| 651 | void section_shared(void) |
| 652 | { |
| 653 | char line[LINEN]; |
| 654 | char* data; |
| 655 | int size; |
| 656 | int res; |
| 657 | int h; |
| 658 | int coins; |
| 659 | |
| 660 | if (g_is_switch) { |
| 661 | gui_message("Shared extdata is a 3DS concept — nothing to show on Switch."); |
| 662 | return; |
| 663 | } |
| 664 | |
| 665 | h = sav_open_shared(GAMECOIN_EXTDATA); |
| 666 | if (h < 0) { |
| 667 | sprintf(line, "sav_open_shared failed: %d", h); |
| 668 | logline(line); |
| 669 | gui_message("Could not open the Home Menu shared extdata."); |
| 670 | return; |
| 671 | } |
| 672 | |
| 673 | res = sav_read(h, GAMECOIN_FILE, &data, &size); |
| 674 | if (res != 0 || size < COIN_OFFSET + 2) { |
| 675 | sav_close(h); |
| 676 | gui_message("gamecoin.dat could not be read."); |
| 677 | return; |
| 678 | } |
| 679 | |
| 680 | /* little-endian u16 at offset 4 */ |
| 681 | coins = (data[COIN_OFFSET] & 0xFF) | ((data[COIN_OFFSET + 1] & 0xFF) << 8); |
| 682 | free(data); |
| 683 | sav_close(h); |
| 684 | |
| 685 | sprintf(line, "gamecoin.dat is %d bytes; you have %d Play Coins.", size, coins); |
| 686 | printf("%s\n", line); |
| 687 | gui_message(line); |
| 688 | } |
| 689 | |
| 690 | /* ------------------------------------------------------------------------- */ |
| 691 | /* 9. Network */ |