Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -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 --skip-duplicate --source github
dotnet nuget push .\XCompression\bin\Release\PCarsTools.XCompression.*.nupkg --skip-duplicate --source github
42 changes: 28 additions & 14 deletions PCarsTools/BPakFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@

namespace PCarsTools
{
public class BPakFile
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; }
Expand All @@ -41,24 +43,29 @@ public class BPakFile
/// </summary>
public string Path { get; set; }

private BPakFile(TextWriter outputWriter)
{
this.outputWriter = outputWriter is null ? Console.Out : outputWriter;
}

/// <summary>
/// Reads a pak file from a provided file name.
/// </summary>
/// <param name="inputFile"></param>
/// <param name="withExtraInfo"></param>
/// <returns></returns>
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('/', '\\');

Expand Down Expand Up @@ -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<BPakFileTocEntry>(fileCount);
SpanReader sr = new SpanReader(pakTocBuffer);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand All @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
Expand All @@ -375,6 +382,13 @@ private bool Unpack(byte[] bytes, BPakFileTocEntry entry, BExtendedFileInfoEntry
return true;
}
}

public void Dispose()
{
if (_fs is not null) {
_fs.Dispose();
}
}
}


Expand Down
2 changes: 1 addition & 1 deletion PCarsTools/Compression/Oodle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Oodle
/// <summary>
/// Oodle Library Path
/// </summary>
private const string OodleLibraryPath = "oo2core_7_win64";
private const string OodleLibraryPath = "oo2core_4_win64";

/// <summary>
/// Oodle64 Decompression Method
Expand Down
4 changes: 2 additions & 2 deletions PCarsTools/PCarsTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Version>1.1.2</Version>
<Version>1.1.2.5</Version>
<Platforms>AnyCPU;x86;x64</Platforms>

<AssemblyName Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">PCarsTools_Debug_x86</AssemblyName>
Expand All @@ -13,7 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BouncyCastle" Version="1.8.9" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.2.1" />
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="SharpZipLib" Version="1.4.1" />
<PackageReference Include="Syroot.BinaryData" Version="5.2.2" />
Expand Down
1 change: 1 addition & 0 deletions XCompression/XCompression.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>PCarsTools.XCompression</AssemblyName>
<TargetFrameworks>net6.0;</TargetFrameworks>
<Company>Gibbed</Company>
<Authors>Gibbed</Authors>
Expand Down