Skip to content

Commit

Permalink
Fix mToolProps writing for other formats
Browse files Browse the repository at this point in the history
  • Loading branch information
iMrShadow committed Mar 20, 2024
1 parent 475124a commit 0a182dd
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ public void WriteBinaryData(BinaryWriter writer)
writer.Write(mImportName_BlockSize); //mImportName Block Size [4 bytes] //mImportName block size (size + string len)
ByteFunctions.WriteString(writer, mImportName); //mImportName [x bytes] (this is always 0)
writer.Write(mImportScale); //mImportScale [4 bytes]
//writer.Write(mToolProps.mbHasProps); //mToolProps mbHasProps [1 byte]
writer.Write('0');
ByteFunctions.WriteBoolean(writer, mToolProps.mbHasProps); //mToolProps mbHasProps [1 byte]
writer.Write(mNumMipLevels); //mNumMipLevels [4 bytes]
writer.Write(mWidth); //mWidth [4 bytes]
writer.Write(mHeight); //mHeight [4 bytes]
Expand All @@ -354,7 +353,6 @@ public void WriteBinaryData(BinaryWriter writer)

int padding = 0;
writer.Write(padding); //extra padding [4 bytes]

writer.Write(mNormalMapFormat); //mNormalMapFormat [4 bytes]
writer.Write(mHDRLightmapScale); //mHDRLightmapScale [4 bytes]
writer.Write(mToonGradientCutoff); //mToonGradientCutoff [4 bytes]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using D3DTX_Converter.Utilities;
using D3DTX_Converter.DirectX;
using D3DTX_Converter.Main;
using System.Runtime.InteropServices;

/*
* NOTE:
Expand Down Expand Up @@ -338,7 +339,7 @@ public void WriteBinaryData(BinaryWriter writer)
ByteFunctions.WriteString(writer, mImportName); //mImportName [x bytes] (this is always 0)
writer.Write(mImportScale); //mImportScale [4 bytes]
writer.Write(Unknown0); //Unknown0 [4 bytes]
writer.Write(mToolProps.mbHasProps); //mToolProps mbHasProps [1 byte]
ByteFunctions.WriteBoolean(writer, mToolProps.mbHasProps); //mToolProps mbHasProps [1 byte]
writer.Write(mNumMipLevels); //mNumMipLevels [4 bytes]
writer.Write(mWidth); //mWidth [4 bytes]
writer.Write(mHeight); //mHeight [4 bytes]
Expand Down Expand Up @@ -388,6 +389,73 @@ public void WriteBinaryData(BinaryWriter writer)
}
}

public uint GetHeaderByteSize()
{
uint totalSize = 0;

totalSize += (uint)Marshal.SizeOf(mVersion); //mVersion [4 bytes]
totalSize += (uint)Marshal.SizeOf(mSamplerState_BlockSize); //mSamplerState Block Size [4 bytes]
totalSize += mSamplerState.GetByteSize(); //mSamplerState mData [4 bytes]
totalSize += (uint)Marshal.SizeOf(mPlatform_BlockSize); //mPlatform Block Size [4 bytes]
totalSize += (uint)Marshal.SizeOf((int)mPlatform); //mPlatform [4 bytes]
totalSize += (uint)Marshal.SizeOf(mName_BlockSize); //mName Block Size [4 bytes] //mName block size (size + string len)
totalSize += (uint)Marshal.SizeOf(mName.Length); //mName (strength length prefix) [4 bytes]
totalSize += (uint)mName.Length; //mName [x bytes]
totalSize += (uint)Marshal.SizeOf(mImportName_BlockSize); //mImportName Block Size [4 bytes] //mImportName block size (size + string len)
totalSize += (uint)Marshal.SizeOf(mImportName.Length); //mImportName (strength length prefix) [4 bytes] (this is always 0)
totalSize += (uint)mImportName.Length; //mImportName [x bytes] (this is always 0)
totalSize += (uint)Marshal.SizeOf(mImportScale); //mImportScale [4 bytes]
totalSize += mToolProps.GetByteSize();
totalSize += (uint)Marshal.SizeOf(mNumMipLevels); //mNumMipLevels [4 bytes]
totalSize += (uint)Marshal.SizeOf(mWidth); //mWidth [4 bytes]
totalSize += (uint)Marshal.SizeOf(mHeight); //mHeight [4 bytes]
// totalSize += (uint)Marshal.SizeOf(mDepth); //mDepth [4 bytes]
// totalSize += (uint)Marshal.SizeOf(mArraySize); //mArraySize [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mSurfaceFormat); //mSurfaceFormat [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mTextureLayout); //mTextureLayout [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mSurfaceGamma); //mSurfaceGamma [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mSurfaceMultisample); //mSurfaceMultisample [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mResourceUsage); //mResourceUsage [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mType); //mType [4 bytes]
// totalSize += (uint)Marshal.SizeOf(mSwizzleSize); //mSwizzleSize [4 bytes]
// totalSize += mSwizzle.GetByteSize();
// totalSize += (uint)Marshal.SizeOf(mSpecularGlossExponent); //mSpecularGlossExponent [4 bytes]
// totalSize += (uint)Marshal.SizeOf(mHDRLightmapScale); //mHDRLightmapScale [4 bytes]
// totalSize += (uint)Marshal.SizeOf(mToonGradientCutoff); //mToonGradientCutoff [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mAlphaMode); //mAlphaMode [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mColorMode); //mColorMode [4 bytes]
// totalSize += mUVOffset.GetByteSize(); //[4 bytes]
// totalSize += mUVScale.GetByteSize(); //[4 bytes]

// totalSize += (uint)Marshal.SizeOf(mArrayFrameNames_ArrayCapacity); //mArrayFrameNames DCArray Capacity [4 bytes]
// totalSize += (uint)Marshal.SizeOf(mArrayFrameNames_ArrayLength); //mArrayFrameNames DCArray Length [4 bytes] //ADD 1 BECAUSE COUNTING STARTS AT 0
// for (int i = 0; i < mArrayFrameNames_ArrayLength; i++)
// {
// totalSize += mArrayFrameNames[i].GetByteSize(); //Symbol [8 bytes]
// }

// totalSize += (uint)Marshal.SizeOf(mToonRegions_ArrayCapacity); //mToonRegions DCArray Capacity [4 bytes]
// totalSize += (uint)Marshal.SizeOf(mToonRegions_ArrayLength); //mToonRegions DCArray Length [4 bytes]
// for (int i = 0; i < mToonRegions_ArrayLength; i++)
// {
// totalSize += mToonRegions[i].GetByteSize();
// }

// totalSize += mStreamHeader.GetByteSize();

// for (int i = 0; i < mStreamHeader.mRegionCount; i++)
// {
// totalSize += 4; //[4 bytes]
// totalSize += 4; //[4 bytes]
// totalSize += 4; //[4 bytes]
// totalSize += 4; //[4 bytes]
// totalSize += 4; //[4 bytes]
// totalSize += 4; //[4 bytes]
// }

return totalSize;
}

public void PrintConsole()
{
Console.WriteLine("||||||||||| D3DTX Header |||||||||||");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using D3DTX_Converter.DirectX;
using D3DTX_Converter.Main;
using System.IO;
using System.Runtime.InteropServices;

/*
* NOTE:
Expand Down Expand Up @@ -311,7 +312,7 @@ public void WriteBinaryData(BinaryWriter writer)
writer.Write(mImportName_BlockSize); //mImportName Block Size [4 bytes] //mImportName block size (size + string len)
ByteFunctions.WriteString(writer, mImportName); //mImportName [x bytes] (this is always 0)
writer.Write(mImportScale); //mImportScale [4 bytes]
writer.Write(mToolProps.mbHasProps); //mToolProps mbHasProps [1 byte]
ByteFunctions.WriteBoolean(writer, mToolProps.mbHasProps); //mToolProps mbHasProps [1 byte]
writer.Write(mNumMipLevels); //mNumMipLevels [4 bytes]
writer.Write(mWidth); //mWidth [4 bytes]
writer.Write(mHeight); //mHeight [4 bytes]
Expand Down Expand Up @@ -359,9 +360,76 @@ public void WriteBinaryData(BinaryWriter writer)
}
}

public uint GetHeaderByteSize()
{
uint totalSize = 0;

totalSize += (uint)Marshal.SizeOf(mVersion); //mVersion [4 bytes]
totalSize += (uint)Marshal.SizeOf(mSamplerState_BlockSize); //mSamplerState Block Size [4 bytes]
totalSize += mSamplerState.GetByteSize(); //mSamplerState mData [4 bytes]
totalSize += (uint)Marshal.SizeOf(mPlatform_BlockSize); //mPlatform Block Size [4 bytes]
totalSize += (uint)Marshal.SizeOf((int)mPlatform); //mPlatform [4 bytes]
totalSize += (uint)Marshal.SizeOf(mName_BlockSize); //mName Block Size [4 bytes] //mName block size (size + string len)
totalSize += (uint)Marshal.SizeOf(mName.Length); //mName (strength length prefix) [4 bytes]
totalSize += (uint)mName.Length; //mName [x bytes]
totalSize += (uint)Marshal.SizeOf(mImportName_BlockSize); //mImportName Block Size [4 bytes] //mImportName block size (size + string len)
totalSize += (uint)Marshal.SizeOf(mImportName.Length); //mImportName (strength length prefix) [4 bytes] (this is always 0)
totalSize += (uint)mImportName.Length; //mImportName [x bytes] (this is always 0)
totalSize += (uint)Marshal.SizeOf(mImportScale); //mImportScale [4 bytes]
totalSize += mToolProps.GetByteSize();
totalSize += (uint)Marshal.SizeOf(mNumMipLevels); //mNumMipLevels [4 bytes]
totalSize += (uint)Marshal.SizeOf(mWidth); //mWidth [4 bytes]
totalSize += (uint)Marshal.SizeOf(mHeight); //mHeight [4 bytes]
// totalSize += (uint)Marshal.SizeOf(mDepth); //mDepth [4 bytes]
// totalSize += (uint)Marshal.SizeOf(mArraySize); //mArraySize [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mSurfaceFormat); //mSurfaceFormat [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mTextureLayout); //mTextureLayout [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mSurfaceGamma); //mSurfaceGamma [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mSurfaceMultisample); //mSurfaceMultisample [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mResourceUsage); //mResourceUsage [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mType); //mType [4 bytes]
// totalSize += (uint)Marshal.SizeOf(mSwizzleSize); //mSwizzleSize [4 bytes]
// totalSize += mSwizzle.GetByteSize();
// totalSize += (uint)Marshal.SizeOf(mSpecularGlossExponent); //mSpecularGlossExponent [4 bytes]
// totalSize += (uint)Marshal.SizeOf(mHDRLightmapScale); //mHDRLightmapScale [4 bytes]
// totalSize += (uint)Marshal.SizeOf(mToonGradientCutoff); //mToonGradientCutoff [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mAlphaMode); //mAlphaMode [4 bytes]
// totalSize += (uint)Marshal.SizeOf((int)mColorMode); //mColorMode [4 bytes]
// totalSize += mUVOffset.GetByteSize(); //[4 bytes]
// totalSize += mUVScale.GetByteSize(); //[4 bytes]

// totalSize += (uint)Marshal.SizeOf(mArrayFrameNames_ArrayCapacity); //mArrayFrameNames DCArray Capacity [4 bytes]
// totalSize += (uint)Marshal.SizeOf(mArrayFrameNames_ArrayLength); //mArrayFrameNames DCArray Length [4 bytes] //ADD 1 BECAUSE COUNTING STARTS AT 0
// for (int i = 0; i < mArrayFrameNames_ArrayLength; i++)
// {
// totalSize += mArrayFrameNames[i].GetByteSize(); //Symbol [8 bytes]
// }

// totalSize += (uint)Marshal.SizeOf(mToonRegions_ArrayCapacity); //mToonRegions DCArray Capacity [4 bytes]
// totalSize += (uint)Marshal.SizeOf(mToonRegions_ArrayLength); //mToonRegions DCArray Length [4 bytes]
// for (int i = 0; i < mToonRegions_ArrayLength; i++)
// {
// totalSize += mToonRegions[i].GetByteSize();
// }

// totalSize += mStreamHeader.GetByteSize();

// for (int i = 0; i < mStreamHeader.mRegionCount; i++)
// {
// totalSize += 4; //[4 bytes]
// totalSize += 4; //[4 bytes]
// totalSize += 4; //[4 bytes]
// totalSize += 4; //[4 bytes]
// totalSize += 4; //[4 bytes]
// totalSize += 4; //[4 bytes]
// }

return totalSize;
}

public void PrintConsole()
{

Console.WriteLine("||||||||||| D3DTX Header |||||||||||");

Console.WriteLine("D3DTX mVersion = {0}", mVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ public D3DTX_V7(BinaryReader reader, bool showConsole = false)
mNumMipLevels = reader.ReadUInt32(); //mNumMipLevels [4 bytes]
mWidth = reader.ReadUInt32(); //mWidth [4 bytes]
mHeight = reader.ReadUInt32(); //mHeight [4 bytes]

mSurfaceFormat = T3TextureBase.GetSurfaceFormat(reader.ReadInt32()); //mSurfaceFormat [4 bytes]
mTextureLayout = T3TextureBase.GetTextureLayout(reader.ReadInt32()); //mTextureLayout [4 bytes]
mSurfaceGamma = T3TextureBase.GetSurfaceGamma(reader.ReadInt32()); //mSurfaceGamma [4 bytes]
Expand Down Expand Up @@ -372,7 +371,7 @@ public void WriteBinaryData(BinaryWriter writer)
writer.Write(mImportName_BlockSize); //mImportName Block Size [4 bytes] //mImportName block size (size + string len)
ByteFunctions.WriteString(writer, mImportName); //mImportName [x bytes] (this is always 0)
writer.Write(mImportScale); //mImportScale [4 bytes]
writer.Write(mToolProps.mbHasProps); //mToolProps mbHasProps [1 byte]
ByteFunctions.WriteBoolean(writer, mToolProps.mbHasProps); //mToolProps mbHasProps [1 byte]
writer.Write(mNumMipLevels); //mNumMipLevels [4 bytes]
writer.Write(mWidth); //mWidth [4 bytes]
writer.Write(mHeight); //mHeight [4 bytes]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,10 @@ public void WriteBinaryData(BinaryWriter writer)
writer.Write((int)mPlatform); //mPlatform [4 bytes]
writer.Write(mName_BlockSize); //mName Block Size [4 bytes] //mName block size (size + string len)
ByteFunctions.WriteString(writer, mName); //mName [x bytes]
writer.Write(
mImportName_BlockSize); //mImportName Block Size [4 bytes] //mImportName block size (size + string len)
writer.Write(mImportName_BlockSize); //mImportName Block Size [4 bytes] //mImportName block size (size + string len)
ByteFunctions.WriteString(writer, mImportName); //mImportName [x bytes] (this is always 0)
writer.Write(mImportScale); //mImportScale [4 bytes]
writer.Write(mToolProps.mbHasProps); //mToolProps mbHasProps [1 byte]
ByteFunctions.WriteBoolean(writer, mToolProps.mbHasProps); //mToolProps mbHasProps [1 byte]
writer.Write(mNumMipLevels); //mNumMipLevels [4 bytes]
writer.Write(mWidth); //mWidth [4 bytes]
writer.Write(mHeight); //mHeight [4 bytes]
Expand Down

0 comments on commit 0a182dd

Please sign in to comment.