From 6f602f0039a534b757fd2a45f404c53b1d9c134c Mon Sep 17 00:00:00 2001 From: Paolo Ambrosio Date: Tue, 9 May 2023 07:28:07 +0100 Subject: [PATCH 1/6] Push NuGet package to GitHub --- .github/workflows/publish.yaml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/publish.yaml diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..d726d8f --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,27 @@ +name: Publish +on: + pull_request: + branches: + - master + push: + branches: + - master +jobs: + publish: + runs-on: windows-latest + permissions: + packages: write + contents: read + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-dotnet@v2 + with: + dotnet-version: '6.0.x' + - name: Build + run: dotnet pack -c Release + - #if: ${{ github.ref == 'refs/heads/master' }} + name: Push + run: | + dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/OpenSimTools/index.json" + dotnet nuget push .\PCarsTools\bin\Release\PCarsTools.*.nupkg --source github + dotnet nuget push .\XCompression\bin\Release\XCompression.*.nupkg --source github \ No newline at end of file From f7873656217a26c9fa45b6b133ca9daea1f4f836 Mon Sep 17 00:00:00 2001 From: Paolo Ambrosio Date: Thu, 11 May 2023 22:25:14 +0100 Subject: [PATCH 2/6] Upgrade BouncyCastle dependency --- PCarsTools/PCarsTools.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PCarsTools/PCarsTools.csproj b/PCarsTools/PCarsTools.csproj index 8396ce9..4980c80 100644 --- a/PCarsTools/PCarsTools.csproj +++ b/PCarsTools/PCarsTools.csproj @@ -3,7 +3,7 @@ Exe net6.0 - 1.1.2 + 1.1.2.1 AnyCPU;x86;x64 PCarsTools_Debug_x86 @@ -13,7 +13,7 @@ - + From 0552fe5ed7d446d9c182aefd25141c2dcaeb668a Mon Sep 17 00:00:00 2001 From: Paolo Ambrosio Date: Fri, 12 May 2023 06:34:43 +0100 Subject: [PATCH 3/6] Rename XCompress to avoid conflicts --- .github/workflows/publish.yaml | 4 ++-- PCarsTools/PCarsTools.csproj | 2 +- XCompression/XCompression.csproj | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index d726d8f..bdb3d0e 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -23,5 +23,5 @@ jobs: name: Push run: | dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/OpenSimTools/index.json" - dotnet nuget push .\PCarsTools\bin\Release\PCarsTools.*.nupkg --source github - dotnet nuget push .\XCompression\bin\Release\XCompression.*.nupkg --source github \ No newline at end of file + dotnet nuget push .\PCarsTools\bin\Release\PCarsTools.*.nupkg --skip-duplicate --source github + dotnet nuget push .\XCompression\bin\Release\PCarsTools.XCompression.*.nupkg --skip-duplicate --source github \ No newline at end of file diff --git a/PCarsTools/PCarsTools.csproj b/PCarsTools/PCarsTools.csproj index 4980c80..07dee75 100644 --- a/PCarsTools/PCarsTools.csproj +++ b/PCarsTools/PCarsTools.csproj @@ -3,7 +3,7 @@ Exe net6.0 - 1.1.2.1 + 1.1.2.2 AnyCPU;x86;x64 PCarsTools_Debug_x86 diff --git a/XCompression/XCompression.csproj b/XCompression/XCompression.csproj index c906228..edd45f5 100644 --- a/XCompression/XCompression.csproj +++ b/XCompression/XCompression.csproj @@ -1,5 +1,6 @@  + PCarsTools.XCompression net6.0; Gibbed Gibbed From 4183bf3bf754e0637949682bdfa613824406791a Mon Sep 17 00:00:00 2001 From: Paolo Ambrosio Date: Fri, 12 May 2023 13:07:50 +0100 Subject: [PATCH 4/6] Let BPakFiles release FileStream --- PCarsTools/BPakFile.cs | 9 ++++++++- PCarsTools/PCarsTools.csproj | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/PCarsTools/BPakFile.cs b/PCarsTools/BPakFile.cs index 66c676d..84876fb 100644 --- a/PCarsTools/BPakFile.cs +++ b/PCarsTools/BPakFile.cs @@ -20,7 +20,7 @@ namespace PCarsTools { - public class BPakFile + public class BPakFile : IDisposable { public const string TagId = "PAK "; @@ -375,6 +375,13 @@ private bool Unpack(byte[] bytes, BPakFileTocEntry entry, BExtendedFileInfoEntry return true; } } + + public void Dispose() + { + if (_fs is not null) { + _fs.Dispose(); + } + } } diff --git a/PCarsTools/PCarsTools.csproj b/PCarsTools/PCarsTools.csproj index 07dee75..606b1ee 100644 --- a/PCarsTools/PCarsTools.csproj +++ b/PCarsTools/PCarsTools.csproj @@ -3,7 +3,7 @@ Exe net6.0 - 1.1.2.2 + 1.1.2.3 AnyCPU;x86;x64 PCarsTools_Debug_x86 From 18a8ba1490ea6fad0443227c588679a1d9c622fd Mon Sep 17 00:00:00 2001 From: Paolo Ambrosio Date: Fri, 12 May 2023 20:40:15 +0100 Subject: [PATCH 5/6] Configurable output in BPakFile --- PCarsTools/BPakFile.cs | 33 ++++++++++++++++++++------------- PCarsTools/PCarsTools.csproj | 2 +- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/PCarsTools/BPakFile.cs b/PCarsTools/BPakFile.cs index 84876fb..1bcfbc0 100644 --- a/PCarsTools/BPakFile.cs +++ b/PCarsTools/BPakFile.cs @@ -24,6 +24,8 @@ public class BPakFile : IDisposable { public const string TagId = "PAK "; + private readonly TextWriter outputWriter; + public BVersion Version { get; set; } public string Name { get; set; } public ePakFlags Flags { get; set; } @@ -41,24 +43,29 @@ public class BPakFile : IDisposable /// public string Path { get; set; } + private BPakFile(TextWriter outputWriter) + { + this.outputWriter = outputWriter is null ? Console.Out : outputWriter; + } + /// /// Reads a pak file from a provided file name. /// /// /// /// - public static BPakFile FromFile(string inputFile, bool withExtraInfo = true) + public static BPakFile FromFile(string inputFile, bool withExtraInfo = true, TextWriter outputWriter = null) { var fs = new FileStream(inputFile, FileMode.Open); - var pak = FromStream(fs, withExtraInfo: withExtraInfo, tocFileName: inputFile); + var pak = FromStream(fs, withExtraInfo: withExtraInfo, tocFileName: inputFile, outputWriter: outputWriter); pak._fs = fs; return pak; } - public static BPakFile FromStream(Stream stream, bool withExtraInfo = false, string tocFileName = null) + public static BPakFile FromStream(Stream stream, bool withExtraInfo = false, string tocFileName = null, TextWriter outputWriter = null) { - var pak = new BPakFile(); + var pak = new BPakFile(outputWriter); int pakOffset = (int)stream.Position; pak.Path = tocFileName.ToLower().Replace('/', '\\'); @@ -120,7 +127,7 @@ public static BPakFile FromStream(Stream stream, bool withExtraInfo = false, str } if (pakTocBuffer[14] != 0 && pakTocBuffer[15] != 0) // Check if first entry offset is absurdly too big that its possibly not decrypted correctly - Console.WriteLine($"Warning - possible crash: {pak.Name} toc could most likely not be decrypted correctly using key No.{pak.KeyIndex}"); + outputWriter.WriteLine($"Warning - possible crash: {pak.Name} toc could most likely not be decrypted correctly using key No.{pak.KeyIndex}"); pak.Entries = new List(fileCount); SpanReader sr = new SpanReader(pakTocBuffer); @@ -177,7 +184,7 @@ public static BPakFile FromStream(Stream stream, bool withExtraInfo = false, str BPakFileEncryption.DecryptData(pak.EncryptionType, tmp, tmp.Length, 0); if (tmp[6] != 0 && tmp[7] != 0) - Console.WriteLine("Warning: possibly failed to decrypt Extended Info Table"); + outputWriter.WriteLine("Warning: possibly failed to decrypt Extended Info Table"); extTocBuffer = tmp; } @@ -200,7 +207,7 @@ public static BPakFile FromStream(Stream stream, bool withExtraInfo = false, str ulong uid = BHashCode.CreateUidRaw(extEntry.Path); if (pak.Entries[i].UId != uid) - Console.WriteLine($"Warning - unmatched UID/Hash: {extEntry.Path} (target={pak.Entries[i].UId:X16}, got={uid}"); + outputWriter.WriteLine($"Warning - unmatched UID/Hash: {extEntry.Path} (target={pak.Entries[i].UId:X16}, got={uid}"); pak.ExtEntries.Add(extEntry); } @@ -227,17 +234,17 @@ public void UnpackAll(string outputDir) if (UnpackFromStream(entry, extEntry, outPath)) { - Console.WriteLine($"Unpacked: [{Name}]\\{extEntry.Path}"); + outputWriter.WriteLine($"Unpacked: [{Name}]\\{extEntry.Path}"); totalCount++; } else { - Console.WriteLine($"Failed to unpack: {extEntry.Path}"); + outputWriter.WriteLine($"Failed to unpack: {extEntry.Path}"); failed++; } } - Console.WriteLine($"Done. Extracted {totalCount} files ({failed} not extracted)"); + outputWriter.WriteLine($"Done. Extracted {totalCount} files ({failed} not extracted)"); } public bool UnpackFromLocalStoredFile(string outputDir, BPakFileTocEntry entry, BExtendedFileInfoEntry extEntry) @@ -252,7 +259,7 @@ public bool UnpackFromLocalStoredFile(string outputDir, BPakFileTocEntry entry, } else { - Console.WriteLine($"File {extEntry.Path} not found to extract, can be ignored"); + outputWriter.WriteLine($"File {extEntry.Path} not found to extract, can be ignored"); } return false; @@ -352,7 +359,7 @@ private bool Unpack(byte[] bytes, BPakFileTocEntry entry, BExtendedFileInfoEntry int outLen = (int)entry.FileSize; ErrorCode err = decompContext.Decompress(bytes, 0, ref pakLen, decBuffer, 0, ref outLen); if (err != ErrorCode.None) - Console.WriteLine($"Error: Failed to unpack {extEntry.Path} (XMemDecompress/LZX) - Code: {(int)err:X8}"); + outputWriter.WriteLine($"Error: Failed to unpack {extEntry.Path} (XMemDecompress/LZX) - Code: {(int)err:X8}"); if (outLen == entry.FileSize) { @@ -365,7 +372,7 @@ private bool Unpack(byte[] bytes, BPakFileTocEntry entry, BExtendedFileInfoEntry } else if (entry.Compression != PakFileCompressionType.None) { - Console.WriteLine($"Warning: Unrecognized compression type {entry.Compression} for {extEntry.Path}"); + outputWriter.WriteLine($"Warning: Unrecognized compression type {entry.Compression} for {extEntry.Path}"); return false; } else diff --git a/PCarsTools/PCarsTools.csproj b/PCarsTools/PCarsTools.csproj index 606b1ee..5945ced 100644 --- a/PCarsTools/PCarsTools.csproj +++ b/PCarsTools/PCarsTools.csproj @@ -3,7 +3,7 @@ Exe net6.0 - 1.1.2.3 + 1.1.2.4 AnyCPU;x86;x64 PCarsTools_Debug_x86 From 40c65df8b130de4a730ff3b4fdb4595c5beae473 Mon Sep 17 00:00:00 2001 From: Paolo Ambrosio Date: Sun, 14 May 2023 17:51:10 +0100 Subject: [PATCH 6/6] Use Oodle vesion that comes with AMS2 --- PCarsTools/Compression/Oodle.cs | 2 +- PCarsTools/PCarsTools.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PCarsTools/Compression/Oodle.cs b/PCarsTools/Compression/Oodle.cs index d342fb6..38de31b 100644 --- a/PCarsTools/Compression/Oodle.cs +++ b/PCarsTools/Compression/Oodle.cs @@ -14,7 +14,7 @@ public class Oodle /// /// Oodle Library Path /// - private const string OodleLibraryPath = "oo2core_7_win64"; + private const string OodleLibraryPath = "oo2core_4_win64"; /// /// Oodle64 Decompression Method diff --git a/PCarsTools/PCarsTools.csproj b/PCarsTools/PCarsTools.csproj index 5945ced..1f96078 100644 --- a/PCarsTools/PCarsTools.csproj +++ b/PCarsTools/PCarsTools.csproj @@ -3,7 +3,7 @@ Exe net6.0 - 1.1.2.4 + 1.1.2.5 AnyCPU;x86;x64 PCarsTools_Debug_x86