about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--gba/source/main.c32
-rw-r--r--source/deserialize.c215
-rw-r--r--source/deserialize.h16
-rw-r--r--source/http.c4
-rw-r--r--source/main.c220
5 files changed, 291 insertions, 196 deletions
diff --git a/gba/source/main.c b/gba/source/main.c index 4bb120f..375adb8 100644 --- a/gba/source/main.c +++ b/gba/source/main.c
@@ -199,9 +199,9 @@ int main(void)
199 sendU32(partyCount); 199 sendU32(partyCount);
200 waitForAck(); 200 waitForAck();
201 201
202 for (int pki=0; pki<partyCount; pki++) 202 for (int ki=0; ki<partyCount; ki++)
203 { 203 {
204 struct Pokemon* pkm = (playerParty + pki); 204 struct Pokemon* pkm = (playerParty + ki);
205 struct BoxPokemon* bpkm = &(pkm->box); 205 struct BoxPokemon* bpkm = &(pkm->box);
206 206
207 struct PokemonIntermediate pki; 207 struct PokemonIntermediate pki;
@@ -209,4 +209,32 @@ int main(void)
209 PokemonIntermediateInit(&pki, bpkm); 209 PokemonIntermediateInit(&pki, bpkm);
210 PokemonIntermediateStream(&pki); 210 PokemonIntermediateStream(&pki);
211 } 211 }
212
213 struct PokemonStorage* pc = gameData.SaveBlock3;
214
215 for (int bi=0; bi<14; bi++)
216 {
217 struct BoxPokemon* box = pc->boxes[bi];
218
219 for (int si=0; si<30; si++)
220 {
221 struct BoxPokemon* bpkm = &(box[si]);
222
223 DecryptBoxPokemon(bpkm);
224 struct PokemonSubstruct0* sub0 = GetBoxPokemonSubstruct0(bpkm);
225 bool isPoke = (sub0->species != 0);
226 EncryptBoxPokemon(bpkm);
227
228 sendU32(isPoke);
229 waitForAck();
230
231 if (isPoke)
232 {
233 struct PokemonIntermediate pki;
234
235 PokemonIntermediateInit(&pki, bpkm);
236 PokemonIntermediateStream(&pki);
237 }
238 }
239 }
212} 240}
diff --git a/source/deserialize.c b/source/deserialize.c new file mode 100644 index 0000000..e6fdf3b --- /dev/null +++ b/source/deserialize.c
@@ -0,0 +1,215 @@
1/*
2 * Copyright (C) 2017 hatkirby
3 *
4 * This software may be modified and distributed under the terms
5 * of the MIT license. See the LICENSE file for details.
6 */
7#include "deserialize.h"
8#include <stdio.h>
9#include "encoding.h"
10
11cJSON* pokemonToJson(const struct PokemonIntermediate* pki)
12{
13 char d_pokename[31];
14 decodePokemonCharset(pki->nickname, 10, d_pokename, pki->language);
15
16 char d_otName[22];
17 decodePokemonCharset(pki->otName, 7, d_otName, pki->language);
18
19 char d_key[57];
20 sprintf(
21 d_key,
22 "%08lx%08lx%08lx%08lx%08lx%08lx%08lx",
23 pki->key[0],
24 pki->key[1],
25 pki->key[2],
26 pki->key[3],
27 pki->key[4],
28 pki->key[5],
29 pki->key[6]);
30
31 cJSON* jPoke = cJSON_CreateObject();
32
33 cJSON_AddNumberToObject(
34 jPoke,
35 "species",
36 __builtin_bswap16(pki->species));
37
38 cJSON_AddItemToObject(
39 jPoke,
40 "nickname",
41 cJSON_CreateString(d_pokename));
42
43 cJSON_AddItemToObject(
44 jPoke,
45 "otName",
46 cJSON_CreateString(d_otName));
47
48 cJSON_AddNumberToObject(
49 jPoke,
50 "otId",
51 __builtin_bswap16(pki->otId));
52
53 cJSON_AddNumberToObject(
54 jPoke,
55 "level",
56 pki->level);
57
58 cJSON_AddNumberToObject(
59 jPoke,
60 "hp",
61 __builtin_bswap32(pki->hp));
62
63 cJSON_AddNumberToObject(
64 jPoke,
65 "attack",
66 __builtin_bswap32(pki->attack));
67
68 cJSON_AddNumberToObject(
69 jPoke,
70 "defense",
71 __builtin_bswap32(pki->defense));
72
73 cJSON_AddNumberToObject(
74 jPoke,
75 "speed",
76 __builtin_bswap32(pki->speed));
77
78 cJSON_AddNumberToObject(
79 jPoke,
80 "spAttack",
81 __builtin_bswap32(pki->spAttack));
82
83 cJSON_AddNumberToObject(
84 jPoke,
85 "spDefense",
86 __builtin_bswap32(pki->spDefense));
87
88 cJSON_AddNumberToObject(
89 jPoke,
90 "coolness",
91 pki->cool);
92
93 cJSON_AddNumberToObject(
94 jPoke,
95 "beauty",
96 pki->beauty);
97
98 cJSON_AddNumberToObject(
99 jPoke,
100 "cuteness",
101 pki->cute);
102
103 cJSON_AddNumberToObject(
104 jPoke,
105 "smartness",
106 pki->smart);
107
108 cJSON_AddNumberToObject(
109 jPoke,
110 "toughness",
111 pki->tough);
112
113 cJSON_AddNumberToObject(
114 jPoke,
115 "sheen",
116 pki->sheen);
117
118 cJSON_AddItemToObject(
119 jPoke,
120 "key",
121 cJSON_CreateString(d_key));
122
123 cJSON_AddNumberToObject(
124 jPoke,
125 "experience",
126 __builtin_bswap32(pki->experience));
127
128 cJSON_AddNumberToObject(
129 jPoke,
130 "heldItem",
131 __builtin_bswap16(pki->heldItem));
132
133 cJSON* jMoves = cJSON_CreateArray();
134
135 for (int j=0; j<4; j++)
136 {
137 if (pki->moves[j] != 0)
138 {
139 cJSON* jMove = cJSON_CreateObject();
140
141 cJSON_AddNumberToObject(
142 jMove,
143 "id",
144 __builtin_bswap16(pki->moves[j]));
145
146 cJSON_AddNumberToObject(
147 jMove,
148 "ppBonuses",
149 (pki->ppBonuses >> (2*j)) & 3);
150
151 cJSON_AddItemToArray(jMoves, jMove);
152 } else {
153 break;
154 }
155 }
156
157 cJSON_AddItemToObject(
158 jPoke,
159 "moves",
160 jMoves);
161
162 if (pki->otGender)
163 {
164 cJSON_AddStringToObject(jPoke, "otGender", "female");
165 } else {
166 cJSON_AddStringToObject(jPoke, "otGender", "male");
167 }
168
169 cJSON_AddNumberToObject(
170 jPoke,
171 "metLevel",
172 pki->metLevel);
173
174 cJSON_AddNumberToObject(
175 jPoke,
176 "metLocation",
177 pki->metLocation);
178
179 cJSON_AddBoolToObject(
180 jPoke,
181 "shiny",
182 pki->shiny);
183
184 cJSON_AddNumberToObject(
185 jPoke,
186 "nature",
187 pki->nature);
188
189 if (pki->gender == 0)
190 {
191 cJSON_AddStringToObject(jPoke, "gender", "male");
192 } else if (pki->gender == 1)
193 {
194 cJSON_AddStringToObject(jPoke, "gender", "female");
195 } else if (pki->gender == 2)
196 {
197 cJSON_AddStringToObject(jPoke, "gender", "genderless");
198 }
199
200 cJSON_AddBoolToObject(
201 jPoke,
202 "secondAbility",
203 pki->altAbility);
204
205 // Handle Unown form.
206 if (pki->species == 201)
207 {
208 cJSON_AddNumberToObject(
209 jPoke,
210 "unownLetter",
211 pki->unownLetter);
212 }
213
214 return jPoke;
215}
diff --git a/source/deserialize.h b/source/deserialize.h new file mode 100644 index 0000000..4ed8754 --- /dev/null +++ b/source/deserialize.h
@@ -0,0 +1,16 @@
1/*
2 * Copyright (C) 2017 hatkirby
3 *
4 * This software may be modified and distributed under the terms
5 * of the MIT license. See the LICENSE file for details.
6 */
7#ifndef DESERIALIZE_H_3E597847
8#define DESERIALIZE_H_3E597847
9
10#include <gccore.h>
11#include "pokemon.h"
12#include "cJSON.h"
13
14cJSON* pokemonToJson(const struct PokemonIntermediate* pki);
15
16#endif /* end of include guard: DESERIALIZE_H_3E597847 */
diff --git a/source/http.c b/source/http.c index 1979e22..be62dce 100644 --- a/source/http.c +++ b/source/http.c
@@ -58,7 +58,7 @@ static int tcpWrite(
58 result = net_write(*(s32*)firstParam, buffer, block); 58 result = net_write(*(s32*)firstParam, buffer, block);
59 } 59 }
60 60
61 if ((result == 0) || (result == -56)) 61 if ((result == 0) || (result == -56) || (result == -11))
62 { 62 {
63 usleep(20 * 1000); 63 usleep(20 * 1000);
64 64
@@ -73,7 +73,7 @@ static int tcpWrite(
73 sent += result; 73 sent += result;
74 left -= result; 74 left -= result;
75 buffer += result; 75 buffer += result;
76 usleep(100); 76 usleep(1000);
77 77
78 if ((sent / TCP_BLOCK_SIZE) > step) 78 if ((sent / TCP_BLOCK_SIZE) > step)
79 { 79 {
diff --git a/source/main.c b/source/main.c index f066a7d..de36755 100644 --- a/source/main.c +++ b/source/main.c
@@ -19,6 +19,7 @@
19#include "pokemon.h" 19#include "pokemon.h"
20#include "http.h" 20#include "http.h"
21#include "netinf.h" 21#include "netinf.h"
22#include "deserialize.h"
22 23
23void printmain() 24void printmain()
24{ 25{
@@ -285,7 +286,7 @@ void* extractor(void* userdata)
285 286
286 sendMsg(1); 287 sendMsg(1);
287 288
288 // Start receiving party pokémon. 289 // Start receiving pokémon.
289 printf("Getting party...\n"); 290 printf("Getting party...\n");
290 291
291 u32 partyCount = getMsg(); 292 u32 partyCount = getMsg();
@@ -301,214 +302,49 @@ void* extractor(void* userdata)
301 302
302 struct PokemonIntermediate* pki = (struct PokemonIntermediate*)(&rawdata); 303 struct PokemonIntermediate* pki = (struct PokemonIntermediate*)(&rawdata);
303 304
304 char d_pokename[31]; 305 cJSON* jPoke = pokemonToJson(pki);
305 decodePokemonCharset(pki->nickname, 10, d_pokename, pki->language);
306
307 char d_otName[22];
308 decodePokemonCharset(pki->otName, 7, d_otName, pki->language);
309
310 char d_key[57];
311 sprintf(
312 d_key,
313 "%08lx%08lx%08lx%08lx%08lx%08lx%08lx",
314 pki->key[0],
315 pki->key[1],
316 pki->key[2],
317 pki->key[3],
318 pki->key[4],
319 pki->key[5],
320 pki->key[6]);
321
322 cJSON* jPoke = cJSON_CreateObject();
323
324 cJSON_AddNumberToObject(
325 jPoke,
326 "species",
327 __builtin_bswap16(pki->species));
328
329 cJSON_AddItemToObject(
330 jPoke,
331 "nickname",
332 cJSON_CreateString(d_pokename));
333
334 cJSON_AddItemToObject(
335 jPoke,
336 "otName",
337 cJSON_CreateString(d_otName));
338
339 cJSON_AddNumberToObject(
340 jPoke,
341 "otId",
342 __builtin_bswap16(pki->otId));
343
344 cJSON_AddNumberToObject(
345 jPoke,
346 "level",
347 pki->level);
348
349 cJSON_AddNumberToObject(
350 jPoke,
351 "hp",
352 __builtin_bswap32(pki->hp));
353
354 cJSON_AddNumberToObject(
355 jPoke,
356 "attack",
357 __builtin_bswap32(pki->attack));
358
359 cJSON_AddNumberToObject(
360 jPoke,
361 "defense",
362 __builtin_bswap32(pki->defense));
363
364 cJSON_AddNumberToObject(
365 jPoke,
366 "speed",
367 __builtin_bswap32(pki->speed));
368
369 cJSON_AddNumberToObject(
370 jPoke,
371 "spAttack",
372 __builtin_bswap32(pki->spAttack));
373
374 cJSON_AddNumberToObject(
375 jPoke,
376 "spDefense",
377 __builtin_bswap32(pki->spDefense));
378
379 cJSON_AddNumberToObject(
380 jPoke,
381 "coolness",
382 pki->cool);
383
384 cJSON_AddNumberToObject(
385 jPoke,
386 "beauty",
387 pki->beauty);
388
389 cJSON_AddNumberToObject(
390 jPoke,
391 "cuteness",
392 pki->cute);
393
394 cJSON_AddNumberToObject(
395 jPoke,
396 "smartness",
397 pki->smart);
398
399 cJSON_AddNumberToObject(
400 jPoke,
401 "toughness",
402 pki->tough);
403
404 cJSON_AddNumberToObject(
405 jPoke,
406 "sheen",
407 pki->sheen);
408
409 cJSON_AddItemToObject(
410 jPoke,
411 "key",
412 cJSON_CreateString(d_key));
413
414 cJSON_AddNumberToObject(
415 jPoke,
416 "experience",
417 __builtin_bswap32(pki->experience));
418
419 cJSON_AddNumberToObject(
420 jPoke,
421 "heldItem",
422 __builtin_bswap16(pki->heldItem));
423
424 cJSON* jMoves = cJSON_CreateArray();
425
426 for (int j=0; j<4; j++)
427 {
428 if (pki->moves[j] != 0)
429 {
430 cJSON* jMove = cJSON_CreateObject();
431
432 cJSON_AddNumberToObject(
433 jMove,
434 "id",
435 __builtin_bswap16(pki->moves[j]));
436 306
437 cJSON_AddNumberToObject( 307 cJSON_AddStringToObject(jPoke, "storage", "party");
438 jMove, 308 cJSON_AddNumberToObject(jPoke, "slot", i);
439 "ppBonuses",
440 (pki->ppBonuses >> (2*j)) & 3);
441 309
442 cJSON_AddItemToArray(jMoves, jMove); 310 cJSON_AddItemToArray(jParty, jPoke);
443 } else { 311 }
444 break;
445 }
446 }
447 312
448 cJSON_AddItemToObject( 313 for (int i=0; i<14; i++)
449 jPoke, 314 {
450 "moves", 315 printf("Getting box %d...\n", i+1);
451 jMoves);
452 316
453 if (pki->otGender) 317 for (int j=0; j<30; j++)
454 { 318 {
455 cJSON_AddStringToObject(jPoke, "otGender", "female"); 319 int isPoke = getMsg();
456 } else {
457 cJSON_AddStringToObject(jPoke, "otGender", "male");
458 }
459
460 cJSON_AddNumberToObject(
461 jPoke,
462 "metLevel",
463 pki->metLevel);
464 320
465 cJSON_AddNumberToObject( 321 if (isPoke == 1)
466 jPoke, 322 {
467 "metLocation", 323 usleep(5000);
468 pki->metLocation);
469 324
470 cJSON_AddBoolToObject( 325 u32 rawdata[sizeof(struct PokemonIntermediate) / 4];
471 jPoke, 326 getMsgArr(rawdata, sizeof(struct PokemonIntermediate) / 4);
472 "shiny",
473 pki->shiny);
474 327
475 cJSON_AddNumberToObject( 328 struct PokemonIntermediate* pki =
476 jPoke, 329 (struct PokemonIntermediate*)(&rawdata);
477 "nature",
478 pki->nature);
479 330
480 if (pki->gender == 0) 331 cJSON* jPoke = pokemonToJson(pki);
481 {
482 cJSON_AddStringToObject(jPoke, "gender", "male");
483 } else if (pki->gender == 1)
484 {
485 cJSON_AddStringToObject(jPoke, "gender", "female");
486 } else if (pki->gender == 2)
487 {
488 cJSON_AddStringToObject(jPoke, "gender", "genderless");
489 }
490 332
491 cJSON_AddBoolToObject( 333 cJSON_AddStringToObject(jPoke, "storage", "box");
492 jPoke, 334 cJSON_AddNumberToObject(jPoke, "box", i);
493 "secondAbility", 335 cJSON_AddNumberToObject(jPoke, "slot", j);
494 pki->altAbility);
495 336
496 // Handle Unown form. 337 cJSON_AddItemToArray(jParty, jPoke);
497 if (pki->species == 201) 338 }
498 {
499 cJSON_AddNumberToObject(
500 jPoke,
501 "unownLetter",
502 pki->unownLetter);
503 } 339 }
504
505 cJSON_AddItemToArray(jParty, jPoke);
506 } 340 }
507 341
508 cJSON_AddItemToObject(root, "pokemon", jParty); 342 cJSON_AddItemToObject(root, "pokemon", jParty);
509 343
510 char *rendered = cJSON_Print(root); 344 char *rendered = cJSON_Print(root);
511 printf("%s\n", rendered); 345 //printf("%s\n", rendered);
346
347 printf("Press A to send.\n");
512 348
513 waitForButtons(PAD_BUTTON_A); 349 waitForButtons(PAD_BUTTON_A);
514 350