mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-07-18 03:24:15 -04:00
Replace C++/CLI components with P/Invoke components (#562)
* Replace C++/CLI components with P/Invoke * Deleted C++/CLI projects * Use Utf8StringHandle to marshal UTF-8 strings * Use plaform-default calling convention * Handle DLL preloading on Linux and macOS * Change intermediate and output directories of native projects * Improve P/Invoke documentation
This commit is contained in:
19
Texture2DDecoderWrapper/Properties/AssemblyInfo.cs
Normal file
19
Texture2DDecoderWrapper/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("Texture2DDecoder")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Texture2DDecoder")]
|
||||
[assembly: AssemblyCopyright("Copyright © Perfare 2020; Copyright © hozuki 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
[assembly: Guid("2afce830-b463-49b3-a026-877e5eafc0a4")]
|
||||
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
9
Texture2DDecoderWrapper/T2DDll.cs
Normal file
9
Texture2DDecoderWrapper/T2DDll.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace Texture2DDecoder
|
||||
{
|
||||
internal static class T2DDll
|
||||
{
|
||||
|
||||
internal const string DllName = "Texture2DDecoderNative";
|
||||
|
||||
}
|
||||
}
|
53
Texture2DDecoderWrapper/Texture2DDecoderWrapper.csproj
Normal file
53
Texture2DDecoderWrapper/Texture2DDecoderWrapper.csproj
Normal file
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{2AFCE830-B463-49B3-A026-877E5EAFC0A4}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Texture2DDecoder</RootNamespace>
|
||||
<AssemblyName>Texture2DDecoderWrapper</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="T2DDll.cs" />
|
||||
<Compile Include="TextureDecoder.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TextureDecoder.PInvoke.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AssetStudio.PInvoke\AssetStudio.PInvoke.csproj">
|
||||
<Project>{40c796b5-88ce-4adc-acd6-2f4862b7f136}</Project>
|
||||
<Name>AssetStudio.PInvoke</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
90
Texture2DDecoderWrapper/TextureDecoder.PInvoke.cs
Normal file
90
Texture2DDecoderWrapper/TextureDecoder.PInvoke.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Texture2DDecoder
|
||||
{
|
||||
unsafe partial class TextureDecoder
|
||||
{
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeDXT1(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeDXT5(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodePVRTC(void* data, int width, int height, void* image, [MarshalAs(UnmanagedType.Bool)] bool is2bpp);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeETC1(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeETC2(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeETC2A1(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeETC2A8(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeEACR(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeEACRSigned(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeEACRG(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeEACRGSigned(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeBC4(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeBC5(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeBC6(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeBC7(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeATCRGB4(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeATCRGBA8(void* data, int width, int height, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DecodeASTC(void* data, int width, int height, int blockWidth, int blockHeight, void* image);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
private static extern void DisposeBuffer(ref void* ppBuffer);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
private static extern void UnpackCrunch(void* data, uint dataSize, out void* result, out uint resultSize);
|
||||
|
||||
[DllImport(T2DDll.DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
private static extern void UnpackUnityCrunch(void* data, uint dataSize, out void* result, out uint resultSize);
|
||||
|
||||
}
|
||||
}
|
262
Texture2DDecoderWrapper/TextureDecoder.cs
Normal file
262
Texture2DDecoderWrapper/TextureDecoder.cs
Normal file
@ -0,0 +1,262 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using AssetStudio.PInvoke;
|
||||
|
||||
namespace Texture2DDecoder
|
||||
{
|
||||
public static unsafe partial class TextureDecoder
|
||||
{
|
||||
|
||||
static TextureDecoder()
|
||||
{
|
||||
DllLoader.PreloadDll(T2DDll.DllName);
|
||||
}
|
||||
|
||||
public static bool DecodeDXT1(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeDXT1(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeDXT5(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeDXT5(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodePVRTC(byte[] data, int width, int height, byte[] image, bool is2bpp)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodePVRTC(pData, width, height, pImage, is2bpp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeETC1(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeETC1(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeETC2(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeETC2(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeETC2A1(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeETC2A1(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeETC2A8(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeETC2A8(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeEACR(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeEACR(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeEACRSigned(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeEACRSigned(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeEACRG(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeEACRG(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeEACRGSigned(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeEACRGSigned(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeBC4(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeBC4(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeBC5(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeBC5(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeBC6(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeBC6(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeBC7(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeBC7(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeATCRGB4(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeATCRGB4(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeATCRGBA8(byte[] data, int width, int height, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeATCRGBA8(pData, width, height, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DecodeASTC(byte[] data, int width, int height, int blockWidth, int blockHeight, byte[] image)
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
fixed (byte* pImage = image)
|
||||
{
|
||||
return DecodeASTC(pData, width, height, blockWidth, blockHeight, pImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] UnpackCrunch(byte[] data)
|
||||
{
|
||||
void* pBuffer;
|
||||
uint bufferSize;
|
||||
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
UnpackCrunch(pData, (uint)data.Length, out pBuffer, out bufferSize);
|
||||
}
|
||||
|
||||
if (pBuffer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var result = new byte[bufferSize];
|
||||
|
||||
Marshal.Copy(new IntPtr(pBuffer), result, 0, (int)bufferSize);
|
||||
|
||||
DisposeBuffer(ref pBuffer);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static byte[] UnpackUnityCrunch(byte[] data)
|
||||
{
|
||||
void* pBuffer;
|
||||
uint bufferSize;
|
||||
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
UnpackUnityCrunch(pData, (uint)data.Length, out pBuffer, out bufferSize);
|
||||
}
|
||||
|
||||
if (pBuffer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var result = new byte[bufferSize];
|
||||
|
||||
Marshal.Copy(new IntPtr(pBuffer), result, 0, (int)bufferSize);
|
||||
|
||||
DisposeBuffer(ref pBuffer);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user