Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ManRNG - a cross-platform command-line RNG generator for Pokémon games
- (c) M.andrew 2012
- This utility provides the user with access to the full range of RNG
- operations available in the popular Pokémon series of games, allowing
- him to find shiny and/or flawless Pokémon no matter what type of computer
- he is using. By default, positive results are send to stdout in CSV format,
- allowing them to be easily piped into bash text manipulation utilities
- or simply saved directly into text files.
- The ultimate goal of this program is to match the seed-generation capabilities
- of the widely-known RNG Reporter utility for Windows while supporting all
- of its major file formats, including the XML profiles of the alpha-stage
- RNGR 9.96. Once this goal is realized and a standarized format for args
- is set in place, I foresee writing frontends for the program to improve
- its ease of use for the public.
- */
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include "researcher.h"
- #include "thirdgen.h"
- #include "fourthgen.h"
- #include "fifthgen.h"
- enum ERROR_CODES {
- ERR_NOARGS = 1,
- ERR_NOMETHOD,
- ERR_FALSEARGS,
- ERR_3GNOSUPPORT,
- ERR_4GNOSUPPORT,
- ERR_5GNOSUPPORT,
- ERR_UNKNOWN = 255,
- };
- char RNGMethodHandler(int Generation, char* Method)
- {
- char MethodSwitch;
- size_t ArgLen = strlen(Method);
- if (ArgLen < 2)
- {
- fprintf(stderr,"Method string must be at least 2 chars!\n");
- exit(ERR_NOMETHOD);
- }
- else if (ArgLen == 2)
- {
- MethodSwitch = Method[1];
- }
- else
- {
- // we're using longops here. we're going to convert
- // them into single-char options and let them
- // gracefully descend through the control flow
- // options supported:
- // -t [--timefinder]
- // -p [--pandora]
- // -v [--pidfromivs]
- // -c [--chainsidfinder]
- // -m [--seed2time]
- // -r [--parameters]
- // -q [--noclue]
- int LongArgLen = static_cast<int>(ArgLen-2); // -2 to account for the two hyphens
- char* LongOpName = new char[LongArgLen];
- for (int i = 0; i >= LongArgLen; ++i)
- {
- LongOpName[i] = Method[i+2];
- }
- if (LongOpName == "timefinder") { MethodSwitch = 't'; }
- else if (LongOpName == "pandora") { MethodSwitch = 'p'; }
- else if (LongOpName == "pidfromivs") { MethodSwitch = 'v'; }
- else if (LongOpName == "chainsidfinder") { MethodSwitch = 'c'; }
- else if (LongOpName == "seed2time") { MethodSwitch = 'm'; }
- else if (LongOpName == "parameters") { MethodSwitch = 'r'; }
- else if (LongOpName == "noclue") { MethodSwitch = 'q'; }
- else
- {
- fprintf(stderr,"Long method name unrecognized!\n");
- delete[] LongOpName;
- exit(ERR_NOMETHOD);
- }
- delete[] LongOpName;
- }
- // Now that we're here, we should
- switch (Generation)
- {
- case '3':
- // options supported:
- // -t [--timefinder]
- // -p [--pandora]
- switch (MethodSwitch)
- {
- case 't':
- TimeFinderThird();
- break;
- case 'p':
- PandoraThird();
- break;
- default:
- fprintf(stderr,"Unsupported method for third generation RNG.\n");
- exit(ERR_3GNOSUPPORT);
- }
- break;
- case '4':
- // options supported:
- // -t [--timefinder]
- // -v [--pidfromivs]
- // -c [--chainsidfinder]
- // -m [--seed2time]
- // -p [--pandora]
- switch (MethodSwitch)
- {
- case 't':
- TimeFinderFourth();
- break;
- case 'v':
- PidFromIVsFourth();
- break;
- case 'c':
- ChainSIDFinderFourth();
- break;
- case 'm':
- Seed2TimeFourth();
- break;
- case 'p':
- PandoraFourth();
- break;
- default:
- fprintf(stderr,"Unsupported method for fourth generation RNG.\n");
- exit(ERR_5GNOSUPPORT);
- break;
- }
- break;
- case '5':
- // options supported:
- // -t [--timefinder]
- // -r [--parameters]
- // -m [--seed2time] (c-gear)
- // -p [--pandora]
- switch (MethodSwitch)
- {
- case 't':
- TimeFinderFifth();
- break;
- case 'r':
- ParamSearchFifth();
- break;
- case 'm':
- Seed2TimeFifth();
- break;
- case 'p':
- PandoraFifth();
- break;
- default:
- fprintf(stderr,"Unsupported method for fifth generation RNG.\n");
- exit(ERR_5GNOSUPPORT);
- break;
- }
- break;
- case 'r':
- // options supported:
- // -q [--noclue]
- switch (MethodSwitch)
- {
- case 'q':
- Researcher();
- break;
- default:
- fprintf(stderr,"I have no idea what modes Researcher should support. But not that one!\n");
- exit(ERR_UNKNOWN);
- break;
- }
- break;
- default:
- fprintf(stderr,"This error should never happen. Consult Mandrew for advice.\n");
- exit(ERR_UNKNOWN);
- break;
- }
- return 0;
- }
- int main(int argc, char* argv[])
- {
- if (argv[1] == NULL)
- {
- fprintf(stderr,"ManRNG cannot function without any arguments!\n");
- exit(ERR_NOARGS);
- }
- char GenFlag = argv[1][1]; //this should be a 3, 4, or 5
- char* MethodSearch;
- if (GenFlag == '3' || GenFlag == '4' || GenFlag == '5' || GenFlag == 'r')
- {
- MethodSearch = argv[2];
- if (MethodSearch == NULL)
- {
- fprintf(stderr,"ManRNG requires a method as its second argument.\n");
- exit(ERR_NOMETHOD);
- }
- RNGMethodHandler(static_cast<int>(GenFlag),MethodSearch);
- }
- else if (GenFlag == 'v')
- {
- printf("ManRNG version 0.01\n");
- }
- else
- {
- fprintf(stderr,"ManRNG requires -3, -4, -5, -r, or -v as its first argument.\n");
- exit(ERR_FALSEARGS);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment