Skip to content

Commit 2fcfa97

Browse files
added writing logic, but might still have write bug
1 parent 150ab15 commit 2fcfa97

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

Diff for: src/main.cpp

+36-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void editstats(string filename);
3232

3333
string backupfile(void);
3434

35-
#define numberofbytesinfile 4357 // last offset 4356=0x1104
35+
#define numberofbytesinfile 4356 // last offset 4356=0x1104
3636
#define medalsstart 1404 // 0x57c
3737
#define medalsend 1422 // 0x58d
3838
#define statsstart 3980 // 0xf8c
@@ -141,6 +141,7 @@ void editmedals(string filename){
141141
medals = fullfile.substr(medalsstart, medalsend - medalsstart);
142142
p3 = fullfile.substr(medalsend);
143143

144+
inFile.close();
144145
/* Decode medals string
145146
// split each medal from string
146147
// decode medal and store in var
@@ -177,8 +178,8 @@ void editmedals(string filename){
177178
cout << "Frenzy" << "\t\t\t" << umed[1] << endl;
178179
cout << endl;
179180

180-
cout << "Change or no change?" << endl;
181-
cout << "c: change medal count\t e: exit to main menu" << endl;
181+
cout << "Change, no change, write to file?" << endl;
182+
cout << "c: change medal count\t w:write to file\t e: exit to main menu" << endl;
182183
string answer;
183184
getline(cin, answer);
184185

@@ -198,6 +199,38 @@ void editmedals(string filename){
198199
myStream >> umed[i];
199200
}
200201
}
202+
if (answer == "w") {
203+
ofstream writeFile(filename, ios::out | ios::binary);
204+
205+
if (writeFile.is_open())
206+
{
207+
char *b = (char*)malloc(18 * sizeof(char));
208+
209+
for (int j = 0; j < 9; j++) {
210+
b[j * 2] = (char)(umed[j] & 0xFF);
211+
b[j * 2 + 1] = (char)(umed[j] >> 8);
212+
}
213+
214+
string newMedals(b);
215+
216+
string newData = p1 + newMedals + p3;
217+
218+
writeFile << newData;
219+
220+
system("cls");
221+
222+
cout << "Write Complete" << endl;
223+
cout << endl;
224+
break;
225+
}
226+
else
227+
{
228+
cout << "Bad filename or other error." << endl;
229+
cout << endl;
230+
break;
231+
}
232+
writeFile.close();
233+
}
201234
}
202235
}
203236

0 commit comments

Comments
 (0)