From 0418e7743e7c840ad567d4d0aedfa5b07fffbdbe Mon Sep 17 00:00:00 2001 From: dexy Date: Thu, 21 Feb 2019 16:37:55 +1100 Subject: [PATCH] Fix for saving texture resources --- CodeWalker.Core/GameFiles/GameFileCache.cs | 15 +++++++++++++++ .../GameFiles/Resources/ResourceBuilder.cs | 15 +++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CodeWalker.Core/GameFiles/GameFileCache.cs b/CodeWalker.Core/GameFiles/GameFileCache.cs index 6a6a157..cfbaa9e 100644 --- a/CodeWalker.Core/GameFiles/GameFileCache.cs +++ b/CodeWalker.Core/GameFiles/GameFileCache.cs @@ -2940,7 +2940,22 @@ namespace CodeWalker.GameFiles if (ytd2.TextureDict.Textures?.Count != ytdfile.TextureDict.Textures?.Count) { continue; } + for (int i = 0; i < ytdfile.TextureDict.Textures.Count; i++) + { + var tx1 = ytdfile.TextureDict.Textures[i]; + var tx2 = ytd2.TextureDict.Textures[i]; + var td1 = tx1.Data; + var td2 = tx2.Data; + if (td1.FullData.Length != td2.FullData.Length) + { continue; } + for (int j = 0; j < td1.FullData.Length; j++) + { + if (td1.FullData[j] != td2.FullData[j]) + { break; } + } + + } } } diff --git a/CodeWalker.Core/GameFiles/Resources/ResourceBuilder.cs b/CodeWalker.Core/GameFiles/Resources/ResourceBuilder.cs index 60fca47..2dba012 100644 --- a/CodeWalker.Core/GameFiles/Resources/ResourceBuilder.cs +++ b/CodeWalker.Core/GameFiles/Resources/ResourceBuilder.cs @@ -127,7 +127,7 @@ namespace CodeWalker.GameFiles foreach (var block in blocks) { if (block.FilePosition != -1) - throw new Exception("A position of -1 is not possible!"); + throw new Exception("Block was already assigned a position!"); //if (block.Length == 0) // throw new Exception("A length of 0 is not allowed!"); @@ -226,23 +226,14 @@ namespace CodeWalker.GameFiles - var sysDataSize = 0x2000; - while (sysDataSize < systemStream.Length) - { - sysDataSize *= 2; - } + var sysDataSize = systemPageCount * systemPageSize; var sysData = new byte[sysDataSize]; systemStream.Flush(); systemStream.Position = 0; systemStream.Read(sysData, 0, (int)systemStream.Length); - var gfxPageSize = 0x2000; - while (gfxPageSize != graphicsPageSize) - { - gfxPageSize *= 2; - } - var gfxDataSize = graphicsPageCount * gfxPageSize; + var gfxDataSize = graphicsPageCount * graphicsPageSize; var gfxData = new byte[gfxDataSize]; graphicsStream.Flush(); graphicsStream.Position = 0;