// dawn of a new project // STUExcavator: // go through all stu files and find GUIDs // future possibilities: // STUv1 excavation: // find padding, then try for guid public static void Main(string[] args) { string overwatchDir = args[0]; string outputDir = args[1]; const string language = "enUS"; // usage: "STUExcavator overwatch_dir output_dir [dataset_dir]" string datasetFolder = ""; if (args.Length >= 3) { datasetFolder = args[2]; } // casc setup Config = CASCConfig.LoadLocalStorageConfig(overwatchDir, false, false); Config.Languages = new HashSet <string> { language }; CASC = CASCHandler.OpenStorage(Config); DataTool.Program.Files = new Dictionary <ulong, PackageRecord>(); DataTool.Program.TrackedFiles = new Dictionary <ushort, HashSet <ulong> >(); DataTool.Program.CASC = CASC; DataTool.Program.Root = CASC.Root as OwRootHandler; DataTool.Program.Flags = new ToolFlags { OverwatchDirectory = outputDir, Language = language }; IO.MapCMF(true); Files = DataTool.Program.Files; TrackedFiles = DataTool.Program.TrackedFiles; // prepare Version2Comparer Version2Comparer.InstanceJSON = STUHashTool.Program.LoadInstanceJson(Path.Combine(datasetFolder, "RegisteredSTUTypes.json")); InvalidTypes = STUHashTool.Program.LoadInvalidTypes(Path.Combine(datasetFolder, "IgnoredBrokenSTUs.txt")); //STUHashTool.Program.LoadHashCSV(Path.Combine(datasetFolder, "KnownFields.csv"), out FieldNames); //STUHashTool.Program.LoadHashCSV(Path.Combine(datasetFolder, "KnownEnums.csv"), out EnumNames); //STUHashTool.Program.LoadHashCSV(Path.Combine(datasetFolder, "KnownTypes.csv"), out InstanceNames); FieldNames = new Dictionary <uint, string>(); EnumNames = new Dictionary <uint, string>(); InstanceNames = new Dictionary <uint, string>(); JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Converters = new List <JsonConverter> { new GUIDArrayConverter(), new GUIDConverter() }, PreserveReferencesHandling = PreserveReferencesHandling.All }; // wipe ISTU ISTU.Clear(); // actual tool Dictionary <string, AssetTypeSummary> types = new Dictionary <string, AssetTypeSummary>(); CompileSTUs(); foreach (KeyValuePair <ushort, HashSet <ulong> > keyValuePair in TrackedFiles.OrderBy(x => x.Key)) { string type = keyValuePair.Key.ToString("X3"); if (type == "09C" || type == "062" || type == "077") { continue; } Log($"Processing type: {type}"); types[type] = Excavate(keyValuePair.Key, keyValuePair.Value); IO.CreateDirectoryFromFile(Path.Combine(outputDir, type, "master.json")); using (Stream masterFile = File.OpenWrite(Path.Combine(outputDir, type, "master.json"))) { masterFile.SetLength(0); string masterJson = JsonConvert.SerializeObject(types[type], Formatting.Indented); using (TextWriter writer = new StreamWriter(masterFile)) { writer.WriteLine(masterJson); } } if (types[type].Assets == null) { continue; } foreach (Asset asset in types[type].Assets) { string assetFile = Path.Combine(outputDir, type, "assets", $"{asset.GUID}.json"); string assetFileJson = Path.Combine(outputDir, type, "jsondump", $"{asset.GUID}.json"); IO.CreateDirectoryFromFile(assetFile); IO.CreateDirectoryFromFile(assetFileJson); using (Stream assetStream = File.OpenWrite(assetFile)) { assetStream.SetLength(0); string assetJson = JsonConvert.SerializeObject(asset, Formatting.Indented); using (TextWriter writer = new StreamWriter(assetStream)) { writer.WriteLine(assetJson); } } if (asset.JSONDump == null) { continue; } using (Stream assetStream = File.OpenWrite(assetFileJson)) { assetStream.SetLength(0); using (TextWriter writer = new StreamWriter(assetStream)) { writer.WriteLine(asset.JSONDump); } } } } }
// dawn of a new project // STUExcavator: // go through all stu files and find GUIDs // future possibilities: // STUv1 excavation: // find padding, then try for guid public static void Main(string[] args) { string overwatchDir = args[0]; string outputDir = args[1]; const string language = "enUS"; // casc setup Config = CASCConfig.LoadLocalStorageConfig(overwatchDir, false, false); Config.Languages = new HashSet <string> { language }; CASC = CASCHandler.OpenStorage(Config); DataTool.Program.Files = new Dictionary <ulong, MD5Hash>(); DataTool.Program.TrackedFiles = new Dictionary <ushort, HashSet <ulong> >(); DataTool.Program.CASC = CASC; DataTool.Program.Root = CASC.Root as OwRootHandler; DataTool.Program.Flags = new ToolFlags { OverwatchDirectory = outputDir, Language = language }; IO.MapCMF(true); Files = DataTool.Program.Files; TrackedFiles = DataTool.Program.TrackedFiles; // prepare Version2Comparer Version2Comparer.InstanceJSON = STUHashTool.Program.LoadInstanceJson("RegisteredSTUTypes.json"); InvalidTypes = STUHashTool.Program.LoadInvalidTypes("IgnoredBrokenSTUs.txt"); // wipe ISTU ISTU.Clear(); // actual tool Dictionary <string, AssetTypeSummary> types = new Dictionary <string, AssetTypeSummary>(); CompileSTUs(); foreach (KeyValuePair <ushort, HashSet <ulong> > keyValuePair in TrackedFiles.OrderBy(x => x.Key)) { string type = keyValuePair.Key.ToString("X3"); if (type == "09C" || type == "062" || type == "077") { continue; } Log($"Processing type: {type}"); types[type] = Excavate(keyValuePair.Key, keyValuePair.Value); IO.CreateDirectoryFromFile(Path.Combine(outputDir, type, "master.json")); using (Stream masterFile = File.OpenWrite(Path.Combine(outputDir, type, "master.json"))) { masterFile.SetLength(0); string masterJson = JsonConvert.SerializeObject(types[type], Formatting.Indented); using (TextWriter writer = new StreamWriter(masterFile)) { writer.WriteLine(masterJson); } } if (types[type].Assets == null) { continue; } foreach (Asset asset in types[type].Assets) { string assetFile = Path.Combine(outputDir, type, "assets", $"{asset.GUID}.json"); IO.CreateDirectoryFromFile(assetFile); using (Stream assetStream = File.OpenWrite(assetFile)) { assetStream.SetLength(0); string assetJson = JsonConvert.SerializeObject(asset, Formatting.Indented); using (TextWriter writer = new StreamWriter(assetStream)) { writer.WriteLine(assetJson); } } } } }