From aa0bc916c36eb0e2cd66ad01a9defd2b523e8258 Mon Sep 17 00:00:00 2001 From: lahm86 <33758420+lahm86@users.noreply.github.com> Date: Mon, 9 May 2022 16:49:22 +0100 Subject: [PATCH] #304 Cross-game Preparations Adds SFX export support for TR1. --- SFXExport/Program.cs | 48 +++++++++++++++++++++++++++++++++++++- SFXExport/SFXExport.csproj | 3 +++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/SFXExport/Program.cs b/SFXExport/Program.cs index 5b81406f0..b839632dc 100644 --- a/SFXExport/Program.cs +++ b/SFXExport/Program.cs @@ -1,5 +1,7 @@ using System; using System.IO; +using TRLevelReader; +using TRLevelReader.Model; namespace SFXExport { @@ -21,6 +23,22 @@ static void Main(string[] args) } Directory.CreateDirectory(exportDir); + switch (Path.GetExtension(file).ToUpper()) + { + case ".SFX": + ExtractFromSFX(file, exportDir); + break; + case ".PHD": + ExtractFromPHD(file, exportDir); + break; + default: + Console.WriteLine("Unsupported file."); + break; + } + } + + private static void ExtractFromSFX(string file, string exportDir) + { int sample = 0; using (BinaryReader reader = new BinaryReader(File.Open(file, FileMode.Open))) { @@ -49,10 +67,32 @@ static void Main(string[] args) } } + private static void ExtractFromPHD(string file, string exportDir) + { + TRLevel level = new TR1LevelReader().ReadLevel(file); + for (int i = 0; i < level.NumSampleIndices; i++) + { + uint sampleStart = level.SampleIndices[i]; + uint sampleEnd = i < level.NumSampleIndices - 1 ? level.SampleIndices[i + 1] : (uint)level.Samples.Length; + if (sampleEnd > level.Samples.Length) + { + sampleEnd = (uint)level.Samples.Length; + } + + using (BinaryWriter writer = new BinaryWriter(File.Create(Path.Combine(exportDir, i + ".wav")))) + { + for (uint j = sampleStart; j < sampleEnd; j++) + { + writer.Write(level.Samples[j]); + } + } + } + } + private static void Usage() { Console.WriteLine(); - Console.WriteLine("Usage: SFXExport [*.SFX] [EXPORT_DIR]"); + Console.WriteLine("Usage: SFXExport [*.SFX|*.PHD] [EXPORT_DIR]"); Console.WriteLine(); Console.WriteLine("Example"); @@ -61,6 +101,12 @@ private static void Usage() Console.ResetColor(); Console.WriteLine("\t\tExtract each sound effect from the SFX file and create a sample file for each in the TR2 directory."); Console.WriteLine(); + + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("\tSFXExport LEVEL1.PHD TR1"); + Console.ResetColor(); + Console.WriteLine("\t\tExtract each sound effect from Caves and create a sample file for each in the TR1 directory."); + Console.WriteLine(); } } } \ No newline at end of file diff --git a/SFXExport/SFXExport.csproj b/SFXExport/SFXExport.csproj index 7534f6b71..9a24bf652 100644 --- a/SFXExport/SFXExport.csproj +++ b/SFXExport/SFXExport.csproj @@ -6,4 +6,7 @@ Copyright © Tombrunners 2021 false + + + \ No newline at end of file