private static void ProcessAssetSTUv2(ulong guid, string typeDir) { teStructuredData structuredData = STUHelper.OpenSTUSafe(guid); if (structuredData == null) { return; } AssetRecord record = new AssetRecord { GUID = (teResourceGUID)guid, StructuredDataInfo = new Common.StructuredDataInfo(), References = new HashSet <teResourceGUID>() }; foreach (STUInstance instance in structuredData.Instances) { if (instance == null) { continue; } STUv2ProcessInstance(record, instance); } using (Stream outputFile = File.OpenWrite(Path.Combine(typeDir, $"{teResourceGUID.AsString(guid)}.json"))) { outputFile.SetLength(0); byte[] buf = JsonSerializer.PrettyPrintByteArray(JsonSerializer.Serialize(record)); outputFile.Write(buf, 0, buf.Length); } }
public ModeResult Run(string[] args) { string gameDir = args[1]; ushort type = ushort.Parse(args[2], NumberStyles.HexNumber); ClientCreateArgs createArgs = new ClientCreateArgs { SpeechLanguage = "enUS", TextLanguage = "enUS" }; TankLib.TACT.LoadHelper.PreLoad(); ClientHandler client = new ClientHandler(gameDir, createArgs); _tankHandler = (ProductHandler_Tank)client.ProductHandler; TankLib.TACT.LoadHelper.PostLoad(client); foreach (var asset in _tankHandler.Assets) { if (teResourceGUID.Type(asset.Key) != type) { continue; } string filename = teResourceGUID.AsString(asset.Key); using (Stream stream = _tankHandler.OpenFile(asset.Key)) { if (stream == null) { continue; } teStructuredData structuredData = new teStructuredData(stream); } } return(ModeResult.Success); }
public object Deserialize(teStructuredData data, STUField_Info field) { if (data.Format == teStructuredDataFormat.V2) { int offset = data.Data.ReadInt32(); if (offset == -1) { return(null); } data.DynData.BaseStream.Position = offset; Deserialize(data, data.DynData, out string value); return(new teString(value)); } if (data.Format == teStructuredDataFormat.V1) { long infoOffset = data.Data.ReadInt64(); data.Data.ReadInt64(); // haHAAA 64-bit if (infoOffset == -1 || infoOffset == 0) { return(null); } long posAfter = data.Data.Position(); data.Data.BaseStream.Position = infoOffset + data.StartPos; Deserialize(data, data.Data, out string value); data.Data.BaseStream.Position = posAfter; return(new teString(value)); } throw new NotImplementedException(); }
private static object GetSubtitle(GUIDEntry value) { using (var stu = new teStructuredData(IOHelper.OpenFile(value))) { STU_7A68A730 container = stu.GetInstance <STU_7A68A730>(); IEnumerable <string> strings = new[] { container.m_798027DE?.m_text?.Value, container.m_A84AA2B5?.m_text?.Value, container.m_D872E45C?.m_text?.Value, container.m_1485B834?.m_text?.Value }.Where(x => !string.IsNullOrEmpty(x)); return(string.Join("\n", strings)); } }
public object Deserialize(teStructuredData data, STUField_Info field) { if (data.Format == teStructuredDataFormat.V1) { return((byte)data.DynData.ReadUInt32()); } return(data.Data.ReadByte()); }
protected override void Read(BinaryReader reader) { Header = reader.Read <PlaceableDataHeader>(); if (Header.PlaceableOffset > 0) { reader.BaseStream.Position = Header.PlaceableOffset; CommonStructures = new CommonStructure[Header.PlaceableCount]; Placeables = new IMapPlaceable[Header.PlaceableCount]; for (int i = 0; i < Header.PlaceableCount; i++) { long beforePos = reader.BaseStream.Position; CommonStructure commonStructure = reader.Read <CommonStructure>(); CommonStructures[i] = commonStructure; Placeables[i] = Manager.CreateType(commonStructure, reader); reader.BaseStream.Position = beforePos + CommonStructures[i].Size; } if (CommonStructures.Length > 0 && CommonStructures[0].Type == teMAP_PLACEABLE_TYPE.ENTITY && Header.InstanceDataOffset > 0) { int execCount = 0; reader.BaseStream.Position = Header.InstanceDataOffset + 16; foreach (IMapPlaceable placeable in Placeables) { if (!(placeable is teMapPlaceableEntity entity)) { continue; } entity.InstanceData = new STUComponentInstanceData[entity.Header.InstanceDataCount]; for (int i = 0; i < entity.Header.InstanceDataCount; i++) { long beforePos = reader.BaseStream.Position; try { teStructuredData structuredData = new teStructuredData(reader); entity.InstanceData[i] = structuredData.GetInstance <STUComponentInstanceData>(); AlignPosition(beforePos, reader, structuredData); } catch (Exception) { execCount++; AlignPositionInternal(reader, beforePos + 8); // try and recover } } } if (execCount > 0) { Debugger.Log(0, "teMapChunk", $"Threw {execCount} exceptions when trying to parse entity instance data\r\n"); } } } }
public static T[] GetInstances <T>(ulong key) where T : STUInstance { if (key == 0) { return(null); } teStructuredData structuredData = OpenSTUSafe(key); return(structuredData?.GetInstances <T>().ToArray()); }
public static T GetInstance <T>(ulong key) where T : STUInstance { if (key == 0) { return(null); } using (teStructuredData structuredData = OpenSTUSafe(key)) { return(structuredData?.GetInstance <T>()); } }
public object DeserializeArray(teStructuredData data, STUField_Info field) { if (data.Format == teStructuredDataFormat.V2) { return(data.DynData.ReadUInt32()); } else { return(data.Data.ReadUInt32()); } }
public ModeResult Run(string[] args) { if (args.Length < 3) { Console.Out.WriteLine("Missing required arg: \"overwatch dir\" types..."); return(ModeResult.Fail); } string gameDir = args[1]; ushort[] types = args.Skip(2).Select(x => ushort.Parse(x, NumberStyles.HexNumber)).ToArray(); ClientCreateArgs createArgs = new ClientCreateArgs { SpeechLanguage = "enUS", TextLanguage = "enUS", Online = false }; TankLib.TACT.LoadHelper.PreLoad(); ClientHandler client = new ClientHandler(gameDir, createArgs); var handler = (ProductHandler_Tank)client.ProductHandler; TankLib.TACT.LoadHelper.PostLoad(client); foreach (var asset in handler.m_assets) { if (!types.Contains(teResourceGUID.Type(asset.Key))) { continue; } string filename = teResourceGUID.AsString(asset.Key); using (Stream stream = handler.OpenFile(asset.Key)) { try { if (stream == null) { throw new Exception(); } using (var structuredData = new teStructuredData(stream)) { var primary = structuredData.Instances.FirstOrDefault(x => x.Usage == TypeUsage.Root) ?? structuredData.Instances.FirstOrDefault(); if (primary == default) { throw new Exception(); } Logger.Info(null, $"{filename}: {primary.GetType().Name}"); } } catch { Logger.Warn(null, $"Can't find root instance for {filename}"); } } } return(ModeResult.Success); }
public void Parse(Stream input) { using (BinaryReader reader = new BinaryReader(input)) { Header = reader.Read <ModelSTUHeader>(); reader.BaseStream.Position = Header.Offset; using (SliceStream sliceStream = new SliceStream(input, Header.Offset, Header.Size)) using (var stu = new teStructuredData(sliceStream)) StructuredData = stu.GetMainInstance <STUModel>(); } }
public void OpenSTUTest(ulong guid) { if (guid == 0) { return; } using (Stream stream = OpenFile(guid)) { using (Stream file = File.OpenWrite(teResourceGUID.AsString(guid))) { stream.CopyTo(file); } stream.Position = 0; teStructuredData structuredData = new teStructuredData(stream); } }
private void Deserialize(teStructuredData data, BinaryReader reader, out string value) { int size = reader.ReadInt32(); if (size != 0) { uint checksum = reader.ReadUInt32(); long offset = reader.ReadInt64(); reader.BaseStream.Position = offset + data.StartPos; value = reader.ReadString(size); } else { value = string.Empty; } }
public void Extract0EE(ICLIFlags toolFlags) { string basePath; if (toolFlags is ExtractFlags flags) { basePath = flags.OutputPath; } else { throw new Exception("no output path"); } const string container = "Debug0EE"; string path = Path.Combine(basePath, container); foreach (ulong key in TrackedFiles[0xEE]) { using (Stream stream = OpenFile(key)) { teStructuredData structuredData = new teStructuredData(stream); STU_E3594B8E inst = structuredData.GetMainInstance <STU_E3594B8E>(); if (inst == null) { continue; //inst = structuredData.GetMainInstance<STU_598579A3>(); } string name = $"{GetString(inst.m_name)}_{teResourceGUID.Index(key):X}"; string description = GetString(inst.m_description); Combo.ComboInfo info = new Combo.ComboInfo(); Combo.Find(info, (ulong)inst.m_21EB3E73); info.SetTextureName((ulong)inst.m_21EB3E73, name); OpenSTUTest(inst.m_7B7CCF55); // ux1 OpenSTUTest(inst.m_E81C5302); // ux2 OpenSTUTest(inst.m_FD9B53F4); // ux3 //{ // teStructuredData uxScreenData = new teStructuredData(); //} SaveLogic.Combo.SaveLooseTextures(flags, path, info); } } }
public object DeserializeArray(teStructuredData data, STUField_Info field) { BinaryReader dynData = data.DynData; long offset = dynData.ReadInt64(); Enums.SDAM mutability = (Enums.SDAM)dynData.ReadInt64(); // SDAM_NONE = 0, SDAM_MUTABLE = 1, SDAM_IMMUTABLE = 2 // Debug.Assert(Mutability == teEnums.SDAM.IMMUTABLE, "teString.unk != 2 (not immutable)"); long pos = dynData.BaseStream.Position; dynData.Seek(offset); Deserialize(data, dynData, out string value); dynData.Seek(pos); return(new teString(value, mutability)); }
public static void TestSTU() { var sw = new Stopwatch(); const int iterateCount = 100000; using (Stream stuStream = OpenFile(0x980000000005632)) { // 000000005632.01A { // generate static fields teStructuredData structuredData = new teStructuredData(stuStream, true); stuStream.Position = 0; } sw.Restart(); for (int i = 0; i < iterateCount; i++) { teStructuredData structuredData = new teStructuredData(stuStream, true); stuStream.Position = 0; } sw.Stop(); Console.WriteLine($"Took {sw.Elapsed}ms to deserialize the file using TankLib.STU.teStructuredData! ({iterateCount}x)"); //sw.Restart(); //for (int i = 0; i < iterateCount; i++) { // ISTU structuredData = ISTU.NewInstance(stuStream, uint.MaxValue); // stuStream.Position = 0; //} //sw.Stop(); //Console.WriteLine($"Took {sw.Elapsed}ms to deserialize the file using STULib.V2! ({iterateCount}x)"); //STUModelLook look = structuredData.GetMainInstance<STUModelLook>(); //foreach (STUModelMaterial lookMaterial in look.Materials) { // ulong guid = lookMaterial.Material; //} } Console.Out.Write("done"); Console.ReadLine(); }
public ModeResult Run(string[] args) { foreach (var arg in args.Skip(1)) { try { using (Stream stream = File.OpenRead(arg)) { teStructuredData structuredData = new teStructuredData(stream); var primary = structuredData.Instances.FirstOrDefault(x => x.Usage == TypeUsage.Root) ?? structuredData.Instances.FirstOrDefault(); if (primary == default) { throw new Exception(); } Logger.Info(null, $"{Path.GetFileName(arg)}: {primary.GetType().Name}"); } } catch { Logger.Warn(null, $"Can't find root instance for {arg}"); } } return(ModeResult.Success); }
public ModeResult Run(string[] args) { string gameDir = args[1]; ushort type = ushort.Parse(args[2], NumberStyles.HexNumber); CASCConfig config = CASCConfig.LoadLocalStorageConfig(gameDir, true, false); CASC = CASCHandler.Open(config); MapCMF("enUS"); // heck foreach (ulong file in Types[type]) { string filename = teResourceGUID.AsString(file); using (Stream stream = OpenFile(file)) { if (stream == null) { continue; } teStructuredData structuredData = new teStructuredData(stream); } } return(ModeResult.Success); }
public object Deserialize(teStructuredData data, STUField_Info field) { return(data.Data.ReadSingle()); }
public object DeserializeArray(teStructuredData data, STUField_Info field) { return(data.DynData.ReadUInt64()); }
public void Deserialize(teStructuredData data, STUField_Info field) { Value = data.Data.ReadBytes(16); }
private void AlignPosition(long start, BinaryReader reader, teStructuredData stu) { long maxOffset = stu.InstanceInfoV1.Max(x => x.Offset) + start; AlignPositionInternal(reader, maxOffset + 8); }
public static T GetInstance <T>(ulong key) where T : STUInstance { teStructuredData structuredData = OpenSTUSafe(key); return(structuredData?.GetInstance <T>()); }
public object Deserialize(teStructuredData data, STUField_Info field) { return data.Data.ReadInt32(); }
public static void TryConvertFile(Stream stream, string convertDir, string md5) { using (BinaryReader reader = new BinaryReader(stream, Encoding.UTF8, true)) { uint magic = reader.ReadUInt32(); stream.Position = 0; if (magic == teChunkedData.Magic) { teChunkedData chunkedData = new teChunkedData(reader); if (chunkedData.Header.StringIdentifier == "MODL") { OverwatchModel model = new OverwatchModel(chunkedData, 0); using (Stream file = File.OpenWrite(Path.Combine(convertDir, md5) + ".owmdl")) { file.SetLength(0); model.Write(file); } } } else if (magic == 0x4D4F5649) // MOVI { stream.Position = 128; using (Stream file = File.OpenWrite(Path.Combine(convertDir, md5) + ".bk2")) { file.SetLength(0); stream.CopyTo(file); } } else { // ok might be a heckin bundle /*int i = 0; * while (reader.BaseStream.Position < reader.BaseStream.Length) { * try { * magic = reader.ReadUInt32(); * if (magic != teChunkedData.Magic) { * reader.BaseStream.Position -= 3; * continue; * } * reader.BaseStream.Position -= 4; * teChunkedData chunkedData = new teChunkedData(reader); * if (chunkedData.Header.StringIdentifier == "MODL") { * OverwatchModel model = new OverwatchModel(chunkedData, 0); * using (Stream file = File.OpenWrite(Path.Combine(convertDir, md5) + $"-{i}.owmdl")) { * file.SetLength(0); * model.Write(file); * } * } * * i++; * } catch (Exception) { * // fine * } * }*/ try { //teStructuredData structuredData =new teStructuredData(stream, true); teTexture texture = new teTexture(reader); if (!texture.PayloadRequired && texture.Header.DataSize <= stream.Length && (texture.Header.Flags == teTexture.Flags.Tex1D || texture.Header.Flags == teTexture.Flags.Tex2D || texture.Header.Flags == teTexture.Flags.Tex3D || texture.Header.Flags == teTexture.Flags.Cube || texture.Header.Flags == teTexture.Flags.Array || texture.Header.Flags == teTexture.Flags.Unk16 || texture.Header.Flags == teTexture.Flags.Unk32 || texture.Header.Flags == teTexture.Flags.Unk128) && texture.Header.Height < 10000 && texture.Header.Width < 10000 && texture.Header.DataSize > 68) { using (Stream file = File.OpenWrite(Path.Combine(convertDir, md5) + ".dds")) { file.SetLength(0); texture.SaveToDDS(file, false, texture.Header.MipCount); } } } catch (Exception) { // fine } try { stream.Position = 0; teStructuredData structuredData = new teStructuredData(stream, true); if (structuredData.GetInstance <STUResourceKey>() != null) { var key = structuredData.GetInstance <STUResourceKey>(); Console.Out.WriteLine("found key"); var longKey = ulong.Parse(key.m_keyID, NumberStyles.HexNumber); var longRevKey = BitConverter.ToUInt64(BitConverter.GetBytes(longKey).Reverse().ToArray(), 0); var keyValueString = BitConverter.ToString(key.m_key).Replace("-", string.Empty); var keyNameProper = longRevKey.ToString("X16"); Console.Out.WriteLine("Added Encryption Key {0}, Value: {1}", keyNameProper, keyValueString); } // if (structuredData.GetInstance<STUHero>() != null) { // // } } catch (Exception) { // fine } } } }