Mandrew

ManRNG - main.cpp nearing completion

Sep 8th, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.73 KB | None | 0 0
  1. /* ManRNG - a cross-platform command-line RNG generator for Pokémon games
  2.  (c) M.andrew 2012
  3.  
  4.  This utility provides the user with access to the full range of RNG
  5.  operations available in the popular Pokémon series of games, allowing
  6.  him to find shiny and/or flawless Pokémon no matter what type of computer
  7.  he is using. By default, positive results are send to stdout in CSV format,
  8.  allowing them to be easily piped into bash text manipulation utilities
  9.  or simply saved directly into text files.
  10.  
  11.  The ultimate goal of this program is to match the seed-generation capabilities
  12.  of the widely-known RNG Reporter utility for Windows while supporting all
  13.  of its major file formats, including the XML profiles of the alpha-stage
  14.  RNGR 9.96. Once this goal is realized and a standarized format for args
  15.  is set in place, I foresee writing frontends for the program to improve
  16.  its ease of use for the public.
  17. */
  18. #include <stdio.h>
  19. #include <cstdlib>
  20. #include <iostream>
  21.  
  22. #include "researcher.h"
  23. #include "thirdgen.h"
  24. #include "fourthgen.h"
  25. #include "fifthgen.h"
  26.  
  27. enum ERROR_CODES {
  28.     ERR_NOARGS   = 1,
  29.     ERR_NOMETHOD,
  30.     ERR_FALSEARGS,
  31.     ERR_3GNOSUPPORT,
  32.     ERR_4GNOSUPPORT,
  33.     ERR_5GNOSUPPORT,
  34. };
  35.  
  36. int MethodLen (char* Method) {
  37.     int counter = 0;
  38.     do
  39.     {
  40.         counter++=Method++;
  41.     }
  42.     while (Method != NULL)
  43.     return counter;
  44. }
  45.  
  46. char RNGMethodHandler(int Generation, char* Method)
  47. {
  48.     char MethodSwitch;
  49.     int ArgLen = MethodLen(Method);
  50.     if (ArgLen < 2)
  51.     {
  52.         fprintf(stderr,"Method string must be at least 2 chars!");
  53.         exit(ERR_NOMETHOD);
  54.     }
  55.     else if (ArgLen == 2)
  56.     {
  57.         MethodSwitch = Method[1];
  58.     }
  59.     char LongOpSwitch = Method[1]++;
  60.     if (LongOpSwitch == '-')
  61.     {
  62.         // we're using longops here. we're going to convert
  63.         // them into single-char options and let them
  64.         // gracefully descend through the control flow
  65.        
  66.         // options supported:  
  67.         // -t [--timefinder]
  68.         // -p [--pandora]
  69.         // -v [--pidfromivs]
  70.         // -c [--chainsidfinder]
  71.         // -m [--seed2time]
  72.         // -r [--parameters]
  73.         char* LongOpName = new char[ArgLen-2];
  74.         for (int i = 0, i >= ArgLen-2, i++)
  75.         {
  76.             LongOpName[i] = Method[i+2];
  77.         }
  78.         if      (LongOpName == "timefinder")     { MethodSwitch = 't'; }
  79.         else if (LongOpName == "pandora")        { MethodSwitch = 'p'; }
  80.         else if (LongOpName == "pidfromivs")     { MethodSwitch = 'v'; }
  81.         else if (LongOpName == "chainsidfinder") { MethodSwitch = 'c'; }
  82.         else if (LongOpName == "seed2time")      { MethodSwitch = 'm'; }
  83.         else if (LongOpName == "parameters")     { MethodSwitch = 'r'; }
  84.         else
  85.         {
  86.             fprintf(stderr,"Long method name unrecognized!")
  87.             exit(ERR_NOMETHOD);
  88.         }
  89.     }
  90.     switch (Generation)
  91.     {
  92.         case 3:
  93.             // options supported:
  94.             // -t [--timefinder]
  95.             // -p [--pandora]
  96.             switch (MethodSwitch)
  97.             {
  98.                 case 't':
  99.                     TimeFinderThird();
  100.                     break;
  101.                 case 'p':
  102.                     PandoraThird();
  103.                     break;
  104.                 default:
  105.                     fprintf(stderr,"Unsupported method for third generation RNG.");
  106.                     exit(ERR_3GNOSUPPORT);
  107.             }
  108.         case 4:
  109.             // options supported:
  110.             // -t [--timefinder]
  111.             // -v [--pidfromivs]
  112.             // -c [--chainsidfinder]
  113.             // -m [--seed2time]
  114.             // -p [--pandora]
  115.             switch (MethodSwitch)
  116.             {
  117.                 case 't':
  118.                     TimeFinderFourth();
  119.                     break;
  120.                 case 'v':
  121.                     PidFromIVsFourth();
  122.                     break;
  123.                 case 'c':
  124.                     ChainSIDFinderFourth();
  125.                     break;
  126.                 case 'm':
  127.                     Seed2TimeFourth();
  128.                     break;
  129.                 case 'p':
  130.                     PandoraFourth();
  131.                     break;
  132.                 default:
  133.                     fprintf(stderr,"Unsupported method for fourth generation RNG.");
  134.                     exit(ERR_5GNOSUPPORT);
  135.             }
  136.         case 5:    
  137.             // options supported:
  138.             // -t [--timefinder]
  139.             // -r [--parameters]
  140.             // -m [--seed2time] (c-gear)
  141.             // -p [--pandora]
  142.             switch (MethodSwitch)
  143.             {
  144.                 case 't':
  145.                     TimeFinderFifth();
  146.                     break;
  147.                 case 'r':
  148.                     ParamSearchFifth();
  149.                     break;
  150.                 case 'm':
  151.                     Seed2TimeFifth();
  152.                     break;
  153.                 case 'p':
  154.                     PandoraFifth();
  155.                     break;
  156.                 default:
  157.                     fprintf(stderr,"Unsupported method for fifth generation RNG.");
  158.                     exit(ERR_5GNOSUPPORT);
  159.             }
  160.     }
  161.     return 0;
  162. }
  163.  
  164. int main(int argc, char* argv[])
  165. {
  166.     if (argv[1] == NULL)
  167.     {
  168.         fprintf(stderr,"ManRNG cannot function without any arguments!");
  169.         exit(ERR_NOARGS);
  170.     }
  171.    
  172.     char GenFlag = argv[1][1]; //this should be a 3, 4, or 5
  173.     char* MethodSearch;
  174.     if (GenFlag == '3' || GenFlag == '4' || GenFlag == '5')
  175.     {
  176.         MethodSearch = argv[2];
  177.         if (MethodSearch == "")
  178.         {
  179.             fprintf(stderr,"ManRNG requires a method as its second argument.");
  180.             exit(ERR_NOMETHOD);
  181.         }
  182.         RNGMethodHandler(static_cast<int>(GenFlag),MethodSearch);
  183.     }
  184.     else if (GenFlag == 'r')
  185.     {
  186.         Researcher();
  187.     }
  188.     else
  189.     {
  190.         fprintf(stderr,"ManRNG requires -3, -4, -5, or -r as its first argument.");
  191.         exit(ERR_FALSEARGS);
  192.     }
  193. }
Advertisement
Add Comment
Please, Sign In to add comment