private void ProcessWaveBankEntries(string filePath, VirtualSoundBank soundBank, VirtualWaveBank waveBank) { bool TryRedirectEntry(Mod mod, int i, string fileName) { var redirectFilePath = Path.Combine(Path.Combine(mod.LoadDirectory, "SND"), waveBank.FileName, fileName); if (File.Exists(redirectFilePath)) { if (waveBank.Entries[i].Redirect(redirectFilePath)) { mLogger.Info($"{waveBank.FileName} Index: {i} Cue: {waveBank.Entries[i].CueName} redirected to {redirectFilePath}"); } else { mLogger.Error($"{waveBank.FileName} Index: {i} Cue: {waveBank.Entries[i].CueName} redirecting to {redirectFilePath} failed!"); } return(true); } return(false); } for (int i = 0; i < waveBank.Entries.Count; i++) { if (soundBank != null) { waveBank.Entries[i].CueName = soundBank.GetTrackCueName(i, 0); } if (waveBank.Entries[i].IsRedirected) { continue; } foreach (var mod in mModDb.Mods) { // Try redirect from wave/track index if (TryRedirectEntry(mod, i, $"{i}.raw")) { break; } if (waveBank.Entries[i].CueName != null) { // Try redirect from cue name if (TryRedirectEntry(mod, i, waveBank.Entries[i].CueName + ".raw")) { break; } } } } }
public override Native.NtStatus NtCreateFileImpl(string newFilePath, out IntPtr handle, FileAccess access, ref Native.OBJECT_ATTRIBUTES objectAttributes, ref Native.IO_STATUS_BLOCK ioStatus, ref long allocSize, uint fileAttributes, FileShare share, uint createDisposition, uint createOptions, IntPtr eaBuffer, uint eaLength) { var result = mHooks.NtCreateFileHook.OriginalFunction(out handle, access, ref objectAttributes, ref ioStatus, ref allocSize, fileAttributes, share, createDisposition, createOptions, eaBuffer, eaLength); var fileName = Path.GetFileNameWithoutExtension(newFilePath); var ext = Path.GetExtension(newFilePath); var isWaveBank = ext.Equals(".xwb", StringComparison.OrdinalIgnoreCase); VirtualWaveBank waveBank = null; VirtualSoundBank soundBank = null; if (isWaveBank && !mWaveBankByName.TryGetValue(fileName, out waveBank)) { // Try get sound bank for cue names mSoundBankByName.TryGetValue(fileName, out soundBank); // Wave bank mWaveBankByName[fileName] = waveBank = new VirtualWaveBank(mLogger); // Load wave bank using (var fileStream = new FileStream(new SafeFileHandle(handle, true), FileAccess.Read, 1024 * 1024)) waveBank.LoadFromFile(newFilePath, fileStream); // Reopen file to reset it result = mHooks.NtCreateFileHook.OriginalFunction(out handle, access, ref objectAttributes, ref ioStatus, ref allocSize, fileAttributes, share, createDisposition, createOptions, eaBuffer, eaLength); ProcessWaveBankEntries(newFilePath, soundBank, waveBank); mLogger.Debug($"{newFilePath} registered"); } else if (!mSoundBankByName.TryGetValue(fileName, out soundBank)) { // Sound bank mSoundBankByName[fileName] = soundBank = new VirtualSoundBank(mLogger); // Load wave bank using (var fileStream = new FileStream(new SafeFileHandle(handle, true), FileAccess.Read, 1024 * 1024)) soundBank.LoadFromFile(newFilePath, fileStream); // Reopen file to reset it result = mHooks.NtCreateFileHook.OriginalFunction(out handle, access, ref objectAttributes, ref ioStatus, ref allocSize, fileAttributes, share, createDisposition, createOptions, eaBuffer, eaLength); // Find associated wave bank if (!mWaveBankByName.TryGetValue(soundBank.Native.WaveBankNames[0].Name, out waveBank)) { mLogger.Error($"{newFilePath} Can't find wavebank!"); } else { ProcessWaveBankEntries(newFilePath, soundBank, waveBank); } } if (isWaveBank) { mWaveBankByHandle.Add(handle, waveBank); mLogger.Debug($"{waveBank.FileName} Hnd {handle} registered"); } else { mSoundBankByHandle.Add(handle, soundBank); } return(result); }