Rebuild bot download

This commit is contained in:
Norbi Peti 2025-01-13 01:31:35 +01:00
parent 81c0130792
commit c914bc1cb8

View file

@ -10,9 +10,7 @@ using RC2BotArchiver;
Console.WriteLine("Hello, World!"); Console.WriteLine("Hello, World!");
FixCRF2Archive.FixIt(); var client = new HttpClient();
/*var client = new HttpClient();
async Task<JsonElement?> GetResponse(HttpResponseMessage result, string url) async Task<JsonElement?> GetResponse(HttpResponseMessage result, string url)
{ {
@ -68,38 +66,41 @@ var jwt = responseJson.Value.GetProperty("Token");
payload = new ExpandoObject(); payload = new ExpandoObject();
payload.Token = responseJson.Value.GetProperty("Token"); payload.Token = responseJson.Value.GetProperty("Token");
payload.ClientVersion = "100.0"; payload.ClientVersion = "100.0";
responseJson = await Post("https://progression.development.robocraft.org/login/fj", payload); responseJson = await Post("https://services-test-robocraft2.robocraft.org/login", payload);
var progressToken = responseJson.Value.GetProperty("token").GetString(); var progressToken = responseJson.Value.GetProperty("token").GetString();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", progressToken); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", progressToken);
const string factoryUrl = "https://factory.development.robocraft.org"; const string factoryUrl = "https://services-test-robocraft2.robocraft.org";
int page = 57;
while (true) while (true)
{ {
try try
{ {
Console.WriteLine($"Getting page {page}"); Console.WriteLine($"Getting bots...");
responseJson = await Get(factoryUrl + $"/v1/foundry/search?page={page}&count=10"); responseJson = await Get(factoryUrl + $"/garage");
if (!responseJson.HasValue) throw new Exception("Failed to get robots!"); if (!responseJson.HasValue) throw new Exception("Failed to get robots!");
var results = responseJson.Value.GetProperty("results"); var garage = responseJson.Value.GetProperty("garage");
if (results.GetArrayLength() == 0) break; var bays = garage.GetProperty("bays");
foreach (var result in results.EnumerateArray()) if (bays.GetArrayLength() == 0) break;
foreach (var robot in bays.EnumerateArray())
{ {
var robot = result.GetProperty("robot");
var dirPath = Path.Combine("robots", robot.GetProperty("id").GetString()!); var dirPath = Path.Combine("robots", robot.GetProperty("id").GetString()!);
Directory.CreateDirectory(dirPath); Directory.CreateDirectory(dirPath);
File.WriteAllText(Path.Combine(dirPath, "metadata.json"), robot.GetRawText()); File.WriteAllText(Path.Combine(dirPath, "metadata.json"), robot.GetRawText());
responseJson = await Get(factoryUrl + "/v1/foundry/vehicles/" + robot.GetProperty("id")); responseJson = await Get(factoryUrl + "/garage/" + robot.GetProperty("id") + "/blockData");
if (!responseJson.HasValue) throw new Exception($"Could not get bot {robot.GetProperty("name")}"); if (!responseJson.HasValue) throw new Exception($"Could not get bot {robot.GetProperty("name")}");
File.WriteAllText(Path.Combine(dirPath, "robotData.json"), responseJson.Value.GetRawText()); var robotBase64 = responseJson.Value.GetProperty("robotBlockData").GetString()!;
Console.WriteLine($"Saved {robot.GetProperty("name")} by {robot.GetProperty("creatorName")}"); File.WriteAllBytes(Path.Combine(dirPath, "robot.rc2"), Convert.FromBase64String(robotBase64));
responseJson = await Get(factoryUrl + "/garage/" + robot.GetProperty("id") + "/imageData");
if (!responseJson.HasValue) throw new Exception($"Could not get bot {robot.GetProperty("name")} image");
var imageBase64 = responseJson.Value.GetProperty("robotImageData").GetString()!;
File.WriteAllBytes(Path.Combine(dirPath, "image.png"), Convert.FromBase64String(imageBase64));
Console.WriteLine($"Saved {robot.GetProperty("name")}");
Thread.Sleep(100); Thread.Sleep(100);
} }
Thread.Sleep(1000); break;
page++;
} }
catch (Exception e) catch (Exception e)
{ {
@ -109,7 +110,3 @@ while (true)
Thread.Sleep(100000); Thread.Sleep(100000);
} }
} }
await DownloadImages.DoIt(client);*/
// TODO: Chart of amount of bots on CRF by date & amount of starter bots