Shared => s_shared;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/AssetStudio/Brotli/BrotliRuntimeException.cs:
--------------------------------------------------------------------------------
1 | /* Copyright 2015 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 | namespace Org.Brotli.Dec
7 | {
8 | /// Unchecked exception used internally.
9 | [System.Serializable]
10 | internal class BrotliRuntimeException : System.Exception
11 | {
12 | internal BrotliRuntimeException(string message)
13 | : base(message)
14 | {
15 | }
16 |
17 | internal BrotliRuntimeException(string message, System.Exception cause)
18 | : base(message, cause)
19 | {
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/AssetStudio/Brotli/HuffmanTreeGroup.cs:
--------------------------------------------------------------------------------
1 | /* Copyright 2015 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 | namespace Org.Brotli.Dec
7 | {
8 | /// Contains a collection of huffman trees with the same alphabet size.
9 | internal sealed class HuffmanTreeGroup
10 | {
11 | /// The maximal alphabet size in this group.
12 | private int alphabetSize;
13 |
14 | /// Storage for Huffman lookup tables.
15 | internal int[] codes;
16 |
17 | ///
18 | /// Offsets of distinct lookup tables in
19 | ///
20 | /// storage.
21 | ///
22 | internal int[] trees;
23 |
24 | /// Initializes the Huffman tree group.
25 | /// POJO to be initialised
26 | /// the maximal alphabet size in this group
27 | /// number of Huffman codes
28 | internal static void Init(Org.Brotli.Dec.HuffmanTreeGroup group, int alphabetSize, int n)
29 | {
30 | group.alphabetSize = alphabetSize;
31 | group.codes = new int[n * Org.Brotli.Dec.Huffman.HuffmanMaxTableSize];
32 | group.trees = new int[n];
33 | }
34 |
35 | /// Decodes Huffman trees from input stream and constructs lookup tables.
36 | /// target POJO
37 | /// data source
38 | internal static void Decode(Org.Brotli.Dec.HuffmanTreeGroup group, Org.Brotli.Dec.BitReader br)
39 | {
40 | int next = 0;
41 | int n = group.trees.Length;
42 | for (int i = 0; i < n; i++)
43 | {
44 | group.trees[i] = next;
45 | Org.Brotli.Dec.Decode.ReadHuffmanCode(group.alphabetSize, group.codes, next, br);
46 | next += Org.Brotli.Dec.Huffman.HuffmanMaxTableSize;
47 | }
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/AssetStudio/Brotli/IntReader.cs:
--------------------------------------------------------------------------------
1 | /* Copyright 2017 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 | namespace Org.Brotli.Dec
7 | {
8 | /// Byte-to-int conversion magic.
9 | internal sealed class IntReader
10 | {
11 | private byte[] byteBuffer;
12 |
13 | private int[] intBuffer;
14 |
15 | internal static void Init(Org.Brotli.Dec.IntReader ir, byte[] byteBuffer, int[] intBuffer)
16 | {
17 | ir.byteBuffer = byteBuffer;
18 | ir.intBuffer = intBuffer;
19 | }
20 |
21 | /// Translates bytes to ints.
22 | ///
23 | /// Translates bytes to ints.
24 | /// NB: intLen == 4 * byteSize!
25 | /// NB: intLen should be less or equal to intBuffer length.
26 | ///
27 | internal static void Convert(Org.Brotli.Dec.IntReader ir, int intLen)
28 | {
29 | for (int i = 0; i < intLen; ++i)
30 | {
31 | ir.intBuffer[i] = ((ir.byteBuffer[i * 4] & unchecked((int)(0xFF)))) | ((ir.byteBuffer[(i * 4) + 1] & unchecked((int)(0xFF))) << 8) | ((ir.byteBuffer[(i * 4) + 2] & unchecked((int)(0xFF))) << 16) | ((ir.byteBuffer[(i * 4) + 3] & unchecked((int
32 | )(0xFF))) << 24);
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/AssetStudio/Brotli/Prefix.cs:
--------------------------------------------------------------------------------
1 | /* Copyright 2015 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 | namespace Org.Brotli.Dec
7 | {
8 | /// Lookup tables to map prefix codes to value ranges.
9 | ///
10 | /// Lookup tables to map prefix codes to value ranges.
11 | /// This is used during decoding of the block lengths, literal insertion lengths and copy
12 | /// lengths.
13 | ///
Range represents values: [offset, offset + 2 ^ n_bits)
14 | ///
15 | internal sealed class Prefix
16 | {
17 | internal static readonly int[] BlockLengthOffset = new int[] { 1, 5, 9, 13, 17, 25, 33, 41, 49, 65, 81, 97, 113, 145, 177, 209, 241, 305, 369, 497, 753, 1265, 2289, 4337, 8433, 16625 };
18 |
19 | internal static readonly int[] BlockLengthNBits = new int[] { 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 8, 9, 10, 11, 12, 13, 24 };
20 |
21 | internal static readonly int[] InsertLengthOffset = new int[] { 0, 1, 2, 3, 4, 5, 6, 8, 10, 14, 18, 26, 34, 50, 66, 98, 130, 194, 322, 578, 1090, 2114, 6210, 22594 };
22 |
23 | internal static readonly int[] InsertLengthNBits = new int[] { 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10, 12, 14, 24 };
24 |
25 | internal static readonly int[] CopyLengthOffset = new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 18, 22, 30, 38, 54, 70, 102, 134, 198, 326, 582, 1094, 2118 };
26 |
27 | internal static readonly int[] CopyLengthNBits = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10, 24 };
28 |
29 | internal static readonly int[] InsertRangeLut = new int[] { 0, 0, 8, 8, 0, 16, 8, 16, 16 };
30 |
31 | internal static readonly int[] CopyRangeLut = new int[] { 0, 8, 0, 8, 16, 0, 16, 8, 16 };
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/AssetStudio/Brotli/RunningState.cs:
--------------------------------------------------------------------------------
1 | /* Copyright 2015 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 | namespace Org.Brotli.Dec
7 | {
8 | /// Enumeration of decoding state-machine.
9 | internal sealed class RunningState
10 | {
11 | internal const int Uninitialized = 0;
12 |
13 | internal const int BlockStart = 1;
14 |
15 | internal const int CompressedBlockStart = 2;
16 |
17 | internal const int MainLoop = 3;
18 |
19 | internal const int ReadMetadata = 4;
20 |
21 | internal const int CopyUncompressed = 5;
22 |
23 | internal const int InsertLoop = 6;
24 |
25 | internal const int CopyLoop = 7;
26 |
27 | internal const int CopyWrapBuffer = 8;
28 |
29 | internal const int Transform = 9;
30 |
31 | internal const int Finished = 10;
32 |
33 | internal const int Closed = 11;
34 |
35 | internal const int Write = 12;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/AssetStudio/Brotli/Utils.cs:
--------------------------------------------------------------------------------
1 | /* Copyright 2015 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 | namespace Org.Brotli.Dec
7 | {
8 | /// A set of utility methods.
9 | internal sealed class Utils
10 | {
11 | private static readonly byte[] ByteZeroes = new byte[1024];
12 |
13 | private static readonly int[] IntZeroes = new int[1024];
14 |
15 | /// Fills byte array with zeroes.
16 | ///
17 | /// Fills byte array with zeroes.
18 | /// Current implementation uses
19 | ///
20 | /// , so it should be used for length not
21 | /// less than 16.
22 | ///
23 | /// array to fill with zeroes
24 | /// the first byte to fill
25 | /// number of bytes to change
26 | internal static void FillWithZeroes(byte[] dest, int offset, int length)
27 | {
28 | int cursor = 0;
29 | while (cursor < length)
30 | {
31 | int step = System.Math.Min(cursor + 1024, length) - cursor;
32 | System.Array.Copy(ByteZeroes, 0, dest, offset + cursor, step);
33 | cursor += step;
34 | }
35 | }
36 |
37 | /// Fills int array with zeroes.
38 | ///
39 | /// Fills int array with zeroes.
40 | /// Current implementation uses
41 | ///
42 | /// , so it should be used for length not
43 | /// less than 16.
44 | ///
45 | /// array to fill with zeroes
46 | /// the first item to fill
47 | /// number of item to change
48 | internal static void FillWithZeroes(int[] dest, int offset, int length)
49 | {
50 | int cursor = 0;
51 | while (cursor < length)
52 | {
53 | int step = System.Math.Min(cursor + 1024, length) - cursor;
54 | System.Array.Copy(IntZeroes, 0, dest, offset + cursor, step);
55 | cursor += step;
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/AssetStudio/Brotli/WordTransformType.cs:
--------------------------------------------------------------------------------
1 | /* Copyright 2015 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 | namespace Org.Brotli.Dec
7 | {
8 | /// Enumeration of all possible word transformations.
9 | ///
10 | /// Enumeration of all possible word transformations.
11 | /// There are two simple types of transforms: omit X first/last symbols, two character-case
12 | /// transforms and the identity transform.
13 | ///
14 | internal sealed class WordTransformType
15 | {
16 | internal const int Identity = 0;
17 |
18 | internal const int OmitLast1 = 1;
19 |
20 | internal const int OmitLast2 = 2;
21 |
22 | internal const int OmitLast3 = 3;
23 |
24 | internal const int OmitLast4 = 4;
25 |
26 | internal const int OmitLast5 = 5;
27 |
28 | internal const int OmitLast6 = 6;
29 |
30 | internal const int OmitLast7 = 7;
31 |
32 | internal const int OmitLast8 = 8;
33 |
34 | internal const int OmitLast9 = 9;
35 |
36 | internal const int UppercaseFirst = 10;
37 |
38 | internal const int UppercaseAll = 11;
39 |
40 | internal const int OmitFirst1 = 12;
41 |
42 | internal const int OmitFirst2 = 13;
43 |
44 | internal const int OmitFirst3 = 14;
45 |
46 | internal const int OmitFirst4 = 15;
47 |
48 | internal const int OmitFirst5 = 16;
49 |
50 | internal const int OmitFirst6 = 17;
51 |
52 | internal const int OmitFirst7 = 18;
53 |
54 | internal const int OmitFirst8 = 19;
55 |
56 | internal const int OmitFirst9 = 20;
57 |
58 | internal static int GetOmitFirst(int type)
59 | {
60 | return type >= OmitFirst1 ? (type - OmitFirst1 + 1) : 0;
61 | }
62 |
63 | internal static int GetOmitLast(int type)
64 | {
65 | return type <= OmitLast9 ? (type - OmitLast1 + 1) : 0;
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/AssetStudio/BuildTarget.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public enum BuildTarget
9 | {
10 | NoTarget = -2,
11 | AnyPlayer = -1,
12 | ValidPlayer = 1,
13 | StandaloneOSX = 2,
14 | StandaloneOSXPPC = 3,
15 | StandaloneOSXIntel = 4,
16 | StandaloneWindows,
17 | WebPlayer,
18 | WebPlayerStreamed,
19 | Wii = 8,
20 | iOS = 9,
21 | PS3,
22 | XBOX360,
23 | Broadcom = 12,
24 | Android = 13,
25 | StandaloneGLESEmu = 14,
26 | StandaloneGLES20Emu = 15,
27 | NaCl = 16,
28 | StandaloneLinux = 17,
29 | FlashPlayer = 18,
30 | StandaloneWindows64 = 19,
31 | WebGL,
32 | WSAPlayer,
33 | StandaloneLinux64 = 24,
34 | StandaloneLinuxUniversal,
35 | WP8Player,
36 | StandaloneOSXIntel64,
37 | BlackBerry,
38 | Tizen,
39 | PSP2,
40 | PS4,
41 | PSM,
42 | XboxOne,
43 | SamsungTV,
44 | N3DS,
45 | WiiU,
46 | tvOS,
47 | Switch,
48 | Lumin,
49 | Stadia,
50 | CloudRendering,
51 | GameCoreXboxSeries,
52 | GameCoreXboxOne,
53 | PS5,
54 | EmbeddedLinux,
55 | QNX,
56 | UnknownPlatform = 9999
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/AssetStudio/BuildType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public class BuildType
9 | {
10 | private string buildType;
11 |
12 | public BuildType(string type)
13 | {
14 | buildType = type;
15 | }
16 |
17 | public bool IsAlpha => buildType == "a";
18 | public bool IsPatch => buildType == "p";
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/Animation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public sealed class Animation : Behaviour
9 | {
10 | public PPtr[] m_Animations;
11 |
12 | public Animation(ObjectReader reader) : base(reader)
13 | {
14 | var m_Animation = new PPtr(reader);
15 | int numAnimations = reader.ReadInt32();
16 | m_Animations = new PPtr[numAnimations];
17 | for (int i = 0; i < numAnimations; i++)
18 | {
19 | m_Animations[i] = new PPtr(reader);
20 | }
21 | }
22 |
23 | public bool IsContainsAnimationClip(AnimationClip clip)
24 | {
25 | foreach (PPtr ptr in m_Animations)
26 | {
27 | if (ptr.TryGet(out var animationClip) && animationClip.Equals(clip))
28 | {
29 | return true;
30 | }
31 | }
32 | return false;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/AnimatorOverrideController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public class AnimationClipOverride
9 | {
10 | public PPtr m_OriginalClip;
11 | public PPtr m_OverrideClip;
12 |
13 | public AnimationClipOverride(ObjectReader reader)
14 | {
15 | m_OriginalClip = new PPtr(reader);
16 | m_OverrideClip = new PPtr(reader);
17 | }
18 | }
19 |
20 | public sealed class AnimatorOverrideController : RuntimeAnimatorController
21 | {
22 | public PPtr m_Controller;
23 | public AnimationClipOverride[] m_Clips;
24 |
25 | public AnimatorOverrideController(ObjectReader reader) : base(reader)
26 | {
27 | m_Controller = new PPtr(reader);
28 |
29 | int numOverrides = reader.ReadInt32();
30 | m_Clips = new AnimationClipOverride[numOverrides];
31 | for (int i = 0; i < numOverrides; i++)
32 | {
33 | m_Clips[i] = new AnimationClipOverride(reader);
34 | }
35 | }
36 |
37 | public override bool IsContainsAnimationClip(AnimationClip clip)
38 | {
39 | AnimationClip animationClip;
40 | foreach (AnimationClipOverride overClip in m_Clips)
41 | {
42 | if (overClip.m_OriginalClip.TryGet(out animationClip) && animationClip.Equals(clip))
43 | {
44 | return true;
45 | }
46 | else if (overClip.m_OverrideClip.TryGet(out animationClip) && animationClip.Equals(clip))
47 | {
48 | return true;
49 | }
50 | }
51 | if (m_Controller.TryGet(out var baseController))
52 | {
53 | return baseController.IsContainsAnimationClip(clip);
54 | }
55 | return false;
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/Behaviour.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public abstract class Behaviour : Component
9 | {
10 | public byte m_Enabled;
11 |
12 | protected Behaviour(ObjectReader reader) : base(reader)
13 | {
14 | m_Enabled = reader.ReadByte();
15 | reader.AlignStream();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/BuildSettings.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public sealed class BuildSettings : Object
9 | {
10 | public string m_Version;
11 |
12 | public BuildSettings(ObjectReader reader) : base(reader)
13 | {
14 | var levels = reader.ReadStringArray();
15 |
16 | var hasRenderTexture = reader.ReadBoolean();
17 | var hasPROVersion = reader.ReadBoolean();
18 | var hasPublishingRights = reader.ReadBoolean();
19 | var hasShadows = reader.ReadBoolean();
20 |
21 | m_Version = reader.ReadAlignedString();
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/Component.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public abstract class Component : EditorExtension
9 | {
10 | public PPtr m_GameObject;
11 |
12 | protected Component(ObjectReader reader) : base(reader)
13 | {
14 | m_GameObject = new PPtr(reader);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/EditorExtension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public abstract class EditorExtension : Object
9 | {
10 | protected EditorExtension(ObjectReader reader) : base(reader)
11 | {
12 | if (platform == BuildTarget.NoTarget)
13 | {
14 | var m_PrefabParentObject = new PPtr(reader);
15 | var m_PrefabInternal = new PPtr(reader); //PPtr
16 | }
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/IndexObject.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System.Collections.Generic;
3 |
4 | namespace AssetStudio
5 | {
6 | public class Index
7 | {
8 | public PPtr Object;
9 | public ulong Size;
10 |
11 | public Index(ObjectReader reader)
12 | {
13 |
14 | Object = new PPtr(reader);
15 | Size = reader.ReadUInt64();
16 | }
17 | }
18 |
19 | [JsonObject(MemberSerialization.OptIn)]
20 | public sealed class IndexObject : NamedObject
21 | {
22 | public static bool Exportable;
23 |
24 | [JsonProperty]
25 | public int Count;
26 | [JsonProperty]
27 | public KeyValuePair[] AssetMap;
28 | [JsonProperty]
29 | public Dictionary Names = new Dictionary();
30 |
31 | public IndexObject(ObjectReader reader) : base(reader)
32 | {
33 | Count = reader.ReadInt32();
34 | AssetMap = new KeyValuePair[Count];
35 | for (int i = 0; i < Count; i++)
36 | {
37 | var key = reader.ReadAlignedString();
38 | var value = new Index(reader);
39 |
40 | AssetMap[i] = new KeyValuePair(key, value);
41 |
42 | if (value.Object.m_FileID == 0)
43 | Names.Add(value.Object.m_PathID, key);
44 | }
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/MeshFilter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public sealed class MeshFilter : Component
9 | {
10 | public PPtr m_Mesh;
11 |
12 | public MeshFilter(ObjectReader reader) : base(reader)
13 | {
14 | m_Mesh = new PPtr(reader);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/MeshRenderer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public sealed class MeshRenderer : Renderer
9 | {
10 | public MeshRenderer(ObjectReader reader) : base(reader)
11 | {
12 | var m_AdditionalVertexStreams = new PPtr(reader);
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/MiHoYoBinData.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using System.Text.RegularExpressions;
4 | using Newtonsoft.Json.Linq;
5 | using Newtonsoft.Json;
6 |
7 | namespace AssetStudio
8 | {
9 | public enum MiHoYoBinDataType
10 | {
11 | None,
12 | Bytes,
13 | JSON
14 | }
15 | public sealed class MiHoYoBinData : Object
16 | {
17 | public static bool doXOR;
18 | public static byte Key;
19 | public byte[] RawData;
20 |
21 | public byte[] Data
22 | {
23 | get
24 | {
25 | if (doXOR)
26 | {
27 | byte[] bytes = new byte[RawData.Length];
28 | for (int i = 0; i < RawData.Length; i++)
29 | {
30 | bytes[i] = (byte)(RawData[i] ^ Key);
31 | }
32 | return bytes;
33 | }
34 | else return RawData;
35 | }
36 | }
37 |
38 | public string Str
39 | {
40 | get
41 | {
42 | var str = Encoding.UTF8.GetString(Data);
43 | switch (Type)
44 | {
45 | case MiHoYoBinDataType.JSON:
46 | return JToken.Parse(str).ToString(Formatting.Indented);
47 | case MiHoYoBinDataType.Bytes:
48 | return Regex.Replace(str, @"[^\u0020-\u007E]", string.Empty);
49 | default:
50 | return "";
51 | }
52 | }
53 | }
54 |
55 | public MiHoYoBinDataType Type
56 | {
57 | get
58 | {
59 | try
60 | {
61 | var str = Encoding.UTF8.GetString(Data);
62 | var asToken = JToken.Parse(str);
63 | if (asToken.Type == JTokenType.Object || asToken.Type == JTokenType.Array)
64 | return MiHoYoBinDataType.JSON;
65 | }
66 | catch (Exception)
67 | {
68 | return MiHoYoBinDataType.Bytes;
69 | }
70 | return MiHoYoBinDataType.None;
71 | }
72 | }
73 |
74 | public MiHoYoBinData(ObjectReader reader) : base(reader)
75 | {
76 | var length = reader.ReadInt32();
77 | RawData = reader.ReadBytes(length);
78 | }
79 |
80 | public new dynamic Dump()
81 | {
82 | switch (Type)
83 | {
84 | case MiHoYoBinDataType.JSON:
85 | return Str;
86 | case MiHoYoBinDataType.Bytes:
87 | return Data;
88 | default:
89 | return null;
90 | }
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/MonoBehaviour.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public sealed class MonoBehaviour : Behaviour
9 | {
10 | public PPtr m_Script;
11 | public string m_Name;
12 |
13 | public MonoBehaviour(ObjectReader reader) : base(reader)
14 | {
15 | m_Script = new PPtr(reader);
16 | m_Name = reader.ReadAlignedString();
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/MonoScript.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public sealed class MonoScript : NamedObject
9 | {
10 | public string m_ClassName;
11 | public string m_Namespace;
12 | public string m_AssemblyName;
13 |
14 | public MonoScript(ObjectReader reader) : base(reader)
15 | {
16 | if (version[0] > 3 || (version[0] == 3 && version[1] >= 4)) //3.4 and up
17 | {
18 | var m_ExecutionOrder = reader.ReadInt32();
19 | }
20 | if (version[0] < 5) //5.0 down
21 | {
22 | var m_PropertiesHash = reader.ReadUInt32();
23 | }
24 | else
25 | {
26 | var m_PropertiesHash = reader.ReadBytes(16);
27 | }
28 | if (version[0] < 3) //3.0 down
29 | {
30 | var m_PathName = reader.ReadAlignedString();
31 | }
32 | m_ClassName = reader.ReadAlignedString();
33 | if (version[0] >= 3) //3.0 and up
34 | {
35 | m_Namespace = reader.ReadAlignedString();
36 | }
37 | m_AssemblyName = reader.ReadAlignedString();
38 | if (version[0] < 2018 || (version[0] == 2018 && version[1] < 2)) //2018.2 down
39 | {
40 | var m_IsEditorScript = reader.ReadBoolean();
41 | }
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/MovieTexture.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public sealed class MovieTexture : Texture
9 | {
10 | public byte[] m_MovieData;
11 | public PPtr m_AudioClip;
12 |
13 | public MovieTexture(ObjectReader reader) : base(reader)
14 | {
15 | var m_Loop = reader.ReadBoolean();
16 | reader.AlignStream();
17 | m_AudioClip = new PPtr(reader);
18 | m_MovieData = reader.ReadUInt8Array();
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/NamedObject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public class NamedObject : EditorExtension
9 | {
10 | public string m_Name;
11 |
12 | protected NamedObject(ObjectReader reader) : base(reader)
13 | {
14 | m_Name = reader.ReadAlignedString();
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/Object.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Specialized;
2 |
3 | namespace AssetStudio
4 | {
5 | public class Object
6 | {
7 | public SerializedFile assetsFile;
8 | public ObjectReader reader;
9 | public long m_PathID;
10 | public int[] version;
11 | protected BuildType buildType;
12 | public BuildTarget platform;
13 | public ClassIDType type;
14 | public SerializedType serializedType;
15 | public uint byteSize;
16 |
17 | public Object(ObjectReader reader)
18 | {
19 | this.reader = reader;
20 | reader.Reset();
21 | assetsFile = reader.assetsFile;
22 | type = reader.type;
23 | m_PathID = reader.m_PathID;
24 | version = reader.version;
25 | buildType = reader.buildType;
26 | platform = reader.platform;
27 | serializedType = reader.serializedType;
28 | byteSize = reader.byteSize;
29 |
30 | if (platform == BuildTarget.NoTarget)
31 | {
32 | var m_ObjectHideFlags = reader.ReadUInt32();
33 | }
34 | }
35 |
36 | public string Dump()
37 | {
38 | if (serializedType?.m_Type != null)
39 | {
40 | return TypeTreeHelper.ReadTypeString(serializedType.m_Type, reader);
41 | }
42 | return null;
43 | }
44 |
45 | public string Dump(TypeTree m_Type)
46 | {
47 | if (m_Type != null)
48 | {
49 | return TypeTreeHelper.ReadTypeString(m_Type, reader);
50 | }
51 | return null;
52 | }
53 |
54 | public OrderedDictionary ToType()
55 | {
56 | if (serializedType?.m_Type != null)
57 | {
58 | return TypeTreeHelper.ReadType(serializedType.m_Type, reader);
59 | }
60 | return null;
61 | }
62 |
63 | public OrderedDictionary ToType(TypeTree m_Type)
64 | {
65 | if (m_Type != null)
66 | {
67 | return TypeTreeHelper.ReadType(m_Type, reader);
68 | }
69 | return null;
70 | }
71 |
72 | public byte[] GetRawData()
73 | {
74 | reader.Reset();
75 | return reader.ReadBytes((int)byteSize);
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/PlayerSettings.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public sealed class PlayerSettings : Object
9 | {
10 | public string companyName;
11 | public string productName;
12 |
13 | public PlayerSettings(ObjectReader reader) : base(reader)
14 | {
15 | if (version[0] > 5 || (version[0] == 5 && version[1] >= 4)) //5.4.0 nad up
16 | {
17 | var productGUID = reader.ReadBytes(16);
18 | }
19 |
20 | var AndroidProfiler = reader.ReadBoolean();
21 | //bool AndroidFilterTouchesWhenObscured 2017.2 and up
22 | //bool AndroidEnableSustainedPerformanceMode 2018 and up
23 | reader.AlignStream();
24 | int defaultScreenOrientation = reader.ReadInt32();
25 | int targetDevice = reader.ReadInt32();
26 | if (version[0] < 5 || (version[0] == 5 && version[1] < 3)) //5.3 down
27 | {
28 | if (version[0] < 5) //5.0 down
29 | {
30 | int targetPlatform = reader.ReadInt32(); //4.0 and up targetGlesGraphics
31 | if (version[0] > 4 || (version[0] == 4 && version[1] >= 6)) //4.6 and up
32 | {
33 | var targetIOSGraphics = reader.ReadInt32();
34 | }
35 | }
36 | int targetResolution = reader.ReadInt32();
37 | }
38 | else
39 | {
40 | var useOnDemandResources = reader.ReadBoolean();
41 | reader.AlignStream();
42 | }
43 | if (version[0] > 3 || (version[0] == 3 && version[1] >= 5)) //3.5 and up
44 | {
45 | var accelerometerFrequency = reader.ReadInt32();
46 | }
47 | companyName = reader.ReadAlignedString();
48 | productName = reader.ReadAlignedString();
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/RectTransform.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public sealed class RectTransform : Transform
9 | {
10 | public RectTransform(ObjectReader reader) : base(reader)
11 | {
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/ResourceManager.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace AssetStudio
4 | {
5 | public class ResourceManager : Object
6 | {
7 | public KeyValuePair>[] m_Container;
8 |
9 | public ResourceManager(ObjectReader reader) : base(reader)
10 | {
11 | var m_ContainerSize = reader.ReadInt32();
12 | m_Container = new KeyValuePair>[m_ContainerSize];
13 | for (int i = 0; i < m_ContainerSize; i++)
14 | {
15 | m_Container[i] = new KeyValuePair>(reader.ReadAlignedString(), new PPtr(reader));
16 | }
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/RuntimeAnimatorController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public abstract class RuntimeAnimatorController : NamedObject
9 | {
10 | protected RuntimeAnimatorController(ObjectReader reader) : base(reader)
11 | {
12 |
13 | }
14 |
15 | public abstract bool IsContainsAnimationClip(AnimationClip clip);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/SkinnedMeshRenderer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public sealed class SkinnedMeshRenderer : Renderer
9 | {
10 | public PPtr m_Mesh;
11 | public PPtr[] m_Bones;
12 | public PPtr m_RootBone;
13 | public float[] m_BlendShapeWeights;
14 | public AABB m_AABB;
15 | public bool m_DirtyAABB;
16 |
17 | public SkinnedMeshRenderer(ObjectReader reader) : base(reader)
18 | {
19 | int m_Quality = reader.ReadInt32();
20 | var m_UpdateWhenOffscreen = reader.ReadBoolean();
21 | var m_SkinNormals = reader.ReadBoolean(); //3.1.0 and below
22 | reader.AlignStream();
23 |
24 | if (version[0] == 2 && version[1] < 6) //2.6 down
25 | {
26 | var m_DisableAnimationWhenOffscreen = new PPtr(reader);
27 | }
28 |
29 | m_Mesh = new PPtr(reader);
30 |
31 | m_Bones = new PPtr[reader.ReadInt32()];
32 | for (int b = 0; b < m_Bones.Length; b++)
33 | {
34 | m_Bones[b] = new PPtr(reader);
35 | }
36 | reader.AlignStream();
37 | if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up
38 | {
39 | m_BlendShapeWeights = reader.ReadSingleArray();
40 | }
41 | reader.AlignStream();
42 | m_RootBone = new PPtr(reader);
43 | m_AABB = new AABB(reader);
44 | m_DirtyAABB = reader.ReadBoolean();
45 | reader.AlignStream();
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/SpriteAtlas.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace AssetStudio
5 | {
6 | public class SpriteAtlasData
7 | {
8 | public PPtr texture;
9 | public PPtr alphaTexture;
10 | public Rectf textureRect;
11 | public Vector2 textureRectOffset;
12 | public Vector2 atlasRectOffset;
13 | public Vector4 uvTransform;
14 | public float downscaleMultiplier;
15 | public SpriteSettings settingsRaw;
16 | public SecondarySpriteTexture[] secondaryTextures;
17 |
18 | public SpriteAtlasData(ObjectReader reader)
19 | {
20 | var version = reader.version;
21 | texture = new PPtr(reader);
22 | alphaTexture = new PPtr(reader);
23 | textureRect = new Rectf(reader);
24 | textureRectOffset = reader.ReadVector2();
25 | if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 2)) //2017.2 and up
26 | {
27 | atlasRectOffset = reader.ReadVector2();
28 | }
29 | uvTransform = reader.ReadVector4();
30 | downscaleMultiplier = reader.ReadSingle();
31 | settingsRaw = new SpriteSettings(reader);
32 | if (version[0] > 2020 || (version[0] == 2020 && version[1] >= 2)) //2020.2 and up
33 | {
34 | var secondaryTexturesSize = reader.ReadInt32();
35 | secondaryTextures = new SecondarySpriteTexture[secondaryTexturesSize];
36 | for (int i = 0; i < secondaryTexturesSize; i++)
37 | {
38 | secondaryTextures[i] = new SecondarySpriteTexture(reader);
39 | }
40 | reader.AlignStream();
41 | }
42 | }
43 | }
44 |
45 | public sealed class SpriteAtlas : NamedObject
46 | {
47 | public PPtr[] m_PackedSprites;
48 | public Dictionary, SpriteAtlasData> m_RenderDataMap;
49 | public bool m_IsVariant;
50 |
51 | public SpriteAtlas(ObjectReader reader) : base(reader)
52 | {
53 | var m_PackedSpritesSize = reader.ReadInt32();
54 | m_PackedSprites = new PPtr[m_PackedSpritesSize];
55 | for (int i = 0; i < m_PackedSpritesSize; i++)
56 | {
57 | m_PackedSprites[i] = new PPtr(reader);
58 | }
59 |
60 | var m_PackedSpriteNamesToIndex = reader.ReadStringArray();
61 |
62 | var m_RenderDataMapSize = reader.ReadInt32();
63 | m_RenderDataMap = new Dictionary, SpriteAtlasData>(m_RenderDataMapSize);
64 | for (int i = 0; i < m_RenderDataMapSize; i++)
65 | {
66 | var first = new Guid(reader.ReadBytes(16));
67 | var second = reader.ReadInt64();
68 | var value = new SpriteAtlasData(reader);
69 | m_RenderDataMap.Add(new KeyValuePair(first, second), value);
70 | }
71 | var m_Tag = reader.ReadAlignedString();
72 | m_IsVariant = reader.ReadBoolean();
73 | reader.AlignStream();
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/TextAsset.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 | using System.Text;
6 |
7 | namespace AssetStudio
8 | {
9 | public sealed class TextAsset : NamedObject
10 | {
11 | public byte[] m_Script;
12 |
13 | public TextAsset(ObjectReader reader) : base(reader)
14 | {
15 | m_Script = reader.ReadUInt8Array();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/Texture.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public abstract class Texture : NamedObject
9 | {
10 | protected Texture(ObjectReader reader) : base(reader)
11 | {
12 | if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 3)) //2017.3 and up
13 | {
14 | var m_ForcedFallbackFormat = reader.ReadInt32();
15 | var m_DownscaleFallback = reader.ReadBoolean();
16 | if (version[0] > 2020 || (version[0] == 2020 && version[1] >= 2)) //2020.2 and up
17 | {
18 | var m_IsAlphaChannelOptional = reader.ReadBoolean();
19 | }
20 | reader.AlignStream();
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/Transform.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public class Transform : Component
9 | {
10 | public Quaternion m_LocalRotation;
11 | public Vector3 m_LocalPosition;
12 | public Vector3 m_LocalScale;
13 | public PPtr[] m_Children;
14 | public PPtr m_Father;
15 |
16 | public Transform(ObjectReader reader) : base(reader)
17 | {
18 | m_LocalRotation = reader.ReadQuaternion();
19 | m_LocalPosition = reader.ReadVector3();
20 | m_LocalScale = reader.ReadVector3();
21 |
22 | int m_ChildrenCount = reader.ReadInt32();
23 | m_Children = new PPtr[m_ChildrenCount];
24 | for (int i = 0; i < m_ChildrenCount; i++)
25 | {
26 | m_Children[i] = new PPtr(reader);
27 | }
28 | m_Father = new PPtr(reader);
29 | }
30 |
31 | public Transform FindChild(string path)
32 | {
33 | if (path.Length == 0)
34 | {
35 | return this;
36 | }
37 | return FindChild(path, 0);
38 | }
39 | private Transform FindChild(string path, int startIndex)
40 | {
41 | int separatorIndex = path.IndexOf('/', startIndex);
42 | string childName = separatorIndex == -1 ?
43 | path.Substring(startIndex, path.Length - startIndex) :
44 | path.Substring(startIndex, separatorIndex - startIndex);
45 | foreach (PPtr childPtr in m_Children)
46 | {
47 | if(childPtr.TryGet(out var child))
48 | {
49 | if (child.m_GameObject.TryGet(out var childGO) && childGO.m_Name == childName)
50 | {
51 | return separatorIndex == -1 ? child : child.FindChild(path, separatorIndex + 1);
52 | }
53 | }
54 | }
55 | return null;
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/VideoClip.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace AssetStudio
4 | {
5 | public class StreamedResource
6 | {
7 | public string m_Source;
8 | public long m_Offset; //ulong
9 | public long m_Size; //ulong
10 |
11 | public StreamedResource(BinaryReader reader)
12 | {
13 | m_Source = reader.ReadAlignedString();
14 | m_Offset = reader.ReadInt64();
15 | m_Size = reader.ReadInt64();
16 | }
17 | }
18 |
19 | public sealed class VideoClip : NamedObject
20 | {
21 | public ResourceReader m_VideoData;
22 | public string m_OriginalPath;
23 | public StreamedResource m_ExternalResources;
24 |
25 | public VideoClip(ObjectReader reader) : base(reader)
26 | {
27 | m_OriginalPath = reader.ReadAlignedString();
28 | var m_ProxyWidth = reader.ReadUInt32();
29 | var m_ProxyHeight = reader.ReadUInt32();
30 | var Width = reader.ReadUInt32();
31 | var Height = reader.ReadUInt32();
32 | if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 2)) //2017.2 and up
33 | {
34 | var m_PixelAspecRatioNum = reader.ReadUInt32();
35 | var m_PixelAspecRatioDen = reader.ReadUInt32();
36 | }
37 | var m_FrameRate = reader.ReadDouble();
38 | var m_FrameCount = reader.ReadUInt64();
39 | var m_Format = reader.ReadInt32();
40 | var m_AudioChannelCount = reader.ReadUInt16Array();
41 | reader.AlignStream();
42 | var m_AudioSampleRate = reader.ReadUInt32Array();
43 | var m_AudioLanguage = reader.ReadStringArray();
44 | if (version[0] >= 2020) //2020.1 and up
45 | {
46 | var m_VideoShadersSize = reader.ReadInt32();
47 | var m_VideoShaders = new PPtr[m_VideoShadersSize];
48 | for (int i = 0; i < m_VideoShadersSize; i++)
49 | {
50 | m_VideoShaders[i] = new PPtr(reader);
51 | }
52 | }
53 | m_ExternalResources = new StreamedResource(reader);
54 | var m_HasSplitAlpha = reader.ReadBoolean();
55 | if (version[0] >= 2020) //2020.1 and up
56 | {
57 | var m_sRGB = reader.ReadBoolean();
58 | }
59 |
60 | ResourceReader resourceReader;
61 | if (!string.IsNullOrEmpty(m_ExternalResources.m_Source))
62 | {
63 | resourceReader = new ResourceReader(m_ExternalResources.m_Source, assetsFile, m_ExternalResources.m_Offset, m_ExternalResources.m_Size);
64 | }
65 | else
66 | {
67 | resourceReader = new ResourceReader(reader, reader.BaseStream.Position, m_ExternalResources.m_Size);
68 | }
69 | m_VideoData = resourceReader;
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/AssetStudio/EndianType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace AssetStudio
8 | {
9 | public enum EndianType
10 | {
11 | LittleEndian,
12 | BigEndian
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/AssetStudio/Extensions/BinaryWriterExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Text;
4 |
5 | namespace AssetStudio
6 | {
7 | public static class BinaryWriterExtensions
8 | {
9 | public static void AlignStream(this BinaryWriter writer, int alignment)
10 | {
11 | var pos = writer.BaseStream.Position;
12 | var mod = pos % alignment;
13 | if (mod != 0)
14 | {
15 | writer.Write(new byte[alignment - mod]);
16 | }
17 | }
18 |
19 | public static void WriteAlignedString(this BinaryWriter writer, string str)
20 | {
21 | var bytes = Encoding.UTF8.GetBytes(str);
22 | writer.Write(bytes.Length);
23 | writer.Write(bytes);
24 | writer.AlignStream(4);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/AssetStudio/Extensions/PrimitiveExtensions.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | public static class PrimitiveExtensions
4 | {
5 | public static int ParseDigit(this char _this)
6 | {
7 | return _this - '0';
8 | }
9 |
10 | public static string ToHexString(this byte _this)
11 | {
12 | return _this.ToString("x2");
13 | }
14 |
15 | public static string ToHexString(this short _this)
16 | {
17 | ushort value = unchecked((ushort)_this);
18 | return ToHexString(value);
19 | }
20 |
21 | public static string ToHexString(this ushort _this)
22 | {
23 | ushort reverse = unchecked((ushort)(((0xFF00 & _this) >> 8) | ((0x00FF & _this) << 8)));
24 | return reverse.ToString("x4");
25 | }
26 |
27 | public static string ToHexString(this int _this)
28 | {
29 | uint value = unchecked((uint)_this);
30 | return ToHexString(value);
31 | }
32 |
33 | public static string ToHexString(this uint _this)
34 | {
35 | uint reverse = ((0xFF000000 & _this) >> 24) | ((0x00FF0000 & _this) >> 8) | ((0x0000FF00 & _this) << 8) | ((0x000000FF & _this) << 24);
36 | return reverse.ToString("x8");
37 | }
38 |
39 | public static string ToHexString(this long _this)
40 | {
41 | ulong value = unchecked((ulong)_this);
42 | return ToHexString(value);
43 | }
44 |
45 | public static string ToHexString(this ulong _this)
46 | {
47 | ulong reverse = (_this & 0x00000000000000FFUL) << 56 | (_this & 0x000000000000FF00UL) << 40 |
48 | (_this & 0x0000000000FF0000UL) << 24 | (_this & 0x00000000FF000000UL) << 8 |
49 | (_this & 0x000000FF00000000UL) >> 8 | (_this & 0x0000FF0000000000UL) >> 24 |
50 | (_this & 0x00FF000000000000UL) >> 40 | (_this & 0xFF00000000000000UL) >> 56;
51 | return reverse.ToString("x16");
52 | }
53 |
54 | public static string ToHexString(this float _this)
55 | {
56 | uint value = BitConverterExtensions.ToUInt32(_this);
57 | return ToHexString(value);
58 | }
59 |
60 | public static string ToHexString(this double _this)
61 | {
62 | ulong value = BitConverterExtensions.ToUInt64(_this);
63 | return ToHexString(value);
64 | }
65 |
66 | public static int ToClosestInt(this long _this)
67 | {
68 | if (_this > int.MaxValue)
69 | {
70 | return int.MaxValue;
71 | }
72 | if (_this < int.MinValue)
73 | {
74 | return int.MinValue;
75 | }
76 | return unchecked((int)_this);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/AssetStudio/Extensions/StreamExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace AssetStudio
4 | {
5 | public static class StreamExtensions
6 | {
7 | private const int BufferSize = 81920;
8 |
9 | public static void CopyTo(this Stream source, Stream destination, long size)
10 | {
11 | var buffer = new byte[BufferSize];
12 | for (var left = size; left > 0; left -= BufferSize)
13 | {
14 | int toRead = BufferSize < left ? BufferSize : (int)left;
15 | int read = source.Read(buffer, 0, toRead);
16 | destination.Write(buffer, 0, read);
17 | if (read != toRead)
18 | {
19 | return;
20 | }
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/AssetStudio/Extensions/StringBuilderExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Text;
2 |
3 | namespace AssetStudio
4 | {
5 | public static class StringBuilderExtensions
6 | {
7 | static StringBuilderExtensions()
8 | {
9 | for (int i = 0; i <= byte.MaxValue; i++)
10 | {
11 | ByteHexRepresentations[i] = i.ToString("x2");
12 | }
13 | }
14 |
15 | public static StringBuilder AppendHex(this StringBuilder _this, byte value)
16 | {
17 | _this.Append(ByteHexRepresentations[value]);
18 | return _this;
19 | }
20 |
21 | public static StringBuilder AppendHex(this StringBuilder _this, ushort value)
22 | {
23 | _this.Append(ByteHexRepresentations[(value >> 0) & 0xFF]);
24 | _this.Append(ByteHexRepresentations[(value >> 8) & 0xFF]);
25 | return _this;
26 | }
27 |
28 | public static StringBuilder AppendHex(this StringBuilder _this, short value)
29 | {
30 | return AppendHex(_this, unchecked((ushort)value));
31 | }
32 |
33 | public static StringBuilder AppendHex(this StringBuilder _this, uint value)
34 | {
35 | _this.Append(ByteHexRepresentations[unchecked((int)(value >> 0) & 0xFF)]);
36 | _this.Append(ByteHexRepresentations[unchecked((int)(value >> 8) & 0xFF)]);
37 | _this.Append(ByteHexRepresentations[unchecked((int)(value >> 16) & 0xFF)]);
38 | _this.Append(ByteHexRepresentations[unchecked((int)(value >> 24) & 0xFF)]);
39 | return _this;
40 | }
41 |
42 | public static StringBuilder AppendHex(this StringBuilder _this, int value)
43 | {
44 | return AppendHex(_this, unchecked((uint)value));
45 | }
46 |
47 | public static StringBuilder AppendHex(this StringBuilder _this, ulong value)
48 | {
49 | _this.Append(ByteHexRepresentations[unchecked((int)(value >> 0) & 0xFF)]);
50 | _this.Append(ByteHexRepresentations[unchecked((int)(value >> 8) & 0xFF)]);
51 | _this.Append(ByteHexRepresentations[unchecked((int)(value >> 16) & 0xFF)]);
52 | _this.Append(ByteHexRepresentations[unchecked((int)(value >> 24) & 0xFF)]);
53 | _this.Append(ByteHexRepresentations[unchecked((int)(value >> 32) & 0xFF)]);
54 | _this.Append(ByteHexRepresentations[unchecked((int)(value >> 40) & 0xFF)]);
55 | _this.Append(ByteHexRepresentations[unchecked((int)(value >> 48) & 0xFF)]);
56 | _this.Append(ByteHexRepresentations[unchecked((int)(value >> 56) & 0xFF)]);
57 | return _this;
58 | }
59 |
60 | public static StringBuilder AppendHex(this StringBuilder _this, long value)
61 | {
62 | return AppendHex(_this, unchecked((ulong)value));
63 | }
64 |
65 | public static StringBuilder AppendHex(this StringBuilder _this, float value)
66 | {
67 | return AppendHex(_this, BitConverterExtensions.ToUInt32(value));
68 | }
69 |
70 | public static StringBuilder AppendHex(this StringBuilder _this, double value)
71 | {
72 | return AppendHex(_this, BitConverterExtensions.ToUInt64(value));
73 | }
74 |
75 | public static StringBuilder AppendIndent(this StringBuilder _this, int count)
76 | {
77 | for (int i = 0; i < count; i++)
78 | {
79 | _this.Append('\t');
80 | }
81 | return _this;
82 | }
83 |
84 | public static readonly string HexAlphabet = "0123456789abcdef";
85 | public static readonly string[] ByteHexRepresentations = new string[256];
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/AssetStudio/FileIdentifier.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public class FileIdentifier
9 | {
10 | public Guid guid;
11 | public int type; //enum { kNonAssetType = 0, kDeprecatedCachedAssetType = 1, kSerializedAssetType = 2, kMetaAssetType = 3 };
12 | public string pathName;
13 |
14 | //custom
15 | public string fileName;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/AssetStudio/FileType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace AssetStudio
8 | {
9 | public enum FileType
10 | {
11 | AssetsFile,
12 | BundleFile,
13 | HoyoFile,
14 | WebFile,
15 | ResourceFile,
16 | GZipFile,
17 | BrotliFile,
18 | ZipFile
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/AssetStudio/HoYo/BH3/WMVFile.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace AssetStudio
4 | {
5 | public class WMVFile
6 | {
7 | public Dictionary Bundles = new Dictionary();
8 | public WMVFile(FileReader reader)
9 | {
10 | if (reader.BundlePos.Length != 0)
11 | {
12 | foreach (var pos in reader.BundlePos)
13 | {
14 | reader.Position = pos;
15 | var bundle = new BundleFile(reader);
16 | Bundles.Add(pos, bundle.FileList);
17 | }
18 | }
19 | else
20 | {
21 | while (reader.Position != reader.Length)
22 | {
23 | var pos = reader.Position;
24 | var bundle = new BundleFile(reader);
25 | Bundles.Add(pos, bundle.FileList);
26 | }
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/AssetStudio/HoYo/Crypto/MT19937_64.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | public class MT19937_64
4 | {
5 | private const ulong N = 312;
6 | private const ulong M = 156;
7 | private const ulong MATRIX_A = 0xB5026F5AA96619E9L;
8 | private const ulong UPPER_MASK = 0xFFFFFFFF80000000;
9 | private const ulong LOWER_MASK = 0X7FFFFFFFUL;
10 | private static ulong[] mt = new ulong[N + 1];
11 | private static ulong mti = N + 1;
12 |
13 | public MT19937_64(ulong seed)
14 | {
15 | this.Seed(seed);
16 | }
17 |
18 | public void Seed(ulong seed)
19 | {
20 | mt[0] = seed;
21 | for (mti = 1; mti < N; mti++)
22 | {
23 | mt[mti] = (6364136223846793005L * (mt[mti - 1] ^ (mt[mti - 1] >> 62)) + mti);
24 | }
25 | }
26 |
27 | public ulong Int63()
28 | {
29 | ulong x = 0;
30 | ulong[] mag01 = new ulong[2] { 0x0UL, MATRIX_A };
31 |
32 | if (mti >= N)
33 | {
34 | ulong kk;
35 | if (mti == N + 1)
36 | {
37 | Seed(5489UL);
38 | }
39 | for (kk = 0; kk < (N - M); kk++)
40 | {
41 | x = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
42 | mt[kk] = mt[kk + M] ^ (x >> 1) ^ mag01[x & 0x1UL];
43 | }
44 | for (; kk < N - 1; kk++)
45 | {
46 | x = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
47 | mt[kk] = mt[kk - M] ^ (x >> 1) ^ mag01[x & 0x1UL];
48 | }
49 | x = (mt[N - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
50 | mt[N - 1] = mt[M - 1] ^ (x >> 1) ^ mag01[x & 0x1UL];
51 |
52 | mti = 0;
53 | }
54 |
55 | x = mt[mti++];
56 | x ^= (x >> 29) & 0x5555555555555555L;
57 | x ^= (x << 17) & 0x71D67FFFEDA60000L;
58 | x ^= (x << 37) & 0xFFF7EEE000000000L;
59 | x ^= (x >> 43);
60 | return x;
61 | }
62 |
63 | public ulong IntN(ulong value)
64 | {
65 | return Int63() % value;
66 | }
67 | }
68 | }
--------------------------------------------------------------------------------
/AssetStudio/HoYo/Crypto/Mr0k.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace AssetStudio
5 | {
6 | public static class Mr0k
7 | {
8 | public static byte[] ExpansionKey;
9 | public static byte[] Key;
10 | public static byte[] ConstKey;
11 | public static byte[] SBox;
12 | public static byte[] BlockKey;
13 | public static void Decrypt(ref byte[] bytes, ref int size)
14 | {
15 | var key1 = new byte[0x10];
16 | var key2 = new byte[0x10];
17 | var key3 = new byte[0x10];
18 |
19 | Buffer.BlockCopy(bytes, 4, key1, 0, key1.Length);
20 | Buffer.BlockCopy(bytes, 0x74, key2, 0, key2.Length);
21 | Buffer.BlockCopy(bytes, 0x84, key3, 0, key3.Length);
22 |
23 | var encryptedBlockSize = Math.Min(0x10 * ((size - 0x94) >> 7), 0x400);
24 | var encryptedBlock = new byte[encryptedBlockSize];
25 |
26 | Buffer.BlockCopy(bytes, 0x94, encryptedBlock, 0, encryptedBlockSize);
27 |
28 | if (ConstKey != null)
29 | {
30 | for (int i = 0; i < ConstKey.Length; i++)
31 | key2[i] ^= ConstKey[i];
32 | }
33 |
34 | if (SBox != null)
35 | {
36 | for (int i = 0; i < 0x10; i++)
37 | key1[i] = SBox[(i % 4 * 0x100) | key1[i]];
38 | }
39 |
40 | AES.Decrypt(key1, ExpansionKey);
41 | AES.Decrypt(key3, ExpansionKey);
42 |
43 | for (int i = 0; i < key1.Length; i++)
44 | {
45 | key1[i] ^= key3[i];
46 | }
47 |
48 | Buffer.BlockCopy(key1, 0, bytes, 0x84, key1.Length);
49 |
50 | var seed1 = BitConverter.ToUInt64(key2, 0);
51 | var seed2 = BitConverter.ToUInt64(key3, 0);
52 | var seed = seed2 ^ seed1 ^ (seed1 + (uint)size - 20);
53 | var seedBytes = BitConverter.GetBytes(seed);
54 |
55 | for (var i = 0; i < encryptedBlockSize; i++)
56 | {
57 | encryptedBlock[i] ^= (byte)(seedBytes[i % 8] ^ Key[i]);
58 | }
59 |
60 | Buffer.BlockCopy(encryptedBlock, 0, bytes, 0x94, encryptedBlockSize);
61 |
62 | size -= 0x14;
63 | bytes = bytes.AsSpan(0x14, size).ToArray();
64 |
65 | if (BlockKey != null)
66 | {
67 | for (int i = 0; i < 0xC00; i++)
68 | {
69 | bytes[i] ^= BlockKey[i % BlockKey.Length];
70 | }
71 |
72 | }
73 | }
74 |
75 | public static bool IsMr0k(byte[] bytes)
76 | {
77 | using (var ms = new MemoryStream(bytes))
78 | using (var reader = new EndianBinaryReader(ms))
79 | {
80 | var header = reader.ReadStringToNull(4);
81 | return header == "mr0k";
82 | }
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/AssetStudio/HoYo/Crypto/XORShift128.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Buffers.Binary;
3 |
4 | namespace AssetStudio
5 | {
6 | public class XORShift128
7 | {
8 | public uint x = 0, y = 0, z = 0, w = 0, initseed = 0;
9 |
10 | const long SEED = 0x61C8864E7A143579;
11 | const uint MT19937 = 0x6C078965;
12 |
13 | public void InitSeed(int seed)
14 | {
15 | initseed = (uint)seed;
16 | x = (uint)seed;
17 | y = MT19937 * x + 1;
18 | z = MT19937 * y + 1;
19 | w = MT19937 * z + 1;
20 | }
21 |
22 | public uint XORShift()
23 | {
24 | uint t = x ^ (x << 11);
25 | x = y; y = z; z = w;
26 | return w = w ^ (w >> 19) ^ t ^ (t >> 8);
27 | }
28 |
29 | public uint NextUInt32()
30 | {
31 | return XORShift();
32 | }
33 |
34 | public int NextDecryptInt() => BinaryPrimitives.ReadInt32LittleEndian(NextDecrypt(4));
35 | public uint NextDecryptUInt() => BinaryPrimitives.ReadUInt32LittleEndian(NextDecrypt(4));
36 |
37 | public long NextDecryptLong() => BinaryPrimitives.ReadInt64LittleEndian(NextDecrypt(8));
38 |
39 | public byte[] NextDecrypt(int size)
40 | {
41 | var valueBytes = new byte[size];
42 | var key = size * initseed - SEED;
43 | var keyBytes = BitConverter.GetBytes(key);
44 | for (int i = 0; i < size; i++)
45 | {
46 | var val = NextUInt32();
47 | valueBytes[i] = keyBytes[val % 8];
48 | }
49 | return valueBytes;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/AssetStudio/HoYo/GI/BlkFile.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 |
5 | namespace AssetStudio
6 | {
7 | public class BlkFile
8 | {
9 | public Dictionary Bundles = new Dictionary();
10 | public BlkFile(FileReader reader)
11 | {
12 | reader.Endian = EndianType.LittleEndian;
13 |
14 | var magic = reader.ReadStringToNull();
15 | if (magic != "blk")
16 | throw new Exception("not a blk");
17 |
18 | var count = reader.ReadInt32();
19 | var key = reader.ReadBytes(count);
20 | reader.ReadBytes(count);
21 |
22 | var blockSize = reader.ReadUInt16();
23 | var data = reader.ReadBytes((int)(reader.Length - reader.Position));
24 |
25 | data = Crypto.Decrypt(key, data, blockSize);
26 |
27 | using (var ms = new MemoryStream(data))
28 | using (var subReader = new EndianBinaryReader(ms, reader.Endian))
29 | {
30 | long pos = -1;
31 | try
32 | {
33 | if (reader.BundlePos.Length != 0)
34 | {
35 | for (int i = 0; i < reader.BundlePos.Length; i++)
36 | {
37 | pos = reader.BundlePos[i];
38 | subReader.Position = pos;
39 | var mhy0 = new Mhy0File(subReader, reader.FullPath);
40 | Bundles.Add(pos, mhy0.FileList);
41 | }
42 | }
43 | else
44 | {
45 | while (subReader.Position != subReader.BaseStream.Length)
46 | {
47 | pos = subReader.Position;
48 | var mhy0 = new Mhy0File(subReader, reader.FullPath);
49 | Bundles.Add(pos, mhy0.FileList);
50 | }
51 | }
52 | }
53 | catch (Exception ex)
54 | {
55 | Console.WriteLine($"Failed to load a mhy0 at {string.Format("0x{0:x8}", pos)} in {Path.GetFileName(reader.FullPath)}");
56 | Console.WriteLine(ex.Message);
57 | }
58 | }
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/AssetStudio/HoYo/HoYoFile.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Collections.Generic;
4 |
5 | namespace AssetStudio
6 | {
7 | public class HoYoFile
8 | {
9 | public Dictionary Bundles = new Dictionary();
10 |
11 | public HoYoFile(FileReader reader)
12 | {
13 | var bundles = new Dictionary();
14 | var ext = Path.GetExtension(reader.FileName);
15 | switch (reader.Game.Name)
16 | {
17 | case "GI":
18 | var gi = GameManager.GetGame("GI");
19 | if (ext != gi.Extension)
20 | goto default;
21 |
22 | var blkFile = new BlkFile(reader);
23 | bundles = blkFile.Bundles;
24 | break;
25 | case "BH3":
26 | var bh3 = GameManager.GetGame("BH3");
27 | if (ext != bh3.Extension)
28 | goto default;
29 |
30 | Mr0k.ExpansionKey = Crypto.BH3ExpansionKey;
31 | Mr0k.Key = Crypto.BH3Key;
32 | Mr0k.ConstKey = Crypto.BH3ConstKey;
33 | Mr0k.SBox = Crypto.BH3SBox;
34 | Mr0k.BlockKey = null;
35 |
36 | var wmvFile = new WMVFile(reader);
37 | bundles = wmvFile.Bundles;
38 | break;
39 | case "SR":
40 | var sr = GameManager.GetGame("SR");
41 | if (ext != sr.Extension)
42 | goto default;
43 |
44 | Mr0k.ExpansionKey = Crypto.ExpansionKey;
45 | Mr0k.Key = Crypto.Key;
46 | Mr0k.ConstKey = Crypto.ConstKey;
47 | Mr0k.SBox = null;
48 | Mr0k.BlockKey = null;
49 |
50 | var srFile = new BundleFile(reader);
51 | bundles.Add(0, srFile.FileList);
52 | break;
53 | case "TOT":
54 | var tot = GameManager.GetGame("TOT");
55 | if (ext != tot.Extension)
56 | goto default;
57 |
58 | Mr0k.ExpansionKey = Crypto.ExpansionKey;
59 | Mr0k.Key = Crypto.Key;
60 | Mr0k.ConstKey = Crypto.ConstKey;
61 | Mr0k.SBox = null;
62 | Mr0k.BlockKey = Crypto.BlockKey;
63 |
64 | var totFile = new TOTFile(reader);
65 | bundles = totFile.Bundles;
66 | break;
67 | default:
68 | throw new NotSupportedException("File not supported !!\nMake sure to select the right game before loading the file");
69 | }
70 | Bundles = bundles;
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/AssetStudio/HoYo/TOT/TOTFile.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace AssetStudio
4 | {
5 | public class TOTFile
6 | {
7 | public Dictionary Bundles = new Dictionary();
8 | public TOTFile(FileReader reader)
9 | {
10 | if (reader.BundlePos.Length != 0)
11 | {
12 | foreach (var pos in reader.BundlePos)
13 | {
14 | reader.Position = pos;
15 | var bundle = new BundleFile(reader);
16 | Bundles.Add(pos, bundle.FileList);
17 | }
18 | }
19 | else
20 | {
21 | while (reader.Position != reader.Length)
22 | {
23 | var pos = reader.Position;
24 | var bundle = new BundleFile(reader);
25 | if (bundle.FileList == null)
26 | continue;
27 | Bundles.Add(pos, bundle.FileList);
28 | }
29 | }
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/AssetStudio/ILogger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public enum LoggerEvent
9 | {
10 | Verbose,
11 | Debug,
12 | Info,
13 | Warning,
14 | Error,
15 | }
16 |
17 | public interface ILogger
18 | {
19 | void Log(LoggerEvent loggerEvent, string message);
20 | }
21 |
22 | public sealed class DummyLogger : ILogger
23 | {
24 | public void Log(LoggerEvent loggerEvent, string message) { }
25 | }
26 |
27 | public sealed class ConsoleLogger : ILogger
28 | {
29 | public void Log(LoggerEvent loggerEvent, string message)
30 | {
31 | Console.WriteLine("[{0}] {1}", loggerEvent, message);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/AssetStudio/IYAMLExportable.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | public interface IYAMLExportable
4 | {
5 | YAMLNode ExportYAML();
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/AssetStudio/ImportHelper.cs:
--------------------------------------------------------------------------------
1 | using Org.Brotli.Dec;
2 | using System.IO;
3 | using System.IO.Compression;
4 |
5 | namespace AssetStudio
6 | {
7 | public static class ImportHelper
8 | {
9 | public static FileReader DecompressGZip(FileReader reader)
10 | {
11 | using (reader)
12 | {
13 | var stream = new MemoryStream();
14 | using (var gs = new GZipStream(reader.BaseStream, CompressionMode.Decompress))
15 | {
16 | gs.CopyTo(stream);
17 | }
18 | stream.Position = 0;
19 | return new FileReader(reader.FullPath, stream);
20 | }
21 | }
22 |
23 | public static FileReader DecompressBrotli(FileReader reader)
24 | {
25 | using (reader)
26 | {
27 | var stream = new MemoryStream();
28 | using (var brotliStream = new BrotliInputStream(reader.BaseStream))
29 | {
30 | brotliStream.CopyTo(stream);
31 | }
32 | stream.Position = 0;
33 | return new FileReader(reader.FullPath, stream);
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/AssetStudio/LocalSerializedObjectIdentifier.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public class LocalSerializedObjectIdentifier
9 | {
10 | public int localSerializedFileIndex;
11 | public long localIdentifierInFile;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/AssetStudio/Logger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public static class Logger
9 | {
10 | public static ILogger Default = new DummyLogger();
11 |
12 | public static void Verbose(string message) => Default.Log(LoggerEvent.Verbose, message);
13 | public static void Debug(string message) => Default.Log(LoggerEvent.Debug, message);
14 | public static void Info(string message) => Default.Log(LoggerEvent.Info, message);
15 | public static void Warning(string message) => Default.Log(LoggerEvent.Warning, message);
16 | public static void Error(string message) => Default.Log(LoggerEvent.Error, message);
17 |
18 | public static void Error(string message, Exception e)
19 | {
20 | var sb = new StringBuilder();
21 | sb.AppendLine(message);
22 | sb.AppendLine(e.ToString());
23 | Default.Log(LoggerEvent.Error, sb.ToString());
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/AssetStudio/Math/Color.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace AssetStudio
6 | {
7 | [StructLayout(LayoutKind.Sequential, Pack = 4)]
8 | public struct Color : IEquatable
9 | {
10 | [JsonProperty(PropertyName = "r")]
11 | public float R;
12 | [JsonProperty(PropertyName = "g")]
13 | public float G;
14 | [JsonProperty(PropertyName = "b")]
15 | public float B;
16 | [JsonProperty(PropertyName = "a")]
17 | public float A;
18 |
19 | public Color(float r, float g, float b, float a)
20 | {
21 | R = r;
22 | G = g;
23 | B = b;
24 | A = a;
25 | }
26 |
27 | public override int GetHashCode()
28 | {
29 | return ((Vector4)this).GetHashCode();
30 | }
31 |
32 | public override bool Equals(object other)
33 | {
34 | if (!(other is Color))
35 | return false;
36 | return Equals((Color)other);
37 | }
38 |
39 | public bool Equals(Color other)
40 | {
41 | return R.Equals(other.R) && G.Equals(other.G) && B.Equals(other.B) && A.Equals(other.A);
42 | }
43 |
44 | public static Color operator +(Color a, Color b)
45 | {
46 | return new Color(a.R + b.R, a.G + b.G, a.B + b.B, a.A + b.A);
47 | }
48 |
49 | public static Color operator -(Color a, Color b)
50 | {
51 | return new Color(a.R - b.R, a.G - b.G, a.B - b.B, a.A - b.A);
52 | }
53 |
54 | public static Color operator *(Color a, Color b)
55 | {
56 | return new Color(a.R * b.R, a.G * b.G, a.B * b.B, a.A * b.A);
57 | }
58 |
59 | public static Color operator *(Color a, float b)
60 | {
61 | return new Color(a.R * b, a.G * b, a.B * b, a.A * b);
62 | }
63 |
64 | public static Color operator *(float b, Color a)
65 | {
66 | return new Color(a.R * b, a.G * b, a.B * b, a.A * b);
67 | }
68 |
69 | public static Color operator /(Color a, float b)
70 | {
71 | return new Color(a.R / b, a.G / b, a.B / b, a.A / b);
72 | }
73 |
74 | public static bool operator ==(Color lhs, Color rhs)
75 | {
76 | return (Vector4)lhs == (Vector4)rhs;
77 | }
78 |
79 | public static bool operator !=(Color lhs, Color rhs)
80 | {
81 | return !(lhs == rhs);
82 | }
83 |
84 | public static implicit operator Vector4(Color c)
85 | {
86 | return new Vector4(c.R, c.G, c.B, c.A);
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/AssetStudio/Math/Float.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | public struct Float : IYAMLExportable
4 | {
5 | public float Value;
6 |
7 | public Float(float value)
8 | {
9 | Value = value;
10 | }
11 |
12 | public static implicit operator Float(float value)
13 | {
14 | return new Float(value);
15 | }
16 |
17 | public static implicit operator float(Float value)
18 | {
19 | return value.Value;
20 | }
21 |
22 | public YAMLNode ExportYAML()
23 | {
24 | return new YAMLScalarNode(Value);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/AssetStudio/Math/Quaternion.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace AssetStudio
5 | {
6 | [StructLayout(LayoutKind.Sequential, Pack = 4)]
7 | public struct Quaternion : IEquatable, IYAMLExportable
8 | {
9 | public float X;
10 | public float Y;
11 | public float Z;
12 | public float W;
13 |
14 | public Quaternion(float x, float y, float z, float w)
15 | {
16 | X = x;
17 | Y = y;
18 | Z = z;
19 | W = w;
20 | }
21 |
22 | public float this[int index]
23 | {
24 | get
25 | {
26 | switch (index)
27 | {
28 | case 0: return X;
29 | case 1: return Y;
30 | case 2: return Z;
31 | case 3: return W;
32 | default: throw new ArgumentOutOfRangeException(nameof(index), "Invalid Quaternion index!");
33 | }
34 | }
35 |
36 | set
37 | {
38 | switch (index)
39 | {
40 | case 0: X = value; break;
41 | case 1: Y = value; break;
42 | case 2: Z = value; break;
43 | case 3: W = value; break;
44 | default: throw new ArgumentOutOfRangeException(nameof(index), "Invalid Quaternion index!");
45 | }
46 | }
47 | }
48 |
49 | public override int GetHashCode()
50 | {
51 | return X.GetHashCode() ^ (Y.GetHashCode() << 2) ^ (Z.GetHashCode() >> 2) ^ (W.GetHashCode() >> 1);
52 | }
53 |
54 | public override bool Equals(object other)
55 | {
56 | if (!(other is Quaternion))
57 | return false;
58 | return Equals((Quaternion)other);
59 | }
60 |
61 | public bool Equals(Quaternion other)
62 | {
63 | return X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z) && W.Equals(other.W);
64 | }
65 |
66 | public static float Dot(Quaternion a, Quaternion b)
67 | {
68 | return a.X * b.X + a.Y * b.Y + a.Z * b.Z + a.W * b.W;
69 | }
70 |
71 | private static bool IsEqualUsingDot(float dot)
72 | {
73 | return dot > 1.0f - kEpsilon;
74 | }
75 |
76 | public static bool operator ==(Quaternion lhs, Quaternion rhs)
77 | {
78 | return IsEqualUsingDot(Dot(lhs, rhs));
79 | }
80 |
81 | public static bool operator !=(Quaternion lhs, Quaternion rhs)
82 | {
83 | return !(lhs == rhs);
84 | }
85 |
86 | public YAMLNode ExportYAML()
87 | {
88 | var node = new YAMLMappingNode();
89 | node.Style = MappingStyle.Flow;
90 | node.Add("x", X);
91 | node.Add("y", Y);
92 | node.Add("z", Z);
93 | node.Add("w", W);
94 | return node;
95 | }
96 |
97 | private const float kEpsilon = 0.000001F;
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/AssetStudio/ObjectInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public class ObjectInfo
9 | {
10 | public long byteStart;
11 | public uint byteSize;
12 | public int typeID;
13 | public int classID;
14 | public ushort isDestroyed;
15 | public byte stripped;
16 |
17 | public long m_PathID;
18 | public SerializedType serializedType;
19 |
20 | public bool HasExportableType()
21 | {
22 | var typeID = (ClassIDType)classID;
23 | var isExportableType = ExportableTypes.Contains(typeID);
24 | switch (typeID)
25 | {
26 | case ClassIDType.IndexObject:
27 | case ClassIDType.MiHoYoBinData:
28 | return isExportableType && IndexObject.Exportable;
29 | default:
30 | return isExportableType;
31 | }
32 | }
33 |
34 | public static ClassIDType[] ExportableTypes = new ClassIDType[]
35 | {
36 | ClassIDType.GameObject,
37 | ClassIDType.Material,
38 | ClassIDType.Texture2D,
39 | ClassIDType.Mesh,
40 | ClassIDType.Shader,
41 | ClassIDType.TextAsset,
42 | ClassIDType.AnimationClip,
43 | ClassIDType.Animator,
44 | ClassIDType.Font,
45 | ClassIDType.AssetBundle,
46 | ClassIDType.Sprite,
47 | ClassIDType.MiHoYoBinData,
48 | ClassIDType.IndexObject
49 | };
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/AssetStudio/ObjectReader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace AssetStudio
8 | {
9 | public class ObjectReader : EndianBinaryReader
10 | {
11 | public SerializedFile assetsFile;
12 | public long m_PathID;
13 | public long byteStart;
14 | public uint byteSize;
15 | public ClassIDType type;
16 | public SerializedType serializedType;
17 | public BuildTarget platform;
18 | public SerializedFileFormatVersion m_Version;
19 |
20 | public int[] version => assetsFile.version;
21 | public BuildType buildType => assetsFile.buildType;
22 |
23 | public ObjectReader(EndianBinaryReader reader, SerializedFile assetsFile, ObjectInfo objectInfo) : base(reader.BaseStream, reader.Endian)
24 | {
25 | this.assetsFile = assetsFile;
26 | Game = reader.Game;
27 | m_PathID = objectInfo.m_PathID;
28 | byteStart = objectInfo.byteStart;
29 | byteSize = objectInfo.byteSize;
30 | if (Enum.IsDefined(typeof(ClassIDType), objectInfo.classID))
31 | {
32 | type = (ClassIDType)objectInfo.classID;
33 | }
34 | else
35 | {
36 | type = ClassIDType.UnknownType;
37 | }
38 | serializedType = objectInfo.serializedType;
39 | platform = assetsFile.m_TargetPlatform;
40 | m_Version = assetsFile.header.m_Version;
41 | }
42 |
43 | public void Reset()
44 | {
45 | Position = byteStart;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/AssetStudio/Progress.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | namespace AssetStudio
3 | {
4 | public static class Progress
5 | {
6 | public static IProgress Default = new Progress();
7 | private static int preValue;
8 |
9 | public static void Reset()
10 | {
11 | preValue = 0;
12 | Default.Report(0);
13 | }
14 |
15 | public static void Report(int current, int total)
16 | {
17 | var value = (int)(current * 100f / total);
18 | Report(value);
19 | }
20 |
21 | private static void Report(int value)
22 | {
23 | if (value > preValue)
24 | {
25 | preValue = value;
26 | Default.Report(value);
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/AssetStudio/ResourceReader.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace AssetStudio
4 | {
5 | public class ResourceReader
6 | {
7 | private bool needSearch;
8 | private string path;
9 | private SerializedFile assetsFile;
10 | private long offset;
11 | private long size;
12 | private BinaryReader reader;
13 |
14 | public int Size { get => (int)size; }
15 |
16 | public ResourceReader(string path, SerializedFile assetsFile, long offset, long size)
17 | {
18 | needSearch = true;
19 | this.path = path;
20 | this.assetsFile = assetsFile;
21 | this.offset = offset;
22 | this.size = size;
23 | }
24 |
25 | public ResourceReader(BinaryReader reader, long offset, long size)
26 | {
27 | this.reader = reader;
28 | this.offset = offset;
29 | this.size = size;
30 | }
31 |
32 | private BinaryReader GetReader()
33 | {
34 | if (needSearch)
35 | {
36 | var resourceFileName = Path.GetFileName(path);
37 | if (assetsFile.assetsManager.resourceFileReaders.TryGetValue(resourceFileName, out reader))
38 | {
39 | needSearch = false;
40 | return reader;
41 | }
42 | var assetsFileDirectory = Path.GetDirectoryName(assetsFile.fullName);
43 | var resourceFilePath = Path.Combine(assetsFileDirectory, resourceFileName);
44 | if (!File.Exists(resourceFilePath))
45 | {
46 | var findFiles = Directory.GetFiles(assetsFileDirectory, resourceFileName, SearchOption.AllDirectories);
47 | if (findFiles.Length > 0)
48 | {
49 | resourceFilePath = findFiles[0];
50 | }
51 | }
52 | if (File.Exists(resourceFilePath))
53 | {
54 | needSearch = false;
55 | reader = new BinaryReader(File.OpenRead(resourceFilePath));
56 | assetsFile.assetsManager.resourceFileReaders.Add(resourceFileName, reader);
57 | return reader;
58 | }
59 | throw new FileNotFoundException($"Can't find the resource file {resourceFileName}");
60 | }
61 | else
62 | {
63 | return reader;
64 | }
65 | }
66 |
67 | public byte[] GetData()
68 | {
69 | var binaryReader = GetReader();
70 | binaryReader.BaseStream.Position = offset;
71 | return binaryReader.ReadBytes((int)size);
72 | }
73 |
74 | public void GetData(byte[] buff)
75 | {
76 | var binaryReader = GetReader();
77 | binaryReader.BaseStream.Position = offset;
78 | binaryReader.Read(buff, 0, (int)size);
79 | }
80 |
81 | public void WriteData(string path)
82 | {
83 | var binaryReader = GetReader();
84 | binaryReader.BaseStream.Position = offset;
85 | using (var writer = File.OpenWrite(path))
86 | {
87 | binaryReader.BaseStream.CopyTo(writer, size);
88 | }
89 | }
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/AssetStudio/SerializedFileFormatVersion.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace AssetStudio
8 | {
9 | public enum SerializedFileFormatVersion
10 | {
11 | Unsupported = 1,
12 | Unknown_2 = 2,
13 | Unknown_3 = 3,
14 | ///
15 | /// 1.2.0 to 2.0.0
16 | ///
17 | Unknown_5 = 5,
18 | ///
19 | /// 2.1.0 to 2.6.1
20 | ///
21 | Unknown_6 = 6,
22 | ///
23 | /// 3.0.0b
24 | ///
25 | Unknown_7 = 7,
26 | ///
27 | /// 3.0.0 to 3.4.2
28 | ///
29 | Unknown_8 = 8,
30 | ///
31 | /// 3.5.0 to 4.7.2
32 | ///
33 | Unknown_9 = 9,
34 | ///
35 | /// 5.0.0aunk1
36 | ///
37 | Unknown_10 = 10,
38 | ///
39 | /// 5.0.0aunk2
40 | ///
41 | HasScriptTypeIndex = 11,
42 | ///
43 | /// 5.0.0aunk3
44 | ///
45 | Unknown_12 = 12,
46 | ///
47 | /// 5.0.0aunk4
48 | ///
49 | HasTypeTreeHashes = 13,
50 | ///
51 | /// 5.0.0unk
52 | ///
53 | Unknown_14 = 14,
54 | ///
55 | /// 5.0.1 to 5.4.0
56 | ///
57 | SupportsStrippedObject = 15,
58 | ///
59 | /// 5.5.0a
60 | ///
61 | RefactoredClassId = 16,
62 | ///
63 | /// 5.5.0unk to 2018.4
64 | ///
65 | RefactorTypeData = 17,
66 | ///
67 | /// 2019.1a
68 | ///
69 | RefactorShareableTypeTreeData = 18,
70 | ///
71 | /// 2019.1unk
72 | ///
73 | TypeTreeNodeWithTypeFlags = 19,
74 | ///
75 | /// 2019.2
76 | ///
77 | SupportsRefObject = 20,
78 | ///
79 | /// 2019.3 to 2019.4
80 | ///
81 | StoresTypeDependencies = 21,
82 | ///
83 | /// 2020.1 to x
84 | ///
85 | LargeFilesSupport = 22
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/AssetStudio/SerializedFileHeader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public class SerializedFileHeader
9 | {
10 | public uint m_MetadataSize;
11 | public long m_FileSize;
12 | public SerializedFileFormatVersion m_Version;
13 | public long m_DataOffset;
14 | public byte m_Endianess;
15 | public byte[] m_Reserved;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/AssetStudio/SerializedType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public class SerializedType
9 | {
10 | public int classID;
11 | public bool m_IsStrippedType;
12 | public short m_ScriptTypeIndex = -1;
13 | public TypeTree m_Type;
14 | public byte[] m_ScriptID; //Hash128
15 | public byte[] m_OldTypeHash; //Hash128
16 | public int[] m_TypeDependencies;
17 | public string m_KlassName;
18 | public string m_NameSpace;
19 | public string m_AsmName;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/AssetStudio/SevenZipHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using SevenZip.Compression.LZMA;
4 |
5 |
6 | namespace AssetStudio
7 | {
8 | public static class SevenZipHelper
9 | {
10 | public static MemoryStream StreamDecompress(MemoryStream inStream)
11 | {
12 | var decoder = new Decoder();
13 |
14 | inStream.Seek(0, SeekOrigin.Begin);
15 | var newOutStream = new MemoryStream();
16 |
17 | var properties = new byte[5];
18 | if (inStream.Read(properties, 0, 5) != 5)
19 | throw new Exception("input .lzma is too short");
20 | long outSize = 0;
21 | for (var i = 0; i < 8; i++)
22 | {
23 | var v = inStream.ReadByte();
24 | if (v < 0)
25 | throw new Exception("Can't Read 1");
26 | outSize |= ((long)(byte)v) << (8 * i);
27 | }
28 | decoder.SetDecoderProperties(properties);
29 |
30 | var compressedSize = inStream.Length - inStream.Position;
31 | decoder.Code(inStream, newOutStream, compressedSize, outSize, null);
32 |
33 | newOutStream.Position = 0;
34 | return newOutStream;
35 | }
36 |
37 | public static void StreamDecompress(Stream compressedStream, Stream decompressedStream, long compressedSize, long decompressedSize)
38 | {
39 | var basePosition = compressedStream.Position;
40 | var decoder = new Decoder();
41 | var properties = new byte[5];
42 | if (compressedStream.Read(properties, 0, 5) != 5)
43 | throw new Exception("input .lzma is too short");
44 | decoder.SetDecoderProperties(properties);
45 | decoder.Code(compressedStream, decompressedStream, compressedSize - 5, decompressedSize, null);
46 | compressedStream.Position = basePosition + compressedSize;
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/AssetStudio/StreamFile.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace AssetStudio
4 | {
5 | public class StreamFile
6 | {
7 | public string path;
8 | public string fileName;
9 | public Stream stream;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/AssetStudio/TypeTree.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace AssetStudio
8 | {
9 | public class TypeTree
10 | {
11 | public List m_Nodes;
12 | public byte[] m_StringBuffer;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/AssetStudio/TypeTreeNode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | public class TypeTreeNode
9 | {
10 | public string m_Type;
11 | public string m_Name;
12 | public int m_ByteSize;
13 | public int m_Index;
14 | public int m_TypeFlags; //m_IsArray
15 | public int m_Version;
16 | public int m_MetaFlag;
17 | public int m_Level;
18 | public uint m_TypeStrOffset;
19 | public uint m_NameStrOffset;
20 | public ulong m_RefTypeHash;
21 |
22 | public TypeTreeNode() { }
23 |
24 | public TypeTreeNode(string type, string name, int level, bool align)
25 | {
26 | m_Type = type;
27 | m_Name = name;
28 | m_Level = level;
29 | m_MetaFlag = align ? 0x4000 : 0;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/AssetStudio/WebFile.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.IO;
3 | using System.Text;
4 |
5 | namespace AssetStudio
6 | {
7 | public class WebFile
8 | {
9 | public StreamFile[] fileList;
10 |
11 | private class WebData
12 | {
13 | public int dataOffset;
14 | public int dataLength;
15 | public string path;
16 | }
17 |
18 | public WebFile(EndianBinaryReader reader)
19 | {
20 | reader.Endian = EndianType.LittleEndian;
21 | var signature = reader.ReadStringToNull();
22 | var headLength = reader.ReadInt32();
23 | var dataList = new List();
24 | while (reader.BaseStream.Position < headLength)
25 | {
26 | var data = new WebData();
27 | data.dataOffset = reader.ReadInt32();
28 | data.dataLength = reader.ReadInt32();
29 | var pathLength = reader.ReadInt32();
30 | data.path = Encoding.UTF8.GetString(reader.ReadBytes(pathLength));
31 | dataList.Add(data);
32 | }
33 | fileList = new StreamFile[dataList.Count];
34 | for (int i = 0; i < dataList.Count; i++)
35 | {
36 | var data = dataList[i];
37 | var file = new StreamFile();
38 | file.path = data.path;
39 | file.fileName = Path.GetFileName(data.path);
40 | reader.BaseStream.Position = data.dataOffset;
41 | file.stream = new MemoryStream(reader.ReadBytes(data.dataLength));
42 | fileList[i] = file;
43 | }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/AssetStudio/YAML/Base/MappingStyle.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | ///
4 | /// Specifies the style of a mapping.
5 | ///
6 | public enum MappingStyle
7 | {
8 | ///
9 | /// The block mapping style.
10 | ///
11 | Block,
12 |
13 | ///
14 | /// The flow mapping style.
15 | ///
16 | Flow
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/AssetStudio/YAML/Base/MetaType.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | internal enum MetaType
4 | {
5 | YAML,
6 | TAG,
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/AssetStudio/YAML/Base/ScalarStyle.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | ///
4 | /// Specifies the style of a YAML scalar.
5 | ///
6 | public enum ScalarStyle
7 | {
8 | ///
9 | /// The plain scalar style.
10 | ///
11 | Plain,
12 |
13 | ///
14 | ///
15 | ///
16 | Hex,
17 |
18 | ///
19 | /// The single-quoted scalar style.
20 | ///
21 | SingleQuoted,
22 |
23 | ///
24 | /// The double-quoted scalar style.
25 | ///
26 | DoubleQuoted,
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/AssetStudio/YAML/Base/ScalarType.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | internal enum ScalarType
4 | {
5 | Boolean,
6 | Byte,
7 | UInt16,
8 | Int16,
9 | UInt32,
10 | Int32,
11 | UInt64,
12 | Int64,
13 | Single,
14 | Double,
15 | String,
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/AssetStudio/YAML/Base/SequenceStyle.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | ///
4 | /// Specifies the style of a sequence.
5 | ///
6 | public enum SequenceStyle
7 | {
8 | ///
9 | /// The block sequence style
10 | ///
11 | Block,
12 |
13 | ///
14 | /// The block sequence style but with curly braces
15 | ///
16 | BlockCurve,
17 |
18 | ///
19 | /// The flow sequence style
20 | ///
21 | Flow,
22 |
23 | ///
24 | /// Single line with hex data
25 | ///
26 | Raw,
27 | }
28 |
29 | public static class SequenceStyleExtensions
30 | {
31 | public static bool IsRaw(this SequenceStyle _this)
32 | {
33 | return _this == SequenceStyle.Raw;
34 | }
35 |
36 | public static bool IsAnyBlock(this SequenceStyle _this)
37 | {
38 | return _this == SequenceStyle.Block || _this == SequenceStyle.BlockCurve;
39 | }
40 |
41 | ///
42 | /// Get scalar style corresponding to current sequence style
43 | ///
44 | /// Sequence style
45 | /// Corresponding scalar style
46 | public static ScalarStyle ToScalarStyle(this SequenceStyle _this)
47 | {
48 | return _this == SequenceStyle.Raw ? ScalarStyle.Hex : ScalarStyle.Plain;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/AssetStudio/YAML/Base/YAMLDocument.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | public sealed class YAMLDocument
4 | {
5 | public YAMLDocument()
6 | {
7 | }
8 |
9 | public YAMLScalarNode CreateScalarRoot()
10 | {
11 | YAMLScalarNode root = new YAMLScalarNode();
12 | Root = root;
13 | return root;
14 | }
15 |
16 | public YAMLSequenceNode CreateSequenceRoot()
17 | {
18 | YAMLSequenceNode root = new YAMLSequenceNode();
19 | Root = root;
20 | return root;
21 | }
22 |
23 | public YAMLMappingNode CreateMappingRoot()
24 | {
25 | YAMLMappingNode root = new YAMLMappingNode();
26 | Root = root;
27 | return root;
28 | }
29 |
30 | internal void Emit(Emitter emitter, bool isSeparator)
31 | {
32 | if(isSeparator)
33 | {
34 | emitter.Write("---").WriteWhitespace();
35 | }
36 |
37 | Root.Emit(emitter);
38 | }
39 |
40 | public YAMLNode Root { get; private set; }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/AssetStudio/YAML/Base/YAMLNode.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | public abstract class YAMLNode
4 | {
5 | internal virtual void Emit(Emitter emitter)
6 | {
7 | bool isWrote = false;
8 | if (!CustomTag.IsEmpty)
9 | {
10 | emitter.Write(CustomTag.ToString()).WriteWhitespace();
11 | isWrote = true;
12 | }
13 | if (Anchor.Length > 0)
14 | {
15 | emitter.Write("&").Write(Anchor).WriteWhitespace();
16 | isWrote = true;
17 | }
18 |
19 | if (isWrote)
20 | {
21 | if (IsMultiline)
22 | {
23 | emitter.WriteLine();
24 | }
25 | }
26 | }
27 |
28 | public abstract YAMLNodeType NodeType { get; }
29 | public abstract bool IsMultiline { get; }
30 | public abstract bool IsIndent { get; }
31 |
32 | public string Tag
33 | {
34 | get => CustomTag.Content;
35 | set => CustomTag = new YAMLTag(YAMLWriter.DefaultTagHandle, value);
36 | }
37 | public YAMLTag CustomTag { get; set; }
38 | public string Anchor { get; set; } = string.Empty;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/AssetStudio/YAML/Base/YAMLNodeType.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | public enum YAMLNodeType
4 | {
5 | ///
6 | /// The node is a .
7 | ///
8 | Mapping,
9 |
10 | ///
11 | /// The node is a .
12 | ///
13 | Scalar,
14 |
15 | ///
16 | /// The node is a .
17 | ///
18 | Sequence
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/AssetStudio/YAML/Base/YAMLTag.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | public readonly struct YAMLTag
4 | {
5 | public YAMLTag(string handle, string content)
6 | {
7 | Handle = handle;
8 | Content = content;
9 | }
10 |
11 | public override string ToString()
12 | {
13 | return IsEmpty ? string.Empty : $"{Handle}{Content}";
14 | }
15 |
16 | public string ToHeaderString()
17 | {
18 | return IsEmpty ? string.Empty : $"{Handle} {Content}";
19 | }
20 |
21 | public bool IsEmpty => string.IsNullOrEmpty(Handle);
22 |
23 | public string Handle { get; }
24 | public string Content { get; }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/AssetStudio/YAML/Base/YAMLWriter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 |
6 | namespace AssetStudio
7 | {
8 | using Version = System.Version;
9 |
10 | public class YAMLWriter
11 | {
12 | public void AddDocument(YAMLDocument document)
13 | {
14 | #if DEBUG
15 | if (document == null)
16 | {
17 | throw new ArgumentNullException(nameof(document));
18 | }
19 | if (m_documents.Contains(document))
20 | {
21 | throw new ArgumentException($"Document {document} is added already", nameof(document));
22 | }
23 | #endif
24 | m_documents.Add(document);
25 | }
26 |
27 | public void AddTag(string handle, string content)
28 | {
29 | if(m_tags.Any(t => t.Handle == handle))
30 | {
31 | throw new Exception($"Writer already contains tag {handle}");
32 | }
33 | YAMLTag tag = new YAMLTag(handle, content);
34 | m_tags.Add(tag);
35 | }
36 |
37 | public void Write(TextWriter output)
38 | {
39 | WriteHead(output);
40 | foreach (YAMLDocument doc in m_documents)
41 | {
42 | WriteDocument(doc);
43 | }
44 | WriteTail(output);
45 | }
46 |
47 | public void WriteHead(TextWriter output)
48 | {
49 | m_emitter = new Emitter(output, IsFormatKeys);
50 | m_isWriteSeparator = false;
51 |
52 | if (IsWriteVersion)
53 | {
54 | m_emitter.WriteMeta(MetaType.YAML, Version.ToString());
55 | m_isWriteSeparator = true;
56 | }
57 |
58 | if (IsWriteDefaultTag)
59 | {
60 | m_emitter.WriteMeta(MetaType.TAG, DefaultTag.ToHeaderString());
61 | m_isWriteSeparator = true;
62 | }
63 | foreach (YAMLTag tag in m_tags)
64 | {
65 | m_emitter.WriteMeta(MetaType.TAG, tag.ToHeaderString());
66 | m_isWriteSeparator = true;
67 | }
68 | }
69 |
70 | public void WriteDocument(YAMLDocument doc)
71 | {
72 | doc.Emit(m_emitter, m_isWriteSeparator);
73 | m_isWriteSeparator = true;
74 | }
75 |
76 | public void WriteTail(TextWriter output)
77 | {
78 | output.Write('\n');
79 | }
80 |
81 | public static Version Version { get; } = new Version(1, 1);
82 |
83 | public const string DefaultTagHandle = "!u!";
84 | public const string DefaultTagContent = "tag:unity3d.com,2011:";
85 |
86 | public readonly YAMLTag DefaultTag = new YAMLTag(DefaultTagHandle, DefaultTagContent);
87 |
88 | public bool IsWriteVersion { get; set; } = true;
89 | public bool IsWriteDefaultTag { get; set; } = true;
90 | public bool IsFormatKeys { get; set; }
91 |
92 | private readonly HashSet m_documents = new HashSet();
93 | private readonly List m_tags = new List();
94 |
95 | private Emitter m_emitter;
96 | private bool m_isWriteSeparator;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/AssetStudio/YAML/Utils/Extensions/ArrayYAMLExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.ComponentModel;
3 | using System.Text;
4 |
5 | namespace AssetStudio
6 | {
7 | public static class ArrayYAMLExtensions
8 | {
9 | public static YAMLNode ExportYAML(this byte[] _this)
10 | {
11 | StringBuilder sb = new StringBuilder(_this.Length * 2);
12 | for (int i = 0; i < _this.Length; i++)
13 | {
14 | sb.AppendHex(_this[i]);
15 | }
16 | return new YAMLScalarNode(sb.ToString(), true);
17 | }
18 |
19 | public static YAMLNode ExportYAML(this T[][] _this)
20 | where T : IYAMLExportable
21 | {
22 | return ((IEnumerable>)_this).ExportYAML();
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/AssetStudio/YAML/Utils/Extensions/YAMLMappingNodeExtensions.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | public static class YAMLMappingNodeExtensions
4 | {
5 | public static void AddSerializedVersion(this YAMLMappingNode _this, int version)
6 | {
7 | if(version > 1)
8 | {
9 | _this.Add(SerializedVersionName, version);
10 | }
11 | }
12 |
13 | public static void ForceAddSerializedVersion(this YAMLMappingNode _this, int version)
14 | {
15 | if (version > 0)
16 | {
17 | _this.Add(SerializedVersionName, version);
18 | }
19 | }
20 |
21 | public static void InsertSerializedVersion(this YAMLMappingNode _this, int version)
22 | {
23 | if(version > 1)
24 | {
25 | _this.InsertBegin(SerializedVersionName, version);
26 | }
27 | }
28 |
29 | public const string SerializedVersionName = "serializedVersion";
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/AssetStudioCLI/AssetStudioCLI.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net472;net5.0-windows;net6.0-windows
6 | Resources\as.ico
7 | 0.17.00
8 | 0.17.00
9 | 0.17.00
10 | ..\AssetStudioGUI\bin
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/AssetStudioCLI/Components/AssetItem.cs:
--------------------------------------------------------------------------------
1 | using AssetStudio;
2 |
3 | namespace AssetStudioCLI
4 | {
5 | public class AssetItem
6 | {
7 | public string Text;
8 | public Object Asset;
9 | public SerializedFile SourceFile;
10 | public string Container = string.Empty;
11 | public string TypeString;
12 | public long m_PathID;
13 | public long FullSize;
14 | public ClassIDType Type;
15 | public string InfoText;
16 | public string UniqueID;
17 |
18 | public AssetItem(Object asset)
19 | {
20 | Text = "";
21 | Asset = asset;
22 | SourceFile = asset.assetsFile;
23 | Type = asset.type;
24 | TypeString = Type.ToString();
25 | m_PathID = asset.m_PathID;
26 | FullSize = asset.byteSize;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/AssetStudioCLI/Resources/as.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seiKiMo-Inc/HoYoStudio/ab84d09ed136419d065d42dcf2229fc37e969e84/AssetStudioCLI/Resources/as.ico
--------------------------------------------------------------------------------
/AssetStudioFBXNative/AssetStudioFBXNative.rc:
--------------------------------------------------------------------------------
1 | // Microsoft Visual C++ generated resource script.
2 | //
3 | #include "resource.h"
4 |
5 | #define APSTUDIO_READONLY_SYMBOLS
6 | /////////////////////////////////////////////////////////////////////////////
7 | //
8 | // Generated from the TEXTINCLUDE 2 resource.
9 | //
10 | #include "winres.h"
11 |
12 | /////////////////////////////////////////////////////////////////////////////
13 | #undef APSTUDIO_READONLY_SYMBOLS
14 |
15 | /////////////////////////////////////////////////////////////////////////////
16 | // Language neutral resources
17 |
18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU)
19 | LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
20 | #pragma code_page(65001)
21 |
22 | #ifdef APSTUDIO_INVOKED
23 | /////////////////////////////////////////////////////////////////////////////
24 | //
25 | // TEXTINCLUDE
26 | //
27 |
28 | 1 TEXTINCLUDE
29 | BEGIN
30 | "resource.h\0"
31 | END
32 |
33 | 2 TEXTINCLUDE
34 | BEGIN
35 | "#include ""winres.h""\r\n"
36 | "\0"
37 | END
38 |
39 | 3 TEXTINCLUDE
40 | BEGIN
41 | "\r\n"
42 | "\0"
43 | END
44 |
45 | #endif // APSTUDIO_INVOKED
46 |
47 |
48 | /////////////////////////////////////////////////////////////////////////////
49 | //
50 | // Version
51 | //
52 |
53 | VS_VERSION_INFO VERSIONINFO
54 | FILEVERSION 1,0,0,1
55 | PRODUCTVERSION 1,0,0,1
56 | FILEFLAGSMASK 0x3fL
57 | #ifdef _DEBUG
58 | FILEFLAGS 0x1L
59 | #else
60 | FILEFLAGS 0x0L
61 | #endif
62 | FILEOS 0x40004L
63 | FILETYPE 0x2L
64 | FILESUBTYPE 0x0L
65 | BEGIN
66 | BLOCK "StringFileInfo"
67 | BEGIN
68 | BLOCK "000004b0"
69 | BEGIN
70 | VALUE "FileDescription", "AssetStudioFBXNative"
71 | VALUE "FileVersion", "1.0.0.1"
72 | VALUE "InternalName", "AssetStudioFBXNative.dll"
73 | VALUE "LegalCopyright", "Copyright (C) Perfare 2018-2020; Copyright (C) hozuki 2020"
74 | VALUE "OriginalFilename", "AssetStudioFBXNative.dll"
75 | VALUE "ProductName", "AssetStudioFBXNative"
76 | VALUE "ProductVersion", "1.0.0.1"
77 | END
78 | END
79 | BLOCK "VarFileInfo"
80 | BEGIN
81 | VALUE "Translation", 0x0, 1200
82 | END
83 | END
84 |
85 | #endif // Language neutral resources
86 | /////////////////////////////////////////////////////////////////////////////
87 |
88 |
89 |
90 | #ifndef APSTUDIO_INVOKED
91 | /////////////////////////////////////////////////////////////////////////////
92 | //
93 | // Generated from the TEXTINCLUDE 3 resource.
94 | //
95 |
96 |
97 | /////////////////////////////////////////////////////////////////////////////
98 | #endif // not APSTUDIO_INVOKED
99 |
100 |
--------------------------------------------------------------------------------
/AssetStudioFBXNative/AssetStudioFBXNative.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | 源文件
20 |
21 |
22 | 源文件
23 |
24 |
25 | 源文件
26 |
27 |
28 | 源文件
29 |
30 |
31 | 源文件
32 |
33 |
34 | 源文件
35 |
36 |
37 |
38 |
39 | 头文件
40 |
41 |
42 | 头文件
43 |
44 |
45 | 头文件
46 |
47 |
48 | 头文件
49 |
50 |
51 | 头文件
52 |
53 |
54 | 头文件
55 |
56 |
57 | 头文件
58 |
59 |
60 | 头文件
61 |
62 |
63 | 头文件
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | 资源文件
72 |
73 |
74 |
--------------------------------------------------------------------------------
/AssetStudioFBXNative/asfbx_anim_context.cpp:
--------------------------------------------------------------------------------
1 | #include "asfbx_anim_context.h"
2 |
3 | AsFbxAnimContext::AsFbxAnimContext(bool32_t eulerFilter)
4 | : lFilter(nullptr)
5 | {
6 | if (eulerFilter)
7 | {
8 | lFilter = new FbxAnimCurveFilterUnroll();
9 | }
10 |
11 | lAnimStack = nullptr;
12 | lAnimLayer = nullptr;
13 |
14 | lCurveSX = nullptr;
15 | lCurveSY = nullptr;
16 | lCurveSZ = nullptr;
17 | lCurveRX = nullptr;
18 | lCurveRY = nullptr;
19 | lCurveRZ = nullptr;
20 | lCurveTX = nullptr;
21 | lCurveTY = nullptr;
22 | lCurveTZ = nullptr;
23 |
24 | pMesh = nullptr;
25 | lBlendShape = nullptr;
26 | lAnimCurve = nullptr;
27 | }
28 |
--------------------------------------------------------------------------------
/AssetStudioFBXNative/asfbx_anim_context.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #include "bool32_t.h"
6 |
7 | struct AsFbxAnimContext
8 | {
9 |
10 | FbxAnimCurveFilterUnroll* lFilter;
11 |
12 | FbxAnimStack* lAnimStack;
13 | FbxAnimLayer* lAnimLayer;
14 |
15 | FbxAnimCurve* lCurveSX;
16 | FbxAnimCurve* lCurveSY;
17 | FbxAnimCurve* lCurveSZ;
18 | FbxAnimCurve* lCurveRX;
19 | FbxAnimCurve* lCurveRY;
20 | FbxAnimCurve* lCurveRZ;
21 | FbxAnimCurve* lCurveTX;
22 | FbxAnimCurve* lCurveTY;
23 | FbxAnimCurve* lCurveTZ;
24 |
25 | FbxMesh* pMesh;
26 | FbxBlendShape* lBlendShape;
27 | FbxAnimCurve* lAnimCurve;
28 |
29 | AsFbxAnimContext(bool32_t eulerFilter);
30 | ~AsFbxAnimContext() = default;
31 |
32 | };
33 |
--------------------------------------------------------------------------------
/AssetStudioFBXNative/asfbx_context.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "asfbx_context.h"
4 |
5 | AsFbxContext::AsFbxContext()
6 | {
7 | pSdkManager = nullptr;
8 | pScene = nullptr;
9 | pTextures = nullptr;
10 | pMaterials = nullptr;
11 | pExporter = nullptr;
12 | pBindPose = nullptr;
13 | }
14 |
15 | AsFbxContext::~AsFbxContext()
16 | {
17 | framePaths.clear();
18 |
19 | delete pMaterials;
20 | delete pTextures;
21 |
22 | if (pExporter != nullptr) {
23 | pExporter->Destroy();
24 | }
25 |
26 | if (pScene != nullptr) {
27 | pScene->Destroy();
28 | }
29 |
30 | if (pSdkManager != nullptr) {
31 | pSdkManager->Destroy();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/AssetStudioFBXNative/asfbx_context.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | struct AsFbxContext
8 | {
9 |
10 | fbxsdk::FbxManager* pSdkManager;
11 | fbxsdk::FbxScene* pScene;
12 | fbxsdk::FbxArray* pTextures;
13 | fbxsdk::FbxArray* pMaterials;
14 | fbxsdk::FbxExporter* pExporter;
15 | fbxsdk::FbxPose* pBindPose;
16 |
17 | std::unordered_set framePaths;
18 |
19 | AsFbxContext();
20 | ~AsFbxContext();
21 | };
22 |
--------------------------------------------------------------------------------
/AssetStudioFBXNative/asfbx_morph_context.cpp:
--------------------------------------------------------------------------------
1 | #include "asfbx_morph_context.h"
2 |
3 | AsFbxMorphContext::AsFbxMorphContext()
4 | {
5 | pMesh = nullptr;
6 | lBlendShape = nullptr;
7 | lBlendShapeChannel = nullptr;
8 | lShape = nullptr;
9 | }
10 |
--------------------------------------------------------------------------------
/AssetStudioFBXNative/asfbx_morph_context.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | struct AsFbxMorphContext
6 | {
7 |
8 | FbxMesh* pMesh;
9 | FbxBlendShape* lBlendShape;
10 | FbxBlendShapeChannel* lBlendShapeChannel;
11 | FbxShape* lShape;
12 |
13 | AsFbxMorphContext();
14 | ~AsFbxMorphContext() = default;
15 |
16 | };
17 |
--------------------------------------------------------------------------------
/AssetStudioFBXNative/asfbx_skin_context.cpp:
--------------------------------------------------------------------------------
1 | #include "asfbx_skin_context.h"
2 | #include "asfbx_context.h"
3 |
4 | AsFbxSkinContext::AsFbxSkinContext(AsFbxContext* pContext, FbxNode* pFrameNode)
5 | : pSkin(nullptr)
6 | {
7 | if (pContext != nullptr && pContext->pScene != nullptr)
8 | {
9 | pSkin = FbxSkin::Create(pContext->pScene, "");
10 | }
11 |
12 | if (pFrameNode != nullptr)
13 | {
14 | lMeshMatrix = pFrameNode->EvaluateGlobalTransform();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/AssetStudioFBXNative/asfbx_skin_context.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | struct AsFbxContext;
6 |
7 | struct AsFbxSkinContext
8 | {
9 |
10 | FbxSkin* pSkin;
11 | FbxAMatrix lMeshMatrix;
12 |
13 | AsFbxSkinContext(AsFbxContext* pContext, FbxNode* pFrameNode);
14 | ~AsFbxSkinContext() = default;
15 |
16 | };
17 |
--------------------------------------------------------------------------------
/AssetStudioFBXNative/bool32_t.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | typedef uint32_t bool32_t;
6 |
--------------------------------------------------------------------------------
/AssetStudioFBXNative/cpp.hint:
--------------------------------------------------------------------------------
1 | #define AS_API(ret_type)
2 |
--------------------------------------------------------------------------------
/AssetStudioFBXNative/dllexport.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #if defined(_MSC_VER)
4 | #if _MSC_VER < 1910 // MSVC 2017-
5 | #error MSVC 2017 or later is required.
6 | #endif
7 | #endif
8 |
9 | #if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW__)
10 | #ifdef _AS_DLL
11 | #ifdef __GNUC__
12 | #define _AS_EXPORT __attribute__ ((dllexport))
13 | #else
14 | #define _AS_EXPORT __declspec(dllexport)
15 | #endif
16 | #else
17 | #ifdef __GNUC__
18 | #define _AS_EXPORT __attribute__ ((dllimport))
19 | #else
20 | #define _AS_EXPORT __declspec(dllimport)
21 | #endif
22 | #endif
23 | #define _AS_LOCAL
24 | #else
25 | #if __GNUC__ >= 4
26 | #define _AS_EXPORT __attribute__ ((visibility ("default")))
27 | #define _AS_LOCAL __attribute__ ((visibility ("hidden")))
28 | #else
29 | #define _AS_EXPORT
30 | #define _AS_LOCAL
31 | #endif
32 | #endif
33 |
34 | #ifdef __cplusplus
35 | #ifndef _EXTERN_C_STMT
36 | #define _EXTERN_C_STMT extern "C"
37 | #endif
38 | #else
39 | #ifndef _EXTERN_C_STMT
40 | #define _EXTERN_C_STMT
41 | #endif
42 | #endif
43 |
44 | #ifndef _AS_CALL
45 | #if defined(WIN32) || defined(_WIN32)
46 | #define _AS_CALL __stdcall
47 | #else
48 | #define _AS_CALL /* __cdecl */
49 | #endif
50 | #endif
51 |
52 | #if defined(_MSC_VER)
53 | #define AS_API(ret_type) _EXTERN_C_STMT _AS_EXPORT ret_type _AS_CALL
54 | #else
55 | #define AS_API(ret_type) _EXTERN_C_STMT _AS_EXPORT _AS_CALL ret_type
56 | #endif
57 |
--------------------------------------------------------------------------------
/AssetStudioFBXNative/resource.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seiKiMo-Inc/HoYoStudio/ab84d09ed136419d065d42dcf2229fc37e969e84/AssetStudioFBXNative/resource.h
--------------------------------------------------------------------------------
/AssetStudioFBXNative/utils.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include "utils.h"
5 |
6 | Vector3::Vector3()
7 | : X(0), Y(0), Z(0)
8 | {
9 | }
10 |
11 | Vector3::Vector3(float x, float y, float z)
12 | : X(x), Y(y), Z(z)
13 | {
14 | }
15 |
16 | Quaternion::Quaternion()
17 | : X(0), Y(0), Z(0), W(1)
18 | {
19 | }
20 |
21 | Quaternion::Quaternion(float x, float y, float z)
22 | : X(x), Y(y), Z(z), W(1)
23 | {
24 | }
25 |
26 | Quaternion::Quaternion(float x, float y, float z, float w)
27 | : X(x), Y(y), Z(z), W(w)
28 | {
29 | }
30 |
31 | Vector3 QuaternionToEuler(Quaternion q) {
32 | FbxAMatrix lMatrixRot;
33 | lMatrixRot.SetQ(FbxQuaternion(q.X, q.Y, q.Z, q.W));
34 | FbxVector4 lEuler = lMatrixRot.GetR();
35 | return Vector3((float)lEuler[0], (float)lEuler[1], (float)lEuler[2]);
36 | }
37 |
38 | Quaternion EulerToQuaternion(Vector3 v) {
39 | FbxAMatrix lMatrixRot;
40 | lMatrixRot.SetR(FbxVector4(v.X, v.Y, v.Z));
41 | FbxQuaternion lQuaternion = lMatrixRot.GetQ();
42 | return Quaternion((float)lQuaternion[0], (float)lQuaternion[1], (float)lQuaternion[2], (float)lQuaternion[3]);
43 | }
44 |
--------------------------------------------------------------------------------
/AssetStudioFBXNative/utils.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | struct Vector3 {
4 |
5 | float X;
6 | float Y;
7 | float Z;
8 |
9 | Vector3();
10 | Vector3(float x, float y, float z);
11 |
12 | };
13 |
14 | struct Quaternion {
15 |
16 | float X;
17 | float Y;
18 | float Z;
19 | float W;
20 |
21 | Quaternion();
22 | Quaternion(float x, float y, float z);
23 | Quaternion(float x, float y, float z, float w);
24 |
25 | };
26 |
27 | Vector3 QuaternionToEuler(Quaternion q);
28 |
29 | Quaternion EulerToQuaternion(Vector3 v);
30 |
--------------------------------------------------------------------------------
/AssetStudioFBXWrapper/AssetStudioFBXWrapper.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net472;netstandard2.0;net5.0;net6.0
5 | true
6 | 0.17.00
7 | 0.17.00
8 | 0.17.00
9 | Copyright © Perfare 2018-2022; Copyright © hozuki 2020
10 | embedded
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/AssetStudioFBXWrapper/Fbx.PInvoke.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using AssetStudio.FbxInterop;
3 |
4 | namespace AssetStudio
5 | {
6 | partial class Fbx
7 | {
8 |
9 | [DllImport(FbxDll.DllName, CallingConvention = CallingConvention.Winapi)]
10 | private static extern void AsUtilQuaternionToEuler(float qx, float qy, float qz, float qw, out float vx, out float vy, out float vz);
11 |
12 | [DllImport(FbxDll.DllName, CallingConvention = CallingConvention.Winapi)]
13 | private static extern void AsUtilEulerToQuaternion(float vx, float vy, float vz, out float qx, out float qy, out float qz, out float qw);
14 |
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/AssetStudioFBXWrapper/Fbx.cs:
--------------------------------------------------------------------------------
1 | using AssetStudio.FbxInterop;
2 | using AssetStudio.PInvoke;
3 | using System.IO;
4 |
5 | namespace AssetStudio
6 | {
7 | public static partial class Fbx
8 | {
9 |
10 | static Fbx()
11 | {
12 | DllLoader.PreloadDll(FbxDll.DllName);
13 | }
14 |
15 | public static Vector3 QuaternionToEuler(Quaternion q)
16 | {
17 | AsUtilQuaternionToEuler(q.X, q.Y, q.Z, q.W, out var x, out var y, out var z);
18 | return new Vector3(x, y, z);
19 | }
20 |
21 | public static Quaternion EulerToQuaternion(Vector3 v)
22 | {
23 | AsUtilEulerToQuaternion(v.X, v.Y, v.Z, out var x, out var y, out var z, out var w);
24 | return new Quaternion(x, y, z, w);
25 | }
26 |
27 | public static class Exporter
28 | {
29 |
30 | public static void Export(string path, IImported imported, bool eulerFilter, float filterPrecision,
31 | bool allNodes, bool skins, bool animation, bool blendShape, bool castToBone, float boneSize, bool exportAllUvsAsDiffuseMaps, float scaleFactor, int versionIndex, bool isAscii)
32 | {
33 | var file = new FileInfo(path);
34 | var dir = file.Directory;
35 |
36 | if (!dir.Exists)
37 | {
38 | dir.Create();
39 | }
40 |
41 | var currentDir = Directory.GetCurrentDirectory();
42 | Directory.SetCurrentDirectory(dir.FullName);
43 |
44 | var name = Path.GetFileName(path);
45 |
46 | using (var exporter = new FbxExporter(name, imported, allNodes, skins, castToBone, boneSize, exportAllUvsAsDiffuseMaps, scaleFactor, versionIndex, isAscii))
47 | {
48 | exporter.Initialize();
49 | exporter.ExportAll(blendShape, animation, eulerFilter, filterPrecision);
50 | }
51 |
52 | Directory.SetCurrentDirectory(currentDir);
53 | }
54 |
55 | }
56 |
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/AssetStudioFBXWrapper/FbxDll.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio.FbxInterop
2 | {
3 | internal static class FbxDll
4 | {
5 |
6 | internal const string DllName = "AssetStudioFBXNative";
7 | internal const string FbxsdkDllName = "libfbxsdk";
8 |
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/AssetStudioGUI/Components/AssetItem.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Forms;
2 | using AssetStudio;
3 |
4 | namespace AssetStudioGUI
5 | {
6 | public class AssetItem : ListViewItem
7 | {
8 | public Object Asset;
9 | public SerializedFile SourceFile;
10 | public string Container = string.Empty;
11 | public string TypeString;
12 | public long m_PathID;
13 | public long FullSize;
14 | public ClassIDType Type;
15 | public string InfoText;
16 | public string UniqueID;
17 | public GameObjectTreeNode TreeNode;
18 |
19 | public AssetItem(Object asset)
20 | {
21 | Asset = asset;
22 | SourceFile = asset.assetsFile;
23 | Type = asset.type;
24 | TypeString = Type.ToString();
25 | m_PathID = asset.m_PathID;
26 | FullSize = asset.byteSize;
27 | }
28 |
29 | public void SetSubItems()
30 | {
31 | SubItems.AddRange(new[]
32 | {
33 | Container, //Container
34 | TypeString, //Type
35 | m_PathID.ToString(), //PathID
36 | FullSize.ToString(), //Size
37 | });
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/AssetStudioGUI/Components/GOHierarchy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows.Forms;
6 |
7 | namespace AssetStudioGUI
8 | {
9 | internal class GOHierarchy : TreeView
10 | {
11 | protected override void WndProc(ref Message m)
12 | {
13 | // Filter WM_LBUTTONDBLCLK
14 | if (m.Msg != 0x203) base.WndProc(ref m);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/AssetStudioGUI/Components/GameObjectTreeNode.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Forms;
2 | using AssetStudio;
3 |
4 | namespace AssetStudioGUI
5 | {
6 | public class GameObjectTreeNode : TreeNode
7 | {
8 | public GameObject gameObject;
9 |
10 | public GameObjectTreeNode(GameObject gameObject)
11 | {
12 | this.gameObject = gameObject;
13 | Text = gameObject.m_Name;
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/AssetStudioGUI/Components/TypeTreeItem.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Text;
3 | using System.Windows.Forms;
4 | using AssetStudio;
5 |
6 | namespace AssetStudioGUI
7 | {
8 | internal class TypeTreeItem : ListViewItem
9 | {
10 | private TypeTree m_Type;
11 |
12 | public TypeTreeItem(int typeID, TypeTree m_Type)
13 | {
14 | this.m_Type = m_Type;
15 | Text = m_Type.m_Nodes[0].m_Type + " " + m_Type.m_Nodes[0].m_Name;
16 | SubItems.Add(typeID.ToString());
17 | }
18 |
19 | public override string ToString()
20 | {
21 | var sb = new StringBuilder();
22 | foreach (var i in m_Type.m_Nodes)
23 | {
24 | sb.AppendFormat("{0}{1} {2} {3} {4}\r\n", new string('\t', i.m_Level), i.m_Type, i.m_Name, i.m_ByteSize, (i.m_MetaFlag & 0x4000) != 0);
25 | }
26 | return sb.ToString();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/AssetStudioGUI/DirectBitmap.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 | using System.Drawing.Imaging;
4 | using System.Runtime.InteropServices;
5 |
6 | namespace AssetStudioGUI
7 | {
8 | public sealed class DirectBitmap : IDisposable
9 | {
10 | public DirectBitmap(byte[] buff, int width, int height)
11 | {
12 | Width = width;
13 | Height = height;
14 | Bits = buff;
15 | m_handle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
16 | m_bitmap = new Bitmap(Width, Height, Stride, PixelFormat.Format32bppArgb, m_handle.AddrOfPinnedObject());
17 | }
18 |
19 | private void Dispose(bool disposing)
20 | {
21 | if (disposing)
22 | {
23 | m_bitmap.Dispose();
24 | m_handle.Free();
25 | }
26 | m_bitmap = null;
27 | }
28 |
29 | public void Dispose()
30 | {
31 | Dispose(true);
32 | }
33 |
34 | public int Height { get; }
35 | public int Width { get; }
36 | public int Stride => Width * 4;
37 | public byte[] Bits { get; }
38 | public Bitmap Bitmap => m_bitmap;
39 |
40 | private Bitmap m_bitmap;
41 | private readonly GCHandle m_handle;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/AssetStudioGUI/GUILogger.cs:
--------------------------------------------------------------------------------
1 | using AssetStudio;
2 | using System;
3 | using System.Windows.Forms;
4 |
5 | namespace AssetStudioGUI
6 | {
7 | class GUILogger : ILogger
8 | {
9 | public bool ShowErrorMessage = true;
10 | private Action action;
11 |
12 | public GUILogger(Action action)
13 | {
14 | this.action = action;
15 | }
16 |
17 | public void Log(LoggerEvent loggerEvent, string message)
18 | {
19 | switch (loggerEvent)
20 | {
21 | case LoggerEvent.Error:
22 | if (ShowErrorMessage)
23 | {
24 | MessageBox.Show(message);
25 | }
26 | break;
27 | default:
28 | action(message);
29 | break;
30 | }
31 |
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/AssetStudioGUI/Libraries/OpenTK.WinForms.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seiKiMo-Inc/HoYoStudio/ab84d09ed136419d065d42dcf2229fc37e969e84/AssetStudioGUI/Libraries/OpenTK.WinForms.dll
--------------------------------------------------------------------------------
/AssetStudioGUI/Libraries/x64/acl.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seiKiMo-Inc/HoYoStudio/ab84d09ed136419d065d42dcf2229fc37e969e84/AssetStudioGUI/Libraries/x64/acl.dll
--------------------------------------------------------------------------------
/AssetStudioGUI/Libraries/x64/fmod.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seiKiMo-Inc/HoYoStudio/ab84d09ed136419d065d42dcf2229fc37e969e84/AssetStudioGUI/Libraries/x64/fmod.dll
--------------------------------------------------------------------------------
/AssetStudioGUI/Libraries/x86/acl.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seiKiMo-Inc/HoYoStudio/ab84d09ed136419d065d42dcf2229fc37e969e84/AssetStudioGUI/Libraries/x86/acl.dll
--------------------------------------------------------------------------------
/AssetStudioGUI/Libraries/x86/fmod.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seiKiMo-Inc/HoYoStudio/ab84d09ed136419d065d42dcf2229fc37e969e84/AssetStudioGUI/Libraries/x86/fmod.dll
--------------------------------------------------------------------------------
/AssetStudioGUI/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using System.Windows.Forms;
6 |
7 | namespace AssetStudioGUI
8 | {
9 | static class Program
10 | {
11 | ///
12 | /// The main entry point for the application.
13 | ///
14 | [STAThread]
15 | static void Main()
16 | {
17 | #if !NETFRAMEWORK
18 | Application.SetHighDpiMode(HighDpiMode.SystemAware);
19 | #endif
20 | Application.EnableVisualStyles();
21 | Application.SetCompatibleTextRenderingDefault(false);
22 | Application.Run(new AssetStudioGUIForm());
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/AssetStudioGUI/Resources/as.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seiKiMo-Inc/HoYoStudio/ab84d09ed136419d065d42dcf2229fc37e969e84/AssetStudioGUI/Resources/as.ico
--------------------------------------------------------------------------------
/AssetStudioGUI/Resources/preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seiKiMo-Inc/HoYoStudio/ab84d09ed136419d065d42dcf2229fc37e969e84/AssetStudioGUI/Resources/preview.png
--------------------------------------------------------------------------------
/AssetStudioUtility/Acl/AclExtensions.cs:
--------------------------------------------------------------------------------
1 | using static ACL.ACL;
2 |
3 | namespace AssetStudio
4 | {
5 | public static class ACLExtensions
6 | {
7 | public static void Process(this ACLClip m_ACLClip, out float[] values, out float[] times) => DecompressAll(m_ACLClip.m_ClipData, out values, out times);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/AssetStudioUtility/Acl/acl.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using AssetStudio.PInvoke;
4 |
5 | namespace ACL
6 | {
7 | public static class ACL
8 | {
9 | private const string DLL_NAME = "acl";
10 | static ACL()
11 | {
12 | DllLoader.PreloadDll(DLL_NAME);
13 | }
14 | public static void DecompressAll(byte[] data, out float[] values, out float[] times)
15 | {
16 | var pinned = GCHandle.Alloc(data, GCHandleType.Pinned);
17 | var pData = pinned.AddrOfPinnedObject();
18 | DecompressAll(pData, out var pValues, out var numValues, out var pTimes, out var numTimes);
19 | pinned.Free();
20 |
21 | values = new float[numValues];
22 | Marshal.Copy(pValues, values, 0, numValues);
23 |
24 | times = new float[numTimes];
25 | Marshal.Copy(pTimes, times, 0, numTimes);
26 | }
27 |
28 | #region importfunctions
29 |
30 | [DllImport(DLL_NAME, CallingConvention = CallingConvention.Winapi)]
31 | private static extern void DecompressAll(IntPtr data, out IntPtr pValues, out int numValues, out IntPtr pTimes, out int numTimes);
32 |
33 | #endregion
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/AssetStudioUtility/AnimationClipExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.Linq;
3 | using System.Text;
4 |
5 | namespace AssetStudio
6 | {
7 | public static class AnimationClipExtensions
8 | {
9 | public static string Convert(this AnimationClip animationClip, Game game)
10 | {
11 | var converter = AnimationClipConverter.Process(animationClip);
12 | animationClip.m_RotationCurves = converter.Rotations.Union(animationClip.m_RotationCurves).ToArray();
13 | animationClip.m_EulerCurves = converter.Eulers.Union(animationClip.m_EulerCurves).ToArray();
14 | animationClip.m_PositionCurves = converter.Translations.Union(animationClip.m_PositionCurves).ToArray();
15 | animationClip.m_ScaleCurves = converter.Scales.Union(animationClip.m_ScaleCurves).ToArray();
16 | animationClip.m_FloatCurves = converter.Floats.Union(animationClip.m_FloatCurves).ToArray();
17 | animationClip.m_PPtrCurves = converter.PPtrs.Union(animationClip.m_PPtrCurves).ToArray();
18 | return ConvertSerializedAnimationClip(animationClip, game);
19 | }
20 |
21 | public static string ConvertSerializedAnimationClip(AnimationClip animationClip, Game game)
22 | {
23 | var sb = new StringBuilder();
24 | using (var stringWriter = new StringWriter(sb))
25 | {
26 | YAMLWriter writer = new YAMLWriter();
27 | YAMLDocument doc = ExportYAMLDocument(animationClip);
28 | writer.AddDocument(doc);
29 | writer.Write(stringWriter);
30 | return sb.ToString();
31 | }
32 | }
33 |
34 | public static YAMLDocument ExportYAMLDocument(AnimationClip animationClip)
35 | {
36 | YAMLDocument document = new YAMLDocument();
37 | YAMLMappingNode root = document.CreateMappingRoot();
38 | root.Tag = ((int)ClassIDType.AnimationClip).ToString();
39 | root.Anchor = ((int)ClassIDType.AnimationClip * 100000).ToString();
40 | YAMLMappingNode node = (YAMLMappingNode)animationClip.ExportYAML();
41 | root.Add(ClassIDType.AnimationClip.ToString(), node);
42 | return document;
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/AssetStudioUtility/AssemblyLoader.cs:
--------------------------------------------------------------------------------
1 | using Mono.Cecil;
2 | using System.Collections.Generic;
3 | using System.IO;
4 |
5 | namespace AssetStudio
6 | {
7 | public class AssemblyLoader
8 | {
9 | public bool Loaded;
10 | private Dictionary moduleDic = new Dictionary();
11 |
12 | public void Load(string path)
13 | {
14 | var files = Directory.GetFiles(path, "*.dll");
15 | var resolver = new MyAssemblyResolver();
16 | var readerParameters = new ReaderParameters();
17 | readerParameters.AssemblyResolver = resolver;
18 | foreach (var file in files)
19 | {
20 | try
21 | {
22 | var assembly = AssemblyDefinition.ReadAssembly(file, readerParameters);
23 | resolver.Register(assembly);
24 | moduleDic.Add(assembly.MainModule.Name, assembly.MainModule);
25 | }
26 | catch
27 | {
28 | // ignored
29 | }
30 | }
31 | Loaded = true;
32 | }
33 |
34 | public TypeDefinition GetTypeDefinition(string assemblyName, string fullName)
35 | {
36 | if (moduleDic.TryGetValue(assemblyName, out var module))
37 | {
38 | var typeDef = module.GetType(fullName);
39 | if (typeDef == null && assemblyName == "UnityEngine.dll")
40 | {
41 | foreach (var pair in moduleDic)
42 | {
43 | typeDef = pair.Value.GetType(fullName);
44 | if (typeDef != null)
45 | {
46 | break;
47 | }
48 | }
49 | }
50 | return typeDef;
51 | }
52 | return null;
53 | }
54 |
55 | public void Clear()
56 | {
57 | foreach (var pair in moduleDic)
58 | {
59 | pair.Value.Dispose();
60 | }
61 | moduleDic.Clear();
62 | Loaded = false;
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/AssetStudioUtility/AssetStudioUtility.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net472;netstandard2.0;net5.0;net6.0
5 | 0.17.00
6 | 0.17.00
7 | 0.17.00
8 | Copyright © Perfare 2018-2022
9 | embedded
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/AssetStudioUtility/CSspv/EnumValuesExtensions.cs:
--------------------------------------------------------------------------------
1 | #if NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 || NETSTANDARD1_6
2 | using System;
3 | using System.Linq;
4 | using System.Reflection;
5 |
6 | namespace SpirV
7 | {
8 | public static class EnumValuesExtensions
9 | {
10 | public static Array GetEnumValues(this System.Type _this)
11 | {
12 | TypeInfo typeInfo = _this.GetTypeInfo ();
13 | if (!typeInfo.IsEnum) {
14 | throw new ArgumentException ("GetEnumValues: Type '" + _this.Name + "' is not an enum");
15 | }
16 |
17 | return
18 | (
19 | from field in typeInfo.DeclaredFields
20 | where field.IsLiteral
21 | select field.GetValue (null)
22 | )
23 | .ToArray();
24 | }
25 |
26 | public static string GetEnumName(this System.Type _this, object value)
27 | {
28 | TypeInfo typeInfo = _this.GetTypeInfo ();
29 | if (!typeInfo.IsEnum) {
30 | throw new ArgumentException ("GetEnumName: Type '" + _this.Name + "' is not an enum");
31 | }
32 | return
33 | (
34 | from field in typeInfo.DeclaredFields
35 | where field.IsLiteral && (uint)field.GetValue(null) == (uint)value
36 | select field.Name
37 | )
38 | .First();
39 | }
40 | }
41 | }
42 | #endif
--------------------------------------------------------------------------------
/AssetStudioUtility/CSspv/Instruction.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace SpirV
4 | {
5 | public enum OperandQuantifier
6 | {
7 | ///
8 | /// 1
9 | ///
10 | Default,
11 | ///
12 | /// 0 or 1
13 | ///
14 | Optional,
15 | ///
16 | /// 0+
17 | ///
18 | Varying
19 | }
20 |
21 | public class Operand
22 | {
23 | public Operand(OperandType kind, string name, OperandQuantifier quantifier)
24 | {
25 | Name = name;
26 | Type = kind;
27 | Quantifier = quantifier;
28 | }
29 |
30 | public string Name { get; }
31 | public OperandType Type { get; }
32 | public OperandQuantifier Quantifier { get; }
33 | }
34 |
35 | public class Instruction
36 | {
37 | public Instruction (string name)
38 | : this (name, new List ())
39 | {
40 | }
41 |
42 | public Instruction (string name, IReadOnlyList operands)
43 | {
44 | Operands = operands;
45 | Name = name;
46 | }
47 |
48 | public string Name { get; }
49 | public IReadOnlyList Operands { get; }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/AssetStudioUtility/CSspv/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 2-Clause License
2 |
3 | Copyright (c) 2017, Matthäus G. Chajdas
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
--------------------------------------------------------------------------------
/AssetStudioUtility/CSspv/Reader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Runtime.CompilerServices;
4 |
5 | namespace SpirV
6 | {
7 | internal sealed class Reader
8 | {
9 | public Reader(BinaryReader reader)
10 | {
11 | reader_ = reader;
12 | uint magicNumber = reader_.ReadUInt32();
13 | if (magicNumber == Meta.MagicNumber)
14 | {
15 | littleEndian_ = true;
16 | }
17 | else if (Reverse(magicNumber) == Meta.MagicNumber)
18 | {
19 | littleEndian_ = false;
20 | }
21 | else
22 | {
23 | throw new Exception("Invalid magic number");
24 | }
25 | }
26 |
27 | public uint ReadDWord()
28 | {
29 | if (littleEndian_)
30 | {
31 | return reader_.ReadUInt32 ();
32 | }
33 | else
34 | {
35 | return Reverse(reader_.ReadUInt32());
36 | }
37 | }
38 |
39 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
40 | private static uint Reverse(uint u)
41 | {
42 | return (u << 24) | (u & 0xFF00U) << 8 | (u >> 8) & 0xFF00U | (u >> 24);
43 | }
44 |
45 | public bool EndOfStream => reader_.BaseStream.Position == reader_.BaseStream.Length;
46 |
47 | private readonly BinaryReader reader_;
48 | private readonly bool littleEndian_;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/AssetStudioUtility/CSspv/SpirV.Meta.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace SpirV
4 | {
5 | internal class Meta
6 | {
7 | public class ToolInfo
8 | {
9 | public ToolInfo(string vendor)
10 | {
11 | Vendor = vendor;
12 | }
13 |
14 | public ToolInfo(string vendor, string name)
15 | {
16 | Vendor = vendor;
17 | Name = name;
18 | }
19 |
20 | public string Name { get; }
21 | public string Vendor { get; }
22 | }
23 |
24 | public static uint MagicNumber => 119734787U;
25 | public static uint Version => 66048U;
26 | public static uint Revision => 2U;
27 | public static uint OpCodeMask => 65535U;
28 | public static uint WordCountShift => 16U;
29 |
30 | public static IReadOnlyDictionary Tools => toolInfos_;
31 |
32 | private readonly static Dictionary toolInfos_ = new Dictionary
33 | {
34 | { 0, new ToolInfo("Khronos") },
35 | { 1, new ToolInfo("LunarG") },
36 | { 2, new ToolInfo("Valve") },
37 | { 3, new ToolInfo("Codeplay") },
38 | { 4, new ToolInfo("NVIDIA") },
39 | { 5, new ToolInfo("ARM") },
40 | { 6, new ToolInfo("Khronos", "LLVM/SPIR-V Translator") },
41 | { 7, new ToolInfo("Khronos", "SPIR-V Tools Assembler") },
42 | { 8, new ToolInfo("Khronos", "Glslang Reference Front End") },
43 | { 9, new ToolInfo("Qualcomm") },
44 | { 10, new ToolInfo("AMD") },
45 | { 11, new ToolInfo("Intel") },
46 | { 12, new ToolInfo("Imagination") },
47 | { 13, new ToolInfo("Google", "Shaderc over Glslang") },
48 | { 14, new ToolInfo("Google", "spiregg") },
49 | { 15, new ToolInfo("Google", "rspirv") },
50 | { 16, new ToolInfo("X-LEGEND", "Mesa-IR/SPIR-V Translator") },
51 | { 17, new ToolInfo("Khronos", "SPIR-V Tools Linker") },
52 | };
53 | }
54 | }
--------------------------------------------------------------------------------
/AssetStudioUtility/ConsoleHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace AssetStudio
5 | {
6 | public static class ConsoleHelper
7 | {
8 | [DllImport("kernel32.dll", SetLastError = true)]
9 | [return: MarshalAs(UnmanagedType.Bool)]
10 | public static extern bool AllocConsole();
11 |
12 | [DllImport("kernel32.dll", SetLastError = true)]
13 | [return: MarshalAs(UnmanagedType.Bool)]
14 | public static extern bool SetConsoleTitle(string lpConsoleTitle);
15 |
16 | [DllImport("kernel32.dll", SetLastError = true)]
17 | public static extern IntPtr GetConsoleWindow();
18 |
19 | [DllImport("user32.dll", SetLastError = true)]
20 | [return: MarshalAs(UnmanagedType.Bool)]
21 | public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
22 |
23 | public const int SW_HIDE = 0;
24 | public const int SW_SHOW = 5;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/AssetStudioUtility/ImageExtensions.cs:
--------------------------------------------------------------------------------
1 | using SixLabors.ImageSharp;
2 | using SixLabors.ImageSharp.Formats.Bmp;
3 | using SixLabors.ImageSharp.Formats.Tga;
4 | using SixLabors.ImageSharp.PixelFormats;
5 | using System.IO;
6 | using System.Runtime.InteropServices;
7 |
8 | namespace AssetStudio
9 | {
10 | public static class ImageExtensions
11 | {
12 | public static void WriteToStream(this Image image, Stream stream, ImageFormat imageFormat)
13 | {
14 | switch (imageFormat)
15 | {
16 | case ImageFormat.Jpeg:
17 | image.SaveAsJpeg(stream);
18 | break;
19 | case ImageFormat.Png:
20 | image.SaveAsPng(stream);
21 | break;
22 | case ImageFormat.Bmp:
23 | image.Save(stream, new BmpEncoder
24 | {
25 | BitsPerPixel = BmpBitsPerPixel.Pixel32,
26 | SupportTransparency = true
27 | });
28 | break;
29 | case ImageFormat.Tga:
30 | image.Save(stream, new TgaEncoder
31 | {
32 | BitsPerPixel = TgaBitsPerPixel.Pixel32,
33 | Compression = TgaCompression.None
34 | });
35 | break;
36 | }
37 | }
38 |
39 | public static MemoryStream ConvertToStream(this Image image, ImageFormat imageFormat)
40 | {
41 | var stream = new MemoryStream();
42 | image.WriteToStream(stream, imageFormat);
43 | return stream;
44 | }
45 |
46 | public static byte[] ConvertToBytes(this Image image) where TPixel : unmanaged, IPixel
47 | {
48 | if (image.TryGetSinglePixelSpan(out var pixelSpan))
49 | {
50 | return MemoryMarshal.AsBytes(pixelSpan).ToArray();
51 | }
52 | return null;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/AssetStudioUtility/ImageFormat.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | public enum ImageFormat
4 | {
5 | Jpeg,
6 | Png,
7 | Bmp,
8 | Tga
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/AssetStudioUtility/ModelExporter.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | public static class ModelExporter
4 | {
5 | public static void ExportFbx(string path, IImported imported, bool eulerFilter, float filterPrecision,
6 | bool allNodes, bool skins, bool animation, bool blendShape, bool castToBone, float boneSize, bool exportAllUvsAsDiffuseMaps, float scaleFactor, int versionIndex, bool isAscii)
7 | {
8 | Fbx.Exporter.Export(path, imported, eulerFilter, filterPrecision, allNodes, skins, animation, blendShape, castToBone, boneSize, exportAllUvsAsDiffuseMaps, scaleFactor, versionIndex, isAscii);
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/AssetStudioUtility/MonoBehaviourConverter.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace AssetStudio
4 | {
5 | public static class MonoBehaviourConverter
6 | {
7 | public static TypeTree ConvertToTypeTree(this MonoBehaviour m_MonoBehaviour, AssemblyLoader assemblyLoader)
8 | {
9 | var m_Type = new TypeTree();
10 | m_Type.m_Nodes = new List();
11 | var helper = new SerializedTypeHelper(m_MonoBehaviour.version);
12 | helper.AddMonoBehaviour(m_Type.m_Nodes, 0);
13 | if (m_MonoBehaviour.m_Script.TryGet(out var m_Script))
14 | {
15 | var typeDef = assemblyLoader.GetTypeDefinition(m_Script.m_AssemblyName, string.IsNullOrEmpty(m_Script.m_Namespace) ? m_Script.m_ClassName : $"{m_Script.m_Namespace}.{m_Script.m_ClassName}");
16 | if (typeDef != null)
17 | {
18 | var typeDefinitionConverter = new TypeDefinitionConverter(typeDef, helper, 1);
19 | m_Type.m_Nodes.AddRange(typeDefinitionConverter.ConvertToTypeTreeNodes());
20 | }
21 | }
22 | return m_Type;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/AssetStudioUtility/MyAssemblyResolver.cs:
--------------------------------------------------------------------------------
1 | using Mono.Cecil;
2 |
3 | namespace AssetStudio
4 | {
5 | public class MyAssemblyResolver : DefaultAssemblyResolver
6 | {
7 | public void Register(AssemblyDefinition assembly)
8 | {
9 | RegisterAssembly(assembly);
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/AssetStudioUtility/SpirVShaderConverter.cs:
--------------------------------------------------------------------------------
1 | using Smolv;
2 | using SpirV;
3 | using System;
4 | using System.IO;
5 | using System.Text;
6 |
7 | namespace AssetStudio
8 | {
9 | public static class SpirVShaderConverter
10 | {
11 | public static string Convert(byte[] m_ProgramCode)
12 | {
13 | var sb = new StringBuilder();
14 | using (var ms = new MemoryStream(m_ProgramCode))
15 | {
16 | using (var reader = new BinaryReader(ms))
17 | {
18 | int requirements = reader.ReadInt32();
19 | int minOffset = m_ProgramCode.Length;
20 | int snippetCount = 5;
21 | /*if (version[0] > 2019 || (version[0] == 2019 && version[1] >= 3)) //2019.3 and up
22 | {
23 | snippetCount = 6;
24 | }*/
25 | for (int i = 0; i < snippetCount; i++)
26 | {
27 | if (reader.BaseStream.Position >= minOffset)
28 | {
29 | break;
30 | }
31 |
32 | int offset = reader.ReadInt32();
33 | int size = reader.ReadInt32();
34 | if (size > 0)
35 | {
36 | if (offset < minOffset)
37 | {
38 | minOffset = offset;
39 | }
40 | var pos = ms.Position;
41 | sb.Append(ExportSnippet(ms, offset, size));
42 | ms.Position = pos;
43 | }
44 | }
45 | }
46 | }
47 | return sb.ToString();
48 | }
49 |
50 | private static string ExportSnippet(Stream stream, int offset, int size)
51 | {
52 | stream.Position = offset;
53 | int decodedSize = SmolvDecoder.GetDecodedBufferSize(stream);
54 | if (decodedSize == 0)
55 | {
56 | throw new Exception("Invalid SMOL-V shader header");
57 | }
58 | using (var decodedStream = new MemoryStream(new byte[decodedSize]))
59 | {
60 | if (SmolvDecoder.Decode(stream, size, decodedStream))
61 | {
62 | decodedStream.Position = 0;
63 | var module = Module.ReadFrom(decodedStream);
64 | var disassembler = new Disassembler();
65 | return disassembler.Disassemble(module, DisassemblyOptions.Default).Replace("\r\n", "\n");
66 | }
67 | else
68 | {
69 | throw new Exception("Unable to decode SMOL-V shader");
70 | }
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/AssetStudioUtility/Texture2DExtensions.cs:
--------------------------------------------------------------------------------
1 | using SixLabors.ImageSharp;
2 | using SixLabors.ImageSharp.PixelFormats;
3 | using SixLabors.ImageSharp.Processing;
4 | using System.IO;
5 |
6 | namespace AssetStudio
7 | {
8 | public static class Texture2DExtensions
9 | {
10 | public static Image ConvertToImage(this Texture2D m_Texture2D, bool flip)
11 | {
12 | var converter = new Texture2DConverter(m_Texture2D);
13 | var buff = BigArrayPool.Shared.Rent(m_Texture2D.m_Width * m_Texture2D.m_Height * 4);
14 | try
15 | {
16 | if (converter.DecodeTexture2D(buff))
17 | {
18 | var image = Image.LoadPixelData(buff, m_Texture2D.m_Width, m_Texture2D.m_Height);
19 | if (flip)
20 | {
21 | image.Mutate(x => x.Flip(FlipMode.Vertical));
22 | }
23 | return image;
24 | }
25 | return null;
26 | }
27 | finally
28 | {
29 | BigArrayPool.Shared.Return(buff);
30 | }
31 | }
32 |
33 | public static MemoryStream ConvertToStream(this Texture2D m_Texture2D, ImageFormat imageFormat, bool flip)
34 | {
35 | var image = ConvertToImage(m_Texture2D, flip);
36 | if (image != null)
37 | {
38 | using (image)
39 | {
40 | return image.ConvertToStream(imageFormat);
41 | }
42 | }
43 | return null;
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/AssetStudioUtility/Unity.CecilTools/CecilUtils.cs:
--------------------------------------------------------------------------------
1 | // Unity C# reference source
2 | // Copyright (c) Unity Technologies. For terms of use, see
3 | // https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4 |
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using Mono.Cecil;
9 | using Unity.CecilTools.Extensions;
10 |
11 | namespace Unity.CecilTools
12 | {
13 | public static class CecilUtils
14 | {
15 | public static MethodDefinition FindInTypeExplicitImplementationFor(MethodDefinition interfaceMethod, TypeDefinition typeDefinition)
16 | {
17 | return typeDefinition.Methods.SingleOrDefault(m => m.Overrides.Any(o => o.CheckedResolve().SameAs(interfaceMethod)));
18 | }
19 |
20 | public static IEnumerable AllInterfacesImplementedBy(TypeDefinition typeDefinition)
21 | {
22 | return TypeAndBaseTypesOf(typeDefinition).SelectMany(t => t.Interfaces).Select(i => i.InterfaceType.CheckedResolve()).Distinct();
23 | }
24 |
25 | public static IEnumerable TypeAndBaseTypesOf(TypeReference typeReference)
26 | {
27 | while (typeReference != null)
28 | {
29 | var typeDefinition = typeReference.CheckedResolve();
30 | yield return typeDefinition;
31 | typeReference = typeDefinition.BaseType;
32 | }
33 | }
34 |
35 | public static IEnumerable BaseTypesOf(TypeReference typeReference)
36 | {
37 | return TypeAndBaseTypesOf(typeReference).Skip(1);
38 | }
39 |
40 | public static bool IsGenericList(TypeReference type)
41 | {
42 | return type.Name == "List`1" && type.SafeNamespace() == "System.Collections.Generic";
43 | }
44 |
45 | public static bool IsGenericDictionary(TypeReference type)
46 | {
47 | if (type is GenericInstanceType)
48 | type = ((GenericInstanceType)type).ElementType;
49 |
50 | return type.Name == "Dictionary`2" && type.SafeNamespace() == "System.Collections.Generic";
51 | }
52 |
53 | public static TypeReference ElementTypeOfCollection(TypeReference type)
54 | {
55 | var at = type as ArrayType;
56 | if (at != null)
57 | return at.ElementType;
58 |
59 | if (IsGenericList(type))
60 | return ((GenericInstanceType)type).GenericArguments.Single();
61 |
62 | throw new ArgumentException();
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/AssetStudioUtility/Unity.CecilTools/ElementType.cs:
--------------------------------------------------------------------------------
1 | // Unity C# reference source
2 | // Copyright (c) Unity Technologies. For terms of use, see
3 | // https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4 |
5 | using System;
6 | using Mono.Cecil;
7 |
8 | namespace Unity.CecilTools
9 | {
10 | static public class ElementType
11 | {
12 | public static TypeReference For(TypeReference byRefType)
13 | {
14 | var refType = byRefType as TypeSpecification;
15 | if (refType != null)
16 | return refType.ElementType;
17 |
18 | throw new ArgumentException(string.Format("TypeReference isn't a TypeSpecification {0} ", byRefType));
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/AssetStudioUtility/Unity.CecilTools/Extensions/MethodDefinitionExtensions.cs:
--------------------------------------------------------------------------------
1 | // Unity C# reference source
2 | // Copyright (c) Unity Technologies. For terms of use, see
3 | // https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4 |
5 | using Mono.Cecil;
6 |
7 | namespace Unity.CecilTools.Extensions
8 | {
9 | static class MethodDefinitionExtensions
10 | {
11 | public static bool SameAs(this MethodDefinition self, MethodDefinition other)
12 | {
13 | // FIXME: should be able to compare MethodDefinition references directly
14 | return self.FullName == other.FullName;
15 | }
16 |
17 | public static string PropertyName(this MethodDefinition self)
18 | {
19 | return self.Name.Substring(4);
20 | }
21 |
22 | public static bool IsConversionOperator(this MethodDefinition method)
23 | {
24 | if (!method.IsSpecialName)
25 | return false;
26 |
27 | return method.Name == "op_Implicit" || method.Name == "op_Explicit";
28 | }
29 |
30 | public static bool IsSimpleSetter(this MethodDefinition original)
31 | {
32 | return original.IsSetter && original.Parameters.Count == 1;
33 | }
34 |
35 | public static bool IsSimpleGetter(this MethodDefinition original)
36 | {
37 | return original.IsGetter && original.Parameters.Count == 0;
38 | }
39 |
40 | public static bool IsSimplePropertyAccessor(this MethodDefinition method)
41 | {
42 | return method.IsSimpleGetter() || method.IsSimpleSetter();
43 | }
44 |
45 | public static bool IsDefaultConstructor(MethodDefinition m)
46 | {
47 | return m.IsConstructor && !m.IsStatic && m.Parameters.Count == 0;
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/AssetStudioUtility/Unity.CecilTools/Extensions/ResolutionExtensions.cs:
--------------------------------------------------------------------------------
1 | // Unity C# reference source
2 | // Copyright (c) Unity Technologies. For terms of use, see
3 | // https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4 |
5 | using System;
6 | using Mono.Cecil;
7 |
8 | namespace Unity.CecilTools.Extensions
9 | {
10 | public static class ResolutionExtensions
11 | {
12 | public static TypeDefinition CheckedResolve(this TypeReference type)
13 | {
14 | return Resolve(type, reference => reference.Resolve());
15 | }
16 |
17 | public static MethodDefinition CheckedResolve(this MethodReference method)
18 | {
19 | return Resolve(method, reference => reference.Resolve());
20 | }
21 |
22 | private static TDefinition Resolve(TReference reference, Func resolve)
23 | where TReference : MemberReference
24 | where TDefinition : class, IMemberDefinition
25 | {
26 | if (reference.Module == null)
27 | throw new ResolutionException(reference);
28 |
29 | var definition = resolve(reference);
30 | if (definition == null)
31 | throw new ResolutionException(reference);
32 |
33 | return definition;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/AssetStudioUtility/Unity.CecilTools/Extensions/TypeDefinitionExtensions.cs:
--------------------------------------------------------------------------------
1 | // Unity C# reference source
2 | // Copyright (c) Unity Technologies. For terms of use, see
3 | // https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4 |
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using Mono.Cecil;
10 |
11 | namespace Unity.CecilTools.Extensions
12 | {
13 | public static class TypeDefinitionExtensions
14 | {
15 | public static bool IsSubclassOf(this TypeDefinition type, string baseTypeName)
16 | {
17 | var baseType = type.BaseType;
18 | if (baseType == null)
19 | return false;
20 | if (baseType.FullName == baseTypeName)
21 | return true;
22 |
23 | var baseTypeDef = baseType.Resolve();
24 | if (baseTypeDef == null)
25 | return false;
26 |
27 | return IsSubclassOf(baseTypeDef, baseTypeName);
28 | }
29 |
30 | public static bool IsSubclassOf(this TypeDefinition type, params string[] baseTypeNames)
31 | {
32 | var baseType = type.BaseType;
33 | if (baseType == null)
34 | return false;
35 |
36 | for (int i = 0; i < baseTypeNames.Length; i++)
37 | if (baseType.FullName == baseTypeNames[i])
38 | return true;
39 |
40 | var baseTypeDef = baseType.Resolve();
41 | if (baseTypeDef == null)
42 | return false;
43 |
44 | return IsSubclassOf(baseTypeDef, baseTypeNames);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/AssetStudioUtility/Unity.CecilTools/Extensions/TypeReferenceExtensions.cs:
--------------------------------------------------------------------------------
1 | // Unity C# reference source
2 | // Copyright (c) Unity Technologies. For terms of use, see
3 | // https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4 |
5 | using Mono.Cecil;
6 |
7 | namespace Unity.CecilTools.Extensions
8 | {
9 | public static class TypeReferenceExtensions
10 | {
11 | public static string SafeNamespace(this TypeReference type)
12 | {
13 | if (type.IsGenericInstance)
14 | return ((GenericInstanceType)type).ElementType.SafeNamespace();
15 | if (type.IsNested)
16 | return type.DeclaringType.SafeNamespace();
17 | return type.Namespace;
18 | }
19 |
20 | public static bool IsAssignableTo(this TypeReference typeRef, string typeName)
21 | {
22 | try
23 | {
24 | if (typeRef.IsGenericInstance)
25 | return ElementType.For(typeRef).IsAssignableTo(typeName);
26 |
27 | if (typeRef.FullName == typeName)
28 | return true;
29 |
30 | return typeRef.CheckedResolve().IsSubclassOf(typeName);
31 | }
32 | catch (AssemblyResolutionException) // If we can't resolve our typeref or one of its base types,
33 | { // let's assume it is not assignable to our target type
34 | return false;
35 | }
36 | }
37 |
38 | public static bool IsEnum(this TypeReference type)
39 | {
40 | return type.IsValueType && !type.IsPrimitive && type.CheckedResolve().IsEnum;
41 | }
42 |
43 | public static bool IsStruct(this TypeReference type)
44 | {
45 | return type.IsValueType && !type.IsPrimitive && !type.IsEnum() && !IsSystemDecimal(type);
46 | }
47 |
48 | private static bool IsSystemDecimal(TypeReference type)
49 | {
50 | return type.FullName == "System.Decimal";
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Radu
4 | Copyright (c) 2016-2020 Perfare
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 |
--------------------------------------------------------------------------------
/Texture2DDecoderNative/Texture2DDecoderNative.rc:
--------------------------------------------------------------------------------
1 | // Microsoft Visual C++ generated resource script.
2 | //
3 | #include "resource.h"
4 |
5 | #define APSTUDIO_READONLY_SYMBOLS
6 | /////////////////////////////////////////////////////////////////////////////
7 | //
8 | // Generated from the TEXTINCLUDE 2 resource.
9 | //
10 | #include "winres.h"
11 |
12 | /////////////////////////////////////////////////////////////////////////////
13 | #undef APSTUDIO_READONLY_SYMBOLS
14 |
15 | /////////////////////////////////////////////////////////////////////////////
16 | // Language neutral resources
17 |
18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU)
19 | LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
20 | #pragma code_page(65001)
21 |
22 | #ifdef APSTUDIO_INVOKED
23 | /////////////////////////////////////////////////////////////////////////////
24 | //
25 | // TEXTINCLUDE
26 | //
27 |
28 | 1 TEXTINCLUDE
29 | BEGIN
30 | "resource.h\0"
31 | END
32 |
33 | 2 TEXTINCLUDE
34 | BEGIN
35 | "#include ""winres.h""\r\n"
36 | "\0"
37 | END
38 |
39 | 3 TEXTINCLUDE
40 | BEGIN
41 | "\r\n"
42 | "\0"
43 | END
44 |
45 | #endif // APSTUDIO_INVOKED
46 |
47 |
48 | /////////////////////////////////////////////////////////////////////////////
49 | //
50 | // Version
51 | //
52 |
53 | VS_VERSION_INFO VERSIONINFO
54 | FILEVERSION 1,0,0,1
55 | PRODUCTVERSION 1,0,0,1
56 | FILEFLAGSMASK 0x3fL
57 | #ifdef _DEBUG
58 | FILEFLAGS 0x1L
59 | #else
60 | FILEFLAGS 0x0L
61 | #endif
62 | FILEOS 0x40004L
63 | FILETYPE 0x2L
64 | FILESUBTYPE 0x0L
65 | BEGIN
66 | BLOCK "StringFileInfo"
67 | BEGIN
68 | BLOCK "000004b0"
69 | BEGIN
70 | VALUE "FileDescription", "Texture2DDecoderNative"
71 | VALUE "FileVersion", "1.0.0.1"
72 | VALUE "InternalName", "Texture2DDecoderNative.dll"
73 | VALUE "LegalCopyright", "Copyright (C) Perfare 2020; Copyright (C) hozuki 2020"
74 | VALUE "OriginalFilename", "Texture2DDecoderNative.dll"
75 | VALUE "ProductName", "Texture2DDecoderNative"
76 | VALUE "ProductVersion", "1.0.0.1"
77 | END
78 | END
79 | BLOCK "VarFileInfo"
80 | BEGIN
81 | VALUE "Translation", 0x0, 1200
82 | END
83 | END
84 |
85 | #endif // Language neutral resources
86 | /////////////////////////////////////////////////////////////////////////////
87 |
88 |
89 |
90 | #ifndef APSTUDIO_INVOKED
91 | /////////////////////////////////////////////////////////////////////////////
92 | //
93 | // Generated from the TEXTINCLUDE 3 resource.
94 | //
95 |
96 |
97 | /////////////////////////////////////////////////////////////////////////////
98 | #endif // not APSTUDIO_INVOKED
99 |
100 |
--------------------------------------------------------------------------------
/Texture2DDecoderNative/astc.h:
--------------------------------------------------------------------------------
1 | #ifndef ASTC_H
2 | #define ASTC_H
3 |
4 | #include
5 |
6 | int decode_astc(const uint8_t *, const long, const long, const int, const int, uint32_t *);
7 |
8 | #endif /* end of include guard: ASTC_H */
9 |
--------------------------------------------------------------------------------
/Texture2DDecoderNative/atc.cpp:
--------------------------------------------------------------------------------
1 | #include "bcn.h"
2 | #include "atc.h"
3 | #include "color.h"
4 | #include
5 |
6 | static uint8_t expand_quantized(uint8_t v, int bits) {
7 | v = v << (8 - bits);
8 | return v | (v >> bits);
9 | }
10 |
11 | void decode_atc_block(const uint8_t* _src, uint32_t* _dst)
12 | {
13 | uint8_t colors[4 * 4];
14 |
15 | uint32_t c0 = _src[0] | (_src[1] << 8);
16 | uint32_t c1 = _src[2] | (_src[3] << 8);
17 |
18 | if (0 == (c0 & 0x8000))
19 | {
20 | colors[0] = expand_quantized((c0 >> 0) & 0x1f, 5);
21 | colors[1] = expand_quantized((c0 >> 5) & 0x1f, 5);
22 | colors[2] = expand_quantized((c0 >> 10) & 0x1f, 5);
23 |
24 | colors[12] = expand_quantized((c1 >> 0) & 0x1f, 5);
25 | colors[13] = expand_quantized((c1 >> 5) & 0x3f, 6);
26 | colors[14] = expand_quantized((c1 >> 11) & 0x1f, 5);
27 |
28 | colors[4] = (5 * colors[0] + 3 * colors[12]) / 8;
29 | colors[5] = (5 * colors[1] + 3 * colors[13]) / 8;
30 | colors[6] = (5 * colors[2] + 3 * colors[14]) / 8;
31 |
32 | colors[8] = (3 * colors[0] + 5 * colors[12]) / 8;
33 | colors[9] = (3 * colors[1] + 5 * colors[13]) / 8;
34 | colors[10] = (3 * colors[2] + 5 * colors[14]) / 8;
35 | }
36 | else
37 | {
38 | colors[0] = 0;
39 | colors[1] = 0;
40 | colors[2] = 0;
41 |
42 | colors[8] = expand_quantized((c0 >> 0) & 0x1f, 5);
43 | colors[9] = expand_quantized((c0 >> 5) & 0x1f, 5);
44 | colors[10] = expand_quantized((c0 >> 10) & 0x1f, 5);
45 |
46 | colors[12] = expand_quantized((c1 >> 0) & 0x1f, 5);
47 | colors[13] = expand_quantized((c1 >> 5) & 0x3f, 6);
48 | colors[14] = expand_quantized((c1 >> 11) & 0x1f, 5);
49 |
50 | colors[4] = std::max(0, colors[8] - colors[12] / 4);
51 | colors[5] = std::max(0, colors[9] - colors[13] / 4);
52 | colors[6] = std::max(0, colors[10] - colors[14] / 4);
53 | }
54 |
55 | for (uint32_t i = 0, next = 8 * 4; i < 16; i += 1, next += 2)
56 | {
57 | int32_t idx = ((_src[next >> 3] >> (next & 7)) & 3) * 4;
58 | _dst[i] = color(colors[idx + 2], colors[idx + 1], colors[idx + 0], 255);
59 | }
60 | }
61 |
62 | int decode_atc_rgb4(const uint8_t* data, uint32_t m_width, uint32_t m_height, uint32_t* image) {
63 | uint32_t m_block_width = 4;
64 | uint32_t m_block_height = 4;
65 | uint32_t m_blocks_x = (m_width + m_block_width - 1) / m_block_width;
66 | uint32_t m_blocks_y = (m_height + m_block_height - 1) / m_block_height;
67 | uint32_t buffer[16];
68 | for (uint32_t by = 0; by < m_blocks_y; by++) {
69 | for (uint32_t bx = 0; bx < m_blocks_x; bx++, data += 8) {
70 | decode_atc_block(data, buffer);
71 | copy_block_buffer(bx, by, m_width, m_height, m_block_width, m_block_height, buffer, image);
72 | }
73 | }
74 | return 1;
75 | }
76 |
77 | int decode_atc_rgba8(const uint8_t* data, uint32_t m_width, uint32_t m_height, uint32_t* image) {
78 | uint32_t m_block_width = 4;
79 | uint32_t m_block_height = 4;
80 | uint32_t m_blocks_x = (m_width + m_block_width - 1) / m_block_width;
81 | uint32_t m_blocks_y = (m_height + m_block_height - 1) / m_block_height;
82 | uint32_t buffer[16];
83 | for (uint32_t by = 0; by < m_blocks_y; by++) {
84 | for (uint32_t bx = 0; bx < m_blocks_x; bx++, data += 16) {
85 | decode_atc_block(data + 8, buffer);
86 | decode_bc3_alpha(data, buffer, 3);
87 | copy_block_buffer(bx, by, m_width, m_height, m_block_width, m_block_height, buffer, image);
88 | }
89 | }
90 | return 1;
91 | }
--------------------------------------------------------------------------------
/Texture2DDecoderNative/atc.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | int decode_atc_rgb4(const uint8_t* data, uint32_t m_width, uint32_t m_height, uint32_t* image);
5 | int decode_atc_rgba8(const uint8_t* data, uint32_t m_width, uint32_t m_height, uint32_t* image);
--------------------------------------------------------------------------------
/Texture2DDecoderNative/bcn.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | struct color_bgra
5 | {
6 | uint8_t b;
7 | uint8_t g;
8 | uint8_t r;
9 | uint8_t a;
10 | };
11 |
12 | const color_bgra g_black_color{ 0, 0, 0, 255 };
13 |
14 | int decode_bc1(const uint8_t* data, const long w, const long h, uint32_t* image);
15 | void decode_bc3_alpha(const uint8_t* data, uint32_t* outbuf, int channel);
16 | int decode_bc3(const uint8_t* data, const long w, const long h, uint32_t* image);
17 | int decode_bc4(const uint8_t* data, uint32_t m_width, uint32_t m_height, uint32_t* image);
18 | int decode_bc5(const uint8_t* data, uint32_t m_width, uint32_t m_height, uint32_t* image);
19 | int decode_bc6(const uint8_t* data, uint32_t m_width, uint32_t m_height, uint32_t* image);
20 | int decode_bc7(const uint8_t* data, uint32_t m_width, uint32_t m_height, uint32_t* image);
--------------------------------------------------------------------------------
/Texture2DDecoderNative/bool32_t.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | typedef uint32_t bool32_t;
6 |
--------------------------------------------------------------------------------
/Texture2DDecoderNative/color.h:
--------------------------------------------------------------------------------
1 | #ifndef COLOR_H
2 | #define COLOR_H
3 |
4 | #include
5 | #include
6 | #include "endianness.h"
7 |
8 | #ifdef __LITTLE_ENDIAN__
9 | static const uint_fast32_t TRANSPARENT_MASK = 0x00ffffff;
10 | #else
11 | static const uint_fast32_t TRANSPARENT_MASK = 0xffffff00;
12 | #endif
13 |
14 | static inline uint_fast32_t color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
15 | #ifdef __LITTLE_ENDIAN__
16 | return b | g << 8 | r << 16 | a << 24;
17 | #else
18 | return a | r << 8 | g << 16 | b << 24;
19 | #endif
20 | }
21 |
22 | static inline uint_fast32_t alpha_mask(uint8_t a) {
23 | #ifdef __LITTLE_ENDIAN__
24 | return TRANSPARENT_MASK | a << 24;
25 | #else
26 | return TRANSPARENT_MASK | a;
27 | #endif
28 | }
29 |
30 | static inline void rgb565_le(const uint16_t d, uint8_t *r, uint8_t *g, uint8_t *b) {
31 | #ifdef __LITTLE_ENDIAN__
32 | *r = (d >> 8 & 0xf8) | (d >> 13);
33 | *g = (d >> 3 & 0xfc) | (d >> 9 & 3);
34 | *b = (d << 3) | (d >> 2 & 7);
35 | #else
36 | *r = (d & 0xf8) | (d >> 5 & 7);
37 | *g = (d << 5 & 0xe0) | (d >> 11 & 0x1c) | (d >> 1 & 3);
38 | *b = (d >> 5 & 0xf8) | (d >> 10 & 0x7);
39 | #endif
40 | }
41 |
42 | static inline void rgb565_be(const uint16_t d, uint8_t *r, uint8_t *g, uint8_t *b) {
43 | #ifdef __BIG_ENDIAN__
44 | *r = (d >> 8 & 0xf8) | (d >> 13);
45 | *g = (d >> 3 & 0xfc) | (d >> 9 & 3);
46 | *b = (d << 3) | (d >> 2 & 7);
47 | #else
48 | *r = (d & 0xf8) | (d >> 5 & 7);
49 | *g = (d << 5 & 0xe0) | (d >> 11 & 0x1c) | (d >> 1 & 3);
50 | *b = (d >> 5 & 0xf8) | (d >> 10 & 0x7);
51 | #endif
52 | }
53 |
54 | static inline void rgb565_lep(const uint16_t d, uint8_t *c) {
55 | #ifdef __LITTLE_ENDIAN__
56 | *(c++) = (d >> 8 & 0xf8) | (d >> 13);
57 | *(c++) = (d >> 3 & 0xfc) | (d >> 9 & 3);
58 | *(c++) = (d << 3) | (d >> 2 & 7);
59 | #else
60 | *(c++) = (d & 0xf8) | (d >> 5 & 7);
61 | *(c++) = (d << 5 & 0xe0) | (d >> 11 & 0x1c) | (d >> 1 & 3);
62 | *(c++) = (d >> 5 & 0xf8) | (d >> 10 & 0x7);
63 | #endif
64 | }
65 |
66 | static inline void rgb565_bep(const uint16_t d, uint8_t *c) {
67 | #ifdef __BIG_ENDIAN__
68 | *(c++) = (d >> 8 & 0xf8) | (d >> 13);
69 | *(c++) = (d >> 3 & 0xfc) | (d >> 9 & 3);
70 | *(c++) = (d << 3) | (d >> 2 & 7);
71 | #else
72 | *(c++) = (d & 0xf8) | (d >> 5 & 7);
73 | *(c++) = (d << 5 & 0xe0) | (d >> 11 & 0x1c) | (d >> 1 & 3);
74 | *(c++) = (d >> 5 & 0xf8) | (d >> 10 & 0x7);
75 | #endif
76 | }
77 |
78 | static inline void copy_block_buffer(const long bx, const long by, const long w, const long h, const long bw,
79 | const long bh, const uint32_t *buffer, uint32_t *image) {
80 | long x = bw * bx;
81 | long xl = (bw * (bx + 1) > w ? w - bw * bx : bw) * 4;
82 | const uint32_t *buffer_end = buffer + bw * bh;
83 | for (long y = by * bh; buffer < buffer_end && y < h; buffer += bw, y++)
84 | memcpy(image + y * w + x, buffer, xl);
85 | }
86 |
87 | #endif /* end of include guard: COLOR_H */
88 |
--------------------------------------------------------------------------------
/Texture2DDecoderNative/cpp.hint:
--------------------------------------------------------------------------------
1 | #define T2D_API(ret_type)
2 |
--------------------------------------------------------------------------------
/Texture2DDecoderNative/crunch.cpp:
--------------------------------------------------------------------------------
1 | #include "crunch.h"
2 | #include
3 | #include
4 | #include "crunch/crn_decomp.h"
5 |
6 | bool crunch_unpack_level(const uint8_t* data, uint32_t data_size, uint32_t level_index, void** ret, uint32_t* ret_size) {
7 | crnd::crn_texture_info tex_info;
8 | if (!crnd::crnd_get_texture_info(data, data_size, &tex_info))
9 | {
10 | return false;
11 | }
12 |
13 | crnd::crnd_unpack_context pContext = crnd::crnd_unpack_begin(data, data_size);
14 | if (!pContext)
15 | {
16 | return false;
17 | }
18 |
19 | const crn_uint32 width = std::max(1U, tex_info.m_width >> level_index);
20 | const crn_uint32 height = std::max(1U, tex_info.m_height >> level_index);
21 | const crn_uint32 blocks_x = std::max(1U, (width + 3) >> 2);
22 | const crn_uint32 blocks_y = std::max(1U, (height + 3) >> 2);
23 | const crn_uint32 row_pitch = blocks_x * crnd::crnd_get_bytes_per_dxt_block(tex_info.m_format);
24 | const crn_uint32 total_face_size = row_pitch * blocks_y;
25 | *ret = new uint8_t[total_face_size];
26 | *ret_size = total_face_size;
27 | if (!crnd::crnd_unpack_level(pContext, ret, total_face_size, row_pitch, level_index))
28 | {
29 | crnd::crnd_unpack_end(pContext);
30 | return false;
31 | }
32 | crnd::crnd_unpack_end(pContext);
33 | return true;
34 | }
--------------------------------------------------------------------------------
/Texture2DDecoderNative/crunch.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | bool crunch_unpack_level(const uint8_t* data, uint32_t data_size, uint32_t level_index, void** ret, uint32_t* ret_size);
--------------------------------------------------------------------------------
/Texture2DDecoderNative/dllexport.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #if defined(_MSC_VER)
4 | #if _MSC_VER < 1910 // MSVC 2017-
5 | #error MSVC 2017 or later is required.
6 | #endif
7 | #endif
8 |
9 | #if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW__)
10 | #ifdef _T2D_DLL
11 | #ifdef __GNUC__
12 | #define _T2D_EXPORT __attribute__ ((dllexport))
13 | #else
14 | #define _T2D_EXPORT __declspec(dllexport)
15 | #endif
16 | #else
17 | #ifdef __GNUC__
18 | #define _T2D_EXPORT __attribute__ ((dllimport))
19 | #else
20 | #define _T2D_EXPORT __declspec(dllimport)
21 | #endif
22 | #endif
23 | #define _T2D_LOCAL
24 | #else
25 | #if __GNUC__ >= 4
26 | #define _T2D_EXPORT __attribute__ ((visibility ("default")))
27 | #define _T2D_LOCAL __attribute__ ((visibility ("hidden")))
28 | #else
29 | #define _T2D_EXPORT
30 | #define _T2D_LOCAL
31 | #endif
32 | #endif
33 |
34 | #ifdef __cplusplus
35 | #ifndef _EXTERN_C_STMT
36 | #define _EXTERN_C_STMT extern "C"
37 | #endif
38 | #else
39 | #ifndef _EXTERN_C_STMT
40 | #define _EXTERN_C_STMT
41 | #endif
42 | #endif
43 |
44 | #ifndef _T2D_CALL
45 | #if defined(WIN32) || defined(_WIN32)
46 | #define _T2D_CALL __stdcall
47 | #else
48 | #define _T2D_CALL /* __cdecl */
49 | #endif
50 | #endif
51 |
52 | #if defined(_MSC_VER)
53 | #define T2D_API(ret_type) _EXTERN_C_STMT _T2D_EXPORT ret_type _T2D_CALL
54 | #else
55 | #define T2D_API(ret_type) _EXTERN_C_STMT _T2D_EXPORT _T2D_CALL ret_type
56 | #endif
57 |
--------------------------------------------------------------------------------
/Texture2DDecoderNative/etc.h:
--------------------------------------------------------------------------------
1 | #ifndef ETC_H
2 | #define ETC_H
3 |
4 | #include
5 |
6 | int decode_etc1(const uint8_t *, const long, const long, uint32_t *);
7 | int decode_etc2(const uint8_t *, const long, const long, uint32_t *);
8 | int decode_etc2a1(const uint8_t *, const long, const long, uint32_t *);
9 | int decode_etc2a8(const uint8_t *, const long, const long, uint32_t *);
10 | int decode_eacr(const uint8_t *, const long, const long, uint32_t *);
11 | int decode_eacr_signed(const uint8_t *, const long, const long, uint32_t *);
12 | int decode_eacrg(const uint8_t *, const long, const long, uint32_t *);
13 | int decode_eacrg_signed(const uint8_t *, const long, const long, uint32_t *);
14 |
15 | #endif /* end of include guard: ETC_H */
16 |
--------------------------------------------------------------------------------
/Texture2DDecoderNative/fp16.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #ifndef FP16_H
3 | #define FP16_H
4 |
5 | #include "fp16/fp16.h"
6 |
7 | #endif /* FP16_H */
8 |
9 | /*
10 | *
11 | * License Information
12 | *
13 | * FP16 library is derived from https://github.com/Maratyszcza/FP16.
14 | * The library is licensed under the MIT License shown below.
15 | *
16 | *
17 | * The MIT License (MIT)
18 | *
19 | * Copyright (c) 2017 Facebook Inc.
20 | * Copyright (c) 2017 Georgia Institute of Technology
21 | * Copyright 2019 Google LLC
22 | *
23 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
24 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
25 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
26 | * permit persons to whom the Software is furnished to do so, subject to the following conditions:
27 | *
28 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
29 | * Software.
30 | *
31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
32 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
33 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
34 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | *
36 | */
37 |
--------------------------------------------------------------------------------
/Texture2DDecoderNative/fp16/bitcasts.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #ifndef FP16_BITCASTS_H
3 | #define FP16_BITCASTS_H
4 |
5 | #if defined(__cplusplus) && (__cplusplus >= 201103L)
6 | #include
7 | #elif !defined(__OPENCL_VERSION__)
8 | #include
9 | #endif
10 |
11 |
12 | static inline float fp32_from_bits(uint32_t w) {
13 | #if defined(__OPENCL_VERSION__)
14 | return as_float(w);
15 | #elif defined(__CUDA_ARCH__)
16 | return __uint_as_float((unsigned int) w);
17 | #elif defined(__INTEL_COMPILER)
18 | return _castu32_f32(w);
19 | #else
20 | union {
21 | uint32_t as_bits;
22 | float as_value;
23 | } fp32 = { w };
24 | return fp32.as_value;
25 | #endif
26 | }
27 |
28 | static inline uint32_t fp32_to_bits(float f) {
29 | #if defined(__OPENCL_VERSION__)
30 | return as_uint(f);
31 | #elif defined(__CUDA_ARCH__)
32 | return (uint32_t) __float_as_uint(f);
33 | #elif defined(__INTEL_COMPILER)
34 | return _castf32_u32(f);
35 | #else
36 | union {
37 | float as_value;
38 | uint32_t as_bits;
39 | } fp32 = { f };
40 | return fp32.as_bits;
41 | #endif
42 | }
43 |
44 | static inline double fp64_from_bits(uint64_t w) {
45 | #if defined(__OPENCL_VERSION__)
46 | return as_double(w);
47 | #elif defined(__CUDA_ARCH__)
48 | return __longlong_as_double((long long) w);
49 | #elif defined(__INTEL_COMPILER)
50 | return _castu64_f64(w);
51 | #else
52 | union {
53 | uint64_t as_bits;
54 | double as_value;
55 | } fp64 = { w };
56 | return fp64.as_value;
57 | #endif
58 | }
59 |
60 | static inline uint64_t fp64_to_bits(double f) {
61 | #if defined(__OPENCL_VERSION__)
62 | return as_ulong(f);
63 | #elif defined(__CUDA_ARCH__)
64 | return (uint64_t) __double_as_longlong(f);
65 | #elif defined(__INTEL_COMPILER)
66 | return _castf64_u64(f);
67 | #else
68 | union {
69 | double as_value;
70 | uint64_t as_bits;
71 | } fp64 = { f };
72 | return fp64.as_bits;
73 | #endif
74 | }
75 |
76 | #endif /* FP16_BITCASTS_H */
77 |
--------------------------------------------------------------------------------
/Texture2DDecoderNative/pvrtc.h:
--------------------------------------------------------------------------------
1 | #ifndef PVRTC_H
2 | #define PVRTC_H
3 |
4 | #include
5 |
6 | typedef struct {
7 | uint8_t r;
8 | uint8_t g;
9 | uint8_t b;
10 | uint8_t a;
11 | } PVRTCTexelColor;
12 |
13 | typedef struct {
14 | int r;
15 | int g;
16 | int b;
17 | int a;
18 | } PVRTCTexelColorInt;
19 |
20 | typedef struct {
21 | PVRTCTexelColor a;
22 | PVRTCTexelColor b;
23 | int8_t weight[32];
24 | uint32_t punch_through_flag;
25 | } PVRTCTexelInfo;
26 |
27 | int decode_pvrtc(const uint8_t *, const long, const long, uint32_t *, const int);
28 |
29 | #endif /* end of include guard: PVRTC_H */
30 |
--------------------------------------------------------------------------------
/Texture2DDecoderNative/resource.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seiKiMo-Inc/HoYoStudio/ab84d09ed136419d065d42dcf2229fc37e969e84/Texture2DDecoderNative/resource.h
--------------------------------------------------------------------------------
/Texture2DDecoderNative/unitycrunch.cpp:
--------------------------------------------------------------------------------
1 | #include "unitycrunch.h"
2 | #include
3 | #include
4 | #include "unitycrunch/crn_decomp.h"
5 |
6 | bool unity_crunch_unpack_level(const uint8_t* data, uint32_t data_size, uint32_t level_index, void** ret, uint32_t* ret_size) {
7 | unitycrnd::crn_texture_info tex_info;
8 | if (!unitycrnd::crnd_get_texture_info(data, data_size, &tex_info))
9 | {
10 | return false;
11 | }
12 |
13 | unitycrnd::crnd_unpack_context pContext = unitycrnd::crnd_unpack_begin(data, data_size);
14 | if (!pContext)
15 | {
16 | return false;
17 | }
18 |
19 | const crn_uint32 width = std::max(1U, tex_info.m_width >> level_index);
20 | const crn_uint32 height = std::max(1U, tex_info.m_height >> level_index);
21 | const crn_uint32 blocks_x = std::max(1U, (width + 3) >> 2);
22 | const crn_uint32 blocks_y = std::max(1U, (height + 3) >> 2);
23 | const crn_uint32 row_pitch = blocks_x * unitycrnd::crnd_get_bytes_per_dxt_block(tex_info.m_format);
24 | const crn_uint32 total_face_size = row_pitch * blocks_y;
25 | *ret = new uint8_t[total_face_size];
26 | *ret_size = total_face_size;
27 | if (!unitycrnd::crnd_unpack_level(pContext, ret, total_face_size, row_pitch, level_index))
28 | {
29 | unitycrnd::crnd_unpack_end(pContext);
30 | return false;
31 | }
32 | unitycrnd::crnd_unpack_end(pContext);
33 | return true;
34 | }
--------------------------------------------------------------------------------
/Texture2DDecoderNative/unitycrunch.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | bool unity_crunch_unpack_level(const uint8_t* data, uint32_t data_size, uint32_t level_index, void** ret, uint32_t* ret_size);
--------------------------------------------------------------------------------
/Texture2DDecoderWrapper/T2DDll.cs:
--------------------------------------------------------------------------------
1 | namespace Texture2DDecoder
2 | {
3 | internal static class T2DDll
4 | {
5 |
6 | internal const string DllName = "Texture2DDecoderNative";
7 |
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Texture2DDecoderWrapper/Texture2DDecoderWrapper.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net472;netstandard2.0;net5.0;net6.0
5 | true
6 | 0.17.00
7 | 0.17.00
8 | 0.17.00
9 | Copyright © Perfare 2020-2022; Copyright © hozuki 2020
10 | embedded
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------