mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
tmp
This commit is contained in:
parent
e15d844d4b
commit
0e8f839471
5 changed files with 812 additions and 140 deletions
63
Penumbra.GameData/Util/Functions.cs
Normal file
63
Penumbra.GameData/Util/Functions.cs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Penumbra.GameData.Util;
|
||||
|
||||
public static class Functions
|
||||
{
|
||||
public static ulong ComputeCrc64( string name )
|
||||
{
|
||||
if( name.Length == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var lastSlash = name.LastIndexOf( '/' );
|
||||
if( lastSlash == -1 )
|
||||
{
|
||||
return Lumina.Misc.Crc32.Get( name );
|
||||
}
|
||||
|
||||
var folder = name[ ..lastSlash ];
|
||||
var file = name[ ( lastSlash + 1 ).. ];
|
||||
return ( ( ulong )Lumina.Misc.Crc32.Get( folder ) << 32 ) | Lumina.Misc.Crc32.Get( file );
|
||||
}
|
||||
|
||||
public static ulong ComputeCrc64( ReadOnlySpan< byte > name )
|
||||
{
|
||||
if( name.Length == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var lastSlash = name.LastIndexOf( ( byte )'/' );
|
||||
if( lastSlash == -1 )
|
||||
{
|
||||
return Lumina.Misc.Crc32.Get( name );
|
||||
}
|
||||
|
||||
var folder = name[ ..lastSlash ];
|
||||
var file = name[ ( lastSlash + 1 ).. ];
|
||||
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 );
|
||||
|
||||
public static unsafe void MemCpyUnchecked( byte* dest, byte* src, int count )
|
||||
=> memcpy( dest, src, count );
|
||||
|
||||
|
||||
[DllImport( "msvcrt.dll", EntryPoint = "memcmp", CallingConvention = CallingConvention.Cdecl, SetLastError = false )]
|
||||
private static extern unsafe int memcmp( byte* b1, byte* b2, int count );
|
||||
|
||||
public static unsafe int MemCmpUnchecked( byte* ptr1, byte* ptr2, int count )
|
||||
=> memcmp( ptr1, ptr2, count );
|
||||
|
||||
|
||||
[DllImport( "msvcrt.dll", EntryPoint = "_memicmp", CallingConvention = CallingConvention.Cdecl, SetLastError = false )]
|
||||
private static extern unsafe int memicmp( byte* b1, byte* b2, int count );
|
||||
|
||||
public static unsafe int MemCmpCaseInsensitiveUnchecked( byte* ptr1, byte* ptr2, int count )
|
||||
=> memicmp( ptr1, ptr2, count );
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue