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 | }
24 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/Animator.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 Animator : Behaviour
9 | {
10 | public PPtr m_Avatar;
11 | public PPtr m_Controller;
12 | public bool m_HasTransformHierarchy = true;
13 |
14 | public Animator(ObjectReader reader) : base(reader)
15 | {
16 | m_Avatar = new PPtr(reader);
17 | m_Controller = new PPtr(reader);
18 | var m_CullingMode = reader.ReadInt32();
19 |
20 | if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up
21 | {
22 | var m_UpdateMode = reader.ReadInt32();
23 | }
24 |
25 | var m_ApplyRootMotion = reader.ReadBoolean();
26 | if (version[0] == 4 && version[1] >= 5) //4.5 and up - 5.0 down
27 | {
28 | reader.AlignStream();
29 | }
30 |
31 | if (version[0] >= 5) //5.0 and up
32 | {
33 | var m_LinearVelocityBlending = reader.ReadBoolean();
34 | if (version[0] > 2021 || (version[0] == 2021 && version[1] >= 2)) //2021.2 and up
35 | {
36 | var m_StabilizeFeet = reader.ReadBoolean();
37 | }
38 | reader.AlignStream();
39 | }
40 |
41 | if (version[0] < 4 || (version[0] == 4 && version[1] < 5)) //4.5 down
42 | {
43 | var m_AnimatePhysics = reader.ReadBoolean();
44 | }
45 |
46 | if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up
47 | {
48 | m_HasTransformHierarchy = reader.ReadBoolean();
49 | }
50 |
51 | if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up
52 | {
53 | var m_AllowConstantClipSamplingOptimization = reader.ReadBoolean();
54 | }
55 | if (version[0] >= 5 && version[0] < 2018) //5.0 and up - 2018 down
56 | {
57 | reader.AlignStream();
58 | }
59 |
60 | if (version[0] >= 2018) //2018 and up
61 | {
62 | var m_KeepAnimatorControllerStateOnDisable = reader.ReadBoolean();
63 | reader.AlignStream();
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/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 | }
38 |
--------------------------------------------------------------------------------
/AssetStudio/Classes/AssetBundle.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 AssetInfo
9 | {
10 | public int preloadIndex;
11 | public int preloadSize;
12 | public PPtr asset;
13 |
14 | public AssetInfo(ObjectReader reader)
15 | {
16 | preloadIndex = reader.ReadInt32();
17 | preloadSize = reader.ReadInt32();
18 | asset = new PPtr(reader);
19 | }
20 | }
21 |
22 | public sealed class AssetBundle : NamedObject
23 | {
24 | public PPtr[] m_PreloadTable;
25 | public KeyValuePair[] m_Container;
26 |
27 | public AssetBundle(ObjectReader reader) : base(reader)
28 | {
29 | var m_PreloadTableSize = reader.ReadInt32();
30 | m_PreloadTable = new PPtr[m_PreloadTableSize];
31 | for (int i = 0; i < m_PreloadTableSize; i++)
32 | {
33 | m_PreloadTable[i] = new PPtr(reader);
34 | }
35 |
36 | var m_ContainerSize = reader.ReadInt32();
37 | m_Container = new KeyValuePair[m_ContainerSize];
38 | for (int i = 0; i < m_ContainerSize; i++)
39 | {
40 | m_Container[i] = new KeyValuePair(reader.ReadAlignedString(), new AssetInfo(reader));
41 | }
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/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/GameObject.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 GameObject : EditorExtension
9 | {
10 | public PPtr[] m_Components;
11 | public string m_Name;
12 |
13 | public Transform m_Transform;
14 | public MeshRenderer m_MeshRenderer;
15 | public MeshFilter m_MeshFilter;
16 | public SkinnedMeshRenderer m_SkinnedMeshRenderer;
17 | public Animator m_Animator;
18 | public Animation m_Animation;
19 |
20 | public GameObject(ObjectReader reader) : base(reader)
21 | {
22 | int m_Component_size = reader.ReadInt32();
23 | m_Components = new PPtr[m_Component_size];
24 | for (int i = 0; i < m_Component_size; i++)
25 | {
26 | if ((version[0] == 5 && version[1] < 5) || version[0] < 5) //5.5 down
27 | {
28 | int first = reader.ReadInt32();
29 | }
30 | m_Components[i] = new PPtr(reader);
31 | }
32 |
33 | var m_Layer = reader.ReadInt32();
34 | m_Name = reader.ReadAlignedString();
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/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 |
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/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 | }
16 |
--------------------------------------------------------------------------------
/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 float[] m_BlendShapeWeights;
13 |
14 | public SkinnedMeshRenderer(ObjectReader reader) : base(reader)
15 | {
16 | int m_Quality = reader.ReadInt32();
17 | var m_UpdateWhenOffscreen = reader.ReadBoolean();
18 | var m_SkinNormals = reader.ReadBoolean(); //3.1.0 and below
19 | reader.AlignStream();
20 |
21 | if (version[0] == 2 && version[1] < 6) //2.6 down
22 | {
23 | var m_DisableAnimationWhenOffscreen = new PPtr(reader);
24 | }
25 |
26 | m_Mesh = new PPtr(reader);
27 |
28 | m_Bones = new PPtr[reader.ReadInt32()];
29 | for (int b = 0; b < m_Bones.Length; b++)
30 | {
31 | m_Bones[b] = new PPtr(reader);
32 | }
33 |
34 | if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up
35 | {
36 | m_BlendShapeWeights = reader.ReadSingleArray();
37 | }
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/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 class TextAsset : NamedObject
10 | {
11 | public byte[] m_Script;
12 |
13 | public TextAsset(ObjectReader reader) : base(reader)
14 | {
15 | m_Script = reader.ReadUInt8Array();
16 | //m_Script = Encoding.UTF8.GetBytes("测试一下");
17 | }
18 |
19 | public virtual byte[] GetRawScript()
20 | {
21 | return m_Script;
22 | }
23 |
24 | public virtual byte[] GetProcessedScript()
25 | {
26 | return m_Script;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/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 | }
32 |
--------------------------------------------------------------------------------
/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/ClassesExt/LuaByte.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace AssetStudio
7 | {
8 | internal class LuaByte : TextAsset
9 | {
10 | private LuaByteInfo m_LuaByteInfo;
11 |
12 | public LuaByte(ObjectReader reader, LuaByteInfo luaByteInfo) : base(reader)
13 | {
14 | m_LuaByteInfo = luaByteInfo;
15 | }
16 |
17 | public override byte[] GetProcessedScript()
18 | {
19 | if (!m_LuaByteInfo.HasDecompiled)
20 | {
21 | LuaDecompileUtils.DecompileLua(m_LuaByteInfo);
22 | }
23 | return m_LuaByteInfo.ProcessedByte;
24 | }
25 |
26 | public override byte[] GetRawScript()
27 | {
28 | return m_LuaByteInfo.RawByte;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/AssetStudio/ClassesExt/TextAssetFactory.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 TextAssetFactory
9 | {
10 | public static TextAsset Create(ObjectReader reader)
11 | {
12 | reader.Reset();
13 | reader.ReadAlignedString(); // 跳过文件名
14 | byte[] content = reader.ReadUInt8Array();
15 | bool success = LuaByteParser.TryParseLuaByte(content, out LuaByteInfo luaInfo);
16 | if (success)
17 | {
18 | return new LuaByte(reader, luaInfo);
19 | }
20 | else
21 | {
22 | return new TextAsset(reader);
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/AssetStudio/Debuger/DebugWriter.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using Newtonsoft.Json;
3 |
4 | namespace AssetStudio.Debuger
5 | {
6 | public static class DebugWriter
7 | {
8 | public static void SaveObjectToJsonFile(System.Object obj, string path)
9 | {
10 | string json = JsonConvert.SerializeObject(obj, Formatting.Indented);
11 | File.WriteAllText($"{path}.json", json);
12 | }
13 |
14 | public static void SaveBinaryReaderToFile(ObjectReader reader, string outputPath)
15 | {
16 | Stream baseStream = reader.BaseStream;
17 | long originalPosition = baseStream.Position;
18 | long start = reader.byteStart;
19 | long size = reader.byteSize;
20 | baseStream.Position = start;
21 |
22 | using (FileStream fileStream = new FileStream(outputPath + ".bin", FileMode.Create, FileAccess.Write))
23 | {
24 | byte[] buffer = new byte[size];
25 | int bytesRead = baseStream.Read(buffer, 0, (int)size);
26 | if (bytesRead > 0)
27 | {
28 | fileStream.Write(buffer, 0, bytesRead);
29 | }
30 | }
31 |
32 | baseStream.Position = originalPosition;
33 | }
34 |
35 | public static void SaveBinaryReaderToFile(BinaryReader reader, string outputPath)
36 | {
37 | Stream baseStream = reader.BaseStream;
38 | long originalPosition = baseStream.Position;
39 | long size = baseStream.Length - baseStream.Position;
40 | SaveBinaryReaderToFile(reader, originalPosition, size, outputPath);
41 | }
42 |
43 | public static void SaveBinaryReaderToFile(BinaryReader reader, long position, long size, string outputPath)
44 | {
45 | Stream baseStream = reader.BaseStream;
46 |
47 | long originalPosition = baseStream.Position;
48 | baseStream.Position = position;
49 |
50 | using (FileStream fileStream = new FileStream(outputPath + ".bin", FileMode.Create, FileAccess.Write))
51 | {
52 | byte[] buffer = new byte[size];
53 | int bytesRead = baseStream.Read(buffer, 0, (int)size);
54 | if (bytesRead > 0)
55 | {
56 | fileStream.Write(buffer, 0, bytesRead);
57 | }
58 | }
59 |
60 | baseStream.Position = originalPosition;
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/.gitignore:
--------------------------------------------------------------------------------
1 | *.lua[co]
2 | *.py[cod]
3 |
4 | # C extensions
5 | *.so
6 |
7 | # Packages
8 | *.egg
9 | *.egg-info
10 | dist
11 | build
12 | eggs
13 | parts
14 | bin
15 | var
16 | sdist
17 | develop-eggs
18 | .installed.cfg
19 | lib
20 | lib64
21 | __pycache__
22 |
23 | # Installer logs
24 | pip-log.txt
25 |
26 | # Unit test / coverage reports
27 | .coverage
28 | .tox
29 | nosetests.xml
30 |
31 | # Translations
32 | *.mo
33 |
34 | # Mr Developer
35 | .mr.developer.cfg
36 | .project
37 | .pydevproject
38 | .*.swp
39 |
40 |
41 | .vscode
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 Andrian Nord
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/README.md:
--------------------------------------------------------------------------------
1 | # What is new ?
2 |
3 | Support decompilation of 64 bit luajit bytecode
4 |
5 | 支持反编译64位luajit字节码
6 |
7 | ## Ref
8 |
9 | [luajit反编译、解密 - 『软件调试区』 - 吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn](https://www.52pojie.cn/thread-1378796-1-1.html)
10 |
11 | # zzwlpx's ReadMe
12 |
13 | 代码在fork https://github.com/NightNord/ljd 的基础上修改的
14 |
15 | 主要修正了原版本没有将_read_header函数解析过的header中的flag值带进_read_protoypes。
16 |
17 | 解决了原代码只能解析带调试信息的luajit字节码,而解析不带调试信息字节码时报错的问题。
18 |
19 | 此版本可解析luajit2.1.0-beta2的字节码文件。如果要解析其它版本的luajit字节码文件,需要将
20 |
21 | luajit源码中的opcode,写进instruction.py 和 code.py
22 |
23 |
24 | 使用说明:python main.py "path of luajit-bytecode"
25 |
26 | 解释文档:http://www.freebuf.com/column/177810.html
27 |
28 | 参考:https://github.com/NightNord/ljd
29 | https://github.com/feicong/lua_re/blob/master/lua/lua_re3.md
30 | https://bbs.pediy.com/thread-216800.htm
31 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/README.md.txt:
--------------------------------------------------------------------------------
1 | LuaJIT raw-bytecode decompiler (LJD)
2 | ===
3 |
4 | The original name was _ljwthgnd_ as in _LuaJIT 'What The Hell is Going On'
5 | Decompiler_ named under the LuaJIT C sources variable naming convention.
6 |
7 |
8 | __WARNING!__ This code is nor finished, nor tested yet! There is no even
9 | slightest warranty that resulting code is even near to the original. Use it at
10 | your own risk of the wasted time.
11 |
12 | __SECOND WARNING!__ And, BTW, this all is a one huge prototype. Because the
13 | "release" version should be written into lua itself. Because it's cool to
14 | decompile the decompiler - a great test too!
15 |
16 | Requirements
17 | ---
18 |
19 | Python __3.0+__ from python.org
20 |
21 |
22 | How to use it
23 | ---
24 |
25 | There is no argument parsing right now, so comment out things in the ```main.py```
26 | script and launch it as in ```main.py path/to/file.luac```
27 |
28 | TODO
29 | ---
30 |
31 | There is a lot of work to do, in the order of priority
32 |
33 | 0. Logical subexpressions in while statements:
34 | ```lua
35 | while x < (xi and 2 or 3) do
36 | print ("Hello crazy world!")
37 | end
38 | ```
39 |
40 | Logical subexpressions (the subexpressions used as operands in
41 | ariphmetic or comparison operations inside other exrpressions) are
42 | currently supported only for ifs. To support them for whiles and
43 | repeat untils an expression unwarping logic should be moved at the
44 | very beginning. But it won't work without all fixes being done in
45 | a loop unwarping logic. So we need to split that and move the fixes
46 | before expressions before loops before ifs. That's not that easy...
47 |
48 | 1. AST Mutations:
49 | 1. Use the line information (or common sense if there is no line
50 | information) to squash similar expressions into a single expression.
51 |
52 | 2. Formatting improvements
53 | 1. Use the line information (or common sense) to preserve empty lines
54 | and break long statements like in the original code.
55 |
56 | This is mostly done, but only in the "common sense" part.
57 |
58 | 2. Use method-style calls and definitions for tables.
59 |
60 | 3. Features not supported:
61 | 1. GOTO statement (from lua 5.2). All the required functionality is
62 | now in place, but that's rather a low-priority task right now.
63 |
64 | 2. Local sub-blocks:
65 | ```lua
66 | do
67 | ...
68 | end
69 | ```
70 | These subblocks are not reflected anyhow directly in the bytecode.
71 | The only way to guess them is to watch local variable scopes, which
72 | is simple enough in case of non-stripped bytecode and a bit
73 | harder otherwise.
74 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/gconfig.py:
--------------------------------------------------------------------------------
1 |
2 | #zzw 20180714 support str encode
3 | gFlagDic = {'strEncode' : 'ascii'}
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/ast/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/ast/helpers.py:
--------------------------------------------------------------------------------
1 | import ljd.ast.nodes as nodes
2 | import ljd.ast.traverse as traverse
3 |
4 |
5 | def insert_table_record(constructor, key, value):
6 | array = constructor.array.contents
7 | records = constructor.records.contents
8 |
9 | if isinstance(key, nodes.MULTRES):
10 | assert len(records) == 0 \
11 | or isinstance(records[-1], nodes.TableRecord)
12 |
13 | records.append(value)
14 | return
15 |
16 | while isinstance(key, nodes.Constant) \
17 | and key.type == key.T_INTEGER \
18 | and key.value >= 0:
19 | index = key.value
20 |
21 | if index == 1 and len(array) == 0:
22 | record = nodes.ArrayRecord()
23 | record.value = nodes.Primitive()
24 | record.value.type = nodes.Primitive.T_NIL
25 |
26 | array.append(record)
27 |
28 | if (index > len(array)):
29 | break
30 |
31 | record = nodes.ArrayRecord()
32 | record.value = value
33 |
34 | if len(array) == 0 or index == len(array):
35 | array.append(record)
36 | else:
37 | array[index] = record
38 |
39 | return
40 |
41 | record = nodes.TableRecord()
42 | record.key = key
43 | record.value = value
44 |
45 | if len(records) == 0:
46 | records.append(record)
47 | return
48 |
49 | last = records[-1]
50 |
51 | if isinstance(last, (nodes.FunctionCall, nodes.Vararg)):
52 | records.insert(-1, record)
53 | else:
54 | records.append(record)
55 |
56 |
57 | def has_same_table(node, table):
58 | class Checker(traverse.Visitor):
59 | def __init__(self, table):
60 | self.found = False
61 | self.table = table
62 |
63 | def visit_table_element(self, node):
64 | if is_equal(self.table, node):
65 | self.found = True
66 |
67 | def _visit(self, node):
68 | if not self.found:
69 | traverse.Visitor._visit(self, node)
70 |
71 | def _visit_list(self, nodes_list):
72 | if not self.found:
73 | traverse.Visitor._visit_list(self, nodes_list)
74 |
75 | checker = Checker(table)
76 | traverse.traverse(checker, node)
77 |
78 | return checker.found
79 |
80 |
81 | def is_equal(a, b):
82 | if type(a) != type(b):
83 | return False
84 |
85 | if isinstance(a, nodes.Identifier):
86 | return a.type == b.type and a.slot == b.slot
87 | elif isinstance(a, nodes.TableElement):
88 | return is_equal(a.table, b.table) \
89 | and is_equal(a.key, b.key)
90 | else:
91 | assert isinstance(a, nodes.Constant)
92 | return a.type == b.type and a.value == b.value
93 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/bytecode/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/bytecode/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 | T_NIL = 0
6 | T_FALSE = 1
7 | T_TRUE = 2
8 |
9 |
10 | class Table():
11 | def __init__(self):
12 | self.array = []
13 |
14 | # Use a list so we can keep the original items order in the
15 | # table
16 | self.dictionary = []
17 |
18 |
19 | class Constants():
20 | def __init__(self):
21 | self.upvalue_references = []
22 | self.numeric_constants = []
23 | self.complex_constants = []
24 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/bytecode/debuginfo.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 |
6 | class VariableInfo():
7 | T_VISIBILE = 0
8 | T_INTERNAL = 1
9 |
10 | def __init__(self):
11 | self.start_addr = 0
12 | self.end_addr = 0
13 | self.type = -1
14 | self.name = ""
15 |
16 |
17 | class DebugInformation():
18 | def __init__(self):
19 | self.addr_to_line_map = []
20 | self.upvalue_variable_names = []
21 | self.variable_info = []
22 |
23 | def lookup_line_number(self, addr):
24 | try:
25 | return self.addr_to_line_map[addr]
26 | except IndexError:
27 | return 0
28 |
29 | def lookup_local_name(self, addr, slot):
30 | for info in self.variable_info:
31 | if info.start_addr > addr:
32 | break
33 | if info.end_addr <= addr:
34 | continue
35 | elif slot == 0:
36 | return info
37 | else:
38 | slot -= 1
39 |
40 | return None
41 |
42 | def lookup_upvalue_name(self, slot):
43 | try:
44 | return self.upvalue_variable_names[slot]
45 | except IndexError:
46 | return None
47 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/bytecode/helpers.py:
--------------------------------------------------------------------------------
1 | def get_jump_destination(addr, instruction):
2 | return addr + instruction.CD + 1
3 |
4 |
5 | def set_jump_destination(addr, instruction, value):
6 | instruction.CD = value - addr - 1
7 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/bytecode/prototype.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 | import ljd.bytecode.constants as constants
6 | import ljd.bytecode.debuginfo as debug
7 |
8 |
9 | class Flags():
10 | def __init(self):
11 | self.has_sub_prototypes = False
12 | self.is_variadic = False
13 | self.has_ffi = False
14 | self.has_jit = True
15 | self.has_iloop = False
16 |
17 |
18 | class Prototype():
19 | def __init__(self):
20 | self.flags = Flags()
21 |
22 | self.arguments_count = 0
23 |
24 | self.framesize = 0
25 |
26 | self.first_line_number = 0
27 | self.lines_count = 0
28 |
29 | self.instructions = []
30 | self.constants = constants.Constants()
31 | self.debuginfo = debug.DebugInformation()
32 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/lua/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/pseudoasm/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/pseudoasm/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 | import ljd.bytecode.constants
6 |
7 |
8 | def write_tables(writer, prototype):
9 | i = 0
10 |
11 | for element in prototype.constants.complex_constants:
12 | if isinstance(element, ljd.bytecode.constants.Table):
13 | _write_table(writer, i, element)
14 |
15 | i += 1
16 |
17 |
18 | def _write_table(writer, index, table):
19 | writer.stream.open_block("ktable#{0} = [", index)
20 |
21 | i = 0
22 |
23 | for element in table.array:
24 | if i != 0 or element is not None:
25 | text = _translate_element(element)
26 |
27 | writer.stream.write_line("#{0}: {1},", i, text)
28 |
29 | i += 1
30 |
31 | for key, value in table.dictionary:
32 | key = _translate_element(key)
33 | value = _translate_element(value)
34 |
35 | writer.stream.write_line("[{0}] = {1},", key, value)
36 |
37 | writer.stream.close_block("]")
38 | writer.stream.write_line()
39 | writer.stream.write_line()
40 |
41 |
42 | def _translate_element(element):
43 | if element is True:
44 | return "true"
45 | elif element is False:
46 | return "false"
47 | elif element is None:
48 | return "nil"
49 | elif isinstance(element, bytes):
50 | return '"' + element.decode("utf8") + '"'
51 | else:
52 | return str(element)
53 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/pseudoasm/prototype.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 | import ljd.pseudoasm.constants
6 | import ljd.pseudoasm.instructions
7 |
8 |
9 | def write(writer, prototype):
10 | _write_header(writer, prototype)
11 | write_body(writer, prototype)
12 |
13 | writer.stream.close_block("")
14 |
15 |
16 | def _write_header(writer, prototype):
17 | writer.stream.open_block("main {0}", format_header(writer, prototype))
18 |
19 |
20 | def format_header(writer, prototype):
21 | return "{s}:{start}-{end}: {argn}{varg} args," \
22 | " {uvs} upvalues, {slots} slots".format(
23 | s=writer.source,
24 | start=prototype.first_line_number,
25 | end=prototype.first_line_number + prototype.lines_count,
26 | argn=prototype.arguments_count,
27 | varg="+" if prototype.flags.is_variadic else "",
28 | uvs=len(prototype.constants.upvalue_references),
29 | slots=prototype.framesize
30 | )
31 |
32 |
33 | def write_body(writer, prototype):
34 | writer.stream.write_line(";;;; constant tables ;;;;")
35 | ljd.pseudoasm.constants.write_tables(writer, prototype)
36 |
37 | writer.stream.write_line(";;;; instructions ;;;;")
38 | ljd.pseudoasm.instructions.write(writer, prototype)
39 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/pseudoasm/writer.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 | import ljd.util.indentedstream
6 |
7 | import ljd.pseudoasm.prototype
8 |
9 |
10 | class _State():
11 | def __init__(self):
12 | self.flags = None
13 | self.stream = None
14 | self.source = None
15 |
16 |
17 | def write(fd, header, prototype):
18 | writer = _State()
19 |
20 | writer.stream = ljd.util.indentedstream.IndentedStream(fd)
21 | writer.flags = header.flags
22 | writer.source = "N/A" if header.flags.is_stripped else header.name
23 |
24 | _write_header(writer, header)
25 |
26 | ljd.pseudoasm.prototype.write(writer, prototype)
27 |
28 |
29 | def _write_header(writer, header):
30 | writer.stream.write_multiline("""
31 | ;
32 | ; Disassemble of {origin}
33 | ;
34 | ; Source file: {source}
35 | ;
36 | ; Flags:
37 | ; Stripped: {stripped}
38 | ; Endianness: {endianness}
39 | ; FFI: {ffi}
40 | ;
41 |
42 | """, origin=header.origin,
43 | source=writer.source,
44 | stripped="Yes" if header.flags.is_stripped else "No",
45 | endianness="Big" if header.flags.is_big_endian else "Little",
46 | ffi="Present" if header.flags.has_ffi else "Not present")
47 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/rawdump/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/rawdump/debuginfo.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 | import sys
6 |
7 | import ljd.bytecode.debuginfo
8 |
9 |
10 | VARNAME_END = 0
11 | VARNAME_FOR_IDX = 1
12 | VARNAME_FOR_STOP = 2
13 | VARNAME_FOR_STEP = 3
14 | VARNAME_FOR_GEN = 4
15 | VARNAME_FOR_STATE = 5
16 | VARNAME_FOR_CTL = 6
17 | VARNAME__MAX = 7
18 |
19 |
20 | INTERNAL_VARNAMES = [
21 | None,
22 | "",
23 | "",
24 | "",
25 | "",
26 | "",
27 | ""
28 | ]
29 |
30 |
31 | def read(parser, line_offset, debuginfo):
32 | r = True
33 |
34 | r = r and _read_lineinfo(parser, line_offset, debuginfo.addr_to_line_map)
35 | r = r and _read_upvalue_names(parser, debuginfo.upvalue_variable_names)
36 | r = r and _read_variable_infos(parser, debuginfo.variable_info)
37 |
38 | return r
39 |
40 |
41 | def _read_lineinfo(parser, line_offset, lineinfo):
42 | if parser.lines_count >= 65536:
43 | lineinfo_size = 4
44 | elif parser.lines_count >= 256:
45 | lineinfo_size = 2
46 | else:
47 | lineinfo_size = 1
48 |
49 | lineinfo.append(0)
50 |
51 | while len(lineinfo) < parser.instructions_count + 1:
52 | line_number = parser.stream.read_uint(lineinfo_size)
53 | lineinfo.append(line_offset + line_number)
54 |
55 | return True
56 |
57 |
58 | def _read_upvalue_names(parser, names):
59 | while len(names) < parser.upvalues_count:
60 | string = parser.stream.read_zstring()
61 | names.append(string.decode("utf-8"))
62 |
63 | return True
64 |
65 |
66 | def _read_variable_infos(parser, infos):
67 | # pc - program counter
68 | last_addr = 0
69 |
70 | while True:
71 | info = ljd.bytecode.debuginfo.VariableInfo()
72 |
73 | internal_vartype = parser.stream.read_byte()
74 |
75 | if internal_vartype >= VARNAME__MAX:
76 | prefix = internal_vartype.to_bytes(1, sys.byteorder)
77 | suffix = parser.stream.read_zstring()
78 |
79 | info.name = (prefix + suffix).decode("utf-8")
80 | info.type = info.T_VISIBILE
81 |
82 | elif internal_vartype == VARNAME_END:
83 | break
84 | else:
85 | index = internal_vartype
86 | info.name = INTERNAL_VARNAMES[index]
87 | info.type = info.T_INTERNAL
88 |
89 | start_addr = last_addr + parser.stream.read_uleb128()
90 | end_addr = start_addr + parser.stream.read_uleb128()
91 |
92 | info.start_addr = start_addr
93 | info.end_addr = end_addr
94 |
95 | last_addr = start_addr
96 |
97 | infos.append(info)
98 |
99 | return True
100 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/rawdump/header.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 | from ljd.util.log import errprint
6 |
7 |
8 | _MAGIC = b'\x1bLJ'
9 |
10 | _MAX_VERSION = 0x80
11 |
12 | _FLAG_IS_BIG_ENDIAN = 0b00000001
13 | _FLAG_IS_STRIPPED = 0b00000010
14 | _FLAG_HAS_FFI = 0b00000100
15 |
16 |
17 | class Flags():
18 | def __init__(self):
19 | self.is_big_endian = False
20 | self.is_stripped = False
21 | self.has_ffi = False
22 |
23 |
24 | class Header():
25 | def __init__(self):
26 | self.version = 0
27 | self.flags = Flags()
28 | self.origin = b''
29 | self.name = b''
30 |
31 |
32 | def read(state, header):
33 | r = True
34 |
35 | header.origin = state.stream.name
36 |
37 | r = r and _check_magic(state)
38 |
39 | r = r and _read_version(state, header)
40 | r = r and _read_flags(state, header)
41 | r = r and _read_name(state, header)
42 | #print("header good!")
43 |
44 | return r
45 |
46 |
47 | def _check_magic(state):
48 | if state.stream.read_bytes(3) != _MAGIC:
49 | errprint("Invalid magic, not a LuaJIT format")
50 | return False
51 |
52 | return True
53 |
54 |
55 | def _read_version(state, header):
56 | header.version = state.stream.read_byte()
57 |
58 | if header.version > _MAX_VERSION:
59 | errprint("Version {0}: propritary modifications",
60 | header.version)
61 | return False
62 |
63 | return True
64 |
65 |
66 | def _read_flags(parser, header):
67 | bits = parser.stream.read_uleb128()
68 |
69 | header.flags.is_big_endian = bits & _FLAG_IS_BIG_ENDIAN
70 | bits &= ~_FLAG_IS_BIG_ENDIAN
71 |
72 | header.flags.is_stripped = bits & _FLAG_IS_STRIPPED
73 | bits &= ~_FLAG_IS_STRIPPED
74 |
75 | header.flags.has_ffi = bits & _FLAG_HAS_FFI
76 | bits &= ~_FLAG_HAS_FFI
77 |
78 | # zzw.20180714 pitch: flag value is according to parser.flag when parse proto, not by header.flags
79 | parser.flags.is_big_endian = header.flags.is_big_endian
80 | parser.flags.is_stripped = header.flags.is_stripped
81 | parser.flags.is_big_endian = header.flags.has_ffi
82 |
83 | #if bits != 0:
84 | # errprint("Unknown flags set: {0:08b}", bits)
85 | # return False
86 |
87 | return True
88 |
89 |
90 | def _read_name(state, header):
91 | if header.flags.is_stripped:
92 | header.name = state.stream.name
93 | else:
94 | length = state.stream.read_uleb128()
95 | header.name = state.stream.read_bytes(length).decode("utf8")
96 |
97 | return True
98 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/rawdump/parser.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 | #!/usr/bin/python3
6 |
7 | import ljd.util.binstream
8 | from ljd.util.log import errprint
9 |
10 | import ljd.bytecode.prototype
11 |
12 | import ljd.rawdump.header
13 | import ljd.rawdump.prototype
14 |
15 |
16 | class _State():
17 | def __init__(self):
18 | self.stream = ljd.util.binstream.BinStream()
19 | self.flags = ljd.rawdump.header.Flags()
20 | self.prototypes = []
21 |
22 |
23 | def parse(filename):
24 | parser = _State()
25 |
26 | parser.stream.open(filename)
27 |
28 | header = ljd.rawdump.header.Header()
29 |
30 | r = True
31 |
32 | try:
33 | r = r and _read_header(parser, header)
34 | #print("good1")
35 | r = r and _read_prototypes(parser, parser.prototypes)
36 | #print("good2")
37 | except IOError as e:
38 | errprint("I/O error while reading dump: {0}", str(e))
39 | r = False
40 |
41 | if r and not parser.stream.eof():
42 | errprint("Stopped before whole file was read, something wrong")
43 | r = False
44 |
45 | if r and len(parser.prototypes) != 1:
46 | errprint("Invalid prototypes stack order")
47 | r = False
48 |
49 | parser.stream.close()
50 |
51 | if r:
52 | return header, parser.prototypes[0]
53 | else:
54 | return None, None
55 |
56 | #zzw 20180716 解析字节码文件头部结构header
57 | '''
58 | | magic(3 bytes)| version(1 byte) | flag(1 uleb128) [| name(1 uleb128) |]
59 | '''
60 | def _read_header(parser, header):
61 | if not ljd.rawdump.header.read(parser, header):
62 | errprint("Failed to read raw-dump header")
63 | return False
64 |
65 | if header.flags.is_big_endian:
66 | parser.stream.data_byteorder = 'big'
67 | else:
68 | parser.stream.data_byteorder = 'little'
69 |
70 | return True
71 |
72 |
73 | def _read_prototypes(state, prototypes):
74 | while not state.stream.eof():
75 | prototype = ljd.bytecode.prototype.Prototype()
76 | #print ("good rwsdump->parser->read_prototypes")
77 |
78 | if not ljd.rawdump.prototype.read(state, prototype):
79 | if state.stream.eof():
80 | break
81 | else:
82 | errprint("Failed to read prototype")
83 | return False
84 |
85 | prototypes.append(prototype)
86 |
87 | return True
88 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/util/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/util/binstream.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 | import io
6 | import os
7 | import sys
8 |
9 |
10 | class BinStream():
11 | def __init__(self):
12 | self.fd = None
13 |
14 | self.size = 0
15 | self.pos = 0
16 | self.name = ""
17 |
18 | self.data_byteorder = sys.byteorder
19 |
20 | def open(self, filename):
21 | self.name = filename
22 | self.fd = io.open(filename, 'rb')
23 | self.size = os.stat(filename).st_size
24 |
25 | def close(self):
26 | self.fd.close()
27 | self.size = 0
28 | self.pos = 0
29 |
30 | def eof(self):
31 | return self.pos >= self.size
32 |
33 | def check_data_available(self, size=1):
34 | return self.pos + size <= self.size
35 |
36 | def read_bytes(self, size=1):
37 | if not self.check_data_available(size):
38 | raise IOError("Unexpected EOF while trying to read {0} bytes"
39 | .format(size))
40 |
41 | data = self.fd.read(size)
42 | self.pos += len(data)#size
43 |
44 | return data
45 |
46 | def read_byte(self):
47 | if not self.check_data_available(1):
48 | raise IOError("Unexpected EOF while trying to read 1 byte")
49 |
50 | data = self.fd.read(1)
51 | self.pos += 1
52 |
53 | return int.from_bytes(data,
54 | byteorder=sys.byteorder,
55 | signed=False)
56 |
57 | def read_zstring(self):
58 | string = b''
59 |
60 | while not self.eof():
61 | byte = self.read_bytes(1)
62 |
63 | if byte == b'\x00':
64 | return string
65 | else:
66 | string += byte
67 |
68 | return string
69 |
70 | def read_uleb128(self):
71 | value = self.read_byte()
72 |
73 | if value >= 0x80:
74 | bitshift = 0
75 | value &= 0x7f
76 |
77 | while True:
78 | byte = self.read_byte()
79 |
80 | bitshift += 7
81 | value |= (byte & 0x7f) << bitshift
82 |
83 | if byte < 0x80:
84 | break
85 |
86 | return value
87 |
88 | def read_uleb128_from33bit(self):
89 | first_byte = self.read_byte()
90 |
91 | is_number_bit = first_byte & 0x1
92 | value = first_byte >> 1
93 |
94 | if value >= 0x40:
95 | bitshift = -1
96 | value &= 0x3f
97 |
98 | while True:
99 | byte = self.read_byte()
100 |
101 | bitshift += 7
102 | value |= (byte & 0x7f) << bitshift
103 |
104 | if byte < 0x80:
105 | break
106 |
107 | return is_number_bit, value
108 |
109 | def read_uint(self, size=4):
110 | value = self.read_bytes(size)
111 |
112 | return int.from_bytes(value, byteorder=self.data_byteorder,
113 | signed=False)
114 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/util/indentedstream.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 | _TAB_WIDTH = " " * 8
6 |
7 |
8 | class IndentedStream():
9 | def __init__(self, fd):
10 | self.fd = fd
11 |
12 | self.indent = 0
13 | self.line_open = False
14 |
15 | def write_multiline(self, fmt, *args, **kargs):
16 | assert not self.line_open
17 |
18 | if len(args) + len(kargs) > 0:
19 | text = fmt.format(*args, **kargs)
20 | else:
21 | text = fmt
22 |
23 | lines = text.split("\n")
24 |
25 | if lines[0] == "":
26 | lines.pop(0)
27 |
28 | if lines[-1] == "":
29 | lines.pop(-1)
30 |
31 | spaces = "\t" * self.indent
32 |
33 | for line in lines:
34 | self.fd.write(spaces + line + "\n")
35 |
36 | def start_line(self):
37 | assert not self.line_open
38 | self.line_open = True
39 |
40 | self.fd.write("\t" * self.indent)
41 |
42 | def write(self, fmt="", *args, **kargs):
43 | assert self.line_open
44 |
45 | if len(args) + len(kargs) > 0:
46 | text = fmt.format(*args, **kargs)
47 | elif isinstance(fmt, str):
48 | text = fmt
49 | else:
50 | text = str(fmt)
51 |
52 | assert "\n" not in text
53 |
54 | self.fd.write(text)
55 |
56 | def end_line(self):
57 | assert self.line_open
58 |
59 | self.fd.write("\n")
60 |
61 | self.line_open = False
62 |
63 | def write_line(self, *args, **kargs):
64 | self.start_line()
65 | self.write(*args, **kargs)
66 | self.end_line()
67 |
68 | def open_block(self, *args, **kargs):
69 | if len(args) + len(kargs) > 0:
70 | self.write_line(*args, **kargs)
71 |
72 | self.indent += 1
73 |
74 | def close_block(self, *args, **kargs):
75 | if len(args) + len(kargs) > 0:
76 | self.write_line(*args, **kargs)
77 |
78 | self.indent -= 1
79 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/ljd/ljd/util/log.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py
3 | #
4 |
5 | import sys
6 |
7 |
8 | def errprint(*args):
9 | fmt = None
10 |
11 | args = list(args)
12 |
13 | if isinstance(args[0], str):
14 | fmt = args.pop(0)
15 |
16 | if fmt:
17 | print(fmt.format(*args), file=sys.stderr)
18 | else:
19 | strs = [repr(x) for x in args]
20 | print(" ".join(strs), file=sys.stderr)
21 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/luadec/lua51/luadec.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/luadec/lua51/luadec.exe
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/luadec/lua52/luadec.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/luadec/lua52/luadec.exe
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/luadec/lua53/luadec.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/luadec/lua53/luadec.exe
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/Lib/site-packages/start_path.pth:
--------------------------------------------------------------------------------
1 | import sys;import os;sys.path.insert(0,os.path.dirname(sys.argv[0]));
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/_asyncio.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/_asyncio.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/_bz2.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/_bz2.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/_ctypes.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/_ctypes.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/_decimal.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/_decimal.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/_elementtree.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/_elementtree.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/_hashlib.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/_hashlib.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/_lzma.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/_lzma.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/_msi.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/_msi.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/_multiprocessing.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/_multiprocessing.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/_overlapped.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/_overlapped.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/_queue.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/_queue.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/_socket.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/_socket.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/_sqlite3.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/_sqlite3.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/_ssl.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/_ssl.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/libcrypto-1_1.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/libcrypto-1_1.dll
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/libffi-7.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/libffi-7.dll
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/libssl-1_1.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/libssl-1_1.dll
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/pyexpat.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/pyexpat.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/python.cat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/python.cat
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/python.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/python.exe
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/python3.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/python3.dll
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/python38._pth:
--------------------------------------------------------------------------------
1 | python38.zip
2 | .
3 |
4 | # Uncomment to run site.main() automatically
5 | import site
6 |
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/python38.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/python38.dll
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/python38.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/python38.zip
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/pythonw.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/pythonw.exe
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/select.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/select.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/sqlite3.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/sqlite3.dll
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/unicodedata.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/unicodedata.pyd
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/vcruntime140.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/vcruntime140.dll
--------------------------------------------------------------------------------
/AssetStudio/Dependencies/python/winsound.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudio/Dependencies/python/winsound.pyd
--------------------------------------------------------------------------------
/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/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/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 | WebFile,
14 | ResourceFile,
15 | GZipFile,
16 | BrotliFile,
17 | ZipFile
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/LuaDecompile/LuaByteInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Text;
2 |
3 | namespace AssetStudio
4 | {
5 | public class LuaByteInfo
6 | {
7 | private byte[] m_Bytes;
8 | private LuaCompileType m_CompileType;
9 | private byte m_Version;
10 | private byte[] m_DecompileContent;
11 |
12 | public byte[] RawByte => m_Bytes;
13 | public LuaCompileType CompileType => m_CompileType;
14 | public byte VersionCode => m_Version;
15 | public bool HasDecompiled;
16 |
17 |
18 | public byte[] ProcessedByte
19 | {
20 | get
21 | {
22 | if (m_DecompileContent == null || m_DecompileContent.Length == 0)
23 | {
24 | return m_Bytes;
25 | }
26 | else
27 | {
28 | return m_DecompileContent;
29 | }
30 | }
31 | }
32 |
33 | public LuaByteInfo(byte[] luaBytes, LuaCompileType compileType, byte version)
34 | {
35 | m_Bytes = luaBytes;
36 | m_CompileType = compileType;
37 | m_Version = version;
38 | }
39 |
40 | public void SetDecompiledContent(byte[] decompiledBytes)
41 | {
42 | m_DecompileContent = decompiledBytes;
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/AssetStudio/LuaDecompile/LuaByteParser.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Linq;
6 |
7 | namespace AssetStudio
8 | {
9 | public static class LuaByteParser
10 | {
11 | private static readonly byte[] LuacMagicNum = new byte[] { 0x1B, 0x4C, 0x75, 0x61 };
12 | private static readonly byte[] LuaJitMagicNum = new byte[] { 0x1B, 0x4C, 0x4A };
13 | public static bool TryParseLuaByte(byte[] luaBytes, out LuaByteInfo luaByteInfo)
14 | {
15 | luaByteInfo = null;
16 | if (luaBytes.Length > 5) //长度大于一个文件头,可以尝试解析
17 | {
18 | {
19 | luaByteInfo = TryParseLuaJit(luaBytes);
20 | }
21 |
22 | if (luaByteInfo == null)
23 | {
24 | luaByteInfo = TryParseLuac(luaBytes);
25 | }
26 | }
27 |
28 | return luaByteInfo != null;
29 | }
30 |
31 | private static LuaByteInfo TryParseLuaJit(byte[] luaBytes)
32 | {
33 | MemoryStream byteStream = new MemoryStream(luaBytes);
34 | BinaryReader luaByteReader = new BinaryReader(byteStream);
35 | if (CompareMagicNum(luaByteReader, LuaJitMagicNum))
36 | {
37 | byte version = luaByteReader.ReadByte();
38 | return new LuaByteInfo(luaBytes, LuaCompileType.LuaJit, version);
39 | }
40 | else
41 | {
42 | return null;
43 | }
44 | }
45 |
46 | private static LuaByteInfo TryParseLuac(byte[] luaBytes)
47 | {
48 | MemoryStream byteStream = new MemoryStream(luaBytes);
49 | BinaryReader luaByteReader = new BinaryReader(byteStream);
50 | if (CompareMagicNum(luaByteReader, LuacMagicNum))
51 | {
52 | byte version = luaByteReader.ReadByte();
53 | return new LuaByteInfo(luaBytes, LuaCompileType.Luac, version);
54 | }
55 | else
56 | {
57 | return null;
58 | }
59 | }
60 |
61 | private static bool CompareMagicNum(BinaryReader br, byte[] magicNum)
62 | {
63 | return br.ReadBytes(magicNum.Length).SequenceEqual(magicNum);
64 | }
65 | }
66 | }
--------------------------------------------------------------------------------
/AssetStudio/LuaDecompile/LuaCompileType.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | public enum LuaCompileType
4 | {
5 | None,
6 | Luac,
7 | LuaJit
8 | }
9 | }
--------------------------------------------------------------------------------
/AssetStudio/LuaDecompile/LuaDecompileUtils.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.IO;
3 | using System.Text;
4 |
5 | namespace AssetStudio
6 | {
7 | public class LuaDecompileUtils
8 | {
9 | private static Dictionary handlerMap = new Dictionary()
10 | {
11 | { LuaCompileType.Luac, new LuacDecompileHandler()},
12 | { LuaCompileType.LuaJit, new LuaJitDecompileHandler()},
13 | };
14 |
15 | public static byte[] DecompileLua(LuaByteInfo luaByteInfo)
16 | {
17 | luaByteInfo.HasDecompiled = true;
18 | bool isSupport = handlerMap.TryGetValue(luaByteInfo.CompileType, out ILuaDecompileHandler handler);
19 | if (!isSupport)
20 | {
21 | // 不支持的编译方式,原文返回
22 | return luaByteInfo.ProcessedByte;
23 | }
24 | else
25 | {
26 | return handler.Decompile(luaByteInfo);
27 | }
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/AssetStudio/LuaDecompile/OutputProcess.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.Text;
4 |
5 | namespace AssetStudio
6 | {
7 | public class OutputProcess : Process
8 | {
9 | private StringBuilder m_Output = new StringBuilder();
10 | private StringBuilder m_Error = new StringBuilder();
11 |
12 | public string Output => m_Output.ToString();
13 | public string Error => m_Error.ToString();
14 |
15 | public OutputProcess()
16 | {
17 | StartInfo.RedirectStandardOutput = true;
18 | StartInfo.RedirectStandardError = true;
19 |
20 | OutputDataReceived += OnProcessOutput;
21 | ErrorDataReceived += OnProcessError;
22 | }
23 |
24 | private void OnProcessOutput(object sender, DataReceivedEventArgs events)
25 | {
26 | if (!string.IsNullOrEmpty(events.Data))
27 | {
28 | m_Output.AppendLine(events.Data);
29 | }
30 | }
31 |
32 | private void OnProcessError(object sender, DataReceivedEventArgs events)
33 | {
34 | if (!string.IsNullOrEmpty(events.Data))
35 | {
36 | m_Error.AppendLine(events.Data);
37 | }
38 | }
39 |
40 | public new bool Start()
41 | {
42 | m_Output.Clear();
43 | bool success = base.Start();
44 | if (success)
45 | {
46 | BeginOutputReadLine();
47 | BeginErrorReadLine();
48 | }
49 | return success;
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/AssetStudio/LuaDecompile/handlers/ILuaDecompileHandler.cs:
--------------------------------------------------------------------------------
1 | namespace AssetStudio
2 | {
3 | public interface ILuaDecompileHandler
4 | {
5 | byte[] Decompile(LuaByteInfo luaByteInfo);
6 | }
7 | }
--------------------------------------------------------------------------------
/AssetStudio/LuaDecompile/handlers/LuaJitDecompileHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Text;
4 |
5 | namespace AssetStudio
6 | {
7 | public class LuaJitDecompileHandler : ILuaDecompileHandler
8 | {
9 | private const string LJD_PATH = "ljd/main.py";
10 | private const string PTYHON_PATH = "python/python.exe";
11 | private const string DEPENDENCY_PATH = "Dependencies";
12 | private const string TEMP_FILE = "tempCompiledLua.lua";
13 |
14 | public byte[] Decompile(LuaByteInfo luaByteInfo)
15 | {
16 | if (TryDecompile(luaByteInfo.RawByte, out byte[] luaCode))
17 | {
18 | // 缓存反编译结果
19 | luaByteInfo.SetDecompiledContent(luaCode);
20 | }
21 |
22 | return luaByteInfo.ProcessedByte;
23 | }
24 |
25 | private bool TryDecompile(byte[] luaBytes, out byte[] luaCode)
26 | {
27 | var dependencyPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DEPENDENCY_PATH));
28 | var decompilerPath = Path.GetFullPath(Path.Combine(dependencyPath, LJD_PATH));
29 | var pythonExePath = Path.GetFullPath(Path.Combine(dependencyPath, PTYHON_PATH));
30 |
31 | File.WriteAllBytes(TEMP_FILE, luaBytes);
32 |
33 | var decompileProcess = BuildProcess(pythonExePath, string.Format("{0} {1}", decompilerPath, TEMP_FILE));
34 |
35 | bool success = true;
36 | luaCode = null;
37 | try
38 | {
39 | decompileProcess.Start();
40 | decompileProcess.WaitForExit();
41 | if (decompileProcess.ExitCode == 0)
42 | {
43 | luaCode = Encoding.UTF8.GetBytes(decompileProcess.Output);
44 | }
45 | else
46 | {
47 | Console.WriteLine(decompileProcess.Error);
48 | }
49 | }
50 | catch (Exception e)
51 | {
52 | Console.WriteLine(e.Message);
53 | success = false;
54 | }
55 | finally
56 | {
57 | decompileProcess.Close();
58 | }
59 |
60 | return success;
61 | }
62 |
63 | private OutputProcess BuildProcess(string pythonExePath, string args)
64 | {
65 | var decompileProcess = new OutputProcess();
66 | decompileProcess.StartInfo.FileName = pythonExePath;
67 | decompileProcess.StartInfo.Arguments = args;
68 | decompileProcess.StartInfo.UseShellExecute = false;
69 | decompileProcess.StartInfo.StandardOutputEncoding = Encoding.UTF8;
70 | return decompileProcess;
71 | }
72 | }
73 | }
--------------------------------------------------------------------------------
/AssetStudio/LuaDecompile/handlers/LuacDecompileHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.IO;
5 | using System.Text;
6 |
7 | namespace AssetStudio
8 | {
9 | public class LuacDecompileHandler : ILuaDecompileHandler
10 | {
11 | private Dictionary versionHandlerMap = new Dictionary()
12 | {
13 | { 0x51, "lua51/luadec.exe" },
14 | { 0x52, "lua52/luadec.exe" },
15 | { 0x53, "lua53/luadec.exe" },
16 | };
17 |
18 | private const string EXE_DIR = "Dependencies/luadec";
19 | private const string TEMP_FILE = "tempCompiledLua.lua";
20 | private static readonly string DecompileArg = $"-se UTF8 {TEMP_FILE}";
21 |
22 | public byte[] Decompile(LuaByteInfo luaByteInfo)
23 | {
24 | var isSupport = versionHandlerMap.TryGetValue(luaByteInfo.VersionCode, out string subPath);
25 | if (!isSupport)
26 | {
27 | // 不支持的版本,原样输出
28 | return luaByteInfo.ProcessedByte;
29 | }
30 | else
31 | {
32 | // 反编译
33 | return TryDecompile(luaByteInfo, subPath);
34 | }
35 | }
36 |
37 | private byte[] TryDecompile(LuaByteInfo luaByteInfo, string exePath)
38 | {
39 | File.WriteAllBytes(TEMP_FILE, luaByteInfo.RawByte);
40 | var decompileProcess = new OutputProcess();
41 | decompileProcess.StartInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, EXE_DIR, exePath);
42 | decompileProcess.StartInfo.Arguments = DecompileArg;
43 | decompileProcess.StartInfo.StandardOutputEncoding = Encoding.UTF8;
44 | decompileProcess.StartInfo.UseShellExecute = false;
45 | try
46 | {
47 | decompileProcess.Start();
48 | decompileProcess.WaitForExit();
49 | if (decompileProcess.ExitCode == 0)
50 | {
51 | // 编译完成结果缓存起来;
52 | luaByteInfo.SetDecompiledContent(Encoding.UTF8.GetBytes(decompileProcess.Output));
53 | }
54 | else
55 | {
56 | Console.WriteLine(decompileProcess.Error);
57 | }
58 | }
59 | catch (Exception e)
60 | {
61 | Console.WriteLine(e.Message);
62 | }
63 | finally
64 | {
65 | decompileProcess.Close();
66 | }
67 | return luaByteInfo.ProcessedByte;
68 | }
69 |
70 | }
71 | }
--------------------------------------------------------------------------------
/AssetStudio/Math/Color.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace AssetStudio
5 | {
6 | [StructLayout(LayoutKind.Sequential, Pack = 4)]
7 | public struct Color : IEquatable
8 | {
9 | public float R;
10 | public float G;
11 | public float B;
12 | public float A;
13 |
14 | public Color(float r, float g, float b, float a)
15 | {
16 | R = r;
17 | G = g;
18 | B = b;
19 | A = a;
20 | }
21 |
22 | public override int GetHashCode()
23 | {
24 | return ((Vector4)this).GetHashCode();
25 | }
26 |
27 | public override bool Equals(object other)
28 | {
29 | if (!(other is Color))
30 | return false;
31 | return Equals((Color)other);
32 | }
33 |
34 | public bool Equals(Color other)
35 | {
36 | return R.Equals(other.R) && G.Equals(other.G) && B.Equals(other.B) && A.Equals(other.A);
37 | }
38 |
39 | public static Color operator +(Color a, Color b)
40 | {
41 | return new Color(a.R + b.R, a.G + b.G, a.B + b.B, a.A + b.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, float b)
55 | {
56 | return new Color(a.R * b, a.G * b, a.B * b, a.A * b);
57 | }
58 |
59 | public static Color operator *(float b, Color a)
60 | {
61 | return new Color(a.R * b, a.G * b, a.B * b, a.A * b);
62 | }
63 |
64 | public static Color operator /(Color a, float b)
65 | {
66 | return new Color(a.R / b, a.G / b, a.B / b, a.A / b);
67 | }
68 |
69 | public static bool operator ==(Color lhs, Color rhs)
70 | {
71 | return (Vector4)lhs == (Vector4)rhs;
72 | }
73 |
74 | public static bool operator !=(Color lhs, Color rhs)
75 | {
76 | return !(lhs == rhs);
77 | }
78 |
79 | public static implicit operator Vector4(Color c)
80 | {
81 | return new Vector4(c.R, c.G, c.B, c.A);
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/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
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 | private const float kEpsilon = 0.000001F;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/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 | }
21 |
--------------------------------------------------------------------------------
/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 | m_PathID = objectInfo.m_PathID;
27 | byteStart = objectInfo.byteStart;
28 | byteSize = objectInfo.byteSize;
29 | if (Enum.IsDefined(typeof(ClassIDType), objectInfo.classID))
30 | {
31 | type = (ClassIDType)objectInfo.classID;
32 | }
33 | else
34 | {
35 | type = ClassIDType.UnknownType;
36 | }
37 | serializedType = objectInfo.serializedType;
38 | platform = assetsFile.m_TargetPlatform;
39 | m_Version = assetsFile.header.m_Version;
40 | }
41 |
42 | public void Reset()
43 | {
44 | Position = byteStart;
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/AssetStudio/Progress.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace AssetStudio
4 | {
5 | public static class Progress
6 | {
7 | public static IProgress Default = new Progress();
8 | private static int preValue;
9 |
10 | public static void Reset()
11 | {
12 | preValue = 0;
13 | Default.Report(0);
14 | }
15 |
16 | public static void Report(int current, int total)
17 | {
18 | var value = (int)(current * 100f / total);
19 | Report(value);
20 | }
21 |
22 | private static void Report(int value)
23 | {
24 | if (value > preValue)
25 | {
26 | preValue = value;
27 | Default.Report(value);
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/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.16.53.0
7 | 0.16.53.0
8 | 0.16.53.0
9 | Copyright © zhangjiequan 2018-2023; 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 | internal 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 | internal 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/DonateForm.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Forms;
2 | using System.Drawing;
3 |
4 | public class DonateForm : Form
5 | {
6 | public DonateForm()
7 | {
8 | InitializeComponent();
9 | }
10 |
11 | private void InitializeComponent()
12 | {
13 | this.Icon = global::AssetStudioGUI.Properties.Resources._as;
14 | this.Size = new Size(840, 470);
15 | this.Text = "Donate to AssetStudio";
16 |
17 | Label label = new Label();
18 | label.Text = "AssetStudio is a free and open-source software.\nIf you like it and find it helpful, you can buy me a coffee!";
19 | label.AutoSize = false;
20 | label.Size = new Size(840, 50);
21 | label.Location = new Point(10, 10);
22 | label.Font = new Font(label.Font.FontFamily, 12, FontStyle.Regular);
23 | label.Padding = new Padding(0, 5, 0, 5);
24 |
25 | PictureBox pictureBox = new PictureBox();
26 | pictureBox.Size = new Size(800, 350);
27 | pictureBox.Location = new Point(10, 60);
28 | pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
29 | pictureBox.Image = global::AssetStudioGUI.Properties.Resources.donate;
30 |
31 | this.Controls.Add(label);
32 | this.Controls.Add(pictureBox);
33 | }
34 | }
--------------------------------------------------------------------------------
/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/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudioGUI/Libraries/OpenTK.WinForms.dll
--------------------------------------------------------------------------------
/AssetStudioGUI/Libraries/x64/fmod.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudioGUI/Libraries/x64/fmod.dll
--------------------------------------------------------------------------------
/AssetStudioGUI/Libraries/x86/fmod.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/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(string[] args)
16 | {
17 | #if !NETFRAMEWORK
18 | Application.SetHighDpiMode(HighDpiMode.SystemAware);
19 | #endif
20 | Application.EnableVisualStyles();
21 | Application.SetCompatibleTextRenderingDefault(false);
22 | Application.Run(new AssetStudioGUIForm(args));
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/AssetStudioGUI/Resources/as.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudioGUI/Resources/as.ico
--------------------------------------------------------------------------------
/AssetStudioGUI/Resources/donate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudioGUI/Resources/donate.png
--------------------------------------------------------------------------------
/AssetStudioGUI/Resources/preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/AssetStudioGUI/Resources/preview.png
--------------------------------------------------------------------------------
/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.16.53.0
6 | 0.16.53.0
7 | 0.16.53.0
8 | Copyright © zhangjiequan 2018-2023
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/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-2023 Perfare
5 | Copyright (c) 2023-2023 zhangjiequan
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in all
15 | copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 | SOFTWARE.
24 |
--------------------------------------------------------------------------------
/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.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/zhangjiequan/AssetStudio/c32bde552015a6cd56ace1c7b60d586084fc3876/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.16.53.0
7 | 0.16.53.0
8 | 0.16.53.0
9 | Copyright © zhangjiequan 2020-2023; Copyright © hozuki 2020
10 | embedded
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------