Skip to content

Commit

Permalink
Fix DXT3 image parsing (YARC-Official#201)
Browse files Browse the repository at this point in the history
* add hopo_threshold support to please jnack

* fix DXT3 image byte parsing

* DXT3 loop cleanup

* hopo threshold fix

* actually reference hopo_threshold this time
  • Loading branch information
rjkiv authored Apr 28, 2023
1 parent cc88a25 commit 8b121e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions Assets/Script/Serialization/Xbox/XboxImage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -63,15 +64,13 @@ public byte[] GetDXTBlocksFromImage() {
DXTBlocks = br.ReadBytes((int) (fs.Length - 32));
} else {
// If DXT-3 format, we have to omit the alpha bytes
DXTBlocks = new byte[(fs.Length - 32) / 2];
byte[] buf = new byte[8];
for (int i = 0; i < DXTBlocks.Length; i += 8) {
buf = br.ReadBytes(8); // Skip over every 8 bytes
buf = br.ReadBytes(8); // We want to read these 8 bytes
for (int j = 0; j < 8; j++) {
DXTBlocks[i + j] = buf[j];
}
List<byte> extractedDXT3 = new List<byte>();
br.ReadBytes(8); //skip the first 8 alpha bytes
for (int i = 8; i < (fs.Length - 32) / 2; i += 8) {
extractedDXT3.AddRange(br.ReadBytes(8)); // We want to read these 8 bytes
br.ReadBytes(8); // and skip these 8 bytes
}
DXTBlocks = extractedDXT3.ToArray();
}

// Swap bytes because xbox is weird like that
Expand Down
4 changes: 2 additions & 2 deletions Assets/Script/Serialization/Xbox/XboxSongData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public void ParseFromDta(DataArray dta) {
songId = (uint) ((DataAtom) dtaArray[1]).Int;
break;
case "song_length": songLength = (uint) ((DataAtom) dtaArray[1]).Int; break;
case "song": // we just want vocal parts for songDta
case "song": // we just want vocal parts and hopo threshold for songDta
hopoThreshold = (dtaArray.Array("hopo_threshold") != null) ? ((DataAtom) dtaArray.Array("hopo_threshold")[1]).Int : 0;
vocalParts = (dtaArray.Array("vocal_parts") != null) ? (byte) ((DataAtom) dtaArray.Array("vocal_parts")[1]).Int : (byte) 1;
break;
case "anim_tempo":
Expand Down Expand Up @@ -91,7 +92,6 @@ public void ParseFromDta(DataArray dta) {
if (dtaArray[j] is DataArray inner)
ranks.Add(((DataSymbol) inner[0]).Name, (ushort) ((DataAtom) inner[1]).Int);
break;
case "hopo_threshold": hopoThreshold = ((DataAtom) dtaArray[1]).Int; break;
case "game_origin": gameOrigin = ((DataSymbol) dtaArray[1]).Name; break;
case "genre": genre = ((DataSymbol) dtaArray[1]).Name; break;
case "rating": rating = (byte) ((DataAtom) dtaArray[1]).Int; break;
Expand Down

0 comments on commit 8b121e6

Please sign in to comment.