| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #include <src/include/pokemon_app.h>
- struct patch_list {
- uint8_t index;
- struct patch_list* next;
- };
- struct patch_list* plist_alloc(void) {
- struct patch_list* plist = NULL;
- plist = malloc(sizeof(struct patch_list));
- plist->index = 0;
- plist->next = NULL;
- return plist;
- }
- void plist_append(struct patch_list* plist, uint8_t index) {
- furi_assert(plist);
- for(;;) {
- if(plist->next == NULL) break;
- plist = plist->next;
- }
- plist->index = index;
- plist->next = plist_alloc();
- }
- void plist_free(struct patch_list* plist) {
- struct patch_list* plist_next = NULL;
- while(plist != NULL) {
- plist_next = plist->next;
- free(plist);
- plist = plist_next;
- }
- }
- /* Returns the index value at offset member of the list. If offset is beyond
- * the length of the allocated list, it will just return 0.
- */
- uint8_t plist_index_get(struct patch_list* plist, int offset) {
- furi_assert(plist);
- int i;
- for(i = 0; i < offset; i++) {
- if(plist->next == NULL) break;
- plist = plist->next;
- }
- return plist->index;
- }
- void plist_create(struct patch_list** pplist, PokemonData* pdata) {
- furi_assert(pdata);
- uint8_t* trade_party_flat = pdata->party;
- size_t i;
- /* If plist is non-NULL that means its already been created. Tear it down
- * first.
- */
- if(*pplist != NULL) {
- plist_free(*pplist);
- *pplist = NULL;
- }
- *pplist = plist_alloc();
- /* The first half of the patch list covers offsets 0x00 - 0xfb, which
- * is expressed as 0x01 - 0xfc. An 0xFF byte is added to signify the
- * end of the first part. The second half of the patch list covers
- * offsets 0xfc - 0x107 (more in gen ii). Which is expressed as
- * 0x01 - 0xc. A 0xFF byte is added to signify the end of the second part.
- */
- for(i = 0; i < pdata->party_sz; i++) {
- if(i == 0xFC) {
- FURI_LOG_D(TAG, "[plist] part 1 end");
- plist_append(*pplist, 0xFF);
- }
- if(trade_party_flat[i] == 0xFE) {
- FURI_LOG_D(
- TAG, "[plist] patching byte 0x%02X, adding 0x%02X to plist", i, (i % 0xfc) + 1);
- plist_append(*pplist, (i % 0xfc) + 1);
- trade_party_flat[i] = 0xFF;
- }
- }
- FURI_LOG_D(TAG, "[plist] part 2 end");
- plist_append(*pplist, 0xFF);
- }
|