Skip to content

Commit

Permalink
Added list of known hash names, list is now sorted like OpenIV.
Browse files Browse the repository at this point in the history
  • Loading branch information
WesternGamer committed Sep 3, 2023
1 parent e188a53 commit 7ad2a26
Show file tree
Hide file tree
Showing 4 changed files with 857,658 additions and 8 deletions.
45 changes: 45 additions & 0 deletions RDR2AudioTool/AlphanumericComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using CodeWalker.GameFiles;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace RDR2AudioTool
{
public class AlphanumericComparer : IComparer<AwcStream>
{
public int Compare(AwcStream x, AwcStream y)
{
if (ReferenceEquals(x, y))
return 0;

if (x == null)
return -1;

if (y == null)
return 1;

string[] xParts = Regex.Split(x.Name, "([0-9]+)");
string[] yParts = Regex.Split(y.Name, "([0-9]+)");

for (int i = 0; i < Math.Min(xParts.Length, yParts.Length); i++)
{
if (i % 2 == 0)
{
int textCompare = string.Compare(xParts[i], yParts[i], StringComparison.OrdinalIgnoreCase);
if (textCompare != 0)
return textCompare;
}
else
{
int xNum = int.Parse(xParts[i]);
int yNum = int.Parse(yParts[i]);
int numCompare = xNum.CompareTo(yNum);
if (numCompare != 0)
return numCompare;
}
}

return xParts.Length.CompareTo(yParts.Length);
}
}
}
34 changes: 29 additions & 5 deletions RDR2AudioTool/AudioEditingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,45 @@ private void RefreshList()

if (Awc?.Streams != null)
{
List<AwcStream> hashStreams = new List<AwcStream>();
List<AwcStream> nameStreams = new List<AwcStream>();

var strlist = Awc.Streams.ToList();
foreach (var audio in strlist)
{
if (audio.Name.StartsWith("0x"))
{
hashStreams.Add(audio);
}
else
{
nameStreams.Add(audio);
}
}

hashStreams.Sort((a, b) => a.Hash.Hash.CompareTo(b.Hash.Hash));
nameStreams.Sort(new AlphanumericComparer());

foreach (var audio in hashStreams)
{
var stereo = (audio.ChannelStreams?.Length == 2);
if ((audio.StreamBlocks != null) && (!stereo)) continue;//don't display multichannel source audios
var name = audio.Name;
if (stereo) continue; // name = "(Stereo Playback)";

if (!name.StartsWith("0x"))
{
name = name + $" (0x{audio.Hash})";
}
StreamList.Items.Add(new ItemInfo(name, audio.Type, audio.LengthStr, TextUtil.GetBytesReadable(audio.ByteLength), audio));
}

var item = StreamList.Items.Add(new ItemInfo(name, audio.Type, audio.LengthStr, TextUtil.GetBytesReadable(audio.ByteLength), audio));
foreach (var audio in nameStreams)
{
var stereo = (audio.ChannelStreams?.Length == 2);
if ((audio.StreamBlocks != null) && (!stereo)) continue;//don't display multichannel source audios
var name = audio.Name + $" (0x{audio.Hash})";
if (stereo) continue; // name = "(Stereo Playback)";

StreamList.Items.Add(new ItemInfo(name, audio.Type, audio.LengthStr, TextUtil.GetBytesReadable(audio.ByteLength), audio));
}

SaveButton.IsEnabled = true;
RenameButton.IsEnabled = true;
ReplaceButton.IsEnabled = true;
Expand Down
2 changes: 1 addition & 1 deletion RDR2AudioTool/RDR2AudioTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Description>Tool to edit RDR2 AWC files.</Description>
<Product>RDR 2 Audio Tool</Product>
<AssemblyTitle>RDR2AudioTool</AssemblyTitle>
<Version>0.2.0</Version>
<Version>0.2.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 7ad2a26

Please sign in to comment.