public static byte[] ConvertDDS(GUIDEntry value, DXGI_FORMAT targetFormat, DDSConverter.ImageFormat imageFormat, int frame) { try { if (GetDataType(value) != DataType.Image) { return(null); } teTexture texture = new teTexture(IOHelper.OpenFile(value)); if (texture.PayloadRequired) { ulong payload = texture.GetPayloadGUID(value.GUID, 1); if (IOHelper.HasFile(payload)) { texture.LoadPayload(IOHelper.OpenFile(payload), 1); } else { return(null); } } Stream ms = texture.SaveToDDS(1); return(DDSConverter.ConvertDDS(ms, targetFormat, imageFormat, frame)); } catch { // ignored } return(null); }
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)); } }
internal static object ConvertSound(GUIDEntry value) { MemoryStream ms = new MemoryStream(); DataTool.SaveLogic.Combo.ConvertSoundFile(IOHelper.OpenFile(value), ms); ms.Position = 0; return(ms); }
internal static Conversation GetConversation(GUIDEntry value) { if (value == null || value.GUID == 0) { return(null); } return(new Conversation(value)); }
internal static MapHeader GetMap(GUIDEntry value) { if (value == null || value.GUID == 0) { return(null); } return(new MapHeader(value.GUID)); }
internal static Hero GetHero(GUIDEntry value) { if (value == null || value.GUID == 0) { return(null); } return(new Hero(value.GUID)); }
public static DataType GetDataType(GUIDEntry value) { if (value == null || value.GUID == 0) { return(DataType.Unknown); } ushort type = teResourceGUID.Type(value.GUID); return(GetDataType(type)); }
public static void SaveImage(GUIDEntry value, Stream fileStream, Stream outStream) { if (GetDataType(value) != DataType.Image) { return; } teTexture texture = LoadTexture(value, fileStream); texture.SaveToDDS(outStream, false, 1); }
public PreviewConversation(GUIDEntry guidEntry, Conversation conversation, Lazy <Dictionary <ulong, ulong[]> > conversationVoiceLineMapping) { GUIDEntry = guidEntry; VoiceLines = conversation.Voicelines .Select(voiceline => new TankViewConversationLine(voiceline, conversationVoiceLineMapping.Value[voiceline.VoicelineGUID])) .OrderBy(x => x.Position) .ToArray(); InitializeComponent(); }
public static Stream OpenFile(GUIDEntry entry) { if (entry.Flags.HasFlag(ContentFlags.Bundle)) { return(OpenFile(entry.Hash, entry.Offset, (int)entry.Size)); } else { return(OpenFile(entry.Hash)); } }
internal static object GetString(GUIDEntry value) { if (teResourceGUID.Type(value.GUID) == 0x071) { return(GetSubtitle(value)); } try { teString str = new teString(IOHelper.OpenFile(value)); return(str.Value); } catch { return(string.Empty); } }
internal static object ConvertSound(GUIDEntry value) { MemoryStream ms = new MemoryStream(); try { DataTool.SaveLogic.Combo.ConvertSoundFile(IOHelper.OpenFile(value), ms); } catch (Exception ex) { Debugger.Log(0, "[TankView.DataHelper.ConvertSound]", $"Error converting sound! {ex.Message}\n"); // ignored } ms.Position = 0; return(ms); }
public static byte[] ConvertDDS(GUIDEntry value, DXGI_FORMAT targetFormat, DDSConverter.ImageFormat imageFormat, int frame) { try { if (GetDataType(value) != DataType.Image) { return(null); } teTexture texture = LoadTexture(value); Stream ms = texture.SaveToDDS(1); return(DDSConverter.ConvertDDS(ms, targetFormat, imageFormat, frame)); } catch { // ignored } return(null); }
internal static teTexture LoadTexture(GUIDEntry value, Stream fileStream = null) { teTexture texture = new teTexture(fileStream ?? IOHelper.OpenFile(value)); if (texture.PayloadRequired) { ulong payload = texture.GetPayloadGUID(value.GUID, 0); if (IOHelper.HasFile(payload)) { texture.LoadPayload(IOHelper.OpenFile(payload), 0); } else { return(null); } } return(texture); }
public static Stream OpenFile(GUIDEntry entry) { return(entry.GUID != 0 ? DataTool.Program.TankHandler.OpenFile(entry.GUID) : DataTool.Program.Client.OpenCKey(entry.ContentKey)); }
private static object GetSubtitle(GUIDEntry value) { var subtitle = new teSubtitleThing(IOHelper.OpenFile(value)); return(string.Join("\n", subtitle.m_strings)); }
public static byte[] ConvertDDS(GUIDEntry value, DXGI_FORMAT targetFormat, ImageFormat imageFormat, int frame) { try { if (GetDataType(value) != DataType.Image) { return(null); } teTexture texture = new teTexture(IOHelper.OpenFile(value)); if (texture.PayloadRequired) { ulong payload = texture.GetPayloadGUID(value.GUID); if (value.APM.FirstOccurence.ContainsKey(payload)) { texture.LoadPayload(IOHelper.OpenFile(value.APM.FirstOccurence[payload])); } else { return(null); } } Stream ms = texture.SaveToDDS(); CoInitializeEx(IntPtr.Zero, CoInit.MultiThreaded | CoInit.SpeedOverMemory); byte[] data = new byte[ms.Length]; ms.Read(data, 0, data.Length); ScratchImage scratch = null; try { unsafe { fixed(byte *dataPin = data) { scratch = TexHelper.Instance.LoadFromDDSMemory((IntPtr)dataPin, data.Length, DDS_FLAGS.NONE); TexMetadata info = scratch.GetMetadata(); if (TexHelper.Instance.IsCompressed(info.Format)) { ScratchImage temp = scratch.Decompress(frame, DXGI_FORMAT.UNKNOWN); scratch.Dispose(); scratch = temp; } info = scratch.GetMetadata(); if (info.Format != targetFormat) { ScratchImage temp = scratch.Convert(targetFormat, TEX_FILTER_FLAGS.DEFAULT, 0.5f); scratch.Dispose(); scratch = temp; } UnmanagedMemoryStream stream = null; if (imageFormat == ImageFormat.TGA) { stream = scratch.SaveToTGAMemory(frame < 0 ? 0 : frame); } else { WICCodecs codec = WICCodecs.PNG; bool isMultiframe = false; switch (imageFormat) { case ImageFormat.BMP: codec = WICCodecs.BMP; break; case ImageFormat.GIF: codec = WICCodecs.GIF; isMultiframe = true; break; case ImageFormat.JPEG: codec = WICCodecs.JPEG; break; case ImageFormat.PNG: codec = WICCodecs.PNG; break; case ImageFormat.TIF: codec = WICCodecs.TIFF; isMultiframe = true; break; } if (frame < 0) { if (!isMultiframe) { frame = 0; } else { stream = scratch.SaveToWICMemory(0, info.ArraySize, WIC_FLAGS.ALL_FRAMES, TexHelper.Instance.GetWICCodec(codec)); } } if (frame >= 0) { stream = scratch.SaveToWICMemory(frame, WIC_FLAGS.NONE, TexHelper.Instance.GetWICCodec(codec)); } byte[] tex = new byte[stream.Length]; stream.Read(tex, 0, tex.Length); scratch.Dispose(); return(tex); } } } } catch { if (scratch != null && scratch.IsDisposed == false) { scratch?.Dispose(); } } } catch { } return(null); }
public PreviewHeroData(GUIDEntry guidEntry, Hero hero) { GUIDString = teResourceGUID.AsString(guidEntry.GUID); Hero = hero; InitializeComponent(); }
public PreviewDataMapHeader(GUIDEntry guidEntry, MapHeader mapHeader) { GUIDString = teResourceGUID.AsString(guidEntry.GUID); MapHeader = mapHeader; InitializeComponent(); }