├── .gitignore
├── LICENSE
├── README.md
├── UnityCN-Helper.sln
└── UnityCN-Helper
├── Program.cs
└── UnityCN-Helper.csproj
/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | obj/
3 | /packages/
4 | riderModule.iml
5 | /_ReSharper.Caches/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 AXiX
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # UnityCN-Helper
2 |
3 | [
](https://api.gitsponsors.com/api/badge/link?p=kgrFzvDuyvkJEf6+zLA7aLDDcBWMpjb6y2T0cwUg3qWtChhxMrU9lzUtyeo9RVIfU4/KIFXE0+fdycrPSrqv60sLut/vi0Lk/nbN5INWYNS3DyemrDmv4liXBIUVXvOz9oY58wyiMV/awJdRZLOzJQ==)
4 |
5 | A tool helps decrypt/encrypt assetbundle files for UnityCN.
6 |
7 | ## Command Line Arguments
8 |
9 | - -i, --infile Required. Input file to be processed.
10 |
11 | - -o, --outfile Required. Output processed file.
12 |
13 | - -e, --encrypt (Default: false) Encrypt the asset file.
14 |
15 | - -d, --decrypt (Default: false) Decrypt the asset file.
16 |
17 | - -k, --key Required. UnityCN key for decryption.
18 |
19 | - -f, --folder (Default: false) Operate on a folder instead of a file.
20 |
21 | - --help Display this help screen.
22 |
23 | - --version Display version information.
24 |
25 | ### Example
26 |
27 | ```bash
28 | ./UnityCN-Helper -i test.bundle -o test.bundle.de -k 5265736F6E616E63655265626F726E52 -d
29 | ./UnityCN-Helper -i test.bundle.de -o test.bundle -k 5265736F6E616E63655265626F726E52 -e
30 | ```
31 |
32 | for operating on a folder:
33 |
34 | ```bash
35 | ./UnityCN-Helper -i test -o output -k 5265736F6E616E63655265626F726E52 -d -f
36 | ./UnityCN-Helper -i output -o output_en -k 5265736F6E616E63655265626F726E52 -e -f
37 | ```
38 |
39 |
40 | ## You need to know
41 |
42 | In fact, after modifying the asset file, encrypting is not necessary.
43 |
44 | For games I encountered, the game can load unencrypted asset files as well as encrypted asset files.
45 |
46 | ## Special Thanks
47 |
48 | - [Perfare](https://github.com/Perfare) for creating and maintaining and every contributor of [AssetStudio](https://github.com/Perfare/AssetStudio)
49 |
50 | - [Razmoth](https://github.com/Razmoth) for figuring out and sharing Unity CN's AssetBundle decryption ([src](https://github.com/RazTools/Studio)).
51 |
--------------------------------------------------------------------------------
/UnityCN-Helper.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnityCN-Helper", "UnityCN-Helper\UnityCN-Helper.csproj", "{F2A71E38-707C-4E28-BB9B-0D82E3450202}"
4 | EndProject
5 | Global
6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
7 | Debug|Any CPU = Debug|Any CPU
8 | Release|Any CPU = Release|Any CPU
9 | EndGlobalSection
10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
11 | {F2A71E38-707C-4E28-BB9B-0D82E3450202}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12 | {F2A71E38-707C-4E28-BB9B-0D82E3450202}.Debug|Any CPU.Build.0 = Debug|Any CPU
13 | {F2A71E38-707C-4E28-BB9B-0D82E3450202}.Release|Any CPU.ActiveCfg = Release|Any CPU
14 | {F2A71E38-707C-4E28-BB9B-0D82E3450202}.Release|Any CPU.Build.0 = Release|Any CPU
15 | EndGlobalSection
16 | EndGlobal
17 |
--------------------------------------------------------------------------------
/UnityCN-Helper/Program.cs:
--------------------------------------------------------------------------------
1 | using CommandLine;
2 | using UnityAsset.NET.BundleFile;
3 |
4 | namespace UnityCN_Helper
5 | {
6 | public class Options
7 | {
8 | [Option('i', "infile", Required = true, HelpText = "Input file to be processed.")]
9 | public string InFile { get; set; }
10 |
11 | [Option('o', "outfile", Required = true, HelpText = "Output processed file.")]
12 | public string OutFile { get; set; }
13 |
14 | [Option('e', "encrypt", Default = false, HelpText = "Encrypt the asset file.")]
15 | public bool Encrypt { get; set; }
16 |
17 | [Option('d', "decrypt", Default = false, HelpText = "Decrypt the asset file.")]
18 | public bool Decrypt { get; set; }
19 |
20 | [Option('k', "key", Required = true, HelpText = "UnityCN key for decryption.")]
21 | public string Key { get; set; }
22 |
23 | [Option('f', "folder", Default = false, HelpText = "Operate on a folder instead of a file.")]
24 | public bool Folder { get; set; }
25 | }
26 |
27 | internal static class Program
28 | {
29 | static void Main(string[] args)
30 | {
31 | Parser.Default.ParseArguments(args)
32 | .WithParsed(o =>
33 | {
34 | if (o.Encrypt)
35 | {
36 | if (o.Folder)
37 | {
38 | if (!Directory.Exists(o.InFile))
39 | {
40 | Console.WriteLine("Folder not found.");
41 | return;
42 | }
43 |
44 | foreach (string file in
45 | Directory.EnumerateFiles(o.InFile, "*", SearchOption.AllDirectories))
46 | {
47 | string outFolder = Path.GetDirectoryName(file).Replace(o.InFile, o.OutFile);
48 | if (!Directory.Exists(outFolder))
49 | {
50 | Directory.CreateDirectory(outFolder);
51 | }
52 |
53 | EncryptSingle(file, Path.Combine(outFolder, Path.GetFileName(file)), o.Key);
54 | }
55 | }
56 | else
57 | {
58 | EncryptSingle(o.InFile, o.OutFile, o.Key);
59 | }
60 | }
61 | else if (o.Decrypt)
62 | {
63 | if (o.Folder)
64 | {
65 | if (!Directory.Exists(o.InFile))
66 | {
67 | Console.WriteLine("Folder not found.");
68 | return;
69 | }
70 |
71 | foreach (string file in
72 | Directory.EnumerateFiles(o.InFile, "*", SearchOption.AllDirectories))
73 | {
74 | string outFolder = Path.GetDirectoryName(file).Replace(o.InFile, o.OutFile);
75 | if (!Directory.Exists(outFolder))
76 | {
77 | Directory.CreateDirectory(outFolder);
78 | }
79 | DecryptSingle(file, Path.Combine(outFolder, Path.GetFileName(file)), o.Key);
80 | }
81 | }
82 | else
83 | {
84 | DecryptSingle(o.InFile, o.OutFile, o.Key);
85 | }
86 | }
87 | });
88 | }
89 |
90 | static void DecryptSingle(string inFile, string outFile, string key)
91 | {
92 | using FileStream inStream = new FileStream(inFile, FileMode.Open, FileAccess.Read);
93 | BundleFile inBundleFile = new BundleFile(inStream, key: key);
94 | inBundleFile.Write(new FileStream(outFile, FileMode.Create, FileAccess.Write), unityCN: false);
95 | }
96 |
97 | static void EncryptSingle(string inFile, string outFile, string key)
98 | {
99 | using FileStream inStream = new FileStream(inFile, FileMode.Open, FileAccess.Read);
100 | BundleFile inBundleFile = new BundleFile(inStream);
101 | inBundleFile.Write(new FileStream(outFile, FileMode.Create, FileAccess.Write), infoPacker: "lz4hc",
102 | dataPacker: "lz4hc", unityCN: true, key: key);
103 | }
104 | }
105 | }
--------------------------------------------------------------------------------
/UnityCN-Helper/UnityCN-Helper.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | UnityCN_Helper
7 | enable
8 | enable
9 | Copyright © AXiX 2024
10 | $(Copyright)
11 |
12 | $(AssemblyName)
13 | false
14 | 1.4.1
15 | False
16 | https://github.com/AXiX-official/UnityCN-Helper
17 | README.md
18 | https://github.com/AXiX-official/UnityCN-Helper
19 | LICENSE
20 | True
21 |
22 |
23 |
24 |
25 | True
26 | \
27 |
28 |
29 | True
30 | \
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------