add initial files

This commit is contained in:
DESKTOP-63JQM2H\justi 2024-10-04 17:07:01 -05:00
parent d261899664
commit 5e4edd102e
23 changed files with 9273 additions and 0 deletions

25
VTFXUtil.sln Normal file
View file

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.438
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VTFXUtil", "VTFXUtil\VTFXUtil.csproj", "{AC6B703C-9018-4420-8EBB-E57E7A1D2562}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AC6B703C-9018-4420-8EBB-E57E7A1D2562}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC6B703C-9018-4420-8EBB-E57E7A1D2562}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC6B703C-9018-4420-8EBB-E57E7A1D2562}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC6B703C-9018-4420-8EBB-E57E7A1D2562}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BEA56C1C-1F4C-42D9-B0F8-3B2DC4321135}
EndGlobalSection
EndGlobal

20
VTFXUtil/App.config Normal file
View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.IO.RecyclableMemoryStream" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.4.0.0" newVersion="1.4.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

265
VTFXUtil/Form1.Designer.cs generated Normal file
View file

@ -0,0 +1,265 @@
namespace VTFXUtil
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.helloWorldLabel = new System.Windows.Forms.Label();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton();
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.importToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.MonsieurResizer = new System.Windows.Forms.Panel();
this.PreviewBox = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.TxFmtLb = new System.Windows.Forms.Label();
this.DimensionLb = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.ResTbl = new System.Windows.Forms.ListView();
this.ResType = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.ResOffset = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.toolStrip1.SuspendLayout();
this.groupBox1.SuspendLayout();
this.MonsieurResizer.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.PreviewBox)).BeginInit();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// helloWorldLabel
//
this.helloWorldLabel.AutoSize = true;
this.helloWorldLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.helloWorldLabel.Location = new System.Drawing.Point(115, 25);
this.helloWorldLabel.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.helloWorldLabel.Name = "helloWorldLabel";
this.helloWorldLabel.Size = new System.Drawing.Size(422, 26);
this.helloWorldLabel.TabIndex = 3;
this.helloWorldLabel.Text = "hello yes i am a program i convert textures";
//
// toolStrip1
//
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripDropDownButton1});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(1212, 25);
this.toolStrip1.TabIndex = 4;
this.toolStrip1.Text = "toolStrip1";
//
// toolStripDropDownButton1
//
this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.toolStripDropDownButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.openToolStripMenuItem,
this.importToolStripMenuItem,
this.exportToolStripMenuItem,
this.exitToolStripMenuItem});
this.toolStripDropDownButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton1.Image")));
this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripDropDownButton1.Name = "toolStripDropDownButton1";
this.toolStripDropDownButton1.ShowDropDownArrow = false;
this.toolStripDropDownButton1.Size = new System.Drawing.Size(29, 22);
this.toolStripDropDownButton1.Text = "File";
//
// openToolStripMenuItem
//
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.Size = new System.Drawing.Size(110, 22);
this.openToolStripMenuItem.Text = "Open";
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
//
// importToolStripMenuItem
//
this.importToolStripMenuItem.Name = "importToolStripMenuItem";
this.importToolStripMenuItem.Size = new System.Drawing.Size(110, 22);
this.importToolStripMenuItem.Text = "Import";
this.importToolStripMenuItem.Click += new System.EventHandler(this.importToolStripMenuItem_Click);
//
// exportToolStripMenuItem
//
this.exportToolStripMenuItem.Name = "exportToolStripMenuItem";
this.exportToolStripMenuItem.Size = new System.Drawing.Size(110, 22);
this.exportToolStripMenuItem.Text = "Export";
this.exportToolStripMenuItem.Click += new System.EventHandler(this.exportToolStripMenuItem_Click);
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(110, 22);
this.exitToolStripMenuItem.Text = "Exit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
//
// groupBox1
//
this.groupBox1.AutoSize = true;
this.groupBox1.Controls.Add(this.MonsieurResizer);
this.groupBox1.Location = new System.Drawing.Point(77, 54);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(527, 553);
this.groupBox1.TabIndex = 5;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Preview";
//
// MonsieurResizer
//
this.MonsieurResizer.AutoScroll = true;
this.MonsieurResizer.Controls.Add(this.PreviewBox);
this.MonsieurResizer.Location = new System.Drawing.Point(6, 19);
this.MonsieurResizer.Name = "MonsieurResizer";
this.MonsieurResizer.Size = new System.Drawing.Size(515, 515);
this.MonsieurResizer.TabIndex = 10;
//
// PreviewBox
//
this.PreviewBox.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.PreviewBox.Location = new System.Drawing.Point(0, 0);
this.PreviewBox.Name = "PreviewBox";
this.PreviewBox.Size = new System.Drawing.Size(512, 512);
this.PreviewBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.PreviewBox.TabIndex = 0;
this.PreviewBox.TabStop = false;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(621, 86);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(74, 13);
this.label1.TabIndex = 6;
this.label1.Text = "Platform type: ";
//
// TxFmtLb
//
this.TxFmtLb.AutoSize = true;
this.TxFmtLb.Location = new System.Drawing.Point(621, 99);
this.TxFmtLb.Name = "TxFmtLb";
this.TxFmtLb.Size = new System.Drawing.Size(81, 13);
this.TxFmtLb.TabIndex = 7;
this.TxFmtLb.Text = "Texture format: ";
//
// DimensionLb
//
this.DimensionLb.AutoSize = true;
this.DimensionLb.Location = new System.Drawing.Point(621, 112);
this.DimensionLb.Name = "DimensionLb";
this.DimensionLb.Size = new System.Drawing.Size(67, 13);
this.DimensionLb.TabIndex = 8;
this.DimensionLb.Text = "Dimensions: ";
//
// groupBox2
//
this.groupBox2.AutoSize = true;
this.groupBox2.Controls.Add(this.ResTbl);
this.groupBox2.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox2.Location = new System.Drawing.Point(867, 25);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(345, 598);
this.groupBox2.TabIndex = 9;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Resources";
//
// ResTbl
//
this.ResTbl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.ResTbl.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.ResType,
this.ResOffset});
this.ResTbl.GridLines = true;
this.ResTbl.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.ResTbl.HideSelection = false;
this.ResTbl.Location = new System.Drawing.Point(7, 20);
this.ResTbl.Name = "ResTbl";
this.ResTbl.Size = new System.Drawing.Size(332, 193);
this.ResTbl.TabIndex = 0;
this.ResTbl.UseCompatibleStateImageBehavior = false;
this.ResTbl.View = System.Windows.Forms.View.Details;
//
// ResType
//
this.ResType.Text = "Resource Type";
this.ResType.Width = 189;
//
// ResOffset
//
this.ResOffset.Text = "Resource Offset (base 10)";
this.ResOffset.Width = 137;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.AutoSize = true;
this.ClientSize = new System.Drawing.Size(1212, 623);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.DimensionLb);
this.Controls.Add(this.TxFmtLb);
this.Controls.Add(this.label1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.toolStrip1);
this.Controls.Add(this.helloWorldLabel);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Margin = new System.Windows.Forms.Padding(2);
this.Name = "Form1";
this.Text = "VTFXUtil";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed);
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.MonsieurResizer.ResumeLayout(false);
this.MonsieurResizer.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.PreviewBox)).EndInit();
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label helloWorldLabel;
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton1;
private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exportToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label TxFmtLb;
private System.Windows.Forms.Label DimensionLb;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.ListView ResTbl;
private System.Windows.Forms.ColumnHeader ResType;
private System.Windows.Forms.ColumnHeader ResOffset;
private System.Windows.Forms.PictureBox PreviewBox;
private System.Windows.Forms.Panel MonsieurResizer;
private System.Windows.Forms.ToolStripMenuItem importToolStripMenuItem;
}
}

500
VTFXUtil/Form1.cs Normal file
View file

@ -0,0 +1,500 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; // image control
using System.Drawing.Drawing2D;
using System.Linq; // this might need to be tossed
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; // UI
namespace VTFXUtil
{
public partial class Form1 : Form
{
public static string MyCodeSucks = null; // i forced this to be classwide, so that importing would work correctly
// i really did not want to deal with returning tuples
private static VTFXHandler.VTFXFile FileInMem; // make this a classwide var, will use for exporting
private static byte[] UnscrewedTextureData; // will be used for exporting
private static byte[] UnscrewedMippedTextureData; // used for non-VTF exports
private static bool GlobalMipped; // non-VTF exports will use this
private static readonly string AppTempPath = System.IO.Path.GetTempPath() + @"\DONT TOUCH ME";
private static int ExportMipCount; // also for exporting
string LabelPersistText = "Platform type: ";
string TexFormatLabelText = "Texture format: ";
string DLb = "Dimensions: ";
public static readonly byte[] XBoxBytes = { 0, 0, 3, 96 };
public static readonly byte[] PS3Bytes = { 0, 0, 3, 51 };
OpenFileDialog Opener = new OpenFileDialog();
public Form1()
{
InitializeComponent();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
ImportAsVTFX(ImportAndClearTable(), null); // isolated this to make it cleaner here
}
private string ImportAndClearTable()
{
ResTbl.Items.Clear();
Opener.Filter = "Valve Texture Format|*.vtf|Xbox 360 VTF|*.360.vtf|PlayStation 3 VTF|*.ps3.vtf";
Opener.Title = "Open File";
Opener.ShowDialog();
if (Opener.FileName.Equals(""))
{
return "";
}
string Path = Opener.FileName;
return Path;
}
private void ImportAsVTFX(string Path, System.IO.MemoryStream MemStream)
{
if (Path.Equals(""))
{
return;
}
VTFXHandler.VTFXFile Imported;
if(MemStream == null) // checks to see if we are using this to import from a MemoryStream
{
Imported = VTFXHandler.ImportVTFX(Path);
}
else
{
Imported = VTFXHandler.ImportVTFX(MemStream);
}
if(Imported == null)
{
GC.Collect(); // we're done here, clean the ram
return;
}
byte[] VerMaj = new byte[4];
byte[] VerMin = new byte[4];
bool NeedLZMADecompress = false;
byte[] Texture;
Array.Copy(Imported.VersionNum, 0, VerMaj, 0, 4);
Array.Copy(Imported.VersionNum, 4, VerMin, 0, 4);
Array.Reverse(VerMin);
int VerMinInt = System.BitConverter.ToInt32(VerMin, 0);
string VerTextAppend = "";
Console.WriteLine(VerMaj);
Console.WriteLine(VerMin);
foreach (object Thing in VerMaj)
{
Console.WriteLine(Thing);
}
foreach (object Thing in VerMin)
{
Console.WriteLine(Thing);
}
if (VerMaj.SequenceEqual(XBoxBytes))
{
VerTextAppend = "Xbox 360";
NeedLZMADecompress = true;
}
else if (VerMaj.SequenceEqual(PS3Bytes))
{
VerTextAppend = "PlayStation 3";
}
else
{
VerTextAppend = "Unknown";
}
label1.Text = LabelPersistText + VerTextAppend + ", Revision " + VerMinInt.ToString();
byte[] TxFmtLE = Imported.TextureFormat;
int TxFmtInt = System.BitConverter.ToInt32(TxFmtLE, 0);
TxFmtLb.Text = TexFormatLabelText + VTFGeneral.TexFmtStrArr[TxFmtInt];
Console.WriteLine("Texture format of imported texture is: {0}.", VTFGeneral.TexFmtStrArr[TxFmtInt]);
DimensionLb.Text = DLb + Imported.ImageWidth.ToString() + "x" + Imported.ImageHeight.ToString();
foreach (var Resource in Imported.Resources)
{
string[] ResArr = new string[2];
ResArr[0] = VTFGeneral.GetResourceType(Resource.Key);
ResArr[1] = Resource.Value.ToString();
ListViewItem ResourceItem = new ListViewItem(ResArr);
ResTbl.Items.Add(ResourceItem);
}
System.IO.Directory.CreateDirectory(AppTempPath);
if (NeedLZMADecompress) //Xbox 360 textures are LZMA compressed, so we need to decompress them into an uncompressed mess
{
string TempInPath = AppTempPath + @"\" + Opener.SafeFileName + ".ENC";
string TempOutPath = AppTempPath + @"\" + Opener.SafeFileName + ".DEC";
Texture = ImageImporter.LZMADecompress(Imported.FileData, TempInPath, TempOutPath);
}
else //just take the file data itself, will only be used in the case of PS3 formatted files
{
Texture = Imported.FileData;
}
VTFGeneral.VTFFormatProps TextureProperties = VTFGeneral.FormatTable[TxFmtInt];
int ByteBufferLen = TextureProperties.ColorByteAmount;
if (!(TextureProperties.IsCompressed)) // endianswap for non-compressed textures
{
Texture = ImageImporter.EndianSwap(Texture, ByteBufferLen);
}
if (TextureProperties.IsCompressed && NeedLZMADecompress) //this will only trigger on files from the 360, as they will always be LZMA compressed
{
Console.WriteLine("This is a 360 texture, needing to fuck it up now!");
Texture = ImageImporter.RearrangeCompressedTexture(Texture, TxFmtInt);
}
//STARTING HERE, MIPMAPS WILL BE REVERSED, AS DDS AND OTHER FORMATS HAVE THE BIGGEST MIP FIRST, WHILE VTF HAS SMALLEST MIP FIRST
bool Mippable = MipMaker.IsMipped(Imported.ImageWidth, Imported.ImageHeight, TxFmtInt, Texture.Length);
GlobalMipped = Mippable;
System.IO.MemoryStream CurrentTexture = new System.IO.MemoryStream();
MipMaker.MipMap[] MipList;
int MipCount = 1;
if (Mippable)
{
//Console.WriteLine("hey we can mip this");
MipList = MipMaker.GenMipInfo(Imported.ImageWidth, Imported.ImageHeight, TxFmtInt);
MipCount = MipList.Length;
CurrentTexture = ImageImporter.ReverseMipsIntoMemoryStream(Texture, Imported.ImageWidth, Imported.ImageHeight, TxFmtInt, MipList);
}
UnscrewedTextureData = Texture;
if (Mippable)
{
Texture = CurrentTexture.ToArray();
UnscrewedMippedTextureData = Texture;
}
ExportMipCount = MipCount;
System.IO.MemoryStream PNGStream = ImageImporter.GenerateImage(Texture, ExportMipCount, TxFmtInt, Imported);
Bitmap PreviewImage = new Bitmap(PNGStream);
PreviewBox.Image = PreviewImage;
FileInMem = Imported; // pass this through for export purposes
if (Imported.ImageWidth > MonsieurResizer.Width || Imported.ImageHeight > MonsieurResizer.Height)
{
PreviewBox.SizeMode = PictureBoxSizeMode.AutoSize; // enable autosizing to allow for scrollbars to appear if image is bigger than 512x512
}
else
{
PreviewBox.Width = 512;
PreviewBox.Height = 512; // set picture box size to default, that way it properly recenters it
PreviewBox.SizeMode = PictureBoxSizeMode.CenterImage; // apply centering
}
GC.Collect(); // we're done here, clean the ram
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (System.IO.Directory.Exists(AppTempPath))
{
System.IO.Directory.Delete(AppTempPath, true); // empty the temp directory that we have
}
}
private void exportToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog SaveDlg = new SaveFileDialog();
SaveDlg.Filter = "Valve Texture Format|*.vtf|Tagged Image Format|*.tif|DirectDraw Surface|*.dds"; // hehe filters
SaveDlg.Title = "Export File";
SaveDlg.ShowDialog();
if (SaveDlg.FileName.Equals(""))
{
return;
}
System.IO.FileStream OutputFile = (System.IO.FileStream)SaveDlg.OpenFile();
switch (SaveDlg.FilterIndex)
{
case 1: // VTF
byte[] VTFString = { 0x56, 0x54, 0x46, 0x00 }; // "VTF" + 0x00
byte[] VTFVer = { 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00 }; // Defaults to 7.3
int ResourceHeaderLength = 8; //only exports high res data and headers, as the console formats seem to only use it
int HeaderSize = 0x50 + ResourceHeaderLength;
byte[] StartFrame = { 0x00, 0x00 };
byte[] FourBytePadding = { 0x00, 0x00, 0x00, 0x00 };
byte[] HighRes = { 0x30, 0x00, 0x00, 0x00 };
byte[] NOFORMAT = { 0xFF, 0xFF, 0xFF, 0xFF };
int MipCount = ExportMipCount; // is set to whatever was calculated earlier on when importing
// holy fuck this feels like too much just to write one file
OutputFile.Write(VTFString, 0, VTFString.Length);
OutputFile.Write(VTFVer, 0, VTFVer.Length);
OutputFile.Write(BitConverter.GetBytes(HeaderSize), 0, 4);
OutputFile.Write(BitConverter.GetBytes(FileInMem.ImageWidth), 0, 2);
OutputFile.Write(BitConverter.GetBytes(FileInMem.ImageHeight), 0, 2);
OutputFile.Write(FileInMem.VTFFlags, 0, FileInMem.VTFFlags.Length);
OutputFile.Write(BitConverter.GetBytes(FileInMem.FrameCount), 0, 2);
OutputFile.Write(StartFrame, 0, 2);
OutputFile.Write(FourBytePadding, 0, 4);
OutputFile.Write(FileInMem.ReflectivityVec, 0, 12);
OutputFile.Write(FourBytePadding, 0, 4);
OutputFile.Write(BitConverter.GetBytes(FileInMem.BumpScale), 0, 4);
OutputFile.Write(FileInMem.TextureFormat, 0, FileInMem.TextureFormat.Length);
OutputFile.Write(BitConverter.GetBytes(MipCount), 0, 1);
OutputFile.Write(NOFORMAT, 0, 4);
OutputFile.Write(BitConverter.GetBytes(0), 0, 1);
OutputFile.Write(BitConverter.GetBytes(0), 0, 1);
OutputFile.Write(BitConverter.GetBytes(FileInMem.BitDepth), 0, 1);
OutputFile.Write(FourBytePadding, 0, 4);
OutputFile.Write(BitConverter.GetBytes(FileInMem.ResourceCount), 0, 4);
OutputFile.Write(FourBytePadding, 0, 4);
OutputFile.Write(FourBytePadding, 0, 4);
OutputFile.Write(HighRes, 0, 4);
OutputFile.Write(BitConverter.GetBytes(HeaderSize), 0, 4);
OutputFile.Write(UnscrewedTextureData, 0, UnscrewedTextureData.Length);
break;
case 2: // TIF
Console.WriteLine("Not implemented yet!!!");
break;
case 3: // DDS
CSharpImageLibrary.ImageEngineFormat ParsedEnum = (CSharpImageLibrary.ImageEngineFormat)Enum.Parse(typeof(VTFGeneral.TEXTURE_FORMATS_INTEROP), Enum.GetName(typeof(VTFGeneral.TEXTURE_FORMATS), System.BitConverter.ToInt32(FileInMem.TextureFormat, 0)));
CSharpImageLibrary.Headers.DDS_Header newDDSHeader = new CSharpImageLibrary.Headers.DDS_Header(ExportMipCount, FileInMem.ImageHeight, FileInMem.ImageWidth, ParsedEnum, CSharpImageLibrary.Headers.DDS_Header.DXGI_FORMAT.DXGI_FORMAT_UNKNOWN);
byte[] DDSHeader = new byte[newDDSHeader.dwSize + 4];
newDDSHeader.WriteToArray(DDSHeader, 0);
byte[] RealTexture = new byte[DDSHeader.Length + UnscrewedTextureData.Length];
Array.Copy(DDSHeader, 0, RealTexture, 0, DDSHeader.Length);
if (GlobalMipped)
{
Array.Copy(UnscrewedMippedTextureData, 0, RealTexture, DDSHeader.Length, UnscrewedMippedTextureData.Length);
}
else
{
Array.Copy(UnscrewedTextureData, 0, RealTexture, DDSHeader.Length, UnscrewedTextureData.Length);
}
OutputFile.Write(RealTexture, 0, RealTexture.Length);
break;
}
OutputFile.Close();
}
private void importToolStripMenuItem_Click(object sender, EventArgs e)
{
// i wonder how well it can work with animated png's
// if i can't do that then i guess some other demuxing of other formats could do the job
Opener = new OpenFileDialog();
Opener.Filter = "Valve Texture Format|*.vtf";
Opener.Title = "Import File";
Opener.ShowDialog();
if (Opener.FileNames.Length == 0)
{
Console.WriteLine("whoops nothing!");
return;
}
Form2 ImportDlg = new Form2();
ImportDlg.ShowDialog();
if (MyCodeSucks == null)
{
return;
}
System.IO.FileStream InputFile = (System.IO.FileStream)Opener.OpenFile();
//Factory.Load(InputFile); // leave this out for now, need to figure out image shit
// anything that isn't png or vtf will have to have individual frames shoved in as seperate files
Formats.VTFFile ImportVTF = new Formats.VTFFile();
byte[] VTFTextureData;
using (InputFile) // convert our file data into an object, and fill the object with the file's data
{
InputFile.Position += 4; // skip file magic, we already told it to ensure that it is correct
InputFile.Read(ImportVTF.FileVersion, 0, 8);
byte[] TempByteConvert = new byte[4];
InputFile.Read(TempByteConvert, 0, 4);
ImportVTF.HeaderLength = System.BitConverter.ToInt32(TempByteConvert, 0);
TempByteConvert = new byte[2];
InputFile.Read(TempByteConvert, 0, 2);
ImportVTF.Width = System.BitConverter.ToInt16(TempByteConvert, 0);
InputFile.Read(TempByteConvert, 0, 2);
ImportVTF.Height = System.BitConverter.ToInt16(TempByteConvert, 0);
InputFile.Read(ImportVTF.Flags, 0, 4);
InputFile.Read(TempByteConvert, 0, 2);
ImportVTF.Frames = System.BitConverter.ToInt16(TempByteConvert, 0);
InputFile.Read(TempByteConvert, 0, 2);
ImportVTF.FirstFrame = System.BitConverter.ToInt16(TempByteConvert, 0);
InputFile.Position += 4; // skip over padding
InputFile.Read(ImportVTF.ReflectivityVector, 0, 12);
InputFile.Position += 4; // skip over more padding
TempByteConvert = new byte[4];
InputFile.Read(TempByteConvert, 0, 4);
ImportVTF.BumpScale = System.BitConverter.ToSingle(TempByteConvert, 0);
InputFile.Read(ImportVTF.Format, 0, 4);
TempByteConvert = new byte[1];
InputFile.Read(TempByteConvert, 0, 1);
ImportVTF.MipmapCount = TempByteConvert[0];
InputFile.Read(ImportVTF.ThumbFormat, 0, 4);
InputFile.Read(TempByteConvert, 0, 1);
ImportVTF.ThumbWidth = TempByteConvert[0];
InputFile.Read(TempByteConvert, 0, 1);
ImportVTF.ThumbHeight = TempByteConvert[0];
InputFile.Read(TempByteConvert, 0, 1);
ImportVTF.ImageDepth = TempByteConvert[0];
InputFile.Position += 4; // skip over even more padding
TempByteConvert = new byte[4];
InputFile.Read(TempByteConvert, 0, 4);
ImportVTF.ResourceCount = System.BitConverter.ToInt32(TempByteConvert, 0);
int ResByteLength = ImportVTF.ResourceCount * 8;
while (ResByteLength > 0) // get those resources, boy
{
byte[] ResType = new byte[3];
byte ResKind;
int ResOffset;
InputFile.Read(ResType, 0, 3);
ResByteLength -= 3;
TempByteConvert = new byte[1];
InputFile.Read(TempByteConvert, 0, 1);
ResKind = TempByteConvert[0];
ResByteLength--;
TempByteConvert = new byte[4];
InputFile.Read(TempByteConvert, 0, 4);
ResOffset = System.BitConverter.ToInt32(TempByteConvert, 0);
ImportVTF.Resources.Add(new VTFGeneral.VTFResource(ResType, ResKind, ResOffset));
ResByteLength -= 4;
}
InputFile.Position = ImportVTF.HeaderLength;
VTFTextureData = new byte[InputFile.Length - ImportVTF.HeaderLength];
InputFile.Read(VTFTextureData, 0, VTFTextureData.Length);
Bitmap ColorSamplingMan = new Bitmap(1, 1);
// TODO: implement actual features for changing texture formats, such as converting DXT5 into RGBA8888 and so forth
// as all this does is just eat the original texture with it's current format, and ignores what the user wanted
// actually no, screw this, i'm going to reduce this to only the VTF format for imports, as it will be easier to do so with
// and then do nothing if our format is already the same
if (ImportVTF.MipmapCount > 1)
{
MipMaker.MipMap[] MipList = MipMaker.GenMipInfo(ImportVTF.Width, ImportVTF.Height, System.BitConverter.ToInt32(ImportVTF.Format, 0));
System.IO.MemoryStream heheimrawdata = ImageImporter.ReverseMipsIntoMemoryStream(VTFTextureData, ImportVTF.Width, ImportVTF.Height, System.BitConverter.ToInt32(ImportVTF.Format, 0), MipList);
System.IO.MemoryStream NewImage = ImageImporter.GenerateImage(heheimrawdata.ToArray(), ImportVTF.MipmapCount, System.BitConverter.ToInt32(ImportVTF.Format, 0), ImportVTF);
heheimrawdata.Flush();
heheimrawdata.Dispose();
Bitmap ReversedMips = new Bitmap(NewImage);
using (Graphics g = Graphics.FromImage(ColorSamplingMan))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(ReversedMips, new Rectangle(0, 0, 1, 1));
}
NewImage.Flush();
NewImage.Dispose();
}
else
{
System.IO.MemoryStream NewImage = ImageImporter.GenerateImage(VTFTextureData, ImportVTF.MipmapCount, System.BitConverter.ToInt32(ImportVTF.Format, 0), ImportVTF);
Bitmap Gimage = new Bitmap(NewImage);
using (Graphics g = Graphics.FromImage(ColorSamplingMan))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(Gimage, new Rectangle(0, 0, 1, 1));
}
NewImage.Flush();
NewImage.Dispose();
}
Color AveragedColor = ColorSamplingMan.GetPixel(0, 0);
byte[] ColorSamplingValue = { AveragedColor.R, AveragedColor.G, AveragedColor.B, AveragedColor.A };
VTFGeneral.VTFFormatProps TextureProperties = VTFGeneral.FormatTable[System.BitConverter.ToInt32(ImportVTF.Format, 0)];
int ByteBufferLen = TextureProperties.ColorByteAmount;
if (!(TextureProperties.IsCompressed)) // endianswap for non-compressed textures, or just only do this in the case of an uncompressed texture
{
VTFTextureData = ImageImporter.EndianSwap(VTFTextureData, ByteBufferLen);
}
byte[] TexturePlatform = null;
byte[] CompressedSize = new byte[4];
string PlatformSpecificExtension = ".vtf";
if (TextureProperties.IsCompressed && MyCodeSucks.Equals("Xbox 360")) //this will only trigger on files from the 360, as they will always be LZMA compressed
{
TexturePlatform = XBoxBytes;
PlatformSpecificExtension = ".360.vtf";
VTFTextureData = ImageImporter.RearrangeCompressedTexture(VTFTextureData, System.BitConverter.ToInt32(ImportVTF.Format, 0));
System.IO.MemoryStream Compressed = ImageImporter.LZMACompress(VTFTextureData);
byte[] CompressedArray = Compressed.ToArray();
VTFTextureData = CompressedArray;
CompressedSize = System.BitConverter.GetBytes(VTFTextureData.Length);
CompressedSize.Reverse();
}
if (MyCodeSucks.Equals("PlayStation 3"))
{
PlatformSpecificExtension = ".PS3.vtf";
TexturePlatform = PS3Bytes;
CompressedSize[0] = 0;
CompressedSize[1] = 0;
CompressedSize[2] = 0;
CompressedSize[3] = 0;
}
if (TexturePlatform == null)
{
return; // program machine broke
}
VTFXHandler.VTFXFile ConversionMan = VTFXHandler.ConvertVTFToVTFX(ImportVTF, VTFTextureData, TexturePlatform, ColorSamplingValue);
System.IO.FileStream OutputFile = new System.IO.FileStream(Opener.FileNames[0] + PlatformSpecificExtension, System.IO.FileMode.Create);
using (OutputFile)
{
OutputFile.Write(Encoding.UTF8.GetBytes(ConversionMan.FileMagic), 0, ConversionMan.FileMagic.Length);
OutputFile.Write(ConversionMan.VersionNum, 0, 4);
TempByteConvert = new byte[4];
TempByteConvert[0] = 0;
TempByteConvert[1] = 0;
TempByteConvert[2] = 0;
TempByteConvert[3] = 0x08;
OutputFile.Write(TempByteConvert, 0, 4);
TempByteConvert = System.BitConverter.GetBytes(ConversionMan.HeaderSize);
Array.Reverse(TempByteConvert);
OutputFile.Write(TempByteConvert, 0, 4);
TempByteConvert = new byte[4];
Array.Copy(ConversionMan.VTFFlags, 0, TempByteConvert, 0, 4);
Array.Reverse(TempByteConvert);
OutputFile.Write(TempByteConvert, 0, 4);
TempByteConvert = new byte[2];
TempByteConvert = System.BitConverter.GetBytes(Convert.ToUInt16(ConversionMan.ImageWidth));
Array.Reverse(TempByteConvert);
OutputFile.Write(TempByteConvert, 0, 2);
TempByteConvert = System.BitConverter.GetBytes(Convert.ToUInt16(ConversionMan.ImageHeight));
Array.Reverse(TempByteConvert);
OutputFile.Write(TempByteConvert, 0, 2);
TempByteConvert = System.BitConverter.GetBytes(Convert.ToUInt16(ConversionMan.BitDepth));
Array.Reverse(TempByteConvert);
OutputFile.Write(TempByteConvert, 0, 2);
TempByteConvert = System.BitConverter.GetBytes(Convert.ToUInt16(ConversionMan.FrameCount));
Array.Reverse(TempByteConvert);
OutputFile.Write(TempByteConvert, 0, 2);
TempByteConvert = System.BitConverter.GetBytes(Convert.ToUInt16(ConversionMan.PreloadSize));
Array.Reverse(TempByteConvert);
OutputFile.Write(TempByteConvert, 0, 2);
OutputFile.WriteByte(Convert.ToByte(ConversionMan.MipSkipCount));
OutputFile.WriteByte(Convert.ToByte(ConversionMan.ResourceCount));
TempByteConvert = new byte[4];
Array.Copy(ConversionMan.ReflectivityVec, 0, TempByteConvert, 0, 4);
Array.Reverse(TempByteConvert);
OutputFile.Write(TempByteConvert, 0, 4);
Array.Copy(ConversionMan.ReflectivityVec, 4, TempByteConvert, 0, 4);
Array.Reverse(TempByteConvert);
OutputFile.Write(TempByteConvert, 0, 4);
Array.Copy(ConversionMan.ReflectivityVec, 8, TempByteConvert, 0, 4);
Array.Reverse(TempByteConvert);
OutputFile.Write(TempByteConvert, 0, 4);
TempByteConvert = System.BitConverter.GetBytes(ConversionMan.BumpScale);
Array.Reverse(TempByteConvert);
OutputFile.Write(TempByteConvert, 0, 4);
TempByteConvert = ConversionMan.TextureFormat;
Array.Reverse(TempByteConvert);
OutputFile.Write(TempByteConvert, 0, 4);
OutputFile.Write(ConversionMan.LowResSamplingAmt, 0, 4);
OutputFile.Write(CompressedSize, 0, 4);
TempByteConvert[0] = 0x30;
TempByteConvert[1] = 0;
TempByteConvert[2] = 0;
TempByteConvert[3] = 0;
OutputFile.Write(TempByteConvert, 0, 4);
TempByteConvert[0] = 0;
TempByteConvert[3] = 0x44;
OutputFile.Write(TempByteConvert, 0, 4);
OutputFile.Write(VTFTextureData, 0, VTFTextureData.Length);
Console.WriteLine("texture imported and saved to " + Opener.FileNames[0] + PlatformSpecificExtension);
}
}
//InputFile.Flush();
InputFile.Dispose();
GC.Collect(); // we're done here, clean the ram
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
}
}

3363
VTFXUtil/Form1.resx Normal file

File diff suppressed because it is too large Load diff

109
VTFXUtil/Form2.Designer.cs generated Normal file
View file

@ -0,0 +1,109 @@
namespace VTFXUtil
{
partial class Form2
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form2));
this.OKButton = new System.Windows.Forms.Button();
this.CancelButton = new System.Windows.Forms.Button();
this.label7 = new System.Windows.Forms.Label();
this.PlatformCombo = new System.Windows.Forms.ComboBox();
this.PlatformTooltip = new System.Windows.Forms.ToolTip(this.components);
this.SuspendLayout();
//
// OKButton
//
this.OKButton.Location = new System.Drawing.Point(63, 33);
this.OKButton.Name = "OKButton";
this.OKButton.Size = new System.Drawing.Size(75, 23);
this.OKButton.TabIndex = 3;
this.OKButton.Text = "OK";
this.OKButton.UseVisualStyleBackColor = true;
this.OKButton.Click += new System.EventHandler(this.OKButton_Click);
//
// CancelButton
//
this.CancelButton.Location = new System.Drawing.Point(144, 33);
this.CancelButton.Name = "CancelButton";
this.CancelButton.Size = new System.Drawing.Size(75, 23);
this.CancelButton.TabIndex = 4;
this.CancelButton.Text = "Cancel";
this.CancelButton.UseVisualStyleBackColor = true;
this.CancelButton.Click += new System.EventHandler(this.CancelButton_Click);
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(12, 9);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(45, 13);
this.label7.TabIndex = 5;
this.label7.Text = "Platform";
//
// PlatformCombo
//
this.PlatformCombo.FormattingEnabled = true;
this.PlatformCombo.Items.AddRange(new object[] {
"PlayStation 3",
"Xbox 360"});
this.PlatformCombo.Location = new System.Drawing.Point(63, 6);
this.PlatformCombo.Name = "PlatformCombo";
this.PlatformCombo.Size = new System.Drawing.Size(148, 21);
this.PlatformCombo.TabIndex = 6;
//
// PlatformTooltip
//
this.PlatformTooltip.ToolTipTitle = "hello";
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(227, 65);
this.Controls.Add(this.PlatformCombo);
this.Controls.Add(this.label7);
this.Controls.Add(this.CancelButton);
this.Controls.Add(this.OKButton);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form2";
this.Text = "Platform Selection";
this.Load += new System.EventHandler(this.Form2_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button OKButton;
private System.Windows.Forms.Button CancelButton;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.ComboBox PlatformCombo;
private System.Windows.Forms.ToolTip PlatformTooltip;
}
}

44
VTFXUtil/Form2.cs Normal file
View file

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
// this will now be a new home for our texture import options
namespace VTFXUtil
{
public partial class Form2 : Form
{
public string Platform;
public Form2()
{
InitializeComponent();
}
private void OKButton_Click(object sender, EventArgs e)
{
Platform = PlatformCombo.GetItemText(PlatformCombo.SelectedItem); // yoink our values, is used down below
Form1.MyCodeSucks = Platform;
Close();
}
private void Form2_Load(object sender, EventArgs e)
{
Console.WriteLine("EYYY IM WALKIN HERE");
PlatformTooltip.SetToolTip(PlatformCombo, "Selects the desired target platform for the texture.");
PlatformCombo.SelectedIndex = 0;
}
private void CancelButton_Click(object sender, EventArgs e)
{
Close(); // release the user from this janky window
}
}
}

3348
VTFXUtil/Form2.resx Normal file

File diff suppressed because it is too large Load diff

50
VTFXUtil/Formats.cs Normal file
View file

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VTFXUtil
{
// format handling/construction type things should go here from now on
public class Formats
{
public class VTFFile
{
public readonly byte[] Magic = { 0x56, 0x54, 0x46, 0x00 };
public byte[] FileVersion = new byte[8];
public int HeaderLength; // may vary upon how many resources the image contains, but a 7.3 header has a length of 0x50 when resource info is stripped
public int Width;
public int Height;
public byte[] Flags = new byte[4];
public int Frames;
public int FirstFrame = 0; // will usually be zero, so it should be fine to hardcode it here
// 4 bytes of padding
public byte[] ReflectivityVector = new byte[12]; // contains three 4 byte floats
// another 4 bytes of padding
public float BumpScale; // single float
public byte[] Format = new byte[4];
public int MipmapCount; // 8-bit integer
public byte[] ThumbFormat = new byte[4];
public int ThumbWidth;
public int ThumbHeight;
public int ImageDepth; // all 3 of these are also 8-bit integers, depth will only apply to 7.2 and above
// another 4 bytes of padding
public int ResourceCount; // will only apply to 7.3 and above
// 8 bytes of padding
public List<VTFGeneral.VTFResource> Resources = new List<VTFGeneral.VTFResource>(); // also only applies to 7.3 and above
public bool CheckMagic(byte[] Magic)
{
if (Magic.Equals(this.Magic))
{
return true;
}
else
{
return false;
}
}
}
}
}

View file

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VTFXUtil
{
public class ImageImportProperties
{
public string OutAlphaFmt;
public string OutNoAlphaFmt;
public string OutTexType;
public bool DemandedResize;
public bool DemandedClamps;
public bool CanGenerateMips;
public string Ree;
public int ClampingWidth;
public int ClampingHeight;
public string Platform;
public ImageImportProperties(string Alphafmt, string Regfmt, string Textype, bool Resizetrig, bool Clampable, bool Genmips, string Resmethod, int Clampwidth, int Clampheight, string Plat)
{
OutAlphaFmt = Alphafmt;
OutNoAlphaFmt = Regfmt;
OutTexType = Textype;
DemandedResize = Resizetrig;
DemandedClamps = Clampable;
CanGenerateMips = Genmips;
Ree = Resmethod;
ClampingWidth = Clampwidth;
ClampingHeight = Clampheight;
Platform = Plat;
}
}
}

292
VTFXUtil/ImageImporter.cs Normal file
View file

@ -0,0 +1,292 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// image importing methods will be left up to this thing, as i may have cluttered the fuck out of Form1.cs
namespace VTFXUtil
{ /// <summary>
/// Handles methods for general texture import/export/manipulation uses.
/// </summary>
class ImageImporter
{
/// <summary>
/// Decompresses LZMA compressed files. Primarily used on Xbox 360 textures.
/// </summary>
/// <param name="inData"></param>
/// <param name="inPath"></param>
/// <param name="outPath"></param>
/// <returns></returns>
public static byte[] LZMADecompress(byte[] inData, string inPath, string outPath)
{
System.IO.FileStream TempLZMAIn = new System.IO.FileStream(inPath, System.IO.FileMode.Create);
TempLZMAIn.Write(inData, 0, inData.Length);
TempLZMAIn.Close();
TempLZMAIn = new System.IO.FileStream(inPath, System.IO.FileMode.Open);
System.IO.FileStream TempLZMAOut = new System.IO.FileStream(outPath, System.IO.FileMode.Create);
byte[] HeaderBytes = new byte[4];
byte[] UncompressedSizeBytes = new byte[4];
byte[] CompressedSizeBytes = new byte[4];
byte[] DecoderProperties = new byte[5];
TempLZMAIn.Read(HeaderBytes, 0, 4);
TempLZMAIn.Read(UncompressedSizeBytes, 0, 4);
TempLZMAIn.Read(CompressedSizeBytes, 0, 4);
TempLZMAIn.Read(DecoderProperties, 0, 5);
int UncompressedSize = System.BitConverter.ToInt32(UncompressedSizeBytes, 0);
int CompressedSize = System.BitConverter.ToInt32(CompressedSizeBytes, 0);
SevenZip.Compression.LZMA.Decoder LZMADec = new SevenZip.Compression.LZMA.Decoder();
LZMADec.SetDecoderProperties(DecoderProperties);
LZMADec.Code(TempLZMAIn, TempLZMAOut, CompressedSize, UncompressedSize, null);
TempLZMAIn.Flush();
TempLZMAOut.Flush();
TempLZMAOut.Close();
TempLZMAOut = new System.IO.FileStream(outPath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] Texture = new byte[UncompressedSize];
using (TempLZMAOut)
{
TempLZMAOut.Read(Texture, 0, UncompressedSize);
}
TempLZMAOut.Close();
TempLZMAIn.Close();
return Texture;
}
/// <summary>
/// Returns an LZMA compressed version of the input data as a MemoryStream.
/// </summary>
/// <param name="InData"></param>
/// <returns></returns>
public static System.IO.MemoryStream LZMACompress(byte[] InData)
{
SevenZip.CoderPropID[] Properties = { SevenZip.CoderPropID.DictionarySize, SevenZip.CoderPropID.PosStateBits, SevenZip.CoderPropID.LitContextBits, SevenZip.CoderPropID.LitPosBits, SevenZip.CoderPropID.Algorithm, SevenZip.CoderPropID.NumFastBytes, SevenZip.CoderPropID.MatchFinder, SevenZip.CoderPropID.EndMarker };
object[] Props2 = { (1 << 23), 2, 3, 0, 2, 128, "bt4", false }; // default properties
SevenZip.Compression.LZMA.Encoder LZMAEnc = new SevenZip.Compression.LZMA.Encoder();
LZMAEnc.SetCoderProperties(Properties, Props2);
System.IO.MemoryStream TempInStream = new System.IO.MemoryStream();
TempInStream.Write(InData, 0, InData.Length);
TempInStream.Position = 0;
System.IO.MemoryStream TempOutStream = new System.IO.MemoryStream();
System.IO.MemoryStream CompressedTexture = new System.IO.MemoryStream();
LZMAEnc.Code(TempInStream, CompressedTexture, -1, -1, null);
long CompressedSize = CompressedTexture.Length;
byte[] LZMAIdent = { 0x4c, 0x5a, 0x4d, 0x41 }; // "LZMA", had to make this a byte array, as you can't copy string values to a stream
TempOutStream.Write(LZMAIdent, 0, 4);
TempOutStream.Write(System.BitConverter.GetBytes(InData.Length), 0, 4);
TempOutStream.Write(System.BitConverter.GetBytes(CompressedSize), 0, 4);
LZMAEnc.WriteCoderProperties(TempOutStream);
TempOutStream.Write(CompressedTexture.ToArray(), 0, CompressedTexture.ToArray().Length); // had to manually append the contents of the texture stream onto the other stream, as apparently resetting the stream screws up with the LZMA coder, which then refuses to properly write the texture
CompressedTexture.Dispose(); // free resources
return TempOutStream;
}
/// <summary>
/// Just a simple endian swap. Nothing more, nothing less.
/// </summary>
/// <param name="Data"></param>
/// <param name="BufferSize"></param>
/// <returns></returns>
public static byte[] EndianSwap(byte[] Data, int BufferSize)
{
byte[] ByteBuffer = new byte[BufferSize]; //create bytebuffer for endianswapping
byte[] TextureTemp = new byte[Data.Length];
for (int i = 0; i < Data.Length; i += ByteBuffer.Length)
{
Array.Copy(Data, i, ByteBuffer, 0, ByteBuffer.Length);
Array.Reverse(ByteBuffer);
Array.Copy(ByteBuffer, 0, TextureTemp, i, ByteBuffer.Length);
}
return TextureTemp;
}
/// <summary>
/// Arranges any Block Compressed texture formats from a format usable by the Xbox 360 into one that a PC can comprehend
/// </summary>
/// <param name="TexData"></param>
/// <param name="Format"></param>
/// <returns></returns>
public static byte[] RearrangeCompressedTexture(byte[] TexData, int Format) //compressed textures on the 360 need to be endianswapped, yet the PS3 counterparts don't
{
byte[] NewTexData = new byte[TexData.Length];
int ColorValLen = 0;
int ColorBlendLen = 0;
int AlphaValLen = 0;
if (Format == (int)VTFGeneral.TEXTURE_FORMATS.IMAGE_FORMAT_DXT1)
{
ColorValLen = 2; //will be doubled!!!
ColorBlendLen = 4;
AlphaValLen = 0;
}
else if (Format == (int)VTFGeneral.TEXTURE_FORMATS.IMAGE_FORMAT_DXT3 || Format == (int)VTFGeneral.TEXTURE_FORMATS.IMAGE_FORMAT_DXT5)
{
AlphaValLen = 8;
ColorValLen = 2; //will be doubled!!
ColorBlendLen = 4;
}
else
{
return TexData;
}
int BlockLength = (ColorValLen * 2) + ColorBlendLen + AlphaValLen;
byte[] EditingBlock = new byte[BlockLength];
for (int i = 0; i < TexData.Length; i += BlockLength)
{
byte[] Color0 = new byte[ColorValLen];
byte[] Color1 = new byte[ColorValLen];
byte[] ColorBlendInfo = new byte[ColorBlendLen];
if (Format == (int)VTFGeneral.TEXTURE_FORMATS.IMAGE_FORMAT_DXT1)
{
Array.Copy(TexData, i, Color0, 0, ColorValLen);
Array.Copy(TexData, i + ColorValLen, Color1, 0, ColorValLen);
Array.Copy(TexData, i + BlockLength - AlphaValLen - ColorBlendLen, ColorBlendInfo, 0, ColorBlendLen);
Array.Reverse(Color0);
Array.Reverse(Color1); // reverse color data, as our endianness is not the same as the Xenon
byte[] DuplicateOfColorLayout = new byte[4];
Array.Copy(ColorBlendInfo, DuplicateOfColorLayout, 4);
ColorBlendInfo[0] = DuplicateOfColorLayout[1];
ColorBlendInfo[1] = DuplicateOfColorLayout[0];
ColorBlendInfo[2] = DuplicateOfColorLayout[3];
ColorBlendInfo[3] = DuplicateOfColorLayout[2]; // color layout inside of the 4x4 blocks is arranged strangely, as [row 2, row 1, row 3, row 4]
Array.Copy(Color0, 0, EditingBlock, 0, ColorValLen);
Array.Copy(Color1, 0, EditingBlock, ColorValLen, ColorValLen);
Array.Copy(ColorBlendInfo, 0, EditingBlock, ColorValLen * 2, ColorBlendLen); //copy new values into the newly created block
}
else //for formats with alpha
{
byte[] AlphaInfo = new byte[AlphaValLen];
Array.Copy(TexData, i, AlphaInfo, 0, AlphaValLen);
byte[] NewAlphaInfo = new byte[AlphaValLen]; // make this for reversible alphas
//Array.Reverse(AlphaInfo);
Array.Copy(TexData, i + AlphaValLen, Color0, 0, ColorValLen);
Array.Copy(TexData, i + AlphaValLen + ColorValLen, Color1, 0, ColorValLen);
Array.Copy(TexData, i + AlphaValLen + BlockLength - AlphaValLen - ColorBlendLen, ColorBlendInfo, 0, ColorBlendLen);
if (Format == (int)VTFGeneral.TEXTURE_FORMATS.IMAGE_FORMAT_DXT5) // the 360's DXT5 type files are reversed in an odd kind of way, i personally haven't encountered many DXT3 files, and will have to be added later if i find one
{
for (int k = 1; k < AlphaValLen; k += 2)
{
NewAlphaInfo[k - 1] = AlphaInfo[k];
NewAlphaInfo[k] = AlphaInfo[k - 1];
}
AlphaInfo = NewAlphaInfo;
}
Array.Reverse(Color0);
Array.Reverse(Color1);
byte[] DuplicateOfColorLayout = new byte[4];
Array.Copy(ColorBlendInfo, DuplicateOfColorLayout, 4);
ColorBlendInfo[0] = DuplicateOfColorLayout[1];
ColorBlendInfo[1] = DuplicateOfColorLayout[0];
ColorBlendInfo[2] = DuplicateOfColorLayout[3];
ColorBlendInfo[3] = DuplicateOfColorLayout[2]; // cloned from dxt1
Array.Copy(AlphaInfo, 0, EditingBlock, 0, AlphaValLen);
Array.Copy(Color0, 0, EditingBlock, AlphaValLen, ColorValLen);
Array.Copy(Color1, 0, EditingBlock, AlphaValLen + ColorValLen, ColorValLen);
Array.Copy(ColorBlendInfo, 0, EditingBlock, AlphaValLen + ColorValLen * 2, ColorBlendLen);
}
Array.Copy(EditingBlock, 0, NewTexData, i, BlockLength); //reconstruct texture data with new stuff
}
return NewTexData;
}
/// <summary>
/// Outputs a MemoryStream with the specified texture data, and reverses the mipmap order, for use in VTF/VTFX or other smallest-mip-first formats.
/// </summary>
/// <param name="TexData"></param>
/// <param name="Width"></param>
/// <param name="Height"></param>
/// <param name="Format"></param>
/// <param name="MipList"></param>
/// <returns></returns>
public static System.IO.MemoryStream ReverseMipsIntoMemoryStream(byte[] TexData, int Width, int Height, int Format, MipMaker.MipMap[] MipList)
{
System.IO.MemoryStream CurrentTexture = new System.IO.MemoryStream();
List<byte[]> Mips = new List<byte[]>();
CurrentTexture.Write(TexData, 0, TexData.Length);
CurrentTexture.Position = 0; // reset back to beginning of the stream, we will need this for what comes next
for (int i = 0; i < MipList.Length; i++)
{
byte[] CurrentMip = new byte[MipList[i].TotalBytes];
CurrentTexture.Read(CurrentMip, 0, MipList[i].TotalBytes);
Mips.Add(CurrentMip); // take the texture data from the stream, and shove it into the list
}
CurrentTexture.Flush();
CurrentTexture.Dispose();
Mips.Reverse();
CurrentTexture = new System.IO.MemoryStream();
foreach (byte[] Mip in Mips)
{
CurrentTexture.Write(Mip, 0, Mip.Length);
}
return CurrentTexture;
}
/// <summary>
/// Converts and outputs texture data as a TIF file in a MemoryStream.
/// </summary>
/// <param name="Texture"></param>
/// <param name="Mipcount"></param>
/// <param name="Format"></param>
/// <param name="Imported"></param>
/// <returns></returns>
public static System.IO.MemoryStream GenerateImage(byte[] Texture, int Mipcount, int Format, VTFXHandler.VTFXFile Imported)
{
System.IO.MemoryStream TextureStream = new System.IO.MemoryStream();
TextureStream.Write(Texture, 0, Texture.Length);
CSharpImageLibrary.ImageEngineFormat ParsedEnum = (CSharpImageLibrary.ImageEngineFormat)Enum.Parse(typeof(VTFGeneral.TEXTURE_FORMATS_INTEROP), Enum.GetName(typeof(VTFGeneral.TEXTURE_FORMATS), Format));
Console.WriteLine(ParsedEnum);
CSharpImageLibrary.Headers.DDS_Header newDDSHeader = new CSharpImageLibrary.Headers.DDS_Header(Mipcount, Imported.ImageHeight, Imported.ImageWidth, ParsedEnum, CSharpImageLibrary.Headers.DDS_Header.DXGI_FORMAT.DXGI_FORMAT_UNKNOWN);
byte[] DDSHeader = new byte[newDDSHeader.dwSize + 4];
newDDSHeader.WriteToArray(DDSHeader, 0);
byte[] RealTexture = new byte[DDSHeader.Length + Texture.Length];
Array.Copy(DDSHeader, 0, RealTexture, 0, DDSHeader.Length);
Array.Copy(Texture, 0, RealTexture, DDSHeader.Length, Texture.Length);
TextureStream.Flush();
TextureStream.Write(RealTexture, 0, RealTexture.Length);
CSharpImageLibrary.ImageEngineImage CSILImage = new CSharpImageLibrary.ImageEngineImage(RealTexture);
//Console.WriteLine(CSILImage.ToString());
CSharpImageLibrary.ImageFormats.ImageEngineFormatDetails DestinationDetails = new CSharpImageLibrary.ImageFormats.ImageEngineFormatDetails(CSharpImageLibrary.ImageEngineFormat.TIF);
bool AlphaRemovalFlag = !(VTFGeneral.HasAlpha(Format));
byte[] ConvertedToPNG = CSILImage.Save(DestinationDetails, CSharpImageLibrary.MipHandling.KeepTopOnly, 8192, 0, false); //show only the first mip, as this is just a preview
System.IO.MemoryStream PNGStream = new System.IO.MemoryStream(); //import our file into ram
PNGStream.Write(ConvertedToPNG, 0, ConvertedToPNG.Length);
return PNGStream;
}
/// <summary>
/// Converts and outputs texture data as a TIF file in a MemoryStream.
/// </summary>
/// <param name="Texture"></param>
/// <param name="Mipcount"></param>
/// <param name="Format"></param>
/// <param name="Imported"></param>
/// <returns></returns>
public static System.IO.MemoryStream GenerateImage(byte[] Texture, int Mipcount, int Format, Formats.VTFFile Imported)
{
System.IO.MemoryStream TextureStream = new System.IO.MemoryStream();
TextureStream.Write(Texture, 0, Texture.Length);
CSharpImageLibrary.ImageEngineFormat ParsedEnum = (CSharpImageLibrary.ImageEngineFormat)Enum.Parse(typeof(VTFGeneral.TEXTURE_FORMATS_INTEROP), Enum.GetName(typeof(VTFGeneral.TEXTURE_FORMATS), Format));
Console.WriteLine(ParsedEnum);
CSharpImageLibrary.Headers.DDS_Header newDDSHeader = new CSharpImageLibrary.Headers.DDS_Header(Mipcount, Imported.Height, Imported.Width, ParsedEnum, CSharpImageLibrary.Headers.DDS_Header.DXGI_FORMAT.DXGI_FORMAT_UNKNOWN);
byte[] DDSHeader = new byte[newDDSHeader.dwSize + 4];
newDDSHeader.WriteToArray(DDSHeader, 0);
byte[] RealTexture = new byte[DDSHeader.Length + Texture.Length];
Array.Copy(DDSHeader, 0, RealTexture, 0, DDSHeader.Length);
Array.Copy(Texture, 0, RealTexture, DDSHeader.Length, Texture.Length);
TextureStream.Flush();
TextureStream.Write(RealTexture, 0, RealTexture.Length);
CSharpImageLibrary.ImageEngineImage CSILImage = new CSharpImageLibrary.ImageEngineImage(RealTexture);
//Console.WriteLine(CSILImage.ToString());
CSharpImageLibrary.ImageFormats.ImageEngineFormatDetails DestinationDetails = new CSharpImageLibrary.ImageFormats.ImageEngineFormatDetails(CSharpImageLibrary.ImageEngineFormat.TIF);
bool AlphaRemovalFlag = !(VTFGeneral.HasAlpha(Format));
byte[] ConvertedToPNG = CSILImage.Save(DestinationDetails, CSharpImageLibrary.MipHandling.KeepTopOnly, 8192, 0, false); //show only the first mip, as this is just a preview
System.IO.MemoryStream PNGStream = new System.IO.MemoryStream(); //import our file into ram
PNGStream.Write(ConvertedToPNG, 0, ConvertedToPNG.Length);
return PNGStream;
}
}
}

231
VTFXUtil/MipMaker.cs Normal file
View file

@ -0,0 +1,231 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/*
HOLY FUCK
ALL OF THIS CODE ALMOST WORKED ON THE FIRST TRY
HOW THE FUCK
*/
namespace VTFXUtil
{
class MipMaker
{
readonly private static int[] OneByteFormats = { 5, 7, 8 };
readonly private static int[] TwoByteFormats = { 4, 6, 17, 18, 19, 21, 22 };
readonly private static int[] ThreeByteFormats = {2, 3, 9, 10};
readonly private static int[] FourByteFormats = { 0, 1, 11, 12, 16, 23, 26, 27 };
readonly private static int[] DXTFormats = { 13, 14, 15 };
public class MipMap
{
/// <summary>
/// Width of the current mip.
/// </summary>
public int Width;
/// <summary>
/// Height of the current mip.
/// </summary>
public int Height;
/// <summary>
/// Total number of bytes in the current mip.
/// </summary>
public int TotalBytes;
public MipMap(int w, int h, int tb)
{
Width = w;
Height = h;
TotalBytes = tb;
}
}
/// <summary>
/// Generates information on every possible mip within the current image.
/// </summary>
/// <param name="SrcWidth"></param>
/// <param name="SrcHeight"></param>
/// <param name="TexFormat"></param>
/// <returns></returns>
public static MipMap[] GenMipInfo(int SrcWidth, int SrcHeight, int TexFormat)
{
double ChunkMult = 1;
bool ImageIsTall = false;
bool ImageIsWide = false;
if (SrcWidth > SrcHeight)
{
ImageIsWide = true;
}
else if (SrcHeight > SrcWidth)
{
ImageIsTall = true;
}
List<MipMap> MipList = new List<MipMap>();
//begin chunknum estimation
if (TwoByteFormats.Contains(TexFormat))
{
ChunkMult = 2;
}
if (ThreeByteFormats.Contains(TexFormat))
{
ChunkMult = 3;
}
else if (FourByteFormats.Contains(TexFormat))
{
ChunkMult = 4;
}
else
{
if (DXTFormats.Contains(TexFormat))
{
if (TexFormat == (int)VTFGeneral.TEXTURE_FORMATS.IMAGE_FORMAT_DXT1)
{
ChunkMult = 0.25;
}
else
{
//ChunkMult = 0.5; //ignore trying to change values for these, as they do nothing but fuck up mip calculations
}
}
}
bool AttemptedPast1x1 = false;
double TempWidth = SrcWidth;
double TempHeight = SrcHeight;
while (!AttemptedPast1x1)
{
if (DXTFormats.Contains(TexFormat))
{
double CurrentMipSize;
if (TexFormat == (int)VTFGeneral.TEXTURE_FORMATS.IMAGE_FORMAT_DXT1)
{
double HorChunkNum = TempWidth * ChunkMult;
if (TempWidth < 4)
{
HorChunkNum = 4 * ChunkMult;
}
double VerChunkNum = TempHeight * ChunkMult;
if (TempHeight < 4)
{
VerChunkNum = 4 * ChunkMult;
}
double TotalChunkNum = HorChunkNum * VerChunkNum;
CurrentMipSize = TotalChunkNum * 8;
}
else
{
CurrentMipSize = TempWidth * TempHeight; //for some strange reason, DXT3 and DXT5's byte size for a single image somehow manages to be just the width multiplied by the height
//thinking about that actually makes sense, in a dumb way
//as each 4x4 chunk is 16 bytes
//so if you think about it like a dumbass, you could get a weird analogy of "hurr each 4 byte is like 1 lines of pixels"
if(CurrentMipSize < 16)
{
CurrentMipSize = 16; //has to be added here, because code would crash otherwise
}
}
Console.WriteLine(TempWidth + "x" + TempHeight + " | Chunk size: " + CurrentMipSize);
MipList.Add(new MipMap((int)TempWidth, (int)TempHeight, (int)CurrentMipSize));
}
else
{
double CurrentMipSizeNoMult = TempWidth * TempHeight;
double CurrentMipSize = CurrentMipSizeNoMult * ChunkMult;
MipList.Add(new MipMap((int)TempWidth, (int)TempHeight, (int)CurrentMipSize));
}
TempWidth *= .5;
TempHeight *= .5;
if (ImageIsTall)
{
if(TempWidth < 1)
{
TempWidth = 1;
}
if(TempHeight < 1)
{
AttemptedPast1x1 = true;
}
}
else if (ImageIsWide)
{
if(TempHeight < 1)
{
TempHeight = 1;
}
if(TempWidth < 1)
{
AttemptedPast1x1 = true;
}
}
else
{
if(TempWidth < 1 && TempHeight < 1)
{
AttemptedPast1x1 = true;
}
}
}
MipMap[] TheList = MipList.ToArray();
Array.Reverse(TheList); // miplist must be reversed, as VTF is a cursed format that has the mips backwards
return TheList;
}
/// <summary>
/// Checks to see if the current image is mipmapped.
/// </summary>
/// <param name="SrcWidth"></param>
/// <param name="SrcHeight"></param>
/// <param name="TexFormat"></param>
/// <param name="RealTexSize"></param>
/// <returns></returns>
public static bool IsMipped(int SrcWidth, int SrcHeight, int TexFormat, int RealTexSize)
{
double ChunkMult = 1;
double PixelCount = SrcWidth * SrcHeight;
double EstimatedSize;
if (TwoByteFormats.Contains(TexFormat))
{
ChunkMult = 2;
}
if (ThreeByteFormats.Contains(TexFormat))
{
ChunkMult = 3;
}
else if (FourByteFormats.Contains(TexFormat))
{
ChunkMult = 4;
}
else
{
if (DXTFormats.Contains(TexFormat))
{
if(TexFormat == (int)VTFGeneral.TEXTURE_FORMATS.IMAGE_FORMAT_DXT1)
{
ChunkMult = 0.5; // for some reason, setting this to 0.5 works for dxt1, but doing it in the actual mip detection code causes it to break
}
else
{
//ChunkMult = 0.5; // disregard, screws up mipinfo for non-mipped textures
}
}
}
EstimatedSize = PixelCount * ChunkMult;
if(RealTexSize > (int)EstimatedSize)
{
Console.WriteLine("We believe we can mipmap this. Real size: " + RealTexSize + " bytes.");
Console.WriteLine("Estimated size: " + EstimatedSize + " bytes.");
Console.WriteLine(RealTexSize + " > " + EstimatedSize);
return true;
}
else
{
return false;
}
}
}
}

22
VTFXUtil/Program.cs Normal file
View file

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace VTFXUtil
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

View file

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("VTFXUtil")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VTFXUtil")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ac6b703c-9018-4420-8ebb-e57e7a1d2562")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace VTFXUtil.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("VTFXUtil.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View file

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

26
VTFXUtil/Properties/Settings.Designer.cs generated Normal file
View file

@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace VTFXUtil.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

View file

@ -0,0 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles />
<Settings />
</SettingsFile>

243
VTFXUtil/VTFGeneral.cs Normal file
View file

@ -0,0 +1,243 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VTFXUtil
{
public class VTFGeneral
{
public struct VTFResource
{
public byte[] ResourceType;
public byte ResourceFlag;
public int Offset;
public VTFResource(byte[] Kind, byte Flag, int Off)
{
ResourceType = Kind;
ResourceFlag = Flag;
Offset = Off;
}
}
public static readonly string[] TexFmtStrArr = { "RGBA8888", "ABGR8888", "RGB888", "BGR888", "RGB565", "I8", "IA88", "P8", "A8", "RGB888 Bluescreen", "BGR888 Bluescreen", "ARGB8888", "BGRA8888", "DXT1", "DXT3", "DXT5", "BGRX8888", "BGR565", "BGRX5551", "BGRA4444", "DXT1 One Bit Alpha", "BGRA5551", "UV88", "UVWQ8888", "RGBA16161616F", "RGBA16161616", "UVLX8888", "R32F", "RGB323232F", "RGBA32323232F", "NVIDIA DST16", "NVIDIA DST24", "NVIDIA INTZ", "NVIDIA RAWZ", "ATI DST16", "ATI DST24", "NVIDIA NULL", "ATI1N", "ATI2N", "Xbox 360 DST16", "Xbox 360 DST24", "Xbox 360 DST24F", "Linear BGRX8888", "Linear RGBA8888", "Linear ABGR8888", "Linear ARGB8888", "Linear BGRA8888", "Linear RGB888", "Linear BGR888", "Linear BGRX5551", "Linear I8", "Linear RGBA16161616", "LE BGRX8888", "LE BGRA8888" };
public static readonly Dictionary<uint, string> VTFFlags = new Dictionary<uint, string>() { { 0x1, "Point Sample" }, { 0x2, "Trilinear" }, { 0x4, "Clamp S" }, { 0x8, "Clamp T" }, { 0x10, "Anisotropic" }, { 0x20, "Hint DXT5" }, { 0x40, "PWL Corrected" }, { 0x80, "Normal Map" }, { 0x100, "No Mipmap" }, { 0x200, "No Level of Detail" }, { 0x400, "All Mipmaps" }, { 0x800, "All Procedural" }, { 0x1000, "One Bit Alpha" }, { 0x2000, "Eight Bit Alpha" }, { 0x4000, "Environment Map" }, { 0x8000, "Rendertarget" }, { 0x10000, "Depth Rendertarget" }, { 0x20000, "No Debug Override" }, { 0x40000, "Single Copy" }, { 0x80000, "Pre sRGB" }, { 0x100000, "Unused" }, { 0x200000, "Unused" }, { 0x400000, "Unused" }, { 0x800000, "No Depth Buffer" }, { 0x1000000, "Unused" }, { 0x2000000, "Clamp U" }, { 0x4000000, "Vertex Texture" }, { 0x8000000, "SS Bump" }, { 0x10000000, "Unused" }, { 0x20000000, "Border" }, { 0x40000000, "Unused" }, { 0x80000000, "Unused" } };
// enum list below is from the Source SDK's imageformat.h "/sp/src/public/bitmap/imageformat.h" https://github.com/ValveSoftware/source-sdk-2013
public enum TEXTURE_FORMATS
{
IMAGE_FORMAT_RGBA8888,
IMAGE_FORMAT_ABGR8888,
IMAGE_FORMAT_RGB888,
IMAGE_FORMAT_BGR888,
IMAGE_FORMAT_RGB565,
IMAGE_FORMAT_I8,
IMAGE_FORMAT_IA88,
IMAGE_FORMAT_P8,
IMAGE_FORMAT_A8,
IMAGE_FORMAT_RGB888_BLUESCREEN,
IMAGE_FORMAT_BGR888_BLUESCREEN,
IMAGE_FORMAT_ARGB8888,
IMAGE_FORMAT_BGRA8888,
IMAGE_FORMAT_DXT1,
IMAGE_FORMAT_DXT3,
IMAGE_FORMAT_DXT5,
IMAGE_FORMAT_BGRX8888,
IMAGE_FORMAT_BGR565,
IMAGE_FORMAT_BGRX5551,
IMAGE_FORMAT_BGRA4444,
IMAGE_FORMAT_DXT1_ONEBITALPHA,
IMAGE_FORMAT_BGRA5551,
IMAGE_FORMAT_UV88,
IMAGE_FORMAT_UVWQ8888,
IMAGE_FORMAT_RGBA16161616F,
IMAGE_FORMAT_RGBA16161616,
IMAGE_FORMAT_UVLX8888,
IMAGE_FORMAT_R32F,
IMAGE_FORMAT_RGB323232F,
IMAGE_FORMAT_RGBA32323232F,
IMAGE_FORMAT_NV_DST16,
IMAGE_FORMAT_NV_DST24,
IMAGE_FORMAT_NV_INTZ,
IMAGE_FORMAT_NV_RAWZ,
IMAGE_FORMAT_ATI_DST16,
IMAGE_FORMAT_ATI_DST24,
IMAGE_FORMAT_NV_NULL,
IMAGE_FORMAT_ATI1N,
IMAGE_FORMAT_ATI2N,
IMAGE_FORMAT_X360_DST16,
IMAGE_FORMAT_X360_DST24,
IMAGE_FORMAT_X360_DST24F,
IMAGE_FORMAT_LINEAR_BGRX8888,
IMAGE_FORMAT_LINEAR_RGBA8888,
IMAGE_FORMAT_LINEAR_ABGR8888,
IMAGE_FORMAT_LINEAR_ARGB8888,
IMAGE_FORMAT_LINEAR_BGRA8888,
IMAGE_FORMAT_LINEAR_RGB888,
IMAGE_FORMAT_LINEAR_BGR888,
IMAGE_FORMAT_LINEAR_BGRX5551,
IMAGE_FORMAT_LINEAR_I8,
IMAGE_FORMAT_LINEAR_RGBA16161616,
IMAGE_FORMAT_LE_BGRX8888,
IMAGE_FORMAT_LE_BGRA8888
}
private static readonly byte[] LRImgBytes = { 0x1, 0x0, 0x0 };
private static readonly byte[] HRImgBytes = { 0x30, 0x0, 0x0 };
private static readonly byte[] PSDatBytes = { 0x10, 0x0, 0x0 };
private static readonly byte[] CRCBytes = { 0x43, 0x52, 0x43 };
private static readonly byte[] LODBytes = { 0x4c, 0x4f, 0x44 };
private static readonly byte[] ExtVTFFlagsBytes = { 0x54, 0x53, 0x4f };
private static readonly byte[] ArbKVFlags = { 0x4b, 0x56, 0x44 };
public static readonly Dictionary<string, string> ResourceTypes = new Dictionary<string, string>() { { Encoding.UTF8.GetString(LRImgBytes), "Low Resolution Image Data" }, { Encoding.UTF8.GetString(HRImgBytes), "High Resolution Image Data" }, { Encoding.UTF8.GetString(PSDatBytes), "Particle Sheet Data" }, { Encoding.UTF8.GetString(CRCBytes), "File CRC" }, { Encoding.UTF8.GetString(LODBytes), "Texture LOD Information" }, { Encoding.UTF8.GetString(ExtVTFFlagsBytes), "Extended VTF Flags" }, { Encoding.UTF8.GetString(ArbKVFlags), "Arbitrary KeyValue Flags" } };
public static string GetResourceType(byte[] ByteArray)
{
return ResourceTypes[Encoding.UTF8.GetString(ByteArray)];
}
/// <summary>
/// Determines if the specified format has an alpha channel.
/// </summary>
/// <param name="Format"></param>
/// <returns></returns>
public static bool HasAlpha(int Format)
{
string[] ValidAlphaFormats = { "RGBA8888", "ABGR8888", null, null, null, null, "IA88", null, "A8", null, null, "ARGB8888", "BGRA8888", null, "DXT3", "DXT5", "BGRX8888", null, "BGRX5551", "BGRA4444", "DXT1 One Bit Alpha", "BGRA5551", null, null, "RGBA16161616F", "RGBA16161616", null, null, null, "RGBA32323232F", null, null, null, null, null, null, null, null, null, null, null, null, "Linear BGRX8888", "Linear RGBA8888", "Linear ABGR8888", "Linear ARGB8888", "Linear BGRA8888", null, null, "Linear BGRX5551", null, "Linear RGBA16161616", "LE BGRX8888", "LE BGRA8888" };
if (ValidAlphaFormats[Format] != null)
{
return true;
}
return false;
}
public class VTFFormatProps
{
public int Format;
public bool IsInCSIL;
public bool IsInTIN;
public int bpp;
public bool IsCompressed;
public bool IsCurrentlySupported;
public int ColorByteAmount;
public VTFFormatProps()
{
Format = -1;
IsInCSIL = false;
IsInTIN = false;
bpp = 0;
IsCompressed = false;
IsCurrentlySupported = false;
ColorByteAmount = 0;
}
public VTFFormatProps(int format, bool SupportsCSIL, bool SupportsTIN, int BPP, bool Compressed, bool CurrentlySupported, int ColBytes)
{
Format = format;
IsInCSIL = SupportsCSIL;
IsInTIN = SupportsTIN;
bpp = BPP;
IsCompressed = Compressed;
IsCurrentlySupported = CurrentlySupported;
ColorByteAmount = ColBytes;
}
}
public static readonly VTFFormatProps[] FormatTable =
{
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_RGBA8888, true, true, 32, false, true, 4),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_ABGR8888, true, true, 32, false, true, 4),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_RGB888, true, true, 24, false, true, 3),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_BGR888, true, true, 24, false, true, 3),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_RGB565, true, true, 16, false, true, 2),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_I8, false, false, 8, false, true, 1),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_IA88, false, false, 16, false, true, 2),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_P8, false, false, 8, false, true, 1),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_A8, true, false, 8, false, true, 1),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_RGB888_BLUESCREEN, true, false, 24, false, true, 3),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_BGR888_BLUESCREEN, true, false, 24, false, true, 3),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_ARGB8888, true, false, 32, false, true, 4),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_BGRA8888, true, false, 32, false, true, 4),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_DXT1, true, false, 4, true, true, 4), //define color bits as negative for compressed textures, so program can ignore it, dxt1 has a fit so it needs to be defined
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_DXT3, true, false, 8, true, true, -1),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_DXT5, true, false, 8, true, true, -1),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_BGRX8888, true, false, 32, false, true, 4),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_BGR565, true, true, 16, false, true, 3),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_BGRX5551, true, true, 16, false, true, 4),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_BGRA4444, true, true, 16, false, true, 4),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_DXT1_ONEBITALPHA, false, true, 4, true, true, -1),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_BGRA5551, false, true, 16, false, true, 4),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_UV88, true, false, 16, false, true, 2),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_UVWQ8888, false, false, 32, false, false, 4),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_RGBA16161616F, true, false, 64, false, true, 8),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_RGBA16161616, true, false, 64, false, true, 8),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_UVLX8888, false, false, 32, false, false, 4),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_R32F, false, false, 32, false, false, 4),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_RGB323232F, true, false, 96, false, true, 12),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_RGBA32323232F, true, false, 128, false, true, 16),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_NV_DST16, false, false, 16, false, false, 2),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_NV_DST24, false, false, 24, false, false, 3),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_NV_INTZ, false, false, 32, false, false, 4),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_NV_RAWZ, false, false, 32, false, false, 4),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_ATI_DST16, false, false, 16, false, false, 2),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_ATI_DST24, false, false, 24, false, false, 3),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_NV_NULL, false, false, 32, false, false, 4),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_ATI1N, true, false, 4, true, true, -1),
new VTFFormatProps((int) TEXTURE_FORMATS.IMAGE_FORMAT_ATI2N, true, false, 8, true, true, -1),
};
public enum TEXTURE_FORMATS_INTEROP
{
IMAGE_FORMAT_RGBA8888 = CSharpImageLibrary.ImageEngineFormat.DDS_ARGB_8, //move rgb values down, alpha to end
IMAGE_FORMAT_ABGR8888 = CSharpImageLibrary.ImageEngineFormat.DDS_ABGR_8,
IMAGE_FORMAT_RGB888 = CSharpImageLibrary.ImageEngineFormat.DDS_RGB_8,
IMAGE_FORMAT_BGR888 = CSharpImageLibrary.ImageEngineFormat.DDS_RGB_8, //reverse color order
IMAGE_FORMAT_RGB565 = CSharpImageLibrary.ImageEngineFormat.DDS_R5G6B5,
IMAGE_FORMAT_I8 = CSharpImageLibrary.ImageEngineFormat.Unknown, //will reparse unknowns later in code
IMAGE_FORMAT_IA88 = CSharpImageLibrary.ImageEngineFormat.Unknown,
IMAGE_FORMAT_P8 = CSharpImageLibrary.ImageEngineFormat.Unknown,
IMAGE_FORMAT_A8 = CSharpImageLibrary.ImageEngineFormat.DDS_A8,
IMAGE_FORMAT_RGB888_BLUESCREEN = CSharpImageLibrary.ImageEngineFormat.DDS_RGB_8,
IMAGE_FORMAT_BGR888_BLUESCREEN = CSharpImageLibrary.ImageEngineFormat.DDS_RGB_8, //reverse these too!!
IMAGE_FORMAT_ARGB8888 = CSharpImageLibrary.ImageEngineFormat.DDS_ARGB_8,
IMAGE_FORMAT_BGRA8888 = CSharpImageLibrary.ImageEngineFormat.DDS_ARGB_8, // reverse!!
IMAGE_FORMAT_DXT1 = CSharpImageLibrary.ImageEngineFormat.DDS_DXT1,
IMAGE_FORMAT_DXT3 = CSharpImageLibrary.ImageEngineFormat.DDS_DXT3,
IMAGE_FORMAT_DXT5 = CSharpImageLibrary.ImageEngineFormat.DDS_DXT5,
IMAGE_FORMAT_BGRX8888 = CSharpImageLibrary.ImageEngineFormat.DDS_ARGB_8, //reverse!!
IMAGE_FORMAT_BGR565 = CSharpImageLibrary.ImageEngineFormat.DDS_R5G6B5, //reverse!!
IMAGE_FORMAT_BGRX5551 = CSharpImageLibrary.ImageEngineFormat.DDS_CUSTOM, //will need to possibly redefine!!!
IMAGE_FORMAT_BGRA4444 = CSharpImageLibrary.ImageEngineFormat.DDS_ARGB_4, //reverse!!
IMAGE_FORMAT_DXT1_ONEBITALPHA = TeximpNet.Compression.CompressionFormat.DXT1a, //no idea if CSharpImageLibrary has this
IMAGE_FORMAT_BGRA5551 = TeximpNet.Compression.CompressionFormat.BGRA,
IMAGE_FORMAT_UV88 = CSharpImageLibrary.ImageEngineFormat.DDS_V8U8, //reverse these!!
IMAGE_FORMAT_UVWQ8888,
IMAGE_FORMAT_RGBA16161616F = CSharpImageLibrary.ImageEngineFormat.DDS_CUSTOM, //possible define
IMAGE_FORMAT_RGBA16161616 = CSharpImageLibrary.ImageEngineFormat.DDS_CUSTOM,
IMAGE_FORMAT_UVLX8888,
IMAGE_FORMAT_R32F,
IMAGE_FORMAT_RGB323232F = CSharpImageLibrary.ImageEngineFormat.DDS_CUSTOM,
IMAGE_FORMAT_RGBA32323232F = CSharpImageLibrary.ImageEngineFormat.DDS_CUSTOM,
IMAGE_FORMAT_NV_DST16,
IMAGE_FORMAT_NV_DST24,
IMAGE_FORMAT_NV_INTZ,
IMAGE_FORMAT_NV_RAWZ,
IMAGE_FORMAT_ATI_DST16,
IMAGE_FORMAT_ATI_DST24,
IMAGE_FORMAT_NV_NULL,
IMAGE_FORMAT_ATI1N = CSharpImageLibrary.ImageEngineFormat.DDS_ATI1,
IMAGE_FORMAT_ATI2N = CSharpImageLibrary.ImageEngineFormat.DDS_ATI2_3Dc,
IMAGE_FORMAT_X360_DST16,
IMAGE_FORMAT_X360_DST24,
IMAGE_FORMAT_X360_DST24F,
IMAGE_FORMAT_LINEAR_BGRX8888,
IMAGE_FORMAT_LINEAR_RGBA8888,
IMAGE_FORMAT_LINEAR_ABGR8888,
IMAGE_FORMAT_LINEAR_ARGB8888,
IMAGE_FORMAT_LINEAR_BGRA8888,
IMAGE_FORMAT_LINEAR_RGB888,
IMAGE_FORMAT_LINEAR_BGR888,
IMAGE_FORMAT_LINEAR_BGRX5551,
IMAGE_FORMAT_LINEAR_I8,
IMAGE_FORMAT_LINEAR_RGBA16161616,
IMAGE_FORMAT_LE_BGRX8888,
IMAGE_FORMAT_LE_BGRA8888
}
}
}

323
VTFXUtil/VTFXHandler.cs Normal file
View file

@ -0,0 +1,323 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace VTFXUtil
{
class VTFXHandler
{
readonly private static string FileMagicVTFX = "VTFX";
public static readonly byte[] VTFXMagicByte = { 0x56, 0x54, 0x46, 0x58 };
/// <summary>
/// Represents a VTFX file.
/// </summary>
public class VTFXFile
{
public string FileMagic; //VTFX
public byte[] VersionNum = new byte[8]; // major version is 0x00000360 for Xbox 360 files, 0x00000333 for PS3 files, minor version always 0x00000008
public int HeaderSize; //usually 0x44 or 68 in base 10
public byte[] VTFFlags = new byte[4]; //same as standard VTF, endianswapped
public int ImageWidth; //ditto
public int ImageHeight; //ditto
public int BitDepth; // this is incorrectly named, this is actually for how much depth a volume texture has
public int FrameCount; // oh come on its obvious
public int PreloadSize; //the size of the preload chunk that exists in __preload_section.pre for this texture
public int MipSkipCount; // basically used for forced texture quality reduction
public int ResourceCount; //same as normal VTF, also needs endianswapping
public byte[] ReflectivityVec = new byte[12]; //ditto
public float BumpScale; //ditto
public byte[] TextureFormat = new byte[4]; //ditto
public byte[] LowResSamplingAmt = new byte[4]; // also misnamed by me, turns out this is for doing light sampling with VRAD
public int CompressedSize; //exact size of the texture data itself once compressed, PS3 files will have this section zeroed out, due to textures being compressed outside of the file
public Dictionary<byte[], int> Resources; //contains resource data
public byte[] FileData; //data contained in the file
}
/// <summary>
/// Returns an imported VTFX file from a path.
/// </summary>
/// <param name="PathToFile"></param>
/// <returns></returns>
public static VTFXFile ImportVTFX(string PathToFile) // why did i make this import from a fucking file path
{
if (PathToFile.Equals(""))
{
return null;
}
System.IO.FileStream ImportFile = new System.IO.FileStream(PathToFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] TempAll = System.IO.File.ReadAllBytes(PathToFile);
byte[] HeaderLenArr = new byte[4];
//Array.Copy(TempAll, 0xc, HeaderLenArr, 0, 4);
HeaderLenArr[3] = 0x44;
Array.Reverse(HeaderLenArr);
int BufferLen = System.BitConverter.ToInt32(HeaderLenArr, 0);
byte[] Header = new byte[BufferLen];
using (ImportFile)
{
ImportFile.Read(Header, 0, BufferLen);
}
byte[] FileMagicBytes = new byte[4];
Array.Copy(Header, 0, FileMagicBytes, 0, 4);
//Console.WriteLine(FileMagic);
if (FileMagicBytes.SequenceEqual(VTFXMagicByte))
{
string FileMagic = System.Text.Encoding.UTF8.GetString(Header).Substring(0, 4);
VTFXFile InMem = new VTFXFile();
InMem.FileMagic = FileMagic;
Array.Copy(Header, 4, InMem.VersionNum, 0, 8);
byte[] TempLen = new byte[4];
Array.Copy(Header, 12, TempLen, 0, 4);
Array.Reverse(TempLen); // yay endianswapping
InMem.HeaderSize = System.BitConverter.ToInt32(TempLen, 0);
byte[] TempVTFFlags = new byte[4];
Array.Copy(Header, 16, TempVTFFlags, 0, 4);
Array.Reverse(TempVTFFlags);
InMem.VTFFlags = TempVTFFlags;
byte[] TempWidth = new byte[2];
Array.Copy(Header, 20, TempWidth, 0, 2);
Array.Reverse(TempWidth);
InMem.ImageWidth = System.BitConverter.ToInt16(TempWidth, 0);
byte[] TempHeight = new byte[2];
Array.Copy(Header, 22, TempHeight, 0, 2);
Array.Reverse(TempHeight);
InMem.ImageHeight = System.BitConverter.ToInt16(TempHeight, 0);
byte[] TempDepth = new byte[2];
Array.Copy(Header, 24, TempDepth, 0, 2);
Array.Reverse(TempDepth);
InMem.BitDepth = System.BitConverter.ToInt16(TempDepth, 0);
byte[] TempFC = new byte[2];
Array.Copy(Header, 25, TempFC, 0, 2);
InMem.FrameCount = System.BitConverter.ToInt16(TempFC, 0);
byte[] TempPreload = new byte[2];
Array.Copy(Header, 28, TempPreload, 0, 2);
Array.Reverse(TempPreload);
InMem.PreloadSize = System.BitConverter.ToInt16(TempPreload, 0);
byte TempMip = Header[30];
InMem.MipSkipCount = Convert.ToSByte(TempMip);
InMem.ResourceCount = Convert.ToSByte(Header[31]);
byte[] TempVec = new byte[12];
byte[] Vec1 = new byte[4];
Array.Copy(Header, 32, Vec1, 0, 4);
byte[] Vec2 = new byte[4];
Array.Copy(Header, 36, Vec2, 0, 4);
byte[] Vec3 = new byte[4];
Array.Copy(Header, 40, Vec3, 0, 4);
Array.Reverse(Vec1);
Array.Reverse(Vec2);
Array.Reverse(Vec3);
Array.Copy(Vec1, 0, TempVec, 0, 4);
Array.Copy(Vec2, 0, TempVec, 4, 4);
Array.Copy(Vec3, 0, TempVec, 8, 4);
InMem.ReflectivityVec = TempVec;
byte[] TempBump = new byte[4];
Array.Copy(Header, 44, TempBump, 0, 4);
Array.Reverse(TempBump);
InMem.BumpScale = System.BitConverter.ToSingle(TempBump, 0);
Array.Copy(Header, 48, InMem.TextureFormat, 0, 4);
Array.Reverse(InMem.TextureFormat);
Array.Copy(Header, 52, InMem.LowResSamplingAmt, 0, 4);
byte[] TempCompSize = new byte[4];
Array.Copy(Header, 56, TempCompSize, 0, 4);
Array.Reverse(TempCompSize);
InMem.CompressedSize = System.BitConverter.ToInt32(TempCompSize, 0);
InMem.Resources = ParseResourceInfo(InMem, PathToFile);
InMem.FileData = new byte[TempAll.Length - InMem.HeaderSize];
Array.Copy(TempAll, InMem.HeaderSize, InMem.FileData, 0, TempAll.Length - InMem.HeaderSize);
GC.Collect();
return InMem;
}
else
{
MessageBox.Show("Specified file was not in the VTFX format.");
return null;
}
}
/// <summary>
/// Returns a VTFX file from the given MemoryStream.
/// </summary>
/// <param name="ImportFile"></param>
/// <returns></returns>
public static VTFXFile ImportVTFX(System.IO.MemoryStream ImportFile) // this is better, but the way i handled this is fucking terrible
{
byte[] TempAll = ImportFile.ToArray();
byte[] HeaderLenArr = new byte[4];
Array.Copy(TempAll, 0xc, HeaderLenArr, 0, 4);
Array.Reverse(HeaderLenArr);
int BufferLen = System.BitConverter.ToInt32(HeaderLenArr, 0);
byte[] Header = new byte[BufferLen];
using (ImportFile)
{
ImportFile.Read(Header, 0, BufferLen);
}
string FileMagic = System.Text.Encoding.UTF8.GetString(Header).Substring(0, 4);
Console.WriteLine(FileMagic);
if (FileMagic.Equals(FileMagicVTFX))
{
VTFXFile InMem = new VTFXFile();
InMem.FileMagic = FileMagic;
Array.Copy(Header, 4, InMem.VersionNum, 0, 8);
byte[] TempLen = new byte[4];
Array.Copy(Header, 12, TempLen, 0, 4);
Array.Reverse(TempLen); // yay endianswapping
InMem.HeaderSize = System.BitConverter.ToInt32(TempLen, 0);
byte[] TempVTFFlags = new byte[4];
Array.Copy(Header, 16, TempVTFFlags, 0, 4);
Array.Reverse(TempVTFFlags);
InMem.VTFFlags = TempVTFFlags;
byte[] TempWidth = new byte[2];
Array.Copy(Header, 20, TempWidth, 0, 2);
Array.Reverse(TempWidth);
InMem.ImageWidth = System.BitConverter.ToInt16(TempWidth, 0);
byte[] TempHeight = new byte[2];
Array.Copy(Header, 22, TempHeight, 0, 2);
Array.Reverse(TempHeight);
InMem.ImageHeight = System.BitConverter.ToInt16(TempHeight, 0);
byte[] TempDepth = new byte[2];
Array.Copy(Header, 24, TempDepth, 0, 2);
Array.Reverse(TempDepth);
InMem.BitDepth = System.BitConverter.ToInt16(TempDepth, 0);
byte[] TempFC = new byte[2];
Array.Copy(Header, 25, TempFC, 0, 2);
InMem.FrameCount = System.BitConverter.ToInt16(TempFC, 0);
byte[] TempPreload = new byte[2];
Array.Copy(Header, 28, TempPreload, 0, 2);
Array.Reverse(TempPreload);
InMem.PreloadSize = System.BitConverter.ToInt16(TempPreload, 0);
byte TempMip = Header[30];
InMem.MipSkipCount = Convert.ToSByte(TempMip);
InMem.ResourceCount = Convert.ToSByte(Header[31]);
byte[] TempVec = new byte[12];
byte[] Vec1 = new byte[4];
Array.Copy(Header, 32, Vec1, 0, 4);
byte[] Vec2 = new byte[4];
Array.Copy(Header, 36, Vec2, 0, 4);
byte[] Vec3 = new byte[4];
Array.Copy(Header, 40, Vec3, 0, 4);
Array.Reverse(Vec1);
Array.Reverse(Vec2);
Array.Reverse(Vec3);
Array.Copy(Vec1, 0, TempVec, 0, 4);
Array.Copy(Vec2, 0, TempVec, 4, 4);
Array.Copy(Vec3, 0, TempVec, 8, 4);
InMem.ReflectivityVec = TempVec;
byte[] TempBump = new byte[4];
Array.Copy(Header, 44, TempBump, 0, 4);
Array.Reverse(TempBump);
InMem.BumpScale = System.BitConverter.ToSingle(TempBump, 0);
Array.Copy(Header, 48, InMem.TextureFormat, 0, 4);
Array.Reverse(InMem.TextureFormat);
Array.Copy(Header, 52, InMem.LowResSamplingAmt, 0, 4);
byte[] TempCompSize = new byte[4];
Array.Copy(Header, 56, TempCompSize, 0, 4);
Array.Reverse(TempCompSize);
InMem.CompressedSize = System.BitConverter.ToInt32(TempCompSize, 0);
InMem.Resources = ParseResourceInfo(InMem, ImportFile);
InMem.FileData = new byte[TempAll.Length - InMem.HeaderSize];
Array.Copy(TempAll, InMem.HeaderSize, InMem.FileData, 0, TempAll.Length - InMem.HeaderSize);
GC.Collect();
return InMem;
}
else
{
MessageBox.Show("Specified file was not in the VTFX format.\nMagic expected was \"VTFX\", magic returned was {0}", FileMagic);
return new VTFXFile();
}
}
public static VTFXFile ConvertVTFToVTFX(Formats.VTFFile Input, byte[] TextureData, byte[] Platform, byte[] ColorSamplingBytes)
{
//byte[] FourBytePadding = { 0x00, 0x00, 0x00, 0x00 };
Dictionary<byte[], int> VTFXResources = new Dictionary<byte[], int>();
foreach(var Resource in Input.Resources)
{
VTFXResources.Add(Resource.ResourceType, Resource.Offset);
}
VTFXFile Amalgamation = new VTFXFile
{
BitDepth = Input.ImageDepth,
BumpScale = Input.BumpScale,
// do some stuff with an if statement here for PS3 files, they don't compress anything
FileData = TextureData,
FileMagic = "VTFX", // i shouldn't have made this property for the VTFXFile object
FrameCount = Input.Frames,
HeaderSize = 0x44,
ImageHeight = Input.Height,
ImageWidth = Input.Width,
LowResSamplingAmt = ColorSamplingBytes, // this is apparently for color sampling, so i need to go and do some code refactors
MipSkipCount = 0, // basically just a built in texture quality setting, and i had no idea that something like this was even a thing
PreloadSize = 0, // make this zero, as i don't understand the format of __preload_section.pre, i hope to fuck this works
ReflectivityVec = Input.ReflectivityVector,
ResourceCount = 1,
Resources = VTFXResources,
TextureFormat = Input.Format,
VTFFlags = Input.Flags,
VersionNum = Platform
};
if (Platform.SequenceEqual(Form1.XBoxBytes))
{
Array.Copy(Form1.XBoxBytes, 0, Amalgamation.VersionNum, 0, 4);
}
else if (Platform.SequenceEqual(Form1.PS3Bytes))
{
Array.Copy(Form1.PS3Bytes, 0, Amalgamation.VersionNum, 0, 4);
}
//Amalgamation.VersionNum[7] = 0x08;
return Amalgamation;
}
public static Dictionary<byte[], int> ParseResourceInfo(VTFXFile File, string PathToFile)
{
int ResourceBuffer = 8;
System.IO.FileStream ImportFile = new System.IO.FileStream(PathToFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] Temp = new byte[File.HeaderSize];
byte[] Header = new byte[File.HeaderSize - 0x3c];
using (ImportFile)
{
ImportFile.Read(Temp, 0, File.HeaderSize);
}
Array.Copy(Temp, 0x3c, Header, 0, File.HeaderSize - 0x3c);
Dictionary<byte[], int> Resources = new Dictionary<byte[], int>();
for(int i = 0; i < File.ResourceCount; i++)
{
byte[] ResType = new byte[3];
byte[] OffsetArray = new byte[4];
Array.Copy(Header, ResourceBuffer * i, ResType, 0, 3);
Array.Copy(Header, ResourceBuffer * i + 4, OffsetArray, 0, 4);
Array.Reverse(OffsetArray);
Console.WriteLine(System.BitConverter.ToInt32(OffsetArray, 0));
Resources.Add(ResType, (int)System.BitConverter.ToInt32(OffsetArray, 0));
}
return Resources;
}
public static Dictionary<byte[], int> ParseResourceInfo(VTFXFile File, System.IO.MemoryStream ImportFile)
{
int ResourceBuffer = 8;
byte[] Temp = new byte[File.HeaderSize];
byte[] Header = new byte[File.HeaderSize - 0x3c];
using (ImportFile)
{
ImportFile.Read(Temp, 0, File.HeaderSize);
}
Array.Copy(Temp, 0x3c, Header, 0, File.HeaderSize - 0x3c);
Dictionary<byte[], int> Resources = new Dictionary<byte[], int>();
for (int i = 0; i < File.ResourceCount; i++)
{
byte[] ResType = new byte[3];
byte[] OffsetArray = new byte[4];
Array.Copy(Header, ResourceBuffer * i, ResType, 0, 3);
Array.Copy(Header, ResourceBuffer * i + 4, OffsetArray, 0, 4);
Array.Reverse(OffsetArray);
Console.WriteLine(System.BitConverter.ToInt32(OffsetArray, 0));
Resources.Add(ResType, (int)System.BitConverter.ToInt32(OffsetArray, 0));
}
return Resources;
}
}
}

144
VTFXUtil/VTFXUtil.csproj Normal file
View file

@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AC6B703C-9018-4420-8EBB-E57E7A1D2562}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>VTFXUtil</RootNamespace>
<AssemblyName>VTFXUtil</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>vtfxedit_icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="CSharpImageLibrary, Version=4.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CSharpImageLibrary.4.2.0\lib\net462\CSharpImageLibrary.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IO.RecyclableMemoryStream, Version=1.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IO.RecyclableMemoryStream.1.4.0\lib\net46\Microsoft.IO.RecyclableMemoryStream.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="SevenZip, Version=19.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\LZMA-SDK.19.0.0\lib\net20\SevenZip.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Dataflow, Version=4.5.24.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="TeximpNet, Version=1.4.3.0, Culture=neutral, PublicKeyToken=978ca55aa4aa29a3, processorArchitecture=MSIL">
<HintPath>..\packages\TeximpNet.1.4.3\lib\net40\TeximpNet.dll</HintPath>
</Reference>
<Reference Include="UsefulThings, Version=1.7.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UsefulCSharpThings.1.7.3\lib\net462\UsefulThings.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Form2.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form2.Designer.cs">
<DependentUpon>Form2.cs</DependentUpon>
</Compile>
<Compile Include="Formats.cs" />
<Compile Include="ImageImporter.cs" />
<Compile Include="ImageImportProperties.cs" />
<Compile Include="MipMaker.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="VTFGeneral.cs" />
<Compile Include="VTFXHandler.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Form2.resx">
<DependentUpon>Form2.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="vtfxedit_icon.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\TeximpNet.1.4.3\build\TeximpNet.targets" Condition="Exists('..\packages\TeximpNet.1.4.3\build\TeximpNet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\TeximpNet.1.4.3\build\TeximpNet.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\TeximpNet.1.4.3\build\TeximpNet.targets'))" />
</Target>
</Project>

11
VTFXUtil/packages.config Normal file
View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CSharpImageLibrary" version="4.2.0" targetFramework="net462" />
<package id="LZMA-SDK" version="19.0.0" targetFramework="net462" />
<package id="Microsoft.IO.RecyclableMemoryStream" version="1.4.0" targetFramework="net462" />
<package id="Microsoft.Tpl.Dataflow" version="4.5.24" targetFramework="net462" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net462" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net462" />
<package id="TeximpNet" version="1.4.3" targetFramework="net461" />
<package id="UsefulCSharpThings" version="1.7.3" targetFramework="net462" />
</packages>

BIN
VTFXUtil/vtfxedit_icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB