From 592dbac710f889323e664ca172f5a484dfbec7b2 Mon Sep 17 00:00:00 2001
From: Denis <93516910+Bussun@users.noreply.github.com>
Date: Fri, 28 Jan 2022 23:58:35 +0100
Subject: [PATCH] trying stuff
---
BMGEditor/BMGEditor.csproj | 1 +
BMGEditor/FS/Yaz0Stream.cs | 109 ++++++++++++++++++++++++++++++++++++-
2 files changed, 109 insertions(+), 1 deletion(-)
diff --git a/BMGEditor/BMGEditor.csproj b/BMGEditor/BMGEditor.csproj
index 5edafe8..e5b7a5e 100644
--- a/BMGEditor/BMGEditor.csproj
+++ b/BMGEditor/BMGEditor.csproj
@@ -9,6 +9,7 @@
AnyCPU;x64
x64
Luma_icon.ico
+ true
diff --git a/BMGEditor/FS/Yaz0Stream.cs b/BMGEditor/FS/Yaz0Stream.cs
index b3d2872..c62ad52 100644
--- a/BMGEditor/FS/Yaz0Stream.cs
+++ b/BMGEditor/FS/Yaz0Stream.cs
@@ -33,7 +33,114 @@ namespace BMGEditor
return;
Int32 decompSize = (data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]);
-
+ Byte[] output = new Byte[decompSize + 1];
+
+ /* Tryed rewriting it using szs tools code from MKW Wiki, not a real success
+ uint pos = 0x10;
+ uint outPos = 0x00;
+
+ byte group_head = 0;
+ int group_head_length = 0;
+
+ while (pos < data.Length && outPos < output.Length)
+ {
+ if (group_head_length == 0)
+ {
+ group_head = data[pos];
+ pos++;
+ group_head_length = 8;
+ }
+ group_head_length--;
+ if ((group_head & 0x80) != 0)
+ {
+ output[outPos] = data[pos];
+ outPos++; pos++;
+ }
+ else
+ {
+ byte b1 = data[pos]; pos++;
+ byte b2 = data[pos]; pos++;
+
+ uint copy_src = (uint)(outPos - ((b1 & 0x0F) << 8 | b2) - 1);
+ int n = b1 >> 4;
+
+ if (n == 0)
+ {
+ n = data[pos] + 0x12; pos++;
+ }
+ else
+ {
+ n += 2;
+ }
+
+ while (n-- < 0)
+ {
+ output[outPos] = output[copy_src];
+ }
+ }
+ group_head <<= 1;
+ }
+ */
+
+ int Read_Position = 0x10;
+ int Write_Position = 0;
+ uint ValidBitCount = 0;
+ byte CurrentCodeByte = 0;
+
+ while (Write_Position < decompSize)
+ {
+ if (ValidBitCount == 0)
+ {
+ CurrentCodeByte = data[Read_Position];
+ ++Read_Position;
+ ValidBitCount = 8;
+ }
+
+ if ((CurrentCodeByte & 0x80) != 0)
+ {
+ output[Write_Position] = data[Read_Position];
+ Write_Position++;
+ Read_Position++;
+ }
+ else
+ {
+ byte Byte1 = data[Read_Position];
+ byte Byte2 = data[Read_Position + 1];
+ Read_Position += 2;
+
+ uint Dist = (uint)(((Byte1 & 0xF) << 8) | Byte2);
+ uint CopySource = (uint)(Write_Position - Dist - 1);
+
+ uint Byte_Count = (uint)(Byte1 >> 4);
+ if (Byte_Count == 0)
+ {
+ Byte_Count = (uint)(data[Read_Position] + 0x12);
+ Read_Position++;
+ }
+ else
+ {
+ Byte_Count += 1;
+ }
+
+ for (int i = 0; i < Byte_Count; ++i)
+ {
+ output[Write_Position] = output[CopySource];
+ CopySource++;
+ Write_Position++;
+ }
+ }
+
+ CurrentCodeByte <<= 1;
+ ValidBitCount -= 1;
+ }
+
+ Array.Resize(ref data, decompSize + 1);
+ output.CopyTo(data, 0);
+
+ FileStream test = File.OpenWrite("./test.bin");
+ test.Write(output);
+ test.Flush();
+ test.Close();
return;
}
}