-
Notifications
You must be signed in to change notification settings - Fork 1
/
Requests.cs
589 lines (458 loc) · 22.4 KB
/
Requests.cs
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using IAH_SinglePlayerAutomation.Class.Response;
using Newtonsoft.Json;
namespace IAH_SinglePlayerAutomation.Class
{
public static class Requests
{
public static string _apiPassword;
public static string _remoteBotIp;
public static async Task<bool> GetApiPassword(TransitionResponse response)
{
if (string.IsNullOrEmpty(response.state)) return false;
// API Password is used to authenticate your APILicense with the game and provide
// you with a password that you have to protect during your gameplay session.
// API Password gives you ownership of the bots that are associated with your RemoteUserBot.
// When you perform Bot Functions you need always supply API Password.
// API Password is always regenerated when your RemoteUserBot respawns. if this function is not called every 15-24 seconds game will exit AI Mode.
// In multiplayer certain bots can crack API Passwords giving you or enemies ability to hjack bots.
// API Key and API Password are not the same thing, never reveal your API Key.
if (response.state == "INGAME")
{
var jsonData = JsonConvert.SerializeObject(new Dictionary<string, object>
{
{
"ip", "127.0.0.1"
}, // in campaign mode this will be always 127.0.0.1 for your RemoteUserBot even if you operate your AI from some other PC.
{"apiKey", "yourkey"} // HTTPS://IAMHACKER.CC -> Get API Key
});
var postResponse = await SendPostRequestAsync("/v1/apipassword", jsonData);
if (postResponse.isSuccessStatusCode)
{
var passwordResponse =
JsonConvert.DeserializeObject<APIPasswordResponse>(postResponse.responseString);
_apiPassword = passwordResponse.apiPassword;
_remoteBotIp = passwordResponse.ip;
Console.WriteLine("Buffer Item Placed on The Map...");
await Task.Delay(2000);
}
return true;
}
return false;
}
public static async Task<bool> BotAction(string entityUniqueID, string action, object actionValue)
{
var jsonData = JsonConvert.SerializeObject(new Dictionary<string, object>
{
{"ip", _remoteBotIp},
{"apiPassword", _apiPassword},
{"entityUniqueID", entityUniqueID},
{"actionType", action},
{"actionValue", actionValue}
});
var postResponse = await SendPostRequestAsync("/v1/botaction", jsonData);
if (postResponse.isSuccessStatusCode) return true;
return false;
}
public static async Task RunAiLogic()
{
for (var i = 0; i < Program.GameState.entities.Count; i++)
if (Program.GameState.entities[i].ip == _remoteBotIp)
Program.GameState.entities[i].RunAi();
// 0.2 sec delay..
await Task.Delay(200);
}
public static async Task<bool> TpScreen(TransitionResponse response)
{
if (string.IsNullOrEmpty(response.state)) return false;
if (response.state == "TPSCREEN")
{
var getResponse = await Program._httpClient.GetAsync("/v1/tpscreen");
var responseContent = await getResponse.Content.ReadAsStringAsync();
if (getResponse.IsSuccessStatusCode)
{
var data = JsonConvert.DeserializeObject<TpScreenResponse>(responseContent);
if (data.tpCards.Count > 0)
{
// we got TP CARDS to choose.... time to choose one.. lets pick first -> index 0.
// https://i.gyazo.com/8e375b3f859fd92626b783c364f39b7b.png
var jsonData = JsonConvert.SerializeObject(new Dictionary<string, object>
{
{"action", 0}
});
var postResponse = await SendPostRequestAsync("/v1/tpscreen", jsonData);
return true;
}
if (data.chaosCards.Count > 0)
{
// same thing as above but only for chaos cards
var jsonData = JsonConvert.SerializeObject(new Dictionary<string, object>
{
{"action", 0}
});
var postResponse = await SendPostRequestAsync("/v1/tpscreen", jsonData);
return true;
}
}
}
return false;
}
public static async Task<bool> GetGameState(TransitionResponse response)
{
if (string.IsNullOrEmpty(response.state)) return false;
if (response.state == "INGAME" || response.state == "TPSCREEN")
{
var getResponse = await Program._httpClient.GetAsync("/v1/gameState");
var responseContent = await getResponse.Content.ReadAsStringAsync();
if (getResponse.IsSuccessStatusCode)
{
var data = JsonConvert.DeserializeObject<GameStateResponse>(responseContent);
Program.GameState.modemConnected = data.modemConnected;
Program.GameState.pcStarted = data.pcStarted;
Program.GameState.osSelected = data.osSelected;
Program.GameState.money = data.money;
Program.GameState.score = data.score;
Program.GameState.money = data.money;
Program.GameState.chaosCards = data.chaosCards;
Program.GameState.TPCards = data.TPCards;
Program.GameState.relativeDificulty = data.relativeDificulty;
Program.GameState.actionTurn = data.actionTurn;
}
return true;
}
return false;
}
public static async Task<bool> GetSystemState(TransitionResponse response)
{
var getResponse = await Program._httpClient.GetAsync("/v1/system");
var responseContent = await getResponse.Content.ReadAsStringAsync();
if (getResponse.IsSuccessStatusCode)
{
var data = JsonConvert.DeserializeObject<SystemResponse>(responseContent);
Program.GameState.fps = data.fps;
Program.GameState.version = data.version;
Program.GameState.timeRunning = data.timeRunning;
}
return true;
}
public static async Task<bool> ClickLevelUp()
{
// lets spawn first unit from our www block.. in windowsOS for example first one (zero index) is Good Bot
if (Program.GameState != null && Program.GameState.TPCards > 0)
{
var getResponse = await Program._httpClient.GetAsync("/v1/levelup");
if (getResponse.IsSuccessStatusCode) return true;
}
return false;
}
public static async Task<bool> UseFramework()
{
// if we have LESSERHEAL framework item in our inventory we will use it on our remote bot when it is low and heal ourselves.
if (Program.GameState != null && Program.GameState.webBufferTiles.Count == 0 && Program.GameState.modemConnected)
{
var tiles = Program.GameState.GetTilesByType("OSTILE", "FRAMEWORK");
//do note that this will use first remoteuserbot, it could be enemy, but for multiplayer you would want to write own code.
var entities = Program.GameState.GetEntitiesByType("REMOTEUSERBOT");
if (entities.Count > 0)
for (var i = 0; i < tiles.Count; i++)
if (tiles[i].frameworkType == "LESSERHEAL")
{
await FrameworkAction(tiles[i].uniqueID, entities[0].uniqueID);
return true;
}
}
return true;
}
public static async Task<bool> UseWWWBlock()
{
// lets spawn first unit from our www block.. in windowsOS for example first one (zero index) is Good Bot
if (Program.GameState != null && Program.GameState.webBufferTiles.Count == 0 && Program.GameState.modemConnected)
{
var tile = Program.GameState.GetTileByType("OSTILE", "WWW_BLOCK");
if (tile == null) return false;
if (tile.isBusy == false)
{
await TileAction(tile.uniqueID, -1);
await Task.Delay(500);
Program.GameState.PerformedAction();
return await TileAction(tile.uniqueID, 0);
}
}
return true;
}
public static async Task<bool> BrowseInternet()
{
// we could later expand this by checkeing that there are no enemies. etc
if (Program.GameState != null && Program.GameState.webBufferTiles.Count == 0 && Program.GameState.modemConnected)
{
var tile = Program.GameState.GetTileByType("MAPTILE", "PLAYERPC");
var ocupied = Program.GameState.GetTileByType("MAPTILE", "OCUPIED");
// for this example. we only browse net once... if we have ocupied Tile somewhere dont browse net.
if (ocupied != null) return false;
if (tile != null && tile.isBusy == false)
{
await TileAction(tile.uniqueID, -1);
await Task.Delay(500);
Program.GameState.PerformedAction();
return await TileAction(tile.uniqueID, 0);
}
}
return true;
}
public static async Task<bool> InitialMenuSequence()
{
if (Program.GameState != null && Program.GameState.tiles.Count > 0 && Program.GameState.pcStarted == false)
{
var tile = Program.GameState.GetTileByType("MAPTILE", "PLAYERPC");
if (tile != null && tile.isBusy == false)
{
await TileAction(tile.uniqueID, -1);
await Task.Delay(500);
var result = await TileAction(tile.uniqueID, 0);
}
}
else if (Program.GameState != null && Program.GameState.tiles.Count > 0 && string.IsNullOrEmpty(Program.GameState.osSelected))
{
var tile = Program.GameState.GetTileByType("MAPTILE", "PLAYERPC");
if (tile != null && tile.isBusy == false)
{
await TileAction(tile.uniqueID, -1);
await Task.Delay(500);
var result = await TileAction(tile.uniqueID, 0); // 0 windows, 1 linux, 2 love
}
}
else if (Program.GameState != null && Program.GameState.tiles.Count > 0 && Program.GameState.modemConnected == false)
{
// you could make function in the Program.GameState class that check that no Tile is busy.
var pcTile = Program.GameState.GetTileByType("MAPTILE", "PLAYERPC");
var tile = Program.GameState.GetTileByType("ITEMTILE", "MODEM");
if (tile != null && tile.isBusy == false && pcTile.isBusy == false)
{
await TileAction(tile.uniqueID, -1);
await Task.Delay(500);
var result = await TileAction(tile.uniqueID, 0);
}
}
return true;
}
public static async Task<bool> MainMenuTransition(TransitionResponse response)
{
if (string.IsNullOrEmpty(response.state)) return false;
if (response.state == "MAIN_MENU_INTRO")
{
var jsonData = JsonConvert.SerializeObject(new Dictionary<string, string>
{
{"transition", "MAIN_MENU"}
});
Console.WriteLine("Enter Main Menu...");
var postResponse = await SendPostRequestAsync("/v1/playerstate", jsonData);
if (postResponse.isSuccessStatusCode) response.state = ""; // consume state.
return true;
}
return false;
}
public static async Task<bool> ModeSelectionTransition(TransitionResponse response)
{
if (string.IsNullOrEmpty(response.state)) return false;
if (response.state == "MAIN_MENU")
{
var jsonData = JsonConvert.SerializeObject(new Dictionary<string, string>
{
{"transition", "MODE_SELECTION"}
});
Console.WriteLine("Enter Mode Selection Menu...");
var postResponse = await SendPostRequestAsync("/v1/playerstate", jsonData);
if (postResponse.isSuccessStatusCode) response.state = ""; // consume state.
return true;
}
return false;
}
public static async Task<bool> HackerSelectionTransition(TransitionResponse response)
{
if (string.IsNullOrEmpty(response.state)) return false;
if (response.state == "MODE_SELECTION")
{
var jsonData = JsonConvert.SerializeObject(new Dictionary<string, string>
{
{"transition", "HACKER_SELECTION"}
});
Console.WriteLine("Enter Hacker Selection Menu...");
var postResponse = await SendPostRequestAsync("/v1/playerstate", jsonData);
if (postResponse.isSuccessStatusCode) response.state = ""; // consume state.
return true;
}
return false;
}
public static async Task<bool> HackerSelectTransition(TransitionResponse response)
{
if (string.IsNullOrEmpty(response.state)) return false;
if (response.state == "HACKER_SELECTION")
{
var jsonData = JsonConvert.SerializeObject(new Dictionary<string, object>
{
{"transition", "HACKER_SELECT"},
{"transitionValue", 0}
});
Program.GameState = null; // reset internal state
Console.WriteLine("Select Hacker...");
var postResponse = await SendPostRequestAsync("/v1/playerstate", jsonData);
if (postResponse.isSuccessStatusCode) response.state = ""; // consume state.
return true;
}
return false;
}
public static async Task<bool> GameOverTransition(TransitionResponse response)
{
if (string.IsNullOrEmpty(response.state)) return false;
if (response.state == "GAMEOVER")
{
var jsonData = JsonConvert.SerializeObject(new Dictionary<string, object>
{
{"transition", "GAMEOVER"}
});
Console.WriteLine("Game Over...");
var postResponse = await SendPostRequestAsync("/v1/playerstate", jsonData);
if (postResponse.isSuccessStatusCode) response.state = ""; // consume state.
return true;
}
return false;
}
public static async Task<bool> GetTiles(TransitionResponse response)
{
if (string.IsNullOrEmpty(response.state)) return false;
if (response.state == "INGAME" || response.state == "TPSCREEN")
{
var getResponse = await Program._httpClient.GetAsync("/v1/tiles");
var responseContent = await getResponse.Content.ReadAsStringAsync();
if (getResponse.IsSuccessStatusCode)
{
var data = JsonConvert.DeserializeObject<TilesResponse>(responseContent);
Program.GameState.tiles = data.tiles;
}
return true;
}
return false;
}
public static async Task<bool> GetGrid(TransitionResponse response)
{
if (string.IsNullOrEmpty(response.state)) return false;
if (response.state == "INGAME" || response.state == "TPSCREEN")
{
// very expensive function -> only returns success once for every grid change. store well.
// you need this if you want to make advanced movement logic for your bots.
var getResponse = await Program._httpClient.GetAsync("/v1/grid");
var responseContent = await getResponse.Content.ReadAsStringAsync();
if (getResponse.IsSuccessStatusCode)
{
var data = JsonConvert.DeserializeObject<GridResponse>(responseContent);
Program.GameState.gridNodes = data.gridNodes;
return true;
}
}
return false;
}
public static async Task<bool> GetEntities(TransitionResponse response)
{
if (string.IsNullOrEmpty(response.state)) return false;
if (response.state == "INGAME" || response.state == "TPSCREEN")
{
var getResponse = await Program._httpClient.GetAsync("/v1/entities");
var responseContent = await getResponse.Content.ReadAsStringAsync();
if (getResponse.IsSuccessStatusCode)
{
var data = JsonConvert.DeserializeObject<EntitiesResponse>(responseContent);
Program.GameState.entities = data.entities;
}
return true;
}
return false;
}
public static async Task<bool> GetBufferTiles(TransitionResponse response)
{
if (string.IsNullOrEmpty(response.state)) return false;
if (response.state == "INGAME")
{
var getResponse = await Program._httpClient.GetAsync("/v1/buffer");
var responseContent = await getResponse.Content.ReadAsStringAsync();
if (getResponse.IsSuccessStatusCode)
{
var data = JsonConvert.DeserializeObject<BufferResponse>(responseContent);
Program.GameState.webBufferTiles = data.tiles;
// we have websites in a buffer, lets try place website from the buffer on the map.
if (Program.GameState.webBufferTiles.Count > 0)
{
var targetTile = Program.GameState.GetTileByType("MAPTILE", "EMPTY");
if (targetTile == null) return false;
Program.GameState.PerformedAction();
var jsonData = JsonConvert.SerializeObject(new Dictionary<string, object>
{
{"bufferUniqueID", Program.GameState.webBufferTiles[0].uniqueID},
// we need empty Tile, its where we want to place.
{"tileUniqueID", targetTile.uniqueID}
});
Console.WriteLine("Place Buffer Item on the Map...");
var postResponse = await SendPostRequestAsync("/v1/buffer", jsonData);
if (postResponse.isSuccessStatusCode)
{
Console.WriteLine("Buffer Item Placed on The Map...");
await Task.Delay(2000);
}
}
}
return true;
}
return false;
}
private static async Task<bool> TileAction(string tileUniqueID, int action)
{
var jsonData = JsonConvert.SerializeObject(new Dictionary<string, object>
{
{"uniqueID", tileUniqueID},
{
"action", action
} // -1: just open or close, 0-4 Button Index -> which button to press, you can send button index without opening Tile, game will open Tile for you and click button.
});
var postResponse = await SendPostRequestAsync("/v1/tileaction", jsonData);
if (postResponse.isSuccessStatusCode)
return true;
return false;
}
private static async Task<bool> FrameworkAction(string tileUniqueID, string entityUniqueID)
{
var jsonData = JsonConvert.SerializeObject(new Dictionary<string, object>
{
{"uniqueID", tileUniqueID},
{"entityUniqueID", entityUniqueID}
});
var postResponse = await SendPostRequestAsync("/v1/frameworkaction", jsonData);
if (postResponse.isSuccessStatusCode)
return true;
return false;
}
private static async Task<PostResponse> SendPostRequestAsync(string endpoint, string jsonData)
{
var request = new HttpRequestMessage(HttpMethod.Post, endpoint);
request.Content = new StringContent(jsonData, Encoding.UTF8, "application/json");
var response = await Program._httpClient.SendAsync(request).ConfigureAwait(false);
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
return new PostResponse
{responseString = responseContent, isSuccessStatusCode = response.IsSuccessStatusCode};
}
public static async Task<bool> RayCast(string uniqueID, string targetUniqueID)
{
var jsonData = JsonConvert.SerializeObject(new Dictionary<string, object>
{
{"uniqueID", uniqueID},
{"targetUniqueID", targetUniqueID}
});
var postResponse = await SendPostRequestAsync("/v1/raycast", jsonData);
if (postResponse.isSuccessStatusCode)
return true;
return false;
}
}
}