Skip to content

Commit

Permalink
Merge pull request #120 from BigBang1112/dev
Browse files Browse the repository at this point in the history
GBX.NET 2.0.7
  • Loading branch information
BigBang1112 authored Aug 16, 2024
2 parents a246be9 + d94426b commit 20e5b94
Show file tree
Hide file tree
Showing 119 changed files with 1,701 additions and 306 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
- GBX.NET.NewtonsoftJson
- GBX.NET.Tool
- GBX.NET.Tool.CLI
- GBX.NET.Crypto

name: Publish ${{ matrix.lib }}
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Benchmarks/GBX.NET.Benchmarks/GBX.NET.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
</ItemGroup>

<ItemGroup>
Expand Down
30 changes: 29 additions & 1 deletion GBX.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InputExtract", "Samples\Too
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InputExtractCLI", "Samples\Tool\InputExtractCLI\InputExtractCLI.csproj", "{5B124FAF-2658-49E0-9ABD-0333E829A5A5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GBX.NET.NewtonsoftJson", "Src\GBX.NET.NewtonsoftJson\GBX.NET.NewtonsoftJson.csproj", "{B4C2F12F-54EA-4844-8620-917BE0303687}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GBX.NET.NewtonsoftJson", "Src\GBX.NET.NewtonsoftJson\GBX.NET.NewtonsoftJson.csproj", "{B4C2F12F-54EA-4844-8620-917BE0303687}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GBX.NET.Tool.Razor", "Src\GBX.NET.Tool.Razor\GBX.NET.Tool.Razor.csproj", "{76A1C1C4-8012-42C8-BB72-B139C9B2963F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CryCryptSwitch", "Tools\CryCryptSwitch\CryCryptSwitch.csproj", "{4327AB87-DF45-4364-9D27-1C72BA0E78FF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GBX.NET.BlockInfo", "Src\GBX.NET.BlockInfo\GBX.NET.BlockInfo.csproj", "{89F6FFE5-E32A-4713-8D63-98D070A17DC1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MuxCryptSwitch", "Tools\MuxCryptSwitch\MuxCryptSwitch.csproj", "{0B5609C6-7B10-4E8D-B41C-35CC1A2532A4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -382,6 +390,22 @@ Global
{B4C2F12F-54EA-4844-8620-917BE0303687}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B4C2F12F-54EA-4844-8620-917BE0303687}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B4C2F12F-54EA-4844-8620-917BE0303687}.Release|Any CPU.Build.0 = Release|Any CPU
{76A1C1C4-8012-42C8-BB72-B139C9B2963F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76A1C1C4-8012-42C8-BB72-B139C9B2963F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76A1C1C4-8012-42C8-BB72-B139C9B2963F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76A1C1C4-8012-42C8-BB72-B139C9B2963F}.Release|Any CPU.Build.0 = Release|Any CPU
{4327AB87-DF45-4364-9D27-1C72BA0E78FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4327AB87-DF45-4364-9D27-1C72BA0E78FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4327AB87-DF45-4364-9D27-1C72BA0E78FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4327AB87-DF45-4364-9D27-1C72BA0E78FF}.Release|Any CPU.Build.0 = Release|Any CPU
{89F6FFE5-E32A-4713-8D63-98D070A17DC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{89F6FFE5-E32A-4713-8D63-98D070A17DC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89F6FFE5-E32A-4713-8D63-98D070A17DC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89F6FFE5-E32A-4713-8D63-98D070A17DC1}.Release|Any CPU.Build.0 = Release|Any CPU
{0B5609C6-7B10-4E8D-B41C-35CC1A2532A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B5609C6-7B10-4E8D-B41C-35CC1A2532A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B5609C6-7B10-4E8D-B41C-35CC1A2532A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B5609C6-7B10-4E8D-B41C-35CC1A2532A4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -446,6 +470,10 @@ Global
{72B2091A-1162-4993-9D3D-278E229F6A43} = {0269B7F3-C346-49B3-A9B3-B33ABC95AB5E}
{5B124FAF-2658-49E0-9ABD-0333E829A5A5} = {0269B7F3-C346-49B3-A9B3-B33ABC95AB5E}
{B4C2F12F-54EA-4844-8620-917BE0303687} = {80DCE6B7-4BD9-415C-B053-92B059D7C938}
{76A1C1C4-8012-42C8-BB72-B139C9B2963F} = {80DCE6B7-4BD9-415C-B053-92B059D7C938}
{4327AB87-DF45-4364-9D27-1C72BA0E78FF} = {F3336145-FDA9-4517-AEDC-7F4C4D526ECB}
{89F6FFE5-E32A-4713-8D63-98D070A17DC1} = {80DCE6B7-4BD9-415C-B053-92B059D7C938}
{0B5609C6-7B10-4E8D-B41C-35CC1A2532A4} = {F3336145-FDA9-4517-AEDC-7F4C4D526ECB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8EA2F0DE-BA72-486D-AB3A-9320C0CE5CFD}
Expand Down
2 changes: 1 addition & 1 deletion Generators/GBX.NET.Generators/GBX.NET.Generators.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" PrivateAssets="all" />
</ItemGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" PrivateAssets="all" />
</ItemGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion Resources/Wrap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
0301A000 2E001000
0301C000 2E002000
03031000 090F4000
0303C000 0915D000
03074000 2E005000
0307B000 03078000
030FD000 2E004000
Expand Down
11 changes: 10 additions & 1 deletion SUPPORTED_GBX_FILE_TYPES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ Older extensions | Latest extension | Class | Read (whole) | Write | Read (heade
| ConstructionCampaign.Gbx | Campaign.Gbx | [CGameCtnCampaign](Src/GBX.NET/Engines/Game/CGameCtnCampaign.chunkl) | Yes | Yes
| TMCollection.Gbx | Collection.Gbx | [CGameCtnCollection](Src/GBX.NET/Engines/Game/CGameCtnCollection.chunkl) | Yes | Yes | Yes
| TMDecoration.Gbx | Decoration.Gbx | [CGameCtnDecoration](Src/GBX.NET/Engines/Game/CGameCtnDecoration.chunkl) | Yes | Yes | Yes
| TMDecorationSize.Gbx | DecorationSize.Gbx | [CGameCtnDecorationSize](Src/GBX.NET/Engines/Game/CGameCtnDecorationSize.chunkl) | Yes | Yes
| TMDecorationSize.Gbx | DecorationSize.Gbx | [CGameCtnDecorationSize](Src/GBX.NET/Engines/Game/CGameCtnDecorationSize.chunkl) | Yes | Yes | Yes
| TMDecorationMood.Gbx | DecorationMood.Gbx | [CGameCtnDecorationMood](Src/GBX.NET/Engines/Game/CGameCtnDecorationMood.chunkl) | Yes | Yes | Yes
| TMDecorationAudio.Gbx | DecorationAudio.Gbx | [CGameCtnDecorationAudio](Src/GBX.NET/Engines/Game/CGameCtnDecorationAudio.chunkl) | Yes | Yes | Yes
| TMEDClassic.Gbx | EDClassic.Gbx | [CGameCtnBlockInfoClassic](Src/GBX.NET/Engines/Game/CGameCtnBlockInfoClassic.chunkl) | Yes | Yes | Yes
| TMEDClip.Gbx | EDClip.Gbx | [CGameCtnBlockInfoClip](Src/GBX.NET/Engines/Game/CGameCtnBlockInfoClip.chunkl) | Yes | Yes | Yes
| TMEDFlat.Gbx | EDFlat.Gbx | [CGameCtnBlockInfoFlat](Src/GBX.NET/Engines/Game/CGameCtnBlockInfoFlat.chunkl) | Yes | Yes | Yes
Expand All @@ -30,6 +32,13 @@ Older extensions | Latest extension | Class | Read (whole) | Write | Read (heade
| TMEDRectAsym.Gbx | EDRectAsym.Gbx | [CGameCtnBlockInfoRectAsym](Src/GBX.NET/Engines/Game/CGameCtnBlockInfoRectAsym.chunkl) | Yes | Yes | Yes
| TMEDRoad.Gbx | EDRoad.Gbx | [CGameCtnBlockInfoRoad](Src/GBX.NET/Engines/Game/CGameCtnBlockInfoRoad.chunkl) | Yes | Yes | Yes
| | EDTransition.Gbx | [CGameCtnBlockInfoTransition](Src/GBX.NET/Engines/Game/CGameCtnBlockInfoTransition.chunkl) | Yes | Yes | Yes
| TMZoneFlat.Gbx | ZoneFlat.Gbx | [CGameCtnZoneFlat](Src/GBX.NET/Engines/Game/CGameCtnZoneFlat.chunkl) | Yes | Yes
| TMZoneFrontier.Gbx | ZoneFrontier.Gbx | [CGameCtnZoneFrontier](Src/GBX.NET/Engines/Game/CGameCtnZoneFrontier.chunkl) | Yes | Yes
| | FuncShader.Gbx | [CFuncShaderLayerUV](Src/GBX.NET/Engines/Func/CFuncShaderLayerUV.chunkl) | Yes | Yes
| | TMTerrainModifier.Gbx | [CGameCtnDecorationTerrainModifier](Src/GBX.NET/Engines/Game/CGameCtnDecorationTerrainModifier.chunkl) | Yes | Yes
| | MotionManagerWeathers.Gbx | [CPlugWeatherModel](Src/GBX.NET/Engines/Plug/CPlugWeatherModel.chunkl) | Up to TMUF | Yes
| | RallyLeafManager.Gbx | [CMotionManagerLeaves](Src/GBX.NET/Engines/Motion/CMotionManagerLeaves.chunkl) | Yes | Yes
| | GameSkin.Gbx | [CPlugGameSkin](Src/GBX.NET/Engines/Plug/CPlugGameSkin.chunkl) | Yes | Yes
| | VehicleTunings.Gbx | [CPlugVehiclePhyTunings](Src/GBX.NET/Engines/Plug/CPlugVehiclePhyTunings.chunkl) | Up to TM2 | Up to TM2 | Yes
| | ObjectInfo.Gbx | [CGameItemModel](Src/GBX.NET/Engines/GameData/CGameItemModel.chunkl) | Yes | Yes | Yes
| | Mobil.Gbx | [CSceneMobil](Src/GBX.NET/Engines/Scene/CSceneMobil.chunkl) | Yes | Yes
Expand Down
6 changes: 4 additions & 2 deletions Samples/Tool/GhostExtract/GhostExtractTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ public IEnumerable<Gbx<CGameCtnGhost>> Produce()
{
logger.LogInformation("Extracting ghost {GhostIndex} from {FileName}...", i + 1, fileName);

var ghostFileName = GbxPath.GetValidFileName($"{GbxPath.GetFileNameWithoutExtension(fileName ?? "Ghost")}_{i + 1:00}.Ghost.Gbx");

return new Gbx<CGameCtnGhost>(ghost, gbx.Header.Basic)
{
FilePath = ghost.CanBeGameVersion(GameVersion.MP3)
? Path.Combine("Replays", "GbxTools", "GhostExtract", $"{GbxPath.GetFileNameWithoutExtension(fileName ?? "Ghost")}_{i + 1:00}.Ghost.Gbx")
: Path.Combine("Tracks", "Replays", "GbxTools", "GhostExtract", $"{GbxPath.GetFileNameWithoutExtension(fileName ?? "Ghost")}_{i + 1:00}.Ghost.Gbx"),
? Path.Combine("Replays", "GbxTools", "GhostExtract", ghostFileName)
: Path.Combine("Tracks", "Replays", "GbxTools", "GhostExtract", ghostFileName),
ClassIdRemapMode = gbx.ClassIdRemapMode,
PackDescVersion = gbx.PackDescVersion,
};
Expand Down
6 changes: 6 additions & 0 deletions Src/GBX.NET.BlockInfo/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace GBX.NET.BlockInfo;

public class Class1
{

}
9 changes: 9 additions & 0 deletions Src/GBX.NET.BlockInfo/GBX.NET.BlockInfo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
6 changes: 0 additions & 6 deletions Src/GBX.NET.Crypto/Class1.cs

This file was deleted.

97 changes: 97 additions & 0 deletions Src/GBX.NET.Crypto/Cry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using GBX.NET.Exceptions;
using GBX.NET.Serialization;
using System.Text;

namespace GBX.NET.Crypto;

public static partial class Cry
{
private const ulong Key = 0xCF08317C90460052;

[Zomp.SyncMethodGenerator.CreateSyncVersion]
public static async Task<string> DecryptAsync(Stream stream, CancellationToken cancellationToken = default)
{
if (Gbx.LZO is null)
{
throw new LzoNotDefinedException();
}

using var r = new GbxReader(stream);
var uncompressedSize = r.ReadInt32();
var compressedData = await r.ReadDataAsync(cancellationToken);

var uncompressedData = new byte[uncompressedSize];

Gbx.LZO.Decompress(compressedData, uncompressedData);

var shift = uncompressedSize & 0x3F;
var rotkey = (Key << shift) | (Key >> (64 - shift));

var rotkeyBytes = BitConverter.GetBytes(rotkey);

for (int i = 0; i < uncompressedSize; i++)
{
uncompressedData[i] ^= rotkeyBytes[i & 0x7];
}

return Encoding.ASCII.GetString(uncompressedData);
}

public static async Task<string> DecryptAsync(string fileName, CancellationToken cancellationToken = default)
{
#if !NETSTANDARD2_0
await
#endif
using var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, useAsync: true);
return await DecryptAsync(fs, cancellationToken);
}

public static string Decrypt(string fileName)
{
using var fs = File.OpenRead(fileName);
return Decrypt(fs);
}

[Zomp.SyncMethodGenerator.CreateSyncVersion]
public static async Task EncryptAsync(Stream stream, string contents, CancellationToken cancellationToken = default)
{
if (Gbx.LZO is null)
{
throw new LzoNotDefinedException();
}

var uncompressedData = Encoding.ASCII.GetBytes(contents);

var shift = uncompressedData.Length & 0x3F;
var rotkey = (Key << shift) | (Key >> (64 - shift));

var rotkeyBytes = BitConverter.GetBytes(rotkey);

for (int i = 0; i < uncompressedData.Length; i++)
{
uncompressedData[i] ^= rotkeyBytes[i & 0x7];
}

using var w = new GbxWriter(stream);

w.Write(uncompressedData.Length);

var compressedData = Gbx.LZO.Compress(uncompressedData);
await w.WriteDataAsync(compressedData, cancellationToken);
}

public static async Task EncryptAsync(string fileName, string contents, CancellationToken cancellationToken = default)
{
#if !NETSTANDARD2_0
await
#endif
using var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None, 4096, useAsync: true);
await EncryptAsync(fs, contents, cancellationToken);
}

public static void Encrypt(string fileName, string contents)
{
using var fs = File.Create(fileName);
Encrypt(fs, contents);
}
}
13 changes: 9 additions & 4 deletions Src/GBX.NET.Crypto/GBX.NET.Crypto.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<PackageId>GBX.NET.Crypto</PackageId>
<Version>1.0.0-alpha1</Version>
<Version>1.0.0</Version>
<Authors>BigBang1112</Authors>
<Description></Description>
<Description>Cryptographic features for GBX.NET 2.</Description>
<Copyright>Copyright (c) 2024 Petr Pivoňka</Copyright>
<PackageProjectUrl>https://github.com/BigBang1112/gbx-net</PackageProjectUrl>
<PackageIcon>logo_icon_outline.png</PackageIcon>
Expand Down Expand Up @@ -39,21 +39,26 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.4.3">
<PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="ThisAssembly.Git" Version="1.4.3">
<PackageReference Include="ThisAssembly.Git" Version="1.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Zomp.SyncMethodGenerator" Version="1.4.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GBX.NET.Hashing\GBX.NET.Hashing.csproj" />
<ProjectReference Include="..\GBX.NET\GBX.NET.csproj" />
</ItemGroup>

Expand Down
45 changes: 45 additions & 0 deletions Src/GBX.NET.Crypto/MD5.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Text;

namespace GBX.NET.Crypto;

public static partial class MD5
{
public static byte[] Compute(byte[] data)
{
#if NET6_0_OR_GREATER
return System.Security.Cryptography.MD5.HashData(data);
#else
using var md5 = System.Security.Cryptography.MD5.Create();
return md5.ComputeHash(data);
#endif
}

public static byte[] Compute(string data)
{
return Compute(Encoding.ASCII.GetBytes(data));
}

#if NET8_0_OR_GREATER
public static async ValueTask<byte[]> ComputeAsync(byte[] data, CancellationToken cancellationToken = default)
{
await using var ms = new MemoryStream(data);
return await System.Security.Cryptography.MD5.HashDataAsync(ms, cancellationToken);
}
#elif NET6_0_OR_GREATER || NETSTANDARD2_0
public static async Task<byte[]> ComputeAsync(byte[] data, CancellationToken cancellationToken = default)
{
using var md5 = System.Security.Cryptography.MD5.Create();
#if NET6_0_OR_GREATER
await using var ms = new MemoryStream(data);
return await md5.ComputeHashAsync(ms, cancellationToken);
#else
return await Task.FromResult(md5.ComputeHash(data));
#endif
}
#endif

public static async Task<byte[]> ComputeAsync(string data, CancellationToken cancellationToken = default)
{
return await ComputeAsync(Encoding.ASCII.GetBytes(data), cancellationToken);
}
}
Loading

0 comments on commit 20e5b94

Please sign in to comment.