Move data to a submodule
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
#define IDR_VERSION2 101
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 102
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
#include "winres.h"
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 0,7,1,0
|
||||
PRODUCTVERSION 0,7,1,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x0L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "000904b0"
|
||||
BEGIN
|
||||
VALUE "FileDescription", "KKdLib"
|
||||
VALUE "FileVersion", "0.7.1.0"
|
||||
VALUE "InternalName", "KKdLib"
|
||||
VALUE "LegalCopyright", "korenkonder (C) 2017-2024"
|
||||
VALUE "OriginalFilename", "KKdLib"
|
||||
VALUE "ProductName", "KKdLib"
|
||||
VALUE "ProductVersion", "0.7.1.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x9, 1200
|
||||
END
|
||||
END
|
||||
@@ -1,281 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="DebugOpt|x64">
|
||||
<Configuration>DebugOpt</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="ReleaseLTCG|x64">
|
||||
<Configuration>ReleaseLTCG</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<ProjectGuid>{65707ad3-568a-4fe9-a75e-bdbf3d5efc88}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugOpt|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='DebugOpt|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<TargetName>KKdLib</TargetName>
|
||||
<OutDir>$(SolutionDir)lib\debug\</OutDir>
|
||||
<IntDir>$(SolutionDir)obj\debug\KKdLib\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugOpt|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<TargetName>KKdLib</TargetName>
|
||||
<OutDir>$(SolutionDir)lib\debugopt\</OutDir>
|
||||
<IntDir>$(SolutionDir)obj\debugopt\KKdLib\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<TargetName>KKdLib</TargetName>
|
||||
<OutDir>$(SolutionDir)lib\release\</OutDir>
|
||||
<IntDir>$(SolutionDir)obj\release\KKdLib\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<TargetName>KKdLib</TargetName>
|
||||
<OutDir>$(SolutionDir)lib\releaseltcg\</OutDir>
|
||||
<IntDir>$(SolutionDir)obj\releaseltcg\KKdLib\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
<OmitFramePointers>false</OmitFramePointers>
|
||||
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
||||
<PreprocessToFile>false</PreprocessToFile>
|
||||
<CallingConvention>FastCall</CallingConvention>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)extern\src</AdditionalIncludeDirectories>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<CompileAs>CompileAsCpp</CompileAs>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<ObjectFileName>$(IntDir)/%(RelativeDir)</ObjectFileName>
|
||||
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugOpt|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Full</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<OmitFramePointers>false</OmitFramePointers>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
||||
<CallingConvention>FastCall</CallingConvention>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)extern\src</AdditionalIncludeDirectories>
|
||||
<CompileAs>CompileAsCpp</CompileAs>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<ObjectFileName>$(IntDir)/%(RelativeDir)</ObjectFileName>
|
||||
<UseFullPaths>false</UseFullPaths>
|
||||
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<Lib>
|
||||
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<OmitFramePointers>false</OmitFramePointers>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
||||
<CallingConvention>FastCall</CallingConvention>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)extern\src</AdditionalIncludeDirectories>
|
||||
<CompileAs>CompileAsCpp</CompileAs>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<ObjectFileName>$(IntDir)/%(RelativeDir)</ObjectFileName>
|
||||
<UseFullPaths>false</UseFullPaths>
|
||||
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<Lib>
|
||||
<LinkTimeCodeGeneration>true</LinkTimeCodeGeneration>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<OmitFramePointers>false</OmitFramePointers>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
||||
<CallingConvention>FastCall</CallingConvention>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)extern\src</AdditionalIncludeDirectories>
|
||||
<CompileAs>CompileAsCpp</CompileAs>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<AdditionalOptions>/Gw %(AdditionalOptions)</AdditionalOptions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<ObjectFileName>$(IntDir)/%(RelativeDir)</ObjectFileName>
|
||||
<UseFullPaths>false</UseFullPaths>
|
||||
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<Lib>
|
||||
<LinkTimeCodeGeneration>true</LinkTimeCodeGeneration>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="aes.hpp" />
|
||||
<ClInclude Include="default.hpp" />
|
||||
<ClInclude Include="deflate.hpp" />
|
||||
<ClInclude Include="divafile.hpp" />
|
||||
<ClInclude Include="f2\enrs.hpp" />
|
||||
<ClInclude Include="f2\header.hpp" />
|
||||
<ClInclude Include="f2\pof.hpp" />
|
||||
<ClInclude Include="f2\struct.hpp" />
|
||||
<ClInclude Include="farc.hpp" />
|
||||
<ClInclude Include="half_t.hpp" />
|
||||
<ClInclude Include="hash.hpp" />
|
||||
<ClInclude Include="image.hpp" />
|
||||
<ClInclude Include="interpolation.hpp" />
|
||||
<ClInclude Include="io\file_stream.hpp" />
|
||||
<ClInclude Include="io\memory_stream.hpp" />
|
||||
<ClInclude Include="io\path.hpp" />
|
||||
<ClInclude Include="io\stream.hpp" />
|
||||
<ClInclude Include="kf.hpp" />
|
||||
<ClInclude Include="mat.hpp" />
|
||||
<ClInclude Include="prj\algorithm.hpp" />
|
||||
<ClInclude Include="prj\math.hpp" />
|
||||
<ClInclude Include="prj\shared_ptr.hpp" />
|
||||
<ClInclude Include="prj\stack_allocator.hpp" />
|
||||
<ClInclude Include="prj\time.hpp" />
|
||||
<ClInclude Include="prj\vector_pair.hpp" />
|
||||
<ClInclude Include="prj\vector_pair_combine.hpp" />
|
||||
<ClInclude Include="quat.hpp" />
|
||||
<ClInclude Include="str_utils.hpp" />
|
||||
<ClInclude Include="time.hpp" />
|
||||
<ClInclude Include="txp.hpp" />
|
||||
<ClInclude Include="types.hpp" />
|
||||
<ClInclude Include="vec.hpp" />
|
||||
<ClInclude Include="waitable_timer.hpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="KKdLib.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="aes.cpp" />
|
||||
<ClCompile Include="default.cpp" />
|
||||
<ClCompile Include="deflate.cpp" />
|
||||
<ClCompile Include="divafile.cpp" />
|
||||
<ClCompile Include="f2\enrs.cpp" />
|
||||
<ClCompile Include="f2\header.cpp" />
|
||||
<ClCompile Include="f2\pof.cpp" />
|
||||
<ClCompile Include="f2\struct.cpp" />
|
||||
<ClCompile Include="farc.cpp" />
|
||||
<ClCompile Include="half_t.cpp" />
|
||||
<ClCompile Include="hash.cpp" />
|
||||
<ClCompile Include="image.cpp" />
|
||||
<ClCompile Include="interpolation.cpp" />
|
||||
<ClCompile Include="io\file_stream.cpp" />
|
||||
<ClCompile Include="io\memory_stream.cpp" />
|
||||
<ClCompile Include="io\path.cpp" />
|
||||
<ClCompile Include="io\stream.cpp" />
|
||||
<ClCompile Include="kf.cpp" />
|
||||
<ClCompile Include="mat.cpp" />
|
||||
<ClCompile Include="prj\stack_allocator.cpp" />
|
||||
<ClCompile Include="prj\time.cpp" />
|
||||
<ClCompile Include="quat.cpp" />
|
||||
<ClCompile Include="str_utils.cpp" />
|
||||
<ClCompile Include="time.cpp" />
|
||||
<ClCompile Include="txp.cpp" />
|
||||
<ClCompile Include="vec.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
</Project>
|
||||
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ShowAllFiles>true</ShowAllFiles>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LocalDebuggerDebuggerType>NativeOnly</LocalDebuggerDebuggerType>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugOpt|x64'">
|
||||
<LocalDebuggerDebuggerType>NativeOnly</LocalDebuggerDebuggerType>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LocalDebuggerDebuggerType>NativeOnly</LocalDebuggerDebuggerType>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|x64'">
|
||||
<LocalDebuggerDebuggerType>NativeOnly</LocalDebuggerDebuggerType>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
-1346
File diff suppressed because it is too large
Load Diff
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
Original: https://github.com/kokke/tiny-AES-c
|
||||
*/
|
||||
|
||||
#ifndef _AES_H_
|
||||
#define _AES_H_
|
||||
|
||||
#include "default.hpp"
|
||||
#include <immintrin.h>
|
||||
|
||||
//#define AES128 1
|
||||
//#define AES192 1
|
||||
//#define AES256 1
|
||||
|
||||
#define AES_BLOCKLEN 16 // Block length in bytes - AES is 128b block only
|
||||
|
||||
#define AES128_KEYLEN 16 // Key length in bytes
|
||||
#define AES128_keyExpSize 176
|
||||
#define AES192_KEYLEN 24
|
||||
#define AES192_keyExpSize 208
|
||||
#define AES256_KEYLEN 32
|
||||
#define AES256_keyExpSize 240
|
||||
|
||||
struct aes128_ctx {
|
||||
union {
|
||||
uint8_t RoundKey[AES128_keyExpSize];
|
||||
__m128i RoundKeyNI[AES128_keyExpSize / sizeof(__m128i) + 9];
|
||||
};
|
||||
uint8_t Iv[AES_BLOCKLEN];
|
||||
};
|
||||
|
||||
struct aes192_ctx {
|
||||
union {
|
||||
uint8_t RoundKey[AES192_keyExpSize];
|
||||
__m128i RoundKeyNI[AES192_keyExpSize / sizeof(__m128i) + 11];
|
||||
};
|
||||
uint8_t Iv[AES_BLOCKLEN];
|
||||
};
|
||||
|
||||
struct aes256_ctx {
|
||||
union {
|
||||
uint8_t RoundKey[AES256_keyExpSize];
|
||||
__m128i RoundKeyNI[AES256_keyExpSize / sizeof(__m128i) + 13];
|
||||
};
|
||||
uint8_t Iv[AES_BLOCKLEN];
|
||||
};
|
||||
|
||||
void aes128_init_ctx(aes128_ctx* ctx, const uint8_t* key);
|
||||
void aes192_init_ctx(aes192_ctx* ctx, const uint8_t* key);
|
||||
void aes256_init_ctx(aes256_ctx* ctx, const uint8_t* key);
|
||||
void aes128_init_ctx_iv(aes128_ctx* ctx, const uint8_t* key, const uint8_t* iv);
|
||||
void aes192_init_ctx_iv(aes192_ctx* ctx, const uint8_t* key, const uint8_t* iv);
|
||||
void aes256_init_ctx_iv(aes256_ctx* ctx, const uint8_t* key, const uint8_t* iv);
|
||||
void aes128_ctx_set_iv(aes128_ctx* ctx, const uint8_t* iv);
|
||||
void aes192_ctx_set_iv(aes192_ctx* ctx, const uint8_t* iv);
|
||||
void aes256_ctx_set_iv(aes256_ctx* ctx, const uint8_t* iv);
|
||||
|
||||
// buffer size is exactly AES_BLOCKLEN bytes;
|
||||
// you need only AES_init_ctx as IV is not used in ECB
|
||||
void aes128_ecb_encrypt(aes128_ctx* ctx, uint8_t* buf);
|
||||
void aes192_ecb_encrypt(aes192_ctx* ctx, uint8_t* buf);
|
||||
void aes256_ecb_encrypt(aes256_ctx* ctx, uint8_t* buf);
|
||||
void aes128_ecb_decrypt(aes128_ctx* ctx, uint8_t* buf);
|
||||
void aes192_ecb_decrypt(aes192_ctx* ctx, uint8_t* buf);
|
||||
void aes256_ecb_decrypt(aes256_ctx* ctx, uint8_t* buf);
|
||||
void aes128_ecb_encrypt_buffer(aes128_ctx* ctx, uint8_t* buf, size_t length);
|
||||
void aes192_ecb_encrypt_buffer(aes192_ctx* ctx, uint8_t* buf, size_t length);
|
||||
void aes256_ecb_encrypt_buffer(aes256_ctx* ctx, uint8_t* buf, size_t length);
|
||||
void aes128_ecb_decrypt_buffer(aes128_ctx* ctx, uint8_t* buf, size_t length);
|
||||
void aes192_ecb_decrypt_buffer(aes192_ctx* ctx, uint8_t* buf, size_t length);
|
||||
void aes256_ecb_decrypt_buffer(aes256_ctx* ctx, uint8_t* buf, size_t length);
|
||||
|
||||
void aes128_cbc_encrypt(aes128_ctx* ctx, uint8_t buf[AES_BLOCKLEN]);
|
||||
void aes192_cbc_encrypt(aes192_ctx* ctx, uint8_t buf[AES_BLOCKLEN]);
|
||||
void aes256_cbc_encrypt(aes256_ctx* ctx, uint8_t buf[AES_BLOCKLEN]);
|
||||
void aes128_cbc_decrypt(aes128_ctx* ctx, uint8_t buf[AES_BLOCKLEN]);
|
||||
void aes192_cbc_decrypt(aes192_ctx* ctx, uint8_t buf[AES_BLOCKLEN]);
|
||||
void aes256_cbc_decrypt(aes256_ctx* ctx, uint8_t buf[AES_BLOCKLEN]);
|
||||
void aes128_cbc_encrypt_buffer(aes128_ctx* ctx, uint8_t* buf, size_t length);
|
||||
void aes192_cbc_encrypt_buffer(aes192_ctx* ctx, uint8_t* buf, size_t length);
|
||||
void aes256_cbc_encrypt_buffer(aes256_ctx* ctx, uint8_t* buf, size_t length);
|
||||
void aes128_cbc_decrypt_buffer(aes128_ctx* ctx, uint8_t* buf, size_t length);
|
||||
void aes192_cbc_decrypt_buffer(aes192_ctx* ctx, uint8_t* buf, size_t length);
|
||||
void aes256_cbc_decrypt_buffer(aes256_ctx* ctx, uint8_t* buf, size_t length);
|
||||
|
||||
void aes128_ctr_xcrypt_buffer(aes128_ctx* ctx, uint8_t* buf, uint32_t length);
|
||||
void aes192_ctr_xcrypt_buffer(aes192_ctx* ctx, uint8_t* buf, uint32_t length);
|
||||
void aes256_ctr_xcrypt_buffer(aes256_ctx* ctx, uint8_t* buf, uint32_t length);
|
||||
|
||||
#endif // _AES_H_
|
||||
@@ -1,345 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "default.hpp"
|
||||
|
||||
void* force_malloc(size_t size) {
|
||||
if (!size)
|
||||
return 0;
|
||||
|
||||
void* buf = 0;
|
||||
while (!buf)
|
||||
buf = malloc(size);
|
||||
memset(buf, 0, size);
|
||||
return buf;
|
||||
}
|
||||
|
||||
wchar_t* utf8_to_utf16(const char* s) {
|
||||
if (!s)
|
||||
return 0;
|
||||
|
||||
uint32_t c = 0;
|
||||
size_t length = utf8_to_utf16_length(s);
|
||||
|
||||
wchar_t* str = force_malloc<wchar_t>(length + 1);
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
size_t j = 0;
|
||||
size_t l = 0;
|
||||
while (*s) {
|
||||
char t = *s++;
|
||||
if (!(t & 0x80)) {
|
||||
l = 0;
|
||||
str[j++] = t;
|
||||
c = 0;
|
||||
continue;
|
||||
}
|
||||
else if ((t & 0xFC) == 0xF8)
|
||||
continue;
|
||||
else if ((t & 0xF8) == 0xF0) {
|
||||
c = t & 0x07;
|
||||
l = 3;
|
||||
}
|
||||
else if ((t & 0xF0) == 0xE0) {
|
||||
c = t & 0x0F;
|
||||
l = 2;
|
||||
}
|
||||
else if ((t & 0xE0) == 0xC0) {
|
||||
c = t & 0x1F;
|
||||
l = 1;
|
||||
}
|
||||
else if ((t & 0xC0) == 0x80) {
|
||||
c = (c << 6) | (t & 0x3F);
|
||||
l--;
|
||||
}
|
||||
|
||||
if (!l) {
|
||||
if (c <= 0xD7FF || (c >= 0xE000 && c <= 0xFFFF))
|
||||
str[j++] = c;
|
||||
else if (c >= 0x10000 && c <= 0x10FFFF) {
|
||||
c -= 0x10000;
|
||||
str[j++] = 0xD800 | ((c >> 10) & 0x3FF);
|
||||
str[j++] = 0xDC00 | (c & 0x3FF);
|
||||
}
|
||||
c = 0;
|
||||
}
|
||||
}
|
||||
str[length] = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
wchar_t* utf8_to_utf16(const char* s, size_t length) {
|
||||
if (!s || !length)
|
||||
return 0;
|
||||
|
||||
uint32_t c = 0;
|
||||
size_t _length = utf8_to_utf16_length(s);
|
||||
|
||||
wchar_t* str = force_malloc<wchar_t>(_length + 1);
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
size_t j = 0;
|
||||
size_t l = 0;
|
||||
while (*s && length) {
|
||||
char t = *s++;
|
||||
length--;
|
||||
if (!(t & 0x80)) {
|
||||
l = 0;
|
||||
str[j++] = t;
|
||||
c = 0;
|
||||
continue;
|
||||
}
|
||||
else if ((t & 0xFC) == 0xF8)
|
||||
continue;
|
||||
else if ((t & 0xF8) == 0xF0) {
|
||||
c = t & 0x07;
|
||||
l = 3;
|
||||
}
|
||||
else if ((t & 0xF0) == 0xE0) {
|
||||
c = t & 0x0F;
|
||||
l = 2;
|
||||
}
|
||||
else if ((t & 0xE0) == 0xC0) {
|
||||
c = t & 0x1F;
|
||||
l = 1;
|
||||
}
|
||||
else if ((t & 0xC0) == 0x80) {
|
||||
c = (c << 6) | (t & 0x3F);
|
||||
l--;
|
||||
}
|
||||
|
||||
if (!l) {
|
||||
if (c <= 0xD7FF || (c >= 0xE000 && c <= 0xFFFF))
|
||||
str[j++] = c;
|
||||
else if (c >= 0x10000 && c <= 0x10FFFF) {
|
||||
c -= 0x10000;
|
||||
str[j++] = 0xD800 | ((c >> 10) & 0x3FF);
|
||||
str[j++] = 0xDC00 | (c & 0x3FF);
|
||||
}
|
||||
c = 0;
|
||||
}
|
||||
}
|
||||
str[_length] = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
char* utf16_to_utf8(const wchar_t* s) {
|
||||
if (!s)
|
||||
return 0;
|
||||
|
||||
uint32_t c = 0;
|
||||
size_t length = utf16_to_utf8_length(s);
|
||||
|
||||
char* str = force_malloc<char>(length + 1);
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
size_t j = 0;
|
||||
while (*s) {
|
||||
c = *s++;
|
||||
if ((c & 0xFC00) == 0xD800) {
|
||||
if (!*s)
|
||||
break;
|
||||
|
||||
wchar_t _c = *s++;
|
||||
if ((_c & 0xFC00) != 0xDC00)
|
||||
continue;
|
||||
|
||||
c &= 0x3FF;
|
||||
c <<= 10;
|
||||
c |= _c & 0x3FF;
|
||||
c += 0x10000;
|
||||
}
|
||||
else if ((c & 0xFC00) == 0xDC00)
|
||||
continue;
|
||||
|
||||
if (c <= 0x7F)
|
||||
str[j++] = (uint8_t)c;
|
||||
else if (c <= 0x7FF) {
|
||||
str[j++] = (uint8_t)(0xC0 | ((c >> 6) & 0x1F));
|
||||
str[j++] = (uint8_t)(0x80 | (c & 0x3F));
|
||||
}
|
||||
else if ((c >= 0x800 && c <= 0xD7FF) || (c >= 0xE000 && c <= 0xFFFF)) {
|
||||
str[j++] = (uint8_t)(0xE0 | ((c >> 12) & 0xF));
|
||||
str[j++] = (uint8_t)(0x80 | ((c >> 6) & 0x3F));
|
||||
str[j++] = (uint8_t)(0x80 | (c & 0x3F));
|
||||
}
|
||||
else if (c >= 0x10000 && c <= 0x10FFFF) {
|
||||
str[j++] = (uint8_t)(0xF0 | ((c >> 18) & 0x7));
|
||||
str[j++] = (uint8_t)(0x80 | ((c >> 12) & 0x3F));
|
||||
str[j++] = (uint8_t)(0x80 | ((c >> 6) & 0x3F));
|
||||
str[j++] = (uint8_t)(0x80 | (c & 0x3F));
|
||||
}
|
||||
}
|
||||
str[length] = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
char* utf16_to_utf8(const wchar_t* s, size_t length) {
|
||||
if (!s || !length)
|
||||
return 0;
|
||||
|
||||
uint32_t c = 0;
|
||||
size_t _length = utf16_to_utf8_length(s);
|
||||
|
||||
char* str = force_malloc<char>(_length + 1);
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
size_t j = 0;
|
||||
while (*s && length) {
|
||||
c = *s++;
|
||||
length--;
|
||||
if ((c & 0xFC00) == 0xD800) {
|
||||
if (!*s)
|
||||
break;
|
||||
|
||||
wchar_t _c = *s++;
|
||||
if ((_c & 0xFC00) != 0xDC00)
|
||||
continue;
|
||||
|
||||
c &= 0x3FF;
|
||||
c <<= 10;
|
||||
c |= _c & 0x3FF;
|
||||
c += 0x10000;
|
||||
}
|
||||
else if ((c & 0xFC00) == 0xDC00)
|
||||
continue;
|
||||
|
||||
if (c <= 0x7F)
|
||||
str[j++] = (uint8_t)c;
|
||||
else if (c <= 0x7FF) {
|
||||
str[j++] = (uint8_t)(0xC0 | ((c >> 6) & 0x1F));
|
||||
str[j++] = (uint8_t)(0x80 | (c & 0x3F));
|
||||
}
|
||||
else if ((c >= 0x800 && c <= 0xD7FF) || (c >= 0xE000 && c <= 0xFFFF)) {
|
||||
str[j++] = (uint8_t)(0xE0 | ((c >> 12) & 0xF));
|
||||
str[j++] = (uint8_t)(0x80 | ((c >> 6) & 0x3F));
|
||||
str[j++] = (uint8_t)(0x80 | (c & 0x3F));
|
||||
}
|
||||
else if (c >= 0x10000 && c <= 0x10FFFF) {
|
||||
str[j++] = (uint8_t)(0xF0 | ((c >> 18) & 0x7));
|
||||
str[j++] = (uint8_t)(0x80 | ((c >> 12) & 0x3F));
|
||||
str[j++] = (uint8_t)(0x80 | ((c >> 6) & 0x3F));
|
||||
str[j++] = (uint8_t)(0x80 | (c & 0x3F));
|
||||
}
|
||||
}
|
||||
str[_length] = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
std::wstring utf8_to_utf16(const std::string& s) {
|
||||
size_t length = s.size();
|
||||
if (!length)
|
||||
return {};
|
||||
|
||||
uint32_t c = 0;
|
||||
size_t _length = utf8_to_utf16_length(s.c_str());
|
||||
|
||||
std::wstring str;
|
||||
str.resize(_length);
|
||||
|
||||
char* _s = (char*)s.data();
|
||||
wchar_t* _str = (wchar_t*)str.data();
|
||||
|
||||
size_t l = 0;
|
||||
while (*_s && length) {
|
||||
char t = *_s++;
|
||||
length--;
|
||||
if (!(t & 0x80)) {
|
||||
l = 0;
|
||||
*_str++ = t;
|
||||
c = 0;
|
||||
continue;
|
||||
}
|
||||
else if ((t & 0xFC) == 0xF8)
|
||||
continue;
|
||||
else if ((t & 0xF8) == 0xF0) {
|
||||
c = t & 0x07;
|
||||
l = 3;
|
||||
}
|
||||
else if ((t & 0xF0) == 0xE0) {
|
||||
c = t & 0x0F;
|
||||
l = 2;
|
||||
}
|
||||
else if ((t & 0xE0) == 0xC0) {
|
||||
c = t & 0x1F;
|
||||
l = 1;
|
||||
}
|
||||
else if ((t & 0xC0) == 0x80) {
|
||||
c = (c << 6) | (t & 0x3F);
|
||||
l--;
|
||||
}
|
||||
|
||||
if (!l) {
|
||||
if (c <= 0xD7FF || (c >= 0xE000 && c <= 0xFFFF))
|
||||
*_str++ = c;
|
||||
else if (c >= 0x10000 && c <= 0x10FFFF) {
|
||||
c -= 0x10000;
|
||||
*_str++ = 0xD800 | ((c >> 10) & 0x3FF);
|
||||
}
|
||||
c = 0;
|
||||
}
|
||||
}
|
||||
*_str++ = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string utf16_to_utf8(const std::wstring& s) {
|
||||
size_t length = s.size();
|
||||
if (!length)
|
||||
return {};
|
||||
|
||||
uint32_t c = 0;
|
||||
size_t _length = utf16_to_utf8_length(s.c_str());
|
||||
|
||||
std::string str;
|
||||
str.resize(_length);
|
||||
|
||||
wchar_t* _s = (wchar_t*)s.data();
|
||||
char* _str = (char*)str.data();
|
||||
|
||||
while (*_s && length) {
|
||||
c = *_s++;
|
||||
length--;
|
||||
if ((c & 0xFC00) == 0xD800) {
|
||||
if (!*_s)
|
||||
break;
|
||||
|
||||
wchar_t _c = *_s++;
|
||||
if ((_c & 0xFC00) != 0xDC00)
|
||||
continue;
|
||||
|
||||
c &= 0x3FF;
|
||||
c <<= 10;
|
||||
c |= _c & 0x3FF;
|
||||
c += 0x10000;
|
||||
}
|
||||
else if ((c & 0xFC00) == 0xDC00)
|
||||
continue;
|
||||
|
||||
if (c <= 0x7F)
|
||||
*_str++ = (uint8_t)c;
|
||||
else if (c <= 0x7FF) {
|
||||
*_str++ = (uint8_t)(0xC0 | ((c >> 6) & 0x1F));
|
||||
*_str++ = (uint8_t)(0x80 | (c & 0x3F));
|
||||
}
|
||||
else if ((c >= 0x800 && c <= 0xD7FF) || (c >= 0xE000 && c <= 0xFFFF)) {
|
||||
*_str++ = (uint8_t)(0xE0 | ((c >> 12) & 0xF));
|
||||
*_str++ = (uint8_t)(0x80 | ((c >> 6) & 0x3F));
|
||||
*_str++ = (uint8_t)(0x80 | (c & 0x3F));
|
||||
}
|
||||
else if (c >= 0x10000 && c <= 0x10FFFF) {
|
||||
*_str++ = (uint8_t)(0xF0 | ((c >> 18) & 0x7));
|
||||
*_str++ = (uint8_t)(0x80 | ((c >> 12) & 0x3F));
|
||||
*_str++ = (uint8_t)(0x80 | ((c >> 6) & 0x3F));
|
||||
*_str++ = (uint8_t)(0x80 | (c & 0x3F));
|
||||
}
|
||||
}
|
||||
*_str++ = 0;
|
||||
return str;
|
||||
}
|
||||
@@ -1,543 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define NOMINMAX
|
||||
#define _USE_MATH_DEFINES
|
||||
#include "types.hpp"
|
||||
#include "prj/math.hpp"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <fileapi.h>
|
||||
#include <string>
|
||||
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable: 26812 )
|
||||
|
||||
template <typename T>
|
||||
inline void free_def(T& ptr) {
|
||||
if (ptr)
|
||||
free(ptr);
|
||||
ptr = 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct null_def {
|
||||
bool has_value;
|
||||
T value;
|
||||
};
|
||||
|
||||
template <typename T, typename U>
|
||||
inline T max_def(const T left, const U right) {
|
||||
return left > right ? left : right;
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline T min_def(const T left, const U right) {
|
||||
return left < right ? left : right;
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline T mult_min_max_def(const T value, const U pos_scale, const U neg_scale) {
|
||||
return (value >= (T)0) ? (value * pos_scale) : (value * neg_scale);
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline T div_min_max_def(const T value, const U pos_scale, const U neg_scale) {
|
||||
return (value >= (T)0) ? (value / pos_scale) : (value / neg_scale);
|
||||
}
|
||||
|
||||
template <typename T, typename U, typename V>
|
||||
inline T clamp_def(const T value, const U min, const V max) {
|
||||
return min_def(max_def(value, min), max);
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline T align_val(const T value, const U align) {
|
||||
return (value + align - (T)1) / align * align;
|
||||
}
|
||||
|
||||
template <typename T, typename U, typename V>
|
||||
inline T align_val_divide(const T value, const U align, const V div) {
|
||||
return (value + align - (T)1) / div;
|
||||
}
|
||||
|
||||
#define BUF_SIZE 4096
|
||||
|
||||
#define RAD_TO_DEG ((double_t)(180.0 / M_PI))
|
||||
|
||||
#define DEG_TO_RAD ((double_t)(M_PI / 180.0))
|
||||
|
||||
#define RAD_TO_DEG_FLOAT ((float_t)(180.0 / M_PI))
|
||||
|
||||
#define DEG_TO_RAD_FLOAT ((float_t)(M_PI / 180.0))
|
||||
|
||||
inline float __CRTDECL ctgf(float _X) {
|
||||
return 1.0f / tanf(_X);
|
||||
}
|
||||
|
||||
inline float __CRTDECL ctghf(float _X) {
|
||||
return 1.0f / tanhf(_X);
|
||||
}
|
||||
|
||||
inline float __CRTDECL actgf(float _X) {
|
||||
return 1.0f / atanf(_X);
|
||||
}
|
||||
|
||||
inline float __CRTDECL actghf(float _X) {
|
||||
return 1.0f / atanhf(_X);
|
||||
}
|
||||
|
||||
inline double __CRTDECL ctg(double _X) {
|
||||
return 1.0 / tan(_X);
|
||||
}
|
||||
|
||||
inline double __CRTDECL ctgh(double _X) {
|
||||
return 1.0 / tanh(_X);
|
||||
}
|
||||
|
||||
inline double __CRTDECL actg(double _X) {
|
||||
return 1.0 / atan(_X);
|
||||
}
|
||||
|
||||
inline double __CRTDECL actgh(double _X) {
|
||||
return 1.0 / atanh(_X);
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline T lerp_def(T x, T y, U blend) {
|
||||
return ((T)1 - (T)blend) * x + blend * y;
|
||||
}
|
||||
|
||||
extern void* force_malloc(size_t size);
|
||||
|
||||
template <typename T>
|
||||
inline T* force_malloc() {
|
||||
return (T*)force_malloc(sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T* force_malloc(size_t size) {
|
||||
return (T*)force_malloc(sizeof(T) * (size));
|
||||
}
|
||||
|
||||
#define enum_or(s0, s1) \
|
||||
(s0) = (decltype(s0))((int32_t)(s0) | (s1))
|
||||
|
||||
#define enum_xor(s0, s1) \
|
||||
(s0) = (decltype(s0))((int32_t)(s0) ^ (s1))
|
||||
|
||||
#define enum_and(s0, s1) \
|
||||
(s0) = (decltype(s0))((int32_t)(s0) & (s1))
|
||||
|
||||
#define enum_not(s0, s1) \
|
||||
(s0) = (decltype(s0))(~(int32_t)(s0))
|
||||
|
||||
inline int16_t load_reverse_endianness_int16_t(const void* ptr) {
|
||||
return (int16_t)_byteswap_ushort(*(uint16_t*)ptr);
|
||||
}
|
||||
|
||||
inline uint16_t load_reverse_endianness_uint16_t(const void* ptr) {
|
||||
return (uint16_t)_byteswap_ushort(*(uint16_t*)ptr);
|
||||
}
|
||||
|
||||
inline int32_t load_reverse_endianness_int32_t(const void* ptr) {
|
||||
return (int32_t)_byteswap_ulong(*(uint32_t*)ptr);
|
||||
}
|
||||
|
||||
inline uint32_t load_reverse_endianness_uint32_t(const void* ptr) {
|
||||
return (uint32_t)_byteswap_ulong(*(uint32_t*)ptr);
|
||||
}
|
||||
|
||||
inline int64_t load_reverse_endianness_int64_t(const void* ptr) {
|
||||
return (int64_t)_byteswap_uint64(*(uint64_t*)ptr);
|
||||
}
|
||||
|
||||
inline uint64_t load_reverse_endianness_uint64_t(const void* ptr) {
|
||||
return (uint64_t)_byteswap_uint64(*(uint64_t*)ptr);
|
||||
}
|
||||
|
||||
inline ssize_t load_reverse_endianness_ssize_t(const void* ptr) {
|
||||
return (ssize_t)_byteswap_uint64(*(uint64_t*)ptr);
|
||||
}
|
||||
|
||||
inline size_t load_reverse_endianness_size_t(const void* ptr) {
|
||||
return (size_t)_byteswap_uint64(*(uint64_t*)ptr);
|
||||
}
|
||||
|
||||
inline float_t load_reverse_endianness_float_t(const void* ptr) {
|
||||
uint32_t v = (uint32_t)_byteswap_ulong(*(uint32_t*)ptr);
|
||||
return *(float_t*)&v;
|
||||
}
|
||||
|
||||
inline double_t load_reverse_endianness_double_t(const void* ptr) {
|
||||
uint64_t v = (uint64_t)_byteswap_uint64(*(uint64_t*)ptr);
|
||||
return *(double_t*)&v;
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_int16_t(void* ptr, int16_t value) {
|
||||
*(int16_t*)ptr = (int16_t)_byteswap_ushort((uint16_t)value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_int16_t(void* ptr, uint16_t value) {
|
||||
*(int16_t*)ptr = (int16_t)_byteswap_ushort(value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_uint16_t(void* ptr, int16_t value) {
|
||||
*(uint16_t*)ptr = (uint16_t)_byteswap_ushort((uint16_t)value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_uint16_t(void* ptr, uint16_t value) {
|
||||
*(uint16_t*)ptr = (uint16_t)_byteswap_ushort(value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_int32_t(void* ptr, int32_t value) {
|
||||
*(int32_t*)ptr = (int32_t)_byteswap_ulong((uint32_t)value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_int32_t(void* ptr, uint32_t value) {
|
||||
*(int32_t*)ptr = (int32_t)_byteswap_ulong(value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_uint32_t(void* ptr, int32_t value) {
|
||||
*(uint32_t*)ptr = (uint32_t)_byteswap_ulong((uint32_t)value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_uint32_t(void* ptr, uint32_t value) {
|
||||
*(uint32_t*)ptr = (uint32_t)_byteswap_ulong(value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_int64_t(void* ptr, int64_t value) {
|
||||
*(int64_t*)ptr = (int64_t)_byteswap_uint64((uint64_t)value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_int64_t(void* ptr, uint64_t value) {
|
||||
*(int64_t*)ptr = (int64_t)_byteswap_uint64(value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_uint64_t(void* ptr, int64_t value) {
|
||||
*(uint64_t*)ptr = (uint64_t)_byteswap_uint64((uint64_t)value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_uint64_t(void* ptr, uint64_t value) {
|
||||
*(uint64_t*)ptr = (uint64_t)_byteswap_uint64(value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_ssize_t(void* ptr, ssize_t value) {
|
||||
*(ssize_t*)ptr = (ssize_t)_byteswap_uint64((uint64_t)value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_ssize_t(void* ptr, size_t value) {
|
||||
*(ssize_t*)ptr = (ssize_t)_byteswap_uint64((uint64_t)value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_size_t(void* ptr, ssize_t value) {
|
||||
*(size_t*)ptr = (size_t)_byteswap_uint64((uint64_t)value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_size_t(void* ptr, size_t value) {
|
||||
*(size_t*)ptr = (size_t)_byteswap_uint64((uint64_t)value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_float_t(void* ptr, float_t value) {
|
||||
*(uint32_t*)ptr = (uint32_t)_byteswap_ulong(*(uint32_t*)&value);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_double_t(void* ptr, double_t value) {
|
||||
*(uint64_t*)ptr = (uint64_t)_byteswap_uint64(*(uint64_t*)&value);
|
||||
}
|
||||
|
||||
inline int16_t reverse_endianness_int16_t(int16_t value) {
|
||||
return (int16_t)_byteswap_ushort((uint16_t)value);
|
||||
}
|
||||
|
||||
inline int16_t reverse_endianness_int16_t(uint16_t value) {
|
||||
return (int16_t)_byteswap_ushort(value);
|
||||
}
|
||||
|
||||
inline uint16_t reverse_endianness_uint16_t(int16_t value) {
|
||||
return (uint16_t)_byteswap_ushort((uint16_t)value);
|
||||
}
|
||||
|
||||
inline uint16_t reverse_endianness_uint16_t(uint16_t value) {
|
||||
return (uint16_t)_byteswap_ushort(value);
|
||||
}
|
||||
|
||||
inline int32_t reverse_endianness_int32_t(int32_t value) {
|
||||
return (int32_t)_byteswap_ulong((uint32_t)value);
|
||||
}
|
||||
|
||||
inline int32_t reverse_endianness_int32_t(uint32_t value) {
|
||||
return (int32_t)_byteswap_ulong(value);
|
||||
}
|
||||
|
||||
inline uint32_t reverse_endianness_uint32_t(int32_t value) {
|
||||
return (uint32_t)_byteswap_ulong((uint32_t)value);
|
||||
}
|
||||
|
||||
inline uint32_t reverse_endianness_uint32_t(uint32_t value) {
|
||||
return (uint32_t)_byteswap_ulong(value);
|
||||
}
|
||||
|
||||
inline int64_t reverse_endianness_int64_t(int64_t value) {
|
||||
return (int64_t)_byteswap_uint64((uint64_t)value);
|
||||
}
|
||||
|
||||
inline int64_t reverse_endianness_int64_t(uint64_t value) {
|
||||
return (int64_t)_byteswap_uint64(value);
|
||||
}
|
||||
|
||||
inline uint64_t reverse_endianness_uint64_t(int64_t value) {
|
||||
return (uint64_t)_byteswap_uint64((uint64_t)value);
|
||||
}
|
||||
|
||||
inline uint64_t reverse_endianness_uint64_t(uint64_t value) {
|
||||
return (uint64_t)_byteswap_uint64(value);
|
||||
}
|
||||
|
||||
inline ssize_t reverse_endianness_ssize_t(ssize_t value) {
|
||||
return (ssize_t)_byteswap_uint64((uint64_t)value);
|
||||
}
|
||||
|
||||
inline ssize_t reverse_endianness_ssize_t(size_t value) {
|
||||
return (ssize_t)_byteswap_uint64((uint64_t)value);
|
||||
}
|
||||
|
||||
inline size_t reverse_endianness_size_t(ssize_t value) {
|
||||
return (size_t)_byteswap_uint64((uint64_t)value);
|
||||
}
|
||||
|
||||
inline size_t reverse_endianness_size_t(size_t value) {
|
||||
return (size_t)_byteswap_uint64((uint64_t)value);
|
||||
}
|
||||
|
||||
inline float_t reverse_endianness_float_t(float_t value) {
|
||||
uint32_t v = (uint32_t)_byteswap_ulong(*(uint32_t*)&value);
|
||||
return *(float_t*)&v;
|
||||
}
|
||||
|
||||
inline double_t reverse_endianness_double_t(double_t value) {
|
||||
uint64_t v = (uint64_t)_byteswap_uint64(*(uint64_t*)&value);
|
||||
return *(double_t*)&v;
|
||||
}
|
||||
|
||||
inline void printf_debug(const char* fmt, ...) {
|
||||
#ifdef DEBUG
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vprintf(fmt, args);
|
||||
va_end(args);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline constexpr size_t utf8_length(const char* s) {
|
||||
if (!s)
|
||||
return 0;
|
||||
|
||||
size_t len = 0;
|
||||
while (*s++)
|
||||
len++;
|
||||
return len;
|
||||
}
|
||||
|
||||
inline constexpr size_t utf16_length(const wchar_t* s) {
|
||||
if (!s)
|
||||
return 0;
|
||||
|
||||
size_t len = 0;
|
||||
while (*s++)
|
||||
len++;
|
||||
return len;
|
||||
}
|
||||
|
||||
inline constexpr bool utf8_check_for_ascii_only(const char* s) {
|
||||
char c = 0;
|
||||
while (c = *s++)
|
||||
if (c & 0x80)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline constexpr size_t utf8_to_utf16_length(const char* s) {
|
||||
if (!s)
|
||||
return 0;
|
||||
|
||||
uint32_t c = 0;
|
||||
size_t length = 0;
|
||||
size_t l = 0;
|
||||
|
||||
while (*s) {
|
||||
char t = *s++;
|
||||
if (!(t & 0x80)) {
|
||||
l = 0;
|
||||
length++;
|
||||
c = 0;
|
||||
continue;
|
||||
}
|
||||
else if ((t & 0xFC) == 0xF8)
|
||||
continue;
|
||||
else if ((t & 0xF8) == 0xF0) {
|
||||
c = t & 0x07;
|
||||
l = 3;
|
||||
}
|
||||
else if ((t & 0xF0) == 0xE0) {
|
||||
c = t & 0x0F;
|
||||
l = 2;
|
||||
}
|
||||
else if ((t & 0xE0) == 0xC0) {
|
||||
c = t & 0x1F;
|
||||
l = 1;
|
||||
}
|
||||
else if ((t & 0xC0) == 0x80) {
|
||||
c = (c << 6) | (t & 0x3F);
|
||||
l--;
|
||||
}
|
||||
|
||||
if (!l) {
|
||||
if (c <= 0xD7FF || (c >= 0xE000 && c <= 0xFFFF))
|
||||
length++;
|
||||
else if (c >= 0x10000 && c <= 0x10FFFF) {
|
||||
length++;
|
||||
length++;
|
||||
}
|
||||
c = 0;
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
inline constexpr size_t utf8_to_utf16_length(const char* s, size_t length) {
|
||||
if (!s || !length)
|
||||
return 0;
|
||||
|
||||
uint32_t c = 0;
|
||||
size_t _length = 0;
|
||||
size_t l = 0;
|
||||
|
||||
while (*s && length) {
|
||||
char t = *s++;
|
||||
length--;
|
||||
if (!(t & 0x80)) {
|
||||
l = 0;
|
||||
_length++;
|
||||
c = 0;
|
||||
continue;
|
||||
}
|
||||
else if ((t & 0xFC) == 0xF8)
|
||||
continue;
|
||||
else if ((t & 0xF8) == 0xF0) {
|
||||
c = t & 0x07;
|
||||
l = 3;
|
||||
}
|
||||
else if ((t & 0xF0) == 0xE0) {
|
||||
c = t & 0x0F;
|
||||
l = 2;
|
||||
}
|
||||
else if ((t & 0xE0) == 0xC0) {
|
||||
c = t & 0x1F;
|
||||
l = 1;
|
||||
}
|
||||
else if ((t & 0xC0) == 0x80) {
|
||||
c = (c << 6) | (t & 0x3F);
|
||||
l--;
|
||||
}
|
||||
|
||||
if (!l) {
|
||||
if (c <= 0xD7FF || (c >= 0xE000 && c <= 0xFFFF))
|
||||
_length++;
|
||||
else if (c >= 0x10000 && c <= 0x10FFFF) {
|
||||
_length++;
|
||||
_length++;
|
||||
}
|
||||
c = 0;
|
||||
}
|
||||
}
|
||||
return _length;
|
||||
}
|
||||
|
||||
inline constexpr size_t utf16_to_utf8_length(const wchar_t* s) {
|
||||
if (!s)
|
||||
return 0;
|
||||
|
||||
uint32_t c = 0;
|
||||
size_t length = 0;
|
||||
while (*s) {
|
||||
c = *s++;
|
||||
if ((c & 0xFC00) == 0xD800) {
|
||||
if (!*s)
|
||||
break;
|
||||
|
||||
wchar_t _c = *s++;
|
||||
if ((_c & 0xFC00) != 0xDC00)
|
||||
continue;
|
||||
|
||||
c &= 0x3FF;
|
||||
c <<= 10;
|
||||
c |= _c & 0x3FF;
|
||||
c += 0x10000;
|
||||
}
|
||||
else if ((c & 0xFC00) == 0xDC00)
|
||||
continue;
|
||||
|
||||
if (c <= 0x7F)
|
||||
length++;
|
||||
else if (c <= 0x7FF)
|
||||
length += 2;
|
||||
else if ((c >= 0x800 && c <= 0xD7FF) || (c >= 0xE000 && c <= 0xFFFF))
|
||||
length += 3;
|
||||
else if (c >= 0x10000 && c <= 0x10FFFF)
|
||||
length += 4;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
inline constexpr size_t utf16_to_utf8_length(const wchar_t* s, size_t length) {
|
||||
if (!s || !length)
|
||||
return 0;
|
||||
|
||||
uint32_t c = 0;
|
||||
size_t _length = 0;
|
||||
while (*s && length) {
|
||||
c = *s++;
|
||||
length--;
|
||||
if ((c & 0xFC00) == 0xD800) {
|
||||
if (!*s)
|
||||
break;
|
||||
|
||||
wchar_t _c = *s++;
|
||||
if ((_c & 0xFC00) != 0xDC00)
|
||||
continue;
|
||||
|
||||
c &= 0x3FF;
|
||||
c <<= 10;
|
||||
c |= _c & 0x3FF;
|
||||
c += 0x10000;
|
||||
}
|
||||
else if ((c & 0xFC00) == 0xDC00)
|
||||
continue;
|
||||
|
||||
if (c <= 0x7F)
|
||||
_length++;
|
||||
else if (c <= 0x7FF)
|
||||
_length += 2;
|
||||
else if ((c >= 0x800 && c <= 0xD7FF) || (c >= 0xE000 && c <= 0xFFFF))
|
||||
_length += 3;
|
||||
else if (c >= 0x10000 && c <= 0x10FFFF)
|
||||
_length += 4;
|
||||
}
|
||||
return _length;
|
||||
}
|
||||
|
||||
extern wchar_t* utf8_to_utf16(const char* s);
|
||||
extern wchar_t* utf8_to_utf16(const char* s, size_t length);
|
||||
extern char* utf16_to_utf8(const wchar_t* s);
|
||||
extern char* utf16_to_utf8(const wchar_t* s, size_t length);
|
||||
extern std::wstring utf8_to_utf16(const std::string& s);
|
||||
extern std::string utf16_to_utf8(const std::wstring& s);
|
||||
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "deflate.hpp"
|
||||
#include <libdeflate.h>
|
||||
|
||||
namespace deflate {
|
||||
static int32_t compress_static(struct libdeflate_compressor* c, const void* src, size_t src_length,
|
||||
void** dst, size_t* dst_length, int32_t compression_level, mode mode);
|
||||
static int32_t decompress_static(struct libdeflate_decompressor* d, const void* src, size_t src_length,
|
||||
void** dst, size_t* dst_length, mode mode);
|
||||
|
||||
int32_t compress(const void* src, size_t src_length, void** dst,
|
||||
size_t* dst_length, int32_t compression_level, mode mode) {
|
||||
if (!src_length)
|
||||
return -1;
|
||||
else if (!src)
|
||||
return -2;
|
||||
else if (!dst)
|
||||
return -3;
|
||||
else if (!dst_length)
|
||||
return -4;
|
||||
else if (mode < MODE_DEFLATE || mode > MODE_ZLIB)
|
||||
return -5;
|
||||
|
||||
struct libdeflate_compressor* c = libdeflate_alloc_compressor(compression_level);
|
||||
if (!c)
|
||||
return -5;
|
||||
|
||||
int32_t result = compress_static(c, src, src_length, dst, dst_length, compression_level, mode);
|
||||
libdeflate_free_compressor(c);
|
||||
return result >= 0 ? result : result - 0x10;
|
||||
}
|
||||
|
||||
int32_t compress_gzip(const void* src, size_t src_length, void** dst,
|
||||
size_t* dst_length, int32_t compression_level, const char* file_name) {
|
||||
if (!src_length)
|
||||
return -1;
|
||||
else if (!src)
|
||||
return -2;
|
||||
else if (!dst)
|
||||
return -3;
|
||||
else if (!dst_length)
|
||||
return -4;
|
||||
|
||||
struct libdeflate_compressor* c = libdeflate_alloc_compressor(compression_level);
|
||||
if (!c)
|
||||
return -5;
|
||||
|
||||
int32_t result = compress_static(c, src, src_length, dst, dst_length, compression_level, MODE_GZIP);
|
||||
libdeflate_free_compressor(c);
|
||||
if (result < 0)
|
||||
return result - 0x10;
|
||||
|
||||
size_t file_name_length = utf8_length(file_name);
|
||||
void* temp = force_malloc(*dst_length + file_name_length + 1);
|
||||
size_t t = (size_t)temp;
|
||||
size_t d = (size_t)*dst;
|
||||
memcpy((void*)t, (void*)d, 0x0A);
|
||||
memcpy((void*)(t + 0x0A), file_name, file_name_length + 1);
|
||||
memcpy((void*)(t + 0x0A + file_name_length + 1), (void*)(d + 0x0A), *dst_length - 0x0A);
|
||||
((uint8_t*)t)[0x03] |= 0x08;
|
||||
free(*dst);
|
||||
*dst = temp;
|
||||
*dst_length += file_name_length + 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t decompress(const void* src, size_t src_length, void** dst,
|
||||
size_t* dst_length, mode mode) {
|
||||
if (!src_length)
|
||||
return -1;
|
||||
else if (!src)
|
||||
return -2;
|
||||
else if (!dst)
|
||||
return -3;
|
||||
else if (!dst_length)
|
||||
return -4;
|
||||
else if (mode < MODE_DEFLATE || mode > MODE_ZLIB)
|
||||
return -5;
|
||||
|
||||
if (!*dst_length)
|
||||
*dst_length = 1;
|
||||
struct libdeflate_decompressor* d = libdeflate_alloc_decompressor();
|
||||
int32_t result = decompress_static(d, src, src_length, dst, dst_length, mode);
|
||||
libdeflate_free_decompressor(d);
|
||||
return result >= 0 ? result : result - 0x10;
|
||||
}
|
||||
|
||||
static int32_t compress_static(struct libdeflate_compressor* c, const void* src, size_t src_length,
|
||||
void** dst, size_t* dst_length, int32_t compression_level, mode mode) {
|
||||
size_t dst_max_length;
|
||||
switch (mode) {
|
||||
case MODE_GZIP:
|
||||
dst_max_length = libdeflate_gzip_compress_bound(c, src_length);
|
||||
break;
|
||||
case MODE_ZLIB:
|
||||
dst_max_length = libdeflate_zlib_compress_bound(c, src_length);
|
||||
break;
|
||||
default:
|
||||
dst_max_length = libdeflate_deflate_compress_bound(c, src_length);
|
||||
break;
|
||||
}
|
||||
|
||||
*dst = force_malloc(dst_max_length);
|
||||
if (!*dst)
|
||||
return -1;
|
||||
|
||||
size_t dst_act_length;
|
||||
switch (mode) {
|
||||
case MODE_GZIP:
|
||||
dst_act_length = libdeflate_gzip_compress(c, src, src_length, *dst, dst_max_length);
|
||||
break;
|
||||
case MODE_ZLIB:
|
||||
dst_act_length = libdeflate_zlib_compress(c, src, src_length, *dst, dst_max_length);
|
||||
break;
|
||||
default:
|
||||
dst_act_length = libdeflate_deflate_compress(c, src, src_length, *dst, dst_max_length);
|
||||
break;
|
||||
}
|
||||
|
||||
if (dst_act_length == dst_max_length) {
|
||||
*dst_length = dst_act_length;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* temp = force_malloc(dst_act_length);
|
||||
if (!temp) {
|
||||
free_def(*dst);
|
||||
return -2;
|
||||
}
|
||||
|
||||
memcpy(temp, *dst, dst_act_length);
|
||||
free_def(*dst);
|
||||
*dst = temp;
|
||||
*dst_length = dst_act_length;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t decompress_static(struct libdeflate_decompressor* d, const void* src, size_t src_length,
|
||||
void** dst, size_t* dst_length, mode mode) {
|
||||
*dst = force_malloc(*dst_length);
|
||||
if (!*dst)
|
||||
return -1;
|
||||
|
||||
size_t dst_act_length = 0;
|
||||
enum libdeflate_result result;
|
||||
switch (mode) {
|
||||
case MODE_GZIP:
|
||||
result = libdeflate_gzip_decompress(d, src, src_length, *dst, *dst_length, &dst_act_length);
|
||||
break;
|
||||
case MODE_ZLIB:
|
||||
result = libdeflate_zlib_decompress(d, src, src_length, *dst, *dst_length, &dst_act_length);
|
||||
break;
|
||||
default:
|
||||
result = libdeflate_deflate_decompress(d, src, src_length, *dst, *dst_length, &dst_act_length);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (result) {
|
||||
case LIBDEFLATE_BAD_DATA:
|
||||
free_def(*dst);
|
||||
return -2;
|
||||
break;
|
||||
case LIBDEFLATE_INSUFFICIENT_SPACE:
|
||||
free_def(*dst);
|
||||
*dst_length *= 2;
|
||||
decompress_static(d, src, src_length, dst, dst_length, mode);
|
||||
break;
|
||||
default:
|
||||
if (dst_act_length >= *dst_length)
|
||||
break;
|
||||
|
||||
void* temp = force_malloc(dst_act_length);
|
||||
if (!temp) {
|
||||
free_def(*dst);
|
||||
return -3;
|
||||
}
|
||||
|
||||
memcpy(temp, *dst, dst_act_length);
|
||||
free_def(*dst);
|
||||
*dst = temp;
|
||||
*dst_length = dst_act_length;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "default.hpp"
|
||||
|
||||
namespace deflate {
|
||||
enum mode {
|
||||
MODE_DEFLATE = 0,
|
||||
MODE_GZIP = 1,
|
||||
MODE_ZLIB = 2,
|
||||
};
|
||||
|
||||
extern int32_t compress(const void* src, size_t src_length, void** dst,
|
||||
size_t* dst_length, int32_t compression_level, mode mode);
|
||||
extern int32_t compress_gzip(const void* src, size_t src_length, void** dst,
|
||||
size_t* dst_length, int32_t compression_level, const char* file_name = 0);
|
||||
extern int32_t decompress(const void* src, size_t src_length, void** dst,
|
||||
size_t* dst_length, mode mode);
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "divafile.hpp"
|
||||
#include "io/file_stream.hpp"
|
||||
#include "aes.hpp"
|
||||
#include "str_utils.hpp"
|
||||
|
||||
namespace divafile {
|
||||
static const uint8_t key[] = {
|
||||
0x66, 0x69, 0x6C, 0x65, 0x20, 0x61, 0x63, 0x63,
|
||||
0x65, 0x73, 0x73, 0x20, 0x64, 0x65, 0x6E, 0x79
|
||||
};
|
||||
|
||||
void decrypt(const char* path) {
|
||||
wchar_t* file_buf = utf8_to_utf16(path);
|
||||
decrypt(file_buf);
|
||||
free_def(file_buf);
|
||||
}
|
||||
|
||||
void decrypt(const wchar_t* path) {
|
||||
wchar_t* file_temp = str_utils_add(path, L"_dec");
|
||||
file_stream s_enc;
|
||||
s_enc.open(path, L"rb");
|
||||
if (s_enc.check_not_null()) {
|
||||
uint64_t signature = s_enc.read_uint64_t();
|
||||
if (signature == 0x454C494641564944) {
|
||||
uint32_t stream_length = s_enc.read_uint32_t();
|
||||
uint32_t file_length = s_enc.read_uint32_t();
|
||||
void* data = force_malloc(stream_length);
|
||||
s_enc.read(data, stream_length);
|
||||
|
||||
aes128_ctx ctx;
|
||||
aes128_init_ctx(&ctx, key);
|
||||
aes128_ecb_decrypt_buffer(&ctx, (uint8_t*)data, stream_length);
|
||||
|
||||
file_stream s_dec;
|
||||
s_dec.open(file_temp, L"wb");
|
||||
s_dec.write(data, min_def(file_length, stream_length));
|
||||
free_def(data);
|
||||
}
|
||||
}
|
||||
free_def(file_temp);
|
||||
}
|
||||
|
||||
void decrypt(void* enc_data, void** dec_data, size_t* dec_size) {
|
||||
if (!enc_data || !dec_data || !dec_size)
|
||||
return;
|
||||
|
||||
*dec_data = 0;
|
||||
*dec_size = 0;
|
||||
|
||||
size_t d = (size_t)enc_data;
|
||||
|
||||
uint64_t signature = *(uint64_t*)d;
|
||||
if (signature != 0x454C494641564944)
|
||||
return;
|
||||
|
||||
uint32_t stream_length = *(uint32_t*)(d + 8);
|
||||
uint32_t file_length = *(uint32_t*)(d + 12);
|
||||
void* data = force_malloc(stream_length);
|
||||
memcpy(data, (void*)(d + 16), stream_length);
|
||||
|
||||
aes128_ctx ctx;
|
||||
aes128_init_ctx(&ctx, key);
|
||||
aes128_ecb_decrypt_buffer(&ctx, (uint8_t*)data, stream_length);
|
||||
|
||||
*dec_data = data;
|
||||
*dec_size = file_length;
|
||||
}
|
||||
|
||||
void decrypt(stream& enc, memory_stream& dec) {
|
||||
size_t pos = enc.get_position();
|
||||
uint64_t signature = enc.read_uint64_t();
|
||||
if (signature != 0x454C494641564944) {
|
||||
std::vector<uint8_t> data;
|
||||
enc.set_position(0, SEEK_SET);
|
||||
int64_t length = enc.get_length();
|
||||
data.resize(length);
|
||||
enc.read(data.data(), length);
|
||||
enc.set_position(pos, SEEK_SET);
|
||||
dec.open(data);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t stream_length = enc.read_uint32_t();
|
||||
uint32_t file_length = enc.read_uint32_t();
|
||||
void* data = force_malloc(stream_length);
|
||||
enc.read(data, stream_length);
|
||||
|
||||
aes128_ctx ctx;
|
||||
aes128_init_ctx(&ctx, key);
|
||||
aes128_ecb_decrypt_buffer(&ctx, (uint8_t*)data, stream_length);
|
||||
|
||||
dec.open(data, file_length);
|
||||
free_def(data);
|
||||
}
|
||||
|
||||
void encrypt(const char* path) {
|
||||
wchar_t* file_buf = utf8_to_utf16(path);
|
||||
encrypt(file_buf);
|
||||
free_def(file_buf);
|
||||
}
|
||||
|
||||
void encrypt(const wchar_t* path) {
|
||||
wchar_t* file_temp = str_utils_add(path, L"_enc");
|
||||
file_stream s_dec;
|
||||
s_dec.open(path, L"rb");
|
||||
if (s_dec.check_not_null()) {
|
||||
size_t len = s_dec.length;
|
||||
size_t len_align = align_val(len, 0x10);
|
||||
|
||||
void* data = force_malloc(len_align);
|
||||
s_dec.read(data, len);
|
||||
|
||||
aes128_ctx ctx;
|
||||
aes128_init_ctx(&ctx, key);
|
||||
aes128_ecb_encrypt_buffer(&ctx, (uint8_t*)data, len_align);
|
||||
|
||||
file_stream s_enc;
|
||||
s_enc.open(file_temp, L"wb");
|
||||
s_enc.write_uint64_t(0x454C494641564944);
|
||||
s_enc.write_uint32_t((uint32_t)len_align);
|
||||
s_enc.write_uint32_t((uint32_t)len);
|
||||
s_enc.write(data, len_align);
|
||||
free_def(data);
|
||||
}
|
||||
free_def(file_temp);
|
||||
}
|
||||
|
||||
void encrypt(void* dec_data, size_t dec_size, void** enc_data, size_t* enc_size) {
|
||||
if (!dec_data || !dec_size || !enc_data || !enc_size)
|
||||
return;
|
||||
|
||||
size_t len = dec_size;
|
||||
size_t len_align = align_val(len, 0x10);
|
||||
|
||||
void* data = force_malloc(len_align + 0x10);
|
||||
size_t d = (size_t)data;
|
||||
memcpy((void*)(d + 16), dec_data, len);
|
||||
|
||||
aes128_ctx ctx;
|
||||
aes128_init_ctx(&ctx, key);
|
||||
aes128_ecb_encrypt_buffer(&ctx, (uint8_t*)(d + 16), len_align);
|
||||
|
||||
*(uint64_t*)d = 0x454C494641564944;
|
||||
*(uint32_t*)(d + 8) = (uint32_t)len_align;
|
||||
*(uint32_t*)(d + 12) = (uint32_t)len;
|
||||
|
||||
*enc_data = data;
|
||||
*enc_size = len_align + 0x10;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "default.hpp"
|
||||
#include "io/memory_stream.hpp"
|
||||
|
||||
namespace divafile {
|
||||
extern void decrypt(const char* path);
|
||||
extern void decrypt(const wchar_t* path);
|
||||
extern void decrypt(void* enc_data, void** dec_data, size_t* dec_size);
|
||||
extern void decrypt(stream& enc, memory_stream& dec);
|
||||
extern void encrypt(const char* path);
|
||||
extern void encrypt(const wchar_t* path);
|
||||
extern void encrypt(void* dec_data, size_t dec_size, void** enc_data, size_t* enc_size);
|
||||
}
|
||||
@@ -1,300 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "enrs.hpp"
|
||||
|
||||
enum enrs_value_type {
|
||||
ENRS_VALUE_INT8 = 0x0,
|
||||
ENRS_VALUE_INT16 = 0x1,
|
||||
ENRS_VALUE_INT32 = 0x2,
|
||||
ENRS_VALUE_INVALID = 0x3,
|
||||
};
|
||||
|
||||
inline static bool enrs_length_get_size_type(uint32_t* length, size_t val);
|
||||
inline static bool enrs_length_get_size(uint32_t* length, size_t val);
|
||||
static bool enrs_read_packed_value(stream& s, uint32_t* val);
|
||||
static bool enrs_write_packed_value(stream& s, uint32_t val);
|
||||
static bool enrs_read_packed_value_type(stream& s, uint32_t* val, enrs_type* type);
|
||||
static bool enrs_write_packed_value_type(stream& s, uint32_t val, enrs_type type);
|
||||
|
||||
enrs_entry::enrs_entry(): offset(), count(), size(), repeat_count() {
|
||||
|
||||
}
|
||||
|
||||
enrs_entry::enrs_entry(uint32_t offset, uint32_t count, uint32_t size, uint32_t repeat_count) {
|
||||
this->offset = offset;
|
||||
this->count = count;
|
||||
this->size = size;
|
||||
this->repeat_count = repeat_count;
|
||||
}
|
||||
|
||||
enrs_entry::~enrs_entry() {
|
||||
|
||||
}
|
||||
|
||||
void enrs_entry::append(uint32_t skip_bytes, uint32_t repeat_count, enrs_type type) {
|
||||
sub.push_back({ skip_bytes, repeat_count, type });
|
||||
}
|
||||
|
||||
void enrs_entry::append(enrs_sub_entry&& data) {
|
||||
sub.push_back(data);
|
||||
}
|
||||
|
||||
enrs_entry& enrs_entry::operator=(const enrs_entry& ee) {
|
||||
offset = ee.offset;
|
||||
count = ee.count;
|
||||
size = ee.size;
|
||||
repeat_count = ee.repeat_count;
|
||||
sub.assign(ee.sub.begin(), ee.sub.end());
|
||||
return *this;
|
||||
}
|
||||
|
||||
enrs::enrs() {
|
||||
|
||||
}
|
||||
|
||||
enrs::~enrs() {
|
||||
|
||||
}
|
||||
|
||||
void enrs::apply(void* data) {
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
uint8_t* d = (uint8_t*)data;
|
||||
uint8_t* temp;
|
||||
for (enrs_entry& i : vec) {
|
||||
d += i.offset;
|
||||
for (size_t j = 0; j < i.repeat_count; j++) {
|
||||
temp = d + i.size * j;
|
||||
for (enrs_sub_entry& k : i.sub) {
|
||||
temp += k.skip_bytes;
|
||||
switch (k.type) {
|
||||
case ENRS_WORD:
|
||||
for (size_t l = k.repeat_count; l; l--) {
|
||||
*(uint16_t*)temp = reverse_endianness_uint16_t(*(uint16_t*)temp);
|
||||
temp += 2;
|
||||
}
|
||||
break;
|
||||
case ENRS_DWORD:
|
||||
for (size_t l = k.repeat_count; l; l--) {
|
||||
*(uint32_t*)temp = reverse_endianness_uint32_t(*(uint32_t*)temp);
|
||||
temp += 4;
|
||||
}
|
||||
break;
|
||||
case ENRS_QWORD:
|
||||
for (size_t l = k.repeat_count; l; l--) {
|
||||
*(uint64_t*)temp = reverse_endianness_uint64_t(*(uint64_t*)temp);
|
||||
temp += 8;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t enrs::length() {
|
||||
uint32_t l = 0x10;
|
||||
uint32_t o = 0;
|
||||
for (enrs_entry& i : vec) {
|
||||
uint32_t offset = i.offset;
|
||||
i.count = (uint32_t)i.sub.size();
|
||||
if (&i != vec.data() && (&i)[-1].count < 1) {
|
||||
o += (uint32_t)((size_t)(&i)[-1].size * (&i)[-1].repeat_count);
|
||||
if (i.count > 0) {
|
||||
offset += o;
|
||||
o = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (i.count < 1)
|
||||
continue;
|
||||
|
||||
if (enrs_length_get_size(&l, offset)
|
||||
|| enrs_length_get_size(&l, i.count)
|
||||
|| enrs_length_get_size(&l, i.size)
|
||||
|| enrs_length_get_size(&l, i.repeat_count))
|
||||
goto End;
|
||||
|
||||
if (i.repeat_count < 1 || i.count > 0x40000000)
|
||||
continue;
|
||||
|
||||
for (enrs_sub_entry& j : i.sub) {
|
||||
if (enrs_length_get_size_type(&l, j.skip_bytes)
|
||||
|| enrs_length_get_size(&l, j.repeat_count))
|
||||
goto End;
|
||||
}
|
||||
}
|
||||
End:
|
||||
l = align_val(l, 0x10);
|
||||
return l;
|
||||
}
|
||||
|
||||
void enrs::read(stream& s) {
|
||||
vec.clear();
|
||||
|
||||
s.read_uint32_t();
|
||||
size_t l = s.read_uint32_t();
|
||||
s.read_uint32_t();
|
||||
s.read_uint32_t();
|
||||
|
||||
vec.reserve(l);
|
||||
for (size_t i = 0; i < l; i++) {
|
||||
enrs_entry entry;
|
||||
if (enrs_read_packed_value(s, &entry.offset)
|
||||
|| enrs_read_packed_value(s, &entry.count)
|
||||
|| enrs_read_packed_value(s, &entry.size)
|
||||
|| enrs_read_packed_value(s, &entry.repeat_count))
|
||||
return;
|
||||
|
||||
if (!entry.count || !entry.repeat_count) {
|
||||
vec.push_back(entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
entry.sub.reserve(entry.count);
|
||||
for (size_t j = 0; j < entry.count; j++) {
|
||||
enrs_sub_entry sub_entry = {};
|
||||
if (enrs_read_packed_value_type(s, &sub_entry.skip_bytes, &sub_entry.type)
|
||||
|| enrs_read_packed_value(s, &sub_entry.repeat_count))
|
||||
return;
|
||||
entry.sub.push_back(sub_entry);
|
||||
}
|
||||
vec.push_back(entry);
|
||||
}
|
||||
}
|
||||
|
||||
void enrs::write(stream& s) {
|
||||
uint32_t o = 0;
|
||||
size_t length = enrs::length();
|
||||
s.write_uint32_t(0);
|
||||
s.write_uint32_t((uint32_t)vec.size());
|
||||
s.write_uint32_t(0);
|
||||
s.write_uint32_t(0);
|
||||
for (enrs_entry& i : vec) {
|
||||
uint32_t offset = i.offset;
|
||||
i.count = (uint32_t)i.sub.size();
|
||||
if (&i != vec.data() && (&i)[-1].count < 1) {
|
||||
o += (uint32_t)((size_t)(&i)[-1].size * (&i)[-1].repeat_count);
|
||||
if ((&i)->count > 0) {
|
||||
offset += o;
|
||||
o = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (i.count < 1)
|
||||
continue;
|
||||
|
||||
if (enrs_write_packed_value(s, offset)
|
||||
|| enrs_write_packed_value(s, i.count)
|
||||
|| enrs_write_packed_value(s, i.size)
|
||||
|| enrs_write_packed_value(s, i.repeat_count))
|
||||
goto End;
|
||||
|
||||
if (i.repeat_count < 1)
|
||||
continue;
|
||||
|
||||
for (enrs_sub_entry& j : i.sub)
|
||||
if (enrs_write_packed_value_type(s, j.skip_bytes, j.type)
|
||||
|| enrs_write_packed_value(s, j.repeat_count))
|
||||
goto End;
|
||||
}
|
||||
|
||||
End:
|
||||
s.align_write(0x10);
|
||||
}
|
||||
|
||||
enrs& enrs::operator=(const enrs& e) {
|
||||
vec.assign(e.vec.begin(), e.vec.end());
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline static bool enrs_length_get_size_type(uint32_t* length, size_t val) {
|
||||
*length += val < 0x10 ? 1 : val < 0x1000 ? 2 : val < 0x10000000 ? 4 : 1;
|
||||
return val >= 0x10000000;
|
||||
}
|
||||
|
||||
inline static bool enrs_length_get_size(uint32_t* length, size_t val) {
|
||||
if (!length)
|
||||
return true;
|
||||
|
||||
*length += val < 0x40 ? 1 : val < 0x4000 ? 2 : val < 0x40000000 ? 4 : 1;
|
||||
return val >= 0x40000000;
|
||||
}
|
||||
|
||||
static bool enrs_read_packed_value(stream& s, uint32_t* val) {
|
||||
*val = s.read_uint8_t();
|
||||
enrs_value_type value = (enrs_value_type)((*val >> 6) & 0x3);
|
||||
*val &= 0x3F;
|
||||
|
||||
if (value == ENRS_VALUE_INT32)
|
||||
*val = (((((*val << 8) | s.read_uint8_t()) << 8) | s.read_uint8_t()) << 8) | s.read_uint8_t();
|
||||
else if (value == ENRS_VALUE_INT16)
|
||||
*val = (*val << 8) | s.read_uint8_t();
|
||||
else if (value == ENRS_VALUE_INVALID) {
|
||||
*val = 0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool enrs_write_packed_value(stream& s, uint32_t val) {
|
||||
if (val < 0x40)
|
||||
s.write_uint8_t((uint8_t)((ENRS_VALUE_INT8 << 6) | (val & 0x3F)));
|
||||
else if (val < 0x4000) {
|
||||
s.write_uint8_t((uint8_t)((ENRS_VALUE_INT16 << 6) | ((val >> 8) & 0x3F)));
|
||||
s.write_uint8_t((uint8_t)val);
|
||||
}
|
||||
else if (val < 0x40000000) {
|
||||
s.write_uint8_t((uint8_t)((ENRS_VALUE_INT32 << 6) | ((val >> 24) & 0x3F)));
|
||||
s.write_uint8_t((uint8_t)(val >> 16));
|
||||
s.write_uint8_t((uint8_t)(val >> 8));
|
||||
s.write_uint8_t((uint8_t)val);
|
||||
}
|
||||
else {
|
||||
s.write_uint8_t(ENRS_VALUE_INVALID << 6);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool enrs_read_packed_value_type(stream& s, uint32_t* val, enrs_type* type) {
|
||||
*val = s.read_uint8_t();
|
||||
enrs_value_type value = (enrs_value_type)((*val >> 6) & 0x3);
|
||||
*type = (enrs_type)((*val >> 4) & 0x3);
|
||||
*val &= 0xF;
|
||||
|
||||
if (value == ENRS_VALUE_INT32)
|
||||
*val = (((((*val << 8) | s.read_uint8_t()) << 8) | s.read_uint8_t()) << 8) | s.read_uint8_t();
|
||||
else if (value == ENRS_VALUE_INT16)
|
||||
*val = (*val << 8) | s.read_uint8_t();
|
||||
else if (value == ENRS_VALUE_INVALID) {
|
||||
*val = 0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool enrs_write_packed_value_type(stream& s, uint32_t val, enrs_type type) {
|
||||
uint8_t t = ((uint8_t)type & 0x3) << 4;
|
||||
if (val < 0x10)
|
||||
s.write_uint8_t((uint8_t)((ENRS_VALUE_INT8 << 6) | t | (val & 0xF)));
|
||||
else if (val < 0x1000) {
|
||||
s.write_uint8_t((uint8_t)((ENRS_VALUE_INT16 << 6) | t | ((val >> 8) & 0xF)));
|
||||
s.write_uint8_t((uint8_t)val);
|
||||
}
|
||||
else if (val < 0x10000000) {
|
||||
s.write_uint8_t((uint8_t)((ENRS_VALUE_INT32 << 6) | t | ((val >> 24) & 0xF)));
|
||||
s.write_uint8_t((uint8_t)(val >> 16));
|
||||
s.write_uint8_t((uint8_t)(val >> 8));
|
||||
s.write_uint8_t((uint8_t)val);
|
||||
}
|
||||
else {
|
||||
s.write_uint8_t(ENRS_VALUE_INVALID << 6);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "../default.hpp"
|
||||
#include "../io/stream.hpp"
|
||||
|
||||
enum enrs_type {
|
||||
ENRS_WORD = 0x0,
|
||||
ENRS_DWORD = 0x1,
|
||||
ENRS_QWORD = 0x2,
|
||||
ENRS_INVALID = 0x3,
|
||||
};
|
||||
|
||||
struct enrs_sub_entry {
|
||||
uint32_t skip_bytes;
|
||||
uint32_t repeat_count;
|
||||
enrs_type type;
|
||||
};
|
||||
|
||||
struct enrs_entry {
|
||||
uint32_t offset;
|
||||
uint32_t count;
|
||||
uint32_t size;
|
||||
uint32_t repeat_count;
|
||||
std::vector<enrs_sub_entry> sub;
|
||||
|
||||
enrs_entry();
|
||||
enrs_entry(uint32_t offset, uint32_t count, uint32_t size, uint32_t repeat_count);
|
||||
~enrs_entry();
|
||||
|
||||
void append(uint32_t skip_bytes, uint32_t repeat_count, enrs_type type);
|
||||
void append(enrs_sub_entry&& data);
|
||||
|
||||
enrs_entry& operator=(const enrs_entry& ee);
|
||||
};
|
||||
|
||||
struct enrs {
|
||||
std::vector<enrs_entry> vec;
|
||||
|
||||
enrs();
|
||||
~enrs();
|
||||
|
||||
void apply(void* data);
|
||||
uint32_t length();
|
||||
void read(stream& s);
|
||||
void write(stream& s);
|
||||
|
||||
enrs& operator=(const enrs& e);
|
||||
};
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "header.hpp"
|
||||
|
||||
void f2_header_read(stream& s, f2_header* h) {
|
||||
memset(h, 0, sizeof(f2_header));
|
||||
|
||||
if (s.check_null())
|
||||
return;
|
||||
|
||||
s.read(h, 0x20);
|
||||
if (h->length == 0x40)
|
||||
s.read((uint8_t*)h + 0x20, 0x20);
|
||||
}
|
||||
|
||||
void f2_header_write(stream& s, f2_header* h, bool extended) {
|
||||
if (s.check_null())
|
||||
return;
|
||||
|
||||
h->length = extended ? 0x40 : 0x20;
|
||||
s.write(h, h->length);
|
||||
}
|
||||
|
||||
void f2_header_write_end_of_container(stream& s, uint32_t depth) {
|
||||
if (s.check_null())
|
||||
return;
|
||||
|
||||
f2_header h = {};
|
||||
h.signature = reverse_endianness_uint32_t('EOFC');
|
||||
h.length = 0x20;
|
||||
h.depth = depth;
|
||||
h.use_section_size = true;
|
||||
f2_header_write(s, &h, false);
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../default.hpp"
|
||||
#include "../io/stream.hpp"
|
||||
|
||||
struct f2_header {
|
||||
union {
|
||||
char signature_char[0x04]; // 0x00
|
||||
uint32_t signature; // 0x00
|
||||
};
|
||||
uint32_t data_size; // 0x04
|
||||
uint32_t length; // 0x08
|
||||
union { // 0x0C
|
||||
struct {
|
||||
uint32_t flags0 : 27;
|
||||
uint32_t use_big_endian : 1;
|
||||
uint32_t use_section_size : 1;
|
||||
uint32_t flags1 : 3;
|
||||
};
|
||||
uint32_t flags;
|
||||
};
|
||||
uint32_t depth; // 0x10
|
||||
uint32_t section_size; // 0x14
|
||||
uint32_t version; // 0x18
|
||||
uint32_t unknown0; // 0x1C
|
||||
uint32_t murmurhash; // 0x20
|
||||
uint32_t unknown1[3]; // 0x24
|
||||
uint32_t inner_signature; // 0x30
|
||||
uint32_t unknown2[3]; // 0x34
|
||||
};
|
||||
|
||||
extern void f2_header_read(stream& s, f2_header* h);
|
||||
extern void f2_header_write(stream& s, f2_header* h, bool extended);
|
||||
extern void f2_header_write_end_of_container(stream& s, uint32_t depth);
|
||||
@@ -1,211 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "pof.hpp"
|
||||
|
||||
enum pof_value_type {
|
||||
POF_VALUE_INVALID = 0x0,
|
||||
POF_VALUE_INT8 = 0x1,
|
||||
POF_VALUE_INT16 = 0x2,
|
||||
POF_VALUE_INT32 = 0x3,
|
||||
};
|
||||
|
||||
inline static bool pof_length_get_size(uint32_t* length, size_t val);
|
||||
static size_t pof_read_offsets_count(stream& s);
|
||||
inline static bool pof_write_packed_value(stream& s, size_t val);
|
||||
|
||||
pof::pof() : shift_x() {
|
||||
|
||||
}
|
||||
|
||||
pof::~pof() {
|
||||
|
||||
}
|
||||
|
||||
void pof::add(stream& s, int64_t offset) {
|
||||
vec.push_back(s.get_position() + offset);
|
||||
}
|
||||
|
||||
uint32_t pof::length() {
|
||||
uint32_t l = 4;
|
||||
size_t j = 0;
|
||||
uint8_t bit_shift = (uint8_t)(shift_x ? 3 : 2);
|
||||
size_t v = ((size_t)1 << bit_shift) - 1;
|
||||
|
||||
for (int64_t& i : vec) {
|
||||
size_t o = i;
|
||||
if (o & v)
|
||||
break;
|
||||
else if (&i != vec.data()) {
|
||||
size_t k = o - j;
|
||||
if (!k)
|
||||
continue;
|
||||
j = o;
|
||||
o = k;
|
||||
}
|
||||
else
|
||||
j = o;
|
||||
|
||||
if (pof_length_get_size(&l, o >> bit_shift))
|
||||
break;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
void pof::read(stream& s) {
|
||||
vec.clear();
|
||||
|
||||
size_t length = pof_read_offsets_count(s);
|
||||
|
||||
uint8_t bit_shift = (uint8_t)(shift_x ? 3 : 2);
|
||||
size_t l = s.read_uint32_t() - 4ULL;
|
||||
|
||||
vec.reserve(length);
|
||||
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
size_t offset = 0;
|
||||
while (i < l) {
|
||||
size_t v = s.read_uint8_t();
|
||||
pof_value_type value = (pof_value_type)((v >> 6) & 0x03);
|
||||
v &= 0x3F;
|
||||
|
||||
if (value == POF_VALUE_INT32) {
|
||||
v = (((((v << 8) | s.read_uint8_t()) << 8) | s.read_uint8_t()) << 8) | s.read_uint8_t();
|
||||
i += 3;
|
||||
}
|
||||
else if (value == POF_VALUE_INT16) {
|
||||
v = (v << 8) | s.read_uint8_t();
|
||||
i++;
|
||||
}
|
||||
else if (value == POF_VALUE_INVALID)
|
||||
break;
|
||||
|
||||
offset += v;
|
||||
vec.push_back(offset << bit_shift);
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
void pof::write(stream& s) {
|
||||
size_t j = 0;
|
||||
size_t o = 0;
|
||||
uint8_t bit_shift = (uint8_t)(shift_x ? 3 : 2);
|
||||
size_t v = ((size_t)1 << bit_shift) - 1;
|
||||
size_t l = length();
|
||||
if (shift_x)
|
||||
s.write_uint32_t((uint32_t)l);
|
||||
else
|
||||
s.write_uint32_t((uint32_t)align_val(l, 4));
|
||||
|
||||
for (int64_t& i : vec) {
|
||||
o = i;
|
||||
if (o & v) {
|
||||
pof_write_packed_value(s, 0x7FFFFFFF);
|
||||
break;
|
||||
}
|
||||
|
||||
size_t k = o - j;
|
||||
if (&i != vec.data() && !k)
|
||||
continue;
|
||||
j = o;
|
||||
o = k;
|
||||
|
||||
pof_write_packed_value(s, o >> bit_shift);
|
||||
}
|
||||
|
||||
size_t pos = s.get_position();
|
||||
for (size_t c = align_val(pos, 0x10) - pos; c > 0; c--)
|
||||
s.write_uint8_t(0);
|
||||
}
|
||||
|
||||
pof& pof::operator=(const pof& p) {
|
||||
vec.assign(p.vec.begin(), p.vec.end());
|
||||
shift_x = p.shift_x;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void io_write_offset_pof_add(stream& s, int64_t val,
|
||||
int32_t offset, bool is_x, pof* pof) {
|
||||
if (!is_x) {
|
||||
if (val)
|
||||
val += offset;
|
||||
pof->add(s, offset);
|
||||
s.write_int32_t_reverse_endianness((int32_t)val);
|
||||
}
|
||||
else {
|
||||
s.align_write(0x08);
|
||||
pof->add(s, 0);
|
||||
s.write_int64_t_reverse_endianness(val);
|
||||
}
|
||||
}
|
||||
|
||||
inline void io_write_offset_f2_pof_add(stream& s, int64_t val,
|
||||
int32_t offset, pof* pof) {
|
||||
if (val)
|
||||
val += offset;
|
||||
pof->add(s, offset);
|
||||
s.write_int32_t_reverse_endianness((int32_t)val);
|
||||
}
|
||||
|
||||
inline void io_write_offset_x_pof_add(stream& s, int64_t val, pof* pof) {
|
||||
s.align_write(0x08);
|
||||
pof->add(s, 0);
|
||||
s.write_int64_t_reverse_endianness(val);
|
||||
}
|
||||
|
||||
inline static bool pof_length_get_size(uint32_t* length, size_t val) {
|
||||
*length += val < 0x40 ? 1 : val < 0x4000 ? 2 : val < 0x40000000 ? 4 : 1;
|
||||
return val >= 0x40000000;
|
||||
}
|
||||
|
||||
static size_t pof_read_offsets_count(stream& s) {
|
||||
size_t pos = s.get_position();
|
||||
size_t i, j, l;
|
||||
pof_value_type val;
|
||||
|
||||
l = s.read_uint32_t() - 4ULL;
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (i < l) {
|
||||
val = (pof_value_type)((s.read_uint8_t() >> 6) & 0x03);
|
||||
if (val == POF_VALUE_INT32) {
|
||||
s.read_uint8_t();
|
||||
s.read_uint8_t();
|
||||
s.read_uint8_t();
|
||||
i += 3;
|
||||
}
|
||||
else if (val == POF_VALUE_INT16) {
|
||||
s.read_uint8_t();
|
||||
i++;
|
||||
}
|
||||
else if (val != POF_VALUE_INT8)
|
||||
break;
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
s.set_position( pos, SEEK_SET);
|
||||
return j;
|
||||
}
|
||||
|
||||
static bool pof_write_packed_value(stream& s, size_t val) {
|
||||
if (val < 0x40)
|
||||
s.write_uint8_t((uint8_t)((POF_VALUE_INT8 << 6) | (val & 0x3F)));
|
||||
else if (val < 0x4000) {
|
||||
s.write_uint8_t((uint8_t)((POF_VALUE_INT16 << 6) | ((val >> 8) & 0x3F)));
|
||||
s.write_uint8_t((uint8_t)val);
|
||||
}
|
||||
else if (val < 0x40000000) {
|
||||
s.write_uint8_t((uint8_t)((POF_VALUE_INT32 << 6) | ((val >> 24) & 0x3F)));
|
||||
s.write_uint8_t((uint8_t)(val >> 16));
|
||||
s.write_uint8_t((uint8_t)(val >> 8));
|
||||
s.write_uint8_t((uint8_t)val);
|
||||
}
|
||||
else {
|
||||
s.write_uint8_t(POF_VALUE_INVALID << 6);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "../default.hpp"
|
||||
#include "../io/stream.hpp"
|
||||
|
||||
struct pof {
|
||||
std::vector<int64_t> vec;
|
||||
bool shift_x;
|
||||
|
||||
pof();
|
||||
~pof();
|
||||
|
||||
void add(stream& s, int64_t offset);
|
||||
uint32_t length();
|
||||
void read(stream& s);
|
||||
void write(stream& s);
|
||||
|
||||
pof& operator=(const pof& p);
|
||||
};
|
||||
|
||||
extern void io_write_offset_pof_add(stream& s, int64_t val,
|
||||
int32_t offset, bool is_x, pof* pof);
|
||||
extern void io_write_offset_f2_pof_add(stream& s, int64_t val,
|
||||
int32_t offset, pof* pof);
|
||||
extern void io_write_offset_x_pof_add(stream& s, int64_t val, pof* pof);
|
||||
@@ -1,244 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "struct.hpp"
|
||||
#include "../io/file_stream.hpp"
|
||||
#include "../io/memory_stream.hpp"
|
||||
#include "../io/path.hpp"
|
||||
#include "../divafile.hpp"
|
||||
|
||||
static void f2_struct_read_data(stream& s, f2_struct* st, f2_header* h);
|
||||
static void f2_struct_write_inner(stream& s, f2_struct* st, uint32_t depth, bool use_depth, bool shift_x);
|
||||
static void f2_struct_get_length(f2_struct* s, bool shift_x);
|
||||
static void f2_struct_write_pof(stream& s, pof* pof, uint32_t depth, bool shift_x);
|
||||
static void f2_struct_write_enrs(stream& s, enrs* enrs, uint32_t depth);
|
||||
|
||||
f2_struct::f2_struct() : header() {
|
||||
|
||||
}
|
||||
|
||||
f2_struct::~f2_struct() {
|
||||
|
||||
}
|
||||
|
||||
void f2_struct::read(const char* path) {
|
||||
if (!path)
|
||||
return;
|
||||
|
||||
file_stream s;
|
||||
s.open(path, "rb");
|
||||
if (s.check_not_null()) {
|
||||
memory_stream ms;
|
||||
divafile::decrypt(s, ms);
|
||||
|
||||
f2_header h;
|
||||
f2_header_read(ms, &h);
|
||||
f2_struct_read_data(ms, this, &h);
|
||||
}
|
||||
}
|
||||
|
||||
void f2_struct::read(const wchar_t* path) {
|
||||
if (!path)
|
||||
return;
|
||||
|
||||
file_stream s;
|
||||
s.open(path, L"rb");
|
||||
if (s.check_not_null()) {
|
||||
memory_stream ms;
|
||||
divafile::decrypt(s, ms);
|
||||
|
||||
f2_header h;
|
||||
f2_header_read(ms, &h);
|
||||
f2_struct_read_data(ms, this, &h);
|
||||
}
|
||||
}
|
||||
|
||||
void f2_struct::read(const void* data, size_t size) {
|
||||
if (!data || !size)
|
||||
return;
|
||||
|
||||
memory_stream s;
|
||||
s.open(data, size);
|
||||
if (s.check_not_null()) {
|
||||
memory_stream ms;
|
||||
divafile::decrypt(s, ms);
|
||||
|
||||
f2_header h;
|
||||
f2_header_read(ms, &h);
|
||||
f2_struct_read_data(ms, this, &h);
|
||||
}
|
||||
}
|
||||
|
||||
void f2_struct::read(stream& s) {
|
||||
if (s.check_null())
|
||||
return;
|
||||
|
||||
memory_stream ms;
|
||||
divafile::decrypt(s, ms);
|
||||
|
||||
f2_header h;
|
||||
f2_header_read(ms, &h);
|
||||
f2_struct_read_data(ms, this, &h);
|
||||
}
|
||||
|
||||
void f2_struct::write(const char* path, bool use_depth, bool shift_x) {
|
||||
if (!path)
|
||||
return;
|
||||
|
||||
file_stream s;
|
||||
s.open(path, "wb");
|
||||
if (s.check_not_null()) {
|
||||
f2_struct_get_length(this, shift_x);
|
||||
f2_struct_write_inner(s, this, 0, use_depth, shift_x);
|
||||
}
|
||||
}
|
||||
|
||||
void f2_struct::write(const wchar_t* path, bool use_depth, bool shift_x) {
|
||||
if (!path)
|
||||
return;
|
||||
|
||||
file_stream s;
|
||||
s.open(path, L"wb");
|
||||
if (s.check_not_null()) {
|
||||
f2_struct_get_length(this, shift_x);
|
||||
f2_struct_write_inner(s, this, 0, use_depth, shift_x);
|
||||
}
|
||||
}
|
||||
|
||||
void f2_struct::write(void** data, size_t* size, bool use_depth, bool shift_x) {
|
||||
if (!data || !size)
|
||||
return;
|
||||
|
||||
f2_struct_get_length(this, shift_x);
|
||||
memory_stream s;
|
||||
s.open(0, header.data_size + 0x40ULL);
|
||||
f2_struct_write_inner(s, this, 0, use_depth, shift_x);
|
||||
|
||||
s.copy(data, size);
|
||||
}
|
||||
|
||||
void f2_struct::write(stream& s, bool use_depth, bool shift_x) {
|
||||
if (s.check_null())
|
||||
return;
|
||||
|
||||
f2_struct_get_length(this, shift_x);
|
||||
f2_struct_write_inner(s, this, 0, use_depth, shift_x);
|
||||
|
||||
}
|
||||
|
||||
static void f2_struct_get_length(f2_struct* s, bool shift_x) {
|
||||
bool has_pof = s->pof.vec.size() > 0 ? true : false;
|
||||
bool has_enrs = s->enrs.vec.size() > 0 ? true : false;
|
||||
bool has_sub_structs = s->sub_structs.size() > 0 ? true : false;
|
||||
|
||||
s->header.section_size = (uint32_t)s->data.size();
|
||||
|
||||
uint32_t l = s->header.section_size;
|
||||
if (has_enrs) {
|
||||
uint32_t len = s->enrs.length();
|
||||
l += 0x20 + align_val(len, 0x10);
|
||||
}
|
||||
|
||||
if (has_pof) {
|
||||
s->pof.shift_x = shift_x;
|
||||
uint32_t len = s->pof.length();
|
||||
l += 0x20 + align_val(len, 0x10);
|
||||
}
|
||||
|
||||
if (has_sub_structs) {
|
||||
for (f2_struct& i : s->sub_structs) {
|
||||
f2_struct_get_length(&i, shift_x);
|
||||
l += i.header.data_size;
|
||||
l += i.header.length;
|
||||
}
|
||||
l += 0x20;
|
||||
}
|
||||
|
||||
s->header.data_size = l;
|
||||
}
|
||||
|
||||
static void f2_struct_read_data(stream& s, f2_struct* st, f2_header* h) {
|
||||
uint32_t l = h->use_section_size ? h->section_size : h->data_size;
|
||||
uint32_t depth = h->depth;
|
||||
st->header = *h;
|
||||
if (l) {
|
||||
st->data.resize(l);
|
||||
s.read(st->data.data(), l);
|
||||
}
|
||||
|
||||
uint32_t sig;
|
||||
size_t length = (size_t)h->data_size - l;
|
||||
size_t position = 0;
|
||||
while (length > position) {
|
||||
f2_header_read(s, h);
|
||||
sig = reverse_endianness_uint32_t(h->signature);
|
||||
l = h->use_section_size ? h->section_size : h->data_size;
|
||||
position += (size_t)h->length + l;
|
||||
if (sig == 'EOFC')
|
||||
break;
|
||||
else if (sig == 'ENRS') {
|
||||
size_t pos = s.get_position();
|
||||
st->enrs.read(s);
|
||||
s.set_position(pos + l, SEEK_SET);
|
||||
}
|
||||
else if ((sig & 0xFFFFFFF0) == 'POF0') {
|
||||
size_t pos = s.get_position();
|
||||
st->pof.shift_x = sig == 'POF1';
|
||||
st->pof.read(s);
|
||||
s.set_position(pos + l, SEEK_SET);
|
||||
}
|
||||
else {
|
||||
st->sub_structs.push_back({});
|
||||
f2_struct_read_data(s, &st->sub_structs.back(), h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void f2_struct_write_inner(stream& s, f2_struct* st, uint32_t depth, bool use_depth, bool shift_x) {
|
||||
bool has_pof = st->pof.vec.size() > 0 ? true : false;
|
||||
bool has_enrs = st->enrs.vec.size() > 0 ? true : false;
|
||||
bool has_sub_structs = st->sub_structs.size() > 0 ? true : false;
|
||||
|
||||
st->header.depth = use_depth ? depth : 0;
|
||||
f2_header_write(s, &st->header, st->header.length == 0x40);
|
||||
if (st->data.size())
|
||||
s.write(st->data.data(), st->data.size());
|
||||
if (has_enrs)
|
||||
f2_struct_write_enrs(s, &st->enrs, use_depth ? depth + 1 : 0);
|
||||
if (has_pof)
|
||||
f2_struct_write_pof(s, &st->pof, use_depth ? depth + 1 : 0, shift_x);
|
||||
if (has_sub_structs) {
|
||||
for (f2_struct& i : st->sub_structs)
|
||||
f2_struct_write_inner(s, &i, depth + 1, use_depth, shift_x);
|
||||
f2_header_write_end_of_container(s, use_depth ? depth + 1 : 0);
|
||||
}
|
||||
if (!depth)
|
||||
f2_header_write_end_of_container(s, 0);
|
||||
}
|
||||
|
||||
static void f2_struct_write_pof(stream& s, pof* pof, uint32_t depth, bool shift_x) {
|
||||
pof->shift_x = shift_x;
|
||||
size_t len = pof->length();
|
||||
f2_header h = {};
|
||||
h.signature = shift_x ? reverse_endianness_uint32_t('POF1') : reverse_endianness_uint32_t('POF0');
|
||||
h.length = 0x20;
|
||||
h.depth = depth;
|
||||
h.use_section_size = true;
|
||||
h.data_size = h.section_size = (uint32_t)align_val(len, 0x10);
|
||||
f2_header_write(s, &h, false);
|
||||
pof->write(s);
|
||||
}
|
||||
|
||||
static void f2_struct_write_enrs(stream& s, enrs* enrs, uint32_t depth) {
|
||||
size_t len = enrs->length();
|
||||
f2_header h = {};
|
||||
h.signature = reverse_endianness_uint32_t('ENRS');
|
||||
h.length = 0x20;
|
||||
h.depth = depth;
|
||||
h.use_section_size = true;
|
||||
h.data_size = h.section_size = (uint32_t)align_val(len, 0x10);
|
||||
f2_header_write(s, &h, false);
|
||||
enrs->write(s);
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../default.hpp"
|
||||
#include "enrs.hpp"
|
||||
#include "header.hpp"
|
||||
#include "pof.hpp"
|
||||
|
||||
struct f2_struct;
|
||||
|
||||
struct f2_struct {
|
||||
f2_header header;
|
||||
std::vector<uint8_t> data;
|
||||
std::vector<f2_struct> sub_structs;
|
||||
|
||||
enrs enrs;
|
||||
pof pof;
|
||||
|
||||
f2_struct();
|
||||
~f2_struct();
|
||||
|
||||
void read(const char* path);
|
||||
void read(const wchar_t* path);
|
||||
void read(const void* data, size_t size);
|
||||
void read(stream& s);
|
||||
void write(const char* path, bool use_depth = true, bool shift_x = false);
|
||||
void write(const wchar_t* path, bool use_depth = true, bool shift_x = false);
|
||||
void write(void** data, size_t* size, bool use_depth = true, bool shift_x = false);
|
||||
void write(stream& s, bool use_depth = true, bool shift_x = false);
|
||||
};
|
||||
@@ -1,948 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "farc.hpp"
|
||||
#include "io/path.hpp"
|
||||
#include "io/file_stream.hpp"
|
||||
#include "io/memory_stream.hpp"
|
||||
#include "aes.hpp"
|
||||
#include "deflate.hpp"
|
||||
#include "hash.hpp"
|
||||
#include "str_utils.hpp"
|
||||
|
||||
static const uint8_t key[] = {
|
||||
0x70, 0x72, 0x6F, 0x6A, 0x65, 0x63, 0x74, 0x5F,
|
||||
0x64, 0x69, 0x76, 0x61, 0x2E, 0x62, 0x69, 0x6E,
|
||||
};
|
||||
|
||||
static const uint8_t key_ft[] = {
|
||||
0x13, 0x72, 0xD5, 0x7B, 0x6E, 0x9E, 0x31, 0xEB,
|
||||
0xA2, 0x39, 0xB8, 0x3C, 0x15, 0x57, 0xC6, 0xBB,
|
||||
};
|
||||
|
||||
static errno_t farc_get_files(farc* f);
|
||||
static void farc_pack_files(farc* f, stream& s, farc_signature signature, farc_flags flags, bool get_files = false);
|
||||
static errno_t farc_read_header(farc* f, stream& s);
|
||||
static void farc_unpack_files(farc* f, stream& s, bool save);
|
||||
static void farc_unpack_file(farc* f, farc_file* ff);
|
||||
static void farc_unpack_file(farc* f, stream& s, farc_file* ff,
|
||||
bool save = false, char* temp_path = 0, size_t dir_len = 0);
|
||||
static void farc_write_padding(farc* f, stream& s, size_t size, bool x = false);
|
||||
|
||||
farc::farc() : flags(), ft() {
|
||||
signature = FARC_FArC;
|
||||
compression_level = 12;
|
||||
alignment = 0x10;
|
||||
}
|
||||
|
||||
farc::~farc() {
|
||||
|
||||
}
|
||||
|
||||
farc_file* farc::add_file(const char* name) {
|
||||
if (!name)
|
||||
return 0;
|
||||
|
||||
uint64_t name_hash = hash_utf8_fnv1a64m(name, true);
|
||||
for (farc_file& i : files)
|
||||
if (hash_string_fnv1a64m(i.name, true) == name_hash)
|
||||
return &i;
|
||||
|
||||
size_t files_count = files.size();
|
||||
void** data_temp = new void* [files_count];
|
||||
void** data_comp_temp = new void* [files_count];
|
||||
if (!data_temp || !data_comp_temp) {
|
||||
if (data_temp)
|
||||
delete[] data_temp;
|
||||
if (data_comp_temp)
|
||||
delete[] data_comp_temp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < files_count; i++) {
|
||||
data_temp[i] = files[i].data;
|
||||
data_comp_temp[i] = files[i].data_compressed;
|
||||
files[i].data = 0;
|
||||
files[i].data_compressed = 0;
|
||||
}
|
||||
|
||||
files.push_back({});
|
||||
files.back().name.assign(name);
|
||||
|
||||
for (size_t i = 0; i < files_count; i++) {
|
||||
files[i].data = data_temp[i];
|
||||
files[i].data_compressed = data_comp_temp[i];
|
||||
data_temp[i] = 0;
|
||||
data_comp_temp[i] = 0;
|
||||
}
|
||||
|
||||
delete[] data_temp;
|
||||
delete[] data_comp_temp;
|
||||
|
||||
return &files.back();
|
||||
}
|
||||
|
||||
farc_file* farc::add_file(const wchar_t* name) {
|
||||
if (!name)
|
||||
return 0;
|
||||
|
||||
uint64_t name_hash = hash_utf16_fnv1a64m(name, true);
|
||||
for (farc_file& i : files)
|
||||
if (hash_string_fnv1a64m(i.name, true) == name_hash)
|
||||
return &i;
|
||||
|
||||
size_t files_count = files.size();
|
||||
void** data_temp = new void* [files_count];
|
||||
void** data_comp_temp = new void* [files_count];
|
||||
if (!data_temp || !data_comp_temp) {
|
||||
if (data_temp)
|
||||
delete[] data_temp;
|
||||
if (data_comp_temp)
|
||||
delete[] data_comp_temp;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < files_count; i++) {
|
||||
data_temp[i] = files[i].data;
|
||||
data_comp_temp[i] = files[i].data_compressed;
|
||||
files[i].data = 0;
|
||||
files[i].data_compressed = 0;
|
||||
}
|
||||
|
||||
files.push_back({});
|
||||
if (name) {
|
||||
char* name_temp = utf16_to_utf8(name);
|
||||
files.back().name.assign(name_temp);
|
||||
free_def(name_temp);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < files_count; i++) {
|
||||
files[i].data = data_temp[i];
|
||||
files[i].data_compressed = data_comp_temp[i];
|
||||
data_temp[i] = 0;
|
||||
data_comp_temp[i] = 0;
|
||||
}
|
||||
|
||||
delete[] data_temp;
|
||||
delete[] data_comp_temp;
|
||||
|
||||
return &files.back();
|
||||
}
|
||||
|
||||
const char* farc::get_file_name(uint32_t hash) {
|
||||
if (!hash || hash == hash_murmurhash_empty)
|
||||
return 0;
|
||||
|
||||
for (farc_file& i : files) {
|
||||
const char* l_str = i.name.c_str();
|
||||
const char* t = strrchr(l_str, '.');
|
||||
size_t l_len = i.name.size();
|
||||
if (t)
|
||||
l_len = t - l_str;
|
||||
|
||||
if (hash_murmurhash(l_str, l_len) == hash)
|
||||
return l_str;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t farc::get_file_size(const char* name) {
|
||||
if (!name)
|
||||
return 0;
|
||||
|
||||
uint64_t name_hash = hash_utf8_fnv1a64m(name, true);
|
||||
for (farc_file& i : files)
|
||||
if (hash_string_fnv1a64m(i.name, true) == name_hash)
|
||||
return i.size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t farc::get_file_size(const wchar_t* name) {
|
||||
if (!name)
|
||||
return 0;
|
||||
|
||||
uint64_t name_hash = hash_utf16_fnv1a64m(name, true);
|
||||
for (farc_file& i : files)
|
||||
if (hash_string_fnv1a64m(i.name, true) == name_hash)
|
||||
return i.size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t farc::get_file_size(uint32_t hash) {
|
||||
if (!hash || hash == hash_murmurhash_empty)
|
||||
return 0;
|
||||
|
||||
for (farc_file& i : files) {
|
||||
const char* l_str = i.name.c_str();
|
||||
const char* t = strrchr(l_str, '.');
|
||||
size_t l_len = i.name.size();
|
||||
if (t)
|
||||
l_len = t - l_str;
|
||||
|
||||
if (hash_murmurhash(l_str, l_len) == hash)
|
||||
return i.size;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool farc::has_file(const char* name) {
|
||||
if (!name)
|
||||
return false;
|
||||
|
||||
uint64_t name_hash = hash_utf8_fnv1a64m(name, true);
|
||||
for (farc_file& i : files)
|
||||
if (hash_string_fnv1a64m(i.name, true) == name_hash)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool farc::has_file(const wchar_t* name) {
|
||||
if (!name)
|
||||
return false;
|
||||
|
||||
uint64_t name_hash = hash_utf16_fnv1a64m(name, true);
|
||||
for (farc_file& i : files)
|
||||
if (hash_string_fnv1a64m(i.name, true) == name_hash)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool farc::has_file(uint32_t hash) {
|
||||
if (!hash || hash == hash_murmurhash_empty)
|
||||
return false;
|
||||
|
||||
for (farc_file& i : files) {
|
||||
const char* l_str = i.name.c_str();
|
||||
const char* t = strrchr(l_str, '.');
|
||||
size_t l_len = i.name.size();
|
||||
if (t)
|
||||
l_len = t - l_str;
|
||||
|
||||
if (hash_murmurhash(l_str, l_len) == hash)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void farc::read(const char* path, bool unpack, bool save) {
|
||||
if (!path)
|
||||
return;
|
||||
|
||||
wchar_t* path_buf = utf8_to_utf16(path);
|
||||
read(path_buf, unpack, save);
|
||||
free_def(path_buf);
|
||||
}
|
||||
|
||||
void farc::read(const wchar_t* path, bool unpack, bool save) {
|
||||
if (!path)
|
||||
return;
|
||||
|
||||
files.clear();
|
||||
|
||||
wchar_t full_path_buf[MAX_PATH];
|
||||
wchar_t* full_path = _wfullpath(full_path_buf, path, MAX_PATH);
|
||||
|
||||
if (!full_path)
|
||||
return;
|
||||
else if (!path_check_file_exists(full_path_buf))
|
||||
return;
|
||||
|
||||
char* dir_temp = utf16_to_utf8(full_path_buf);
|
||||
size_t dir_temp_len = utf8_length(dir_temp);
|
||||
file_path.assign(dir_temp, dir_temp_len);
|
||||
directory_path.assign(dir_temp, dir_temp_len);
|
||||
free_def(dir_temp);
|
||||
|
||||
const char* dot = strrchr(directory_path.c_str(), '.');
|
||||
if (dot)
|
||||
directory_path = directory_path.substr(0, dot - directory_path.c_str());
|
||||
|
||||
file_stream s;
|
||||
s.open(file_path.c_str(), "rb");
|
||||
if (s.check_not_null() && !farc_read_header(this, s) && unpack)
|
||||
farc_unpack_files(this, s, save);
|
||||
}
|
||||
|
||||
void farc::read(const void* data, size_t size, bool unpack) {
|
||||
if (!data || !size)
|
||||
return;
|
||||
|
||||
files.clear();
|
||||
file_path.clear();
|
||||
|
||||
directory_path.clear();
|
||||
|
||||
memory_stream s;
|
||||
s.open(data, size);
|
||||
if (!farc_read_header(this, s) && unpack)
|
||||
farc_unpack_files(this, s, false);
|
||||
}
|
||||
|
||||
farc_file* farc::read_file(const char* name) {
|
||||
if (!name)
|
||||
return 0;
|
||||
|
||||
uint64_t name_hash = hash_utf8_fnv1a64m(name, true);
|
||||
for (farc_file& i : files)
|
||||
if (hash_string_fnv1a64m(i.name, true) == name_hash) {
|
||||
farc_unpack_file(this, &i);
|
||||
return &i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
farc_file* farc::read_file(const wchar_t* name) {
|
||||
if (!name)
|
||||
return 0;
|
||||
|
||||
uint64_t name_hash = hash_utf16_fnv1a64m(name, true);
|
||||
for (farc_file& i : files)
|
||||
if (hash_string_fnv1a64m(i.name, true) == name_hash) {
|
||||
farc_unpack_file(this, &i);
|
||||
return &i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
farc_file* farc::read_file(uint32_t hash) {
|
||||
if (!hash || hash == hash_murmurhash_empty)
|
||||
return 0;
|
||||
|
||||
for (farc_file& i : files) {
|
||||
const char* l_str = i.name.c_str();
|
||||
const char* t = strrchr(l_str, '.');
|
||||
size_t l_len = i.name.size();
|
||||
if (t)
|
||||
l_len = t - l_str;
|
||||
|
||||
if (hash_murmurhash(l_str, l_len) == hash) {
|
||||
farc_unpack_file(this, &i);
|
||||
return &i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void farc::write(const char* path, farc_signature signature, farc_flags flags, bool get_files) {
|
||||
if (!path)
|
||||
return;
|
||||
|
||||
wchar_t* path_buf = utf8_to_utf16(path);
|
||||
write(path_buf, signature, flags, get_files);
|
||||
free_def(path_buf);
|
||||
}
|
||||
|
||||
void farc::write(const wchar_t* path, farc_signature signature, farc_flags flags, bool get_files) {
|
||||
if (!path)
|
||||
return;
|
||||
|
||||
if (get_files)
|
||||
files.clear();
|
||||
|
||||
wchar_t full_path_buf[MAX_PATH];
|
||||
wchar_t* full_path = _wfullpath(full_path_buf, path, MAX_PATH);
|
||||
|
||||
if (!full_path)
|
||||
return;
|
||||
else if (get_files && !path_check_directory_exists(full_path_buf))
|
||||
return;
|
||||
|
||||
char* dir_temp = utf16_to_utf8(full_path_buf);
|
||||
size_t dir_temp_len = utf8_length(dir_temp);
|
||||
directory_path.assign(dir_temp, dir_temp_len);
|
||||
file_path.assign(dir_temp, dir_temp_len);
|
||||
file_path.append(".farc", 5);
|
||||
free_def(dir_temp);
|
||||
|
||||
if (!get_files || (get_files && !farc_get_files(this))) {
|
||||
file_stream s;
|
||||
s.open(file_path.c_str(), "wb");
|
||||
if (s.check_not_null())
|
||||
farc_pack_files(this, s, signature, flags, get_files);
|
||||
}
|
||||
}
|
||||
|
||||
void farc::write(void** data, size_t* size, farc_signature signature, farc_flags flags) {
|
||||
if (!data || !size)
|
||||
return;
|
||||
|
||||
directory_path.clear();
|
||||
file_path.clear();
|
||||
|
||||
memory_stream s;
|
||||
s.open();
|
||||
farc_pack_files(this, s, signature, flags);
|
||||
}
|
||||
|
||||
bool farc::load_file(void* data, const char* path, const char* file, uint32_t hash) {
|
||||
size_t file_len = utf8_length(file);
|
||||
if (file_len < 5 || memcmp(&file[file_len - 5], ".farc", 6))
|
||||
return false;
|
||||
|
||||
size_t path_len = utf8_length(path);
|
||||
if (path_len + file_len + 2 > 0x1000)
|
||||
return false;
|
||||
|
||||
char buf[0x1000];
|
||||
memcpy(buf, path, path_len);
|
||||
memcpy(buf + path_len, file, file_len + 1);
|
||||
if (!path_check_file_exists(buf))
|
||||
return false;
|
||||
|
||||
farc* f = (farc*)data;
|
||||
f->read(buf, true, false);
|
||||
return !!f->files.size();
|
||||
}
|
||||
|
||||
static errno_t farc_get_files(farc* f) {
|
||||
f->files.clear();
|
||||
f->files.shrink_to_fit();
|
||||
|
||||
std::vector<std::string> files = path_get_files(f->directory_path.c_str());
|
||||
if (files.size() < 1)
|
||||
return -1;
|
||||
|
||||
f->files = std::vector<farc_file>(files.size());
|
||||
for (farc_file& i : f->files)
|
||||
i.name = files[&i - f->files.data()];
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void farc_pack_files(farc* f, stream& s, farc_signature signature, farc_flags flags, bool get_files) {
|
||||
bool plain = false;
|
||||
for (farc_file& i : f->files) {
|
||||
bool is_a3da = i.name.find(".a3da") == i.name.size() - 5;
|
||||
bool is_diva = i.name.find(".diva") == i.name.size() - 5;
|
||||
bool is_vag = i.name.find(".vag" ) == i.name.size() - 4;
|
||||
|
||||
if (is_a3da || is_diva || is_vag) {
|
||||
plain = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (plain)
|
||||
signature = FARC_FArc;
|
||||
|
||||
bool compressed = false;
|
||||
bool encrypted = false;
|
||||
switch (signature) {
|
||||
case FARC_FARC:
|
||||
f->flags = flags;
|
||||
compressed = !!(flags & FARC_GZIP);
|
||||
encrypted = !!(flags & FARC_AES);
|
||||
break;
|
||||
case FARC_FArC:
|
||||
f->flags = (farc_flags)0;
|
||||
compressed = true;
|
||||
break;
|
||||
default:
|
||||
f->flags = (farc_flags)0;
|
||||
break;
|
||||
}
|
||||
|
||||
size_t header_length = 0;
|
||||
switch (signature) {
|
||||
case FARC_FARC:
|
||||
header_length += sizeof(int32_t) * 5;
|
||||
break;
|
||||
default:
|
||||
header_length += sizeof(int32_t);
|
||||
break;
|
||||
}
|
||||
|
||||
if (signature == FARC_FArc)
|
||||
for (farc_file& i : f->files) {
|
||||
header_length += i.name.size() + 1;
|
||||
header_length += sizeof(int32_t) * 2;
|
||||
}
|
||||
else
|
||||
for (farc_file& i : f->files) {
|
||||
header_length += i.name.size() + 1;
|
||||
header_length += sizeof(int32_t) * 3;
|
||||
}
|
||||
|
||||
size_t align = header_length + 8;
|
||||
s.set_position(align_val(align, f->alignment), SEEK_SET);
|
||||
size_t dir_len = f->directory_path.size();
|
||||
|
||||
aes128_ctx ctx;
|
||||
if (signature == FARC_FARC)
|
||||
aes128_init_ctx(&ctx, key);
|
||||
|
||||
f->compression_level = clamp_def(f->compression_level, 0, 12);
|
||||
|
||||
if (get_files) {
|
||||
char* temp = force_malloc<char>(dir_len + 2 + MAX_PATH);
|
||||
memcpy(temp, f->directory_path.c_str(), sizeof(char) * dir_len);
|
||||
temp[dir_len] = '\\';
|
||||
for (farc_file& i : f->files) {
|
||||
if (i.name.size()) {
|
||||
memcpy(temp + dir_len + 1, i.name.c_str(), sizeof(char) * i.name.size());
|
||||
temp[dir_len + 1 + i.name.size()] = '\0';
|
||||
}
|
||||
|
||||
i.offset = s.get_position();
|
||||
i.size = 0;
|
||||
i.size_compressed = 0;
|
||||
free_def(i.data);
|
||||
free_def(i.data_compressed);
|
||||
i.compressed = false;
|
||||
i.encrypted = false;
|
||||
|
||||
file_stream s_t;
|
||||
s_t.open(temp, "rb");
|
||||
if (s_t.check_null())
|
||||
continue;
|
||||
|
||||
size_t file_len = s_t.get_length();
|
||||
|
||||
i.size = file_len;
|
||||
i.data = force_malloc(file_len);
|
||||
s_t.read(i.data, file_len);
|
||||
i.compressed = compressed;
|
||||
i.encrypted = encrypted;
|
||||
i.data_changed = false;
|
||||
}
|
||||
free_def(temp);
|
||||
}
|
||||
|
||||
for (farc_file& i : f->files) {
|
||||
i.offset = s.get_position();
|
||||
size_t file_len = i.size;
|
||||
|
||||
if (i.encrypted && encrypted) {
|
||||
void* t1;
|
||||
size_t t1_len;
|
||||
if (i.compressed && compressed) {
|
||||
if (!i.data_compressed || i.data_changed) {
|
||||
free_def(i.data_compressed);
|
||||
deflate::compress_gzip(i.data, file_len, &i.data_compressed,
|
||||
&i.size_compressed, f->compression_level, i.name.c_str());
|
||||
}
|
||||
t1 = i.data_compressed;
|
||||
t1_len = i.size_compressed;
|
||||
}
|
||||
else {
|
||||
i.compressed = false;
|
||||
free_def(i.data_compressed);
|
||||
t1 = i.data;
|
||||
t1_len = i.size;
|
||||
}
|
||||
|
||||
size_t t2_len = align_val(t1_len, f->alignment);
|
||||
uint8_t* t2 = (uint8_t*)force_malloc(t2_len);
|
||||
memcpy(t2, t1, t1_len);
|
||||
memset(t2 + t1_len, 0x78, t2_len - t1_len);
|
||||
|
||||
aes128_ecb_encrypt_buffer(&ctx, t2, t2_len);
|
||||
|
||||
s.write(t2, t2_len);
|
||||
free_def(t2);
|
||||
}
|
||||
else if (i.compressed && compressed) {
|
||||
i.encrypted = false;
|
||||
if (!i.data_compressed || i.data_changed) {
|
||||
free_def(i.data_compressed);
|
||||
deflate::compress_gzip(i.data, file_len, &i.data_compressed,
|
||||
&i.size_compressed, f->compression_level, i.name.c_str());
|
||||
}
|
||||
s.write(i.data_compressed, i.size_compressed);
|
||||
farc_write_padding(f, s, i.size_compressed, signature != FARC_FArc);
|
||||
}
|
||||
else {
|
||||
i.compressed = false;
|
||||
i.encrypted = false;
|
||||
free_def(i.data_compressed);
|
||||
s.write(i.data, file_len);
|
||||
farc_write_padding(f, s, i.size);
|
||||
}
|
||||
i.data_changed = false;
|
||||
}
|
||||
|
||||
s.set_position(0, SEEK_SET);
|
||||
switch (signature) {
|
||||
case FARC_FArc:
|
||||
default:
|
||||
s.write_uint32_t_reverse_endianness(FARC_FArc, true);
|
||||
s.write_uint32_t_reverse_endianness((int32_t)header_length, true);
|
||||
s.write_uint32_t_reverse_endianness(f->alignment, true);
|
||||
break;
|
||||
case FARC_FArC:
|
||||
s.write_uint32_t_reverse_endianness(FARC_FArC, true);
|
||||
s.write_uint32_t_reverse_endianness((int32_t)header_length, true);
|
||||
s.write_uint32_t_reverse_endianness(f->alignment, true);
|
||||
break;
|
||||
case FARC_FARC:
|
||||
s.write_uint32_t_reverse_endianness(FARC_FARC, true);
|
||||
s.write_uint32_t_reverse_endianness((int32_t)header_length, true);
|
||||
s.write_uint32_t_reverse_endianness(f->flags, true);
|
||||
s.write_uint32_t_reverse_endianness(0x00, true);
|
||||
s.write_uint32_t_reverse_endianness(f->alignment, true);
|
||||
s.write_uint32_t_reverse_endianness(0x00, true);
|
||||
s.write_uint32_t_reverse_endianness(0x00, true);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (signature) {
|
||||
case FARC_FArc:
|
||||
for (farc_file& i : f->files) {
|
||||
s.write_string_null_terminated(i.name);
|
||||
s.write_int32_t_reverse_endianness((int32_t)i.offset, true);
|
||||
s.write_int32_t_reverse_endianness((int32_t)i.size, true);
|
||||
}
|
||||
break;
|
||||
case FARC_FArC:
|
||||
for (farc_file& i : f->files) {
|
||||
s.write_string_null_terminated(i.name);
|
||||
s.write_int32_t_reverse_endianness((int32_t)i.offset, true);
|
||||
if (i.compressed) {
|
||||
s.write_int32_t_reverse_endianness((int32_t)i.size_compressed, true);
|
||||
s.write_int32_t_reverse_endianness((int32_t)i.size, true);
|
||||
}
|
||||
else {
|
||||
s.write_int32_t_reverse_endianness((int32_t)i.size, true);
|
||||
s.write_int32_t_reverse_endianness(0x00, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FARC_FARC:
|
||||
for (farc_file& i : f->files) {
|
||||
s.write_string_null_terminated(i.name);
|
||||
s.write_int32_t_reverse_endianness((int32_t)i.offset, true);
|
||||
if (i.compressed) {
|
||||
s.write_int32_t_reverse_endianness((int32_t)i.size_compressed, true);
|
||||
s.write_int32_t_reverse_endianness((int32_t)i.size, true);
|
||||
}
|
||||
else {
|
||||
s.write_int32_t_reverse_endianness((int32_t)i.size, true);
|
||||
s.write_int32_t_reverse_endianness(0x00, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
farc_write_padding(f, s, header_length + 0x08, signature != FARC_FArc);
|
||||
}
|
||||
|
||||
static errno_t farc_read_header(farc* f, stream& s) {
|
||||
if (!f || s.check_null())
|
||||
return -1;
|
||||
|
||||
s.set_position(0, SEEK_SET);
|
||||
f->signature = (farc_signature)s.read_uint32_t_reverse_endianness(true);
|
||||
switch (f->signature) {
|
||||
case FARC_FArc:
|
||||
case FARC_FArC:
|
||||
case FARC_FARC:
|
||||
break;
|
||||
default:
|
||||
return -2;
|
||||
}
|
||||
|
||||
f->ft = false;
|
||||
|
||||
uint32_t header_length = s.read_uint32_t_reverse_endianness(true);
|
||||
if (f->signature == FARC_FARC) {
|
||||
f->flags = (farc_flags)s.read_uint32_t_reverse_endianness(true);
|
||||
s.read_uint32_t();
|
||||
uint32_t alignment = s.read_uint32_t_reverse_endianness(true);
|
||||
bool modern = !!s.read_uint32_t_reverse_endianness(true);
|
||||
|
||||
// If alignment is way too big, then it might be part of IV
|
||||
f->ft = (f->flags & FARC_AES) && modern && alignment > 0x1000;
|
||||
s.set_position(0x10, SEEK_SET);
|
||||
header_length -= 0x08;
|
||||
}
|
||||
|
||||
f->files.clear();
|
||||
|
||||
uint8_t* d_t;
|
||||
uint8_t* dt;
|
||||
int32_t length = 0;
|
||||
|
||||
dt = d_t = force_malloc<uint8_t>(header_length);
|
||||
s.read(d_t, header_length);
|
||||
if (f->ft) {
|
||||
header_length -= 0x10;
|
||||
|
||||
aes128_ctx ctx;
|
||||
aes128_init_ctx_iv(&ctx, key_ft, dt);
|
||||
dt += 0x10;
|
||||
aes128_cbc_decrypt_buffer(&ctx, dt, header_length);
|
||||
|
||||
header_length -= ((uint8_t*)dt)[header_length - 1]; // PKCS7 Padding
|
||||
}
|
||||
|
||||
if (f->ft) {
|
||||
f->alignment = load_reverse_endianness_uint32_t((void*)dt);
|
||||
uint32_t files_count = load_reverse_endianness_uint32_t((void*)(dt + 8));
|
||||
uint32_t entry_size = load_reverse_endianness_uint32_t((void*)(dt + 12));
|
||||
dt += sizeof(uint32_t) * 4;
|
||||
|
||||
f->files.clear();
|
||||
f->files.reserve(files_count);
|
||||
while ((dt - d_t < header_length + 0x08LL) && files_count) {
|
||||
size_t length = 0;
|
||||
while (dt[length])
|
||||
length++;
|
||||
|
||||
farc_file ff;
|
||||
ff.name.assign((const char*)dt, length);
|
||||
dt += length + 1;
|
||||
ff.offset = (size_t)load_reverse_endianness_uint32_t((void*)dt);
|
||||
ff.size_compressed = (size_t)load_reverse_endianness_uint32_t((void*)(dt + 4));
|
||||
ff.size = (size_t)load_reverse_endianness_uint32_t((void*)(dt + 8));
|
||||
farc_flags flags = (farc_flags)load_reverse_endianness_uint32_t((void*)(dt + 12));
|
||||
|
||||
if (ff.size)
|
||||
ff.compressed = true;
|
||||
else {
|
||||
ff.size = ff.size_compressed;
|
||||
ff.size_compressed = 0;
|
||||
ff.compressed = false;
|
||||
}
|
||||
|
||||
ff.encrypted = ((f->flags | flags) & FARC_AES) != 0;
|
||||
f->files.push_back(ff);
|
||||
dt += entry_size;
|
||||
files_count--;
|
||||
}
|
||||
|
||||
free_def(d_t);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t entry_size;
|
||||
if (f->signature == FARC_FARC) {
|
||||
f->alignment = load_reverse_endianness_uint32_t((void*)dt);
|
||||
uint32_t entry_offset = load_reverse_endianness_uint32_t((void*)(dt + 4));
|
||||
uint32_t header_offset = load_reverse_endianness_uint32_t((void*)(dt + 8));
|
||||
dt += sizeof(uint32_t) * 3;
|
||||
|
||||
entry_size = sizeof(uint32_t) * 3 + entry_offset;
|
||||
}
|
||||
else if (f->signature != FARC_FArc) {
|
||||
f->alignment = load_reverse_endianness_uint32_t((void*)dt);
|
||||
dt += sizeof(uint32_t);
|
||||
|
||||
entry_size = sizeof(uint32_t) * 3;
|
||||
}
|
||||
else {
|
||||
f->alignment = load_reverse_endianness_uint32_t((void*)dt);
|
||||
dt += sizeof(uint32_t);
|
||||
|
||||
entry_size = sizeof(uint32_t) * 2;
|
||||
}
|
||||
|
||||
size_t count = 0;
|
||||
uint8_t* position = dt;
|
||||
|
||||
while (dt - d_t < header_length) {
|
||||
while (*dt++);
|
||||
dt += entry_size;
|
||||
count++;
|
||||
}
|
||||
dt = position;
|
||||
|
||||
bool encrypted = !!(f->flags & FARC_AES);
|
||||
|
||||
f->files.clear();
|
||||
f->files.resize(count);
|
||||
if (f->signature != FARC_FArc)
|
||||
for (farc_file& i : f->files) {
|
||||
size_t length = 0;
|
||||
while (dt[length])
|
||||
length++;
|
||||
i.name.assign((const char*)dt, length);
|
||||
dt += length + 1;
|
||||
i.offset = (size_t)load_reverse_endianness_uint32_t((void*)dt);
|
||||
i.size_compressed = (size_t)load_reverse_endianness_uint32_t((void*)(dt + 4));
|
||||
i.size = (size_t)load_reverse_endianness_uint32_t((void*)(dt + 8));
|
||||
|
||||
if (i.size)
|
||||
i.compressed = true;
|
||||
else {
|
||||
i.size = i.size_compressed;
|
||||
i.size_compressed = 0;
|
||||
i.compressed = false;
|
||||
}
|
||||
|
||||
i.encrypted = encrypted;
|
||||
dt += entry_size;
|
||||
}
|
||||
else
|
||||
for (farc_file& i : f->files) {
|
||||
size_t length = 0;
|
||||
while (dt[length])
|
||||
length++;
|
||||
i.name.assign((const char*)dt, length);
|
||||
dt += length + 1;
|
||||
i.offset = (size_t)load_reverse_endianness_uint32_t((void*)dt);
|
||||
i.size = (size_t)load_reverse_endianness_uint32_t((void*)(dt + 4));
|
||||
|
||||
i.size_compressed = 0;
|
||||
i.compressed = false;
|
||||
i.encrypted = false;
|
||||
dt += sizeof(int32_t) * 2;
|
||||
}
|
||||
|
||||
free_def(d_t);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void farc_unpack_files(farc* f, stream& s, bool save) {
|
||||
if (!f || s.check_null() || !f->files.size())
|
||||
return;
|
||||
|
||||
size_t max_path_len = 0;
|
||||
size_t dir_len = f->directory_path.size();
|
||||
for (farc_file& i : f->files) {
|
||||
size_t path_len = dir_len + 1 + utf8_to_utf16_length(i.name.c_str());
|
||||
if (max_path_len < path_len)
|
||||
max_path_len = path_len;
|
||||
}
|
||||
|
||||
if (save) {
|
||||
wchar_t* dir_temp = utf8_to_utf16(f->directory_path.c_str());
|
||||
CreateDirectoryW(dir_temp, 0);
|
||||
free_def(dir_temp);
|
||||
}
|
||||
|
||||
char* temp_path = force_malloc<char>(max_path_len + 1);
|
||||
memcpy(temp_path, f->directory_path.c_str(), sizeof(char) * dir_len);
|
||||
temp_path[dir_len] = '\\';
|
||||
|
||||
for (farc_file& i : f->files)
|
||||
farc_unpack_file(f, s, &i, save, temp_path, dir_len);
|
||||
|
||||
free_def(temp_path);
|
||||
}
|
||||
|
||||
static void farc_unpack_file(farc* f, farc_file* ff) {
|
||||
if (ff->data)
|
||||
return;
|
||||
else if (ff->data_compressed) {
|
||||
deflate::decompress(ff->data_compressed, ff->size_compressed,
|
||||
&ff->data, &ff->size, deflate::MODE_GZIP);
|
||||
return;
|
||||
}
|
||||
|
||||
file_stream s;
|
||||
s.open(f->file_path.c_str(), "rb");
|
||||
if (s.check_not_null())
|
||||
farc_unpack_file(f, s, ff);
|
||||
}
|
||||
|
||||
static void farc_unpack_file(farc* f, stream& s, farc_file* ff, bool save, char* temp_path, size_t dir_len) {
|
||||
if (!f || s.check_null())
|
||||
return;
|
||||
|
||||
if (ff->data)
|
||||
free_def(ff->data);
|
||||
|
||||
s.set_position(ff->offset, SEEK_SET);
|
||||
|
||||
if (f->signature == FARC_FArc) {
|
||||
ff->data_compressed = 0;
|
||||
ff->data = force_malloc(ff->size);
|
||||
s.read(ff->data, ff->size);
|
||||
}
|
||||
else if (f->signature == FARC_FArC) {
|
||||
if (ff->compressed) {
|
||||
ff->data_compressed = force_malloc(ff->size_compressed);
|
||||
s.read(ff->data_compressed, ff->size_compressed);
|
||||
deflate::decompress(ff->data_compressed, ff->size_compressed,
|
||||
&ff->data, &ff->size, deflate::MODE_GZIP);
|
||||
}
|
||||
else {
|
||||
ff->data = force_malloc(ff->size);
|
||||
s.read(ff->data, ff->size);
|
||||
}
|
||||
}
|
||||
else if (ff->compressed || ff->encrypted) {
|
||||
size_t temp_s = ff->compressed ? ff->size_compressed : ff->size;
|
||||
temp_s = ff->encrypted ? align_val(temp_s, f->alignment) : temp_s;
|
||||
void* temp = force_malloc(temp_s);
|
||||
s.read(temp, temp_s);
|
||||
|
||||
size_t t = (size_t)temp;
|
||||
if (ff->encrypted)
|
||||
if (f->ft) {
|
||||
temp_s -= 0x10;
|
||||
t += 0x10;
|
||||
|
||||
aes128_ctx ctx;
|
||||
aes128_init_ctx_iv(&ctx, key_ft, (uint8_t*)temp);
|
||||
aes128_cbc_decrypt_buffer(&ctx, (uint8_t*)t, temp_s);
|
||||
|
||||
ff->size_compressed = temp_s - ((uint8_t*)t)[temp_s - 1]; // PKCS7 Padding
|
||||
}
|
||||
else {
|
||||
aes128_ctx ctx;
|
||||
aes128_init_ctx(&ctx, key);
|
||||
aes128_ecb_decrypt_buffer(&ctx, (uint8_t*)t, temp_s);
|
||||
}
|
||||
|
||||
if (ff->compressed) {
|
||||
ff->data_compressed = force_malloc(ff->size_compressed);
|
||||
memcpy(ff->data_compressed, (void*)t, ff->size_compressed);
|
||||
deflate::decompress(ff->data_compressed, ff->size_compressed,
|
||||
&ff->data, &ff->size, deflate::MODE_GZIP);
|
||||
}
|
||||
else {
|
||||
ff->data_compressed = 0;
|
||||
ff->data = force_malloc(ff->size);
|
||||
memcpy(ff->data, (void*)t, ff->size);
|
||||
}
|
||||
free_def(temp);
|
||||
}
|
||||
else {
|
||||
ff->data_compressed = 0;
|
||||
ff->data = force_malloc(ff->size);
|
||||
s.read(ff->data, ff->size);
|
||||
}
|
||||
ff->data_changed = false;
|
||||
|
||||
if (!save)
|
||||
return;
|
||||
|
||||
if (ff->data) {
|
||||
if (ff->name.size()) {
|
||||
memcpy(temp_path + dir_len + 1, ff->name.c_str(), ff->name.size());
|
||||
temp_path[dir_len + 1 + ff->name.size()] = '\0';
|
||||
|
||||
file_stream temp_s;
|
||||
temp_s.open(temp_path, "wb");
|
||||
if (temp_s.check_not_null())
|
||||
temp_s.write(ff->data, ff->size);
|
||||
}
|
||||
|
||||
free(ff->data);
|
||||
ff->data = 0;
|
||||
}
|
||||
|
||||
if (ff->data_compressed) {
|
||||
free(ff->data_compressed);
|
||||
ff->data_compressed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void farc_write_padding(farc* f, stream& s, size_t size, bool x) {
|
||||
size_t align = align_val(size, f->alignment) - size;
|
||||
if (!x) {
|
||||
uint8_t padding[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
s.write(padding, align);
|
||||
}
|
||||
else {
|
||||
uint8_t padding[] = {
|
||||
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
|
||||
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
|
||||
};
|
||||
s.write(padding, align);
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "default.hpp"
|
||||
|
||||
enum farc_signature {
|
||||
FARC_FArc = 'FArc',
|
||||
FARC_FArC = 'FArC',
|
||||
FARC_FARC = 'FARC',
|
||||
};
|
||||
|
||||
enum farc_flags {
|
||||
FARC_NONE = 0x00,
|
||||
FARC_GZIP = 0x02,
|
||||
FARC_AES = 0x04,
|
||||
};
|
||||
|
||||
struct farc_file {
|
||||
std::string name;
|
||||
size_t offset;
|
||||
size_t size;
|
||||
size_t size_compressed;
|
||||
void* data;
|
||||
void* data_compressed;
|
||||
bool compressed;
|
||||
bool encrypted;
|
||||
bool data_changed;
|
||||
|
||||
inline farc_file() : offset(), size(), size_compressed(), data(),
|
||||
data_compressed(), compressed(), encrypted(), data_changed() {
|
||||
|
||||
}
|
||||
|
||||
inline ~farc_file() {
|
||||
if (data)
|
||||
free(data);
|
||||
if (data_compressed)
|
||||
free(data_compressed);
|
||||
}
|
||||
};
|
||||
|
||||
struct farc {
|
||||
std::string file_path;
|
||||
std::string directory_path;
|
||||
std::vector<farc_file> files;
|
||||
farc_signature signature;
|
||||
farc_flags flags;
|
||||
int32_t compression_level;
|
||||
uint32_t alignment;
|
||||
bool ft;
|
||||
|
||||
farc();
|
||||
~farc();
|
||||
|
||||
farc_file* add_file(const char* name);
|
||||
farc_file* add_file(const wchar_t* name);
|
||||
const char* get_file_name(uint32_t hash);
|
||||
size_t get_file_size(const char* name);
|
||||
size_t get_file_size(const wchar_t* name);
|
||||
size_t get_file_size(uint32_t hash);
|
||||
bool has_file(const char* name);
|
||||
bool has_file(const wchar_t* name);
|
||||
bool has_file(uint32_t hash);
|
||||
void read(const char* path, bool unpack = true, bool save = false);
|
||||
void read(const wchar_t* path, bool unpack = true, bool save = false);
|
||||
void read(const void* data, size_t size, bool unpack = true);
|
||||
farc_file* read_file(const char* name);
|
||||
farc_file* read_file(const wchar_t* name);
|
||||
farc_file* read_file(uint32_t hash);
|
||||
void write(const char* path, farc_signature signature = FARC_FArC,
|
||||
farc_flags flags = FARC_NONE, bool get_files = true);
|
||||
void write(const wchar_t* path, farc_signature signature = FARC_FArC,
|
||||
farc_flags flags = FARC_NONE, bool get_files = true);
|
||||
void write(void** data, size_t* size, farc_signature signature = FARC_FArC,
|
||||
farc_flags flags = FARC_NONE);
|
||||
|
||||
static bool load_file(void* data, const char* path, const char* file, uint32_t hash);
|
||||
};
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "half_t.hpp"
|
||||
|
||||
float_t half_to_float_convert(half_t h) {
|
||||
int32_t si32;
|
||||
uint16_t sign = (h >> 15) & 0x001;
|
||||
uint16_t exponent = (h >> 10) & 0x01F;
|
||||
uint16_t mantissa = h & 0x3FF;
|
||||
si32 = sign ? (int32_t)0x80000000 : 0x00000000;
|
||||
|
||||
if (exponent == 0x1F)
|
||||
si32 |= 0x7F800000;
|
||||
else if (exponent != 0x00)
|
||||
si32 |= ((int32_t)exponent - 0x0F + 0x7F) << 23;
|
||||
si32 |= (int32_t)mantissa << 13;
|
||||
return *(float_t*)&si32;
|
||||
}
|
||||
|
||||
half_t float_to_half_convert(float_t val) {
|
||||
int32_t si32 = *(int32_t*)&val;
|
||||
if (si32 == 0x00000000)
|
||||
return FLOAT16_POSITIVE_ZERO;
|
||||
else if ((uint64_t)si32 == 0x80000000)
|
||||
return FLOAT16_NEGATIVE_ZERO;
|
||||
|
||||
int16_t sign = (int16_t)((si32 >> 31) & 0x001);
|
||||
int16_t exponent = (int16_t)((si32 >> 23) & 0x0FF);
|
||||
int16_t mantissa = (int16_t)((si32 >> 13) & 0x3FF);
|
||||
|
||||
if (exponent == 0xFF)
|
||||
exponent = 0x1F;
|
||||
else if (exponent != 0x00) {
|
||||
exponent -= 0x7F - 0x0F;
|
||||
if (exponent < 0x00)
|
||||
exponent = mantissa = 0;
|
||||
else if (exponent >= 0x1F)
|
||||
exponent = 0x1F;
|
||||
}
|
||||
return (half_t)((sign << 15) | (exponent << 10) | mantissa);
|
||||
}
|
||||
|
||||
double_t half_to_double_convert(half_t h) {
|
||||
int64_t si64;
|
||||
uint16_t sign = (h >> 15) & 0x001;
|
||||
uint16_t exponent = (h >> 10) & 0x01F;
|
||||
uint16_t mantissa = h & 0x3FF;
|
||||
si64 = sign ? (int64_t)0x8000000000000000 : 0x0000000000000000;
|
||||
|
||||
if (exponent == 0x1F)
|
||||
si64 |= 0x7FF0000000000000;
|
||||
else if (exponent != 0x00)
|
||||
si64 |= ((int64_t)exponent - 0x0F + 0x3FF) << 52;
|
||||
si64 |= (int64_t)mantissa << 42;
|
||||
return *(double_t*)&si64;
|
||||
}
|
||||
|
||||
half_t double_to_half_convert(double_t val) {
|
||||
int64_t si64 = *(int64_t*)&val;
|
||||
if (si64 == 0x0000000000000000)
|
||||
return FLOAT16_POSITIVE_ZERO;
|
||||
else if ((uint64_t)si64 == 0x8000000000000000)
|
||||
return FLOAT16_NEGATIVE_ZERO;
|
||||
|
||||
int16_t sign = (int16_t)((si64 >> 63) & 0x001);
|
||||
int16_t exponent = (int16_t)((si64 >> 52) & 0x7FF);
|
||||
int16_t mantissa = (int16_t)((si64 >> 42) & 0x3FF);
|
||||
|
||||
if (exponent == 0x7FF)
|
||||
exponent = 0x1F;
|
||||
else if (exponent != 0x00) {
|
||||
exponent -= 0x3FF - 0x0F;
|
||||
if (exponent < 0x00)
|
||||
exponent = mantissa = 0;
|
||||
else if (exponent >= 0x1F)
|
||||
exponent = 0x1F;
|
||||
}
|
||||
return (half_t)((sign << 15) | (exponent << 10) | mantissa);
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "default.hpp"
|
||||
#include <immintrin.h>
|
||||
|
||||
#define FLOAT16_NAN ((half_t)0x7FFF)
|
||||
#define FLOAT16_POSITIVE_NAN ((half_t)0x7FFF)
|
||||
#define FLOAT16_NEGATIVE_NAN ((half_t)0xFFFF)
|
||||
#define FLOAT16_POSITIVE_ZERO ((half_t)0x0000)
|
||||
#define FLOAT16_NEGATIVE_ZERO ((half_t)0x8000)
|
||||
#define FLOAT16_POSITIVE_INF ((half_t)0x7C00)
|
||||
#define FLOAT16_NEGATIVE_INF ((half_t)0xFC00)
|
||||
|
||||
#define HALF_MAX 65504
|
||||
#define HALF_MIN 0.00006103515625
|
||||
|
||||
typedef unsigned short half_t;
|
||||
|
||||
inline half_t load_reverse_endianness_half_t(void* ptr) {
|
||||
return (half_t)_byteswap_ushort(*(uint16_t*)ptr);
|
||||
}
|
||||
|
||||
inline void store_reverse_endianness_half_t(void* ptr, half_t value) {
|
||||
*(half_t*)ptr = (half_t)_byteswap_ushort((uint16_t)value);
|
||||
}
|
||||
|
||||
inline half_t reverse_endianness_half_t(half_t value) {
|
||||
return (half_t)_byteswap_ushort((uint16_t)value);
|
||||
}
|
||||
|
||||
extern float_t half_to_float_convert(half_t h);
|
||||
extern half_t float_to_half_convert(float_t val);
|
||||
extern double_t half_to_double_convert(half_t h);
|
||||
extern half_t double_to_half_convert(double_t val);
|
||||
|
||||
inline float_t half_to_float(half_t h) {
|
||||
extern bool f16c;
|
||||
if (f16c)
|
||||
return _mm_cvtss_f32(_mm_cvtph_ps(_mm_cvtsi32_si128((uint16_t)h)));
|
||||
return half_to_float_convert(h);
|
||||
}
|
||||
|
||||
inline half_t float_to_half(float_t val) {
|
||||
extern bool f16c;
|
||||
if (f16c)
|
||||
return (half_t)_mm_cvtsi128_si32(_mm_cvtps_ph(_mm_load_ss(&val), _MM_FROUND_CUR_DIRECTION));
|
||||
return float_to_half_convert(val);
|
||||
}
|
||||
|
||||
inline double_t half_to_double(half_t h) {
|
||||
extern bool f16c;
|
||||
if (f16c)
|
||||
return _mm_cvtss_f32(_mm_cvtph_ps(_mm_cvtsi32_si128((uint16_t)h)));
|
||||
return half_to_double_convert(h);
|
||||
}
|
||||
|
||||
inline half_t double_to_half(double_t val) {
|
||||
extern bool f16c;
|
||||
if (f16c)
|
||||
return (half_t)_mm_cvtsi128_si32(_mm_cvtps_ph(_mm_cvtpd_ps(_mm_load_sd(&val)), _MM_FROUND_CUR_DIRECTION));
|
||||
return double_to_half_convert(val);
|
||||
}
|
||||
@@ -1,225 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "hash.hpp"
|
||||
|
||||
static const uint16_t hash_crc16_ccitt_table[] = {
|
||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
|
||||
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
|
||||
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
|
||||
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
|
||||
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
|
||||
0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
|
||||
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
|
||||
0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
|
||||
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
|
||||
0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
|
||||
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
|
||||
0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
|
||||
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
|
||||
0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
|
||||
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
|
||||
0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
|
||||
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
|
||||
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
|
||||
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
|
||||
0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
|
||||
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
|
||||
0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
||||
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
|
||||
0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
|
||||
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
|
||||
0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
|
||||
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
|
||||
0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
|
||||
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
|
||||
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
|
||||
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
|
||||
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0,
|
||||
};
|
||||
|
||||
// Empty string
|
||||
const uint64_t hash_fnv1a64m_empty = 0xCBF29CE44FD0BFC1;
|
||||
// Empty string
|
||||
const uint32_t hash_murmurhash_empty = 0x0CAD3078;
|
||||
// "NULL" string
|
||||
const uint32_t hash_murmurhash_null = 0x5A009B23;
|
||||
// Empty string
|
||||
const uint32_t hash_crc16_ccitt_empty = 0xFFFF;
|
||||
|
||||
// FNV 1a 64-bit Modified
|
||||
// 0x1403B04D0 in SBZV_7.10
|
||||
uint64_t hash_fnv1a64m(const void* data, size_t size, bool make_upper) {
|
||||
const uint8_t* d = (const uint8_t*)data;
|
||||
|
||||
uint64_t hash = 0xCBF29CE484222325;
|
||||
if (data)
|
||||
if (make_upper) // Hash text UPPERCASE
|
||||
for (size_t i = size; i; i--) {
|
||||
uint8_t c = *d++;
|
||||
if (c > 0x60 && c < 0x7B)
|
||||
c -= 0x20;
|
||||
hash ^= c;
|
||||
hash *= 0x100000001B3;
|
||||
}
|
||||
else
|
||||
for (size_t i = size; i; i--) {
|
||||
hash ^= *d++;
|
||||
hash *= 0x100000001B3;
|
||||
}
|
||||
return (hash >> 32) ^ hash; // Actual Modification
|
||||
}
|
||||
|
||||
// MurmurHash
|
||||
// 0x814D7A9C in PCSB00554
|
||||
// 0x8134C304 in PCSB01007
|
||||
// 0x0069CEA4 in NPEB02013
|
||||
uint32_t hash_murmurhash(const void* data, size_t size,
|
||||
uint32_t seed, bool upper, bool big_endian) {
|
||||
const uint8_t* d = (const uint8_t*)data;
|
||||
|
||||
uint32_t a = 0;
|
||||
uint32_t b = 0;
|
||||
uint32_t hash = 0;
|
||||
size_t i = 0;
|
||||
|
||||
const uint32_t m = 0x7FD652AD;
|
||||
const int32_t r = 16;
|
||||
|
||||
hash = seed + 0xDEADBEEF;
|
||||
if (d)
|
||||
if (upper) {
|
||||
if (big_endian)
|
||||
for (i = 0; size > 3; size -= 4, i += 4, d += 4) {
|
||||
b = load_reverse_endianness_uint32_t(d);
|
||||
hash += b;
|
||||
hash *= m;
|
||||
hash ^= hash >> r;
|
||||
}
|
||||
else
|
||||
for (i = 0; size > 3; size -= 4, i += 4, d += 4) {
|
||||
b = *(uint32_t*)d;
|
||||
hash += b;
|
||||
hash *= m;
|
||||
hash ^= hash >> r;
|
||||
}
|
||||
|
||||
if (size > 0) {
|
||||
if (size > 1) {
|
||||
if (size > 2)
|
||||
hash += (uint32_t)d[2] << 16;
|
||||
hash += (uint32_t)d[1] << 8;
|
||||
}
|
||||
hash += d[0];
|
||||
hash *= m;
|
||||
hash ^= hash >> r;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (big_endian)
|
||||
for (i = 0; size > 3; size -= 4, i += 4, d += 4) {
|
||||
b = load_reverse_endianness_uint32_t(d);
|
||||
|
||||
a = b & 0xFF;
|
||||
if (a > 0x60 && a < 0x7B)
|
||||
a -= 0x20;
|
||||
b = (b & 0xFFFFFF00) | a;
|
||||
|
||||
a = (b >> 8) & 0xFF;
|
||||
if (a > 0x60 && a < 0x7B)
|
||||
a -= 0x20;
|
||||
b = (b & 0xFFFF00FF) | (a << 8);
|
||||
|
||||
a = (b >> 16) & 0xFF;
|
||||
if (a > 0x60 && a < 0x7B)
|
||||
a -= 0x20;
|
||||
b = (b & 0xFF00FFFF) | (a << 16);
|
||||
|
||||
a = (b >> 24) & 0xFF;
|
||||
if (a > 0x60 && a < 0x7B)
|
||||
a -= 0x20;
|
||||
b = (b & 0x00FFFFFF) | (a << 24);
|
||||
|
||||
hash += b;
|
||||
hash *= m;
|
||||
hash ^= hash >> r;
|
||||
}
|
||||
else
|
||||
for (i = 0; size > 3; size -= 4, i += 4, d += 4) {
|
||||
b = *(uint32_t*)d;
|
||||
|
||||
a = b & 0xFF;
|
||||
if (a > 0x60 && a < 0x7B)
|
||||
a -= 0x20;
|
||||
b = (b & 0xFFFFFF00) | a;
|
||||
|
||||
a = (b >> 8) & 0xFF;
|
||||
if (a > 0x60 && a < 0x7B)
|
||||
a -= 0x20;
|
||||
b = (b & 0xFFFF00FF) | (a << 8);
|
||||
|
||||
a = (b >> 16) & 0xFF;
|
||||
if (a > 0x60 && a < 0x7B)
|
||||
a -= 0x20;
|
||||
b = (b & 0xFF00FFFF) | (a << 16);
|
||||
|
||||
a = (b >> 24) & 0xFF;
|
||||
if (a > 0x60 && a < 0x7B)
|
||||
a -= 0x20;
|
||||
b = (b & 0x00FFFFFF) | (a << 24);
|
||||
|
||||
hash += b;
|
||||
hash *= m;
|
||||
hash ^= hash >> r;
|
||||
}
|
||||
|
||||
switch (size) {
|
||||
case 3:
|
||||
b = d[2];
|
||||
if (b > 0x60 && b < 0x7B)
|
||||
b -= 0x20;
|
||||
hash += b << 16;
|
||||
case 2:
|
||||
b = d[1];
|
||||
if (b > 0x60 && b < 0x7B)
|
||||
b -= 0x20;
|
||||
hash += b << 8;
|
||||
case 1:
|
||||
b = d[0];
|
||||
if (b > 0x60 && b < 0x7B)
|
||||
b -= 0x20;
|
||||
hash += b;
|
||||
|
||||
hash *= m;
|
||||
hash ^= hash >> r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
hash *= m;
|
||||
hash ^= hash >> 10;
|
||||
hash *= m;
|
||||
hash ^= hash >> 17;
|
||||
return hash;
|
||||
}
|
||||
|
||||
// CRC16-CCITT
|
||||
// 0x140011A90 in SBZV_7.10
|
||||
uint16_t hash_crc16_ccitt(const void* data, size_t size, bool make_upper) {
|
||||
const uint8_t* d = (const uint8_t*)data;
|
||||
|
||||
uint16_t hash = 0xFFFF;
|
||||
if (make_upper) // Modification for only uppercase latin text
|
||||
for (size_t i = size; i; i--) {
|
||||
uint8_t a = *d++;
|
||||
if (a > 0x60 && a < 0x7B)
|
||||
a -= 0x20;
|
||||
hash = (uint16_t)(hash_crc16_ccitt_table[(hash >> 8) ^ a] ^ (hash << 8));
|
||||
}
|
||||
else
|
||||
for (size_t i = size; i; i--)
|
||||
hash = (uint16_t)(hash_crc16_ccitt_table[(hash >> 8) ^ *d++] ^ (hash << 8));
|
||||
return hash;
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "default.hpp"
|
||||
|
||||
// Empty string
|
||||
extern const uint64_t hash_fnv1a64m_empty;
|
||||
// Empty string
|
||||
extern const uint32_t hash_murmurhash_empty;
|
||||
// "NULL" string
|
||||
extern const uint32_t hash_murmurhash_null;
|
||||
// Empty string
|
||||
extern const uint32_t hash_crc16_ccitt_empty;
|
||||
|
||||
extern uint64_t hash_fnv1a64m(const void* data, size_t size, bool make_upper = false);
|
||||
extern uint32_t hash_murmurhash(const void* data, size_t size,
|
||||
uint32_t seed = 0, bool upper = false, bool big_endian = false);
|
||||
extern uint16_t hash_crc16_ccitt(const void* data, size_t size, bool make_upper = false);
|
||||
|
||||
inline uint64_t hash_utf8_fnv1a64m(const char* data, bool make_upper = false) {
|
||||
return hash_fnv1a64m(data, utf8_length(data), make_upper);
|
||||
}
|
||||
|
||||
inline uint64_t hash_utf16_fnv1a64m(const wchar_t* data, bool make_upper = false) {
|
||||
char* temp = utf16_to_utf8(data);
|
||||
uint64_t hash = hash_fnv1a64m(temp, utf8_length(temp), make_upper);
|
||||
free_def(temp);
|
||||
return hash;
|
||||
}
|
||||
|
||||
inline uint64_t hash_string_fnv1a64m(const std::string& data, bool make_upper = false) {
|
||||
return hash_fnv1a64m(data.c_str(), data.size(), make_upper);
|
||||
}
|
||||
|
||||
inline uint32_t hash_utf8_murmurhash(const char* data, uint32_t seed = 0, bool upper = false) {
|
||||
return hash_murmurhash(data, utf8_length(data), seed, upper);
|
||||
}
|
||||
|
||||
inline uint32_t hash_utf16_murmurhash(const wchar_t* data, uint32_t seed = 0, bool upper = false) {
|
||||
char* temp = utf16_to_utf8(data);
|
||||
uint32_t hash = hash_murmurhash(temp, utf8_length(temp), seed, upper);
|
||||
free_def(temp);
|
||||
return hash;
|
||||
}
|
||||
|
||||
inline uint32_t hash_string_murmurhash(const std::string& data, uint32_t seed = 0, bool upper = false) {
|
||||
return hash_murmurhash(data.c_str(), data.size(), seed, upper);
|
||||
}
|
||||
|
||||
inline uint16_t hash_utf8_crc16_ccitt(const char* data, bool make_upper = false) {
|
||||
return hash_crc16_ccitt(data, utf8_length(data), make_upper);
|
||||
}
|
||||
|
||||
inline uint16_t hash_utf16_crc16_ccitt(const wchar_t* data, bool make_upper = false) {
|
||||
char* temp = utf16_to_utf8(data);
|
||||
uint32_t hash = hash_crc16_ccitt(temp, utf8_length(temp), make_upper);
|
||||
free_def(temp);
|
||||
return hash;
|
||||
}
|
||||
|
||||
inline uint16_t hash_string_crc16_ccitt(const std::string& data, bool make_upper = false) {
|
||||
return hash_crc16_ccitt(data.c_str(), data.size(), make_upper);
|
||||
}
|
||||
|
||||
struct string_hash {
|
||||
std::string str;
|
||||
uint64_t hash_fnv1a64m;
|
||||
uint32_t hash_murmurhash;
|
||||
|
||||
inline string_hash() {
|
||||
hash_fnv1a64m = hash_fnv1a64m_empty;
|
||||
hash_murmurhash = hash_murmurhash_empty;
|
||||
}
|
||||
|
||||
inline string_hash(const char* str) {
|
||||
this->str.assign(str);
|
||||
this->hash_fnv1a64m = hash_string_fnv1a64m(this->str);
|
||||
this->hash_murmurhash = hash_string_murmurhash(this->str);
|
||||
}
|
||||
|
||||
inline string_hash(const char* str, size_t length) {
|
||||
this->str.assign(str, length);
|
||||
this->hash_fnv1a64m = hash_string_fnv1a64m(this->str);
|
||||
this->hash_murmurhash = hash_string_murmurhash(this->str);
|
||||
}
|
||||
|
||||
inline string_hash(const std::string& str) {
|
||||
this->str.assign(str);
|
||||
this->hash_fnv1a64m = hash_string_fnv1a64m(this->str);
|
||||
this->hash_murmurhash = hash_string_murmurhash(this->str);
|
||||
}
|
||||
|
||||
inline string_hash(const std::string&& str) {
|
||||
this->str.assign(str);
|
||||
this->hash_fnv1a64m = hash_string_fnv1a64m(this->str);
|
||||
this->hash_murmurhash = hash_string_murmurhash(this->str);
|
||||
}
|
||||
|
||||
inline ~string_hash() {
|
||||
|
||||
}
|
||||
|
||||
inline const char* c_str() const {
|
||||
return str.c_str();
|
||||
}
|
||||
|
||||
inline size_t size() const {
|
||||
return str.size();
|
||||
}
|
||||
|
||||
inline void append(const char* str) {
|
||||
this->str.append(str);
|
||||
this->hash_fnv1a64m = hash_string_fnv1a64m(this->str);
|
||||
this->hash_murmurhash = hash_string_murmurhash(this->str);
|
||||
}
|
||||
|
||||
inline void append(const char* str, size_t length) {
|
||||
this->str.append(str, length);
|
||||
this->hash_fnv1a64m = hash_string_fnv1a64m(this->str);
|
||||
this->hash_murmurhash = hash_string_murmurhash(this->str);
|
||||
}
|
||||
|
||||
inline void append(std::string& str) {
|
||||
this->str.append(str);
|
||||
this->hash_fnv1a64m = hash_string_fnv1a64m(this->str);
|
||||
this->hash_murmurhash = hash_string_murmurhash(this->str);
|
||||
}
|
||||
|
||||
inline void append(std::string&& str) {
|
||||
this->str.append(str);
|
||||
this->hash_fnv1a64m = hash_string_fnv1a64m(this->str);
|
||||
this->hash_murmurhash = hash_string_murmurhash(this->str);
|
||||
}
|
||||
|
||||
inline void append(string_hash& str) {
|
||||
this->str.append(str.str);
|
||||
this->hash_fnv1a64m = hash_string_fnv1a64m(this->str);
|
||||
this->hash_murmurhash = hash_string_murmurhash(this->str);
|
||||
}
|
||||
|
||||
inline void assign(const char* str) {
|
||||
this->str.assign(str);
|
||||
this->hash_fnv1a64m = hash_string_fnv1a64m(this->str);
|
||||
this->hash_murmurhash = hash_string_murmurhash(this->str);
|
||||
}
|
||||
|
||||
inline void assign(const char* str, size_t length) {
|
||||
this->str.assign(str, length);
|
||||
this->hash_fnv1a64m = hash_string_fnv1a64m(this->str);
|
||||
this->hash_murmurhash = hash_string_murmurhash(this->str);
|
||||
}
|
||||
|
||||
inline void assign(std::string& str) {
|
||||
this->str.assign(str);
|
||||
this->hash_fnv1a64m = hash_string_fnv1a64m(this->str);
|
||||
this->hash_murmurhash = hash_string_murmurhash(this->str);
|
||||
}
|
||||
|
||||
inline void assign(std::string&& str) {
|
||||
this->str.assign(str);
|
||||
this->hash_fnv1a64m = hash_string_fnv1a64m(this->str);
|
||||
this->hash_murmurhash = hash_string_murmurhash(this->str);
|
||||
}
|
||||
|
||||
inline void assign(string_hash& str) {
|
||||
this->str.assign(str.str);
|
||||
this->hash_fnv1a64m = hash_string_fnv1a64m(this->str);
|
||||
this->hash_murmurhash = hash_string_murmurhash(this->str);
|
||||
}
|
||||
|
||||
inline void clear() {
|
||||
str.clear();
|
||||
str.shrink_to_fit();
|
||||
hash_fnv1a64m = hash_fnv1a64m_empty;
|
||||
hash_murmurhash = hash_murmurhash_empty;
|
||||
}
|
||||
};
|
||||
|
||||
inline bool operator >(const string_hash& left, const string_hash& right) {
|
||||
return left.str.compare(right.str) > 0;
|
||||
}
|
||||
|
||||
inline bool operator <(const string_hash& left, const string_hash& right) {
|
||||
return left.str.compare(right.str) < 0;
|
||||
}
|
||||
|
||||
inline bool operator >=(const string_hash& left, const string_hash& right) {
|
||||
return left.str.compare(right.str) >= 0;
|
||||
}
|
||||
|
||||
inline bool operator <=(const string_hash& left, const string_hash& right) {
|
||||
return left.str.compare(right.str) <= 0;
|
||||
}
|
||||
|
||||
inline bool operator ==(const string_hash& left, const string_hash& right) {
|
||||
return !left.str.compare(right.str);
|
||||
}
|
||||
|
||||
inline bool operator !=(const string_hash& left, const string_hash& right) {
|
||||
return !!left.str.compare(right.str);
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "image.hpp"
|
||||
|
||||
static rgb565 rgb565_apply_color_tone(rgb565 col, const color_tone* col_tone);
|
||||
static void rgb_to_ycc(vec3& rgb, vec3& ycc);
|
||||
static void ycc_apply_col_tone_hue(vec3& ycc, const color_tone* col_tone);
|
||||
static void ycc_to_rgb(vec3& ycc, vec3& rgb);
|
||||
|
||||
color_tone::color_tone() : hue(), saturation(), value(), contrast(), inverse() {
|
||||
|
||||
}
|
||||
|
||||
void dxt1_image_apply_color_tone(int32_t width, int32_t height,
|
||||
int32_t size, dxt1_block* data, const color_tone* col_tone) {
|
||||
if (size <= 0)
|
||||
return;
|
||||
|
||||
for (size_t i = (size - 1ULL) / sizeof(dxt1_block) + 1; i; i--, data++) {
|
||||
data->color0 = rgb565_apply_color_tone(data->color0, col_tone);
|
||||
data->color1 = rgb565_apply_color_tone(data->color1, col_tone);
|
||||
if (*(uint16_t*)&data->color0 <= *(uint16_t*)&data->color1) {
|
||||
data->indices[0] &= ~((data->indices[0] >> 1) & 0x5555);
|
||||
data->indices[1] &= ~((data->indices[1] >> 1) & 0x5555);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dxt5_image_apply_color_tone(int32_t width, int32_t height,
|
||||
int32_t size, dxt5_block* data, const color_tone* col_tone) {
|
||||
if (size <= 0)
|
||||
return;
|
||||
|
||||
for (size_t i = (size - 1ULL) / sizeof(dxt5_block) + 1; i; i--, data++) {
|
||||
data->color0 = rgb565_apply_color_tone(data->color0, col_tone);
|
||||
data->color1 = rgb565_apply_color_tone(data->color1, col_tone);
|
||||
if (*(uint16_t*)&data->color0 <= *(uint16_t*)&data->color1) {
|
||||
data->color_indices[0] &= ~((data->color_indices[0] >> 1) & 0x5555);
|
||||
data->color_indices[1] &= ~((data->color_indices[1] >> 1) & 0x5555);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rgb565_image_apply_color_tone(int32_t width, int32_t height,
|
||||
int32_t size, rgb565* data, const color_tone* col_tone) {
|
||||
for (size_t i = (size - 1ULL) / sizeof(uint16_t) + 1; i; i--, data++)
|
||||
*data = rgb565_apply_color_tone(*data, col_tone);
|
||||
}
|
||||
|
||||
static rgb565 rgb565_apply_color_tone(rgb565 col, const color_tone* col_tone) {
|
||||
const vec3 scale = {
|
||||
(float_t)((1 << 5) - 1),
|
||||
(float_t)((1 << 6) - 1),
|
||||
(float_t)((1 << 5) - 1),
|
||||
};
|
||||
|
||||
const vec3 inv_scale = {
|
||||
(float_t)(1.0 / (double_t)((1 << 5) - 1)),
|
||||
(float_t)(1.0 / (double_t)((1 << 6) - 1)),
|
||||
(float_t)(1.0 / (double_t)((1 << 5) - 1)),
|
||||
};
|
||||
|
||||
vec3 rgb;
|
||||
if (col_tone->inverse) {
|
||||
rgb.x = (float_t)((1 << 5) - 1 - col.r);
|
||||
rgb.y = (float_t)((1 << 5) - 1 - col.g);
|
||||
rgb.z = (float_t)((1 << 5) - 1 - col.b);
|
||||
}
|
||||
else {
|
||||
rgb.x = (float_t)col.r;
|
||||
rgb.y = (float_t)col.g;
|
||||
rgb.z = (float_t)col.b;
|
||||
}
|
||||
|
||||
rgb = vec3::clamp(rgb * inv_scale * col_tone->blend + col_tone->offset, 0.0f, 1.0f);
|
||||
|
||||
vec3 ycc;
|
||||
rgb_to_ycc(rgb, ycc);
|
||||
|
||||
*(vec2*)&ycc.y = *(vec2*)&ycc.y * col_tone->saturation;
|
||||
ycc_apply_col_tone_hue(ycc, col_tone);
|
||||
ycc.x = (ycc.x + col_tone->value - 0.5f) * col_tone->contrast + 0.5f;
|
||||
ycc.x = clamp_def(ycc.x, 0.0f, 1.0f);
|
||||
*(vec2*)&ycc.y = vec2::clamp(*(vec2*)&ycc.y, -0.5f, 0.5f);
|
||||
|
||||
ycc_to_rgb(ycc, rgb);
|
||||
|
||||
rgb = vec3::clamp(rgb, 0.0f, 1.0f) * scale;
|
||||
|
||||
col.r = (uint8_t)rgb.x;
|
||||
col.g = (uint8_t)rgb.y;
|
||||
col.b = (uint8_t)rgb.z;
|
||||
return col;
|
||||
}
|
||||
|
||||
inline static void rgb_to_ycc(vec3& rgb, vec3& ycc) {
|
||||
const vec3 _y_coef_601 = { 0.29891f, 0.58661f, 0.11448f };
|
||||
const vec3 _cb_coef_601 = { -0.16874f, -0.33126f, 0.5f };
|
||||
const vec3 _cr_coef_601 = { 0.5f, -0.41869f, -0.08131f };
|
||||
|
||||
ycc.x = vec3::dot(rgb, _y_coef_601);
|
||||
ycc.y = vec3::dot(rgb, _cb_coef_601);
|
||||
ycc.z = vec3::dot(rgb, _cr_coef_601);
|
||||
}
|
||||
|
||||
inline static void ycc_apply_col_tone_hue(vec3& ycc, const color_tone* col_tone) {
|
||||
float_t hue = col_tone->hue * DEG_TO_RAD_FLOAT;
|
||||
float_t cos = cosf(hue);
|
||||
float_t sin = sinf(hue);
|
||||
ycc.y = ycc.y * cos + ycc.z * sin;
|
||||
ycc.z = ycc.z * cos - ycc.y * sin;
|
||||
}
|
||||
|
||||
inline static void ycc_to_rgb(vec3& ycc, vec3& rgb) {
|
||||
const vec3 _red_coef_601 = { 1.0f, 0.0f, 1.402f };
|
||||
const vec3 _grn_coef_601 = { 1.0f, -0.34414f, -0.71414f };
|
||||
const vec3 _blu_coef_601 = { 1.0f, 1.772f, 0.0f };
|
||||
|
||||
rgb.x = vec3::dot(ycc, _red_coef_601);
|
||||
rgb.y = vec3::dot(ycc, _grn_coef_601);
|
||||
rgb.z = vec3::dot(ycc, _blu_coef_601);
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "default.hpp"
|
||||
#include "vec.hpp"
|
||||
|
||||
struct color_tone {
|
||||
vec3 blend;
|
||||
vec3 offset;
|
||||
float_t hue;
|
||||
float_t saturation;
|
||||
float_t value;
|
||||
float_t contrast;
|
||||
bool inverse;
|
||||
|
||||
color_tone();
|
||||
};
|
||||
|
||||
struct rgb565 {
|
||||
uint16_t b : 5;
|
||||
uint16_t g : 6;
|
||||
uint16_t r : 5;
|
||||
};
|
||||
|
||||
struct dxt1_block {
|
||||
rgb565 color0;
|
||||
rgb565 color1;
|
||||
uint16_t indices[2];
|
||||
};
|
||||
|
||||
struct dxt5_block {
|
||||
uint8_t alpha0;
|
||||
uint8_t alpha1;
|
||||
uint8_t alpha_indices[6];
|
||||
rgb565 color0;
|
||||
rgb565 color1;
|
||||
uint16_t color_indices[2];
|
||||
};
|
||||
|
||||
extern void dxt1_image_apply_color_tone(int32_t width, int32_t height,
|
||||
int32_t size, dxt1_block* data, const color_tone* col_tone);
|
||||
extern void dxt5_image_apply_color_tone(int32_t width, int32_t height,
|
||||
int32_t size, dxt5_block* data, const color_tone* col_tone);
|
||||
extern void rgb565_image_apply_color_tone(int32_t width, int32_t height,
|
||||
int32_t size, rgb565* data, const color_tone* col_tone);
|
||||
@@ -1,381 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "interpolation.hpp"
|
||||
|
||||
void interpolate_chs_reverse_value(float_t* arr, size_t length,
|
||||
float_t& t1, float_t& t2, size_t f1, size_t f2, size_t f) {
|
||||
vec2 t = vec2(
|
||||
(float_t)(int64_t)(f - f1 + 0),
|
||||
(float_t)(int64_t)(f - f1 + 1)
|
||||
) / (float_t)(int64_t)(f2 - f1);
|
||||
vec2 t_2 = t * t;
|
||||
vec2 t_3 = t_2 * t;
|
||||
vec2 t_23 = 3.0f * t_2;
|
||||
vec2 t_32 = 2.0f * t_3;
|
||||
|
||||
vec2 h00 = t_32 - t_23 + 1.0f;
|
||||
vec2 h01 = t_23 - t_32;
|
||||
vec2 h10 = t_3 - 2.0f * t_2 + t;
|
||||
vec2 h11 = t_3 - t_2;
|
||||
|
||||
vec2 t1_t2 = *(vec2*)&arr[f] - h00 * arr[f1] - h01 * arr[f2];
|
||||
t1_t2 /= (t_2.x - t.x) * (t_2.y - t.y);
|
||||
|
||||
t1 = -h11.y * t1_t2.x + h11.x * t1_t2.y;
|
||||
t2 = h10.y * t1_t2.x - h10.x * t1_t2.y;
|
||||
}
|
||||
|
||||
void interpolate_chs_reverse_value(float_t* arr, size_t length, float_t& t1a, float_t& t2a,
|
||||
float_t& t1b, float_t& t2b, float_t& t1c, float_t& t2c, size_t f1, size_t f2, size_t f) {
|
||||
vec4 t = vec4(
|
||||
(float_t)(int64_t)(f - f1 + 0),
|
||||
(float_t)(int64_t)(f - f1 + 1),
|
||||
(float_t)(int64_t)(f - f1 + 2),
|
||||
(float_t)(int64_t)(f - f1 + 3)
|
||||
) / (float_t)(int64_t)(f2 - f1);
|
||||
vec4 t_2 = t * t;
|
||||
vec4 t_3 = t_2 * t;
|
||||
vec4 t_23 = 3.0f * t_2;
|
||||
vec4 t_32 = 2.0f * t_3;
|
||||
|
||||
vec4 h00 = t_32 - t_23 + 1.0f;
|
||||
vec4 h01 = t_23 - t_32;
|
||||
vec4 h10 = t_3 - 2.0f * t_2 + t;
|
||||
vec4 h11 = t_3 - t_2;
|
||||
|
||||
vec4 t1_t2 = *(vec4*)&arr[f] - h00 * arr[f1] - h01 * arr[f2];
|
||||
vec3 t_div = (*(vec3*)&t_2.x - *(vec3*)&t.x) * (*(vec3*)&t_2.y - *(vec3*)&t.y);
|
||||
vec2 t1_t2a = *(vec2*)&t1_t2.x / t_div.x;
|
||||
vec2 t1_t2b = *(vec2*)&t1_t2.y / t_div.y;
|
||||
vec2 t1_t2c = *(vec2*)&t1_t2.z / t_div.z;
|
||||
|
||||
t1a = -h11.y * t1_t2a.x + h11.x * t1_t2a.y;
|
||||
t2a = h10.y * t1_t2a.x - h10.x * t1_t2a.y;
|
||||
t1b = -h11.z * t1_t2b.x + h11.y * t1_t2b.y;
|
||||
t2b = h10.z * t1_t2b.x - h10.y * t1_t2b.y;
|
||||
t1c = -h11.w * t1_t2c.x + h11.z * t1_t2c.y;
|
||||
t2c = h10.w * t1_t2c.x - h10.z * t1_t2c.y;
|
||||
}
|
||||
|
||||
void interpolate_chs_reverse_value(double_t* arr, size_t length,
|
||||
double_t& t1, double_t& t2, size_t f1, size_t f2, size_t f) {
|
||||
vec2d t = vec2d(
|
||||
(double_t)(int64_t)(f - f1 + 0),
|
||||
(double_t)(int64_t)(f - f1 + 1)
|
||||
) / (double_t)(int64_t)(f2 - f1);
|
||||
vec2d t_2 = t * t;
|
||||
vec2d t_3 = t_2 * t;
|
||||
vec2d t_23 = 3.0 * t_2;
|
||||
vec2d t_32 = 2.0 * t_3;
|
||||
|
||||
vec2d h00 = t_32 - t_23 + 1.0;
|
||||
vec2d h01 = t_23 - t_32;
|
||||
vec2d h10 = t_3 - 2.0 * t_2 + t;
|
||||
vec2d h11 = t_3 - t_2;
|
||||
|
||||
vec2d t1_t2 = *(vec2d*)&arr[f] - h00 * arr[f1] - h01 * arr[f2];
|
||||
t1_t2 /= (t_2.x - t.x) * (t_2.y - t.y);
|
||||
|
||||
t1 = -h11.y * t1_t2.x + h11.x * t1_t2.y;
|
||||
t2 = h10.y * t1_t2.x - h10.x * t1_t2.y;
|
||||
}
|
||||
|
||||
void interpolate_chs_reverse(float_t* arr, size_t length,
|
||||
float_t& t1, float_t& t2, size_t f1, size_t f2) {
|
||||
t1 = 0.0f;
|
||||
t2 = 0.0f;
|
||||
|
||||
if (f2 - f1 - 2 < 1)
|
||||
return;
|
||||
|
||||
double_t tt1 = 0.0;
|
||||
double_t tt2 = 0.0;
|
||||
|
||||
size_t i = f1 + 1;
|
||||
for (; i < f2 - 1 && i + 3 <= f2 - 1; i += 3) {
|
||||
float_t t1a = 0.0f;
|
||||
float_t t2a = 0.0f;
|
||||
float_t t1b = 0.0f;
|
||||
float_t t2b = 0.0f;
|
||||
float_t t1c = 0.0f;
|
||||
float_t t2c = 0.0f;
|
||||
interpolate_chs_reverse_value(arr, length, t1a, t2a, t1b, t2b, t1c, t2c, f1, f2, i);
|
||||
tt1 += t1a;
|
||||
tt1 += t2a;
|
||||
tt1 += t1b;
|
||||
tt1 += t2b;
|
||||
tt1 += t1c;
|
||||
tt1 += t2c;
|
||||
}
|
||||
|
||||
for (; i < f2 - 1; i++) {
|
||||
float_t t1 = 0.0f;
|
||||
float_t t2 = 0.0f;
|
||||
interpolate_chs_reverse_value(arr, length, t1, t2, f1, f2, i);
|
||||
tt1 += t1;
|
||||
tt2 += t2;
|
||||
}
|
||||
|
||||
t1 = (float_t)(tt1 / (double_t)(f2 - f1 - 2));
|
||||
t2 = (float_t)(tt2 / (double_t)(f2 - f1 - 2));
|
||||
}
|
||||
|
||||
void interpolate_chs_reverse(double_t* arr, size_t length,
|
||||
double_t& t1, double_t& t2, size_t f1, size_t f2) {
|
||||
t1 = 0.0;
|
||||
t2 = 0.0;
|
||||
|
||||
if (f2 - f1 - 2 < 1)
|
||||
return;
|
||||
|
||||
double_t _t1 = 0.0;
|
||||
double_t _t2 = 0.0;
|
||||
double_t tt1 = 0.0;
|
||||
double_t tt2 = 0.0;
|
||||
for (size_t i = f1 + 1; i < f2 - 1; i++) {
|
||||
interpolate_chs_reverse_value(arr, length, _t1, _t2, f1, f2, i);
|
||||
tt1 += _t1;
|
||||
tt2 += _t2;
|
||||
}
|
||||
t1 = tt1 / (double_t)(f2 - f1 - 2);
|
||||
t2 = tt2 / (double_t)(f2 - f1 - 2);
|
||||
}
|
||||
|
||||
int32_t interpolate_chs_reverse_sequence(
|
||||
std::vector<float_t>& values_src, std::vector<kft3>& values, bool fast) {
|
||||
size_t count = values_src.size();
|
||||
if (!count)
|
||||
return 0;
|
||||
else if (count == 1) {
|
||||
if (values_src[0] != 0.0f) {
|
||||
values.push_back({ 0, values_src[0] });
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
float_t val = values_src.data()[0];
|
||||
float_t* arr = &values_src.data()[1];
|
||||
for (size_t i = count - 1; i; i--)
|
||||
if (val != *arr++)
|
||||
break;
|
||||
|
||||
if (arr == values_src.data() + count)
|
||||
if (values_src[0] != 0.0f) {
|
||||
values.push_back({ 0, values_src[0] });
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
float_t* arr = values_src.data();
|
||||
|
||||
const float_t reverse_bias = 0.0001f;
|
||||
const int32_t reverse_min_count = 4;
|
||||
|
||||
float_t* a = arr;
|
||||
size_t left_count = count;
|
||||
int32_t frame = 0;
|
||||
int32_t prev_frame = 0;
|
||||
float_t t2_old = 0.0f;
|
||||
while (left_count > 0) {
|
||||
if (left_count < reverse_min_count) {
|
||||
if (left_count > 1) {
|
||||
values.push_back({ (float_t)frame, a[0], t2_old, 0.0f });
|
||||
for (size_t j = 1; j < left_count - 1; j++)
|
||||
values.push_back({ (float_t)(int64_t)(frame + j), a[j] });
|
||||
t2_old = 0.0f;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
size_t i = 0;
|
||||
size_t i_prev = 0;
|
||||
float_t t1 = 0.0f;
|
||||
float_t t2 = 0.0f;
|
||||
float_t t1_prev = 0.0f;
|
||||
float_t t2_prev = 0.0f;
|
||||
bool has_prev_succeded = false;
|
||||
bool has_error = false;
|
||||
bool has_prev_error = false;
|
||||
bool constant_prev = false;
|
||||
|
||||
int32_t c = 0;
|
||||
for (i = reverse_min_count - 1, i_prev = i; i < left_count; i++) {
|
||||
bool constant = true;
|
||||
for (size_t j = 1; j <= i; j++)
|
||||
if (memcmp(&a[0], &a[j], sizeof(float_t))) {
|
||||
constant = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!fast) {
|
||||
double_t t1_accum = 0.0;
|
||||
double_t t2_accum = 0.0;
|
||||
|
||||
size_t j = 1;
|
||||
for (; j < i - 1 && j + 3 <= i - 1; j += 3) {
|
||||
float_t t1a = 0.0f;
|
||||
float_t t2a = 0.0f;
|
||||
float_t t1b = 0.0f;
|
||||
float_t t2b = 0.0f;
|
||||
float_t t1c = 0.0f;
|
||||
float_t t2c = 0.0f;
|
||||
interpolate_chs_reverse_value(a, left_count, t1a, t2a, t1b, t2b, t1c, t2c, 0, i, j);
|
||||
t1_accum += t1a;
|
||||
t2_accum += t2a;
|
||||
t1_accum += t1b;
|
||||
t2_accum += t2b;
|
||||
t1_accum += t1c;
|
||||
t2_accum += t2c;
|
||||
}
|
||||
|
||||
for (; j < i - 1; j++) {
|
||||
float_t t1 = 0.0f;
|
||||
float_t t2 = 0.0f;
|
||||
interpolate_chs_reverse_value(a, left_count, t1, t2, 0, i, j);
|
||||
t1_accum += t1;
|
||||
t2_accum += t2;
|
||||
}
|
||||
t1 = (float_t)(t1_accum / (double_t)(i - 2));
|
||||
t2 = (float_t)(t2_accum / (double_t)(i - 2));
|
||||
}
|
||||
else
|
||||
interpolate_chs_reverse_value(a, left_count, t1, t2, 0, i, 1);
|
||||
|
||||
has_error = false;
|
||||
for (size_t j = 1; j < i; j++) {
|
||||
float_t val = interpolate_chs_value(a[0], a[i], t1, t2, 0.0f, (float_t)i, (float_t)j);
|
||||
if (fabsf(val - a[j]) > reverse_bias) {
|
||||
has_error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fabsf(t1) > 0.5f || fabsf(t2) > 0.5f)
|
||||
has_error = true;
|
||||
|
||||
if (!has_error) {
|
||||
i_prev = i;
|
||||
t1_prev = t1;
|
||||
t2_prev = t2;
|
||||
constant_prev = constant;
|
||||
has_prev_error = false;
|
||||
has_prev_succeded = true;
|
||||
if (i < left_count)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (has_prev_succeded) {
|
||||
i = i_prev;
|
||||
t1 = t1_prev;
|
||||
t2 = t2_prev;
|
||||
constant = constant_prev;
|
||||
has_error = false;
|
||||
has_prev_succeded = false;
|
||||
}
|
||||
|
||||
if (!has_error) {
|
||||
if (constant) {
|
||||
t1 = 0.0f;
|
||||
t2 = 0.0f;
|
||||
}
|
||||
|
||||
c = (int32_t)i;
|
||||
values.push_back({ (float_t)frame, a[0], t2_old, t1 });
|
||||
t2_old = t2;
|
||||
has_prev_error = false;
|
||||
break;
|
||||
}
|
||||
|
||||
has_prev_error = true;
|
||||
}
|
||||
|
||||
if (has_prev_succeded) {
|
||||
if (has_error) {
|
||||
values.push_back({ (float_t)frame, a[0], t2_old, 0.0f });
|
||||
for (size_t j = 1; j < c; j++)
|
||||
values.push_back({ (float_t)(int64_t)(frame + j), a[j] });
|
||||
t2_old = 0.0f;
|
||||
}
|
||||
else {
|
||||
values.push_back({ (float_t)frame, a[0], t2_old, t1_prev });
|
||||
t2_old = t2_prev;
|
||||
}
|
||||
c = (int32_t)i;
|
||||
}
|
||||
else if (has_prev_error) {
|
||||
values.push_back({ (float_t)frame, a[0], t2_old, 0.0f });
|
||||
t2_old = 0.0f;
|
||||
c = 1;
|
||||
}
|
||||
|
||||
prev_frame = frame;
|
||||
frame += c;
|
||||
a += c;
|
||||
left_count -= c;
|
||||
}
|
||||
|
||||
values.push_back({ (float_t)(int64_t)(count - 1), arr[count - 1], t2_old, 0.0f });
|
||||
|
||||
if (values.size() > 2) {
|
||||
kft3* keys = values.data();
|
||||
size_t length = values.size();
|
||||
for (size_t i = 0; i < length - 3; i++)
|
||||
if (*(uint32_t*)&keys[i + 0].value == *(uint32_t*)&keys[i + 1].value
|
||||
&& *(uint32_t*)&keys[i + 1].value == *(uint32_t*)&keys[i + 2].value
|
||||
&& *(uint32_t*)&keys[i + 0].tangent2 == 0
|
||||
&& *(uint32_t*)&keys[i + 1].tangent1 == 0
|
||||
&& *(uint32_t*)&keys[i + 1].tangent2 == 0
|
||||
&& *(uint32_t*)&keys[i + 2].tangent1 == 0) {
|
||||
keys[i + 1].frame = keys[i + 2].frame;
|
||||
keys[i + 1].tangent2 = keys[i + 2].tangent2;
|
||||
values.erase(values.begin() + (i + 2));
|
||||
keys = values.data();
|
||||
length = values.size();
|
||||
if (length < 3)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
kft3* keys = values.data();
|
||||
size_t length = values.size();
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
float_t frame = (float_t)(int64_t)i;
|
||||
|
||||
kft3* first_key = keys;
|
||||
kft3* key = keys;
|
||||
size_t _length = length;
|
||||
size_t temp;
|
||||
while (_length > 0)
|
||||
if (frame < key[temp = _length / 2].frame)
|
||||
_length = temp;
|
||||
else {
|
||||
key += temp + 1;
|
||||
_length -= temp + 1;
|
||||
}
|
||||
|
||||
float_t val;
|
||||
if (key == first_key)
|
||||
val = first_key->value;
|
||||
else if (key == &first_key[length])
|
||||
val = key[-1].value;
|
||||
else
|
||||
val = interpolate_linear_value(key[-1].value, key[0].value,
|
||||
key[-1].frame, key[0].frame, frame);
|
||||
|
||||
if (fabsf(val - arr[i]) > reverse_bias)
|
||||
return 3;
|
||||
}
|
||||
|
||||
for (kft3& i : values) {
|
||||
i.tangent1 = 0.0f;
|
||||
i.tangent2 = 0.0f;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
@@ -1,348 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "default.hpp"
|
||||
#include "kf.hpp"
|
||||
#include "vec.hpp"
|
||||
#include <vector>
|
||||
|
||||
inline float_t interpolate_linear_value(const float_t p1, const float_t p2,
|
||||
const float_t f1, const float_t f2, const float_t f) {
|
||||
if (p1 == p2)
|
||||
return p1;
|
||||
|
||||
float_t t = (f - f1) / (f2 - f1);
|
||||
return (1.0f - t) * p1 + t * p2;
|
||||
}
|
||||
|
||||
inline vec2 interpolate_linear_value(const vec2 p1, const vec2 p2,
|
||||
const vec2 f1, const vec2 f2, const vec2 f) {
|
||||
if (p1 == p2)
|
||||
return p1;
|
||||
|
||||
__m128 _p1 = vec2::load_xmm(p1);
|
||||
__m128 _p2 = vec2::load_xmm(p2);
|
||||
__m128 _f1 = vec2::load_xmm(f1);
|
||||
__m128 _f2 = vec2::load_xmm(f2);
|
||||
__m128 _f = vec2::load_xmm(f);
|
||||
|
||||
const __m128 _1 = vec4::load_xmm(1.0f);
|
||||
|
||||
__m128 t = _mm_div_ps(_mm_sub_ps(_f, _f1), _mm_sub_ps(_f2, _f1));
|
||||
return vec2::store_xmm(_mm_add_ps(_mm_mul_ps(_p1, _mm_sub_ps(_1, t)), _mm_mul_ps(_p2, t)));
|
||||
}
|
||||
|
||||
inline vec3 interpolate_linear_value(const vec3 p1, const vec3 p2,
|
||||
const vec3 f1, const vec3 f2, const vec3 f) {
|
||||
if (p1 == p2)
|
||||
return p1;
|
||||
|
||||
__m128 _p1 = vec3::load_xmm(p1);
|
||||
__m128 _p2 = vec3::load_xmm(p2);
|
||||
__m128 _f1 = vec3::load_xmm(f1);
|
||||
__m128 _f2 = vec3::load_xmm(f2);
|
||||
__m128 _f = vec3::load_xmm(f);
|
||||
|
||||
const __m128 _1 = vec4::load_xmm(1.0f);
|
||||
|
||||
__m128 t = _mm_div_ps(_mm_sub_ps(_f, _f1), _mm_sub_ps(_f2, _f1));
|
||||
return vec3::store_xmm(_mm_add_ps(_mm_mul_ps(_p1, _mm_sub_ps(_1, t)), _mm_mul_ps(_p2, t)));
|
||||
}
|
||||
|
||||
inline vec4 interpolate_linear_value(const vec4 p1, const vec4 p2,
|
||||
const vec4 f1, const vec4 f2, const vec4 f) {
|
||||
if (p1 == p2)
|
||||
return p1;
|
||||
|
||||
__m128 _p1 = vec4::load_xmm(p1);
|
||||
__m128 _p2 = vec4::load_xmm(p2);
|
||||
__m128 _f1 = vec4::load_xmm(f1);
|
||||
__m128 _f2 = vec4::load_xmm(f2);
|
||||
__m128 _f = vec4::load_xmm(f);
|
||||
|
||||
const __m128 _1 = vec4::load_xmm(1.0f);
|
||||
|
||||
__m128 t = _mm_div_ps(_mm_sub_ps(_f, _f1), _mm_sub_ps(_f2, _f1));
|
||||
return vec4::store_xmm(_mm_add_ps(_mm_mul_ps(_p1, _mm_sub_ps(_1, t)), _mm_mul_ps(_p2, t)));
|
||||
}
|
||||
|
||||
inline std::vector<float_t> interpolate_linear(float_t p1, float_t p2, size_t f1, size_t f2) {
|
||||
size_t length = f2 - f1 + 1;
|
||||
if (p1 == p2)
|
||||
return std::vector<float_t>(length, p1);
|
||||
|
||||
std::vector<float_t> arr(length);
|
||||
float_t* a = arr.data();
|
||||
for (size_t i = 0, j = length; j; i++, j--, a++)
|
||||
*a = interpolate_linear_value(p1, p2,
|
||||
(float_t)f1, (float_t)f2, (float_t)(f1 + i));
|
||||
return arr;
|
||||
}
|
||||
|
||||
inline double_t interpolate_linear_value(const double_t p1, const double_t p2,
|
||||
const double_t f1, const double_t f2, const double_t f) {
|
||||
if (p1 == p2)
|
||||
return p1;
|
||||
|
||||
double_t t = (f - f1) / (f2 - f1);
|
||||
return (1.0 - t) * p1 + t * p2;
|
||||
}
|
||||
|
||||
inline vec2d interpolate_linear_value(const vec2d p1, const vec2d p2,
|
||||
const vec2d f1, const vec2d f2, const vec2d f) {
|
||||
if (p1 == p2)
|
||||
return p1;
|
||||
|
||||
__m128d _p1 = vec2d::load_xmm(p1);
|
||||
__m128d _p2 = vec2d::load_xmm(p2);
|
||||
__m128d _f1 = vec2d::load_xmm(f1);
|
||||
__m128d _f2 = vec2d::load_xmm(f2);
|
||||
__m128d _f = vec2d::load_xmm(f);
|
||||
|
||||
const __m128d _1 = vec2d::load_xmm(1.0);
|
||||
|
||||
__m128d t = _mm_div_pd(_mm_sub_pd(_f, _f1), _mm_sub_pd(_f2, _f1));
|
||||
return vec2d::store_xmm(_mm_add_pd(_mm_mul_pd(_p1, _mm_sub_pd(_1, t)), _mm_mul_pd(_p2, t)));
|
||||
}
|
||||
|
||||
inline std::vector<double_t> interpolate_linear(double_t p1, double_t p2, size_t f1, size_t f2) {
|
||||
size_t length = f2 - f1 + 1;
|
||||
if (p1 == p2)
|
||||
return std::vector<double_t>(length, p1);
|
||||
|
||||
std::vector<double_t> arr(length);
|
||||
double_t* a = arr.data();
|
||||
for (size_t i = 0, j = length; j; i++, j--, a++)
|
||||
*a = interpolate_linear_value(p1, p2,
|
||||
(double_t)f1, (double_t)f2, (double_t)(f1 + i));
|
||||
return arr;
|
||||
}
|
||||
|
||||
inline float_t interpolate_chs_value(const float_t p1, const float_t p2,
|
||||
const float_t t1, const float_t t2, const float_t f1, const float_t f2, const float_t f) {
|
||||
if (p1 == p2 && fabsf(t1) == 0.0f && fabsf(t2) == 0.0f)
|
||||
return p1;
|
||||
|
||||
float_t df = f2 - f1;
|
||||
float_t t = (f - f1) / df;
|
||||
float_t t_2 = t * t;
|
||||
float_t t_3 = t_2 * t;
|
||||
float_t t_23 = 3.0f * t_2;
|
||||
float_t t_32 = 2.0f * t_3;
|
||||
|
||||
float_t h00 = t_32 - t_23 + 1.0f;
|
||||
float_t h01 = t_23 - t_32;
|
||||
float_t h10 = t_3 - 2.0f * t_2 + t;
|
||||
float_t h11 = t_3 - t_2;
|
||||
|
||||
return h00 * p1 + h01 * p2 + h10 * (t1 * df) + h11 * (t2 * df);
|
||||
}
|
||||
|
||||
inline vec2 interpolate_chs_value(const vec2 p1, const vec2 p2,
|
||||
const vec2 t1, const vec2 t2, const vec2 f1, const vec2 f2, const vec2 f) {
|
||||
if (p1 == p2 && vec2::abs(t1) == 0.0f && vec2::abs(t2) == 0.0f)
|
||||
return p1;
|
||||
|
||||
__m128 _p1 = vec2::load_xmm(p1);
|
||||
__m128 _p2 = vec2::load_xmm(p2);
|
||||
__m128 _t1 = vec2::load_xmm(t1);
|
||||
__m128 _t2 = vec2::load_xmm(t2);
|
||||
__m128 _f1 = vec2::load_xmm(f1);
|
||||
__m128 _f2 = vec2::load_xmm(f2);
|
||||
__m128 _f = vec2::load_xmm(f);
|
||||
|
||||
const __m128 _1 = vec4::load_xmm(1.0f);
|
||||
const __m128 _2 = vec4::load_xmm(2.0f);
|
||||
const __m128 _3 = vec4::load_xmm(3.0f);
|
||||
|
||||
__m128 df = _mm_sub_ps(_f2, _f1);
|
||||
__m128 t = _mm_div_ps(_mm_sub_ps(_f, _f1), df);
|
||||
__m128 t_2 = _mm_mul_ps(t, t);
|
||||
__m128 t_3 = _mm_mul_ps(t_2, t);
|
||||
__m128 t_23 = _mm_mul_ps(_3, t_2);
|
||||
__m128 t_32 = _mm_mul_ps(_2, t_3);
|
||||
|
||||
__m128 h00 = _mm_add_ps(_mm_sub_ps(t_32, t_23), _1);
|
||||
__m128 h01 = _mm_sub_ps(t_23, t_32);
|
||||
__m128 h10 = _mm_add_ps(_mm_sub_ps(t_3, _mm_mul_ps(_2, t_2)), t);
|
||||
__m128 h11 = _mm_sub_ps(t_3, t_2);
|
||||
|
||||
_p1 = _mm_mul_ps(h00, _p1);
|
||||
_p2 = _mm_mul_ps(h01, _p2);
|
||||
_t1 = _mm_mul_ps(h10, _mm_mul_ps(_t1, df));
|
||||
_t2 = _mm_mul_ps(h11, _mm_mul_ps(_t2, df));
|
||||
return vec2::store_xmm(_mm_add_ps(_mm_add_ps(_p1, _p2), _mm_add_ps(_t1, _t2)));
|
||||
}
|
||||
|
||||
inline vec3 interpolate_chs_value(const vec3 p1, const vec3 p2,
|
||||
const vec3 t1, const vec3 t2, const vec3 f1, const vec3 f2, const vec3 f) {
|
||||
if (p1 == p2 && vec3::abs(t1) == 0.0f && vec3::abs(t2) == 0.0f)
|
||||
return p1;
|
||||
|
||||
__m128 _p1 = vec3::load_xmm(p1);
|
||||
__m128 _p2 = vec3::load_xmm(p2);
|
||||
__m128 _t1 = vec3::load_xmm(t1);
|
||||
__m128 _t2 = vec3::load_xmm(t2);
|
||||
__m128 _f1 = vec3::load_xmm(f1);
|
||||
__m128 _f2 = vec3::load_xmm(f2);
|
||||
__m128 _f = vec3::load_xmm(f);
|
||||
|
||||
const __m128 _1 = vec4::load_xmm(1.0f);
|
||||
const __m128 _2 = vec4::load_xmm(2.0f);
|
||||
const __m128 _3 = vec4::load_xmm(3.0f);
|
||||
|
||||
__m128 df = _mm_sub_ps(_f2, _f1);
|
||||
__m128 t = _mm_div_ps(_mm_sub_ps(_f, _f1), df);
|
||||
__m128 t_2 = _mm_mul_ps(t, t);
|
||||
__m128 t_3 = _mm_mul_ps(t_2, t);
|
||||
__m128 t_23 = _mm_mul_ps(_3, t_2);
|
||||
__m128 t_32 = _mm_mul_ps(_2, t_3);
|
||||
|
||||
__m128 h00 = _mm_add_ps(_mm_sub_ps(t_32, t_23), _1);
|
||||
__m128 h01 = _mm_sub_ps(t_23, t_32);
|
||||
__m128 h10 = _mm_add_ps(_mm_sub_ps(t_3, _mm_mul_ps(_2, t_2)), t);
|
||||
__m128 h11 = _mm_sub_ps(t_3, t_2);
|
||||
|
||||
_p1 = _mm_mul_ps(h00, _p1);
|
||||
_p2 = _mm_mul_ps(h01, _p2);
|
||||
_t1 = _mm_mul_ps(h10, _mm_mul_ps(_t1, df));
|
||||
_t2 = _mm_mul_ps(h11, _mm_mul_ps(_t2, df));
|
||||
return vec3::store_xmm(_mm_add_ps(_mm_add_ps(_p1, _p2), _mm_add_ps(_t1, _t2)));
|
||||
}
|
||||
|
||||
inline vec4 interpolate_chs_value(const vec4 p1, const vec4 p2,
|
||||
const vec4 t1, const vec4 t2, const vec4 f1, const vec4 f2, const vec4 f) {
|
||||
if (p1 == p2 && vec4::abs(t1) == 0.0f && vec4::abs(t2) == 0.0f)
|
||||
return p1;
|
||||
|
||||
__m128 _p1 = vec4::load_xmm(p1);
|
||||
__m128 _p2 = vec4::load_xmm(p2);
|
||||
__m128 _t1 = vec4::load_xmm(t1);
|
||||
__m128 _t2 = vec4::load_xmm(t2);
|
||||
__m128 _f1 = vec4::load_xmm(f1);
|
||||
__m128 _f2 = vec4::load_xmm(f2);
|
||||
__m128 _f = vec4::load_xmm(f);
|
||||
|
||||
const __m128 _1 = vec4::load_xmm(1.0f);
|
||||
const __m128 _2 = vec4::load_xmm(2.0f);
|
||||
const __m128 _3 = vec4::load_xmm(3.0f);
|
||||
|
||||
__m128 df = _mm_sub_ps(_f2, _f1);
|
||||
__m128 t = _mm_div_ps(_mm_sub_ps(_f, _f1), df);
|
||||
__m128 t_2 = _mm_mul_ps(t, t);
|
||||
__m128 t_3 = _mm_mul_ps(t_2, t);
|
||||
__m128 t_23 = _mm_mul_ps(_3, t_2);
|
||||
__m128 t_32 = _mm_mul_ps(_2, t_3);
|
||||
|
||||
__m128 h00 = _mm_add_ps(_mm_sub_ps(t_32, t_23), _1);
|
||||
__m128 h01 = _mm_sub_ps(t_23, t_32);
|
||||
__m128 h10 = _mm_add_ps(_mm_sub_ps(t_3, _mm_mul_ps(_2, t_2)), t);
|
||||
__m128 h11 = _mm_sub_ps(t_3, t_2);
|
||||
|
||||
_p1 = _mm_mul_ps(h00, _p1);
|
||||
_p2 = _mm_mul_ps(h01, _p2);
|
||||
_t1 = _mm_mul_ps(h10, _mm_mul_ps(_t1, df));
|
||||
_t2 = _mm_mul_ps(h11, _mm_mul_ps(_t2, df));
|
||||
return vec4::store_xmm(_mm_add_ps(_mm_add_ps(_p1, _p2), _mm_add_ps(_t1, _t2)));
|
||||
}
|
||||
|
||||
inline std::vector<float_t> interpolate_chs(const float_t p1, const float_t p2,
|
||||
const float_t t1, const float_t t2, const size_t f1, const size_t f2) {
|
||||
size_t length = f2 - f1 + 1;
|
||||
if (p1 == p2 && fabsf(t1) == 0.0f && fabsf(t2) == 0.0f)
|
||||
return std::vector<float_t>(length, p1);
|
||||
|
||||
std::vector<float_t> arr(length);
|
||||
float_t* a = arr.data();
|
||||
for (size_t i = 0, j = length; j; i++, j--, a++)
|
||||
*a = interpolate_chs_value(p1, p2, t1, t2,
|
||||
(float_t)f1, (float_t)f2, (float_t)(f1 + i));
|
||||
return arr;
|
||||
}
|
||||
|
||||
inline double_t interpolate_chs_value(const double_t p1, const double_t p2,
|
||||
const double_t t1, const double_t t2, const double_t f1, const double_t f2, const double_t f) {
|
||||
if (p1 == p2 && fabs(t1) == 0.0 && fabs(t2) == 0.0)
|
||||
return p1;
|
||||
|
||||
double_t df = f2 - f1;
|
||||
double_t t = (f - f1) / df;
|
||||
double_t t_2 = t * t;
|
||||
double_t t_3 = t_2 * t;
|
||||
double_t t_23 = 3.0f * t_2;
|
||||
double_t t_32 = 2.0f * t_3;
|
||||
|
||||
double_t h00 = t_32 - t_23 + 1.0f;
|
||||
double_t h01 = t_23 - t_32;
|
||||
double_t h10 = t_3 - 2.0f * t_2 + t;
|
||||
double_t h11 = t_3 - t_2;
|
||||
|
||||
return h00 * p1 + h01 * p2 + h10 * (t1 * df) + h11 * (t2 * df);
|
||||
}
|
||||
|
||||
inline vec2d interpolate_chs_value(const vec2d p1, const vec2d p2,
|
||||
const vec2d t1, const vec2d t2, const vec2d f1, const vec2d f2, const vec2d f) {
|
||||
if (p1 == p2 && vec2d::abs(t1) == 0.0 && vec2d::abs(t2) == 0.0)
|
||||
return p1;
|
||||
|
||||
__m128d _p1 = vec2d::load_xmm(p1);
|
||||
__m128d _p2 = vec2d::load_xmm(p2);
|
||||
__m128d _t1 = vec2d::load_xmm(t1);
|
||||
__m128d _t2 = vec2d::load_xmm(t2);
|
||||
__m128d _f1 = vec2d::load_xmm(f1);
|
||||
__m128d _f2 = vec2d::load_xmm(f2);
|
||||
__m128d _f = vec2d::load_xmm(f);
|
||||
|
||||
const __m128d _1 = vec2d::load_xmm(1.0);
|
||||
const __m128d _2 = vec2d::load_xmm(2.0);
|
||||
const __m128d _3 = vec2d::load_xmm(3.0);
|
||||
|
||||
__m128d df = _mm_sub_pd(_f2, _f1);
|
||||
__m128d t = _mm_div_pd(_mm_sub_pd(_f, _f1), df);
|
||||
__m128d t_2 = _mm_mul_pd(t, t);
|
||||
__m128d t_3 = _mm_mul_pd(t_2, t);
|
||||
__m128d t_23 = _mm_mul_pd(_3, t_2);
|
||||
__m128d t_32 = _mm_mul_pd(_2, t_3);
|
||||
|
||||
__m128d h00 = _mm_add_pd(_mm_sub_pd(t_32, t_23), _1);
|
||||
__m128d h01 = _mm_sub_pd(t_23, t_32);
|
||||
__m128d h10 = _mm_add_pd(_mm_sub_pd(t_3, _mm_mul_pd(_2, t_2)), t);
|
||||
__m128d h11 = _mm_sub_pd(t_3, t_2);
|
||||
|
||||
_p1 = _mm_mul_pd(h00, _p1);
|
||||
_p2 = _mm_mul_pd(h01, _p2);
|
||||
_t1 = _mm_mul_pd(h10, _mm_mul_pd(_t1, df));
|
||||
_t2 = _mm_mul_pd(h11, _mm_mul_pd(_t2, df));
|
||||
return vec2d::store_xmm(_mm_add_pd(_mm_add_pd(_p1, _p2), _mm_add_pd(_t1, _t2)));
|
||||
}
|
||||
|
||||
inline std::vector<double_t> interpolate_chs(const double_t p1, const double_t p2,
|
||||
const double_t t1, const double_t t2, const size_t f1, const size_t f2) {
|
||||
size_t length = f2 - f1 + 1;
|
||||
if (p1 == p2 && fabs(t1) == 0.0 && fabs(t2) == 0.0)
|
||||
return std::vector<double_t>(length, p1);
|
||||
|
||||
std::vector<double_t> arr(length);
|
||||
double_t* a = arr.data();
|
||||
for (size_t i = 0, j = length; j; i++, j--, a++)
|
||||
*a = interpolate_chs_value(p1, p2, t1, t2,
|
||||
(double_t)f1, (double_t)f2, (double_t)(f1 + i));
|
||||
return arr;
|
||||
}
|
||||
|
||||
extern void interpolate_chs_reverse_value(float_t* arr, size_t length,
|
||||
float_t& t1, float_t& t2, size_t f1, size_t f2, size_t f);
|
||||
extern void interpolate_chs_reverse_value(float_t* arr, size_t length, float_t& t1a, float_t& t2a,
|
||||
float_t& t1b, float_t& t2b, float_t& t1c, float_t& t2c, size_t f1, size_t f2, size_t f);
|
||||
extern void interpolate_chs_reverse_value(double_t* arr, size_t length,
|
||||
double_t& t1, double_t& t2, size_t f1, size_t f2, size_t f);
|
||||
extern void interpolate_chs_reverse(float_t* arr, size_t length,
|
||||
float_t& t1, float_t& t2, size_t f1, size_t f2);
|
||||
extern void interpolate_chs_reverse(double_t* arr, size_t length,
|
||||
double_t& t1, double_t& t2, size_t f1, size_t f2);
|
||||
extern int32_t interpolate_chs_reverse_sequence(
|
||||
std::vector<float_t>& values_src, std::vector<kft3>& values, bool fast = false);
|
||||
@@ -1,182 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "file_stream.hpp"
|
||||
#include <share.h>
|
||||
|
||||
file_stream::file_stream() : stream() {
|
||||
|
||||
}
|
||||
|
||||
file_stream::~file_stream() {
|
||||
close();
|
||||
}
|
||||
|
||||
int file_stream::flush() {
|
||||
return fflush(stream);
|
||||
}
|
||||
|
||||
void file_stream::close() {
|
||||
if (!this)
|
||||
return;
|
||||
|
||||
if (stream) {
|
||||
fflush(stream);
|
||||
fclose(stream);
|
||||
stream = 0;
|
||||
}
|
||||
stream::close();
|
||||
}
|
||||
|
||||
bool file_stream::check_null() {
|
||||
return !stream;
|
||||
}
|
||||
|
||||
bool file_stream::check_not_null() {
|
||||
return !!stream;
|
||||
}
|
||||
|
||||
void file_stream::align_read(size_t align) {
|
||||
int64_t position = _ftelli64(stream);
|
||||
size_t temp_align = align - position % align;
|
||||
if (align != temp_align)
|
||||
_fseeki64(stream, position + temp_align, 0);
|
||||
}
|
||||
|
||||
void file_stream::align_write(size_t align) {
|
||||
int64_t position = _ftelli64(stream);
|
||||
size_t temp_align = align - position % align;
|
||||
if (align != temp_align) {
|
||||
memset(buf, 0, min_def(sizeof(buf), temp_align));
|
||||
size_t i = temp_align;
|
||||
while (i >= sizeof(buf)) {
|
||||
fwrite(buf, 1, sizeof(buf), stream);
|
||||
i -= sizeof(buf);
|
||||
}
|
||||
|
||||
if (i > 0)
|
||||
fwrite(buf, 1, i, stream);
|
||||
}
|
||||
}
|
||||
|
||||
size_t file_stream::read(size_t count) {
|
||||
return read((void*)0, count);
|
||||
}
|
||||
|
||||
size_t file_stream::read(void* buf, size_t count) {
|
||||
if (!buf) {
|
||||
int64_t act_count = 0;
|
||||
while (count > 0) {
|
||||
act_count += fread(this->buf, 1, min_def(count, sizeof(this->buf)), stream);
|
||||
count -= sizeof(this->buf);
|
||||
}
|
||||
return act_count;
|
||||
}
|
||||
else
|
||||
return fread(buf, 1, count, stream);
|
||||
}
|
||||
|
||||
size_t file_stream::read(void* buf, size_t size, size_t count) {
|
||||
if (!buf) {
|
||||
int64_t act_count = 0;
|
||||
while (count > 0) {
|
||||
act_count += fread(this->buf, size, min_def(count, sizeof(this->buf) / size), stream);
|
||||
count -= sizeof(this->buf);
|
||||
}
|
||||
return act_count;
|
||||
}
|
||||
else
|
||||
return fread(buf, size, count, stream);
|
||||
}
|
||||
|
||||
size_t file_stream::write(size_t count) {
|
||||
return write((void*)0, count);
|
||||
}
|
||||
|
||||
size_t file_stream::write(const void* buf, size_t count) {
|
||||
if (!buf) {
|
||||
memset(this->buf, 0, sizeof(this->buf));
|
||||
int64_t act_count = 0;
|
||||
while (count > 0) {
|
||||
act_count += fwrite(this->buf, 1, min_def(count, sizeof(this->buf)), stream);
|
||||
if (count > sizeof(this->buf))
|
||||
count -= sizeof(this->buf);
|
||||
else
|
||||
break;
|
||||
}
|
||||
return act_count;
|
||||
}
|
||||
else
|
||||
return fwrite(buf, 1, count, stream);
|
||||
}
|
||||
|
||||
size_t file_stream::write(const void* buf, size_t size, size_t count) {
|
||||
if (!buf) {
|
||||
memset(this->buf, 0, sizeof(this->buf));
|
||||
int64_t act_count = 0;
|
||||
while (count > 0) {
|
||||
act_count += fwrite(this->buf, 1, min_def(count, sizeof(this->buf) / size), stream);
|
||||
if (count > sizeof(this->buf) / size)
|
||||
count -= sizeof(this->buf) / size;
|
||||
else
|
||||
break;
|
||||
}
|
||||
return act_count;
|
||||
}
|
||||
else
|
||||
return fwrite(buf, size, count, stream);
|
||||
}
|
||||
|
||||
int32_t file_stream::read_char() {
|
||||
return fgetc(stream);
|
||||
}
|
||||
|
||||
int32_t file_stream::write_char(char c) {
|
||||
return fputc(c, stream);
|
||||
}
|
||||
|
||||
int64_t file_stream::get_length() {
|
||||
if (stream) {
|
||||
size_t temp = _ftelli64(stream);
|
||||
_fseeki64(stream, 0, SEEK_END);
|
||||
length = _ftelli64(stream);
|
||||
_fseeki64(stream, temp, SEEK_SET);
|
||||
}
|
||||
else
|
||||
length = 0;
|
||||
return length;
|
||||
}
|
||||
|
||||
int64_t file_stream::get_position() {
|
||||
return _ftelli64(stream);
|
||||
}
|
||||
|
||||
int32_t file_stream::set_position(int64_t pos, int32_t seek) {
|
||||
return _fseeki64(stream, pos, seek);
|
||||
}
|
||||
|
||||
void file_stream::open(const char* path, const char* mode) {
|
||||
close();
|
||||
|
||||
if (!path || !mode)
|
||||
return;
|
||||
|
||||
wchar_t* temp_path = utf8_to_utf16(path);
|
||||
wchar_t* temp_mode = utf8_to_utf16(mode);
|
||||
stream = _wfsopen(temp_path, temp_mode, _SH_DENYNO);
|
||||
get_length();
|
||||
free_def(temp_path);
|
||||
free_def(temp_mode);
|
||||
}
|
||||
|
||||
void file_stream::open(const wchar_t* path, const wchar_t* mode) {
|
||||
close();
|
||||
|
||||
if (!path || !mode)
|
||||
return;
|
||||
|
||||
stream = _wfsopen(path, mode, _SH_DENYNO);
|
||||
get_length();
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stream.hpp"
|
||||
|
||||
class file_stream : public stream {
|
||||
private:
|
||||
FILE* stream;
|
||||
|
||||
public:
|
||||
file_stream();
|
||||
virtual ~file_stream();
|
||||
|
||||
virtual int flush() override;
|
||||
virtual void close() override;
|
||||
virtual bool check_null() override;
|
||||
virtual bool check_not_null() override;
|
||||
|
||||
virtual void align_read(size_t align) override;
|
||||
virtual void align_write(size_t align) override;
|
||||
virtual size_t read(size_t count) override;
|
||||
virtual size_t read(void* buf, size_t count) override;
|
||||
virtual size_t read(void* buf, size_t size, size_t count) override;
|
||||
virtual size_t write(size_t count) override;
|
||||
virtual size_t write(const void* buf, size_t count) override;
|
||||
virtual size_t write(const void* buf, size_t size, size_t count) override;
|
||||
virtual int32_t read_char() override;
|
||||
virtual int32_t write_char(char c) override;
|
||||
virtual int64_t get_length() override;
|
||||
virtual int64_t get_position() override;
|
||||
virtual int32_t set_position(int64_t pos, int32_t seek) override;
|
||||
|
||||
void open(const char* path, const char* mode);
|
||||
void open(const wchar_t* path, const wchar_t* mode);
|
||||
|
||||
template <typename T>
|
||||
size_t read_data(T& data) {
|
||||
return read(&data, sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t write_data(const T& data) {
|
||||
return write(&data, sizeof(T));
|
||||
}
|
||||
};
|
||||
@@ -1,255 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "memory_stream.hpp"
|
||||
|
||||
memory_stream::memory_stream() {
|
||||
data.data = data.vec.begin();
|
||||
}
|
||||
|
||||
memory_stream::~memory_stream() {
|
||||
close();
|
||||
}
|
||||
|
||||
int memory_stream::flush() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void memory_stream::close() {
|
||||
if (!this)
|
||||
return;
|
||||
|
||||
data.vec.clear();
|
||||
data.vec.shrink_to_fit();
|
||||
data.data = data.vec.begin();
|
||||
stream::close();
|
||||
}
|
||||
|
||||
bool memory_stream::check_null() {
|
||||
return !data.vec.size();
|
||||
}
|
||||
|
||||
bool memory_stream::check_not_null() {
|
||||
return !!data.vec.size();
|
||||
}
|
||||
|
||||
void memory_stream::align_read(size_t align) {
|
||||
size_t position = data.data - data.vec.begin();
|
||||
size_t temp_align = align - position % align;
|
||||
if (align != temp_align) {
|
||||
size_t pos = data.data - data.vec.begin();
|
||||
if (data.vec.size() < (size_t)(pos + temp_align)) {
|
||||
size_t size = data.vec.size();
|
||||
data.vec.resize(pos + temp_align);
|
||||
data.data = data.vec.begin() + pos;
|
||||
memset(data.data._Ptr, 0, temp_align);
|
||||
}
|
||||
data.data += temp_align;
|
||||
}
|
||||
}
|
||||
|
||||
void memory_stream::align_write(size_t align) {
|
||||
size_t position = data.data - data.vec.begin();
|
||||
size_t temp_align = align - position % align;
|
||||
if (align != temp_align) {
|
||||
size_t pos = data.data - data.vec.begin();
|
||||
if (data.vec.size() < (size_t)(pos + temp_align)) {
|
||||
size_t size = data.vec.size();
|
||||
data.vec.resize(pos + temp_align);
|
||||
data.data = data.vec.begin() + pos;
|
||||
memset(data.data._Ptr, 0, temp_align);
|
||||
}
|
||||
data.data += temp_align;
|
||||
}
|
||||
}
|
||||
|
||||
size_t memory_stream::read(size_t count) {
|
||||
return read((void*)0, count);
|
||||
}
|
||||
|
||||
size_t memory_stream::read(void* buf, size_t count) {
|
||||
if (data.data >= data.vec.end())
|
||||
return EOF;
|
||||
|
||||
size_t _count = data.vec.end() - data.data;
|
||||
if (_count >= count)
|
||||
_count = count;
|
||||
if (buf)
|
||||
memcpy(buf, data.data._Ptr, _count);
|
||||
data.data += _count;
|
||||
return _count;
|
||||
}
|
||||
|
||||
size_t memory_stream::read(void* buf, size_t size, size_t count) {
|
||||
if (data.data >= data.vec.end())
|
||||
return EOF;
|
||||
|
||||
size_t _count = data.vec.end() - data.data;
|
||||
if (_count >= size * count)
|
||||
_count = size * count;
|
||||
if (buf)
|
||||
memcpy(buf, data.data._Ptr, _count);
|
||||
data.data += _count;
|
||||
return _count;
|
||||
}
|
||||
|
||||
size_t memory_stream::write(size_t count) {
|
||||
return write((void*)0, count);
|
||||
}
|
||||
|
||||
size_t memory_stream::write(const void* buf, size_t count) {
|
||||
size_t pos = data.data - data.vec.begin();
|
||||
if (data.vec.size() < pos + count) {
|
||||
data.vec.resize(pos + count);
|
||||
data.data = data.vec.begin() + pos;
|
||||
}
|
||||
if (buf)
|
||||
memcpy(data.data._Ptr, buf, count);
|
||||
else
|
||||
memset(data.data._Ptr, 0, count);
|
||||
data.data += count;
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t memory_stream::write(const void* buf, size_t size, size_t count) {
|
||||
size_t pos = data.data - data.vec.begin();
|
||||
size_t _count = size * count;
|
||||
if (data.vec.size() < (size_t)(pos + _count)) {
|
||||
data.vec.resize(pos + _count);
|
||||
data.data = data.vec.begin() + pos;
|
||||
}
|
||||
if (buf)
|
||||
memcpy(data.data._Ptr, buf, _count);
|
||||
else
|
||||
memset(data.data._Ptr, 0, _count);
|
||||
data.data += _count;
|
||||
return _count;
|
||||
}
|
||||
|
||||
int32_t memory_stream::read_char() {
|
||||
if (data.data >= data.vec.end())
|
||||
return EOF;
|
||||
return *(data.data++);
|
||||
}
|
||||
|
||||
int32_t memory_stream::write_char(char c) {
|
||||
size_t pos = data.data - data.vec.begin();
|
||||
if (data.vec.size() < (size_t)(pos + 1)) {
|
||||
size_t size = data.vec.size();
|
||||
data.vec.resize(pos + 1);
|
||||
data.data = data.vec.begin() + pos;
|
||||
}
|
||||
*(data.data++) = c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t memory_stream::get_length() {
|
||||
length = data.vec.size();
|
||||
return length;
|
||||
}
|
||||
|
||||
int64_t memory_stream::get_position() {
|
||||
return data.data - data.vec.begin();
|
||||
}
|
||||
|
||||
int32_t memory_stream::set_position(int64_t pos, int32_t seek) {
|
||||
switch (seek) {
|
||||
case SEEK_SET: {
|
||||
if (pos < 0)
|
||||
return EOF;
|
||||
|
||||
if (data.vec.size() < (size_t)pos) {
|
||||
size_t size = data.vec.size();
|
||||
data.vec.resize(pos);
|
||||
memset(data.vec.data() + size, 0, pos - size);
|
||||
}
|
||||
data.data = data.vec.begin() + pos;
|
||||
} return 0;
|
||||
case SEEK_CUR: {
|
||||
if (pos > 0) {
|
||||
size_t _pos = data.data - data.vec.begin();
|
||||
if (data.vec.size() < (size_t)(_pos + pos)) {
|
||||
size_t size = data.vec.size();
|
||||
data.vec.resize(_pos + pos);
|
||||
memset(data.vec.data() + size, 0, _pos + pos - size);
|
||||
data.data = data.vec.begin() + _pos;
|
||||
}
|
||||
data.data += pos;
|
||||
}
|
||||
else if (pos < 0) {
|
||||
if (data.data - data.vec.begin() < -pos)
|
||||
return EOF;
|
||||
else
|
||||
data.data += pos;
|
||||
}
|
||||
} return 0;
|
||||
case SEEK_END: {
|
||||
if (pos < 0)
|
||||
break;
|
||||
|
||||
if (data.vec.size() < (size_t)pos)
|
||||
break;
|
||||
|
||||
data.data = data.vec.end() - pos;
|
||||
} return 0;
|
||||
}
|
||||
return EOF;
|
||||
}
|
||||
|
||||
void memory_stream::open() {
|
||||
close();
|
||||
|
||||
length = 0;
|
||||
}
|
||||
|
||||
void memory_stream::open(const void* data, size_t size) {
|
||||
close();
|
||||
|
||||
if (!size) {
|
||||
length = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
this->data.vec.clear();
|
||||
this->data.vec.resize(size);
|
||||
if (this->data.vec.data())
|
||||
if (data)
|
||||
memcpy(this->data.vec.data(), data, size);
|
||||
else
|
||||
memset(this->data.vec.data(), 0, size);
|
||||
this->data.data = this->data.vec.begin();
|
||||
length = size;
|
||||
}
|
||||
|
||||
void memory_stream::open(std::vector<uint8_t>& data) {
|
||||
close();
|
||||
|
||||
if (!data.size()) {
|
||||
length = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
this->data.vec = data;
|
||||
this->data.data = this->data.vec.begin();
|
||||
length = data.size();
|
||||
}
|
||||
|
||||
void memory_stream::copy(void** data, size_t* size) {
|
||||
if (!this || !data || !size)
|
||||
return;
|
||||
|
||||
*size = this->data.vec.size();
|
||||
*data = force_malloc(*size);
|
||||
memcpy(*data, this->data.vec.data(), *size);
|
||||
}
|
||||
|
||||
void memory_stream::copy(std::vector<uint8_t>& data) {
|
||||
if (!this)
|
||||
return;
|
||||
|
||||
size_t length = this->data.vec.size();
|
||||
data.resize(length);
|
||||
memcpy(data.data(), this->data.vec.data(), length);
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stream.hpp"
|
||||
|
||||
class memory_stream : public stream {
|
||||
private:
|
||||
struct data {
|
||||
std::vector<uint8_t>::iterator data;
|
||||
std::vector<uint8_t> vec;
|
||||
} data;
|
||||
|
||||
public:
|
||||
memory_stream();
|
||||
virtual ~memory_stream();
|
||||
|
||||
virtual int flush() override;
|
||||
virtual void close() override;
|
||||
virtual bool check_null() override;
|
||||
virtual bool check_not_null() override;
|
||||
|
||||
virtual void align_read(size_t align) override;
|
||||
virtual void align_write(size_t align) override;
|
||||
virtual size_t read(size_t count) override;
|
||||
virtual size_t read(void* buf, size_t count) override;
|
||||
virtual size_t read(void* buf, size_t size, size_t count) override;
|
||||
virtual size_t write(size_t count) override;
|
||||
virtual size_t write(const void* buf, size_t count) override;
|
||||
virtual size_t write(const void* buf, size_t size, size_t count) override;
|
||||
virtual int32_t read_char() override;
|
||||
virtual int32_t write_char(char c) override;
|
||||
virtual int64_t get_length() override;
|
||||
virtual int64_t get_position() override;
|
||||
virtual int32_t set_position(int64_t pos, int32_t seek) override;
|
||||
|
||||
void open();
|
||||
void open(const void* data, size_t size);
|
||||
void open(std::vector<uint8_t>& data);
|
||||
void copy(void** data, size_t* size);
|
||||
void copy(std::vector<uint8_t>& data);
|
||||
|
||||
template <typename T>
|
||||
size_t read_data(T& data) {
|
||||
return read(&data, sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t write_data(const T& data) {
|
||||
return write(&data, sizeof(T));
|
||||
}
|
||||
};
|
||||
@@ -1,428 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "path.hpp"
|
||||
#include "../str_utils.hpp"
|
||||
|
||||
bool path_check_path_exists(const char* path) {
|
||||
wchar_t* path_temp = utf8_to_utf16(path);
|
||||
DWORD ftyp = GetFileAttributesW(path_temp);
|
||||
free_def(path_temp);
|
||||
if (ftyp == INVALID_FILE_ATTRIBUTES)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
bool path_check_path_exists(const wchar_t* path) {
|
||||
DWORD ftyp = GetFileAttributesW(path);
|
||||
if (ftyp == INVALID_FILE_ATTRIBUTES)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
bool path_check_file_exists(const char* path) {
|
||||
wchar_t* path_temp = utf8_to_utf16(path);
|
||||
DWORD ftyp = GetFileAttributesW(path_temp);
|
||||
free_def(path_temp);
|
||||
if (ftyp == INVALID_FILE_ATTRIBUTES)
|
||||
return false;
|
||||
else
|
||||
return ftyp & FILE_ATTRIBUTE_DIRECTORY ? false : true;
|
||||
}
|
||||
|
||||
bool path_check_file_exists(const wchar_t* path) {
|
||||
DWORD ftyp = GetFileAttributesW(path);
|
||||
if (ftyp == INVALID_FILE_ATTRIBUTES)
|
||||
return false;
|
||||
else
|
||||
return ftyp & FILE_ATTRIBUTE_DIRECTORY ? false : true;
|
||||
}
|
||||
|
||||
bool path_check_directory_exists(const char* path) {
|
||||
wchar_t* path_temp = utf8_to_utf16(path);
|
||||
DWORD ftyp = GetFileAttributesW(path_temp);
|
||||
free_def(path_temp);
|
||||
if (ftyp == INVALID_FILE_ATTRIBUTES)
|
||||
return false;
|
||||
else
|
||||
return ftyp & FILE_ATTRIBUTE_DIRECTORY ? true : false;
|
||||
}
|
||||
|
||||
bool path_check_directory_exists(const wchar_t* path) {
|
||||
DWORD ftyp = GetFileAttributesW(path);
|
||||
if (ftyp == INVALID_FILE_ATTRIBUTES)
|
||||
return false;
|
||||
else
|
||||
return ftyp & FILE_ATTRIBUTE_DIRECTORY ? true : false;
|
||||
}
|
||||
|
||||
std::vector<std::string> path_get_files(const char* path) {
|
||||
wchar_t* dir_temp = utf8_to_utf16(path);
|
||||
size_t dir_len = utf16_length(dir_temp);
|
||||
if (!dir_temp)
|
||||
return {};
|
||||
|
||||
std::wstring dir;
|
||||
dir.assign(dir_temp, dir_len);
|
||||
if (dir.size() && dir.back() != L'\\')
|
||||
dir.push_back(L'\\');
|
||||
dir.push_back(L'*');
|
||||
free_def(dir_temp);
|
||||
|
||||
WIN32_FIND_DATAW fdata = {};
|
||||
HANDLE h = FindFirstFileW(dir.c_str(), &fdata);
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
return {};
|
||||
|
||||
std::vector<std::string> files;
|
||||
do {
|
||||
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
continue;
|
||||
|
||||
char* file_temp = utf16_to_utf8(fdata.cFileName);
|
||||
if (file_temp) {
|
||||
files.push_back(file_temp);
|
||||
free(file_temp);
|
||||
}
|
||||
} while (FindNextFileW(h, &fdata));
|
||||
FindClose(h);
|
||||
return files;
|
||||
}
|
||||
|
||||
std::vector<std::wstring> path_get_files(const wchar_t* path) {
|
||||
size_t dir_len = utf16_length(path);
|
||||
|
||||
std::wstring dir;
|
||||
dir.assign(path, dir_len);
|
||||
if (dir.size() && dir.back() != L'\\')
|
||||
dir.push_back(L'\\');
|
||||
dir.push_back(L'*');
|
||||
|
||||
WIN32_FIND_DATAW fdata = {};
|
||||
HANDLE h = FindFirstFileW(dir.c_str(), &fdata);
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
return {};
|
||||
|
||||
std::vector<std::wstring> files;
|
||||
do {
|
||||
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
continue;
|
||||
|
||||
files.push_back(fdata.cFileName);
|
||||
} while (FindNextFileW(h, &fdata));
|
||||
FindClose(h);
|
||||
return files;
|
||||
}
|
||||
|
||||
std::vector<std::string> path_get_directories(
|
||||
const char* path, const char** exclude_list, size_t exclude_count) {
|
||||
wchar_t* dir_temp = utf8_to_utf16(path);
|
||||
size_t dir_len = utf16_length(dir_temp);
|
||||
if (!dir_temp)
|
||||
return {};
|
||||
|
||||
std::wstring dir;
|
||||
std::wstring temp;
|
||||
dir.assign(dir_temp, dir_len);
|
||||
if (dir.size() && dir.back() != L'\\')
|
||||
dir.push_back(L'\\');
|
||||
temp.assign(dir);
|
||||
dir.push_back(L'*');
|
||||
free_def(dir_temp);
|
||||
|
||||
WIN32_FIND_DATAW fdata = {};
|
||||
HANDLE h = FindFirstFileW(dir.c_str(), &fdata);
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
return {};
|
||||
|
||||
std::vector<std::string> directories;
|
||||
do {
|
||||
if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
|| !str_utils_compare(fdata.cFileName, L".")
|
||||
|| !str_utils_compare(fdata.cFileName, L".."))
|
||||
continue;
|
||||
|
||||
if (exclude_list && exclude_count) {
|
||||
size_t len = utf16_length(fdata.cFileName);
|
||||
temp.append(fdata.cFileName, len);
|
||||
std::string temp_utf8 = utf16_to_utf8(temp);
|
||||
|
||||
bool exclude = false;
|
||||
for (size_t i = 0; i < exclude_count; i++) {
|
||||
size_t exclude_path_len = utf8_length(exclude_list[i]);
|
||||
size_t pos = temp_utf8.rfind(exclude_list[i], -1, exclude_path_len);
|
||||
if (pos != -1 && pos == temp_utf8.size() - exclude_path_len) {
|
||||
exclude = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
temp.resize(temp.size() - len);
|
||||
|
||||
if (exclude)
|
||||
continue;
|
||||
}
|
||||
|
||||
char* directory_temp = utf16_to_utf8(fdata.cFileName);
|
||||
if (directory_temp)
|
||||
directories.push_back(directory_temp);
|
||||
free_def(directory_temp);
|
||||
} while (FindNextFileW(h, &fdata));
|
||||
FindClose(h);
|
||||
return directories;
|
||||
}
|
||||
|
||||
std::vector<std::wstring> path_get_directories(
|
||||
const wchar_t* path, wchar_t** exclude_list, size_t exclude_count) {
|
||||
size_t dir_len = utf16_length(path);
|
||||
|
||||
std::wstring dir;
|
||||
std::wstring temp;
|
||||
dir.assign(path, dir_len);
|
||||
if (dir.size() && dir.back() != L'\\')
|
||||
dir.push_back(L'\\');
|
||||
temp.assign(dir);
|
||||
dir.push_back(L'*');
|
||||
|
||||
WIN32_FIND_DATAW fdata = {};
|
||||
HANDLE h = FindFirstFileW(dir.c_str(), &fdata);
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
return {};
|
||||
|
||||
std::vector<std::wstring> directories;
|
||||
do {
|
||||
if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
|| !str_utils_compare(fdata.cFileName, L".")
|
||||
|| !str_utils_compare(fdata.cFileName, L".."))
|
||||
continue;
|
||||
|
||||
if (exclude_list && exclude_count) {
|
||||
size_t len = utf16_length(fdata.cFileName);
|
||||
temp.append(fdata.cFileName, len);
|
||||
|
||||
bool exclude = false;
|
||||
for (size_t i = 0; i < exclude_count; i++) {
|
||||
size_t exclude_path_len = utf16_length(exclude_list[i]);
|
||||
size_t pos = temp.rfind(exclude_list[i], -1, exclude_path_len);
|
||||
if (pos != -1 && pos == temp.size() - exclude_path_len) {
|
||||
exclude = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
temp.resize(temp.size() - len);
|
||||
|
||||
if (exclude)
|
||||
continue;
|
||||
}
|
||||
|
||||
directories.push_back(fdata.cFileName);
|
||||
} while (FindNextFileW(h, &fdata));
|
||||
FindClose(h);
|
||||
return directories;
|
||||
}
|
||||
|
||||
std::vector<std::string> path_get_directories_recursive(
|
||||
const char* path, const char** exclude_list, size_t exclude_count) {
|
||||
wchar_t* dir_temp = utf8_to_utf16(path);
|
||||
size_t dir_len = utf16_length(dir_temp);
|
||||
if (!dir_temp)
|
||||
return {};
|
||||
|
||||
std::wstring dir;
|
||||
std::wstring temp;
|
||||
dir.assign(dir_temp, dir_len);
|
||||
if (dir.size() && dir.back() != L'\\')
|
||||
dir.push_back(L'\\');
|
||||
temp.assign(dir);
|
||||
dir.push_back(L'*');
|
||||
free_def(dir_temp);
|
||||
|
||||
WIN32_FIND_DATAW fdata = {};
|
||||
HANDLE h = FindFirstFileW(dir.c_str(), &fdata);
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
return {};
|
||||
|
||||
std::vector<std::string> temp_vec;
|
||||
do {
|
||||
if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
|| !str_utils_compare(fdata.cFileName, L".")
|
||||
|| !str_utils_compare(fdata.cFileName, L".."))
|
||||
continue;
|
||||
|
||||
if (exclude_list && exclude_count) {
|
||||
size_t len = utf16_length(fdata.cFileName);
|
||||
temp.append(fdata.cFileName, len);
|
||||
std::string temp_utf8 = utf16_to_utf8(temp);
|
||||
|
||||
bool exclude = false;
|
||||
for (size_t i = 0; i < exclude_count; i++) {
|
||||
size_t exclude_path_len = utf8_length(exclude_list[i]);
|
||||
size_t pos = temp_utf8.rfind(exclude_list[i], -1, exclude_path_len);
|
||||
if (pos != -1 && pos == temp_utf8.size() - exclude_path_len) {
|
||||
exclude = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
temp.resize(temp.size() - len);
|
||||
|
||||
if (exclude)
|
||||
continue;
|
||||
}
|
||||
|
||||
char* directory_temp = utf16_to_utf8(fdata.cFileName);
|
||||
temp_vec.push_back(directory_temp);
|
||||
free_def(directory_temp);
|
||||
} while (FindNextFileW(h, &fdata));
|
||||
FindClose(h);
|
||||
|
||||
size_t max_len = 0;
|
||||
for (std::string& i : temp_vec) {
|
||||
size_t len = i.size();
|
||||
if (max_len < len)
|
||||
max_len = len;
|
||||
}
|
||||
|
||||
std::vector<std::string> directories;
|
||||
std::string path_temp;
|
||||
path_temp.assign(path);
|
||||
path_temp += '\\';
|
||||
for (std::string& i : temp_vec) {
|
||||
path_temp.append(i);
|
||||
std::vector<std::string> temp = path_get_directories_recursive(
|
||||
path_temp.c_str(), exclude_list, exclude_count);
|
||||
path_temp.resize(path_temp.size() - i.size());
|
||||
|
||||
directories.push_back(i);
|
||||
|
||||
if (temp.size() < 1)
|
||||
continue;
|
||||
|
||||
max_len = 0;
|
||||
for (std::string& j : temp) {
|
||||
size_t len = j.size();
|
||||
if (max_len < len)
|
||||
max_len = len;
|
||||
}
|
||||
|
||||
if (i.size()) {
|
||||
std::string sub_path_temp;
|
||||
sub_path_temp.assign(i);
|
||||
sub_path_temp += '\\';
|
||||
for (std::string& j : temp)
|
||||
directories.push_back(sub_path_temp + j);
|
||||
}
|
||||
}
|
||||
return directories;
|
||||
}
|
||||
|
||||
std::vector<std::wstring> path_get_directories_recursive(
|
||||
const wchar_t* path, const wchar_t** exclude_list, size_t exclude_count) {
|
||||
size_t dir_len = utf16_length(path);
|
||||
|
||||
std::wstring dir;
|
||||
std::wstring temp;
|
||||
dir.assign(path, dir_len);
|
||||
if (dir.size() && dir.back() != L'\\')
|
||||
dir.push_back(L'\\');
|
||||
temp.assign(dir);
|
||||
dir.push_back(L'*');
|
||||
|
||||
WIN32_FIND_DATAW fdata = {};
|
||||
HANDLE h = FindFirstFileW(dir.c_str(), &fdata);
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
return {};
|
||||
|
||||
std::vector<std::wstring> temp_vec;
|
||||
do {
|
||||
if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
|| !str_utils_compare(fdata.cFileName, L".")
|
||||
|| !str_utils_compare(fdata.cFileName, L".."))
|
||||
continue;
|
||||
|
||||
if (exclude_list && exclude_count) {
|
||||
size_t len = utf16_length(fdata.cFileName);
|
||||
temp.append(fdata.cFileName, len);
|
||||
|
||||
bool exclude = false;
|
||||
for (size_t i = 0; i < exclude_count; i++) {
|
||||
size_t exclude_path_len = utf16_length(exclude_list[i]);
|
||||
size_t pos = temp.rfind(exclude_list[i], -1, exclude_path_len);
|
||||
if (pos != -1 && pos == temp.size() - exclude_path_len) {
|
||||
exclude = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
temp.resize(temp.size() - len);
|
||||
|
||||
if (exclude)
|
||||
continue;
|
||||
}
|
||||
|
||||
std::wstring directory = std::wstring(fdata.cFileName);
|
||||
temp_vec.push_back(directory);
|
||||
} while (FindNextFileW(h, &fdata));
|
||||
FindClose(h);
|
||||
|
||||
size_t max_len = 0;
|
||||
for (std::wstring& i : temp_vec) {
|
||||
size_t len = i.size();
|
||||
if (max_len < len)
|
||||
max_len = len;
|
||||
}
|
||||
|
||||
std::vector<std::wstring> directories;
|
||||
std::wstring path_temp;
|
||||
path_temp.assign(path);
|
||||
path_temp.push_back(L'\\');
|
||||
for (std::wstring& i : temp_vec) {
|
||||
path_temp.append(i);
|
||||
std::vector<std::wstring> temp = path_get_directories_recursive(
|
||||
path_temp.c_str(), exclude_list, exclude_count);
|
||||
path_temp.resize(path_temp.size() - i.size());
|
||||
|
||||
directories.push_back(i);
|
||||
|
||||
if (temp.size() < 1)
|
||||
continue;
|
||||
|
||||
max_len = 0;
|
||||
for (std::wstring& j : temp) {
|
||||
size_t len = j.size();
|
||||
if (max_len < len)
|
||||
max_len = len;
|
||||
}
|
||||
|
||||
if (i.size()) {
|
||||
std::wstring sub_path_temp;
|
||||
sub_path_temp.assign(i);
|
||||
sub_path_temp.push_back(L'\\');
|
||||
for (std::wstring& j : temp)
|
||||
directories.push_back(sub_path_temp + j);
|
||||
}
|
||||
}
|
||||
return directories;
|
||||
}
|
||||
|
||||
void path_get_full_path(std::string& str) {
|
||||
wchar_t buf[MAX_PATH * 2];
|
||||
buf[0] = 0;
|
||||
wchar_t* utf16_temp = utf8_to_utf16(str.c_str());
|
||||
if (utf16_temp)
|
||||
GetFullPathNameW(utf16_temp, MAX_PATH * 2, buf, 0);
|
||||
free_def(utf16_temp);
|
||||
|
||||
char* utf0_temp = utf16_to_utf8(buf);
|
||||
if (utf0_temp)
|
||||
str.assign(utf0_temp);
|
||||
free_def(utf0_temp);
|
||||
}
|
||||
|
||||
void path_get_full_path(std::wstring& str) {
|
||||
wchar_t buf[MAX_PATH * 2];
|
||||
buf[0] = 0;
|
||||
GetFullPathNameW(str.c_str(), MAX_PATH * 2, buf, 0);
|
||||
str.assign(buf);
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../default.hpp"
|
||||
|
||||
extern bool path_check_path_exists(const char* path);
|
||||
extern bool path_check_path_exists(const wchar_t* path);
|
||||
extern bool path_check_file_exists(const char* path);
|
||||
extern bool path_check_file_exists(const wchar_t* path);
|
||||
extern bool path_check_directory_exists(const char* path);
|
||||
extern bool path_check_directory_exists(const wchar_t* path);
|
||||
extern std::vector<std::string> path_get_files(const char* path);
|
||||
extern std::vector<std::wstring> path_get_files(const wchar_t* path);
|
||||
extern std::vector<std::string> path_get_directories(
|
||||
const char* path, const char** exclude_list = 0, size_t exclude_count = 0);
|
||||
extern std::vector<std::wstring> path_get_directories(
|
||||
const wchar_t* path, const wchar_t** exclude_list = 0, size_t exclude_count = 0);
|
||||
extern std::vector<std::string> path_get_directories_recursive(
|
||||
const char* path, const char** exclude_list = 0, size_t exclude_count = 0);
|
||||
extern std::vector<std::wstring> path_get_directories_recursive(
|
||||
const wchar_t* path, const wchar_t** exclude_list = 0, size_t exclude_count = 0);
|
||||
extern void path_get_full_path(std::string& str);
|
||||
extern void path_get_full_path(std::wstring& str);
|
||||
@@ -1,718 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "stream.hpp"
|
||||
|
||||
stream::stream() : buf(), length(), big_endian() {
|
||||
|
||||
}
|
||||
|
||||
stream::~stream() {
|
||||
close();
|
||||
}
|
||||
|
||||
void stream::close() {
|
||||
if (!this)
|
||||
return;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
length = 0;
|
||||
big_endian = false;
|
||||
position_stack.clear();
|
||||
position_stack.shrink_to_fit();
|
||||
}
|
||||
|
||||
int32_t stream::position_push(int64_t pos, int32_t seek) {
|
||||
position_stack.push_back(get_position());
|
||||
return set_position(pos, seek);
|
||||
}
|
||||
|
||||
void stream::position_pop() {
|
||||
if (position_stack.size() < 1)
|
||||
return;
|
||||
|
||||
int64_t position = position_stack.back();
|
||||
position_stack.pop_back();
|
||||
set_position(position, SEEK_SET);
|
||||
flush();
|
||||
}
|
||||
|
||||
int8_t stream::read_int8_t() {
|
||||
int32_t c = read_char();
|
||||
if (c != EOF)
|
||||
return (int8_t)c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t stream::read_uint8_t() {
|
||||
int32_t c = read_char();
|
||||
if (c != EOF)
|
||||
return (uint8_t)c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void stream::write_int8_t(int8_t val) {
|
||||
write_char((char)val);
|
||||
}
|
||||
|
||||
void stream::write_uint8_t(uint8_t val) {
|
||||
write_char((char)val);
|
||||
}
|
||||
|
||||
std::string stream::read_string(size_t length) {
|
||||
std::string str(length, 0);
|
||||
read(&str.front(), sizeof(char) * length);
|
||||
return str;
|
||||
}
|
||||
|
||||
std::wstring stream::read_wstring(size_t length) {
|
||||
std::wstring str(length, 0);
|
||||
read(&str.front(), sizeof(wchar_t) * length);
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string stream::read_string_null_terminated() {
|
||||
int64_t offset = get_position();
|
||||
|
||||
size_t length = read_utf8_string_null_terminated_offset_length(offset);
|
||||
if (length)
|
||||
return read_string(length);
|
||||
|
||||
std::string str = {};
|
||||
return str;
|
||||
}
|
||||
|
||||
std::wstring stream::read_wstring_null_terminated() {
|
||||
int64_t offset = get_position();
|
||||
|
||||
size_t length = read_utf16_string_null_terminated_offset_length(offset);
|
||||
if (length)
|
||||
return read_wstring(length);
|
||||
|
||||
std::wstring str = {};
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string stream::read_string_null_terminated_offset(int64_t offset) {
|
||||
if (offset) {
|
||||
size_t length = read_utf8_string_null_terminated_offset_length(offset);
|
||||
if (length) {
|
||||
position_push(offset, SEEK_SET);
|
||||
std::string str = read_string(length);
|
||||
position_pop();
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
std::string str = {};
|
||||
return str;
|
||||
}
|
||||
|
||||
std::wstring stream::read_wstring_null_terminated_offset(int64_t offset) {
|
||||
if (offset) {
|
||||
size_t length = read_utf16_string_null_terminated_offset_length(offset);
|
||||
if (length) {
|
||||
position_push(offset, SEEK_SET);
|
||||
std::wstring str = read_wstring(length);
|
||||
position_pop();
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring str = {};
|
||||
return str;
|
||||
}
|
||||
|
||||
char* stream::read_utf8_string_null_terminated() {
|
||||
int64_t offset = get_position();
|
||||
return read_utf8_string_null_terminated_offset(offset);
|
||||
}
|
||||
|
||||
wchar_t* stream::read_utf16_string_null_terminated() {
|
||||
int64_t offset = get_position();
|
||||
return read_utf16_string_null_terminated_offset(offset);
|
||||
}
|
||||
|
||||
char* stream::read_utf8_string_null_terminated_offset(int64_t offset) {
|
||||
size_t len = read_utf8_string_null_terminated_offset_length(offset);
|
||||
if (!len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* str = force_malloc<char>(len + 1);
|
||||
position_push(offset, SEEK_SET);
|
||||
read(str, len);
|
||||
str[len] = 0;
|
||||
position_pop();
|
||||
return str;
|
||||
}
|
||||
|
||||
wchar_t* stream::read_utf16_string_null_terminated_offset(int64_t offset) {
|
||||
size_t len = read_utf16_string_null_terminated_offset_length(offset);
|
||||
if (!len) {
|
||||
position_pop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
wchar_t* str = force_malloc<wchar_t>(len + 1);
|
||||
position_push(offset, SEEK_SET);
|
||||
read(str, sizeof(wchar_t) * len);
|
||||
str[len] = 0;
|
||||
position_pop();
|
||||
return str;
|
||||
}
|
||||
|
||||
size_t stream::read_utf8_string_null_terminated_length() {
|
||||
int64_t offset = get_position();
|
||||
return read_utf8_string_null_terminated_offset_length(offset);
|
||||
}
|
||||
|
||||
size_t stream::read_utf16_string_null_terminated_length() {
|
||||
int64_t offset = get_position();
|
||||
return read_utf16_string_null_terminated_offset_length(offset);
|
||||
}
|
||||
|
||||
size_t stream::read_utf8_string_null_terminated_offset_length(int64_t offset) {
|
||||
position_push(offset, SEEK_SET);
|
||||
|
||||
size_t len = 0;
|
||||
int32_t c;
|
||||
while ((c = read_char()) != EOF && c != 0)
|
||||
len++;
|
||||
|
||||
position_pop();
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t stream::read_utf16_string_null_terminated_offset_length(int64_t offset) {
|
||||
position_push(offset, SEEK_SET);
|
||||
|
||||
size_t len = 0;
|
||||
int32_t c0, c1;
|
||||
while ((c0 = read_char()) != EOF && (c1 = read_char()) != EOF
|
||||
&& (((c0 & 0xFF) | ((c1 & 0xFF) << 8)) != 0))
|
||||
len++;
|
||||
|
||||
position_pop();
|
||||
return len;
|
||||
}
|
||||
|
||||
int16_t stream::read_int16_t() {
|
||||
read(buf, sizeof(int16_t));
|
||||
return *(int16_t*)buf;
|
||||
}
|
||||
|
||||
int16_t stream::read_int16_t_reverse_endianness() {
|
||||
read(buf, sizeof(int16_t));
|
||||
int16_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_int16_t(buf);
|
||||
else
|
||||
val = *(int16_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
int16_t stream::read_int16_t_reverse_endianness(bool big_endian) {
|
||||
read(buf, sizeof(int16_t));
|
||||
int16_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_int16_t(buf);
|
||||
else
|
||||
val = *(int16_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
void stream::write_int16_t(int16_t val) {
|
||||
*(int16_t*)buf = val;
|
||||
write(buf, sizeof(int16_t));
|
||||
}
|
||||
|
||||
void stream::write_int16_t_reverse_endianness(int16_t val) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_int16_t(buf, val);
|
||||
else
|
||||
*(int16_t*)buf = val;
|
||||
write(buf, sizeof(int16_t));
|
||||
}
|
||||
|
||||
void stream::write_int16_t_reverse_endianness(int16_t val, bool big_endian) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_int16_t(buf, val);
|
||||
else
|
||||
*(int16_t*)buf = val;
|
||||
write(buf, sizeof(int16_t));
|
||||
}
|
||||
|
||||
uint16_t stream::read_uint16_t() {
|
||||
read(buf, sizeof(uint16_t));
|
||||
return *(uint16_t*)buf;
|
||||
}
|
||||
|
||||
uint16_t stream::read_uint16_t_reverse_endianness() {
|
||||
read(buf, sizeof(uint16_t));
|
||||
uint16_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_uint16_t(buf);
|
||||
else
|
||||
val = *(uint16_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
uint16_t stream::read_uint16_t_reverse_endianness(bool big_endian) {
|
||||
read(buf, sizeof(uint16_t));
|
||||
uint16_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_uint16_t(buf);
|
||||
else
|
||||
val = *(uint16_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
void stream::write_uint16_t(uint16_t val) {
|
||||
*(uint16_t*)buf = val;
|
||||
write(buf, sizeof(uint16_t));
|
||||
}
|
||||
|
||||
void stream::write_uint16_t_reverse_endianness(uint16_t val) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_uint16_t(buf, val);
|
||||
else
|
||||
*(uint16_t*)buf = val;
|
||||
write(buf, sizeof(uint16_t));
|
||||
}
|
||||
|
||||
void stream::write_uint16_t_reverse_endianness(uint16_t val, bool big_endian) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_uint16_t(buf, val);
|
||||
else
|
||||
*(uint16_t*)buf = val;
|
||||
write(buf, sizeof(uint16_t));
|
||||
}
|
||||
|
||||
int32_t stream::read_int32_t() {
|
||||
read(buf, sizeof(int32_t));
|
||||
return *(int32_t*)buf;
|
||||
}
|
||||
|
||||
int32_t stream::read_int32_t_reverse_endianness() {
|
||||
read(buf, sizeof(int32_t));
|
||||
int32_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_int32_t(buf);
|
||||
else
|
||||
val = *(int32_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
int32_t stream::read_int32_t_reverse_endianness(bool big_endian) {
|
||||
read(buf, sizeof(int32_t));
|
||||
int32_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_int32_t(buf);
|
||||
else
|
||||
val = *(int32_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
void stream::write_int32_t(int32_t val) {
|
||||
*(int32_t*)buf = val;
|
||||
write(buf, sizeof(int32_t));
|
||||
}
|
||||
|
||||
void stream::write_int32_t_reverse_endianness(int32_t val) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_int32_t(buf, val);
|
||||
else
|
||||
*(int32_t*)buf = val;
|
||||
write(buf, sizeof(int32_t));
|
||||
}
|
||||
|
||||
void stream::write_int32_t_reverse_endianness(int32_t val, bool big_endian) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_int32_t(buf, val);
|
||||
else
|
||||
*(int32_t*)buf = val;
|
||||
write(buf, sizeof(int32_t));
|
||||
}
|
||||
|
||||
uint32_t stream::read_uint32_t() {
|
||||
read(buf, sizeof(uint32_t));
|
||||
return *(uint32_t*)buf;
|
||||
}
|
||||
|
||||
uint32_t stream::read_uint32_t_reverse_endianness() {
|
||||
read(buf, sizeof(uint32_t));
|
||||
uint32_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_uint32_t(buf);
|
||||
else
|
||||
val = *(uint32_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
uint32_t stream::read_uint32_t_reverse_endianness(bool big_endian) {
|
||||
read(buf, sizeof(uint32_t));
|
||||
uint32_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_uint32_t(buf);
|
||||
else
|
||||
val = *(uint32_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
void stream::write_uint32_t(uint32_t val) {
|
||||
*(uint32_t*)buf = val;
|
||||
write(buf, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
void stream::write_uint32_t_reverse_endianness(uint32_t val) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_uint32_t(buf, val);
|
||||
else
|
||||
*(uint32_t*)buf = val;
|
||||
write(buf, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
void stream::write_uint32_t_reverse_endianness(uint32_t val, bool big_endian) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_uint32_t(buf, val);
|
||||
else
|
||||
*(uint32_t*)buf = val;
|
||||
write(buf, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
int64_t stream::read_int64_t() {
|
||||
read(buf, sizeof(int64_t));
|
||||
return *(int64_t*)buf;
|
||||
}
|
||||
|
||||
int64_t stream::read_int64_t_reverse_endianness() {
|
||||
read(buf, sizeof(int64_t));
|
||||
int64_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_int64_t(buf);
|
||||
else
|
||||
val = *(int64_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
int64_t stream::read_int64_t_reverse_endianness(bool big_endian) {
|
||||
read(buf, sizeof(int64_t));
|
||||
int64_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_int64_t(buf);
|
||||
else
|
||||
val = *(int64_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
void stream::write_int64_t(int64_t val) {
|
||||
*(int64_t*)buf = val;
|
||||
write(buf, sizeof(int64_t));
|
||||
}
|
||||
|
||||
void stream::write_int64_t_reverse_endianness(int64_t val) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_int64_t(buf, val);
|
||||
else
|
||||
*(int64_t*)buf = val;
|
||||
write(buf, sizeof(int64_t));
|
||||
}
|
||||
|
||||
void stream::write_int64_t_reverse_endianness(int64_t val, bool big_endian) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_int64_t(buf, val);
|
||||
else
|
||||
*(int64_t*)buf = val;
|
||||
write(buf, sizeof(int64_t));
|
||||
}
|
||||
|
||||
uint64_t stream::read_uint64_t() {
|
||||
read(buf, sizeof(uint64_t));
|
||||
return *(uint64_t*)buf;
|
||||
}
|
||||
|
||||
uint64_t stream::read_uint64_t_reverse_endianness() {
|
||||
read(buf, sizeof(uint64_t));
|
||||
uint64_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_uint64_t(buf);
|
||||
else
|
||||
val = *(uint64_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
uint64_t stream::read_uint64_t_reverse_endianness(bool big_endian) {
|
||||
read(buf, sizeof(uint64_t));
|
||||
uint64_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_uint64_t(buf);
|
||||
else
|
||||
val = *(uint64_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
void stream::write_uint64_t(uint64_t val) {
|
||||
*(uint64_t*)buf = val;
|
||||
write(buf, sizeof(uint64_t));
|
||||
}
|
||||
|
||||
void stream::write_uint64_t_reverse_endianness(uint64_t val) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_uint64_t(buf, val);
|
||||
else
|
||||
*(uint64_t*)buf = val;
|
||||
write(buf, sizeof(uint64_t));
|
||||
}
|
||||
|
||||
void stream::write_uint64_t_reverse_endianness(uint64_t val, bool big_endian) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_uint64_t(buf, val);
|
||||
else
|
||||
*(uint64_t*)buf = val;
|
||||
write(buf, sizeof(uint64_t));
|
||||
}
|
||||
|
||||
half_t stream::read_half_t() {
|
||||
read(buf, sizeof(half_t));
|
||||
return *(half_t*)buf;
|
||||
}
|
||||
|
||||
half_t stream::read_half_t_reverse_endianness() {
|
||||
read(buf, sizeof(half_t));
|
||||
half_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_half_t(buf);
|
||||
else
|
||||
val = *(half_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
half_t stream::read_half_t_reverse_endianness(bool big_endian) {
|
||||
read(buf, sizeof(half_t));
|
||||
half_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_half_t(buf);
|
||||
else
|
||||
val = *(half_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
void stream::write_half_t(half_t val) {
|
||||
*(half_t*)buf = val;
|
||||
write(buf, sizeof(half_t));
|
||||
}
|
||||
|
||||
void stream::write_half_t_reverse_endianness(half_t val) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_half_t(buf, val);
|
||||
else
|
||||
*(half_t*)buf = val;
|
||||
write(buf, sizeof(half_t));
|
||||
}
|
||||
|
||||
void stream::write_half_t_reverse_endianness(half_t val, bool big_endian) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_half_t(buf, val);
|
||||
else
|
||||
*(half_t*)buf = val;
|
||||
write(buf, sizeof(half_t));
|
||||
}
|
||||
|
||||
float_t stream::read_float_t() {
|
||||
read(buf, sizeof(float_t));
|
||||
return *(float_t*)buf;
|
||||
}
|
||||
|
||||
float_t stream::read_float_t_reverse_endianness() {
|
||||
read(buf, sizeof(float_t));
|
||||
float_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_float_t(buf);
|
||||
else
|
||||
val = *(float_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
float_t stream::read_float_t_reverse_endianness(bool big_endian) {
|
||||
read(buf, sizeof(float_t));
|
||||
float_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_float_t(buf);
|
||||
else
|
||||
val = *(float_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
void stream::write_float_t(float_t val) {
|
||||
*(float_t*)buf = val;
|
||||
write(buf, sizeof(float_t));
|
||||
}
|
||||
|
||||
void stream::write_float_t_reverse_endianness(float_t val) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_float_t(buf, val);
|
||||
else
|
||||
*(float_t*)buf = val;
|
||||
write(buf, sizeof(float_t));
|
||||
}
|
||||
|
||||
void stream::write_float_t_reverse_endianness(float_t val, bool big_endian) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_float_t(buf, val);
|
||||
else
|
||||
*(float_t*)buf = val;
|
||||
write(buf, sizeof(float_t));
|
||||
}
|
||||
|
||||
double_t stream::read_double_t() {
|
||||
read(buf, sizeof(double_t));
|
||||
return *(double_t*)buf;
|
||||
}
|
||||
|
||||
double_t stream::read_double_t_reverse_endianness() {
|
||||
read(buf, sizeof(double_t));
|
||||
double_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_double_t(buf);
|
||||
else
|
||||
val = *(double_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
double_t stream::read_double_t_reverse_endianness(bool big_endian) {
|
||||
read(buf, sizeof(double_t));
|
||||
double_t val;
|
||||
if (big_endian)
|
||||
val = load_reverse_endianness_double_t(buf);
|
||||
else
|
||||
val = *(double_t*)buf;
|
||||
return val;
|
||||
}
|
||||
|
||||
void stream::write_double_t(double_t val) {
|
||||
*(double_t*)buf = val;
|
||||
write(buf, sizeof(double_t));
|
||||
}
|
||||
|
||||
void stream::write_double_t_reverse_endianness(double_t val) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_double_t(buf, val);
|
||||
else
|
||||
*(double_t*)buf = val;
|
||||
write(buf, sizeof(double_t));
|
||||
}
|
||||
|
||||
void stream::write_double_t_reverse_endianness(double_t val, bool big_endian) {
|
||||
if (big_endian)
|
||||
store_reverse_endianness_double_t(buf, val);
|
||||
else
|
||||
*(double_t*)buf = val;
|
||||
write(buf, sizeof(double_t));
|
||||
}
|
||||
|
||||
void stream::write_string(const std::string& str) {
|
||||
write(str.c_str(), str.size());
|
||||
}
|
||||
|
||||
void stream::write_string(const std::string&& str) {
|
||||
write(str.c_str(), str.size());
|
||||
}
|
||||
|
||||
void stream::write_wstring(const std::wstring& str) {
|
||||
write(str.c_str(), sizeof(wchar_t) * str.size());
|
||||
}
|
||||
|
||||
void stream::write_wstring(const std::wstring&& str) {
|
||||
write(str.c_str(), sizeof(wchar_t) * str.size());
|
||||
}
|
||||
|
||||
void stream::write_string_null_terminated(const std::string& str) {
|
||||
write(str.c_str(), str.size());
|
||||
write_uint8_t(0);
|
||||
}
|
||||
|
||||
void stream::write_string_null_terminated(const std::string&& str) {
|
||||
write(str.c_str(), str.size());
|
||||
write_uint8_t(0);
|
||||
}
|
||||
|
||||
void stream::write_wstring_null_terminated(const std::wstring& str) {
|
||||
write(str.c_str(), sizeof(wchar_t) * str.size());
|
||||
write_uint16_t(0);
|
||||
}
|
||||
|
||||
void stream::write_wstring_null_terminated(const std::wstring&& str) {
|
||||
write(str.c_str(), sizeof(wchar_t) * str.size());
|
||||
write_uint16_t(0);
|
||||
}
|
||||
|
||||
void stream::write_utf8_string(const char* str) {
|
||||
write(str, utf8_length(str));
|
||||
}
|
||||
|
||||
void stream::write_utf16_string(const wchar_t* str) {
|
||||
write(str, sizeof(wchar_t) * utf16_length(str));
|
||||
}
|
||||
|
||||
void stream::write_utf8_string_null_terminated(const char* str) {
|
||||
write(str, utf8_length(str));
|
||||
write_uint8_t(0);
|
||||
}
|
||||
|
||||
void stream::write_utf16_string_null_terminated(const wchar_t* str) {
|
||||
write(str, sizeof(wchar_t) * utf16_length(str));
|
||||
write_uint16_t(0);
|
||||
}
|
||||
|
||||
int64_t stream::read_offset(int64_t offset, bool is_x) {
|
||||
int64_t val;
|
||||
if (!is_x) {
|
||||
val = read_uint32_t_reverse_endianness();
|
||||
if (val)
|
||||
val -= offset;
|
||||
}
|
||||
else {
|
||||
align_read(0x08);
|
||||
val = read_int64_t_reverse_endianness();
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
int64_t stream::read_offset_f2(int64_t offset) {
|
||||
int64_t val = read_uint32_t_reverse_endianness();
|
||||
if (val)
|
||||
val -= offset;
|
||||
return val;
|
||||
}
|
||||
|
||||
int64_t stream::read_offset_x() {
|
||||
align_read(0x08);
|
||||
int64_t val = read_int64_t_reverse_endianness();
|
||||
return val;
|
||||
}
|
||||
|
||||
void stream::write_offset(int64_t val, int64_t offset, bool is_x) {
|
||||
if (!is_x) {
|
||||
if (val)
|
||||
val += offset;
|
||||
write_uint32_t_reverse_endianness((uint32_t)val);
|
||||
}
|
||||
else {
|
||||
align_write(0x08);
|
||||
write_int64_t_reverse_endianness(val);
|
||||
}
|
||||
}
|
||||
|
||||
void stream::write_offset_f2(int64_t val, int64_t offset) {
|
||||
if (val)
|
||||
val += offset;
|
||||
write_uint32_t_reverse_endianness((uint32_t)val);
|
||||
}
|
||||
|
||||
void stream::write_offset_x(int64_t val) {
|
||||
align_write(0x08);
|
||||
write_int64_t_reverse_endianness(val);
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../default.hpp"
|
||||
#include "../half_t.hpp"
|
||||
|
||||
class stream {
|
||||
public:
|
||||
uint8_t buf[0x100];
|
||||
int64_t length;
|
||||
bool big_endian;
|
||||
std::vector<int64_t> position_stack;
|
||||
|
||||
stream();
|
||||
virtual ~stream();
|
||||
|
||||
virtual int flush() = 0;
|
||||
virtual void close();
|
||||
virtual bool check_null() = 0;
|
||||
virtual bool check_not_null() = 0;
|
||||
|
||||
virtual void align_read(size_t align) = 0;
|
||||
virtual void align_write(size_t align) = 0;
|
||||
virtual size_t read(size_t count) = 0;
|
||||
virtual size_t read(void* buf, size_t count) = 0;
|
||||
virtual size_t read(void* buf, size_t size, size_t count) = 0;
|
||||
virtual size_t write(size_t count) = 0;
|
||||
virtual size_t write(const void* buf, size_t count) = 0;
|
||||
virtual size_t write(const void* buf, size_t size, size_t count) = 0;
|
||||
virtual int32_t read_char() = 0;
|
||||
virtual int32_t write_char(char c) = 0;
|
||||
virtual int64_t get_length() = 0;
|
||||
virtual int64_t get_position() = 0;
|
||||
virtual int32_t set_position(int64_t pos, int32_t seek) = 0;
|
||||
|
||||
int32_t position_push(int64_t pos, int32_t seek);
|
||||
void position_pop();
|
||||
|
||||
int8_t read_int8_t();
|
||||
uint8_t read_uint8_t();
|
||||
void write_int8_t(int8_t val);
|
||||
void write_uint8_t(uint8_t val);
|
||||
|
||||
int16_t read_int16_t();
|
||||
int16_t read_int16_t_reverse_endianness();
|
||||
int16_t read_int16_t_reverse_endianness(bool big_endian);
|
||||
void write_int16_t(int16_t val);
|
||||
void write_int16_t_reverse_endianness(int16_t val);
|
||||
void write_int16_t_reverse_endianness(int16_t val, bool big_endian);
|
||||
|
||||
uint16_t read_uint16_t();
|
||||
uint16_t read_uint16_t_reverse_endianness();
|
||||
uint16_t read_uint16_t_reverse_endianness(bool big_endian);
|
||||
void write_uint16_t(uint16_t val);
|
||||
void write_uint16_t_reverse_endianness(uint16_t val);
|
||||
void write_uint16_t_reverse_endianness(uint16_t val, bool big_endian);
|
||||
|
||||
int32_t read_int32_t();
|
||||
int32_t read_int32_t_reverse_endianness();
|
||||
int32_t read_int32_t_reverse_endianness(bool big_endian);
|
||||
void write_int32_t(int32_t val);
|
||||
void write_int32_t_reverse_endianness(int32_t val);
|
||||
void write_int32_t_reverse_endianness(int32_t val, bool big_endian);
|
||||
|
||||
uint32_t read_uint32_t();
|
||||
uint32_t read_uint32_t_reverse_endianness();
|
||||
uint32_t read_uint32_t_reverse_endianness(bool big_endian);
|
||||
void write_uint32_t(uint32_t val);
|
||||
void write_uint32_t_reverse_endianness(uint32_t val);
|
||||
void write_uint32_t_reverse_endianness(uint32_t val, bool big_endian);
|
||||
|
||||
int64_t read_int64_t();
|
||||
int64_t read_int64_t_reverse_endianness();
|
||||
int64_t read_int64_t_reverse_endianness(bool big_endian);
|
||||
void write_int64_t(int64_t val);
|
||||
void write_int64_t_reverse_endianness(int64_t val);
|
||||
void write_int64_t_reverse_endianness(int64_t val, bool big_endian);
|
||||
|
||||
uint64_t read_uint64_t();
|
||||
uint64_t read_uint64_t_reverse_endianness();
|
||||
uint64_t read_uint64_t_reverse_endianness(bool big_endian);
|
||||
void write_uint64_t(uint64_t val);
|
||||
void write_uint64_t_reverse_endianness(uint64_t val);
|
||||
void write_uint64_t_reverse_endianness(uint64_t val, bool big_endian);
|
||||
|
||||
half_t read_half_t();
|
||||
half_t read_half_t_reverse_endianness();
|
||||
half_t read_half_t_reverse_endianness(bool big_endian);
|
||||
void write_half_t(half_t val);
|
||||
void write_half_t_reverse_endianness(half_t val);
|
||||
void write_half_t_reverse_endianness(half_t val, bool big_endian);
|
||||
|
||||
float_t read_float_t();
|
||||
float_t read_float_t_reverse_endianness();
|
||||
float_t read_float_t_reverse_endianness(bool big_endian);
|
||||
void write_float_t(float_t val);
|
||||
void write_float_t_reverse_endianness(float_t val);
|
||||
void write_float_t_reverse_endianness(float_t val, bool big_endian);
|
||||
|
||||
double_t read_double_t();
|
||||
double_t read_double_t_reverse_endianness();
|
||||
double_t read_double_t_reverse_endianness(bool big_endian);
|
||||
void write_double_t(double_t val);
|
||||
void write_double_t_reverse_endianness(double_t val);
|
||||
void write_double_t_reverse_endianness(double_t val, bool big_endian);
|
||||
|
||||
std::string read_string(size_t length);
|
||||
std::wstring read_wstring(size_t length);
|
||||
std::string read_string_null_terminated();
|
||||
std::wstring read_wstring_null_terminated();
|
||||
std::string read_string_null_terminated_offset(int64_t offset);
|
||||
std::wstring read_wstring_null_terminated_offset(int64_t offset);
|
||||
char* read_utf8_string_null_terminated();
|
||||
wchar_t* read_utf16_string_null_terminated();
|
||||
char* read_utf8_string_null_terminated_offset(int64_t offset);
|
||||
wchar_t* read_utf16_string_null_terminated_offset(int64_t offset);
|
||||
size_t read_utf8_string_null_terminated_length();
|
||||
size_t read_utf16_string_null_terminated_length();
|
||||
size_t read_utf8_string_null_terminated_offset_length(int64_t offset);
|
||||
size_t read_utf16_string_null_terminated_offset_length(int64_t offset);
|
||||
|
||||
void write_string(const std::string& str);
|
||||
void write_string(const std::string&& str);
|
||||
void write_wstring(const std::wstring& str);
|
||||
void write_wstring(const std::wstring&& str);
|
||||
void write_string_null_terminated(const std::string& str);
|
||||
void write_string_null_terminated(const std::string&& str);
|
||||
void write_wstring_null_terminated(const std::wstring& str);
|
||||
void write_wstring_null_terminated(const std::wstring&& str);
|
||||
void write_utf8_string(const char* str);
|
||||
void write_utf16_string(const wchar_t* str);
|
||||
void write_utf8_string_null_terminated(const char* str);
|
||||
void write_utf16_string_null_terminated(const wchar_t* str);
|
||||
|
||||
int64_t read_offset(int64_t offset, bool is_x);
|
||||
int64_t read_offset_f2(int64_t offset);
|
||||
int64_t read_offset_x();
|
||||
void write_offset(int64_t val, int64_t offset, bool is_x);
|
||||
void write_offset_f2(int64_t val, int64_t offset);
|
||||
void write_offset_x(int64_t val);
|
||||
|
||||
template <typename T>
|
||||
size_t read_data(T& data) {
|
||||
return read(&data, sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t write_data(const T& data) {
|
||||
return write(&data, sizeof(T));
|
||||
}
|
||||
};
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "kf.hpp"
|
||||
|
||||
void kft_check(void* src_key, kf_type src_type, void* dst_key, kf_type* dst_type) {
|
||||
switch (src_type) {
|
||||
case KEY_FRAME_TYPE_0: {
|
||||
kft0* sk = (kft0*)src_key;
|
||||
kft0* dk = (kft0*)dst_key;
|
||||
dk->frame = sk->frame;
|
||||
*dst_type = KEY_FRAME_TYPE_1;
|
||||
} break;
|
||||
case KEY_FRAME_TYPE_1: {
|
||||
kft1* sk = (kft1*)src_key;
|
||||
if (*(uint32_t*)&sk->value != 0) {
|
||||
kft1* dk = (kft1*)dst_key;
|
||||
dk->frame = sk->frame;
|
||||
dk->value = sk->value;
|
||||
*dst_type = KEY_FRAME_TYPE_1;
|
||||
}
|
||||
else {
|
||||
kft0* dk = (kft0*)dst_key;
|
||||
dk->frame = sk->frame;
|
||||
*dst_type = KEY_FRAME_TYPE_0;
|
||||
}
|
||||
} break;
|
||||
case KEY_FRAME_TYPE_2: {
|
||||
kft2* sk = (kft2*)src_key;
|
||||
if (*(uint32_t*)&sk->tangent != 0) {
|
||||
kft2* dk = (kft2*)dst_key;
|
||||
dk->frame = sk->frame;
|
||||
dk->value = sk->value;
|
||||
dk->tangent = sk->tangent;
|
||||
*dst_type = KEY_FRAME_TYPE_2;
|
||||
}
|
||||
else if (*(uint32_t*)&sk->value != 0) {
|
||||
kft1* dk = (kft1*)dst_key;
|
||||
dk->frame = sk->frame;
|
||||
dk->value = sk->value;
|
||||
*dst_type = KEY_FRAME_TYPE_1;
|
||||
}
|
||||
else {
|
||||
kft0* dk = (kft0*)dst_key;
|
||||
dk->frame = sk->frame;
|
||||
*dst_type = KEY_FRAME_TYPE_0;
|
||||
}
|
||||
} break;
|
||||
case KEY_FRAME_TYPE_3: {
|
||||
kft3* sk = (kft3*)src_key;
|
||||
if (*(uint32_t*)&sk->tangent1 != *(uint32_t*)&sk->tangent2) {
|
||||
kft3* dk = (kft3*)dst_key;
|
||||
dk->frame = sk->frame;
|
||||
dk->value = sk->value;
|
||||
dk->tangent1 = sk->tangent1;
|
||||
dk->tangent2 = sk->tangent2;
|
||||
*dst_type = KEY_FRAME_TYPE_3;
|
||||
}
|
||||
else if (*(uint32_t*)&sk->tangent1 != 0) {
|
||||
kft2* dk = (kft2*)dst_key;
|
||||
dk->frame = sk->frame;
|
||||
dk->value = sk->value;
|
||||
dk->tangent = sk->tangent1;
|
||||
*dst_type = KEY_FRAME_TYPE_2;
|
||||
}
|
||||
else if (*(uint32_t*)&sk->value != 0) {
|
||||
kft1* dk = (kft1*)dst_key;
|
||||
dk->frame = sk->frame;
|
||||
dk->value = sk->value;
|
||||
*dst_type = KEY_FRAME_TYPE_1;
|
||||
}
|
||||
else {
|
||||
kft0* dk = (kft0*)dst_key;
|
||||
dk->frame = sk->frame;
|
||||
*dst_type = KEY_FRAME_TYPE_0;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "default.hpp"
|
||||
|
||||
enum kf_type {
|
||||
KEY_FRAME_TYPE_0 = 0,
|
||||
KEY_FRAME_TYPE_1 = 1,
|
||||
KEY_FRAME_TYPE_2 = 2,
|
||||
KEY_FRAME_TYPE_3 = 3,
|
||||
};
|
||||
|
||||
struct kft0 {
|
||||
float_t frame;
|
||||
};
|
||||
|
||||
struct kft1 {
|
||||
float_t frame;
|
||||
float_t value;
|
||||
};
|
||||
|
||||
struct kft2 {
|
||||
float_t frame;
|
||||
float_t value;
|
||||
float_t tangent;
|
||||
};
|
||||
|
||||
struct kft3 {
|
||||
float_t frame;
|
||||
float_t value;
|
||||
float_t tangent1;
|
||||
float_t tangent2;
|
||||
};
|
||||
|
||||
extern void kft_check(void* src_key, kf_type src_type, void* dst_key, kf_type* dst_type);
|
||||
-2007
File diff suppressed because it is too large
Load Diff
@@ -1,345 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "default.hpp"
|
||||
#include "vec.hpp"
|
||||
#include "quat.hpp"
|
||||
|
||||
struct mat3 {
|
||||
vec3 row0;
|
||||
vec3 row1;
|
||||
vec3 row2;
|
||||
|
||||
inline mat3() : row0(), row1(), row2() {
|
||||
|
||||
}
|
||||
|
||||
inline mat3(vec3 row0, vec3 row1, vec3 row2) :
|
||||
row0(row0), row1(row1), row2(row2) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
struct mat4 {
|
||||
vec4 row0;
|
||||
vec4 row1;
|
||||
vec4 row2;
|
||||
vec4 row3;
|
||||
|
||||
inline mat4() : row0(), row1(), row2(), row3() {
|
||||
|
||||
}
|
||||
|
||||
inline mat4(vec4 row0, vec4 row1, vec4 row2, vec4 row3) :
|
||||
row0(row0), row1(row1), row2(row2), row3(row3) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
extern const mat3 mat3_identity;
|
||||
extern const mat3 mat3_null;
|
||||
extern const mat4 mat4_identity;
|
||||
extern const mat4 mat4_null;
|
||||
|
||||
extern void mat3_set(const quat* in_q1, mat3* out_m);
|
||||
extern void mat3_set(const vec3* in_axis, const float_t in_angle, mat3* out_m);
|
||||
extern void mat3_set(const vec3* in_axis, const float_t s, const float_t c, mat3* out_m);
|
||||
extern void mat3_add(const mat3* in_m1, const float_t value, mat3* out_m);
|
||||
extern void mat3_add(const mat3* in_m1, const mat3* in_m2, mat3* out_m);
|
||||
extern void mat3_sub(const mat3* in_m1, const float_t value, mat3* out_m);
|
||||
extern void mat3_sub(const mat3* in_m1, const mat3* in_m2, mat3* out_m);
|
||||
extern void mat3_mul(const mat3* in_m1, const float_t value, mat3* out_m);
|
||||
extern void mat3_mul(const mat3* in_m1, const mat3* in_m2, mat3* out_m);
|
||||
extern void mat3_mul(const mat3* in_m1, const vec3* in_axis, const float_t in_angle, mat3* out_m);
|
||||
extern void mat3_transform_vector(const mat3* in_m1, const vec2* normal, vec2* normalOut);
|
||||
extern void mat3_transform_vector(const mat3* in_m1, const vec3* normal, vec3* normalOut);
|
||||
extern void mat3_inverse_transform_vector(const mat3* in_m1, const vec2* normal, vec2* normalOut);
|
||||
extern void mat3_inverse_transform_vector(const mat3* in_m1, const vec3* normal, vec3* normalOut);
|
||||
extern void mat3_transpose(const mat3* in_m1, mat3* out_m);
|
||||
extern void mat3_invert(const mat3* in_m1, mat3* out_m);
|
||||
extern void mat3_invert_fast(const mat3* in_m1, mat3* out_m);
|
||||
extern void mat3_normalize(const mat3* in_m1, mat3* out_m);
|
||||
extern void mat3_normalize_rotation(const mat3* in_m1, mat3* out_m);
|
||||
extern float_t mat3_determinant(const mat3* in_m1);
|
||||
extern void mat3_rotate_x(float_t rad, mat3* out_m);
|
||||
extern void mat3_rotate_y(float_t rad, mat3* out_m);
|
||||
extern void mat3_rotate_z(float_t rad, mat3* out_m);
|
||||
extern void mat3_rotate_x(float_t s, float_t c, mat3* out_m);
|
||||
extern void mat3_rotate_y(float_t s, float_t c, mat3* out_m);
|
||||
extern void mat3_rotate_z(float_t s, float_t c, mat3* out_m);
|
||||
extern void mat3_rotate_xyz(float_t rad_x, float_t rad_y, float_t rad_z, mat3* out_m);
|
||||
extern void mat3_rotate_xzy(float_t rad_x, float_t rad_y, float_t rad_z, mat3* out_m);
|
||||
extern void mat3_rotate_yxz(float_t rad_x, float_t rad_y, float_t rad_z, mat3* out_m);
|
||||
extern void mat3_rotate_yzx(float_t rad_x, float_t rad_y, float_t rad_z, mat3* out_m);
|
||||
extern void mat3_rotate_zxy(float_t rad_x, float_t rad_y, float_t rad_z, mat3* out_m);
|
||||
extern void mat3_rotate_zyx(float_t rad_x, float_t rad_y, float_t rad_z, mat3* out_m);
|
||||
extern void mat3_mul_rotate_x(const mat3* in_m1, float_t rad, mat3* out_m);
|
||||
extern void mat3_mul_rotate_y(const mat3* in_m1, float_t rad, mat3* out_m);
|
||||
extern void mat3_mul_rotate_z(const mat3* in_m1, float_t rad, mat3* out_m);
|
||||
extern void mat3_mul_rotate_x(const mat3* in_m1, float_t s, float_t c, mat3* out_m);
|
||||
extern void mat3_mul_rotate_y(const mat3* in_m1, float_t s, float_t c, mat3* out_m);
|
||||
extern void mat3_mul_rotate_z(const mat3* in_m1, float_t s, float_t c, mat3* out_m);
|
||||
extern void mat3_mul_rotate_xyz(const mat3* in_m1, float_t rad_x, float_t rad_y, float_t rad_z, mat3* out_m);
|
||||
extern void mat3_mul_rotate_xzy(const mat3* in_m1, float_t rad_x, float_t rad_y, float_t rad_z, mat3* out_m);
|
||||
extern void mat3_mul_rotate_yxz(const mat3* in_m1, float_t rad_x, float_t rad_y, float_t rad_z, mat3* out_m);
|
||||
extern void mat3_mul_rotate_yzx(const mat3* in_m1, float_t rad_x, float_t rad_y, float_t rad_z, mat3* out_m);
|
||||
extern void mat3_mul_rotate_zxy(const mat3* in_m1, float_t rad_x, float_t rad_y, float_t rad_z, mat3* out_m);
|
||||
extern void mat3_mul_rotate_zyx(const mat3* in_m1, float_t rad_x, float_t rad_y, float_t rad_z, mat3* out_m);
|
||||
extern void mat3_scale(float_t sx, float_t sy, float_t sz, mat3* out_m);
|
||||
extern void mat3_scale_x(float_t s, mat3* out_m);
|
||||
extern void mat3_scale_y(float_t s, mat3* out_m);
|
||||
extern void mat3_scale_z(float_t s, mat3* out_m);
|
||||
extern void mat3_mul_scale(const mat3* in_m1, float_t sx, float_t sy, float_t sz, mat3* out_m);
|
||||
extern void mat3_mul_scale_x(const mat3* in_m1, float_t s, mat3* out_m);
|
||||
extern void mat3_mul_scale_y(const mat3* in_m1, float_t s, mat3* out_m);
|
||||
extern void mat3_mul_scale_z(const mat3* in_m1, float_t s, mat3* out_m);
|
||||
extern void mat3_get_rotation(const mat3* in_m1, vec3* out_rad);
|
||||
extern void mat3_get_scale(const mat3* in_m1, vec3* out_s);
|
||||
extern float_t mat3_get_max_scale(const mat3* in_m1);
|
||||
|
||||
extern void mat4_set(const quat* in_q1, mat4* out_m);
|
||||
extern void mat4_set(const vec3* in_v1, const vec3* in_v2, mat4* out_m);
|
||||
extern void mat4_set(const vec3* in_axis, const float_t in_angle, mat4* out_m);
|
||||
extern void mat4_set(const vec3* in_axis, const float_t s, const float_t c, mat4* out_m);
|
||||
extern void mat4_set_rotation(mat4* in_m1, const quat* in_q1);
|
||||
extern void mat4_set_rotation(mat4* in_m1, const vec3* in_axis, const float_t in_angle);
|
||||
extern void mat4_set_rotation(mat4* in_m1, const vec3* in_axis, const float_t s, const float_t c);
|
||||
extern void mat4_add(const mat4* in_m1, const float_t value, mat4* out_m);
|
||||
extern void mat4_add(const mat4* in_m1, const mat4* in_m2, mat4* out_m);
|
||||
extern void mat4_sub(const mat4* in_m1, const float_t value, mat4* out_m);
|
||||
extern void mat4_sub(const mat4* in_m1, const mat4* in_m2, mat4* out_m);
|
||||
extern void mat4_mul(const mat4* in_m1, const float_t value, mat4* out_m);
|
||||
extern void mat4_mul(const mat4* in_m1, const mat4* in_m2, mat4* out_m);
|
||||
extern void mat4_mul_rotation(const mat4* in_m1, const vec3* in_axis, const float_t angle, mat4* out_m);
|
||||
extern void mat4_transform_vector(const mat4* in_m1, const vec2* normal, vec2* normalOut);
|
||||
extern void mat4_transform_vector(const mat4* in_m1, const vec3* normal, vec3* normalOut);
|
||||
extern void mat4_transform_vector(const mat4* in_m1, const vec4* normal, vec4* normalOut);
|
||||
extern void mat4_transform_point(const mat4* in_m1, const vec2* point, vec2* pointOut);
|
||||
extern void mat4_transform_point(const mat4* in_m1, const vec3* point, vec3* pointOut);
|
||||
extern void mat4_inverse_transform_vector(const mat4* in_m1, const vec2* normal, vec2* normalOut);
|
||||
extern void mat4_inverse_transform_vector(const mat4* in_m1, const vec3* normal, vec3* normalOut);
|
||||
extern void mat4_inverse_transform_vector(const mat4* in_m1, const vec4* normal, vec4* normalOut);
|
||||
extern void mat4_inverse_transform_point(const mat4* in_m1, const vec2* point, vec2* pointOut);
|
||||
extern void mat4_inverse_transform_point(const mat4* in_m1, const vec3* point, vec3* pointOut);
|
||||
extern void mat4_transpose(const mat4* in_m1, mat4* out_m);
|
||||
extern void mat4_invert(const mat4* in_m1, mat4* out_m);
|
||||
extern void mat4_invert_rotation(const mat4* in_m1, mat4* out_m);
|
||||
extern void mat4_invert_fast(const mat4* in_m1, mat4* out_m);
|
||||
extern void mat4_invert_rotation_fast(const mat4* in_m1, mat4* out_m);
|
||||
extern void mat4_normalize(const mat4* in_m1, mat4* out_m);
|
||||
extern void mat4_normalize_rotation(const mat4* in_m1, mat4* out_m);
|
||||
extern float_t mat4_determinant(const mat4* in_m1);
|
||||
extern void mat4_rotate_x(float_t rad, mat4* out_m);
|
||||
extern void mat4_rotate_y(float_t rad, mat4* out_m);
|
||||
extern void mat4_rotate_z(float_t rad, mat4* out_m);
|
||||
extern void mat4_rotate_x(float_t s, float_t c, mat4* out_m);
|
||||
extern void mat4_rotate_y(float_t s, float_t c, mat4* out_m);
|
||||
extern void mat4_rotate_z(float_t s, float_t c, mat4* out_m);
|
||||
extern void mat4_rotate_xyz(float_t rad_x, float_t rad_y, float_t rad_z, mat4* out_m);
|
||||
extern void mat4_rotate_xzy(float_t rad_x, float_t rad_y, float_t rad_z, mat4* out_m);
|
||||
extern void mat4_rotate_yxz(float_t rad_x, float_t rad_y, float_t rad_z, mat4* out_m);
|
||||
extern void mat4_rotate_yzx(float_t rad_x, float_t rad_y, float_t rad_z, mat4* out_m);
|
||||
extern void mat4_rotate_zxy(float_t rad_x, float_t rad_y, float_t rad_z, mat4* out_m);
|
||||
extern void mat4_rotate_zyx(float_t rad_x, float_t rad_y, float_t rad_z, mat4* out_m);
|
||||
extern void mat4_mul_rotate_x(const mat4* in_m1, float_t rad, mat4* out_m);
|
||||
extern void mat4_mul_rotate_y(const mat4* in_m1, float_t rad, mat4* out_m);
|
||||
extern void mat4_mul_rotate_z(const mat4* in_m1, float_t rad, mat4* out_m);
|
||||
extern void mat4_mul_rotate_x(const mat4* in_m1, float_t s, float_t c, mat4* out_m);
|
||||
extern void mat4_mul_rotate_y(const mat4* in_m1, float_t s, float_t c, mat4* out_m);
|
||||
extern void mat4_mul_rotate_z(const mat4* in_m1, float_t s, float_t c, mat4* out_m);
|
||||
extern void mat4_mul_rotate_xyz(const mat4* in_m1, float_t rad_x, float_t rad_y, float_t rad_z, mat4* out_m);
|
||||
extern void mat4_mul_rotate_xzy(const mat4* in_m1, float_t rad_x, float_t rad_y, float_t rad_z, mat4* out_m);
|
||||
extern void mat4_mul_rotate_yxz(const mat4* in_m1, float_t rad_x, float_t rad_y, float_t rad_z, mat4* out_m);
|
||||
extern void mat4_mul_rotate_yzx(const mat4* in_m1, float_t rad_x, float_t rad_y, float_t rad_z, mat4* out_m);
|
||||
extern void mat4_mul_rotate_zxy(const mat4* in_m1, float_t rad_x, float_t rad_y, float_t rad_z, mat4* out_m);
|
||||
extern void mat4_mul_rotate_zyx(const mat4* in_m1, float_t rad_x, float_t rad_y, float_t rad_z, mat4* out_m);
|
||||
extern void mat4_scale(float_t sx, float_t sy, float_t sz, mat4* out_m);
|
||||
extern void mat4_scale_x(float_t s, mat4* out_m);
|
||||
extern void mat4_scale_y(float_t s, mat4* out_m);
|
||||
extern void mat4_scale_z(float_t s, mat4* out_m);
|
||||
extern void mat4_mul_scale(const mat4* in_m1, float_t sx, float_t sy, float_t sz, float_t sw, mat4* out_m);
|
||||
extern void mat4_mul_scale_x(const mat4* in_m1, float_t s, mat4* out_m);
|
||||
extern void mat4_mul_scale_y(const mat4* in_m1, float_t s, mat4* out_m);
|
||||
extern void mat4_mul_scale_z(const mat4* in_m1, float_t s, mat4* out_m);
|
||||
extern void mat4_scale_w_mult(const mat4* in_m1, float_t s, mat4* out_m);
|
||||
extern void mat4_scale_rot(const mat4* in_m1, float_t sx, float_t sy, float_t sz, mat4* out_m);
|
||||
extern void mat4_scale_x_rot(const mat4* in_m1, float_t s, mat4* out_m);
|
||||
extern void mat4_scale_y_rot(const mat4* in_m1, float_t s, mat4* out_m);
|
||||
extern void mat4_scale_z_rot(const mat4* in_m1, float_t s, mat4* out_m);
|
||||
extern void mat4_translate(float_t tx, float_t ty, float_t tz, mat4* out_m);
|
||||
extern void mat4_translate_x(float_t t, mat4* out_m);
|
||||
extern void mat4_translate_y(float_t t, mat4* out_m);
|
||||
extern void mat4_translate_z(float_t t, mat4* out_m);
|
||||
extern void mat4_mul_translate(const mat4* in_m1, float_t tx, float_t ty, float_t tz, mat4* out_m);
|
||||
extern void mat4_mul_translate_x(const mat4* in_m1, float_t t, mat4* out_m);
|
||||
extern void mat4_mul_translate_y(const mat4* in_m1, float_t t, mat4* out_m);
|
||||
extern void mat4_mul_translate_z(const mat4* in_m1, float_t t, mat4* out_m);
|
||||
extern void mat4_add_translate(const mat4* in_m1, float_t tx, float_t ty, float_t tz, mat4* out_m);
|
||||
extern void mat4_add_translate_x(const mat4* in_m1, float_t t, mat4* out_m);
|
||||
extern void mat4_add_translate_y(const mat4* in_m1, float_t t, mat4* out_m);
|
||||
extern void mat4_add_translate_z(const mat4* in_m1, float_t t, mat4* out_m);
|
||||
extern void mat4_to_mat3(const mat4* in_m1, mat3* out_m);
|
||||
extern void mat4_to_mat3_inverse(const mat4* in_m1, mat3* out_m);
|
||||
extern void mat4_from_mat3(const mat3* in_m1, mat4* out_m);
|
||||
extern void mat4_from_mat3_inverse(const mat3* in_m1, mat4* out_m);
|
||||
extern void mat4_clear_rot(const mat4* in_m1, mat4* out_m);
|
||||
extern void mat4_clear_trans(const mat4* in_m1, mat4* out_m);
|
||||
extern void mat4_get_scale(const mat4* in_m1, vec3* out_s);
|
||||
extern void mat4_get_rotation(const mat4* in_m1, vec3* out_rad);
|
||||
extern void mat4_get_translation(const mat4* in_m1, vec3* out_t);
|
||||
extern void mat4_set_translation(mat4* in_m1, const vec3* in_t);
|
||||
extern float_t mat4_get_max_scale(const mat4* in_m1);
|
||||
extern void mat4_blend(const mat4* in_m1, const mat4* in_m2, mat4* out_m, float_t blend);
|
||||
extern void mat4_blend_rotation(const mat4* in_m1, const mat4* in_m2, mat4* out_m, float_t blend);
|
||||
extern void mat4_lerp_rotation(const mat4* in_m1, const mat4* in_m2, mat4* out_m, float_t blend);
|
||||
extern void mat4_frustrum(float_t left, float_t right,
|
||||
float_t bottom, float_t top, float_t z_near, float_t z_far, mat4* out_m);
|
||||
extern void mat4_ortho(float_t left, float_t right,
|
||||
float_t bottom, float_t top, float_t z_near, float_t z_far, mat4* out_m);
|
||||
extern void mat4_persp(float_t fov_y, float_t aspect, float_t z_near, float_t z_far, mat4* out_m);
|
||||
extern void mat4_look_at(const vec3* eye, const vec3* target, const vec3* up, mat4* out_m);
|
||||
extern void mat4_look_at(const vec3* eye, const vec3* target, mat4* out_m);
|
||||
|
||||
inline void mat3_rotate_xyz(const vec3* rad, mat3* out_m) {
|
||||
mat3_rotate_xyz(rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat3_rotate_xzy(const vec3* rad, mat3* out_m) {
|
||||
mat3_rotate_xzy(rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat3_rotate_yxz(const vec3* rad, mat3* out_m) {
|
||||
mat3_rotate_yxz(rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat3_rotate_yzx(const vec3* rad, mat3* out_m) {
|
||||
mat3_rotate_yzx(rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat3_rotate_zxy(const vec3* rad, mat3* out_m) {
|
||||
mat3_rotate_zxy(rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat3_rotate_zyx(const vec3* rad, mat3* out_m) {
|
||||
mat3_rotate_zyx(rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat3_mul_rotate_xyz(const mat3* in_m1, const vec3* rad, mat3* out_m) {
|
||||
mat3_mul_rotate_xyz(in_m1, rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat3_mul_rotate_xzy(const mat3* in_m1, const vec3* rad, mat3* out_m) {
|
||||
mat3_mul_rotate_xzy(in_m1, rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat3_mul_rotate_yxz(const mat3* in_m1, const vec3* rad, mat3* out_m) {
|
||||
mat3_mul_rotate_yxz(in_m1, rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat3_mul_rotate_yzx(const mat3* in_m1, const vec3* rad, mat3* out_m) {
|
||||
mat3_mul_rotate_yzx(in_m1, rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat3_mul_rotate_zxy(const mat3* in_m1, const vec3* rad, mat3* out_m) {
|
||||
mat3_mul_rotate_zxy(in_m1, rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat3_mul_rotate_zyx(const mat3* in_m1, const vec3* rad, mat3* out_m) {
|
||||
mat3_mul_rotate_zyx(in_m1, rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat3_scale(const vec3* s, mat3* out_m) {
|
||||
mat3_scale(s->x, s->y, s->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat3_mul_scale(const mat3* in_m1, float_t s, mat3* out_m) {
|
||||
mat3_mul_scale(in_m1, s, s, s, out_m);
|
||||
}
|
||||
|
||||
inline void mat3_mul_scale(const mat3* in_m1, const vec3* s, mat3* out_m) {
|
||||
mat3_mul_scale(in_m1, s->x, s->y, s->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_rotate_xyz(const vec3* rad, mat4* out_m) {
|
||||
mat4_rotate_xyz(rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_rotate_xzy(const vec3* rad, mat4* out_m) {
|
||||
mat4_rotate_xzy(rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_rotate_yxz(const vec3* rad, mat4* out_m) {
|
||||
mat4_rotate_yxz(rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_rotate_yzx(const vec3* rad, mat4* out_m) {
|
||||
mat4_rotate_yzx(rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_rotate_zxy(const vec3* rad, mat4* out_m) {
|
||||
mat4_rotate_zxy(rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_rotate_zyx(const vec3* rad, mat4* out_m) {
|
||||
mat4_rotate_zyx(rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_mul_rotate_xyz(const mat4* in_m1, const vec3* rad, mat4* out_m) {
|
||||
mat4_mul_rotate_xyz(in_m1, rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_mul_rotate_xzy(const mat4* in_m1, const vec3* rad, mat4* out_m) {
|
||||
mat4_mul_rotate_xzy(in_m1, rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_mul_rotate_yxz(const mat4* in_m1, const vec3* rad, mat4* out_m) {
|
||||
mat4_mul_rotate_yxz(in_m1, rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_mul_rotate_yzx(const mat4* in_m1, const vec3* rad, mat4* out_m) {
|
||||
mat4_mul_rotate_yzx(in_m1, rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_mul_rotate_zxy(const mat4* in_m1, const vec3* rad, mat4* out_m) {
|
||||
mat4_mul_rotate_zxy(in_m1, rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_mul_rotate_zyx(const mat4* in_m1, const vec3* rad, mat4* out_m) {
|
||||
mat4_mul_rotate_zyx(in_m1, rad->x, rad->y, rad->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_scale(const vec3* s, mat4* out_m) {
|
||||
mat4_scale(s->x, s->y, s->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_mul_scale(const mat4* in_m1, float_t s, mat4* out_m) {
|
||||
mat4_mul_scale(in_m1, s, s, s, s, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_mul_scale(const mat4* in_m1, vec4* s, mat4* out_m) {
|
||||
mat4_mul_scale(in_m1, s->x, s->y, s->z, s->w, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_scale_rot(const mat4* in_m1, const float_t s, mat4* out_m) {
|
||||
mat4_scale_rot(in_m1, s, s, s, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_scale_rot(const mat4* in_m1, const vec3* s, mat4* out_m) {
|
||||
mat4_scale_rot(in_m1, s->x, s->y, s->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_translate(const vec3* s, mat4* out_m) {
|
||||
mat4_translate(s->x, s->y, s->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_mul_translate(const mat4* in_m1, const vec3* t, mat4* out_m) {
|
||||
mat4_mul_translate(in_m1, t->x, t->y, t->z, out_m);
|
||||
}
|
||||
|
||||
inline void mat4_add_translate(const mat4* in_m1, const vec3* t, mat4* out_m) {
|
||||
mat4_add_translate(in_m1, t->x, t->y, t->z, out_m);
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
|
||||
Taken from MSVC's VC/include/memory
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../default.hpp"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace prj {
|
||||
template <class T>
|
||||
bool find(std::vector<T>& vec, T& value) {
|
||||
auto begin = vec.begin();
|
||||
auto end = vec.end();
|
||||
for (auto i = begin; i != end; i++)
|
||||
if (*i == value)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void sort(std::vector<T>& vec) {
|
||||
std::sort(vec.begin(), vec.end());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void unique(std::vector<T>& vec) {
|
||||
if (vec.size() <= 1)
|
||||
return;
|
||||
|
||||
auto begin = vec.begin();
|
||||
auto end = vec.end();
|
||||
for (auto i = begin, j = begin + 1; i != end && j != end; )
|
||||
if (*i == *j) {
|
||||
std::move(j + 1, end, j);
|
||||
end--;
|
||||
}
|
||||
else {
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
|
||||
if (vec.size() != end - begin)
|
||||
vec.resize(end - begin);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void sort_unique(std::vector<T>& vec) {
|
||||
sort(vec);
|
||||
unique(vec);
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../default.hpp"
|
||||
#include <xmmintrin.h>
|
||||
#include <emmintrin.h>
|
||||
|
||||
namespace prj {
|
||||
inline int32_t extract_sign(const float_t x) {
|
||||
return _mm_movemask_ps(_mm_load_ss(&x)) & 0x01;
|
||||
}
|
||||
|
||||
inline float_t ceilf(const float_t x) {
|
||||
int32_t x_int = (int32_t)x;
|
||||
if (x_int != 0x80000000 && (float_t)x_int != x)
|
||||
return (float_t)(x_int + !extract_sign(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
inline float_t floorf(const float_t x) {
|
||||
int32_t x_int = (int32_t)x;
|
||||
if (x_int != 0x80000000 && (float_t)x_int != x)
|
||||
return (float_t)(x_int - extract_sign(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
inline float_t roundf(const float_t x) {
|
||||
if (x >= 0.0f)
|
||||
return floorf(x + 0.5f);
|
||||
else
|
||||
return ceilf(x - 0.5f);
|
||||
}
|
||||
|
||||
inline float_t truncf(const float_t x) {
|
||||
if (x >= 0.0f)
|
||||
return floorf(x);
|
||||
else
|
||||
return ceilf(x);
|
||||
}
|
||||
|
||||
inline int32_t extract_sign(const double_t x) {
|
||||
return _mm_movemask_pd(_mm_load_sd(&x)) & 0x01;
|
||||
}
|
||||
|
||||
inline double_t ceil(const double_t x) {
|
||||
int64_t x_int = (int64_t)x;
|
||||
if (x_int != 0x8000000000000000 && (float_t)x_int != x)
|
||||
return (float_t)(x_int + !extract_sign(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
inline double_t floor(const double_t x) {
|
||||
int64_t x_int = (int64_t)x;
|
||||
if (x_int != 0x8000000000000000 && (float_t)x_int != x)
|
||||
return (float_t)(x_int - extract_sign(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
inline double_t roundf(const double_t x) {
|
||||
if (x >= 0.0f)
|
||||
return floor(x + 0.5f);
|
||||
else
|
||||
return ceil(x - 0.5f);
|
||||
}
|
||||
|
||||
inline double_t truncf(const double_t x) {
|
||||
if (x >= 0.0f)
|
||||
return floor(x);
|
||||
else
|
||||
return ceil(x);
|
||||
}
|
||||
}
|
||||
@@ -1,284 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
|
||||
Taken from MSVC's VC/include/memory
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../default.hpp"
|
||||
|
||||
namespace prj {
|
||||
template <typename T>
|
||||
class ref_count {
|
||||
private:
|
||||
uint32_t uses;
|
||||
uint32_t weaks;
|
||||
T* ptr;
|
||||
void(*delete_this_func)(ref_count<T>* ref);
|
||||
void(*destroy_func)(ref_count<T>* ref, T* ptr);
|
||||
|
||||
protected:
|
||||
ref_count<T>() {
|
||||
uses = 1;
|
||||
weaks = 1;
|
||||
ptr = nullptr;
|
||||
delete_this_func = delete_this;
|
||||
destroy_func = destroy;
|
||||
}
|
||||
|
||||
public:
|
||||
~ref_count<T>() {
|
||||
|
||||
}
|
||||
|
||||
ref_count(T* ptr) {
|
||||
uses = 1;
|
||||
weaks = 1;
|
||||
this->ptr = ptr;
|
||||
delete_this_func = delete_this;
|
||||
destroy_func = destroy;
|
||||
}
|
||||
|
||||
bool expired() const {
|
||||
return !use_count();
|
||||
}
|
||||
|
||||
void decrement() {
|
||||
if (!--uses) {
|
||||
destroy_func(this, ptr);
|
||||
decrement_weaks();
|
||||
}
|
||||
}
|
||||
|
||||
void decrement_weaks() {
|
||||
if (!--weaks)
|
||||
delete_this_func(this);
|
||||
}
|
||||
|
||||
uint32_t use_count() const {
|
||||
return uses;
|
||||
}
|
||||
|
||||
void increment() {
|
||||
uses++;
|
||||
}
|
||||
|
||||
void increment_weaks() {
|
||||
weaks++;
|
||||
}
|
||||
|
||||
private:
|
||||
static void delete_this(ref_count<T>* ref) {
|
||||
delete ref;
|
||||
}
|
||||
|
||||
static void destroy(ref_count<T>* ref, T* ptr) {
|
||||
delete ptr;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class shared_ptr;
|
||||
|
||||
template<class T>
|
||||
class ptr_base {
|
||||
public:
|
||||
typedef ptr_base<T> my_t;
|
||||
|
||||
ptr_base() : ptr(0), ref(0) {
|
||||
|
||||
}
|
||||
|
||||
ptr_base(my_t&& right) noexcept : ptr(0), ref(0) {
|
||||
assign(std::forward<my_t>(right));
|
||||
}
|
||||
|
||||
template<class U>
|
||||
ptr_base(ptr_base<U>&& right)
|
||||
: ptr(right.ptr), ref(right.ref) {
|
||||
right.ptr = 0;
|
||||
right.ref = 0;
|
||||
}
|
||||
|
||||
my_t& operator=(my_t&& right) {
|
||||
assign(std::forward<my_t>(right));
|
||||
return *this;
|
||||
}
|
||||
|
||||
void assign(my_t&& right) {
|
||||
swap(right);
|
||||
}
|
||||
|
||||
uint32_t use_count() const {
|
||||
return ref ? ref->use_count() : 0;
|
||||
}
|
||||
|
||||
void swap(ptr_base& right) {
|
||||
std::swap(ref, right.ref);
|
||||
std::swap(ptr, right.ptr);
|
||||
}
|
||||
|
||||
template<class U>
|
||||
bool owner_before(const ptr_base<U>& right) const {
|
||||
return ref < right.ref;
|
||||
}
|
||||
|
||||
T* get() const {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
bool expired() const {
|
||||
return !ref || ref->expired();
|
||||
}
|
||||
|
||||
void decrement() {
|
||||
if (ref)
|
||||
ref->decrement();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
reset(0, 0);
|
||||
}
|
||||
|
||||
template<class U>
|
||||
void reset(const ptr_base<U>& other) {
|
||||
reset(other.ptr, other.ref);
|
||||
}
|
||||
|
||||
template<class U>
|
||||
void reset(T* ptr, const ptr_base<U>& other) {
|
||||
reset(ptr, other.ref);
|
||||
}
|
||||
|
||||
void reset(T* other_ptr, ref_count<T>* other_ref) {
|
||||
if (other_ref)
|
||||
other_ref->increment();
|
||||
reset_base(other_ptr, other_ref);
|
||||
}
|
||||
|
||||
void reset_base(T* other_ptr, ref_count<T>* other_ref) {
|
||||
if (ref)
|
||||
ref->decrement();
|
||||
ref = other_ref;
|
||||
ptr = other_ptr;
|
||||
}
|
||||
|
||||
void decrement_weaks() {
|
||||
if (ref)
|
||||
ref->decrement_weaks();
|
||||
}
|
||||
|
||||
private:
|
||||
T* ptr;
|
||||
ref_count<T>* ref;
|
||||
template<class U>
|
||||
friend class ptr_base;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class shared_ptr : public ptr_base<T> {
|
||||
public:
|
||||
typedef shared_ptr<T> my_t;
|
||||
typedef ptr_base<T> my_base;
|
||||
|
||||
shared_ptr() {
|
||||
|
||||
}
|
||||
|
||||
template<class U>
|
||||
explicit shared_ptr(U* ptr) {
|
||||
reset_ptr(ptr);
|
||||
}
|
||||
|
||||
template<class U>
|
||||
shared_ptr(nullptr_t) {
|
||||
reset_ptr((T*)0);
|
||||
}
|
||||
|
||||
shared_ptr(const my_t& other) {
|
||||
ptr_base<T>::reset(other);
|
||||
}
|
||||
|
||||
shared_ptr(my_t&& right) noexcept : my_base(std::forward<my_t>(right)) {
|
||||
|
||||
}
|
||||
|
||||
my_t& operator=(my_t&& right) noexcept {
|
||||
shared_ptr(std::move(right)).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class U>
|
||||
my_t& operator=(shared_ptr<U>&& right) {
|
||||
shared_ptr(std::move(right)).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~shared_ptr() {
|
||||
this->decrement();
|
||||
}
|
||||
|
||||
my_t& operator=(const my_t& right) {
|
||||
shared_ptr(right).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class U>
|
||||
my_t& operator=(const shared_ptr<U>& right) {
|
||||
shared_ptr(right).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
shared_ptr().swap(*this);
|
||||
}
|
||||
|
||||
template<class U>
|
||||
void reset(U* ptr) {
|
||||
shared_ptr(ptr).swap(*this);
|
||||
}
|
||||
|
||||
T* operator->() const {
|
||||
return this->get();
|
||||
}
|
||||
|
||||
bool unique() const {
|
||||
return this->use_count() == 1;
|
||||
}
|
||||
|
||||
operator bool() const {
|
||||
return !!this->get();
|
||||
}
|
||||
|
||||
private:
|
||||
template<class U>
|
||||
void reset_ptr(U* ptr) {
|
||||
try {
|
||||
this->reset_base(ptr, new ref_count<U>(ptr));
|
||||
}
|
||||
catch (...) {
|
||||
delete ptr;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
bool operator==(const shared_ptr<T>& left,
|
||||
const shared_ptr<U>& right) {
|
||||
return left.get() == right.get();
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
bool operator!=(const shared_ptr<T>& left,
|
||||
const shared_ptr<U>& right) {
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void swap(shared_ptr<T>& left, shared_ptr<T>& right) {
|
||||
left.swap(right);
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "stack_allocator.hpp"
|
||||
|
||||
namespace prj {
|
||||
void* stack_allocator::allocate(size_t size) {
|
||||
#if PRJ_STACK_ALLOCATOR_ORIGINAL_CODE
|
||||
stack_allocator_node* node = (stack_allocator_node*)begin;
|
||||
#else
|
||||
stack_allocator_node* node = next;
|
||||
#endif
|
||||
size = max_def(size, 1);
|
||||
size = align_val(size, 8);
|
||||
|
||||
#if PRJ_STACK_ALLOCATOR_ORIGINAL_CODE
|
||||
bool allocate = !node || (capacity_end - end) < (ssize_t)size;
|
||||
#else
|
||||
bool allocate = true;
|
||||
if (node) {
|
||||
stack_allocator_node* last_node = 0;
|
||||
while (node) {
|
||||
if ((size_t)(node->capacity - node->size) >= size)
|
||||
last_node = node;
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
if (last_node) {
|
||||
node = last_node;
|
||||
allocate = false;
|
||||
}
|
||||
else
|
||||
node = next;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (allocate) {
|
||||
#if PRJ_STACK_ALLOCATOR_ORIGINAL_CODE
|
||||
size_t data_size = this->size;
|
||||
#else
|
||||
size_t data_size = node ? (node->capacity + sizeof(stack_allocator_node)) * 2 : this->size;
|
||||
#endif
|
||||
size_t _size = size + sizeof(stack_allocator_node);
|
||||
size_t mults = 0;
|
||||
while (data_size < _size) {
|
||||
data_size *= 2;
|
||||
if (data_size >= _size)
|
||||
break;
|
||||
|
||||
mults++;
|
||||
data_size *= 2;
|
||||
|
||||
if (mults >= 16) {
|
||||
if (data_size < _size)
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
stack_allocator_node* new_node = (stack_allocator_node*)malloc(data_size);
|
||||
if (!new_node)
|
||||
return 0;
|
||||
|
||||
#if PRJ_STACK_ALLOCATOR_ORIGINAL_CODE
|
||||
new_node->next = node;
|
||||
begin = (uint8_t*)new_node;
|
||||
end = (uint8_t*)new_node + sizeof(stack_allocator_node);
|
||||
capacity_end = (uint8_t*)new_node + data_size;
|
||||
#else
|
||||
new_node->next = node;
|
||||
new_node->size = 0;
|
||||
new_node->capacity = data_size - sizeof(stack_allocator_node);
|
||||
next = new_node;
|
||||
#endif
|
||||
node = new_node;
|
||||
}
|
||||
|
||||
#if PRJ_STACK_ALLOCATOR_ORIGINAL_CODE
|
||||
uint8_t* data = end;
|
||||
end += size;
|
||||
#else
|
||||
uint8_t* data = node->data + node->size;
|
||||
node->size += size;
|
||||
#endif
|
||||
memset(data, 0, size);
|
||||
return data;
|
||||
}
|
||||
|
||||
void stack_allocator::deallocate() {
|
||||
#if PRJ_STACK_ALLOCATOR_ORIGINAL_CODE
|
||||
stack_allocator_node* node = (stack_allocator_node*)begin;
|
||||
#else
|
||||
stack_allocator_node* node = next;
|
||||
#endif
|
||||
while (node) {
|
||||
stack_allocator_node* next_node = node->next;
|
||||
free(node);
|
||||
node = next_node;
|
||||
}
|
||||
next = 0;
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../default.hpp"
|
||||
|
||||
#define PRJ_STACK_ALLOCATOR_ORIGINAL_CODE 0
|
||||
|
||||
namespace prj {
|
||||
struct stack_allocator_node {
|
||||
stack_allocator_node * next;
|
||||
#if !PRJ_STACK_ALLOCATOR_ORIGINAL_CODE
|
||||
size_t size;
|
||||
size_t capacity;
|
||||
#endif
|
||||
#pragma warning(suppress: 4200)
|
||||
uint8_t data[];
|
||||
};
|
||||
|
||||
struct stack_allocator {
|
||||
size_t size;
|
||||
#if PRJ_STACK_ALLOCATOR_ORIGINAL_CODE
|
||||
uint8_t* begin;
|
||||
uint8_t* end;
|
||||
uint8_t* capacity_end;
|
||||
#else
|
||||
stack_allocator_node* next;
|
||||
#endif
|
||||
|
||||
#if PRJ_STACK_ALLOCATOR_ORIGINAL_CODE
|
||||
inline stack_allocator() : begin(), end(), capacity_end() {
|
||||
size = 4000;
|
||||
}
|
||||
#else
|
||||
inline stack_allocator() : next() {
|
||||
size = 4000;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline ~stack_allocator() {
|
||||
deallocate();
|
||||
}
|
||||
|
||||
void* allocate(size_t size);
|
||||
void deallocate();
|
||||
|
||||
template <typename T>
|
||||
inline T* allocate() {
|
||||
return new((T*)allocate(sizeof(T))) T;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T* allocate(size_t size) {
|
||||
if (!size)
|
||||
return 0;
|
||||
|
||||
T* arr = (T*)allocate(sizeof(T) * size);
|
||||
for (size_t i = 0; i < size; i++)
|
||||
new(&arr[i]) T();
|
||||
return arr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T* allocate(const T* src) {
|
||||
if (!src)
|
||||
return 0;
|
||||
|
||||
return new((T*)allocate(sizeof(T))) T(*src);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T* allocate(const T* src, size_t size) {
|
||||
if (!src || !size)
|
||||
return 0;
|
||||
|
||||
T* dst = (T*)allocate(sizeof(T) * size);
|
||||
for (size_t i = 0; i < size; i++)
|
||||
new(&dst[i]) T(src[i]);
|
||||
return dst;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "time.hpp"
|
||||
#include <time.h>
|
||||
|
||||
namespace prj {
|
||||
prj::time prj::time::get_default() {
|
||||
static prj::time start_of_2005 = prj::strptime("2005-01-01 00:00:00");
|
||||
return start_of_2005;
|
||||
}
|
||||
|
||||
prj::time strptime(std::string& str) {
|
||||
int32_t year;
|
||||
int32_t month;
|
||||
int32_t day;
|
||||
int32_t hour;
|
||||
int32_t min;
|
||||
int32_t sec;
|
||||
if (sscanf_s(str.c_str(), "%4d-%2d-%2d %2d:%2d:%2d", &year, &month, &day, &hour, &min, &sec) == 6) {
|
||||
struct tm time;
|
||||
time.tm_isdst = -1;
|
||||
time.tm_year = year - 1900;
|
||||
time.tm_mon = month - 1;
|
||||
time.tm_mday = day;
|
||||
time.tm_hour = hour;
|
||||
time.tm_min = min;
|
||||
time.tm_sec = sec;
|
||||
return prj::time(_mkgmtime(&time));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
prj::time strptime(std::string&& str) {
|
||||
return strptime(str);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../default.hpp"
|
||||
|
||||
namespace prj {
|
||||
struct time {
|
||||
time_t value;
|
||||
|
||||
inline time() {
|
||||
value = -1;
|
||||
}
|
||||
|
||||
inline time(time_t value) {
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
static prj::time get_default();
|
||||
};
|
||||
|
||||
prj::time strptime(std::string& str);
|
||||
prj::time strptime(std::string&& str);
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
|
||||
Taken from MSVC's VC/include/memory
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../default.hpp"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace prj {
|
||||
template <class T, class U>
|
||||
class vector_pair : public std::vector<std::pair<T, U>> {
|
||||
public:
|
||||
using value_pair = std::pair<T, U>;
|
||||
|
||||
inline void push_back(const T& first, const U& second) {
|
||||
push_back({ first, second });
|
||||
}
|
||||
|
||||
inline void push_back(const T& first, U&& second) {
|
||||
push_back({ first, second });
|
||||
}
|
||||
|
||||
inline void push_back(T&& first, const U& second) {
|
||||
push_back({ first, second });
|
||||
}
|
||||
|
||||
inline void push_back(T&& first, U&& second) {
|
||||
push_back({ first, second });
|
||||
}
|
||||
|
||||
inline void push_back(const value_pair& value) {
|
||||
std::vector<std::pair<T, U>>::push_back(value);
|
||||
}
|
||||
|
||||
inline void push_back(value_pair&& value) {
|
||||
std::vector<std::pair<T, U>>::push_back(value);
|
||||
}
|
||||
|
||||
inline void sort() {
|
||||
std::sort(this->begin(), this->end(),
|
||||
[](const std::pair<T, U>& a, const std::pair<T, U>& b) {
|
||||
return a.first < b.first;
|
||||
});
|
||||
}
|
||||
|
||||
inline void unique() {
|
||||
if (this->size() <= 1)
|
||||
return;
|
||||
|
||||
auto begin = this->begin();
|
||||
auto end = this->end();
|
||||
for (auto i = begin, j = begin + 1; i != end && j != end; )
|
||||
if (i->first == j->first) {
|
||||
std::move(j + 1, end, j);
|
||||
end--;
|
||||
}
|
||||
else {
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
|
||||
if (this->size() != end - begin)
|
||||
this->resize(end - begin);
|
||||
}
|
||||
|
||||
inline void sort_unique() {
|
||||
sort();
|
||||
unique();
|
||||
}
|
||||
|
||||
inline typename auto find(const T& key) {
|
||||
auto k = this->begin();
|
||||
size_t l = this->size();
|
||||
size_t temp;
|
||||
while (l > 0) {
|
||||
if (k[temp = l / 2].first >= key)
|
||||
l /= 2;
|
||||
else {
|
||||
k += temp + 1;
|
||||
l -= temp + 1;
|
||||
}
|
||||
}
|
||||
if (k == this->end() || key < k->first)
|
||||
return this->end();
|
||||
return k;
|
||||
}
|
||||
|
||||
inline typename auto find(const T& key) const {
|
||||
auto k = this->begin();
|
||||
size_t l = this->size();
|
||||
size_t temp;
|
||||
while (l > 0) {
|
||||
if (k[temp = l / 2].first >= key)
|
||||
l /= 2;
|
||||
else {
|
||||
k += temp + 1;
|
||||
l -= temp + 1;
|
||||
}
|
||||
}
|
||||
if (k == this->end() || key < k->first)
|
||||
return this->end();
|
||||
return k;
|
||||
}
|
||||
|
||||
inline typename auto find(T&& key) {
|
||||
auto k = this->begin();
|
||||
size_t l = this->size();
|
||||
size_t temp;
|
||||
while (l > 0) {
|
||||
if (k[temp = l / 2].first >= key)
|
||||
l /= 2;
|
||||
else {
|
||||
k += temp + 1;
|
||||
l -= temp + 1;
|
||||
}
|
||||
}
|
||||
if (k == this->end() || key < k->first)
|
||||
return this->end();
|
||||
return k;
|
||||
}
|
||||
|
||||
inline typename auto find(T&& key) const {
|
||||
auto k = this->begin();
|
||||
size_t l = this->size();
|
||||
size_t temp;
|
||||
while (l > 0) {
|
||||
if (k[temp = l / 2].first >= key)
|
||||
l /= 2;
|
||||
else {
|
||||
k += temp + 1;
|
||||
l -= temp + 1;
|
||||
}
|
||||
}
|
||||
if (k == this->end() || key < k->first)
|
||||
return this->end();
|
||||
return k;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,262 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
|
||||
Taken from MSVC's VC/include/memory
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../default.hpp"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace prj {
|
||||
template <class T, class U>
|
||||
class vector_pair_combine {
|
||||
public:
|
||||
using value_pair = std::pair<T, U>;
|
||||
using iterator = typename std::vector<value_pair>::iterator;
|
||||
using const_iterator = typename std::vector<value_pair>::const_iterator;
|
||||
std::vector<value_pair> data;
|
||||
std::vector<value_pair> new_data;
|
||||
|
||||
inline auto find(const T& key) {
|
||||
auto k = data.begin();
|
||||
size_t l = data.size();
|
||||
size_t temp;
|
||||
while (l > 0) {
|
||||
if (k[temp = l / 2].first >= key)
|
||||
l /= 2;
|
||||
else {
|
||||
k += temp + 1;
|
||||
l -= temp + 1;
|
||||
}
|
||||
}
|
||||
if (k == data.end() || key < k->first)
|
||||
return data.end();
|
||||
return k;
|
||||
}
|
||||
|
||||
inline auto find(const T& key) const {
|
||||
auto k = data.begin();
|
||||
size_t l = data.size();
|
||||
size_t temp;
|
||||
while (l > 0) {
|
||||
if (k[temp = l / 2].first >= key)
|
||||
l /= 2;
|
||||
else {
|
||||
k += temp + 1;
|
||||
l -= temp + 1;
|
||||
}
|
||||
}
|
||||
if (k == data.end() || key < k->first)
|
||||
return data.end();
|
||||
return k;
|
||||
}
|
||||
|
||||
inline auto find(T&& key) {
|
||||
auto k = data.begin();
|
||||
size_t l = data.size();
|
||||
size_t temp;
|
||||
while (l > 0) {
|
||||
if (k[temp = l / 2].first >= key)
|
||||
l /= 2;
|
||||
else {
|
||||
k += temp + 1;
|
||||
l -= temp + 1;
|
||||
}
|
||||
}
|
||||
if (k == data.end() || key < k->first)
|
||||
return data.end();
|
||||
return k;
|
||||
}
|
||||
|
||||
inline auto find(T&& key) const {
|
||||
auto k = data.begin();
|
||||
size_t l = data.size();
|
||||
size_t temp;
|
||||
while (l > 0) {
|
||||
if (k[temp = l / 2].first >= key)
|
||||
l /= 2;
|
||||
else {
|
||||
k += temp + 1;
|
||||
l -= temp + 1;
|
||||
}
|
||||
}
|
||||
if (k == data.end() || key < k->first)
|
||||
return data.end();
|
||||
return k;
|
||||
}
|
||||
|
||||
inline void combine() {
|
||||
if (data.size() > 1)
|
||||
std::sort(data.begin(), data.end(),
|
||||
[](const value_pair& a, const value_pair& b) {
|
||||
return a.first < b.first;
|
||||
});
|
||||
|
||||
for (auto& i : new_data) {
|
||||
auto elem = find(i.first);
|
||||
if (elem != data.end())
|
||||
elem->second = i.second;
|
||||
else
|
||||
data.push_back(i);
|
||||
}
|
||||
|
||||
new_data.clear();
|
||||
|
||||
if (data.size() > 1) {
|
||||
std::sort(data.begin(), data.end(),
|
||||
[](const value_pair& a, const value_pair& b) {
|
||||
return a.first < b.first;
|
||||
});
|
||||
|
||||
auto begin = data.begin();
|
||||
auto end = data.end();
|
||||
for (auto i = begin, j = begin + 1; i != end && j != end; )
|
||||
if (i->first == j->first) {
|
||||
std::move(j + 1, end, j);
|
||||
end--;
|
||||
}
|
||||
else {
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
|
||||
if (data.size() != end - begin)
|
||||
data.resize(end - begin);
|
||||
}
|
||||
}
|
||||
|
||||
inline auto begin() {
|
||||
return data.begin();
|
||||
}
|
||||
|
||||
inline auto begin() const {
|
||||
return data.begin();
|
||||
}
|
||||
|
||||
inline auto cbegin() const {
|
||||
return data.cbegin();
|
||||
}
|
||||
|
||||
inline auto end() {
|
||||
return data.end();
|
||||
}
|
||||
|
||||
inline auto end() const {
|
||||
return data.end();
|
||||
}
|
||||
|
||||
inline auto cend() const {
|
||||
return data.cend();
|
||||
}
|
||||
|
||||
inline auto rbegin() {
|
||||
return data.rbegin();
|
||||
}
|
||||
|
||||
inline auto rbegin() const {
|
||||
return data.rbegin();
|
||||
}
|
||||
|
||||
inline auto crbegin() const {
|
||||
return data.crbegin();
|
||||
}
|
||||
|
||||
inline auto rend() {
|
||||
return data.rend();
|
||||
}
|
||||
|
||||
inline auto rend() const {
|
||||
return data.rend();
|
||||
}
|
||||
|
||||
inline auto crend() const {
|
||||
return data.crend();
|
||||
}
|
||||
|
||||
inline void push_back(const T& first, const U& second) {
|
||||
new_data.push_back({ first, second });
|
||||
}
|
||||
|
||||
inline void push_back(const T& first, U&& second) {
|
||||
new_data.push_back({ first, second });
|
||||
}
|
||||
|
||||
inline void push_back(T&& first, const U& second) {
|
||||
new_data.push_back({ first, second });
|
||||
}
|
||||
|
||||
inline void push_back(T&& first, U&& second) {
|
||||
new_data.push_back({ first, second });
|
||||
}
|
||||
|
||||
inline void push_back(const value_pair& value) {
|
||||
new_data.push_back(value);
|
||||
}
|
||||
|
||||
inline void push_back(value_pair&& value) {
|
||||
new_data.push_back(value);
|
||||
}
|
||||
|
||||
inline auto erase(const_iterator where) noexcept {
|
||||
return data.erase(where);
|
||||
}
|
||||
|
||||
inline auto erase(const_iterator first, const_iterator last) noexcept {
|
||||
return data.erase(first, last);
|
||||
}
|
||||
|
||||
inline void clear() noexcept {
|
||||
data.clear();
|
||||
new_data.clear();
|
||||
}
|
||||
|
||||
inline void shrink_to_fit() noexcept {
|
||||
data.shrink_to_fit();
|
||||
new_data.shrink_to_fit();
|
||||
}
|
||||
|
||||
inline void reserve(size_t new_capacity) {
|
||||
new_data.reserve(new_capacity);
|
||||
}
|
||||
|
||||
inline size_t size() const {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
inline value_pair& operator[](const size_t pos) noexcept {
|
||||
return data[pos];
|
||||
}
|
||||
|
||||
inline const value_pair& operator[](const size_t pos) const noexcept {
|
||||
return data[pos];
|
||||
}
|
||||
|
||||
inline value_pair& at(const size_t pos) {
|
||||
return data.at(pos);
|
||||
}
|
||||
|
||||
inline const value_pair& at(const size_t pos) const {
|
||||
return data.at(pos);
|
||||
}
|
||||
|
||||
inline value_pair& front() noexcept {
|
||||
return data.front();
|
||||
}
|
||||
|
||||
inline const value_pair& front() const noexcept {
|
||||
return data.front();
|
||||
}
|
||||
|
||||
inline value_pair& back() noexcept {
|
||||
return data.back();
|
||||
}
|
||||
|
||||
inline const value_pair& back() const noexcept {
|
||||
return data.back();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "quat.hpp"
|
||||
#include <pmmintrin.h>
|
||||
#include <xmmintrin.h>
|
||||
|
||||
static const quat quat_identity = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
@@ -1,397 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "default.hpp"
|
||||
#include "vec.hpp"
|
||||
|
||||
struct quat {
|
||||
float_t x;
|
||||
float_t y;
|
||||
float_t z;
|
||||
float_t w;
|
||||
|
||||
quat();
|
||||
quat(float_t value);
|
||||
quat(float_t x, float_t y, float_t z, float_t w);
|
||||
quat(const vec3& axis, const float_t angle);
|
||||
quat(float_t m00, float_t m01, float_t m02, float_t m10,
|
||||
float_t m11, float_t m12, float_t m20, float_t m21, float_t m22);
|
||||
|
||||
static __m128 load_xmm(const float_t data);
|
||||
static __m128 load_xmm(const quat& data);
|
||||
static __m128 load_xmm(const quat&& data);
|
||||
static quat store_xmm(const __m128& data);
|
||||
static quat store_xmm(const __m128&& data);
|
||||
|
||||
static quat mul(const quat& in_q1, const quat& in_q2);
|
||||
|
||||
static float_t dot(const quat& left, const quat& right);
|
||||
static float_t length(const quat& left);
|
||||
static float_t length_squared(const quat& left);
|
||||
static float_t distance(const quat& left, const quat& right);
|
||||
static float_t distance_squared(const quat& left, const quat& right);
|
||||
static quat abs(const quat& left);
|
||||
static quat lerp(const quat& left, const quat& right, const float_t blend);
|
||||
static quat slerp(const quat& left, const quat& right, const float_t blend);
|
||||
static quat normalize(const quat& left);
|
||||
static quat normalize_rcp(const quat& left);
|
||||
static quat rcp(const quat& left);
|
||||
static quat min(const quat& min, const quat& max);
|
||||
static quat max(const quat& min, const quat& max);
|
||||
static quat clamp(const quat& left, const quat& min, const quat& max);
|
||||
static quat clamp(const quat& left, const float_t min, const float_t max);
|
||||
static quat mult_min_max(const quat& left, const quat& min, const quat& max);
|
||||
static quat mult_min_max(const quat& left, const float_t min, const float_t max);
|
||||
static quat div_min_max(const quat& left, const quat& min, const quat& max);
|
||||
static quat div_min_max(const quat& left, const float_t min, const float_t max);
|
||||
};
|
||||
|
||||
extern const quat quat_identity;
|
||||
|
||||
inline quat::quat() : x(), y(), z(), w() {
|
||||
|
||||
}
|
||||
|
||||
inline quat::quat(float_t value) : x(value), y(value), z(value), w(value) {
|
||||
|
||||
}
|
||||
|
||||
inline quat::quat(float_t x, float_t y, float_t z, float_t w) : x(x), y(y), z(z), w(w) {
|
||||
|
||||
}
|
||||
|
||||
inline quat::quat(const vec3& axis, const float_t angle) {
|
||||
vec3 _axis = vec3::normalize(axis) * sinf(angle * 0.5f);
|
||||
x = _axis.x;
|
||||
y = _axis.y;
|
||||
z = _axis.z;
|
||||
w = cosf(angle * 0.5f);
|
||||
}
|
||||
|
||||
inline quat::quat(float_t m00, float_t m01, float_t m02, float_t m10,
|
||||
float_t m11, float_t m12, float_t m20, float_t m21, float_t m22) {
|
||||
if (m00 + m11 + m22 >= 0.0f) {
|
||||
float_t sq = sqrtf(m00 + m11 + m22 + 1.0f);
|
||||
w = sq * 0.5f;
|
||||
sq = 0.5f / sq;
|
||||
x = (m21 - m12) * sq;
|
||||
y = (m02 - m20) * sq;
|
||||
z = (m10 - m01) * sq;
|
||||
return;
|
||||
}
|
||||
|
||||
float_t max = max_def(m22, max_def(m11, m00));
|
||||
if (max == m00) {
|
||||
float_t sq = sqrtf(m00 - (m11 + m22) + 1.0f);
|
||||
x = sq * 0.5f;
|
||||
sq = 0.5f / sq;
|
||||
y = (m01 + m10) * sq;
|
||||
z = (m02 + m20) * sq;
|
||||
w = (m21 - m12) * sq;
|
||||
}
|
||||
else if (max == m11) {
|
||||
float_t sq = sqrtf(m11 - (m00 + m22) + 1.0f);
|
||||
y = sq * 0.5f;
|
||||
sq = 0.5f / sq;
|
||||
x = (m01 + m10) * sq;
|
||||
z = (m12 + m21) * sq;
|
||||
w = (m02 - m20) * sq;
|
||||
}
|
||||
else {
|
||||
float_t sq = sqrtf(m22 - (m00 + m11) + 1.0f);
|
||||
z = sq * 0.5f;
|
||||
sq = 0.5f / sq;
|
||||
x = (m02 + m20) * sq;
|
||||
y = (m12 + m21) * sq;
|
||||
w = (m10 - m01) * sq;
|
||||
}
|
||||
}
|
||||
|
||||
inline quat operator +(const quat& left, const quat& right) {
|
||||
return quat::store_xmm(_mm_add_ps(quat::load_xmm(left), quat::load_xmm(right)));
|
||||
}
|
||||
|
||||
inline quat operator +(const quat& left, const float_t right) {
|
||||
return quat::store_xmm(_mm_add_ps(quat::load_xmm(left), quat::load_xmm(right)));
|
||||
}
|
||||
|
||||
inline quat operator -(const quat& left, const quat& right) {
|
||||
return quat::store_xmm(_mm_sub_ps(quat::load_xmm(left), quat::load_xmm(right)));
|
||||
}
|
||||
|
||||
inline quat operator -(const quat& left, const float_t right) {
|
||||
return quat::store_xmm(_mm_sub_ps(quat::load_xmm(left), quat::load_xmm(right)));
|
||||
}
|
||||
|
||||
inline quat operator *(const quat& left, const quat& right) {
|
||||
return quat::store_xmm(_mm_mul_ps(quat::load_xmm(left), quat::load_xmm(right)));
|
||||
}
|
||||
|
||||
inline quat operator *(const quat& left, const float_t right) {
|
||||
return quat::store_xmm(_mm_mul_ps(quat::load_xmm(left), quat::load_xmm(right)));
|
||||
}
|
||||
|
||||
inline quat operator /(const quat& left, const quat& right) {
|
||||
return quat::store_xmm(_mm_div_ps(quat::load_xmm(left), quat::load_xmm(right)));
|
||||
}
|
||||
|
||||
inline quat operator /(const quat& left, const float_t right) {
|
||||
return quat::store_xmm(_mm_div_ps(quat::load_xmm(left), quat::load_xmm(right)));
|
||||
}
|
||||
|
||||
inline quat operator &(const quat& left, const quat& right) {
|
||||
return quat::store_xmm(_mm_and_ps(quat::load_xmm(left), quat::load_xmm(right)));
|
||||
}
|
||||
|
||||
inline quat operator &(const quat& left, const float_t right) {
|
||||
return quat::store_xmm(_mm_and_ps(quat::load_xmm(left), quat::load_xmm(right)));
|
||||
}
|
||||
|
||||
inline quat operator ^(const quat& left, const quat& right) {
|
||||
return quat::store_xmm(_mm_xor_ps(quat::load_xmm(left), quat::load_xmm(right)));
|
||||
}
|
||||
|
||||
inline quat operator ^(const quat& left, const float_t right) {
|
||||
return quat::store_xmm(_mm_xor_ps(quat::load_xmm(left), quat::load_xmm(right)));
|
||||
}
|
||||
|
||||
inline quat operator -(const quat& left) {
|
||||
return quat::store_xmm(_mm_xor_ps(quat::load_xmm(left), vec4_neg));
|
||||
}
|
||||
|
||||
inline __m128 quat::load_xmm(const float_t data) {
|
||||
__m128 _data = _mm_load_ss(&data);
|
||||
return _mm_shuffle_ps(_data, _data, 0);
|
||||
}
|
||||
|
||||
inline __m128 quat::load_xmm(const quat& data) {
|
||||
return _mm_loadu_ps((const float*)&data);
|
||||
}
|
||||
|
||||
inline __m128 quat::load_xmm(const quat&& data) {
|
||||
return _mm_loadu_ps((const float*)&data);
|
||||
}
|
||||
|
||||
inline quat quat::store_xmm(const __m128& data) {
|
||||
quat _data;
|
||||
_mm_storeu_ps((float*)&_data, data);
|
||||
return _data;
|
||||
}
|
||||
|
||||
inline quat quat::store_xmm(const __m128&& data) {
|
||||
quat _data;
|
||||
_mm_storeu_ps((float*)&_data, data);
|
||||
return _data;
|
||||
}
|
||||
|
||||
inline quat quat::mul(const quat& in_q1, const quat& in_q2) {
|
||||
__m128 xt;
|
||||
__m128 yt;
|
||||
__m128 zt0;
|
||||
__m128 zt1;
|
||||
__m128 zt2;
|
||||
__m128 zt3;
|
||||
|
||||
xt = quat::load_xmm(in_q1);
|
||||
yt = quat::load_xmm(in_q2);
|
||||
zt0 = _mm_mul_ps(xt, _mm_shuffle_ps(yt, yt, 0x1B));
|
||||
zt1 = _mm_mul_ps(xt, _mm_shuffle_ps(yt, yt, 0x4E));
|
||||
zt2 = _mm_mul_ps(xt, _mm_shuffle_ps(yt, yt, 0xB1));
|
||||
zt3 = _mm_mul_ps(xt, _mm_shuffle_ps(yt, yt, 0xE4));
|
||||
zt0 = _mm_xor_ps(zt0, __m128({ 0.0f, 0.0f, -0.0f, 0.0f }));
|
||||
zt1 = _mm_xor_ps(zt1, __m128({ -0.0f, 0.0f, 0.0f, 0.0f }));
|
||||
zt2 = _mm_xor_ps(zt2, __m128({ 0.0f, -0.0f, 0.0f, 0.0f }));
|
||||
zt3 = _mm_xor_ps(zt3, __m128({ -0.0f, -0.0f, -0.0f, 0.0f }));
|
||||
zt0 = _mm_hadd_ps(zt0, zt0);
|
||||
zt1 = _mm_hadd_ps(zt1, zt1);
|
||||
zt2 = _mm_hadd_ps(zt2, zt2);
|
||||
zt3 = _mm_hadd_ps(zt3, zt3);
|
||||
|
||||
quat out_q;
|
||||
out_q.x = _mm_cvtss_f32(_mm_hadd_ps(zt0, zt0));
|
||||
out_q.y = _mm_cvtss_f32(_mm_hadd_ps(zt1, zt1));
|
||||
out_q.z = _mm_cvtss_f32(_mm_hadd_ps(zt2, zt2));
|
||||
out_q.w = _mm_cvtss_f32(_mm_hadd_ps(zt3, zt3));
|
||||
return out_q;
|
||||
}
|
||||
|
||||
inline float_t quat::dot(const quat& left, const quat& right) {
|
||||
__m128 zt;
|
||||
zt = _mm_mul_ps(quat::load_xmm(left), quat::load_xmm(right));
|
||||
zt = _mm_hadd_ps(zt, zt);
|
||||
return _mm_cvtss_f32(_mm_hadd_ps(zt, zt));
|
||||
}
|
||||
|
||||
inline float_t quat::length(const quat& left) {
|
||||
__m128 xt;
|
||||
__m128 zt;
|
||||
xt = quat::load_xmm(left);
|
||||
zt = _mm_mul_ps(xt, xt);
|
||||
zt = _mm_hadd_ps(zt, zt);
|
||||
return _mm_cvtss_f32(_mm_sqrt_ss(_mm_hadd_ps(zt, zt)));
|
||||
}
|
||||
|
||||
inline float_t quat::length_squared(const quat& left) {
|
||||
__m128 xt;
|
||||
__m128 zt;
|
||||
xt = quat::load_xmm(left);
|
||||
zt = _mm_mul_ps(xt, xt);
|
||||
zt = _mm_hadd_ps(zt, zt);
|
||||
return _mm_cvtss_f32(_mm_hadd_ps(zt, zt));
|
||||
}
|
||||
|
||||
inline float_t quat::distance(const quat& left, const quat& right) {
|
||||
__m128 zt;
|
||||
zt = _mm_sub_ps(quat::load_xmm(left), quat::load_xmm(right));
|
||||
zt = _mm_mul_ps(zt, zt);
|
||||
zt = _mm_hadd_ps(zt, zt);
|
||||
return _mm_cvtss_f32(_mm_sqrt_ss(_mm_hadd_ps(zt, zt)));
|
||||
}
|
||||
|
||||
inline float_t quat::distance_squared(const quat& left, const quat& right) {
|
||||
__m128 zt;
|
||||
zt = _mm_sub_ps(quat::load_xmm(left), quat::load_xmm(right));
|
||||
zt = _mm_mul_ps(zt, zt);
|
||||
zt = _mm_hadd_ps(zt, zt);
|
||||
return _mm_cvtss_f32(_mm_hadd_ps(zt, zt));
|
||||
}
|
||||
|
||||
inline quat quat::abs(const quat& left) {
|
||||
return quat::store_xmm(_mm_castsi128_ps(_mm_and_si128(_mm_castps_si128(quat::load_xmm(left)), vec4i_abs)));
|
||||
}
|
||||
|
||||
inline quat quat::lerp(const quat& left, const quat& right, const float_t blend) {
|
||||
quat x_t;
|
||||
quat y_t;
|
||||
x_t = left;
|
||||
y_t = right;
|
||||
|
||||
if (quat::dot(x_t, y_t) < 0.0f)
|
||||
x_t = -x_t;
|
||||
|
||||
return quat::normalize(x_t * (1.0f - blend) + y_t * blend);
|
||||
}
|
||||
|
||||
inline quat quat::slerp(const quat& left, const quat& right, const float_t blend) {
|
||||
quat x_t;
|
||||
quat y_t;
|
||||
x_t = left;
|
||||
y_t = right;
|
||||
|
||||
float_t dot = quat::dot(x_t, y_t);
|
||||
if (dot < 0.0f) {
|
||||
dot = -dot;
|
||||
x_t = -x_t;
|
||||
}
|
||||
|
||||
dot = min_def(dot, 1.0f);
|
||||
|
||||
float_t theta = acosf(dot);
|
||||
if (theta == 0.0f)
|
||||
return x_t;
|
||||
|
||||
float_t st = 1.0f / sinf(theta);
|
||||
float_t s0 = sinf((1.0f - blend) * theta) * st;
|
||||
float_t s1 = sinf(theta * blend) * st;
|
||||
return quat::normalize(x_t * s0 + y_t * s1);
|
||||
}
|
||||
|
||||
inline quat quat::normalize(const quat& left) {
|
||||
__m128 xt;
|
||||
__m128 zt;
|
||||
xt = quat::load_xmm(left);
|
||||
zt = _mm_mul_ps(xt, xt);
|
||||
zt = _mm_hadd_ps(zt, zt);
|
||||
zt = _mm_sqrt_ss(_mm_hadd_ps(zt, zt));
|
||||
if (_mm_cvtss_f32(zt) != 0.0f)
|
||||
return quat::store_xmm(_mm_div_ps(xt, _mm_shuffle_ps(zt, zt, 0)));
|
||||
return quat::store_xmm(xt);
|
||||
}
|
||||
|
||||
inline quat quat::normalize_rcp(const quat& left) {
|
||||
__m128 xt;
|
||||
__m128 zt;
|
||||
xt = quat::load_xmm(left);
|
||||
zt = _mm_mul_ps(xt, xt);
|
||||
zt = _mm_hadd_ps(zt, zt);
|
||||
zt = _mm_sqrt_ss(_mm_hadd_ps(zt, zt));
|
||||
if (_mm_cvtss_f32(zt) != 0.0f)
|
||||
zt = _mm_div_ss(quat::load_xmm(1.0f), zt);
|
||||
return quat::store_xmm(_mm_mul_ps(xt, _mm_shuffle_ps(zt, zt, 0)));
|
||||
}
|
||||
|
||||
inline quat quat::rcp(const quat& left) {
|
||||
return quat::store_xmm(_mm_div_ps(quat::load_xmm(1.0f), quat::load_xmm(left)));
|
||||
}
|
||||
|
||||
inline quat quat::min(const quat& left, const quat& right) {
|
||||
return quat::store_xmm(_mm_min_ps(quat::load_xmm(left), quat::load_xmm(right)));
|
||||
}
|
||||
|
||||
inline quat quat::max(const quat& left, const quat& right) {
|
||||
return quat::store_xmm(_mm_max_ps(quat::load_xmm(left), quat::load_xmm(right)));
|
||||
}
|
||||
|
||||
inline quat quat::clamp(const quat& left, const quat& min, const quat& max) {
|
||||
return quat::store_xmm(_mm_min_ps(_mm_max_ps(quat::load_xmm(left),
|
||||
quat::load_xmm(min)), quat::load_xmm(max)));
|
||||
}
|
||||
|
||||
inline quat quat::clamp(const quat& left, const float_t min, const float_t max) {
|
||||
return quat::store_xmm(_mm_min_ps(_mm_max_ps(quat::load_xmm(left),
|
||||
quat::load_xmm(min)), quat::load_xmm(max)));
|
||||
}
|
||||
|
||||
inline quat quat::mult_min_max(const quat& left, const quat& min, const quat& max) {
|
||||
__m128 xt;
|
||||
__m128 yt;
|
||||
__m128 wt;
|
||||
xt = quat::load_xmm(left);
|
||||
yt = _mm_xor_ps(quat::load_xmm(min), vec4_neg);
|
||||
wt = _mm_or_ps(_mm_and_ps(yt, _mm_cmplt_ps(xt, vec4::load_xmm(0.0f))),
|
||||
_mm_and_ps(quat::load_xmm(max), _mm_cmpge_ps(xt, vec4::load_xmm(0.0f))));
|
||||
return quat::store_xmm(_mm_mul_ps(xt, wt));
|
||||
}
|
||||
|
||||
inline quat quat::mult_min_max(const quat& left, const float_t min, const float_t max) {
|
||||
__m128 xt;
|
||||
__m128 yt;
|
||||
__m128 zt;
|
||||
__m128 wt;
|
||||
xt = quat::load_xmm(left);
|
||||
yt = quat::load_xmm(min);
|
||||
zt = quat::load_xmm(max);
|
||||
yt = _mm_xor_ps(yt, vec4_neg);
|
||||
wt = _mm_or_ps(_mm_and_ps(yt, _mm_cmplt_ps(xt, vec4::load_xmm(0.0f))),
|
||||
_mm_and_ps(zt, _mm_cmpge_ps(xt, vec4::load_xmm(0.0f))));
|
||||
return quat::store_xmm(_mm_mul_ps(xt, wt));
|
||||
}
|
||||
|
||||
inline quat quat::div_min_max(const quat& left, const quat& min, const quat& max) {
|
||||
__m128 xt;
|
||||
__m128 yt;
|
||||
__m128 wt;
|
||||
xt = quat::load_xmm(left);
|
||||
yt = _mm_xor_ps(quat::load_xmm(min), vec4_neg);
|
||||
wt = _mm_or_ps(_mm_and_ps(yt, _mm_cmplt_ps(xt, vec4::load_xmm(0.0f))),
|
||||
_mm_and_ps(quat::load_xmm(max), _mm_cmpge_ps(xt, vec4::load_xmm(0.0f))));
|
||||
return quat::store_xmm(_mm_div_ps(xt, wt));
|
||||
}
|
||||
|
||||
inline quat quat::div_min_max(const quat& left, const float_t min, const float_t max) {
|
||||
__m128 xt;
|
||||
__m128 yt;
|
||||
__m128 zt;
|
||||
__m128 wt;
|
||||
xt = quat::load_xmm(left);
|
||||
yt = quat::load_xmm(min);
|
||||
zt = quat::load_xmm(max);
|
||||
yt = _mm_xor_ps(yt, vec4_neg);
|
||||
wt = _mm_or_ps(_mm_and_ps(yt, _mm_cmplt_ps(xt, vec4::load_xmm(0.0f))),
|
||||
_mm_and_ps(zt, _mm_cmpge_ps(xt, vec4::load_xmm(0.0f))));
|
||||
return quat::store_xmm(_mm_div_ps(xt, wt));
|
||||
}
|
||||
@@ -1,690 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "str_utils.hpp"
|
||||
|
||||
bool str_utils_check_ends_with(const char* str, const char* mask) {
|
||||
if (!str || !mask)
|
||||
return false;
|
||||
|
||||
size_t mask_len = utf8_length(mask);
|
||||
size_t len = utf8_length(str);
|
||||
const char* t = str;
|
||||
while (t) {
|
||||
t = strstr(t, mask);
|
||||
if (t) {
|
||||
t += mask_len;
|
||||
if (t == str + len)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool str_utils_check_ends_with(const wchar_t* str, const wchar_t* mask) {
|
||||
if (!str || !mask)
|
||||
return false;
|
||||
|
||||
size_t mask_len = utf16_length(mask);
|
||||
size_t len = utf16_length(str);
|
||||
const wchar_t* t = str;
|
||||
while (t) {
|
||||
t = wcsstr(t, mask);
|
||||
if (t) {
|
||||
t += mask_len;
|
||||
if (t == str + len)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* str_utils_get_next_int32_t(const char* str, int32_t& value, const char split) {
|
||||
std::string s;
|
||||
str = str_utils_get_next_string(str, s, split);
|
||||
sscanf_s(s.c_str(), "%d", &value);
|
||||
return str;
|
||||
}
|
||||
|
||||
const wchar_t* str_utils_get_next_int32_t(const wchar_t* str, int32_t& value, const wchar_t split) {
|
||||
std::wstring s;
|
||||
str = str_utils_get_next_string(str, s, split);
|
||||
swscanf_s(s.c_str(), L"%d", &value);
|
||||
return str;
|
||||
}
|
||||
|
||||
const char* str_utils_get_next_float_t(const char* str, float_t& value, const char split) {
|
||||
std::string s;
|
||||
str = str_utils_get_next_string(str, s, split);
|
||||
sscanf_s(s.c_str(), "%f", &value);
|
||||
return str;
|
||||
}
|
||||
|
||||
const wchar_t* str_utils_get_next_float_t(const wchar_t* str, float_t& value, const wchar_t split) {
|
||||
std::wstring s;
|
||||
str = str_utils_get_next_string(str, s, split);
|
||||
swscanf_s(s.c_str(), L"%f", &value);
|
||||
return str;
|
||||
}
|
||||
|
||||
const char* str_utils_get_next_string(const char* str, std::string& value, const char split) {
|
||||
value.clear();
|
||||
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const char* t = strchr(str, split);
|
||||
if (!t) {
|
||||
value.assign(str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
value.assign(str, t - str);
|
||||
t++;
|
||||
return *t ? t : 0;
|
||||
}
|
||||
|
||||
const wchar_t* str_utils_get_next_string(const wchar_t* str, std::wstring& value, const wchar_t split) {
|
||||
value.clear();
|
||||
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const wchar_t* t = wcschr(str, split);
|
||||
if (!t) {
|
||||
value.assign(str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
value.assign(str, t - str);
|
||||
t++;
|
||||
return *t ? t : 0;
|
||||
}
|
||||
|
||||
char* str_utils_split_get_right(const char* str, const char split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const char* t = strchr(str, split);
|
||||
if (!t)
|
||||
return str_utils_copy(str);
|
||||
t++;
|
||||
|
||||
size_t len = utf8_length(t);
|
||||
char* p = force_malloc<char>(len + 1);
|
||||
memcpy(p, t, len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
wchar_t* str_utils_split_get_right(const wchar_t* str, const wchar_t split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const wchar_t* t = wcschr(str, split);
|
||||
if (!t)
|
||||
return str_utils_copy(str);
|
||||
t++;
|
||||
|
||||
size_t len = utf16_length(t);
|
||||
wchar_t* p = force_malloc<wchar_t>(len + 1);
|
||||
memcpy(p, t, sizeof(wchar_t) * len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
char* str_utils_split_get_left(const char* str, const char split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const char* t = strchr(str, split);
|
||||
|
||||
size_t len = t ? t - str : utf8_length(str);
|
||||
char* p = force_malloc<char>(len + 1);
|
||||
memcpy(p, str, len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
wchar_t* str_utils_split_get_left(const wchar_t* str, const wchar_t split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const wchar_t* t = wcschr(str, split);
|
||||
|
||||
size_t len = t ? t - str : utf16_length(str);
|
||||
wchar_t* p = force_malloc<wchar_t>(len + 1);
|
||||
memcpy(p, str, sizeof(wchar_t) * len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
char* str_utils_split_get_right_include(const char* str, const char split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const char* t = strchr(str, split);
|
||||
if (!t)
|
||||
return str_utils_copy(str);
|
||||
|
||||
size_t len = utf8_length(t);
|
||||
char* p = force_malloc<char>(len + 1);
|
||||
memcpy(p, t, len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
wchar_t* str_utils_split_get_right_include(const wchar_t* str, const wchar_t split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const wchar_t* t = wcschr(str, split);
|
||||
if (!t)
|
||||
return str_utils_copy(str);
|
||||
|
||||
size_t len = utf16_length(t);
|
||||
wchar_t* p = force_malloc<wchar_t>(len + 1);
|
||||
memcpy(p, t, sizeof(wchar_t) * len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
char* str_utils_split_get_left_include(const char* str, const char split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const char* t = strchr(str, split);
|
||||
t++;
|
||||
|
||||
size_t len = t ? t - str : utf8_length(str);
|
||||
char* p = force_malloc<char>(len + 1);
|
||||
memcpy(p, str, len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
wchar_t* str_utils_split_get_left_include(const wchar_t* str, const wchar_t split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const wchar_t* t = wcschr(str, split);
|
||||
t++;
|
||||
|
||||
size_t len = t ? t - str : utf16_length(str);
|
||||
wchar_t* p = force_malloc<wchar_t>(len + 1);
|
||||
memcpy(p, str, sizeof(wchar_t) * len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
char* str_utils_split_right_get_right(const char* str, const char split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const char* t = strrchr(str, split);
|
||||
if (!t)
|
||||
return str_utils_copy(str);
|
||||
t++;
|
||||
|
||||
size_t len = t - str;
|
||||
char* p = force_malloc<char>(len + 1);
|
||||
memcpy(p, t, len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
wchar_t* str_utils_split_right_get_right(const wchar_t* str, const wchar_t split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const wchar_t* t = wcsrchr(str, split);
|
||||
if (!t)
|
||||
return str_utils_copy(str);
|
||||
t++;
|
||||
|
||||
size_t len = t - str;
|
||||
wchar_t* p = force_malloc<wchar_t>(len + 1);
|
||||
memcpy(p, t, sizeof(wchar_t) * len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
char* str_utils_split_right_get_left(const char* str, const char split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const char* t = strrchr(str, split);
|
||||
|
||||
size_t len = t ? t - str : utf8_length(str);
|
||||
char* p = force_malloc<char>(len + 1);
|
||||
memcpy(p, str, len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
wchar_t* str_utils_split_right_get_left(const wchar_t* str, const wchar_t split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const wchar_t* t = wcsrchr(str, split);
|
||||
|
||||
size_t len = t ? t - str : utf16_length(str);
|
||||
wchar_t* p = force_malloc<wchar_t>(len + 1);
|
||||
memcpy(p, str, sizeof(wchar_t) * len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
char* str_utils_split_right_get_right_include(const char* str, const char split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const char* t = strrchr(str, split);
|
||||
if (!t)
|
||||
return str_utils_copy(str);
|
||||
|
||||
size_t len = utf8_length(t);
|
||||
char* p = force_malloc<char>(len + 1);
|
||||
memcpy(p, t, len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
wchar_t* str_utils_split_right_get_right_include(const wchar_t* str, const wchar_t split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const wchar_t* t = wcsrchr(str, split);
|
||||
if (!t)
|
||||
return str_utils_copy(str);
|
||||
|
||||
size_t len = utf16_length(t);
|
||||
wchar_t* p = force_malloc<wchar_t>(len + 1);
|
||||
memcpy(p, t, sizeof(wchar_t) * len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
char* str_utils_split_right_get_left_include(const char* str, const char split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const char* t = strrchr(str, split);
|
||||
if (t)
|
||||
t++;
|
||||
|
||||
size_t len = t ? t - str : utf8_length(str);
|
||||
char* p = force_malloc<char>(len + 1);
|
||||
memcpy(p, str, len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
wchar_t* str_utils_split_right_get_left_include(const wchar_t* str, const wchar_t split) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const wchar_t* t = wcsrchr(str, split);
|
||||
if (t)
|
||||
t++;
|
||||
|
||||
size_t len = t ? t - str : utf16_length(str);
|
||||
wchar_t* p = force_malloc<wchar_t>(len + 1);
|
||||
memcpy(p, str, sizeof(wchar_t) * len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
char* str_utils_get_extension(const char* str) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const char* t = strrchr(str, '\\');
|
||||
return str_utils_split_right_get_right_include(t ? t + 1 : str, '.');
|
||||
}
|
||||
|
||||
wchar_t* str_utils_get_extension(const wchar_t* str) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const wchar_t* t = wcsrchr(str, L'\\');
|
||||
return str_utils_split_right_get_right_include(t ? t + 1 : str, L'.');
|
||||
}
|
||||
|
||||
char* str_utils_get_without_extension(const char* str) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const char* t = strrchr(str, '\\');
|
||||
return str_utils_split_right_get_left(t ? t + 1 : str, '.');
|
||||
}
|
||||
|
||||
wchar_t* str_utils_get_without_extension(const wchar_t* str) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
const wchar_t* t = wcsrchr(str, L'\\');
|
||||
return str_utils_split_right_get_left(t ? t + 1 : str, L'.');
|
||||
}
|
||||
|
||||
char* str_utils_add(const char* str0, const char* str1) {
|
||||
if (str0 && str1) {
|
||||
size_t str0_len = utf8_length(str0);
|
||||
size_t str1_len = utf8_length(str1);
|
||||
char* p = force_malloc<char>(str0_len + str1_len + 1);
|
||||
memcpy(p, str0, str0_len + 1);
|
||||
memcpy(p + str0_len, str1, str1_len + 1);
|
||||
return p;
|
||||
}
|
||||
else if (str0)
|
||||
return str_utils_copy(str0);
|
||||
else if (str1)
|
||||
return str_utils_copy(str1);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
wchar_t* str_utils_add(const wchar_t* str0, const wchar_t* str1) {
|
||||
if (str0 && str1) {
|
||||
size_t str0_len = utf16_length(str0);
|
||||
size_t str1_len = utf16_length(str1);
|
||||
wchar_t* p = force_malloc<wchar_t>(str0_len + str1_len + 1);
|
||||
memcpy(p, str0, sizeof(wchar_t) * (str0_len + 1));
|
||||
memcpy(p + str0_len, str1, sizeof(wchar_t) * (str1_len + 1));
|
||||
return p;
|
||||
}
|
||||
else if (str0)
|
||||
return str_utils_copy(str0);
|
||||
else if (str1)
|
||||
return str_utils_copy(str1);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* str_utils_copy(const char* str) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
size_t len = utf8_length(str) + 1;
|
||||
char* p = force_malloc<char>(len);
|
||||
memcpy(p, str, len);
|
||||
return p;
|
||||
}
|
||||
|
||||
wchar_t* str_utils_copy(const wchar_t* str) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
size_t len = utf16_length(str) + 1;
|
||||
wchar_t* p = force_malloc<wchar_t>(len);
|
||||
memcpy(p, str, sizeof(wchar_t) * len);
|
||||
return p;
|
||||
}
|
||||
|
||||
inline int32_t str_utils_compare_length(const char* str0, size_t str0_len, const char* str1, size_t str1_len) {
|
||||
if (!str0_len)
|
||||
return -*str1;
|
||||
else if (!str1_len)
|
||||
return *str0;
|
||||
|
||||
size_t str0_len_act = str0_len;
|
||||
const char* i0 = str0;
|
||||
for (size_t i = str0_len; i; i--)
|
||||
if (!*i0++) {
|
||||
str0_len_act = i + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
size_t str1_len_act = str1_len;
|
||||
const char* i1 = str1;
|
||||
for (size_t i = str1_len; i; i--)
|
||||
if (!*i1++) {
|
||||
str1_len_act = i + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
str0_len = str0_len_act;
|
||||
str1_len = str1_len_act;
|
||||
|
||||
int32_t diff = 0;
|
||||
char c0;
|
||||
char c1;
|
||||
do {
|
||||
c0 = *str0++;
|
||||
c1 = *str1++;
|
||||
if (!c0 || !c1)
|
||||
return c0 - c1;
|
||||
} while (c0 == c1 && --str0_len && --str1_len);
|
||||
return c0 - c1;
|
||||
}
|
||||
|
||||
inline int32_t str_utils_compare_length(const wchar_t* str0, size_t str0_len, const wchar_t* str1, size_t str1_len) {
|
||||
if (!str0_len)
|
||||
return -*str1;
|
||||
else if (!str1_len)
|
||||
return *str0;
|
||||
|
||||
size_t str0_len_act = str0_len;
|
||||
const wchar_t* i0 = str0;
|
||||
for (size_t i = str0_len; i; i--)
|
||||
if (!*i0++) {
|
||||
str0_len_act = i + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
size_t str1_len_act = str1_len;
|
||||
const wchar_t* i1 = str1;
|
||||
for (size_t i = str1_len; i; i--)
|
||||
if (!*i1++) {
|
||||
str1_len_act = i + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
str0_len = str0_len_act;
|
||||
str1_len = str1_len_act;
|
||||
|
||||
int32_t diff = 0;
|
||||
wchar_t c0;
|
||||
wchar_t c1;
|
||||
do {
|
||||
c0 = *str0++;
|
||||
c1 = *str1++;
|
||||
if (!c0 || !c1)
|
||||
return c0 - c1;
|
||||
} while (c0 == c1 && --str0_len && --str1_len);
|
||||
return c0 - c1;
|
||||
}
|
||||
|
||||
size_t str_utils_get_substring_offset(const char* str0, size_t str0_len,
|
||||
size_t str0_off, const char* str1, size_t str1_len) {
|
||||
if (!str1_len && str0_off <= str0_len)
|
||||
return str0_off;
|
||||
|
||||
if (str0_off < str0_len && str1_len <= str0_len - str0_off) {
|
||||
size_t len = str0_len - str1_len - str0_off + 1;
|
||||
const char* str = &str0[str0_off];
|
||||
for (; len; ) {
|
||||
const char* s = (const char*)memchr(str, *str1, len);
|
||||
if (!s)
|
||||
break;
|
||||
|
||||
if (!str1_len || !memcmp(s, str1, str1_len))
|
||||
return s - str0;
|
||||
|
||||
len += str - (s + 1);
|
||||
str = s + 1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t str_utils_get_substring_offset(const wchar_t* str0, size_t str0_len,
|
||||
size_t str0_off, const wchar_t* str1, size_t str1_len) {
|
||||
if (!str1_len && str0_off <= str0_len)
|
||||
return str0_off;
|
||||
|
||||
if (str0_off < str0_len && str1_len <= str0_len - str0_off) {
|
||||
size_t len = str0_len - str1_len - str0_off + 1;
|
||||
const wchar_t* str = &str0[str0_off];
|
||||
for (; len; ) {
|
||||
const wchar_t* s = wmemchr(str, *str1, len);
|
||||
if (!s)
|
||||
break;
|
||||
|
||||
if (!str1_len || !memcmp(s, str1, sizeof(wchar_t) * str1_len))
|
||||
return s - str0;
|
||||
|
||||
len += str - (s + 1);
|
||||
str = s + 1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool str_utils_text_file_parse(const void* data, size_t size,
|
||||
char*& buf, char**& lines, size_t& count) {
|
||||
if (!data || !size)
|
||||
return false;
|
||||
|
||||
const char* d = (const char*)data;
|
||||
bool del = false;
|
||||
size_t c;
|
||||
buf = 0;
|
||||
lines = 0;
|
||||
count = 0;
|
||||
if ((uint8_t)d[0] == 0x00)
|
||||
return false;
|
||||
else if (d[0] == 0xFF) {
|
||||
if (size == 1 || (uint8_t)d[1] != 0xFE || size == 2)
|
||||
return false;
|
||||
|
||||
wchar_t* w_d = (wchar_t*)data + 1;
|
||||
d = utf16_to_utf8(w_d);
|
||||
size = utf8_length(d);
|
||||
del = true;
|
||||
goto decode_utf8_ansi;
|
||||
}
|
||||
else if ((uint8_t)d[0] == 0xFE) {
|
||||
if (size == 1 || (uint8_t)d[1] != 0xFF || size == 2)
|
||||
return false;
|
||||
|
||||
size /= 2;
|
||||
wchar_t* w_d = (wchar_t*)data + 1;
|
||||
w_d = str_utils_copy(w_d);
|
||||
for (size_t i = 0; i < size; i++)
|
||||
w_d[i] = (wchar_t)reverse_endianness_uint16_t((uint16_t)w_d[i]);
|
||||
d = utf16_to_utf8(w_d);
|
||||
size = utf8_length(d);
|
||||
del = true;
|
||||
free_def(w_d);
|
||||
goto decode_utf8_ansi;
|
||||
}
|
||||
else if ((uint8_t)d[0] == 0xEF) {
|
||||
if (size == 1 || (uint8_t)d[1] != 0xBB || size == 2 || (uint8_t)d[2] != 0xBF || size == 3)
|
||||
return false;
|
||||
|
||||
d += 3;
|
||||
size -= 3;
|
||||
goto decode_utf8_ansi;
|
||||
}
|
||||
else {
|
||||
decode_utf8_ansi:
|
||||
c = 1;
|
||||
bool lf;
|
||||
char ch;
|
||||
const char* t;
|
||||
lf = false;
|
||||
t = d;
|
||||
ch = 0;
|
||||
|
||||
size_t buf_len = size;
|
||||
for (size_t i = 0, l = 0, m = 0; i < size; i++) {
|
||||
ch = *t++;
|
||||
if (ch == '\r') {
|
||||
if (i + 1 < size && *t == '\n') {
|
||||
i++;
|
||||
t++;
|
||||
l++;
|
||||
}
|
||||
lf = true;
|
||||
}
|
||||
else if (ch == '\n')
|
||||
lf = true;
|
||||
|
||||
if (lf) {
|
||||
if (!l && c > 1)
|
||||
buf_len--;
|
||||
c++;
|
||||
l = 0;
|
||||
m = 0;
|
||||
lf = false;
|
||||
}
|
||||
else {
|
||||
l++;
|
||||
m++;
|
||||
}
|
||||
}
|
||||
|
||||
if (ch != '\r' && ch != '\n')
|
||||
buf_len++;
|
||||
else
|
||||
c--;
|
||||
|
||||
lf = false;
|
||||
t = d;
|
||||
char* temp_buf = force_malloc<char>(buf_len);
|
||||
char** temp_lines = force_malloc<char*>(c);
|
||||
|
||||
char* b = temp_buf;
|
||||
for (size_t i = 0, j = 0, l = 0, m = 0; j < c; i++) {
|
||||
ch = *t++;
|
||||
if (ch == '\r') {
|
||||
if (i + 1 < size && *t == '\n') {
|
||||
i++;
|
||||
t++;
|
||||
l++;
|
||||
}
|
||||
lf = true;
|
||||
}
|
||||
else if (ch == '\n')
|
||||
lf = true;
|
||||
|
||||
if (i >= size || lf) {
|
||||
temp_lines[j] = b;
|
||||
if (l) {
|
||||
memcpy(b, d + i - l, m);
|
||||
b[l] = 0;
|
||||
b += l + 1;
|
||||
}
|
||||
else if (j)
|
||||
temp_lines[j]--;
|
||||
else
|
||||
*b++ = 0;
|
||||
j++;
|
||||
|
||||
if (!lf)
|
||||
break;
|
||||
|
||||
l = 0;
|
||||
m = 0;
|
||||
lf = false;
|
||||
}
|
||||
else {
|
||||
l++;
|
||||
m++;
|
||||
}
|
||||
}
|
||||
|
||||
buf = temp_buf;
|
||||
lines = temp_lines;
|
||||
count = c;
|
||||
}
|
||||
|
||||
if (del) {
|
||||
void* data = (void*)d;
|
||||
free_def(data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "default.hpp"
|
||||
|
||||
inline int32_t str_utils_compare(const char* str0, const char* str1) {
|
||||
return strcmp(str0, str1);
|
||||
}
|
||||
|
||||
inline int32_t str_utils_compare(const wchar_t* str0, const wchar_t* str1) {
|
||||
return wcscmp(str0, str1);
|
||||
}
|
||||
|
||||
extern bool str_utils_check_ends_with(const char* str, const char* mask);
|
||||
extern bool str_utils_check_ends_with(const wchar_t* str, const wchar_t* mask);
|
||||
extern const char* str_utils_get_next_int32_t(const char* str, int32_t& value, const char split);
|
||||
extern const wchar_t* str_utils_get_next_int32_t(const wchar_t* str, int32_t& value, const wchar_t split);
|
||||
extern const char* str_utils_get_next_float_t(const char* str, float_t& value, const char split);
|
||||
extern const wchar_t* str_utils_get_next_float_t(const wchar_t* str, float_t& value, const wchar_t split);
|
||||
extern const char* str_utils_get_next_string(const char* str, std::string& value, const char split);
|
||||
extern const wchar_t* str_utils_get_next_string(const wchar_t* str, std::wstring& value, const wchar_t split);
|
||||
extern char* str_utils_split_get_right(const char* str, const char split);
|
||||
extern wchar_t* str_utils_split_get_right(const wchar_t* str, const wchar_t split);
|
||||
extern char* str_utils_split_get_left(const char* str, const char split);
|
||||
extern wchar_t* str_utils_split_get_left(const wchar_t* str, const wchar_t split);
|
||||
extern char* str_utils_split_get_right_include(const char* str, const char split);
|
||||
extern wchar_t* str_utils_split_get_right_include(const wchar_t* str, const wchar_t split);
|
||||
extern char* str_utils_split_get_left_include(const char* str, const char split);
|
||||
extern wchar_t* str_utils_split_get_left_include(const wchar_t* str, const wchar_t split);
|
||||
extern char* str_utils_split_right_get_right(const char* str, const char split);
|
||||
extern wchar_t* str_utils_split_right_get_right(const wchar_t* str, const wchar_t split);
|
||||
extern char* str_utils_split_right_get_left(const char* str, const char split);
|
||||
extern wchar_t* str_utils_split_right_get_left(const wchar_t* str, const wchar_t split);
|
||||
extern char* str_utils_split_right_get_right_include(const char* str, const char split);
|
||||
extern wchar_t* str_utils_split_right_get_right_include(const wchar_t* str, const wchar_t split);
|
||||
extern char* str_utils_split_right_get_left_include(const char* str, const char split);
|
||||
extern wchar_t* str_utils_split_right_get_left_include(const wchar_t* str, const wchar_t split);
|
||||
extern char* str_utils_get_extension(const char* str);
|
||||
extern wchar_t* str_utils_get_extension(const wchar_t* str);
|
||||
extern char* str_utils_get_without_extension(const char* str);
|
||||
extern wchar_t* str_utils_get_without_extension(const wchar_t* str);
|
||||
extern char* str_utils_add(const char* str0, const char* str1);
|
||||
extern wchar_t* str_utils_add(const wchar_t* str0, const wchar_t* str1);
|
||||
extern char* str_utils_copy(const char* str);
|
||||
extern wchar_t* str_utils_copy(const wchar_t* str);
|
||||
extern int32_t str_utils_compare_length(const char* str0, size_t str0_len, const char* str1, size_t str1_len);
|
||||
extern int32_t str_utils_compare_length(const wchar_t* str0, size_t str0_len, const wchar_t* str1, size_t str1_len);
|
||||
extern size_t str_utils_get_substring_offset(const char* str0, size_t str0_len,
|
||||
size_t str0_off, const char* str1, size_t str1_len);
|
||||
extern size_t str_utils_get_substring_offset(const wchar_t* str0, size_t str0_len,
|
||||
size_t str0_off, const wchar_t* str1, size_t str1_len);
|
||||
extern bool str_utils_text_file_parse(const void* data, size_t size,
|
||||
char*& buf, char**& lines, size_t& count);
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "time.hpp"
|
||||
|
||||
static double_t time_struct_get_freq();
|
||||
|
||||
time_struct::time_struct() : timestamp() {
|
||||
get_timestamp();
|
||||
inv_freq = time_struct_get_freq();
|
||||
}
|
||||
|
||||
double_t time_struct::calc_time() {
|
||||
LARGE_INTEGER timestamp;
|
||||
if (QueryPerformanceCounter(×tamp))
|
||||
return (double_t)(timestamp.QuadPart - this->timestamp.QuadPart) * inv_freq;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
int64_t time_struct::calc_time_int() {
|
||||
LARGE_INTEGER timestamp;
|
||||
if (QueryPerformanceCounter(×tamp))
|
||||
return (int64_t)((double_t)(timestamp.QuadPart - this->timestamp.QuadPart) * inv_freq * 1000.0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void time_struct::get_timestamp() {
|
||||
if (!QueryPerformanceCounter(×tamp))
|
||||
timestamp.QuadPart = 0;
|
||||
}
|
||||
|
||||
static double_t time_struct_get_freq() {
|
||||
LARGE_INTEGER freq;
|
||||
if (QueryPerformanceFrequency(&freq))
|
||||
return 1000.0 / (double_t)freq.LowPart;
|
||||
return 0.0;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "default.hpp"
|
||||
|
||||
struct time_struct {
|
||||
LARGE_INTEGER timestamp;
|
||||
double_t inv_freq;
|
||||
|
||||
time_struct();
|
||||
|
||||
double_t calc_time();
|
||||
int64_t calc_time_int();
|
||||
void get_timestamp();
|
||||
};
|
||||
@@ -1,434 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "txp.hpp"
|
||||
#include "f2/struct.hpp"
|
||||
#include "io/memory_stream.hpp"
|
||||
|
||||
txp_mipmap::txp_mipmap() : width(), height(), format(), size() {
|
||||
|
||||
}
|
||||
|
||||
txp_mipmap::~txp_mipmap() {
|
||||
|
||||
}
|
||||
|
||||
uint32_t txp_mipmap::get_size() {
|
||||
return txp::get_size(format, width, height);
|
||||
}
|
||||
|
||||
txp::txp() : has_cube_map(), array_size(), mipmaps_count() {
|
||||
|
||||
}
|
||||
|
||||
txp::~txp() {
|
||||
|
||||
}
|
||||
|
||||
uint32_t txp::get_size(txp_format format, uint32_t width, uint32_t height) {
|
||||
uint32_t size = width * height;
|
||||
switch (format) {
|
||||
case TXP_A8:
|
||||
return size;
|
||||
case TXP_RGB8:
|
||||
return size * 3;
|
||||
case TXP_RGBA8:
|
||||
return size * 4;
|
||||
case TXP_RGB5:
|
||||
return size * 2;
|
||||
case TXP_RGB5A1:
|
||||
return size * 2;
|
||||
case TXP_RGBA4:
|
||||
return size * 2;
|
||||
case TXP_L8:
|
||||
return size;
|
||||
case TXP_L8A8:
|
||||
return size * 2;
|
||||
case TXP_BC1:
|
||||
case TXP_BC1a:
|
||||
case TXP_BC2:
|
||||
case TXP_BC3:
|
||||
case TXP_BC4:
|
||||
case TXP_BC5:
|
||||
width = align_val(width, 4);
|
||||
height = align_val(height, 4);
|
||||
size = width * height;
|
||||
switch (format) {
|
||||
case TXP_BC1:
|
||||
return size / 2;
|
||||
case TXP_BC1a:
|
||||
return size / 2;
|
||||
case TXP_BC2:
|
||||
return size;
|
||||
case TXP_BC3:
|
||||
return size;
|
||||
case TXP_BC4:
|
||||
return size / 2;
|
||||
case TXP_BC5:
|
||||
return size;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
txp_set::txp_set() {
|
||||
|
||||
}
|
||||
|
||||
txp_set::~txp_set() {
|
||||
|
||||
}
|
||||
|
||||
bool txp_set::pack_file(void** data, size_t* size, bool big_endian) {
|
||||
size_t l;
|
||||
txp* tex;
|
||||
txp_mipmap* tex_mipmap;
|
||||
|
||||
if (!data || !size)
|
||||
return false;
|
||||
|
||||
*data = 0;
|
||||
*size = 0;
|
||||
|
||||
size_t count = textures.size();
|
||||
if (count < 1)
|
||||
return false;
|
||||
|
||||
size_t* txp4_offset = force_malloc<size_t>(count);
|
||||
size_t** txp2_offset = force_malloc<size_t*>(count);
|
||||
tex = textures.data();
|
||||
for (size_t i = 0; i < count; i++, tex++)
|
||||
txp2_offset[i] = force_malloc<size_t>((size_t)tex->mipmaps_count * tex->array_size);
|
||||
|
||||
l = 12 + count * 4;
|
||||
|
||||
tex = textures.data();
|
||||
for (size_t i = 0; i < count; i++, tex++) {
|
||||
txp4_offset[i] = l;
|
||||
l += 12 + (size_t)tex->array_size * tex->mipmaps_count * 4;
|
||||
|
||||
tex_mipmap = tex->mipmaps.data();
|
||||
for (size_t j = 0; j < tex->array_size; j++) {
|
||||
for (size_t k = 0; k < tex->mipmaps_count; k++, tex_mipmap++) {
|
||||
txp2_offset[i][j * tex->mipmaps_count + k] = l;
|
||||
l += 24;
|
||||
l += tex_mipmap->size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memory_stream s;
|
||||
s.open(0, l);
|
||||
s.big_endian = big_endian;
|
||||
s.write_uint32_t_reverse_endianness(0x03505854);
|
||||
s.write_uint32_t_reverse_endianness((uint32_t)count);
|
||||
s.write_uint32_t_reverse_endianness((uint8_t)count | 0x01010100);
|
||||
for (size_t i = 0; i < count; i++)
|
||||
s.write_uint32_t_reverse_endianness((uint32_t)txp4_offset[i]);
|
||||
|
||||
tex = textures.data();
|
||||
for (size_t i = 0; i < count; i++, tex++) {
|
||||
s.set_position(txp4_offset[i], SEEK_SET);
|
||||
s.write_uint32_t_reverse_endianness(tex->array_size > 1 ? 0x05505854 : 0x04505854);
|
||||
s.write_uint32_t_reverse_endianness(tex->mipmaps_count * tex->array_size);
|
||||
s.write_uint32_t_reverse_endianness((uint8_t)tex->mipmaps_count
|
||||
| ((uint8_t)tex->array_size << 8) | 0x01010000);
|
||||
for (size_t j = 0; j < tex->array_size; j++)
|
||||
for (size_t k = 0; k < tex->mipmaps_count; k++)
|
||||
s.write_uint32_t_reverse_endianness(
|
||||
(uint32_t)(txp2_offset[i][j * tex->mipmaps_count + k] - txp4_offset[i]));
|
||||
|
||||
tex_mipmap = tex->mipmaps.data();
|
||||
for (size_t j = 0; j < tex->array_size; j++)
|
||||
for (size_t k = 0; k < tex->mipmaps_count; k++, tex_mipmap++) {
|
||||
s.set_position(txp2_offset[i][j * tex->mipmaps_count + k], SEEK_SET);
|
||||
s.write_uint32_t_reverse_endianness(0x02505854);
|
||||
s.write_uint32_t_reverse_endianness(tex_mipmap->width);
|
||||
s.write_uint32_t_reverse_endianness(tex_mipmap->height);
|
||||
s.write_uint32_t_reverse_endianness(tex_mipmap->format);
|
||||
s.write_uint32_t_reverse_endianness((uint32_t)(j * tex->mipmaps_count + k));
|
||||
s.write_uint32_t_reverse_endianness(tex_mipmap->size);
|
||||
s.write(tex_mipmap->data.data(), tex_mipmap->size);
|
||||
s.align_write(0x04);
|
||||
}
|
||||
}
|
||||
s.set_position(0, SEEK_END);
|
||||
|
||||
s.align_write(0x10);
|
||||
s.copy(data, size);
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
free_def(txp2_offset[i]);
|
||||
free_def(txp2_offset);
|
||||
free_def(txp4_offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool txp_set::pack_file(std::vector<uint8_t>& data, bool big_endian) {
|
||||
size_t l;
|
||||
txp* tex;
|
||||
txp_mipmap* tex_mipmap;
|
||||
|
||||
data.clear();
|
||||
data.shrink_to_fit();
|
||||
|
||||
size_t count = textures.size();
|
||||
if (count < 1)
|
||||
return false;
|
||||
|
||||
size_t* txp4_offset = force_malloc<size_t>(count);
|
||||
size_t** txp2_offset = force_malloc<size_t*>(count);
|
||||
tex = textures.data();
|
||||
for (size_t i = 0; i < count; i++, tex++)
|
||||
txp2_offset[i] = force_malloc<size_t>((size_t)tex->mipmaps_count * tex->array_size);
|
||||
|
||||
l = 12 + count * 4;
|
||||
|
||||
tex = textures.data();
|
||||
for (size_t i = 0; i < count; i++, tex++) {
|
||||
txp4_offset[i] = l;
|
||||
l += 12 + (size_t)tex->array_size * tex->mipmaps_count * 4;
|
||||
|
||||
tex_mipmap = tex->mipmaps.data();
|
||||
for (size_t j = 0; j < tex->array_size; j++) {
|
||||
for (size_t k = 0; k < tex->mipmaps_count; k++, tex_mipmap++) {
|
||||
txp2_offset[i][j * tex->mipmaps_count + k] = l;
|
||||
l += 24;
|
||||
l += tex_mipmap->size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memory_stream s;
|
||||
s.open(0, l);
|
||||
s.big_endian = big_endian;
|
||||
s.write_uint32_t_reverse_endianness(0x03505854);
|
||||
s.write_uint32_t_reverse_endianness((uint32_t)count);
|
||||
s.write_uint32_t_reverse_endianness((uint8_t)count | 0x01010100);
|
||||
for (size_t i = 0; i < count; i++)
|
||||
s.write_uint32_t_reverse_endianness((uint32_t)txp4_offset[i]);
|
||||
|
||||
tex = textures.data();
|
||||
for (size_t i = 0; i < count; i++, tex++) {
|
||||
s.set_position(txp4_offset[i], SEEK_SET);
|
||||
s.write_uint32_t_reverse_endianness(tex->array_size > 1 ? 0x05505854 : 0x04505854);
|
||||
s.write_uint32_t_reverse_endianness(tex->mipmaps_count * tex->array_size);
|
||||
s.write_uint32_t_reverse_endianness((uint8_t)tex->mipmaps_count
|
||||
| ((uint8_t)tex->array_size << 8) | 0x01010000);
|
||||
for (size_t j = 0; j < tex->array_size; j++)
|
||||
for (size_t k = 0; k < tex->mipmaps_count; k++)
|
||||
s.write_uint32_t_reverse_endianness(
|
||||
(uint32_t)(txp2_offset[i][j * tex->mipmaps_count + k] - txp4_offset[i]));
|
||||
|
||||
tex_mipmap = tex->mipmaps.data();
|
||||
for (size_t j = 0; j < tex->array_size; j++)
|
||||
for (size_t k = 0; k < tex->mipmaps_count; k++, tex_mipmap++) {
|
||||
s.set_position(txp2_offset[i][j * tex->mipmaps_count + k], SEEK_SET);
|
||||
s.write_uint32_t_reverse_endianness(0x02505854);
|
||||
s.write_uint32_t_reverse_endianness(tex_mipmap->width);
|
||||
s.write_uint32_t_reverse_endianness(tex_mipmap->height);
|
||||
s.write_uint32_t_reverse_endianness(tex_mipmap->format);
|
||||
s.write_uint32_t_reverse_endianness((uint32_t)(j * tex->mipmaps_count + k));
|
||||
s.write_uint32_t_reverse_endianness(tex_mipmap->size);
|
||||
s.write(tex_mipmap->data.data(), tex_mipmap->size);
|
||||
s.align_write(0x04);
|
||||
}
|
||||
}
|
||||
s.set_position(0, SEEK_END);
|
||||
|
||||
s.align_write(0x10);
|
||||
s.copy(data);
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
free_def(txp2_offset[i]);
|
||||
free_def(txp2_offset);
|
||||
free_def(txp4_offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool txp_set::pack_file_modern(void** data, size_t* size, bool big_endian, uint32_t signature) {
|
||||
f2_struct st;
|
||||
if (!pack_file(st.data, big_endian)) {
|
||||
*data = 0;
|
||||
*size = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
produce_enrs(&st.enrs);
|
||||
|
||||
st.header.signature = reverse_endianness_uint32_t(signature);
|
||||
st.header.length = 0x20;
|
||||
st.header.use_big_endian = big_endian;
|
||||
st.header.use_section_size = true;
|
||||
st.write(data, size, true, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool txp_set::produce_enrs(enrs* enrs) {
|
||||
size_t l;
|
||||
txp* tex;
|
||||
txp_mipmap* tex_mipmap;
|
||||
|
||||
if (!enrs)
|
||||
return false;
|
||||
|
||||
enrs->vec.clear();
|
||||
l = 0;
|
||||
|
||||
size_t count = textures.size();
|
||||
if (count < 1)
|
||||
return false;
|
||||
|
||||
uint32_t o;
|
||||
enrs_entry ee;
|
||||
|
||||
ee = { 0, 1, 12, 1 };
|
||||
ee.append(0, 3, ENRS_DWORD);
|
||||
enrs->vec.push_back(ee);
|
||||
l += o = 12;
|
||||
|
||||
ee = { o, 1, (uint32_t)(count * 4), 1 };
|
||||
ee.append(0, (uint32_t)count, ENRS_DWORD);
|
||||
enrs->vec.push_back(ee);
|
||||
l += (size_t)(o = (uint32_t)(count * 4ULL));
|
||||
|
||||
tex = textures.data();
|
||||
for (size_t i = 0; i < count; i++, tex++) {
|
||||
ee = { o, 1, 12, 1 };
|
||||
ee.append(0, 3, ENRS_DWORD);
|
||||
enrs->vec.push_back(ee);
|
||||
l += o = 12;
|
||||
|
||||
ee = { o, 1, tex->array_size * 4, tex->mipmaps_count };
|
||||
ee.append(0, tex->array_size, ENRS_DWORD);
|
||||
enrs->vec.push_back(ee);
|
||||
l += (size_t)(o = (uint32_t)((size_t)tex->array_size * tex->mipmaps_count * 4));
|
||||
|
||||
tex_mipmap = tex->mipmaps.data();
|
||||
for (size_t j = 0; j < tex->array_size; j++) {
|
||||
for (size_t k = 0; k < tex->mipmaps_count; k++, tex_mipmap++) {
|
||||
ee = { o, 1, 24, 1 };
|
||||
ee.append(0, 6, ENRS_DWORD);
|
||||
enrs->vec.push_back(ee);
|
||||
l += (size_t)(o = (uint32_t)(24 + tex_mipmap->size));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool txp_set::unpack_file(const void* data, bool big_endian) {
|
||||
uint32_t signature;
|
||||
uint32_t tex_count;
|
||||
txp* tex;
|
||||
txp_mipmap* tex_mipmap;
|
||||
size_t set_d;
|
||||
size_t d;
|
||||
size_t mipmap_d;
|
||||
uint32_t sub_tex_count;
|
||||
uint32_t info;
|
||||
|
||||
if (!data)
|
||||
return false;
|
||||
|
||||
if (big_endian)
|
||||
signature = load_reverse_endianness_uint32_t((void*)data);
|
||||
else
|
||||
signature = *(uint32_t*)data;
|
||||
|
||||
if (signature != 0x03505854)
|
||||
return false;
|
||||
|
||||
set_d = (size_t)data;
|
||||
if (big_endian)
|
||||
tex_count = load_reverse_endianness_uint32_t((void*)(set_d + 4));
|
||||
else
|
||||
tex_count = *(uint32_t*)(set_d + 4);
|
||||
|
||||
textures.resize(tex_count);
|
||||
for (size_t i = 0; i < tex_count; i++) {
|
||||
if (big_endian) {
|
||||
d = set_d + (size_t)load_reverse_endianness_uint32_t((uint32_t*)(set_d + 12) + i);
|
||||
signature = load_reverse_endianness_uint32_t((void*)d);
|
||||
}
|
||||
else {
|
||||
d = set_d + (size_t)((uint32_t*)(set_d + 12))[i];
|
||||
signature = *(uint32_t*)d;
|
||||
}
|
||||
|
||||
if (signature != 0x04505854 && signature != 0x05505854) {
|
||||
textures.pop_back();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (big_endian) {
|
||||
sub_tex_count = load_reverse_endianness_uint32_t((void*)(d + 4));
|
||||
info = load_reverse_endianness_uint32_t((void*)(d + 8));
|
||||
}
|
||||
else {
|
||||
sub_tex_count = *(uint32_t*)(d + 4);
|
||||
info = *(uint32_t*)(d + 8);
|
||||
}
|
||||
|
||||
tex = &textures[i - (tex_count - textures.size())];
|
||||
tex->has_cube_map = signature == 0x05505854;
|
||||
tex->mipmaps_count = info & 0xFF;
|
||||
tex->array_size = (info >> 8) & 0xFF;
|
||||
|
||||
if (tex->array_size == 1 && tex->mipmaps_count != sub_tex_count)
|
||||
tex->mipmaps_count = sub_tex_count & 0xFF;
|
||||
|
||||
uint32_t mipmaps_count = tex->mipmaps_count;
|
||||
tex->mipmaps.resize((size_t)tex->array_size * tex->mipmaps_count);
|
||||
tex_mipmap = tex->mipmaps.data();
|
||||
for (size_t j = 0; j < tex->array_size; j++)
|
||||
for (size_t k = 0; k < tex->mipmaps_count; k++, tex_mipmap++) {
|
||||
if (big_endian) {
|
||||
mipmap_d = d + (size_t)load_reverse_endianness_uint32_t((uint32_t*)(d + 12) + j * mipmaps_count + k);
|
||||
signature = load_reverse_endianness_uint32_t((void*)mipmap_d);
|
||||
}
|
||||
else {
|
||||
mipmap_d = d + (size_t)((uint32_t*)(d + 12))[j * mipmaps_count + k];
|
||||
signature = *(uint32_t*)mipmap_d;
|
||||
}
|
||||
|
||||
if (big_endian) {
|
||||
tex_mipmap->width = load_reverse_endianness_uint32_t((void*)(mipmap_d + 4));
|
||||
tex_mipmap->height = load_reverse_endianness_uint32_t((void*)(mipmap_d + 8));
|
||||
tex_mipmap->format = (txp_format)load_reverse_endianness_uint32_t((void*)(mipmap_d + 12));
|
||||
tex_mipmap->size = load_reverse_endianness_uint32_t((void*)(mipmap_d + 20));
|
||||
}
|
||||
else {
|
||||
tex_mipmap->width = *(uint32_t*)(mipmap_d + 4);
|
||||
tex_mipmap->height = *(uint32_t*)(mipmap_d + 8);
|
||||
tex_mipmap->format = (txp_format)*(uint32_t*)(mipmap_d + 12);
|
||||
tex_mipmap->size = *(uint32_t*)(mipmap_d + 20);
|
||||
}
|
||||
|
||||
ssize_t size = tex_mipmap->get_size();
|
||||
tex_mipmap->data.resize(max_def(size, tex_mipmap->size));
|
||||
memcpy(tex_mipmap->data.data(), (void*)(mipmap_d + 24), tex_mipmap->size);
|
||||
size -= tex_mipmap->size;
|
||||
if (size > 0)
|
||||
memset((void*)((size_t)tex_mipmap->data.data() + tex_mipmap->size), 0, size);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool txp_set::unpack_file_modern(const void* data, size_t size, uint32_t signature) {
|
||||
bool ret = false;
|
||||
f2_struct st;
|
||||
st.read(data, size);
|
||||
if (st.header.signature == reverse_endianness_uint32_t(signature))
|
||||
ret = unpack_file(st.data.data(), st.header.use_big_endian);
|
||||
return ret;
|
||||
}
|
||||
|
||||
txp_set& txp_set::operator=(const txp_set& set) {
|
||||
textures.assign(set.textures.begin(), set.textures.end());
|
||||
return *this;
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "default.hpp"
|
||||
#include "f2/enrs.hpp"
|
||||
|
||||
enum txp_format {
|
||||
TXP_A8 = 0,
|
||||
TXP_RGB8 = 1,
|
||||
TXP_RGBA8 = 2,
|
||||
TXP_RGB5 = 3,
|
||||
TXP_RGB5A1 = 4,
|
||||
TXP_RGBA4 = 5,
|
||||
TXP_BC1 = 6,
|
||||
TXP_BC1a = 7,
|
||||
TXP_BC2 = 8,
|
||||
TXP_BC3 = 9,
|
||||
TXP_BC4 = 10,
|
||||
TXP_BC5 = 11,
|
||||
TXP_L8 = 12,
|
||||
TXP_L8A8 = 13,
|
||||
};
|
||||
|
||||
struct txp_mipmap {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
txp_format format;
|
||||
uint32_t size;
|
||||
std::vector<uint8_t> data;
|
||||
|
||||
txp_mipmap();
|
||||
~txp_mipmap();
|
||||
|
||||
uint32_t get_size();
|
||||
};
|
||||
|
||||
struct txp {
|
||||
bool has_cube_map;
|
||||
uint32_t array_size;
|
||||
uint32_t mipmaps_count;
|
||||
std::vector<txp_mipmap> mipmaps;
|
||||
|
||||
txp();
|
||||
~txp();
|
||||
|
||||
static uint32_t get_size(txp_format format, uint32_t width, uint32_t height);
|
||||
};
|
||||
|
||||
struct txp_set {
|
||||
std::vector<txp> textures;
|
||||
|
||||
txp_set();
|
||||
~txp_set();
|
||||
|
||||
bool pack_file(void** data, size_t* size, bool big_endian);
|
||||
bool pack_file(std::vector<uint8_t>& data, bool big_endian);
|
||||
bool pack_file_modern(void** data, size_t* size, bool big_endian, uint32_t signature);
|
||||
bool produce_enrs(enrs* enrs);
|
||||
bool unpack_file(const void* data, bool big_endian);
|
||||
bool unpack_file_modern(const void* data, size_t size, uint32_t signature);
|
||||
|
||||
txp_set& operator=(const txp_set& set);
|
||||
};
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <float.h>
|
||||
#include <stdint.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#define FASTCALL __fastcall
|
||||
#define ALIGN(n) __declspec(align(n))
|
||||
|
||||
#ifdef ssize_t
|
||||
#undef ssize_t
|
||||
#endif
|
||||
#ifdef _WIN64
|
||||
typedef __int64 ssize_t;
|
||||
#else
|
||||
typedef int size_t;
|
||||
#endif
|
||||
|
||||
#ifdef float_t
|
||||
#undef float_t
|
||||
#endif
|
||||
typedef float float_t;
|
||||
|
||||
#ifdef double_t
|
||||
#undef double_t
|
||||
#endif
|
||||
typedef double double_t;
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "vec.hpp"
|
||||
|
||||
const __m128 vec2_neg = { -0.0f, -0.0f, 0.0f, 0.0f };
|
||||
const __m128 vec3_neg = { -0.0f, -0.0f, -0.0f, 0.0f };
|
||||
const __m128 vec4_neg = { -0.0f, -0.0f, -0.0f, -0.0f };
|
||||
|
||||
extern const __m128d vec2d_neg = { -0.0, -0.0f };
|
||||
|
||||
const __m128i vec2i_abs = {
|
||||
(char)0xFF, (char)0xFF, (char)0xFF, (char)0x7F,
|
||||
(char)0xFF, (char)0xFF, (char)0xFF, (char)0x7F,
|
||||
(char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||
(char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||
};
|
||||
|
||||
const __m128i vec3i_abs = {
|
||||
(char)0xFF, (char)0xFF, (char)0xFF, (char)0x7F,
|
||||
(char)0xFF, (char)0xFF, (char)0xFF, (char)0x7F,
|
||||
(char)0xFF, (char)0xFF, (char)0xFF, (char)0x7F,
|
||||
(char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||
};
|
||||
|
||||
const __m128i vec4i_abs = {
|
||||
(char)0xFF, (char)0xFF, (char)0xFF, (char)0x7F,
|
||||
(char)0xFF, (char)0xFF, (char)0xFF, (char)0x7F,
|
||||
(char)0xFF, (char)0xFF, (char)0xFF, (char)0x7F,
|
||||
(char)0xFF, (char)0xFF, (char)0xFF, (char)0x7F,
|
||||
};
|
||||
|
||||
extern const __m128i vec2i64_abs = {
|
||||
(char)0xFF, (char)0xFF, (char)0xFF, (char)0xFF, (char)0xFF, (char)0xFF, (char)0xFF, (char)0x7F,
|
||||
(char)0xFF, (char)0xFF, (char)0xFF, (char)0xFF, (char)0xFF, (char)0xFF, (char)0xFF, (char)0x7F,
|
||||
};
|
||||
-2414
File diff suppressed because it is too large
Load Diff
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "default.hpp"
|
||||
|
||||
struct waitable_timer {
|
||||
HANDLE handle;
|
||||
|
||||
inline waitable_timer() {
|
||||
handle = CreateWaitableTimerW(0, 0, 0);
|
||||
}
|
||||
|
||||
inline ~waitable_timer() {
|
||||
if (handle) {
|
||||
CloseHandle(handle);
|
||||
handle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline void sleep(int64_t msec) {
|
||||
if (msec <= 0.0)
|
||||
return;
|
||||
|
||||
if (handle) {
|
||||
LARGE_INTEGER t;
|
||||
t.QuadPart = (LONGLONG)(msec * -10000);
|
||||
SetWaitableTimer(handle, &t, 0, 0, 0, 0);
|
||||
WaitForSingleObject(handle, INFINITE);
|
||||
}
|
||||
else {
|
||||
DWORD msec_dw = (DWORD)msec;
|
||||
if (msec_dw)
|
||||
Sleep(msec_dw);
|
||||
}
|
||||
}
|
||||
|
||||
inline void sleep_float(double_t msec) {
|
||||
if (msec <= 0.0)
|
||||
return;
|
||||
|
||||
if (handle) {
|
||||
LARGE_INTEGER t;
|
||||
t.QuadPart = (LONGLONG)round(msec * -10000.0);
|
||||
SetWaitableTimer(handle, &t, 0, 0, 0, 0);
|
||||
WaitForSingleObject(handle, INFINITE);
|
||||
}
|
||||
else {
|
||||
DWORD msec_dw = (DWORD)round(msec);
|
||||
if (msec_dw)
|
||||
Sleep(msec_dw);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user