From 723f687dbdc2bda806e810e504437b0542d66a34 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Wed, 15 Apr 2020 05:53:49 -0600 Subject: [PATCH] Several fixes for BSA compiling --- Compression.BSA/BSABuilder.cs | 2 +- Wabbajack.Common/Json.cs | 13 ++++++++++++- Wabbajack.Common/Util/DiskSlabAllocator.cs | 6 +++++- Wabbajack.Lib/CompilationSteps/DeconstructBSAs.cs | 2 +- Wabbajack.Lib/CompilationSteps/IncludeDummyESPs.cs | 2 +- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Compression.BSA/BSABuilder.cs b/Compression.BSA/BSABuilder.cs index 36120877..1bce94cb 100644 --- a/Compression.BSA/BSABuilder.cs +++ b/Compression.BSA/BSABuilder.cs @@ -280,7 +280,7 @@ namespace Compression.BSA case VersionType.SSE: { var r = new MemoryStream(); - using (var w = LZ4Stream.Encode(r, new LZ4EncoderSettings {CompressionLevel = LZ4Level.L10_OPT}, true)) + using (var w = LZ4Stream.Encode(r, new LZ4EncoderSettings {CompressionLevel = LZ4Level.L12_MAX}, true)) { _srcData.CopyTo(w); } diff --git a/Wabbajack.Common/Json.cs b/Wabbajack.Common/Json.cs index 979a0fc8..afde444d 100644 --- a/Wabbajack.Common/Json.cs +++ b/Wabbajack.Common/Json.cs @@ -314,7 +314,18 @@ namespace Wabbajack.Common if (!_typeToName.ContainsKey(serializedType)) { - throw new InvalidDataException($"No Binding name for {serializedType}"); + var custom = serializedType.GetCustomAttributes(false) + .OfType().FirstOrDefault(); + if (custom == null) + { + throw new InvalidDataException($"No Binding name for {serializedType}"); + } + + _nameToType[custom.Name] = serializedType; + _typeToName[serializedType] = custom.Name; + assemblyName = null; + typeName = custom.Name; + return; } var name = _typeToName[serializedType]; diff --git a/Wabbajack.Common/Util/DiskSlabAllocator.cs b/Wabbajack.Common/Util/DiskSlabAllocator.cs index baf3a5ef..89f3346a 100644 --- a/Wabbajack.Common/Util/DiskSlabAllocator.cs +++ b/Wabbajack.Common/Util/DiskSlabAllocator.cs @@ -30,8 +30,12 @@ namespace Wabbajack.Common { lock (this) { + // This can happen at times due to differences in compression sizes if (_head + size >= _size) - throw new InvalidDataException($"Size out of range. Declared {_size} used {_head + size}"); + { + return new MemoryStream(); + } + var startAt = _head; _head += size; var stream = _mmap.CreateViewStream(startAt, size, MemoryMappedFileAccess.ReadWrite); diff --git a/Wabbajack.Lib/CompilationSteps/DeconstructBSAs.cs b/Wabbajack.Lib/CompilationSteps/DeconstructBSAs.cs index 19d00fcb..b5adf2f0 100644 --- a/Wabbajack.Lib/CompilationSteps/DeconstructBSAs.cs +++ b/Wabbajack.Lib/CompilationSteps/DeconstructBSAs.cs @@ -66,7 +66,7 @@ namespace Wabbajack.Lib.CompilationSteps var id = Guid.NewGuid().ToString(); - var matches = await sourceFiles.PMap(_mo2Compiler.Queue, e => _mo2Compiler.RunStack(stack, new RawSourceFile(e, Consts.BSACreationDir.Combine((RelativePath)id, e.Name.FileName)))); + var matches = await sourceFiles.PMap(_mo2Compiler.Queue, e => _mo2Compiler.RunStack(stack, new RawSourceFile(e, Consts.BSACreationDir.Combine((RelativePath)id, (RelativePath)e.Name)))); foreach (var match in matches) diff --git a/Wabbajack.Lib/CompilationSteps/IncludeDummyESPs.cs b/Wabbajack.Lib/CompilationSteps/IncludeDummyESPs.cs index 5dd9f1a7..fc11f20c 100644 --- a/Wabbajack.Lib/CompilationSteps/IncludeDummyESPs.cs +++ b/Wabbajack.Lib/CompilationSteps/IncludeDummyESPs.cs @@ -17,7 +17,7 @@ namespace Wabbajack.Lib.CompilationSteps source.AbsolutePath.Extension != Consts.ESM) return null; var bsa = source.AbsolutePath.ReplaceExtension(Consts.BSA); - var bsaTextures = source.AbsolutePath.AppendToName(" - Textures"); + var bsaTextures = source.AbsolutePath.AppendToName(" - Textures").ReplaceExtension(Consts.BSA); if (source.AbsolutePath.Size > 250 || !bsa.IsFile && !bsaTextures.IsFile) return null;