Skip to content

Commit bdf3960

Browse files
committed
0.1.0
1 parent 3a2f4d2 commit bdf3960

7 files changed

Lines changed: 60 additions & 8 deletions

File tree

README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# UnityAsset.NET
22

3+
---
4+
35
[![MIT](https://img.shields.io/github/license/AXiX-official/UnityAsset.NET)](https://github.com/AXiX-official/UnityAsset.NET/master/LICENSE)
46
[![NuGet Stats](https://img.shields.io/nuget/v/UnityAsset.NET.svg)](https://www.nuget.org/packages/UnityAsset.NET)
57

@@ -9,11 +11,13 @@ Only support Unity 2017.x or later.
911

1012
## Features
1113

14+
---
15+
1216
### BundleFile
1317

1418
- [x] Parse/Serialize
1519
- [ ] Patch
16-
- [ ] Calculate/Patch crc32
20+
- [x] Calculate/Patch crc32
1721

1822
### SerializedFile
1923

@@ -25,7 +29,39 @@ Only support Unity 2017.x or later.
2529
- [x] Parse/Serialize
2630
- [ ] Patch
2731

28-
## Acknowledgements
32+
## Examples
33+
34+
---
35+
36+
### Unity CN Decryption
37+
38+
To load `BundleFile` with Unity CN Encryption, there are two ways.
39+
```csharp
40+
// Hex string format (32 characters)
41+
Setting.DefaultUnityCNKey = "587865636f6472506547616b61326536"; // Represents "XxecodrPeGaka2e6" in hex
42+
BundleFile bf = new BundleFile( @"path to your bundlefile");
43+
```
44+
or
45+
```csharp
46+
// Plain string format (16 characters)
47+
BundleFile bf = new BundleFile( @"path to your bundlefile", "XxecodrPeGaka2e6");
48+
```
49+
50+
To remove Unity CN Encryption form File, you can simply save `BundleFile` without key
51+
```csharp
52+
bf.Serialize(@"path to save file", CompressionType.Lz4HC, CompressionType.Lz4HC);
53+
```
54+
55+
### Stripped Version
56+
57+
Some `BundleFile`'s version may be stripped, to load those file you can set a specific version
58+
```csharp
59+
Setting.DefaultUnityVerion = "2020.3.48f1"
60+
```
61+
62+
## Credits
63+
64+
---
2965

3066
This project stands on the shoulders of these amazing open-source projects:
3167

UnityAsset.NET/Files/BundleFileExtension.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using UnityAsset.NET.Files.SerializedFiles;
1+
using UnityAsset.NET.Files.BundleFiles;
2+
using UnityAsset.NET.Files.SerializedFiles;
3+
using UnityAsset.NET.IO;
24

35
namespace UnityAsset.NET.Files;
46

@@ -9,4 +11,13 @@ public static List<Asset> Assets(this BundleFile bf) =>
911
.Where(file => file.File is SerializedFile)
1012
.SelectMany(file => ((SerializedFile)file.File).Assets)
1113
.ToList();
14+
15+
public static void PatchCrc32(this BundleFile bf, uint newCrc32)
16+
{
17+
if (bf.Crc32 != newCrc32)
18+
{
19+
var patchBytes = CRC32.rCRC(newCrc32, bf.Crc32);
20+
bf.Files.Add(new FileWrapper(new HeapDataBuffer(patchBytes), new FileEntry(0, 4, 0, "crc32-patch-data")));
21+
}
22+
}
1223
}

UnityAsset.NET/Files/BundleFiles/BundleFile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ public BundleFile(string path, string? key = null)
140140
var db = DataBuffer.FromFile(path);
141141
UnityCnKey = key;
142142
Header = Header.Parse(ref db);
143+
if (string.IsNullOrEmpty(Header.UnityRevision))
144+
Header.UnityRevision = Setting.DefaultUnityVerion;
143145
UnityCnInfo = ParseUnityCnInfo(ref db, Header, UnityCnKey);
144146
AlignAfterHeader(ref db, Header);
145147
DataInfo = ParseDataInfo(ref db, Header);

UnityAsset.NET/Files/SerializedFiles/SerializedFile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public SerializedFile(SerializedFileHeader header, SerializedFileMetadata metada
1313
{
1414
Header = header;
1515
Metadata = metadata;
16+
if (string.IsNullOrEmpty(Metadata.UnityVersion))
17+
Metadata.UnityVersion = Setting.DefaultUnityVerion;
1618
Assets = assets;
1719
}
1820

UnityAsset.NET/IO/DataBuffer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public void WriteUInt64(UInt64 value)
291291

292292
public string ReadNullTerminatedString(int maxLength = 32767)
293293
{
294-
var span = AsSpan().Slice(Position);
294+
var span = SliceForward();
295295
int nullTerminator = span.IndexOf((byte)0);
296296
if (nullTerminator < 0 || nullTerminator > maxLength)
297297
nullTerminator = maxLength;

UnityAsset.NET/Setting.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ public static class Setting
44
{
55
public static UInt32 DefaultChunkSize = 0x00020000;
66
public static string? DefaultUnityCNKey = null;
7+
public static string DefaultUnityVerion = "2019.4.40f1";
78
}

UnityAsset.NET/UnityAsset.NET.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<Authors>AXiX</Authors>
8-
<Description>A .NET library for reading and modifying Unity assets and bundles.</Description>
9-
<Version>0.0.5</Version>
8+
<Description>A work-in-progress .NET library for parsing/serializing/patching Unity Engine asset files.</Description>
9+
<Version>0.1.0</Version>
1010
<Title>UnityAsset.NET</Title>
1111
<Copyright>AXiX</Copyright>
1212
<PackageProjectUrl>https://github.com/AXiX-official/UnityAsset.NET</PackageProjectUrl>
1313
<RepositoryUrl>https://github.com/AXiX-official/UnityAsset.NET</RepositoryUrl>
1414
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
15-
<AssemblyVersion>0.0.5.0</AssemblyVersion>
16-
<FileVersion>0.0.5.0</FileVersion>
15+
<AssemblyVersion>0.1.0.0</AssemblyVersion>
16+
<FileVersion>0.1.0.0</FileVersion>
1717
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1818
<PackageReadmeFile>README.md</PackageReadmeFile>
1919
<PackageTags>Unity</PackageTags>

0 commit comments

Comments
 (0)