diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-09-24 12:40:12 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-09-24 12:40:12 -0400 |
commit | 34e22f57f04180d71772f192dad32df6e82fbe6d (patch) | |
tree | 804414973e108be676e132ae1ca433619bfeb02a /source/main.c | |
parent | 0632b82c82cb26ec942a6b77a95b3b919482b8d4 (diff) | |
download | gen3uploader-34e22f57f04180d71772f192dad32df6e82fbe6d.tar.gz gen3uploader-34e22f57f04180d71772f192dad32df6e82fbe6d.tar.bz2 gen3uploader-34e22f57f04180d71772f192dad32df6e82fbe6d.zip |
GBA now sends over contents of boxes
Diffstat (limited to 'source/main.c')
-rw-r--r-- | source/main.c | 220 |
1 files changed, 28 insertions, 192 deletions
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 | ||
23 | void printmain() | 24 | void 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 | ||