mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-13 12:14:17 +01:00
Add Byte String stuff, remove Services, cleanup and refactor interop stuff, disable path resolver for the moment
This commit is contained in:
parent
0e8f839471
commit
c3454f1d16
65 changed files with 4707 additions and 3371 deletions
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using ByteStringFunctions = Penumbra.GameData.ByteString.ByteStringFunctions;
|
||||
|
||||
namespace Penumbra.GameData.Util;
|
||||
|
||||
|
|
@ -41,10 +43,96 @@ public static class Functions
|
|||
return ( ( ulong )Lumina.Misc.Crc32.Get( folder ) << 32 ) | Lumina.Misc.Crc32.Get( file );
|
||||
}
|
||||
|
||||
[DllImport( "msvcrt.dll", EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false )]
|
||||
private static extern unsafe IntPtr memcpy( byte* dest, byte* src, int count );
|
||||
private static readonly uint[] CrcTable =
|
||||
typeof( Lumina.Misc.Crc32 ).GetField( "CrcTable", BindingFlags.Static | BindingFlags.NonPublic )?.GetValue( null ) as uint[]
|
||||
?? throw new Exception( "Could not fetch CrcTable from Lumina." );
|
||||
|
||||
public static unsafe void MemCpyUnchecked( byte* dest, byte* src, int count )
|
||||
|
||||
public static unsafe int ComputeCrc64LowerAndSize( byte* ptr, out ulong crc64, out int crc32Ret, out bool isLower, out bool isAscii )
|
||||
{
|
||||
var tmp = ptr;
|
||||
uint crcFolder = 0;
|
||||
uint crcFile = 0;
|
||||
var crc32 = uint.MaxValue;
|
||||
crc64 = 0;
|
||||
isLower = true;
|
||||
isAscii = true;
|
||||
while( true )
|
||||
{
|
||||
var value = *tmp;
|
||||
if( value == 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if( ByteStringFunctions.AsciiToLower( *tmp ) != *tmp )
|
||||
{
|
||||
isLower = false;
|
||||
}
|
||||
|
||||
if( value > 0x80 )
|
||||
{
|
||||
isAscii = false;
|
||||
}
|
||||
|
||||
if( value == ( byte )'/' )
|
||||
{
|
||||
crcFolder = crc32;
|
||||
crcFile = uint.MaxValue;
|
||||
crc32 = CrcTable[ ( byte )( crc32 ^ value ) ] ^ ( crc32 >> 8 );
|
||||
}
|
||||
else
|
||||
{
|
||||
crcFile = CrcTable[ ( byte )( crcFolder ^ value ) ] ^ ( crcFolder >> 8 );
|
||||
crc32 = CrcTable[ ( byte )( crc32 ^ value ) ] ^ ( crc32 >> 8 );
|
||||
}
|
||||
|
||||
++tmp;
|
||||
}
|
||||
|
||||
var size = ( int )( tmp - ptr );
|
||||
crc64 = ~( ( ulong )crcFolder << 32 ) | crcFile;
|
||||
crc32Ret = ( int )~crc32;
|
||||
return size;
|
||||
}
|
||||
|
||||
public static unsafe int ComputeCrc32AsciiLowerAndSize( byte* ptr, out int crc32Ret, out bool isLower, out bool isAscii )
|
||||
{
|
||||
var tmp = ptr;
|
||||
var crc32 = uint.MaxValue;
|
||||
isLower = true;
|
||||
isAscii = true;
|
||||
while( true )
|
||||
{
|
||||
var value = *tmp;
|
||||
if( value == 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if( ByteStringFunctions.AsciiToLower( *tmp ) != *tmp )
|
||||
{
|
||||
isLower = false;
|
||||
}
|
||||
|
||||
if( value > 0x80 )
|
||||
{
|
||||
isAscii = false;
|
||||
}
|
||||
|
||||
crc32 = CrcTable[ ( byte )( crc32 ^ value ) ] ^ ( crc32 >> 8 );
|
||||
++tmp;
|
||||
}
|
||||
|
||||
var size = ( int )( tmp - ptr );
|
||||
crc32Ret = ( int )~crc32;
|
||||
return size;
|
||||
}
|
||||
|
||||
[DllImport( "msvcrt.dll", EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false )]
|
||||
private static extern unsafe IntPtr memcpy( void* dest, void* src, int count );
|
||||
|
||||
public static unsafe void MemCpyUnchecked( void* dest, void* src, int count )
|
||||
=> memcpy( dest, src, count );
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue