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)); } }
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 GetInstance <T>(ulong key) where T : STUInstance { if (key == 0) { return(null); } teStructuredData structuredData = OpenSTUSafe(key); return(structuredData?.GetInstance <T>()); }
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 } } } }