Skip to content

Commit 21158a1

Browse files
committedJan 18, 2020
Added stats editing, fixed potential issue with zeroes, added tutorial vid.
1 parent ed8b553 commit 21158a1

File tree

2 files changed

+135
-2
lines changed

2 files changed

+135
-2
lines changed
 

‎src/main.cpp

+135-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ string names[9] = { "Gunslinger",
2626
"Guardian",
2727
"War Hero" };
2828

29+
string statStrings[3] = { "Player Points",
30+
"Kills",
31+
"Deaths" };
32+
2933
void edit(string cmd, bool &done);
3034
void editmedals(string filename);
3135
void editstats(string filename);
@@ -36,7 +40,7 @@ string backupfile(void);
3640
#define medalsstart 1404 // 0x57c
3741
#define medalsend 1422 // 0x58d
3842
#define statsstart 3980 // 0xf8c
39-
#define statend 3991 // 0xf97
43+
#define statend 3992 // 0xf97
4044
// each medal two bytes
4145
// stats 4 bytes
4246
/*
@@ -211,7 +215,7 @@ void editmedals(string filename){
211215
b[j * 2 + 1] = (char)(umed[j] >> 8);
212216
}
213217

214-
string newMedals(b);
218+
string newMedals(b, 18);
215219
newMedals.resize(18);
216220
string newData = p1 + newMedals + p3;
217221

@@ -234,8 +238,137 @@ void editmedals(string filename){
234238
}
235239
}
236240

241+
// this function proves how lazy I am.
237242
void editstats(string filename){
238243

244+
ifstream inFile;
245+
size_t size = 0; // here
246+
247+
inFile.open(filename, ios::in | ios::binary | ios::ate);
248+
//char* oData = 0;
249+
250+
inFile.seekg(0, ios::end); // set the pointer to the end
251+
size = inFile.tellg(); // get the length of the file
252+
cout << "Size of file: " << size << endl;
253+
inFile.seekg(0, ios::beg); // set the pointer to the beginning
254+
255+
//print data
256+
//for (size_t i = 0; i < strlen(oData); i++)
257+
//{
258+
// cout << "oData[" << i << "] " << oData[i];
259+
// cout << oData[i] << " + 'a' = " << (oData[i] + 'a');
260+
//
261+
//}
262+
263+
// load file into string, easy to view for debugging
264+
string fullfile;
265+
fullfile.reserve(size);
266+
fullfile.assign((istreambuf_iterator<char>(inFile)),
267+
istreambuf_iterator<char>());
268+
269+
/* Separate data into parts
270+
// part 1: name and extraneous
271+
// part 2: medals
272+
// part 3: extraneous to stats and beyond
273+
*/
274+
string p1;
275+
string stats;
276+
string p3;
277+
278+
p1 = fullfile.substr(0, statsstart);
279+
stats = fullfile.substr(statsstart, statend - statsstart);
280+
p3 = fullfile.substr(statend);
281+
282+
inFile.close();
283+
/* Decode medals string
284+
// split each medal from string
285+
// decode medal and store in var
286+
*/
287+
char const *c = stats.c_str(); // am I efficient now?
288+
uint32_t umed[3]; // haha nope
289+
290+
/*
291+
uint16_t Gunslinger = ((uint8_t)c[1] << 8) | (uint8_t)c[0];
292+
uint16_t Frenzy = ((uint8_t)c[3] << 8) | (uint8_t)c[2];
293+
uint16_t Demolition = ((uint8_t)c[5] << 8) | (uint8_t)c[4];
294+
uint16_t Technician = ((uint8_t)c[7] << 8) | (uint8_t)c[6];
295+
uint16_t Marksman = ((uint8_t)c[9] << 8) | (uint8_t)c[8];
296+
uint16_t Regulator = ((uint8_t)c[11] << 8) | (uint8_t)c[10];
297+
uint16_t Endurance = ((uint8_t)c[13] << 8) | (uint8_t)c[12];
298+
uint16_t Guardian = ((uint8_t)c[15] << 8) | (uint8_t)c[14];
299+
uint16_t WarHero = ((uint8_t)c[17] << 8) | (uint8_t)c[16];
300+
*/
301+
302+
for (int k = 0; k < 3; k++) {
303+
umed[k] = ((uint8_t)c[k * 4 + 3] << 24) | ((uint8_t)c[k * 4 + 2] << 16) | ((uint8_t)c[k * 4 + 1] << 8) | (uint8_t)c[k * 4];
304+
}
305+
306+
for (;;) {
307+
system("cls");
308+
309+
cout << endl;
310+
cout << "Career Stats" << endl;
311+
cout << endl;
312+
cout << "Player Points" << "\t\t" << umed[0] << "\t" << "Kills" << "\t\t" << umed[1] << endl;
313+
cout << "Deaths" << "\t\t\t" << umed[2] << endl;
314+
cout << endl;
315+
316+
cout << "Change, no change, write to file?" << endl;
317+
cout << "c: change stat count\t w:write to file\t e: exit to main menu" << endl;
318+
string answer;
319+
getline(cin, answer);
320+
321+
if (answer == "e") {
322+
break;
323+
}
324+
if (answer == "c") {
325+
string input = "";
326+
327+
cout << "Select new stat counts." << endl; // a map would be handy
328+
for (int i = 0; i < 3; i++) {
329+
cout << statStrings[i] << ": ";
330+
getline(cin, input);
331+
cout << endl;
332+
333+
stringstream myStream(input);
334+
myStream >> umed[i];
335+
}
336+
}
337+
if (answer == "w") {
338+
ofstream writeFile(filename, ios::out | ios::binary);
339+
340+
if (writeFile.is_open())
341+
{
342+
char b[12];
343+
344+
for (int j = 0; j < 3; j++) {
345+
b[j * 4] = (char)(umed[j] & 0xFFFFFF);
346+
b[j * 4 + 1] = (char)(umed[j] >> 8);
347+
b[j * 4 + 2] = (char)(umed[j] >> 16);
348+
b[j * 4 + 3] = (char)(umed[j] >> 24);
349+
}
350+
351+
string newStats(b, 12);
352+
newStats.resize(12); // remove extraneous data
353+
string newData = p1 + newStats + p3;
354+
355+
writeFile << newData;
356+
357+
system("cls");
358+
359+
cout << "Write Complete" << endl;
360+
cout << endl;
361+
break;
362+
}
363+
else
364+
{
365+
cout << "Bad filename or other error." << endl;
366+
cout << endl;
367+
break;
368+
}
369+
writeFile.close();
370+
}
371+
}
239372

240373
}
241374

‎tutorial.mp4

2.15 MB
Binary file not shown.

0 commit comments

Comments
 (0)