View difference between Paste ID: LbJEGpUN and 7PGq8Eyw
SHOW: | | - or go back to the newest paste.
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
#include <cstring>
22
23
#include "researcher.h"
24
#include "thirdgen.h"
25
#include "fourthgen.h"
26
#include "fifthgen.h"
27
28
enum ERROR_CODES {
29
	ERR_NOARGS   = 1,
30
	ERR_NOMETHOD,
31
	ERR_FALSEARGS,
32
	ERR_3GNOSUPPORT,
33
	ERR_4GNOSUPPORT,
34
	ERR_5GNOSUPPORT,
35
};
36-
int MethodLen (char* Method) {
36+
37-
	int counter = 0;
37+
38-
	do
38+
39
	char MethodSwitch;
40-
		counter++=Method++;
40+
	int ArgLen = strlen(Method);
41
	if (ArgLen < 2)
42-
	while (Method != NULL)
42+
43-
	return counter;
43+
44
		exit(ERR_NOMETHOD);
45
	}
46
	else if (ArgLen == 2)
47
	{
48
		MethodSwitch = Method[1];
49-
	int ArgLen = MethodLen(Method);
49+
50
	char LongOpSwitch = Method[1]++;
51
	if (LongOpSwitch == '-')
52
	{
53
		// we're using longops here. we're going to convert
54
		// them into single-char options and let them
55
		// gracefully descend through the control flow
56
		
57
		// options supported:	
58
		// -t [--timefinder]
59
		// -p [--pandora]
60
		// -v [--pidfromivs]
61
		// -c [--chainsidfinder]
62
		// -m [--seed2time]
63
		// -r [--parameters]
64
		char* LongOpName = new char[ArgLen-2];
65
		for (int i = 0; i >= ArgLen-2; ++i)
66
		{
67
			LongOpName[i] = Method[i+2];
68
		}
69
		if      (LongOpName == "timefinder")     { MethodSwitch = 't'; }
70
		else if (LongOpName == "pandora")        { MethodSwitch = 'p'; }
71
		else if (LongOpName == "pidfromivs")     { MethodSwitch = 'v'; }
72
		else if (LongOpName == "chainsidfinder") { MethodSwitch = 'c'; }
73
		else if (LongOpName == "seed2time")      { MethodSwitch = 'm'; }
74-
		for (int i = 0, i >= ArgLen-2, i++)
74+
75
		else
76
		{
77
			fprintf(stderr,"Long method name unrecognized!");
78
			exit(ERR_NOMETHOD);
79
		}
80
	}
81
	switch (Generation)
82
	{
83
		case 3:
84
			// options supported:
85
			// -t [--timefinder]
86-
			fprintf(stderr,"Long method name unrecognized!")
86+
87
			switch (MethodSwitch)
88
			{
89
				case 't':
90
					TimeFinderThird();
91
					break;
92
				case 'p':
93
					PandoraThird();
94
					break;
95
				default:
96
					fprintf(stderr,"Unsupported method for third generation RNG.");
97
					exit(ERR_3GNOSUPPORT);
98
			}
99
		case 4:
100
			// options supported:
101
			// -t [--timefinder]
102
			// -v [--pidfromivs]
103
			// -c [--chainsidfinder]
104
			// -m [--seed2time]
105
			// -p [--pandora]
106
			switch (MethodSwitch)
107
			{
108
				case 't':
109
					TimeFinderFourth();
110
					break;
111
				case 'v':
112
					PidFromIVsFourth();
113
					break;
114
				case 'c':
115
					ChainSIDFinderFourth();
116
					break;
117
				case 'm':
118
					Seed2TimeFourth();
119
					break;
120
				case 'p':
121
					PandoraFourth();
122
					break;
123
				default:
124
					fprintf(stderr,"Unsupported method for fourth generation RNG.");
125
					exit(ERR_5GNOSUPPORT);
126
			}
127
		case 5:		
128
			// options supported:
129
			// -t [--timefinder]
130
			// -r [--parameters]
131
			// -m [--seed2time] (c-gear)
132
			// -p [--pandora]
133
			switch (MethodSwitch)
134
			{
135
				case 't':
136
					TimeFinderFifth();
137
					break;
138
				case 'r':
139
					ParamSearchFifth();
140
					break;
141
				case 'm':
142
					Seed2TimeFifth();
143
					break;
144
				case 'p':
145
					PandoraFifth();
146
					break;
147
				default:
148
					fprintf(stderr,"Unsupported method for fifth generation RNG.");
149
					exit(ERR_5GNOSUPPORT);
150
			}
151
	}
152
	return 0;
153
}
154
155
int main(int argc, char* argv[])
156
{
157
	if (argv[1] == NULL)
158
	{
159
		fprintf(stderr,"ManRNG cannot function without any arguments!");
160
		exit(ERR_NOARGS);
161
	}
162
	
163
	char GenFlag = argv[1][1]; //this should be a 3, 4, or 5
164
	char* MethodSearch;
165
	if (GenFlag == '3' || GenFlag == '4' || GenFlag == '5')
166
	{
167
		MethodSearch = argv[2];
168
		if (MethodSearch == "")
169
		{
170
			fprintf(stderr,"ManRNG requires a method as its second argument.");
171
			exit(ERR_NOMETHOD);
172
		}
173
		RNGMethodHandler(static_cast<int>(GenFlag),MethodSearch);
174
	}
175
	else if (GenFlag == 'r')
176
	{
177
		Researcher();
178
	}
179
	else
180
	{
181
		fprintf(stderr,"ManRNG requires -3, -4, -5, or -r as its first argument.");
182
		exit(ERR_FALSEARGS);
183
	}
184
}