1
0
mirror of https://github.com/soarqin/DSP_Mods_TO.git synced 2026-02-04 22:22:22 +08:00

CompressSave 1.3.7

This commit is contained in:
2024-12-01 15:32:20 +08:00
parent f832fbf0d6
commit 3cc1dfa750
10 changed files with 249 additions and 315 deletions

View File

@@ -1,4 +1,6 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace CompressSave.Wrapper;
@@ -34,6 +36,45 @@ public class WrapperDefines
protected CompressUpdateFunc CompressUpdate;
protected DecompressUpdateFunc DecompressUpdate;
public bool ResolveDllImports(string dllName)
{
var assemblyPath = System.Reflection.Assembly.GetAssembly(typeof(ZstdAPI)).Location;
string[] dlls;
if (string.IsNullOrEmpty(assemblyPath))
{
dlls = [
dllName, "x64/" + dllName, "plugins/x64/" + dllName, "BepInEx/scripts/x64/" + dllName
];
}
else
{
var root = Path.GetDirectoryName(assemblyPath) ?? string.Empty;
dlls = [
dllName, "x64/" + dllName, "plugins/x64/" + dllName, "BepInEx/scripts/x64/" + dllName,
Path.Combine(root, dllName), Path.Combine(root, "x64/" + dllName), Path.Combine(root, "plugins/x64/" + dllName)
];
}
foreach (var dll in dlls)
{
var lib = WinApi.LoadLibrary(dll);
if (lib == IntPtr.Zero) continue;
CompressBufferBound = Marshal.GetDelegateForFunctionPointer<CompressBufferBoundFunc>(WinApi.GetProcAddress(lib, "CompressBufferBound"));
CompressBegin = Marshal.GetDelegateForFunctionPointer<CompressBeginFunc>(WinApi.GetProcAddress(lib, "CompressBegin"));
CompressEnd = Marshal.GetDelegateForFunctionPointer<CompressEndFunc>(WinApi.GetProcAddress(lib, "CompressEnd"));
CompressUpdate = Marshal.GetDelegateForFunctionPointer<CompressUpdateFunc>(WinApi.GetProcAddress(lib, "CompressUpdate"));
CompressContextFree = Marshal.GetDelegateForFunctionPointer<CompressContextFreeFunc>(WinApi.GetProcAddress(lib, "CompressContextFree"));
DecompressBegin = Marshal.GetDelegateForFunctionPointer<DecompressBeginFunc>(WinApi.GetProcAddress(lib, "DecompressBegin"));
DecompressEnd = Marshal.GetDelegateForFunctionPointer<DecompressEndFunc>(WinApi.GetProcAddress(lib, "DecompressEnd"));
DecompressUpdate = Marshal.GetDelegateForFunctionPointer<DecompressUpdateFunc>(WinApi.GetProcAddress(lib, "DecompressUpdate"));
DecompressContextReset = Marshal.GetDelegateForFunctionPointer<DecompressContextResetFunc>(WinApi.GetProcAddress(lib, "DecompressContextReset"));
if (CompressBufferBound != null && CompressBegin != null && CompressEnd != null && CompressUpdate != null && CompressContextFree != null &&
DecompressBegin != null && DecompressEnd != null && DecompressUpdate != null && DecompressContextReset != null) return true;
WinApi.FreeLibrary(lib);
}
return false;
}
public unsafe long CompressUpdateEx(IntPtr ctx, byte[] dstBuffer, long dstOffset, byte[] srcBuffer,
long srcOffset, long srcLen)
{