mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 11:17:05 +02:00
feat: more shit
This commit is contained in:
1 parent
920ef6e5c4
commit
8b0f95c53d
7 files changed
+129
-174
No files matched your search
@@ -1,112 +1,52 @@
|
||||
using Blitzkit;
|
||||
using BlitzKit.CLI.Models;
|
||||
using BlitzKit.CLI.Utils;
|
||||
using CUE4Parse.FileProvider.Objects;
|
||||
using Google.Protobuf.Collections;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace BlitzKit.CLI.Functions
|
||||
{
|
||||
public static class Mangler
|
||||
public class Mangler
|
||||
{
|
||||
public static void Mangle()
|
||||
{
|
||||
Tanks tanks = new();
|
||||
BlitzProvider provider = new();
|
||||
readonly Tanks tanks = new();
|
||||
readonly BlitzProvider provider = new();
|
||||
|
||||
foreach (
|
||||
var nationDir in provider.RootDirectory.GetDirectory("Blitz/Content/Tanks").Directories
|
||||
)
|
||||
public void Mangle()
|
||||
{
|
||||
var nationDirs = provider.RootDirectory.GetDirectory("Blitz/Content/Tanks").Directories;
|
||||
|
||||
foreach (var nationDir in nationDirs)
|
||||
{
|
||||
if (nationDir.Key == "TankStub")
|
||||
continue;
|
||||
|
||||
foreach (var tankDir in nationDir.Value.Directories)
|
||||
{
|
||||
var id = tankDir.Key;
|
||||
|
||||
if (id != "R90_IS_4")
|
||||
continue;
|
||||
|
||||
var attributeFileName = $"DA_{id}_Attributes.uasset";
|
||||
var hasAttributesFile = tankDir.Value.HasFile(attributeFileName);
|
||||
GameFile? attributesFile = null;
|
||||
|
||||
if (hasAttributesFile)
|
||||
{
|
||||
attributesFile = tankDir.Value.GetFile(attributeFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
PrettyLog.Warn(
|
||||
$"No attributes file found for {nationDir.Key}/{id}, it may be misspelled; finding any attributes file..."
|
||||
);
|
||||
|
||||
foreach (var file in tankDir.Value.Files)
|
||||
{
|
||||
if (file.Key.EndsWith("_Attributes.uasset"))
|
||||
{
|
||||
attributesFile = file.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (attributesFile == null)
|
||||
{
|
||||
PrettyLog.Error(
|
||||
$"No suffixed attributes file found for {nationDir.Key}/{id}; skipping..."
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
var exports = provider.LoadAllObjects(attributesFile.Path);
|
||||
|
||||
var tankAttributesDataAsset =
|
||||
exports.First((export) => export.ExportType == "TankAttributesDataAsset")
|
||||
?? throw new Exception("TankAttributesDataAsset not found");
|
||||
var attr = JObject.FromObject(tankAttributesDataAsset);
|
||||
|
||||
if (attr["Properties"] is not JObject props || props["MaxHealth"] == null)
|
||||
{
|
||||
PrettyLog.Warn($"{nationDir.Key}/{id} has not migrated to Reforged; skipping...");
|
||||
continue;
|
||||
}
|
||||
|
||||
var tank = MangleTank(id, props);
|
||||
|
||||
tanks.Tanks_.Add(tank.Id);
|
||||
|
||||
Console.WriteLine($"Mangled {nationDir.Key}/{id}");
|
||||
}
|
||||
MangleNation(nationDir.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Tank MangleTank(string id, JObject props)
|
||||
void MangleNation(VfsDirectory nation)
|
||||
{
|
||||
Tank tank = new()
|
||||
foreach (var tankDir in nation.Directories)
|
||||
{
|
||||
Id = id,
|
||||
// TODO: Name
|
||||
// TODO: Set
|
||||
// TODO: Class
|
||||
// TODO: Faction
|
||||
if (tankDir.Value.Name != "R90_IS_4")
|
||||
continue;
|
||||
|
||||
TurretRotatorHealth = MangleModuleHealth((props["TurretRotatorHealth"] as JObject)!),
|
||||
SurveyingDeviceHealth = MangleModuleHealth((props["SurveyingDeviceHealth"] as JObject)!),
|
||||
GunHealth = MangleModuleHealth((props["GunHealth"] as JObject)!),
|
||||
ChassisHealth = MangleModuleHealth((props["ChassisHealth"] as JObject)!),
|
||||
AmmoBayHealth = MangleModuleHealth((props["AmmoBayHealth"] as JObject)!),
|
||||
EngineHealth = MangleModuleHealth((props["EngineHealth"] as JObject)!),
|
||||
FuelTankHealth = MangleModuleHealth((props["FuelTankHealth"] as JObject)!),
|
||||
};
|
||||
var tank = MangleTank(tankDir.Value);
|
||||
|
||||
MangleCrewHealth(tank.CrewHealth, (props["CrewHealth"] as JArray)!);
|
||||
|
||||
return tank;
|
||||
tanks.Tanks_.Add(tank.Id);
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string, CrewType> CrewTypes = new()
|
||||
Tank MangleTank(VfsDirectory tankDir)
|
||||
{
|
||||
var pdaName = $"PDA_{tankDir.Name}";
|
||||
var pda = tankDir.GetUasset($"{pdaName}.uasset").Get(pdaName);
|
||||
|
||||
Console.WriteLine(pda);
|
||||
|
||||
return new();
|
||||
}
|
||||
|
||||
Dictionary<string, CrewType> CrewTypes = new()
|
||||
{
|
||||
{ "EModuleOrTankmen::Commander", CrewType.Commander },
|
||||
{ "EModuleOrTankmen::Driver", CrewType.Driver },
|
||||
@@ -116,7 +56,7 @@ namespace BlitzKit.CLI.Functions
|
||||
{ "EModuleOrTankmen::Loader2", CrewType.Loader2 },
|
||||
};
|
||||
|
||||
public static void MangleCrewHealth(RepeatedField<CrewHealth> map, JArray array)
|
||||
void MangleCrewHealth(RepeatedField<CrewHealth> map, JArray array)
|
||||
{
|
||||
foreach (var member in array.Cast<JObject>())
|
||||
{
|
||||
@@ -138,7 +78,7 @@ namespace BlitzKit.CLI.Functions
|
||||
}
|
||||
}
|
||||
|
||||
public static ModuleHealth MangleModuleHealth(JObject obj)
|
||||
ModuleHealth MangleModuleHealth(JObject obj)
|
||||
{
|
||||
ModuleHealth moduleHealth = new()
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace BlitzKit.CLI.Models
|
||||
private static readonly string LOCAL_MAPPINGS_PATH =
|
||||
"../../submodules/blitzkit-closed/blitz.usmap";
|
||||
|
||||
public readonly VfsDirectory RootDirectory = new();
|
||||
public readonly VfsDirectory RootDirectory;
|
||||
|
||||
public BlitzProvider()
|
||||
: base(
|
||||
@@ -25,6 +25,7 @@ namespace BlitzKit.CLI.Models
|
||||
versions: new(EGame.GAME_UE5_3)
|
||||
)
|
||||
{
|
||||
RootDirectory = new() { Name = "", provider = this };
|
||||
MappingsContainer = new FileUsmapTypeMappingsProvider(LOCAL_MAPPINGS_PATH);
|
||||
|
||||
Initialize();
|
||||
@@ -51,7 +52,7 @@ namespace BlitzKit.CLI.Models
|
||||
}
|
||||
else
|
||||
{
|
||||
VfsDirectory newDirectory = new();
|
||||
VfsDirectory newDirectory = new() { Name = segment, provider = this };
|
||||
directory.AddDirectory(segment, newDirectory);
|
||||
directory = newDirectory;
|
||||
}
|
||||
@@ -59,42 +60,4 @@ namespace BlitzKit.CLI.Models
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class VfsDirectory
|
||||
{
|
||||
public Dictionary<string, VfsDirectory> Directories = [];
|
||||
public Dictionary<string, GameFile> Files = [];
|
||||
|
||||
public void AddFile(string name, GameFile file) => Files.TryAdd(name, file);
|
||||
|
||||
public bool HasFile(string name) => Files.ContainsKey(name);
|
||||
|
||||
public GameFile GetFile(string name)
|
||||
{
|
||||
var directoryPath = Path.GetDirectoryName(name);
|
||||
var fileName = Path.GetFileName(name);
|
||||
var directory =
|
||||
directoryPath == null || directoryPath.Length == 0 ? this : GetDirectory(directoryPath);
|
||||
|
||||
return directory.Files[fileName];
|
||||
}
|
||||
|
||||
public bool HasDirectory(string name) => Directories.ContainsKey(name);
|
||||
|
||||
public VfsDirectory GetDirectory(string name)
|
||||
{
|
||||
var segments = name.Split('/');
|
||||
var directory = this;
|
||||
|
||||
foreach (var segment in segments)
|
||||
{
|
||||
directory = directory.Directories[segment];
|
||||
}
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
public void AddDirectory(string name, VfsDirectory directory) =>
|
||||
Directories.Add(name, directory);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using CUE4Parse.FileProvider;
|
||||
using CUE4Parse.FileProvider.Objects;
|
||||
using CUE4Parse.UE4.Assets.Exports;
|
||||
|
||||
namespace BlitzKit.CLI.Models
|
||||
{
|
||||
public class Uasset
|
||||
{
|
||||
readonly GameFile file;
|
||||
readonly Dictionary<string, UObject> objects = [];
|
||||
|
||||
public Uasset(GameFile file, AbstractFileProvider provider)
|
||||
{
|
||||
this.file = file;
|
||||
var objects = provider.LoadAllObjects(file.Path);
|
||||
|
||||
foreach (var obj in objects)
|
||||
{
|
||||
this.objects.Add(obj.Name, obj);
|
||||
}
|
||||
}
|
||||
|
||||
public UObject Get(string name) => objects[name];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using CUE4Parse.FileProvider;
|
||||
using CUE4Parse.FileProvider.Objects;
|
||||
|
||||
namespace BlitzKit.CLI.Models
|
||||
{
|
||||
public class VfsDirectory
|
||||
{
|
||||
public Dictionary<string, VfsDirectory> Directories = [];
|
||||
public Dictionary<string, GameFile> Files = [];
|
||||
public required string Name;
|
||||
public required AbstractFileProvider provider;
|
||||
|
||||
public void AddFile(string name, GameFile file) => Files.TryAdd(name, file);
|
||||
|
||||
public bool HasFile(string name) => Files.ContainsKey(name);
|
||||
|
||||
public Uasset GetUasset(string name) => new(GetFile(name), provider);
|
||||
|
||||
public GameFile GetFile(string name)
|
||||
{
|
||||
var directoryPath = Path.GetDirectoryName(name);
|
||||
var fileName = Path.GetFileName(name);
|
||||
var directory =
|
||||
directoryPath == null || directoryPath.Length == 0 ? this : GetDirectory(directoryPath);
|
||||
|
||||
return directory.Files[fileName];
|
||||
}
|
||||
|
||||
public bool HasDirectory(string name) => Directories.ContainsKey(name);
|
||||
|
||||
public VfsDirectory GetDirectory(string name)
|
||||
{
|
||||
var segments = name.Split('/');
|
||||
var directory = this;
|
||||
|
||||
foreach (var segment in segments)
|
||||
{
|
||||
directory = directory.Directories[segment];
|
||||
}
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
public void AddDirectory(string name, VfsDirectory directory) =>
|
||||
Directories.Add(name, directory);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,10 @@ namespace BlitzKit.CLI
|
||||
|
||||
case "mangle":
|
||||
{
|
||||
Mangler.Mangle();
|
||||
Mangler mangler = new();
|
||||
|
||||
mangler.Mangle();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user