diff --git a/src/Parsec/Cryptography/SahCrypto.cs b/src/Parsec/Cryptography/SahCrypto.cs deleted file mode 100644 index 2ecd16da..00000000 --- a/src/Parsec/Cryptography/SahCrypto.cs +++ /dev/null @@ -1,54 +0,0 @@ -namespace Parsec.Cryptography; - -public sealed class SahCrypto -{ - public Func DecryptFileCount { get; set; } - public Func EncryptFileCount { get; set; } - - public Func DecryptFileName { get; set; } - public Func EncryptFileName { get; set; } - - public Func DecryptFolderCount { get; set; } - public Func EncryptFolderCount { get; set; } - - public Func DecryptFolderName { get; set; } - public Func EncryptFolderName { get; set; } - - public static SahCrypto Default { get; } = new() - { - DecryptFileCount = x => x, - EncryptFileCount = x => x, - DecryptFileName = x => x, - EncryptFileName = x => x, - DecryptFolderCount = x => x, - EncryptFolderCount = x => x, - DecryptFolderName = x => x, - EncryptFolderName = x => x - }; - - public static SahCrypto WithFileCountXorKey(int fileCountKey) - { - var crypto = Default; - crypto.DecryptFileCount = x => x ^ fileCountKey; - crypto.EncryptFileCount = x => x ^ fileCountKey; - return crypto; - } - - public static SahCrypto WithFolderCountXorKey(int folderCountKey) - { - var crypto = Default; - crypto.DecryptFolderCount = x => x ^ folderCountKey; - crypto.EncryptFolderCount = x => x ^ folderCountKey; - return crypto; - } - - public static SahCrypto WithXorKeys(int fileCountKey, int folderCountKey) - { - var crypto = Default; - crypto.DecryptFileCount = x => x ^ fileCountKey; - crypto.EncryptFileCount = x => x ^ fileCountKey; - crypto.DecryptFolderCount = x => x ^ folderCountKey; - crypto.EncryptFolderCount = x => x ^ folderCountKey; - return crypto; - } -} diff --git a/src/Parsec/Readers/Reader.cs b/src/Parsec/Readers/Reader.cs index 7e63d5a0..e8f6d33b 100644 --- a/src/Parsec/Readers/Reader.cs +++ b/src/Parsec/Readers/Reader.cs @@ -1,5 +1,6 @@ using System.Text; using Newtonsoft.Json; +using Parsec.Common; using Parsec.Extensions; using Parsec.Helpers; using Parsec.Shaiya.Core; @@ -13,50 +14,50 @@ public static class Reader /// Reads a shaiya file format from a file /// /// File path - /// Array of reading options + /// File episode /// Shaiya File Format Type /// T instance - public static T ReadFromFile(string path, params object[] options) where T : FileBase, new() => - FileBase.ReadFromFile(path, options); + public static T ReadFromFile(string path, Episode episode = Episode.EP5) where T : FileBase, new() => + FileBase.ReadFromFile(path, episode); /// /// Reads a shaiya file format from a file /// /// File path - /// Array of reading options + /// File episode /// Shaiya File Format Type - public static Task ReadFromFileAsync(string path, params object[] options) where T : FileBase, new() => - Task.FromResult(ReadFromFile(path, options)); + public static Task ReadFromFileAsync(string path, Episode episode = Episode.EP5) where T : FileBase, new() => + Task.FromResult(ReadFromFile(path, episode)); /// /// Reads the shaiya file format from a file /// /// File path /// FileBase child type to be read - /// Array of reading options + /// File episode /// FileBase instance - public static FileBase ReadFromFile(string path, Type type, params object[] options) => - FileBase.ReadFromFile(path, type, options); + public static FileBase ReadFromFile(string path, Type type, Episode episode = Episode.EP5) => + FileBase.ReadFromFile(path, type, episode); /// /// Reads the shaiya file format from a file /// /// File path /// FileBase child type to be read - /// Array of reading options - public static Task ReadFromFileAsync(string path, Type type, params object[] options) => - Task.FromResult(ReadFromFile(path, type, options)); + /// File episode + public static Task ReadFromFileAsync(string path, Type type, Episode episode = Episode.EP5) => + Task.FromResult(ReadFromFile(path, type, episode)); /// /// Reads a shaiya file format from a buffer (byte array) /// /// File name /// File buffer - /// Array of reading options + /// File episode /// Shaiya File Format Type /// T instance - public static T ReadFromBuffer(string name, byte[] buffer, params object[] options) where T : FileBase, new() => - FileBase.ReadFromBuffer(name, buffer, options); + public static T ReadFromBuffer(string name, byte[] buffer, Episode episode = Episode.EP5) where T : FileBase, new() => + FileBase.ReadFromBuffer(name, buffer, episode); /// @@ -64,10 +65,10 @@ public static Task ReadFromFileAsync(string path, Type type, params ob /// /// File name /// File buffer - /// Array of reading options + /// File episode /// Shaiya File Format Type - public static Task ReadFromBufferAsync(string name, byte[] buffer, params object[] options) where T : FileBase, new() => - Task.FromResult(ReadFromBuffer(name, buffer, options)); + public static Task ReadFromBufferAsync(string name, byte[] buffer, Episode episode = Episode.EP5) where T : FileBase, new() => + Task.FromResult(ReadFromBuffer(name, buffer, episode)); /// /// Reads the shaiya file format from a buffer (byte array) @@ -75,9 +76,9 @@ public static Task ReadFromFileAsync(string path, Type type, params ob /// File name /// File buffer /// FileBase child type to be read - /// Array of reading options + /// File episode /// FileBase instance - public static FileBase ReadFromBuffer(string name, byte[] buffer, Type type, params object[] options) => + public static FileBase ReadFromBuffer(string name, byte[] buffer, Type type, Episode episode = Episode.EP5) => FileBase.ReadFromBuffer(name, buffer, type); /// @@ -86,8 +87,8 @@ public static FileBase ReadFromBuffer(string name, byte[] buffer, Type type, par /// File name /// File buffer /// FileBase child type to be read - /// Array of reading options - public static Task ReadFromBufferAsync(string name, byte[] buffer, Type type, params object[] options) => + /// File episode + public static Task ReadFromBufferAsync(string name, byte[] buffer, Type type, Episode episode = Episode.EP5) => Task.FromResult(ReadFromBuffer(name, buffer, type)); /// @@ -219,19 +220,19 @@ public static Task ReadFromJsonAsync(string name, string jsonText, Typ /// /// instance /// instance - /// Array of reading options + /// File episode /// FileBase instance - public static T ReadFromData(Data data, SFile file, params object[] options) where T : FileBase, new() => - FileBase.ReadFromData(data, file, options); + public static T ReadFromData(Data data, SFile file, Episode episode = Episode.EP5) where T : FileBase, new() => + FileBase.ReadFromData(data, file, episode); /// /// Reads the shaiya file format from a buffer (byte array) within a instance /// /// instance /// instance - /// Array of reading options - public static Task ReadFromDataAsync(Data data, SFile file, params object[] options) where T : FileBase, new() => - Task.FromResult(ReadFromData(data, file, options)); + /// File episode + public static Task ReadFromDataAsync(Data data, SFile file, Episode episode = Episode.EP5) where T : FileBase, new() => + Task.FromResult(ReadFromData(data, file, episode)); /// /// Reads the shaiya file format from a buffer (byte array) within a instance @@ -239,10 +240,10 @@ public static Task ReadFromJsonAsync(string name, string jsonText, Typ /// instance /// instance /// FileBase child type to be read - /// Array of reading options + /// File episode /// FileBase instance - public static FileBase ReadFromData(Data data, SFile file, Type type, params object[] options) => - FileBase.ReadFromData(data, file, type, options); + public static FileBase ReadFromData(Data data, SFile file, Type type, Episode episode = Episode.EP5) => + FileBase.ReadFromData(data, file, type, episode); /// /// Reads the shaiya file format from a buffer (byte array) within a instance @@ -250,7 +251,7 @@ public static FileBase ReadFromData(Data data, SFile file, Type type, params obj /// instance /// instance /// FileBase child type to be read - /// Array of reading options - public static Task ReadFromDataAsync(Data data, SFile file, Type type, params object[] options) => - Task.FromResult(ReadFromData(data, file, type, options)); + /// File episode + public static Task ReadFromDataAsync(Data data, SFile file, Type type, Episode episode = Episode.EP5) => + Task.FromResult(ReadFromData(data, file, type, episode)); } diff --git a/src/Parsec/Shaiya/3DE/_3DE.cs b/src/Parsec/Shaiya/3DE/_3DE.cs index d699ad44..803cf297 100644 --- a/src/Parsec/Shaiya/3DE/_3DE.cs +++ b/src/Parsec/Shaiya/3DE/_3DE.cs @@ -42,7 +42,7 @@ public sealed class _3DE : FileBase /// Reads the .3DE file from the file buffer. This format requires a manually defined Read method because of its "complexity" when /// dealing with the vertex translation frames. /// - public override void Read(params object[] options) + public override void Read() { Texture = _binaryReader.ReadString(); diff --git a/src/Parsec/Shaiya/ALT/ALT.cs b/src/Parsec/Shaiya/ALT/ALT.cs index e847a2ef..656b082a 100644 --- a/src/Parsec/Shaiya/ALT/ALT.cs +++ b/src/Parsec/Shaiya/ALT/ALT.cs @@ -16,7 +16,7 @@ public sealed class ALT : FileBase public override string Extension => ".ALT"; - public override void Read(params object[] options) + public override void Read() { Signature = _binaryReader.ReadString(3); diff --git a/src/Parsec/Shaiya/Cloak/ClothTexture/CTL.cs b/src/Parsec/Shaiya/Cloak/ClothTexture/CTL.cs index 9f8f10fa..4bbf1b04 100644 --- a/src/Parsec/Shaiya/Cloak/ClothTexture/CTL.cs +++ b/src/Parsec/Shaiya/Cloak/ClothTexture/CTL.cs @@ -17,7 +17,7 @@ public CTL() [JsonIgnore] public override string Extension => "CTL"; - public override void Read(params object[] options) + public override void Read() { int textureCount = _binaryReader.Read(); for (int i = 0; i < textureCount; i++) diff --git a/src/Parsec/Shaiya/Cloak/Emblem/EmblemDat.cs b/src/Parsec/Shaiya/Cloak/Emblem/EmblemDat.cs index 0f82c6a8..28e2f89c 100644 --- a/src/Parsec/Shaiya/Cloak/Emblem/EmblemDat.cs +++ b/src/Parsec/Shaiya/Cloak/Emblem/EmblemDat.cs @@ -17,7 +17,7 @@ public EmblemDat() [JsonIgnore] public override string Extension => "dat"; - public override void Read(params object[] options) + public override void Read() { int textureCount = _binaryReader.Read(); for (int i = 0; i < textureCount; i++) diff --git a/src/Parsec/Shaiya/Core/FileBase.cs b/src/Parsec/Shaiya/Core/FileBase.cs index 4cbd8912..b063801f 100644 --- a/src/Parsec/Shaiya/Core/FileBase.cs +++ b/src/Parsec/Shaiya/Core/FileBase.cs @@ -64,8 +64,63 @@ public virtual string JsonSerialize(FileBase obj, params string[] ignoredPropert return JsonConvert.SerializeObject(obj, settings); } + /// + public virtual void Write(string path, Episode episode = Episode.Unknown) => FileHelper.WriteFile(path, GetBytes(episode)); + + /// + public virtual IEnumerable GetBytes(Episode episode = Episode.Unknown) + { + var buffer = new List(); + var type = GetType(); + + // If episode wasn't explicitly set, use former episode + if (episode == Episode.Unknown) + episode = Episode; + + if (episode == Episode.Unknown && type.IsDefined(typeof(DefaultVersionAttribute))) + { + var defaultEpisodeAttribute = type.GetCustomAttributes().FirstOrDefault(); + episode = defaultEpisodeAttribute!.Episode; + } + + // Add version prefix if present (eg. "ANI_V2", "MO2", "MO4", etc) + bool isVersionPrefixed = type.IsDefined(typeof(VersionPrefixedAttribute)); + if (isVersionPrefixed) + { + var versionPrefixes = type.GetCustomAttributes(); + + foreach (var versionPrefix in versionPrefixes) + { + if ((episode == versionPrefix.MinEpisode && versionPrefix.MaxEpisode == Episode.Unknown) || + (episode >= versionPrefix.MinEpisode && episode <= versionPrefix.MaxEpisode)) + { + if (versionPrefix.PrefixType == typeof(string)) + { + buffer.AddRange(((string)versionPrefix.Prefix).GetBytes()); + } + else if (versionPrefix.PrefixType.IsPrimitive) + { + buffer.AddRange(ReflectionHelper.GetPrimitiveBytes(versionPrefix.PrefixType, versionPrefix.Prefix)); + } + } + } + } + + // Get bytes for all properties + var properties = GetType().GetProperties(); + foreach (var property in properties) + { + if (!property.IsDefined(typeof(ShaiyaPropertyAttribute))) + continue; + + buffer.AddRange(ReflectionHelper.GetPropertyBytes(type, this, property, Encoding, episode)); + } + + return buffer; + } + /// - public virtual void Read(params object[] options) + public virtual void Read() { var type = GetType(); @@ -76,10 +131,6 @@ public virtual void Read(params object[] options) Episode = defaultEpisodeAttribute.Episode; } - // Set episode from options - if (options.Length > 0 && options[0] is Episode episode) - Episode = episode; - // Check if version prefix could be present (eg. "ANI_V2", "MO2", "MO4", etc) bool isVersionPrefixed = type.IsDefined(typeof(VersionPrefixedAttribute)); @@ -141,76 +192,21 @@ public virtual void Read(params object[] options) } } - /// - public virtual void Write(string path, Episode episode = Episode.Unknown) => FileHelper.WriteFile(path, GetBytes(episode)); - - /// - public virtual IEnumerable GetBytes(Episode episode = Episode.Unknown) - { - var buffer = new List(); - var type = GetType(); - - // If episode wasn't explicitly set, use former episode - if (episode == Episode.Unknown) - episode = Episode; - - if (episode == Episode.Unknown && type.IsDefined(typeof(DefaultVersionAttribute))) - { - var defaultEpisodeAttribute = type.GetCustomAttributes().FirstOrDefault(); - episode = defaultEpisodeAttribute!.Episode; - } - - // Add version prefix if present (eg. "ANI_V2", "MO2", "MO4", etc) - bool isVersionPrefixed = type.IsDefined(typeof(VersionPrefixedAttribute)); - if (isVersionPrefixed) - { - var versionPrefixes = type.GetCustomAttributes(); - - foreach (var versionPrefix in versionPrefixes) - { - if ((episode == versionPrefix.MinEpisode && versionPrefix.MaxEpisode == Episode.Unknown) || - (episode >= versionPrefix.MinEpisode && episode <= versionPrefix.MaxEpisode)) - { - if (versionPrefix.PrefixType == typeof(string)) - { - buffer.AddRange(((string)versionPrefix.Prefix).GetBytes()); - } - else if (versionPrefix.PrefixType.IsPrimitive) - { - buffer.AddRange(ReflectionHelper.GetPrimitiveBytes(versionPrefix.PrefixType, versionPrefix.Prefix)); - } - } - } - } - - // Get bytes for all properties - var properties = GetType().GetProperties(); - foreach (var property in properties) - { - if (!property.IsDefined(typeof(ShaiyaPropertyAttribute))) - continue; - - buffer.AddRange(ReflectionHelper.GetPropertyBytes(type, this, property, Encoding, episode)); - } - - return buffer; - } - /// /// Reads the shaiya file format from a file /// /// File path - /// Array of reading options + /// File episode /// Shaiya File Format Type /// T instance - public static T ReadFromFile(string path, params object[] options) where T : FileBase, new() + public static T ReadFromFile(string path, Episode episode = Episode.EP5) where T : FileBase, new() { - var instance = new T { Path = path, _binaryReader = new SBinaryReader(path) }; + var instance = new T { Path = path, _binaryReader = new SBinaryReader(path), Episode = episode }; if (instance is IEncryptable encryptableInstance) encryptableInstance.DecryptBuffer(); - instance.Read(options); + instance.Read(); instance._binaryReader?.Dispose(); return instance; @@ -221,9 +217,9 @@ public virtual IEnumerable GetBytes(Episode episode = Episode.Unknown) /// /// File path /// FileBase child type to be read - /// Array of reading options + /// File episode /// FileBase instance - public static FileBase ReadFromFile(string path, Type type, params object[] options) + public static FileBase ReadFromFile(string path, Type type, Episode episode = Episode.EP5) { if (!type.GetBaseClassesAndInterfaces().Contains(typeof(FileBase))) throw new ArgumentException("Type must be a child of FileBase"); @@ -232,12 +228,12 @@ public static FileBase ReadFromFile(string path, Type type, params object[] opti var instance = (FileBase)Activator.CreateInstance(type); instance.Path = path; instance._binaryReader = binaryReader; + instance.Episode = episode; if (instance is IEncryptable encryptableInstance) encryptableInstance.DecryptBuffer(); - // Parse the file - instance.Read(options); + instance.Read(); instance._binaryReader?.Dispose(); return instance; @@ -248,17 +244,17 @@ public static FileBase ReadFromFile(string path, Type type, params object[] opti /// /// File name /// File buffer - /// Array of reading options + /// File episode /// Shaiya File Format Type /// T instance - public static T ReadFromBuffer(string name, byte[] buffer, params object[] options) where T : FileBase, new() + public static T ReadFromBuffer(string name, byte[] buffer, Episode episode = Episode.EP5) where T : FileBase, new() { - var instance = new T { Path = name, _binaryReader = new SBinaryReader(buffer) }; + var instance = new T { Path = name, _binaryReader = new SBinaryReader(buffer), Episode = episode }; if (instance is IEncryptable encryptableInstance) encryptableInstance.DecryptBuffer(); - instance.Read(options); + instance.Read(); instance._binaryReader?.Dispose(); return instance; @@ -270,9 +266,9 @@ public static FileBase ReadFromFile(string path, Type type, params object[] opti /// File name /// File buffer /// FileBase child type to be read - /// Array of reading options + /// File episode /// FileBase instance - public static FileBase ReadFromBuffer(string name, byte[] buffer, Type type, params object[] options) + public static FileBase ReadFromBuffer(string name, byte[] buffer, Type type, Episode episode = Episode.EP5) { if (!type.GetBaseClassesAndInterfaces().Contains(typeof(FileBase))) throw new ArgumentException("Type must be a child of FileBase"); @@ -280,11 +276,12 @@ public static FileBase ReadFromBuffer(string name, byte[] buffer, Type type, par var instance = (FileBase)Activator.CreateInstance(type); instance.Path = name; instance._binaryReader = new SBinaryReader(buffer); + instance.Episode = episode; if (instance is IEncryptable encryptableInstance) encryptableInstance.DecryptBuffer(); - instance.Read(options); + instance.Read(); instance._binaryReader?.Dispose(); return instance; @@ -295,10 +292,10 @@ public static FileBase ReadFromBuffer(string name, byte[] buffer, Type type, par /// /// instance /// instance - /// Array of reading options + /// File episode /// FileBase instance - public static T ReadFromData(Data.Data data, SFile file, params object[] options) where T : FileBase, new() => - ReadFromBuffer(file.Name, data.GetFileBuffer(file), options); + public static T ReadFromData(Data.Data data, SFile file, Episode episode = Episode.EP5) where T : FileBase, new() => + ReadFromBuffer(file.Name, data.GetFileBuffer(file), episode); /// /// Reads the shaiya file format from a buffer (byte array) within a instance @@ -306,13 +303,13 @@ public static FileBase ReadFromBuffer(string name, byte[] buffer, Type type, par /// instance /// instance /// FileBase child type to be read - /// Array of reading options + /// File episode /// FileBase instance - public static FileBase ReadFromData(Data.Data data, SFile file, Type type, params object[] options) + public static FileBase ReadFromData(Data.Data data, SFile file, Type type, Episode episode = Episode.EP5) { if (!data.FileIndex.ContainsValue(file)) throw new FileNotFoundException("The provided SFile instance is not part of the Data"); - return ReadFromBuffer(file.Name, data.GetFileBuffer(file), type, options); + return ReadFromBuffer(file.Name, data.GetFileBuffer(file), type, episode); } } diff --git a/src/Parsec/Shaiya/Core/IFileBase.cs b/src/Parsec/Shaiya/Core/IFileBase.cs index 9ce6ef3b..970dc848 100644 --- a/src/Parsec/Shaiya/Core/IFileBase.cs +++ b/src/Parsec/Shaiya/Core/IFileBase.cs @@ -7,8 +7,7 @@ public interface IFileBase /// /// Reads and parses the file /// - /// Reading options - void Read(params object[] options); + void Read(); /// /// Writes the file to its original format diff --git a/src/Parsec/Shaiya/Data/Data.cs b/src/Parsec/Shaiya/Data/Data.cs index ff0d652e..62fb2cbe 100644 --- a/src/Parsec/Shaiya/Data/Data.cs +++ b/src/Parsec/Shaiya/Data/Data.cs @@ -1,5 +1,4 @@ -using Parsec.Cryptography; -using Parsec.Helpers; +using Parsec.Helpers; namespace Parsec.Shaiya.Data; @@ -11,7 +10,7 @@ public Data(Sah sah, Saf saf) Saf = saf; } - public Data(string path, SahCrypto crypto = null) + public Data(string path) { if (!FileHelper.FileExists(path)) throw new FileNotFoundException($"Data file not found at {path}"); @@ -20,7 +19,7 @@ public Data(string path, SahCrypto crypto = null) { case ".sah": { - Sah = Reader.ReadFromFile(path, crypto); + Sah = Reader.ReadFromFile(path); if (!FileHelper.FileExists(Sah.SafPath)) throw new FileNotFoundException("A valid saf file must be placed in the same directory as the sah file."); @@ -35,7 +34,7 @@ public Data(string path, SahCrypto crypto = null) if (!FileHelper.FileExists(Saf.SahPath)) throw new FileNotFoundException("A valid sah file must be placed in the same directory as the saf file."); - Sah = Reader.ReadFromFile(Saf.SahPath, crypto); + Sah = Reader.ReadFromFile(Saf.SahPath); break; } @@ -57,7 +56,7 @@ public Data(string path, SahCrypto crypto = null) /// /// The data's root folder from the sah index /// - public SFolder RootFolder => Sah.RootFolder; + public SDirectory RootDirectory => Sah.RootDirectory; /// /// The data's file count @@ -71,7 +70,7 @@ public int FileCount /// /// Dictionary of folders that can be accessed by path /// - public Dictionary FolderIndex => Sah.FolderIndex; + public Dictionary DirectoryIndex => Sah.DirectoryIndex; /// /// Dictionary of files that can be accessed by path @@ -82,9 +81,9 @@ public int FileCount /// Gets a data folder from the FolderIndex /// /// Folder path - public SFolder GetFolder(string path) + public SDirectory GetFolder(string path) { - FolderIndex.TryGetValue(path, out var folder); + DirectoryIndex.TryGetValue(path, out var folder); return folder; } @@ -102,29 +101,29 @@ public SFile GetFile(string path) /// Extracts the whole data file /// /// Extraction directory path - public void ExtractAll(string extractionDirectory) => Extract(Sah.RootFolder, extractionDirectory); + public void ExtractAll(string extractionDirectory) => Extract(Sah.RootDirectory, extractionDirectory); /// /// Extracts a shaiya folder from the saf file. If the folder to be extracted is the root folder, /// then the folder's content gets extracted in the provided extraction directory and if it's not, /// a child directory will be created inside the provided extraction directory /// - /// The instance to extract + /// The instance to extract /// Extraction directory path - public void Extract(SFolder folder, string extractionDirectory) + public void Extract(SDirectory directory, string extractionDirectory) { string extractionPath = extractionDirectory; - if (folder != Sah.RootFolder) - extractionPath = Path.Combine(extractionDirectory, folder.RelativePath); + if (directory != Sah.RootDirectory) + extractionPath = Path.Combine(extractionDirectory, directory.RelativePath); if (!FileHelper.CreateDirectory(extractionPath)) return; - foreach (var file in folder.Files) + foreach (var file in directory.Files) Extract(file, extractionPath); - foreach (var subfolder in folder.Subfolders) + foreach (var subfolder in directory.Directories) Extract(subfolder, extractionDirectory); } @@ -156,7 +155,7 @@ public void RemoveFile(string path) return; Sah.FileCount--; - file.ParentFolder.Files.Remove(file); + file.ParentDirectory.Files.Remove(file); FileIndex.Remove(path); Saf.ClearBytes(file.Offset, file.Length); diff --git a/src/Parsec/Shaiya/Data/DataBuilder.cs b/src/Parsec/Shaiya/Data/DataBuilder.cs index 74dec6db..9b580890 100644 --- a/src/Parsec/Shaiya/Data/DataBuilder.cs +++ b/src/Parsec/Shaiya/Data/DataBuilder.cs @@ -42,7 +42,7 @@ public static Data CreateFromDirectory(string inputFolderPath, string outputFold _safWriter = new BinaryWriter(File.OpenWrite(safPath)); - var rootFolder = new SFolder(null); + var rootFolder = new SDirectory(null); ReadFolderFromDirectory(rootFolder, inputFolderPath); var sah = new Sah(inputFolderPath, rootFolder, _fileCount); @@ -63,19 +63,19 @@ public static Data CreateFromDirectory(string inputFolderPath, string outputFold } /// - /// Reads a folder's content and assigns it to a instance + /// Reads a folder's content and assigns it to a instance /// - /// The instance + /// The instance /// Directory path - private static void ReadFolderFromDirectory(SFolder folder, string directoryPath) + private static void ReadFolderFromDirectory(SDirectory directory, string directoryPath) { - ReadFilesFromDirectory(folder, directoryPath); + ReadFilesFromDirectory(directory, directoryPath); var subfolders = Directory.GetDirectories(directoryPath).Select(sf => new DirectoryInfo(sf).Name); foreach (var subfolder in subfolders) { - var shaiyaFolder = new SFolder(folder) { Name = subfolder, ParentFolder = folder }; - folder.AddSubfolder(shaiyaFolder); + var shaiyaFolder = new SDirectory(directory) { Name = subfolder, ParentDirectory = directory }; + directory.AddDirectory(shaiyaFolder); ReadFolderFromDirectory(shaiyaFolder, Path.Combine(directoryPath, subfolder)); } } @@ -83,9 +83,9 @@ private static void ReadFolderFromDirectory(SFolder folder, string directoryPath /// /// Reads the files inside a directory and adds them to a ShaiyaFolder instance /// - /// The shaiya folder instance + /// The shaiya folder instance /// Directory path - private static void ReadFilesFromDirectory(SFolder folder, string directoryPath) + private static void ReadFilesFromDirectory(SDirectory directory, string directoryPath) { var files = Directory.GetFiles(directoryPath).Select(Path.GetFileName); @@ -95,10 +95,10 @@ private static void ReadFilesFromDirectory(SFolder folder, string directoryPath) var fileStream = File.OpenRead(filePath); - var shaiyaFile = new SFile(folder) { Name = file, Length = (int)fileStream.Length }; + var shaiyaFile = new SFile(directory) { Name = file, Length = (int)fileStream.Length }; WriteFile(shaiyaFile); - folder.AddFile(shaiyaFile); + directory.AddFile(shaiyaFile); _fileCount++; } diff --git a/src/Parsec/Shaiya/Data/DataPatcher.cs b/src/Parsec/Shaiya/Data/DataPatcher.cs index 7710b723..8aa1d349 100644 --- a/src/Parsec/Shaiya/Data/DataPatcher.cs +++ b/src/Parsec/Shaiya/Data/DataPatcher.cs @@ -71,7 +71,7 @@ private void PatchFiles(Data targetData, Data patchData, Action filePatchedCallb var offset = AppendFile(patchFile); patchFile.Offset = offset; - var folder = targetData.Sah.EnsureFolderExists(patchFile.ParentFolder.RelativePath); + var folder = targetData.Sah.EnsureFolderExists(patchFile.ParentDirectory.RelativePath); folder.AddFile(patchFile); targetData.FileCount++; diff --git a/src/Parsec/Shaiya/Data/SFolder.cs b/src/Parsec/Shaiya/Data/SDirectory.cs similarity index 53% rename from src/Parsec/Shaiya/Data/SFolder.cs rename to src/Parsec/Shaiya/Data/SDirectory.cs index ebc69275..71a51b98 100644 --- a/src/Parsec/Shaiya/Data/SFolder.cs +++ b/src/Parsec/Shaiya/Data/SDirectory.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using Newtonsoft.Json; -using Parsec.Cryptography; using Parsec.Extensions; using Parsec.Readers; using Parsec.Shaiya.Core; @@ -8,43 +7,39 @@ namespace Parsec.Shaiya.Data; [DataContract] -public sealed class SFolder : IBinary +public sealed class SDirectory : IBinary { [JsonConstructor] - public SFolder() + public SDirectory() { } - public SFolder(SFolder parentFolder) + public SDirectory(SDirectory parentDirectory) { - ParentFolder = parentFolder; + ParentDirectory = parentDirectory; } - public SFolder( + public SDirectory( SBinaryReader binaryReader, - SFolder parentFolder, - Dictionary folderIndex, - Dictionary fileIndex, - SahCrypto crypto = null + SDirectory parentDirectory, + Dictionary directoryIndex, + Dictionary fileIndex ) { - ParentFolder = parentFolder; + ParentDirectory = parentDirectory; Name = binaryReader.ReadString(); // Make root folder's name empty and store its real name, this is done to avoid confusion when retrieving files and folders // from episodes where the root folder's name isn't empty ("data" in episode 8) - if (parentFolder == null) + if (parentDirectory == null) { RealName = Name; Name = string.Empty; } - folderIndex.Add(RelativePath, this); + directoryIndex.Add(RelativePath, this); int fileCount = binaryReader.Read(); - // Decrypt value - if (crypto != null) - fileCount = crypto.DecryptFileCount(fileCount); // Read all files in this folder for (int i = 0; i < fileCount; i++) @@ -54,19 +49,16 @@ public SFolder( } int subfolderCount = binaryReader.Read(); - // Decrypt value - if (crypto != null) - subfolderCount = crypto.DecryptFolderCount(subfolderCount); // Recursively read subfolders data for (int i = 0; i < subfolderCount; i++) { - var subfolder = new SFolder(binaryReader, this, folderIndex, fileIndex, crypto); - AddSubfolder(subfolder); + var subfolder = new SDirectory(binaryReader, this, directoryIndex, fileIndex); + AddDirectory(subfolder); } } - public SFolder(string name, SFolder parentFolder) : this(parentFolder) + public SDirectory(string name, SDirectory parentDirectory) : this(parentDirectory) { Name = name; } @@ -82,9 +74,9 @@ public SFolder(string name, SFolder parentFolder) : this(parentFolder) /// /// The relative path to the folder /// - public string RelativePath => ParentFolder == null || string.IsNullOrEmpty(ParentFolder.Name) + public string RelativePath => ParentDirectory == null || string.IsNullOrEmpty(ParentDirectory.Name) ? Name - : Path.Combine(ParentFolder.RelativePath, Name); + : Path.Combine(ParentDirectory.RelativePath, Name); /// /// List of files the folder has @@ -96,40 +88,20 @@ public SFolder(string name, SFolder parentFolder) : this(parentFolder) /// List of subfolders the file has /// [DataMember] - public List Subfolders { get; } = new(); + public List Directories { get; } = new(); /// /// The folder's parent directory /// - public SFolder ParentFolder { get; set; } + public SDirectory ParentDirectory { get; set; } /// public IEnumerable GetBytes(params object[] options) { - var crypto = SahCrypto.Default; - if (options.Length > 0) - crypto = (SahCrypto)options[0]; - var buffer = new List(); - - buffer.AddRange(ParentFolder == null ? RealName.GetLengthPrefixedBytes() : Name.GetLengthPrefixedBytes()); - - int fileCount = Files.Count; - if (crypto != null) - fileCount = crypto.EncryptFileCount(Files.Count); - - buffer.AddRange(fileCount.GetBytes()); - foreach (var file in Files) - buffer.AddRange(file.GetBytes()); - - int subfolderCount = Subfolders.Count; - if (crypto != null) - subfolderCount = crypto.EncryptFolderCount(subfolderCount); - - buffer.AddRange(subfolderCount.GetBytes()); - foreach (var subfolder in Subfolders) - buffer.AddRange(subfolder.GetBytes(crypto)); - + buffer.AddRange(ParentDirectory == null ? RealName.GetLengthPrefixedBytes() : Name.GetLengthPrefixedBytes()); + buffer.AddRange(Files.GetBytes()); + buffer.AddRange(Directories.GetBytes()); return buffer; } @@ -141,22 +113,22 @@ public IEnumerable GetBytes(params object[] options) public void AddFile(SFile file) { if (HasFile(file.Name)) - file.Name += "_pv"; + throw new Exception($"File {file.Name} already exists in folder {Name}"); Files.Add(file); } /// - /// Adds a child to this folder + /// Adds a child to this directory /// - /// The subfolder instance - /// When subfolder with the same name already existed - public void AddSubfolder(SFolder subfolder) + /// The subdirectory instance + /// When subdirectory with the same name already existed + public void AddDirectory(SDirectory childDirectory) { - if (HasSubfolder(subfolder.Name)) - throw new Exception($"Folder {subfolder.Name} already exists in {Name}"); + if (HasSubfolder(childDirectory.Name)) + throw new Exception($"Subdirectory {childDirectory.Name} already exists in directory {Name}"); - Subfolders.Add(subfolder); + Directories.Add(childDirectory); } /// @@ -169,7 +141,7 @@ public void AddSubfolder(SFolder subfolder) /// Checks if a folder contains a subfolder with a specified name /// /// Subfolder name to check - public bool HasSubfolder(string name) => Subfolders.Any(sf => sf.Name == name); + public bool HasSubfolder(string name) => Directories.Any(sf => sf.Name == name); /// /// Gets a folder's file @@ -181,5 +153,5 @@ public void AddSubfolder(SFolder subfolder) /// Gets a folder's subfolder /// /// Subfolder name - public SFolder GetSubfolder(string name) => Subfolders.FirstOrDefault(sf => sf.Name == name); + public SDirectory GetSubfolder(string name) => Directories.FirstOrDefault(sf => sf.Name == name); } diff --git a/src/Parsec/Shaiya/Data/SFile.cs b/src/Parsec/Shaiya/Data/SFile.cs index 249e707f..93f51b18 100644 --- a/src/Parsec/Shaiya/Data/SFile.cs +++ b/src/Parsec/Shaiya/Data/SFile.cs @@ -14,9 +14,9 @@ public SFile() { } - public SFile(SFolder parentFolder) + public SFile(SDirectory parentDirectory) { - ParentFolder = parentFolder; + ParentDirectory = parentDirectory; } public SFile(string name, long offset, int length) @@ -26,7 +26,7 @@ public SFile(string name, long offset, int length) Length = length; } - public SFile(SBinaryReader binaryReader, SFolder folder, Dictionary fileIndex) : this(folder) + public SFile(SBinaryReader binaryReader, SDirectory directory, Dictionary fileIndex) : this(directory) { Name = binaryReader.ReadString(); Offset = binaryReader.Read(); @@ -64,14 +64,14 @@ public SFile(SBinaryReader binaryReader, SFolder folder, Dictionary /// The relative path to the file /// - public string RelativePath => ParentFolder == null || string.IsNullOrEmpty(ParentFolder.Name) + public string RelativePath => ParentDirectory == null || string.IsNullOrEmpty(ParentDirectory.Name) ? Name - : Path.Combine(ParentFolder.RelativePath, Name); + : Path.Combine(ParentDirectory.RelativePath, Name); /// /// The directory in which the file is /// - public SFolder ParentFolder { get; set; } + public SDirectory ParentDirectory { get; set; } /// public IEnumerable GetBytes(params object[] options) diff --git a/src/Parsec/Shaiya/Data/Sah.cs b/src/Parsec/Shaiya/Data/Sah.cs index 79124406..e59aa996 100644 --- a/src/Parsec/Shaiya/Data/Sah.cs +++ b/src/Parsec/Shaiya/Data/Sah.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using Newtonsoft.Json; using Parsec.Common; -using Parsec.Cryptography; using Parsec.Extensions; using Parsec.Shaiya.Core; @@ -18,7 +17,7 @@ public sealed class Sah : FileBase /// /// Dictionary of folders that can be accessed by path /// - public Dictionary FolderIndex = new(StringComparer.InvariantCultureIgnoreCase); + public Dictionary DirectoryIndex = new(StringComparer.InvariantCultureIgnoreCase); [JsonConstructor] public Sah() @@ -29,12 +28,12 @@ public Sah() /// Constructor used when creating a sah file from a directory /// /// Path where sah file will be saved - /// Shaiya main Folder containing all the sah's data + /// Shaiya main Folder containing all the sah's data /// - public Sah(string path, SFolder rootFolder, int fileCount) + public Sah(string path, SDirectory rootDirectory, int fileCount) { Path = path; - RootFolder = rootFolder; + RootDirectory = rootDirectory; FileCount = fileCount; } @@ -63,24 +62,14 @@ public Sah(string path, SFolder rootFolder, int fileCount) /// The data's root directory. /// [DataMember] - public SFolder RootFolder { get; set; } - - /// - /// Defines how file and folder counts should be encrypted/decrypted. - /// - public SahCrypto Crypto { get; set; } + public SDirectory RootDirectory { get; set; } [JsonIgnore] public override string Extension => "sah"; - public void ResetEncryption() => Crypto = null; - /// - public override void Read(params object[] options) + public override void Read() { - if (options.Length > 0) - Crypto = (SahCrypto)options[0]; - Signature = _binaryReader.ReadString(3); Version = _binaryReader.Read(); FileCount = _binaryReader.Read(); @@ -88,15 +77,14 @@ public override void Read(params object[] options) // Index where data starts (after header - skip padding bytes) _binaryReader.Skip(40); - // Read root folder and all of its subfolders - RootFolder = new SFolder(_binaryReader, null, FolderIndex, FileIndex, Crypto); + RootDirectory = new SDirectory(_binaryReader, null, DirectoryIndex, FileIndex); } /// /// Adds a folder to the sah file /// /// Folder's path - public SFolder AddFolder(string path) => EnsureFolderExists(path); + public SDirectory AddFolder(string path) => EnsureFolderExists(path); /// /// Adds a file to the sah file @@ -106,7 +94,7 @@ public override void Read(params object[] options) public void AddFile(string directoryPath, SFile file) { var parentFolder = AddFolder(directoryPath); - file.ParentFolder = parentFolder; + file.ParentDirectory = parentFolder; parentFolder.AddFile(file); FileIndex.Add(file.RelativePath, file); @@ -116,22 +104,22 @@ public void AddFile(string directoryPath, SFile file) /// Checks if a folder exists based on its path. If it doesn't exist, it will be created /// /// Folder path - public SFolder EnsureFolderExists(string path) + public SDirectory EnsureFolderExists(string path) { - if (FolderIndex.TryGetValue(path, out var matchingFolder)) + if (DirectoryIndex.TryGetValue(path, out var matchingFolder)) return matchingFolder; var pathFolders = path.Separate().ToList(); - var currentFolder = RootFolder; + var currentFolder = RootDirectory; foreach (string folderName in pathFolders) { if (!currentFolder.HasSubfolder(folderName)) { - var newFolder = new SFolder(folderName, currentFolder); - currentFolder.AddSubfolder(newFolder); + var newFolder = new SDirectory(folderName, currentFolder); + currentFolder.AddDirectory(newFolder); - FolderIndex.Add(newFolder.RelativePath, newFolder); + DirectoryIndex.Add(newFolder.RelativePath, newFolder); currentFolder = newFolder; } else @@ -147,7 +135,7 @@ public SFolder EnsureFolderExists(string path) /// Checks if the sah has a folder with the given path /// /// Folder's relative path (ie. "Character/Human") - public bool HasFolder(string relativePath) => FolderIndex.ContainsKey(relativePath); + public bool HasFolder(string relativePath) => DirectoryIndex.ContainsKey(relativePath); /// /// Checks if the sah has a file with the given path @@ -162,12 +150,8 @@ public override IEnumerable GetBytes(Episode episode = Episode.Unknown) buffer.AddRange(Signature.GetBytes()); buffer.AddRange(Version.GetBytes()); buffer.AddRange(FileCount.GetBytes()); - - // Padding - buffer.AddRange(new byte[40]); - - buffer.AddRange(RootFolder.GetBytes(Crypto)); - + buffer.AddRange(new byte[40]); // Padding + buffer.AddRange(RootDirectory.GetBytes()); // Suffix with 8 empty bytes - I don't think the game cares about these at all, but some other tools do buffer.AddRange(new byte[8]); return buffer; diff --git a/src/Parsec/Shaiya/EFT/EFT.cs b/src/Parsec/Shaiya/EFT/EFT.cs index 40f31acd..028d1ea5 100644 --- a/src/Parsec/Shaiya/EFT/EFT.cs +++ b/src/Parsec/Shaiya/EFT/EFT.cs @@ -18,7 +18,7 @@ public sealed class EFT : FileBase [JsonIgnore] public override string Extension => "EFT"; - public override void Read(params object[] options) + public override void Read() { string signature = _binaryReader.ReadString(3); diff --git a/src/Parsec/Shaiya/GuildHouse/GuildHouse.cs b/src/Parsec/Shaiya/GuildHouse/GuildHouse.cs index 34868618..cfc3a676 100644 --- a/src/Parsec/Shaiya/GuildHouse/GuildHouse.cs +++ b/src/Parsec/Shaiya/GuildHouse/GuildHouse.cs @@ -16,7 +16,7 @@ public sealed class GuildHouse : SData.SData public List Npcs { get; set; } = new(); /// - public override void Read(params object[] options) + public override void Read() { Unknown = _binaryReader.Read(); HousePrice = _binaryReader.Read(); diff --git a/src/Parsec/Shaiya/ITM/ITM.cs b/src/Parsec/Shaiya/ITM/ITM.cs index f1dba368..9a038754 100644 --- a/src/Parsec/Shaiya/ITM/ITM.cs +++ b/src/Parsec/Shaiya/ITM/ITM.cs @@ -33,7 +33,7 @@ public sealed class ITM : FileBase [JsonIgnore] public override string Extension => "ITM"; - public override void Read(params object[] options) + public override void Read() { Signature = _binaryReader.ReadString(3); diff --git a/src/Parsec/Shaiya/Item/Item.cs b/src/Parsec/Shaiya/Item/Item.cs index 39ea1be5..998efac4 100644 --- a/src/Parsec/Shaiya/Item/Item.cs +++ b/src/Parsec/Shaiya/Item/Item.cs @@ -44,13 +44,8 @@ public void WriteCsv(string outputPath) } } - public override void Read(params object[] options) + public override void Read() { - Episode = Episode.EP5; - - if (options.Length > 0) - Episode = (Episode)options[0]; - MaxType = _binaryReader.Read(); for (int i = 0; i < MaxType; i++) { diff --git a/src/Parsec/Shaiya/MAni/MAni.cs b/src/Parsec/Shaiya/MAni/MAni.cs index e43fb44c..99552a61 100644 --- a/src/Parsec/Shaiya/MAni/MAni.cs +++ b/src/Parsec/Shaiya/MAni/MAni.cs @@ -65,7 +65,7 @@ public sealed class MAni : FileBase public override string Extension => "mani"; - public override void Read(params object[] options) + public override void Read() { Version = _binaryReader.Read(); Unknown1 = _binaryReader.Read(); diff --git a/src/Parsec/Shaiya/MLT/MLT.cs b/src/Parsec/Shaiya/MLT/MLT.cs index 22d3a62e..408eaf9c 100644 --- a/src/Parsec/Shaiya/MLT/MLT.cs +++ b/src/Parsec/Shaiya/MLT/MLT.cs @@ -28,7 +28,7 @@ public sealed class MLT : FileBase public override string Extension => "MLT"; - public override void Read(params object[] options) + public override void Read() { Signature = _binaryReader.ReadString(3); diff --git a/src/Parsec/Shaiya/MLX/MLX.cs b/src/Parsec/Shaiya/MLX/MLX.cs index 93d6471f..1ff250f2 100644 --- a/src/Parsec/Shaiya/MLX/MLX.cs +++ b/src/Parsec/Shaiya/MLX/MLX.cs @@ -15,7 +15,7 @@ public sealed class MLX : FileBase public MLXFormat Format { get; set; } = MLXFormat.MLX1; - public override void Read(params object[] options) + public override void Read() { // For some reason, sometimes MLX files are empty if (_binaryReader.Length == 0) diff --git a/src/Parsec/Shaiya/MON/MON.cs b/src/Parsec/Shaiya/MON/MON.cs index b9a4c3df..4d28250e 100644 --- a/src/Parsec/Shaiya/MON/MON.cs +++ b/src/Parsec/Shaiya/MON/MON.cs @@ -17,7 +17,7 @@ public sealed class MON : FileBase public override string Extension => "MON"; - public override void Read(params object[] options) + public override void Read() { Signature = _binaryReader.ReadString(3); diff --git a/src/Parsec/Shaiya/Monster/Monster.cs b/src/Parsec/Shaiya/Monster/Monster.cs index 5c82844e..a22745af 100644 --- a/src/Parsec/Shaiya/Monster/Monster.cs +++ b/src/Parsec/Shaiya/Monster/Monster.cs @@ -29,7 +29,7 @@ public void WriteCsv(string outputPath) csvWriter.WriteRecords(Records); } - public override void Read(params object[] options) + public override void Read() { int recordCount = _binaryReader.Read(); for (int i = 0; i < recordCount; i++) diff --git a/src/Parsec/Shaiya/NpcQuest/NpcQuest.cs b/src/Parsec/Shaiya/NpcQuest/NpcQuest.cs index 8aa9b560..badbbaac 100644 --- a/src/Parsec/Shaiya/NpcQuest/NpcQuest.cs +++ b/src/Parsec/Shaiya/NpcQuest/NpcQuest.cs @@ -21,16 +21,8 @@ public class NpcQuest : SData.SData public byte[] UnknownArray { get; set; } public List Quests { get; } = new(); - public override void Read(params object[] options) + public override void Read() { - Episode = Episode.EP5; - - if (options.Length > 0) - { - object format = options[0]; - Episode = (Episode)format; - } - ReadMerchants(); ReadGatekeepers(); ReadStandardNpcs(Blacksmiths); diff --git a/src/Parsec/Shaiya/SData/BinarySData.cs b/src/Parsec/Shaiya/SData/BinarySData.cs index 410c477a..826b04a1 100644 --- a/src/Parsec/Shaiya/SData/BinarySData.cs +++ b/src/Parsec/Shaiya/SData/BinarySData.cs @@ -24,7 +24,7 @@ namespace Parsec.Shaiya.SData; [ShaiyaProperty] public List Records { get; set; } = new(); - public override void Read(params object[] options) + public override void Read() { Header = _binaryReader.ReadBytes(128); int fieldCount = _binaryReader.Read(); diff --git a/src/Parsec/Shaiya/SMOD/SMOD.cs b/src/Parsec/Shaiya/SMOD/SMOD.cs index 202a2702..631a8438 100644 --- a/src/Parsec/Shaiya/SMOD/SMOD.cs +++ b/src/Parsec/Shaiya/SMOD/SMOD.cs @@ -48,7 +48,7 @@ public sealed class SMOD : FileBase public List CollisionObjects { get; set; } = new(); /// - public override void Read(params object[] options) + public override void Read() { Center = new Vector3(_binaryReader); DistanceToCenter = _binaryReader.Read(); diff --git a/src/Parsec/Shaiya/Seff/Seff.cs b/src/Parsec/Shaiya/Seff/Seff.cs index cc119d36..e8a483c0 100644 --- a/src/Parsec/Shaiya/Seff/Seff.cs +++ b/src/Parsec/Shaiya/Seff/Seff.cs @@ -14,7 +14,7 @@ public sealed class Seff : FileBase [JsonIgnore] public override string Extension => "seff"; - public override void Read(params object[] options) + public override void Read() { Format = _binaryReader.Read(); TimeStamp.Year = _binaryReader.Read(); diff --git a/src/Parsec/Shaiya/SetItem/SetItem.cs b/src/Parsec/Shaiya/SetItem/SetItem.cs index f0ebb256..a8c03310 100644 --- a/src/Parsec/Shaiya/SetItem/SetItem.cs +++ b/src/Parsec/Shaiya/SetItem/SetItem.cs @@ -7,7 +7,7 @@ public sealed class SetItem : SData.SData { public List Records { get; } = new(); - public override void Read(params object[] options) + public override void Read() { int recordCount = _binaryReader.Read(); for (int i = 0; i < recordCount; i++) diff --git a/src/Parsec/Shaiya/Skill/Skill.cs b/src/Parsec/Shaiya/Skill/Skill.cs index e0ee6db4..bb18aad9 100644 --- a/src/Parsec/Shaiya/Skill/Skill.cs +++ b/src/Parsec/Shaiya/Skill/Skill.cs @@ -9,23 +9,16 @@ public sealed class Skill : SData.SData, ICsv { public List Records { get; set; } = new(); - public override void Read(params object[] options) + public override void Read() { - var episode = Episode.EP5; - - if (options.Length > 0) - { - episode = (Episode)options[0]; - } - var skillCount = _binaryReader.Read(); - var recordCountPerSkill = GetRecordCountPerSkill(episode); + var recordCountPerSkill = GetRecordCountPerSkill(Episode); for (int skillId = 0; skillId < skillCount; skillId++) { for (int i = 0; i < recordCountPerSkill; i++) { - var record = new SkillRecord(_binaryReader, episode, skillId); + var record = new SkillRecord(_binaryReader, Episode, skillId); Records.Add(record); } } diff --git a/src/Parsec/Shaiya/Svmap/Svmap.cs b/src/Parsec/Shaiya/Svmap/Svmap.cs index 40563114..0321ede9 100644 --- a/src/Parsec/Shaiya/Svmap/Svmap.cs +++ b/src/Parsec/Shaiya/Svmap/Svmap.cs @@ -25,7 +25,7 @@ public Svmap() [JsonIgnore] public override string Extension => "svmap"; - public override void Read(params object[] options) + public override void Read() { MapSize = _binaryReader.Read(); int mapHeightCount = MapSize * MapSize / 8; diff --git a/src/Parsec/Shaiya/VAni/VAni.cs b/src/Parsec/Shaiya/VAni/VAni.cs index 36542d49..f51a757d 100644 --- a/src/Parsec/Shaiya/VAni/VAni.cs +++ b/src/Parsec/Shaiya/VAni/VAni.cs @@ -43,7 +43,7 @@ public sealed class VAni : FileBase public override string Extension => "VANI"; - public override void Read(params object[] options) + public override void Read() { Center = new Vector3(_binaryReader); DistanceToCenter = _binaryReader.Read(); diff --git a/src/Parsec/Shaiya/Wld/WLD.cs b/src/Parsec/Shaiya/Wld/WLD.cs index 978a1ba0..250ac828 100644 --- a/src/Parsec/Shaiya/Wld/WLD.cs +++ b/src/Parsec/Shaiya/Wld/WLD.cs @@ -164,7 +164,7 @@ public sealed class WLD : FileBase [JsonIgnore] public override string Extension => "wld"; - public override void Read(params object[] options) + public override void Read() { string typeStr = _binaryReader.ReadString(4).Trim('\0'); diff --git a/src/Parsec/Shaiya/Wtr/Wtr.cs b/src/Parsec/Shaiya/Wtr/Wtr.cs index 2d484cb6..9c412781 100644 --- a/src/Parsec/Shaiya/Wtr/Wtr.cs +++ b/src/Parsec/Shaiya/Wtr/Wtr.cs @@ -18,7 +18,7 @@ public sealed class Wtr : FileBase public override string Extension => "wtr"; - public override void Read(params object[] options) + public override void Read() { Unknown1 = _binaryReader.Read(); Unknown2 = _binaryReader.Read(); diff --git a/src/Parsec/Shaiya/Zon/Zon.cs b/src/Parsec/Shaiya/Zon/Zon.cs index 36fd8b3c..8937fa0c 100644 --- a/src/Parsec/Shaiya/Zon/Zon.cs +++ b/src/Parsec/Shaiya/Zon/Zon.cs @@ -11,7 +11,7 @@ public sealed class Zon : FileBase public override string Extension => "zon"; - public override void Read(params object[] options) + public override void Read() { Format = _binaryReader.Read(); diff --git a/tests/Parsec.Tests/Shaiya/Data/DataTests.cs b/tests/Parsec.Tests/Shaiya/Data/DataTests.cs index e98e8f08..bc1a32d9 100644 --- a/tests/Parsec.Tests/Shaiya/Data/DataTests.cs +++ b/tests/Parsec.Tests/Shaiya/Data/DataTests.cs @@ -17,7 +17,7 @@ public void DataReadingTest() var dataFromSaf = new Parsec.Shaiya.Data.Data("Shaiya/Data/sample.saf"); Assert.Equal(dataFromSah.FileIndex.Count, dataFromSaf.FileIndex.Count); - Assert.Equal(dataFromSah.FolderIndex.Count, dataFromSaf.FolderIndex.Count); + Assert.Equal(dataFromSah.DirectoryIndex.Count, dataFromSaf.DirectoryIndex.Count); } [Fact] @@ -50,8 +50,8 @@ public void DataFolderExtractionTest() var data = new Parsec.Shaiya.Data.Data("Shaiya/Data/sample.sah"); const string extractionDirectory = "Shaiya/Data/single_folder_extraction"; - var folder1 = data.RootFolder.Subfolders.FirstOrDefault(); - var folder2 = data.RootFolder.Subfolders.LastOrDefault(); + var folder1 = data.RootDirectory.Directories.FirstOrDefault(); + var folder2 = data.RootDirectory.Directories.LastOrDefault(); if (folder1 == null || folder2 == null) throw new XunitException("Folder not found in RootFolder"); diff --git a/tests/Parsec.Tests/Shaiya/Data/SahTests.cs b/tests/Parsec.Tests/Shaiya/Data/SahTests.cs index f4ef036d..dfce7e59 100644 --- a/tests/Parsec.Tests/Shaiya/Data/SahTests.cs +++ b/tests/Parsec.Tests/Shaiya/Data/SahTests.cs @@ -1,6 +1,5 @@ using System; using System.ComponentModel; -using Parsec.Cryptography; using Parsec.Shaiya.Data; namespace Parsec.Tests.Shaiya; @@ -33,35 +32,34 @@ public void SahFileExistenceTest(string folderName, string fileName) var newSubfolder = sah.AddFolder($"{folderName}/sub"); Assert.True(newFolder.HasSubfolder("sub")); - // Try to add the file and subfolder again - newFolder.AddFile(newFile1); - Assert.True(newFolder.HasFile($"{fileName}_pv")); - Assert.Throws(() => newFolder.AddSubfolder(newSubfolder)); + // Try to re-add file and folder + Assert.Throws(() => newFolder.AddFile(newFile1)); + Assert.Throws(() => newFolder.AddDirectory(newSubfolder)); } - [Fact] - public void SahEncryptionTest() - { - var crypto = SahCrypto.WithFileCountXorKey(0x55); - var sah = Reader.ReadFromFile("Shaiya/Data/sample.enc0x55.sah", crypto); - sah.Write("Shaiya/Data/sample.new.enc0x55.sah"); - var cs1 = FileHash.Checksum("Shaiya/Data/sample.enc0x55.sah"); - var cs2 = FileHash.Checksum("Shaiya/Data/sample.new.enc0x55.sah"); - Assert.Equal(cs1, cs2); - - sah.ResetEncryption(); - sah.Write("Shaiya/Data/sample.new.sah"); - var cs3 = FileHash.Checksum("Shaiya/Data/sample.sah"); - var cs4 = FileHash.Checksum("Shaiya/Data/sample.new.sah"); - Assert.Equal(cs3, cs4); - } + // [Fact] + // public void SahEncryptionTest() + // { + // var crypto = SahCrypto.WithFileCountXorKey(0x55); + // var sah = Reader.ReadFromFile("Shaiya/Data/sample.enc0x55.sah", crypto); + // sah.Write("Shaiya/Data/sample.new.enc0x55.sah"); + // var cs1 = FileHash.Checksum("Shaiya/Data/sample.enc0x55.sah"); + // var cs2 = FileHash.Checksum("Shaiya/Data/sample.new.enc0x55.sah"); + // Assert.Equal(cs1, cs2); + // + // sah.ResetEncryption(); + // sah.Write("Shaiya/Data/sample.new.sah"); + // var cs3 = FileHash.Checksum("Shaiya/Data/sample.sah"); + // var cs4 = FileHash.Checksum("Shaiya/Data/sample.new.sah"); + // Assert.Equal(cs3, cs4); + // } [Fact] [Description("Test that checks if the Sah subclasses can be instanciated with an empty constructor for json deserialization")] public void SahJsonCreationTest() { var sah = new Sah(); - var folder = new SFolder(); + var folder = new SDirectory(); var file = new SFile(); Assert.NotNull(sah);