Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

soundcache packing fix #37

Merged
merged 3 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions WolvenKit.CR2W/CR2W/CR2WReaderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -27,10 +27,16 @@ public static string ReadCR2WString(this BinaryReader file, int len = 0)
var sb = new StringBuilder();
while (true)
{
var c = (char)file.ReadByte();
if (c == 0)
if (file.BaseStream.Position <= file.BaseStream.Length)
{
var c = (char)file.ReadByte();
if (c == 0)
break;
sb.Append(c);
} else
{
break;
sb.Append(c);
}
}
str = sb.ToString();
}
Expand Down Expand Up @@ -73,4 +79,4 @@ public static byte[] ReadRemainingData(this BinaryReader br)


}
}
}
45 changes: 28 additions & 17 deletions WolvenKit.Wwise/SoundCache/Sound_Cache.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.MemoryMappedFiles;
Expand Down Expand Up @@ -73,7 +73,7 @@ public SoundCache()
/// <returns>The concatenated string.</returns>
private static byte[] GetNames(List<string> FileList)
{
return Encoding.UTF8.GetBytes(string.Join("\0",FileList.Select(x=> Path.GetFileName(GetIDFromPath(x)).Trim())) + "\0");
return Encoding.UTF8.GetBytes(string.Join("\0", FileList.Select(x => Path.GetFileName(GetIDFromPath(x)).Trim())) + "\0");
}

/// <summary>
Expand Down Expand Up @@ -102,7 +102,7 @@ private static List<SoundCacheItem> BuildInfo(List<string> FileList)
/// <param name="FileList">The list of files to build the info for.</param>
/// <returns></returns>
private static byte[] GetInfo(List<string> FileList)
{
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
Expand Down Expand Up @@ -154,7 +154,7 @@ private static ulong CalculateChecksum(List<string> Files2Buffer)
/// Reads the soundcache file.
/// </summary>
/// <param name="br">The binaryreader to read the file contents from.</param>
public void Read(BinaryReader br)
public void Read(BinaryReader br)
{
Files = new List<SoundCacheItem>();
if (!br.ReadBytes(4).SequenceEqual(Magic))
Expand All @@ -176,32 +176,39 @@ public void Read(BinaryReader br)
}
NamesSize = br.ReadUInt32();
if (Version >= 2)
Unk3 = br.ReadUInt32();
Unk3 = br.ReadUInt32();
buffsize = br.ReadInt64();
checksum = br.ReadInt64();
br.BaseStream.Seek(InfoOffset, SeekOrigin.Begin);
for (var i = 0; i < FileCount; i++)
{
var sf = new SoundCacheItem(this);
if (Version >= 2)
if (br.BaseStream.Position != br.BaseStream.Length)
{
sf.NameOffset = br.ReadInt64();
sf.PageOffset = br.ReadInt64();
sf.Size = (uint)br.ReadInt64();
var sf = new SoundCacheItem(this);
if (Version >= 2)
{
sf.NameOffset = br.ReadInt64();
sf.PageOffset = br.ReadInt64();
sf.Size = (uint)br.ReadInt64();
}
else
{
sf.NameOffset = br.ReadUInt32();
sf.PageOffset = br.ReadUInt32();
sf.Size = br.ReadUInt32();
}
Files.Add(sf);
}
else
{
sf.NameOffset = br.ReadUInt32();
sf.PageOffset = br.ReadUInt32();
sf.Size = br.ReadUInt32();
break;
}
Files.Add(sf);
}
foreach (var f in Files)
{
br.BaseStream.Seek(NamesOffset + f.NameOffset, SeekOrigin.Begin);
f.Name = br.ReadCR2WString();
if(f.Name.EndsWith(".wem") && info.StreamedFiles.Any(x => x.Id == (f.Name.Split('.')[0])))
if (f.Name.EndsWith(".wem") && info.StreamedFiles.Any(x => x.Id == (f.Name.Split('.')[0])))
{
f.Name = info.StreamedFiles.First(x => x.Id == (f.Name.Split('.')[0])).Path;
}
Expand Down Expand Up @@ -251,14 +258,18 @@ public static void Write(List<string> FileList, string OutPath)
for (int i = 0; i < data_array.Count; i++)
data_array[i].PageOffset = -1;
}
else
{
Version = 1;
}

if (buffersize <= CACHE_BUFFER_SIZE)
buffersize = CACHE_BUFFER_SIZE;
else
{
var fremainder = buffersize % CACHE_BUFFER_SIZE;
buffersize += (CACHE_BUFFER_SIZE - fremainder);
}
}

bw.Write(Magic);
bw.Write((UInt32)Version);
Expand Down Expand Up @@ -290,7 +301,7 @@ public static void Write(List<string> FileList, string OutPath)
bw.Write(File.ReadAllBytes(FileList[i]));
//Write filenames and the offsets and such for the files.
bw.Write(GetNames(FileList));
bw.Write(GetInfo(FileList));
bw.Write(GetInfo(FileList));
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions WolvenKit.Wwise/Wwise/WemFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -278,7 +278,7 @@ public void LoadFromFile(string path, WwAudioFileType filetype)
case "LIST":
{
LIST_offset = chunk_offset + 8;
LIST_offset = size;
LIST_size = size;
break;
}
case "smpl":
Expand All @@ -299,6 +299,8 @@ public void LoadFromFile(string path, WwAudioFileType filetype)
data_size = size;
break;
}
case "hash":
break;
default:
throw new Exception("Unknown chunk with type: " + type + "!");
}
Expand Down Expand Up @@ -422,8 +424,8 @@ public void LoadFromFile(string path, WwAudioFileType filetype)
br.BaseStream.Seek(LIST_offset, SeekOrigin.Begin);
adtlbuf = new String(br.ReadChars(4));

if (adtlbuf != "adtl")
throw new Exception("List is not adtl!");
//if (adtlbuf != "adtl")
// throw new Exception("List is not adtl!");

LIST_remain = br.ReadBytes((int)(LIST_size - 4));
}
Expand Down
3 changes: 2 additions & 1 deletion WolvenKit/Forms/MVVM/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,8 @@ private void SetupUnbundling()
return;

// check path length
if (MainController.Get().Configuration.DepotPath.Length > 38)
//if (MainController.Get().Configuration.DepotPath.Length > 38)
if (MainController.Get().Configuration.DepotPath.Length > 255)
{
MainController.LogString("Wcc probably does not support path lengths > 255. " +
"Please move your wcc_lite Modkit directory closer to root, e.g. C:\\Modkit\\.", Common.Services.Logtype.Error);
Expand Down
15 changes: 12 additions & 3 deletions WolvenKit/Forms/frmWelcome.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BrightIdeasSoftware;
using BrightIdeasSoftware;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand Down Expand Up @@ -107,10 +107,11 @@ private void PopulateRecentFileList()
</style>
</head>
<body>
<li><a href = ${"\"https://www.nexusmods.com/witcher3/mods/3161\""}> Features and Guidelines </a></li>
<li><a href = ${"\"https://github.com/Traderain/Wolven-kit/wiki\""}> WolvenKit Wiki </a></li>
<li><a href = ${"\"https://github.com/WolvenKit/WolvenKit-7\""}> GitHub Repository </a></li>
<li><a href = ${"\"https://www.youtube.com/watch?v=jUoamicYtjk\""}> Package creation </a></li>
<li><a href = ${"\"https://www.youtube.com/watch?v=jUoamicYtjk\""}> Sound modding </a></li>
<li><a href = ${"\"https://youtu.be/0Ef-HkEhdv8\""}> Sound modding </a></li>
</body>
</html>
";
Expand Down Expand Up @@ -149,17 +150,25 @@ protected void ApplyCustomTheme()
wolvenKitLbl.ForeColor = UIController.GetForeColor();

helpWebBrowser.DocumentText = DocumentText;
helpWebBrowser.Navigating += HelpWebBrowser_Navigating;
}


public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool ReleaseCapture();

// UI Events //

private void HelpWebBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
e.Cancel = true;
Process.Start(e.Url.ToString());
}

private void mainMenuStrip_MouseDown(object sender, MouseEventArgs e)
{
Expand Down