1
0
mirror of synced 2024-12-01 10:37:25 +01:00

Now save bntx arrays back

This commit is contained in:
KillzXGaming 2019-06-29 16:59:00 -04:00
parent 53d5f3aafd
commit d4884d81aa
5 changed files with 42 additions and 18 deletions

Binary file not shown.

View File

@ -206,7 +206,7 @@ namespace FirstPlugin
FileNameText = FileName; FileNameText = FileName;
if (!IsLoadingArray) if (!IsLoadingArray)
LoadBNTXArray(stream, this); LoadBNTXArray(ContainerArray, stream, this);
LoadFile(stream, Name); LoadFile(stream, Name);
@ -214,12 +214,13 @@ namespace FirstPlugin
} }
static bool IsLoadingArray = false; static bool IsLoadingArray = false;
private static void LoadBNTXArray(Stream stream, BNTX bntx) static bool IsSavingArray = false;
List<BNTX> ContainerArray = new List<BNTX>();
private static void LoadBNTXArray(List<BNTX> Containers, Stream stream, BNTX bntx)
{ {
IsLoadingArray = true; IsLoadingArray = true;
int Alignment = 4096; int Alignment = 4096;
List<BNTX> Containers = new List<BNTX>();
using (var reader = new FileReader(stream, true)) using (var reader = new FileReader(stream, true))
{ {
SearchForBinaryContainerFile(reader, Alignment, Containers); SearchForBinaryContainerFile(reader, Alignment, Containers);
@ -237,6 +238,23 @@ namespace FirstPlugin
IsLoadingArray = false; IsLoadingArray = false;
} }
private static void SaveBNTXArray(MemoryStream mem, List<BNTX> Containers)
{
IsSavingArray = true;
int Alignment = 4096;
using (var saver = new FileWriter(mem))
{
foreach (var container in Containers)
{
saver.Write(container.Save());
saver.Align(Alignment);
}
}
IsSavingArray = false;
}
private static void SearchForBinaryContainerFile(FileReader reader, int Alignment, List<BNTX> Containers) private static void SearchForBinaryContainerFile(FileReader reader, int Alignment, List<BNTX> Containers)
{ {
long Pos = reader.Position; long Pos = reader.Position;
@ -793,32 +811,38 @@ namespace FirstPlugin
} }
public byte[] Save() public byte[] Save()
{ {
MemoryStream mem = new MemoryStream();
BinaryTexFile.Textures.Clear(); BinaryTexFile.Textures.Clear();
BinaryTexFile.TextureDict.Clear(); BinaryTexFile.TextureDict.Clear();
foreach (TextureData tex in Textures.Values) if (ContainerArray.Count > 0 && !IsSavingArray)
{ {
if (tex.IsEdited) SaveBNTXArray(mem, ContainerArray);
}
else
{
foreach (TextureData tex in Textures.Values)
{ {
for (int i = 0; i < tex.EditedImages.Length; i++) if (tex.IsEdited)
{ {
tex.SetImageData(tex.EditedImages[i].bitmap, tex.EditedImages[i].ArrayLevel); for (int i = 0; i < tex.EditedImages.Length; i++)
tex.EditedImages[i].bitmap.Dispose(); {
tex.SetImageData(tex.EditedImages[i].bitmap, tex.EditedImages[i].ArrayLevel);
tex.EditedImages[i].bitmap.Dispose();
}
tex.EditedImages = new EditedBitmap[0];
} }
tex.EditedImages = new EditedBitmap[0];
tex.Texture.Name = tex.Text;
BinaryTexFile.Textures.Add(tex.Texture);
BinaryTexFile.TextureDict.Add(tex.Text);
} }
tex.Texture.Name = tex.Text; BinaryTexFile.Save(mem);
BinaryTexFile.Textures.Add(tex.Texture);
BinaryTexFile.TextureDict.Add(tex.Text);
} }
MemoryStream mem = new MemoryStream();
BinaryTexFile.Save(mem);
return mem.ToArray(); return mem.ToArray();
} }