This repository was archived by the owner on Dec 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
350 lines (310 loc) · 11.8 KB
/
main.cpp
File metadata and controls
350 lines (310 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <chrono>
#include <bitset>
#include "h2o/h2o.hpp"
h2o::Replay globalReplay;
void createDirectories(){
std::filesystem::path folder1 = "hydro";
if (!std::filesystem::exists(folder1)) {
std::filesystem::create_directory(folder1);
}
std::filesystem::path folder2 = "plaintext";
if (!std::filesystem::exists(folder2)) {
std::filesystem::create_directory(folder2);
}
}
void plainToHydro(){
std::string fileName;
std::cout << "\n" << "Enter the file name: ";
std::getline(std::cin >> std::ws,fileName);
globalReplay = h2o::Replay();
uint8_t r = globalReplay.importPlaintext(fileName);
switch(r){
case 0:
std::cout << "\n" << "File Has Been Imported And Loaded Into Memory" << "\n\n";
break;
case 1:
std::cout << "\n" << "An Error Occurred (File Open Failed)" << "\n\n";
default:
std::cout << "\n" << "An Error Occurred (Unknown)" << "\n\n";
break;
}
}
void exportMacro(){
std::string cleanMacro;
std::cout << "\n" << "Clean Macro/Remove Redunant Releases (y/n): ";
std::cin >> cleanMacro;
if(cleanMacro == "y"){ globalReplay.cleanMacro(); }
globalReplay.calculateInputCount();
globalReplay.prepareDeltaVector();
uint8_t exportLog = globalReplay.exportFile();
switch (exportLog){
case 0:
std::cout << "\nMacro Has Been Exported \n\n";
break;
case 1:
std::cout << "\nMacro Has Already Been Exported/File Exists With The Same Name\n\n";
break;
}
}
void importMacro(){
std::string fileName;
std::cout << "\n" << "Enter the file name: ";
std::getline(std::cin >> std::ws,fileName);
bool crc = true;
std::string temp;
std::cout << "\n" << "Check For Corruption(y/n): ";
std::getline(std::cin >> std::ws,temp);
if(temp == "n"){ crc = false; }
globalReplay = h2o::Replay();
uint8_t r = globalReplay.importHydro(fileName,crc);
switch(r){
case 0:
std::cout << "\n" << "File Has Been Imported And Loaded Into Memory" << "\n\n";
break;
case 1:
std::cout << "\n" << "An Error Occurred (File Open Failed)" << "\n\n";
break;
case 2:
std::cout << "\n" << "An Error Occurred (Magic Number Doesn't Match)" << "\n\n";
break;
case 3:
std::cout << "\n" << "An Error Occurred (Format Version Isn't Supported)" << "\n\n";
break;
case 4:
std::cout << "\n" << "File Has Been Imported And Loaded Into Memory But Corruption Has Been Detected" << "\n\n";
break;
default:
std::cout << "\n" << "An Error Occurred (Unknown)" << "\n\n";
break;
}
}
void testMacro(){
globalReplay = h2o::Replay();
globalReplay.macroMetadata("Friend List Challenge","EESports","this is the first ever hydro macro");
globalReplay.levelMetadata("Friend List Challeng",70823189,false,false,false,false,false);
globalReplay.botMetadata("xdBot",h2o::SemVer(2,4,0));
globalReplay.changeTPS(240);
globalReplay.timeMetadata(5163,1239);
using InputType = h2o::InputType;
globalReplay.addInput(49,InputType::P1JUMPCLICK);
globalReplay.addInput(60,InputType::P1JUMPREL);
globalReplay.addInput(205,InputType::P1JUMPCLICK);
globalReplay.addInput(213,InputType::P1JUMPREL);
globalReplay.addInput(233,InputType::P1JUMPCLICK);
globalReplay.addInput(291,InputType::P1JUMPREL);
globalReplay.addInput(420,InputType::P1JUMPCLICK);
globalReplay.addInput(428,InputType::P1JUMPREL);
globalReplay.addInput(439,InputType::P1JUMPCLICK);
globalReplay.addInput(447,InputType::P1JUMPREL);
globalReplay.addInput(464,InputType::P1JUMPCLICK);
globalReplay.addInput(470,InputType::P1JUMPREL);
globalReplay.addInput(484,InputType::P1JUMPCLICK);
globalReplay.addInput(490,InputType::P1JUMPREL);
globalReplay.addInput(551,InputType::P1JUMPCLICK);
globalReplay.addInput(606,InputType::P1JUMPREL);
globalReplay.addInput(676,InputType::P1JUMPCLICK);
globalReplay.addInput(683,InputType::P1JUMPREL);
globalReplay.addInput(893,InputType::P1JUMPCLICK);
globalReplay.addInput(905,InputType::P1JUMPREL);
globalReplay.addInput(1049,InputType::P1JUMPCLICK);
globalReplay.addInput(1060,InputType::P1JUMPREL);
globalReplay.addInput(1226,InputType::P1JUMPCLICK);
globalReplay.addInput(1239,InputType::P1JUMPREL);
globalReplay.calculateInputCount();
globalReplay.prepareDeltaVector();
uint8_t exportLog = globalReplay.exportFile();
switch (exportLog){
case 0:
std::cout << "\nTest Macro Has Been Exported And Loaded Into Memory\n\n";
break;
case 1:
std::cout << "\nTest Macro Has Already Been Exported But Has Been Loaded Into Memory\n\n";
break;
}
}
void viewMacroSnippet(){
std::cout << "\n" << "Macro Name: " << globalReplay.viewMacroName() << "\n"
<< "Macro Creator: " << globalReplay.viewMacroCreator() << "\n"
<< "Macro Description: " << globalReplay.viewMacroDescription() << "\n"
<< "Game Version: " << globalReplay.viewGameVersion() << "\n"
<< "Bot Name: " << globalReplay.viewBotName() << "\n"
<< "Bot Version: "
<< globalReplay.viewBotVersion().major
<< "." << globalReplay.viewBotVersion().minor
<< "." << globalReplay.viewBotVersion().patch
<< globalReplay.viewBotVersion().prNote << "\n"
<< "Level Name: " << globalReplay.viewLevelName() << "\n"
<< "Level ID: " << globalReplay.viewLevelID() << "\n"
<< "Replay Time: " << globalReplay.viewReplayTime() << " ms\n"
<< "Total Frames: " << globalReplay.viewTotalFrames() << " frames\n"
<< "Death Count: " << globalReplay.viewDeathCount() << " deaths\n"
<< "Player 1 Input Count: " << globalReplay.viewP1InputCount() << " inputs\n"
<< "Player 2 Input Count: " << globalReplay.viewP2InputCount() << " inputs\n"
<< "Raw Hydro Bitmask: " << std::bitset<16>(globalReplay.viewBitmask()) << "\n\n";
std::cout << "Initial TPS: " << globalReplay.viewTPS()[0] << " TPS\n\n";
std::vector<h2o::InputPair> inputVector = globalReplay.viewInputBlock();
uint8_t iterations = std::min(50,static_cast<int32_t>(inputVector.size()));
for(uint16_t i = 0; i < iterations; i++){
std::string playerInput;
switch (inputVector[i].input){
case 0:
playerInput = "Player 1 Jump Click";
break;
case 1:
playerInput = "Player 1 Jump Release";
break;
case 2:
playerInput = "Player 2 Jump Click";
break;
case 3:
playerInput = "Player 2 Jump Release";
break;
case 4:
playerInput = "TPS Change";
break;
case 5:
playerInput = "Intentional Death";
break;
case 6:
playerInput = "Set Player Physics/Position";
break;
case 7:
playerInput = "Reserved";
break;
case 8:
playerInput = "Player 1 Left Click";
break;
case 9:
playerInput = "Player 1 Left Release";
break;
case 10:
playerInput = "Player 1 Right Click";
break;
case 11:
playerInput = "Player 1 Right Release";
break;
case 12:
playerInput = "Player 2 Left Click";
break;
case 13:
playerInput = "Player 2 Left Release";
break;
case 14:
playerInput = "Player 2 Right Click";
break;
case 15:
playerInput = "Player 2 Right Release";
break;
}
std::cout << "Input #" << i+1 << "\n"
<< "Frame: " << inputVector[i].frame << "\n"
<< "Input Type: " << playerInput << "\n\n";
}
}
void editMetadata(){
std::string mName, mCreator, mDescription;
std::cout << "\n" << "Macro Name: ";
std::getline(std::cin >> std::ws,mName);
std::cout << "\n" << "Macro Creator: ";
std::getline(std::cin >> std::ws,mCreator);
std::cout << "\n" << "Macro Description (n for none): ";
std::getline(std::cin >> std::ws,mDescription);
if(mDescription == "n"){ mDescription = ""; }
globalReplay.macroMetadata(mName,mCreator,mDescription);
std::string lvlName, lvlID, temp;
std::cout << "\n" << "Level Name: ";
std::getline(std::cin >> std::ws,lvlName);
std::cout << "\n" << "Level ID: ";
std::getline(std::cin >> std::ws,lvlID);
std::string botName, verMajor, verMinor, verPatch, verPRNote;
std::cout << "\n" << "Bot Name: ";
std::getline(std::cin >> std::ws,botName);
std::cout << "\n" << "Bot Version Major: ";
std::getline(std::cin >> std::ws,verMajor);
std::cout << "\n" << "Bot Version Minor: ";
std::getline(std::cin >> std::ws,verMinor);
std::cout << "\n" << "Bot Version Patch: ";
std::getline(std::cin >> std::ws,verPatch);
std::cout << "\n" << "Bot Version Pre-Release Note (n for none): ";
std::getline(std::cin >> std::ws,verPRNote);
if(verPRNote == "n"){ verPRNote = ""; }
globalReplay.botMetadata(botName,h2o::SemVer(std::stoi(verMajor),std::stoi(verMinor),std::stoi(verPatch),verPRNote));
bool LDM, platformer, coin1, coin2, coin3;
LDM = platformer = coin1 = coin2 = coin3 = false;
std::cout << "\n" << "Low Detail Mode (y/n): ";
std::getline(std::cin >> std::ws,temp);
if(temp == "y"){ LDM = true; temp = ""; }
std::cout << "\n" << "Platformer Mode (y/n): ";
std::getline(std::cin >> std::ws,temp);
if(temp == "y"){ platformer = true; temp = ""; }
std::cout << "\n" << "Coin 1 Collected (y/n): ";
std::getline(std::cin >> std::ws,temp);
if(temp == "y"){ coin1 = true; temp = ""; }
std::cout << "\n" << "Coin 2 Collected (y/n): ";
std::getline(std::cin >> std::ws,temp);
if(temp == "y"){ coin2 = true; temp = ""; }
std::cout << "\n" << "Coin 3 Collected (y/n): ";
std::getline(std::cin >> std::ws,temp);
if(temp == "y"){ coin3 = true; temp = ""; }
globalReplay.levelMetadata(lvlName,std::stoi(lvlID),LDM,platformer,coin1,coin2,coin3);
std::string replayTime, totalFrames;
std::cout << "\n" << "Replay Time (ms): ";
std::getline(std::cin >> std::ws,replayTime);
std::cout << "\n" << "Total Frames: ";
std::getline(std::cin >> std::ws,totalFrames);
globalReplay.timeMetadata(std::stoi(replayTime),std::stoi(totalFrames));
std::cout << "\n\n" << "Metadata Editing Complete" << "\n\n";
}
void clearMemory(){
globalReplay = h2o::Replay();
std::cout << "\n" << "Memory Has Been Cleared" << "\n\n";
}
int main(){
createDirectories();
while(true){
std::cout << "Select one of the following\n"
<< "1. Import Plaintext\n"
<< "2. Export Hydro Macro\n"
<< "3. Import Hydro Macro\n"
<< "4. Hydro Test Macro\n"
<< "5. List Macro Metadata & 50 Inputs\n"
<< "6. Edit Metadata (Header)\n"
<< "7. Clear Memory\n"
<< "\n";
std::string option;
std::cin >> option;
switch (std::stoi(option)){
case 0:
return 0;
break;
case 1:
plainToHydro();
break;
case 2:
exportMacro();
break;
case 3:
importMacro();
break;
case 4:
testMacro();
break;
case 5:
viewMacroSnippet();
break;
case 6:
editMetadata();
break;
case 7:
clearMemory();
break;
default:
std::cout << "The following input is not valid, please try again\n";
break;
}
}
}