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

177
CompressSave/CHANGELOG.md Normal file
View File

@@ -0,0 +1,177 @@
## Changelog
### 1.3.7
* Remove use of MonoMod.Util on loading dll import functions to make mod compatible with HarmonyX 2.13.0 (Although it is not merged yet. Check the PR [here](https://github.com/BepInEx/BepInEx/pull/902)).
### 1.3.6
* Support for using subfolder in save filepath (only MODs are doing this currently).
### 1.3.5
* Fix a crash issue on choosing language other than English and Chinese.
### 1.3.4
* Support for game version 0.10.28.20759.
### 1.3.3
* Fix a display issue on combobox of compression type.
### 1.3.2
* Add config UI on Save Game dialog, to set compression types.
* Change button text to `Save (Compress)` for better understanding.
### 1.3.1
* Add config to disable feature for auto saves.
* Fix bug that first save after game start is always compressed in Zstd.
### 1.3.0
* Separate config entries for manual save and auto save.
* Now you can still get speed benefit while setting compression type to `None` for auto saves, and for manual saves if using the new `Save` button.
+ Adds a `nonewrap.dll` for this function.
* Update `LZ4` and `Zstd` library to latest version.
* `lz4wrap.dll` and `zstdwrap.dll` are compiled using `-O3` instead of `-Os`, expect to be slightly faster but larger.
<details>
<summary>Older versions</summary>
### 1.2.2
* Fix #4, a bug caused by non-ASCII UTF-8 characters.
* Remove use of Harmony.UnpatchAll() to avoid warnings in BepInEx log.
### 1.2.1
* Simplified codes to display compression type and `Decompress` button on save/load UI, making CompressSave compatible with other MODs(like GalacticScale) which override `UILoadGameWindow::OnSelectedChange()`.
* Add compression level -5 to -1 for zstd, which makes it working better than lz4(which is actually lz4hc used by lz4frame) now:
* -5 gets faster compression speed than lz4 with still a little better compression ratio.
* -1 has almost the same speed against lz4 with greater compression ratio.
* Due to bug of r2modman UI which does not support negative integer, the config value of compression level is not limited any more.
* move native wrapper DLLs into `x64` folder to avoid warning logs on loading BepInEx plugins.
### 1.2.0
* Match game version 0.9.27.15033.
* Add new compression type: zstd (a bit slower but get better compression ratio than lz4).
* Add config to set compression type and level(Don't use high compression levels for zstd as they are very slow).
* Hide decompress button for normal save files.
* Optimize native dlls for other compression library support:
* Unified naming rules for filenames and export functions.
* Add compression level support.
### 1.1.14
* Fix Sandbox info on Save/Load Panel.
* Fix DLL version info.
### 1.1.13
* Match game version 0.9.26.13026.
* Move "Sandbox Mode" checkbox on Save Panel to avoid overlap.
* Avoid warning message on "Continue" button of main menu.
### 1.1.12
* Match game version 0.9.25.12007.
### 1.1.11
* Fix 1.1.10 package issue.
### 1.1.10
* Fix 1.1.8 Archive corruption with DIY System, corrupted archives can be fixed by using \[Fix118\] mod
Fix118: https://github.com/bluedoom/DSP_Mod/blob/master/Fix118
### 1.1.9
* CompressSave is temporarily disabled due to some error with the DIY system.
### 1.1.8
* Match game version 0.9.24.11029
### 1.1.7
* Fix incorrect data on statistic panel.
* Improve performance.
### 1.1.6
* fix memory leak
### 1.1.5 (Game Version 0.8.22)
* Match game version 0.8.22.
* Thanks [@starfi5h] for
- PatchSave now use transpiler for better robustness.
- Change version check to soft warning.
- Add PeekableReader so other mods can use BinaryReader.PeekChar().
- Change LZ4DecompressionStream.Position behavior. Position setter i - available now.
### 1.1.4 (Game Version 0.8.19)
* Match game version 0.8.19.
### 1.1.3 (2021/05/29) (Game Version 0.7.18)
* Match game version 0.7.18.
* Fix memory leak.
### 1.1.2 (2021/03/24) (Game Version 0.6.17)
* Handle lz4 library missing Error
### 1.1.1 (2021/03/17) (Game Version 0.6.17)
* Fix Load Error
### 1.1.0 (2021/03/17) (Game Version 0.6.17)
* Add UI button
</details>
## 更新日志
### 1.3.7
* 移除使用MonoMod.Util加载dll导入函数以使MOD与HarmonyX 2.13.0兼容(尽管此改动尚未合并。[在此](https://github.com/BepInEx/BepInEx/pull/902)查看合并请求)。
### 1.3.6
* 支持在存档路径中使用子文件夹(目前只有MOD会这么干)。
### 1.3.5
* 修复了选择英文和中文以外的语言时的崩溃问题。
### 1.3.4
* 支持游戏版本 0.10.28.20759。
### 1.3.3
* 修复压缩类型下拉框显示问题。
### 1.3.2
* 在保存面板上增加设置压缩方式的UI。
* 将按钮文本改为`压缩保存`以区分功能。
### 1.3.1
* 增加在自动存档中禁用压缩的设置项。
* 修复一个导致游戏开始后第一次保存总是使用Zstd压缩的bug。
### 1.3.0
* 分离手动存档和自动存档的设置项。
* 现在在自动存档设置压缩类型为`存储`也可以获得速度提升,手动存档也可以在使用新的`保存`按钮后获得速度提升。
+ 为此增加了`nonewrap.dll`
* 更新`LZ4``Zstd`库到最新版本。
* `lz4wrap.dll``zstdwrap.dll`使用`-O3`编译而不是`-Os`,速度略有提升但体积变大。
<details>
<summary>Older versions</summary>
### 1.2.2
* 修复 #4一个导致非ASCII UTF-8字符导致的bug。
* 移除使用Harmony.UnpatchAll()以避免在BepInEx日志中出现警告。
### 1.2.1
* 简化代码以在存档读取面板上显示压缩类型和`解压`按钮使得CompressSave与其他MOD(如GalacticScale)兼容,因为它们都覆盖了`UILoadGameWindow::OnSelectedChange()`
* 为zstd添加了压缩等级-5到-1现在它比lz4(实际上是lz4frame)表现更好了:
* -5比lz4更快但压缩比略有提升。
* -1和lz4几乎一样快但压缩比更高。
* 由于r2modman UI的bug压缩等级的设置项不再限制范围。
* 将本地的wrapper DLL移动到`x64`目录。
</details>

View File

@@ -106,8 +106,9 @@ public class CompressSave : BaseUnityPlugin
public class PatchSave
{
public static readonly WrapperDefines LZ4Wrapper = new LZ4API(), ZstdWrapper = new ZstdAPI();
private static readonly WrapperDefines NoneWrapper = new NoneAPI();
public static readonly WrapperDefines LZ4Wrapper = LZ4API.Instance;
public static readonly WrapperDefines ZstdWrapper = ZstdAPI.Instance;
private static readonly WrapperDefines NoneWrapper = NoneAPI.Instance;
private static CompressionStream.CompressBuffer _compressBuffer;
public static bool UseCompressSave;
private static CompressionType _compressionTypeForLoading = CompressionType.None;

View File

@@ -4,7 +4,7 @@
<AssemblyName>CompressSave</AssemblyName>
<BepInExPluginGuid>org.soardev.compresssave</BepInExPluginGuid>
<Description>DSP MOD - CompressSave</Description>
<Version>1.3.6</Version>
<Version>1.3.7</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<TargetFramework>net472</TargetFramework>
@@ -24,6 +24,6 @@
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(Configuration)' == 'Release'">
<Exec Command="del /F /Q package\$(ProjectName)-$(Version).zip&#xA;copy /y &quot;$(TargetPath)&quot; package\plugins\&#xA;copy /y &quot;$(TargetDir)\System.Runtime.CompilerServices.Unsafe.dll&quot; package\plugins\&#xA;cd package&#xA;powershell Compress-Archive -Force -DestinationPath '$(ProjectName)-$(Version).zip' -Path plugins, icon.png, manifest.json, ../README.md" />
<Exec Command="del /F /Q package\$(ProjectName)-$(Version).zip&#xA;copy /y &quot;$(TargetPath)&quot; package\plugins\&#xA;copy /y &quot;$(TargetDir)\System.Runtime.CompilerServices.Unsafe.dll&quot; package\plugins\&#xA;cd package&#xA;powershell Compress-Archive -Force -DestinationPath '$(ProjectName)-$(Version).zip' -Path plugins, icon.png, manifest.json, ../README.md, ../CHANGELOG.md" />
</Target>
</Project>

View File

@@ -5,127 +5,6 @@
#### 压缩游戏存档以降低空间使用并提升保存速度
#### 原作者 [@bluedoom](https://github.com/bluedoom/DSP_Mod)(直到1.1.11) 和 [@starfi5h](https://github.com/starfi5h/DSP_CompressSave)(1.1.12),本人继续更新以支持最新游戏版本。
## Changelog
### 1.3.6
* Support for using subfolder in save filepath (only MODs are doing this currently).
### 1.3.5
* Fix a crash issue on choosing language other than English and Chinese.
### 1.3.4
* Support for game version 0.10.28.20759.
### 1.3.3
* Fix a display issue on combobox of compression type.
### 1.3.2
* Add config UI on Save Game dialog, to set compression types.
* Change button text to `Save (Compress)` for better understanding.
### 1.3.1
* Add config to disable feature for auto saves.
* Fix bug that first save after game start is always compressed in Zstd.
### 1.3.0
* Separate config entries for manual save and auto save.
* Now you can still get speed benefit while setting compression type to `None` for auto saves, and for manual saves if using the new `Save` button.
+ Adds a `nonewrap.dll` for this function.
* Update `LZ4` and `Zstd` library to latest version.
* `lz4wrap.dll` and `zstdwrap.dll` are compiled using `-O3` instead of `-Os`, expect to be slightly faster but larger.
### 1.2.2
* Fix #4, a bug caused by non-ASCII UTF-8 characters.
* Remove use of Harmony.UnpatchAll() to avoid warnings in BepInEx log.
### 1.2.1
* Simplified codes to display compression type and `Decompress` button on save/load UI, making CompressSave compatible with other MODs(like GalacticScale) which override `UILoadGameWindow::OnSelectedChange()`.
* Add compression level -5 to -1 for zstd, which makes it working better than lz4(which is actually lz4hc used by lz4frame) now:
* -5 gets faster compression speed than lz4 with still a little better compression ratio.
* -1 has almost the same speed against lz4 with greater compression ratio.
* Due to bug of r2modman UI which does not support negative integer, the config value of compression level is not limited any more.
* move native wrapper DLLs into `x64` folder to avoid warning logs on loading BepInEx plugins.
### 1.2.0
* Match game version 0.9.27.15033.
* Add new compression type: zstd (a bit slower but get better compression ratio than lz4).
* Add config to set compression type and level(Don't use high compression levels for zstd as they are very slow).
* Hide decompress button for normal save files.
* Optimize native dlls for other compression library support:
* Unified naming rules for filenames and export functions.
* Add compression level support.
### 1.1.14
* Fix Sandbox info on Save/Load Panel.
* Fix DLL version info.
### 1.1.13
* Match game version 0.9.26.13026.
* Move "Sandbox Mode" checkbox on Save Panel to avoid overlap.
* Avoid warning message on "Continue" button of main menu.
### 1.1.12
* Match game version 0.9.25.12007.
### 1.1.11
* Fix 1.1.10 package issue.
### 1.1.10
* Fix 1.1.8 Archive corruption with DIY System, corrupted archives can be fixed by using \[Fix118\] mod
Fix118: https://github.com/bluedoom/DSP_Mod/blob/master/Fix118
### 1.1.9
* CompressSave is temporarily disabled due to some error with the DIY system.
### 1.1.8
* Match game version 0.9.24.11029
### 1.1.7
* Fix incorrect data on statistic panel.
* Improve performance.
### 1.1.6
* fix memory leak
### 1.1.5 (Game Version 0.8.22)
* Match game version 0.8.22.
* Thanks [@starfi5h] for
- PatchSave now use transpiler for better robustness.
- Change version check to soft warning.
- Add PeekableReader so other mods can use BinaryReader.PeekChar().
- Change LZ4DecompressionStream.Position behavior. Position setter i - available now.
### 1.1.4 (Game Version 0.8.19)
* Match game version 0.8.19.
### 1.1.3 (2021/05/29) (Game Version 0.7.18)
* Match game version 0.7.18.
* Fix memory leak.
### 1.1.2 (2021/03/24) (Game Version 0.6.17)
* Handle lz4 library missing Error
### 1.1.1 (2021/03/17) (Game Version 0.6.17)
* Fix Load Error
### 1.1.0 (2021/03/17) (Game Version 0.6.17)
* Add UI button
## Introduction
* Reduce archive size by 30% / save time by 75% (Compressed by LZ4, on HDD + i7-4790K@4.4G + DDR3 2400MHz)
@@ -144,47 +23,6 @@
* You can decompress saves on load panel.
* Remember to backup your save(use original save button) before updating game to avoid loading failure.
## 更新日志
### 1.3.6
* 支持在存档路径中使用子文件夹(目前只有MOD会这么干)。
### 1.3.5
* 修复了选择英文和中文以外的语言时的崩溃问题。
### 1.3.4
* 支持游戏版本 0.10.28.20759。
### 1.3.3
* 修复压缩类型下拉框显示问题。
### 1.3.2
* 在保存面板上增加设置压缩方式的UI。
* 将按钮文本改为`压缩保存`以区分功能。
### 1.3.1
* 增加在自动存档中禁用压缩的设置项。
* 修复一个导致游戏开始后第一次保存总是使用Zstd压缩的bug。
### 1.3.0
* 分离手动存档和自动存档的设置项。
* 现在在自动存档设置压缩类型为`存储`也可以获得速度提升,手动存档也可以在使用新的`保存`按钮后获得速度提升。
+ 为此增加了`nonewrap.dll`
* 更新`LZ4``Zstd`库到最新版本。
* `lz4wrap.dll``zstdwrap.dll`使用`-O3`编译而不是`-Os`,速度略有提升但体积变大。
### 1.2.2
* 修复 #4一个导致非ASCII UTF-8字符导致的bug。
* 移除使用Harmony.UnpatchAll()以避免在BepInEx日志中出现警告。
### 1.2.1
* 简化代码以在存档读取面板上显示压缩类型和`解压`按钮使得CompressSave与其他MOD(如GalacticScale)兼容,因为它们都覆盖了`UILoadGameWindow::OnSelectedChange()`
* 为zstd添加了压缩等级-5到-1现在它比lz4(实际上是lz4frame)表现更好了:
* -5比lz4更快但压缩比略有提升。
* -1和lz4几乎一样快但压缩比更高。
* 由于r2modman UI的bug压缩等级的设置项不再限制范围。
* 将本地的wrapper DLL移动到`x64`
## 介绍
* 减少存档容量30% / 存档用时75% (LZ4压缩测试环境机械硬盘 + i7-4790K@4.4G + DDR3 2400MHz)

View File

@@ -1,41 +1,17 @@
using System;
using System.Collections.Generic;
using System.IO;
using MonoMod.Utils;
namespace CompressSave.Wrapper;
public class LZ4API: WrapperDefines
{
public static readonly bool Avaliable;
public static readonly LZ4API Instance = new();
static LZ4API()
{
Avaliable = true;
var assemblyPath = System.Reflection.Assembly.GetAssembly(typeof(LZ4API)).Location;
var root = string.Empty;
try
{
if (!string.IsNullOrEmpty(assemblyPath))
{
root = Path.GetDirectoryName(assemblyPath) ?? string.Empty;
}
var map = new Dictionary<string, List<DynDllMapping>>
{
{
"lz4wrap.dll", [
"lz4wrap.dll",
"x64/lz4wrap.dll",
"plugins/x64/lz4wrap.dll",
"BepInEx/scripts/x64/lz4wrap.dll",
Path.Combine(root, "lz4wrap.dll"),
Path.Combine(root, "x64/lz4wrap.dll"),
Path.Combine(root, "plugins/x64/lz4wrap.dll")
]
},
};
typeof(LZ4API).ResolveDynDllImports(map);
Avaliable = Instance.ResolveDllImports("lz4wrap.dll");
}
catch (Exception e)
{
@@ -43,27 +19,4 @@ public class LZ4API: WrapperDefines
Console.WriteLine($"Error: {e}");
}
}
public LZ4API()
{
CompressBufferBound = CompressBufferBound_;
CompressBegin = CompressBegin_;
CompressEnd = CompressEnd_;
CompressUpdate = CompressUpdate_;
CompressContextFree = CompressContextFree_;
DecompressBegin = DecompressBegin_;
DecompressEnd = DecompressEnd_;
DecompressUpdate = DecompressUpdate_;
DecompressContextReset = DecompressContextReset_;
}
[DynDllImport(libraryName: "lz4wrap.dll", "CompressBufferBound")] protected static CompressBufferBoundFunc CompressBufferBound_;
[DynDllImport(libraryName: "lz4wrap.dll", "CompressBegin")] protected static CompressBeginFunc CompressBegin_;
[DynDllImport(libraryName: "lz4wrap.dll", "CompressEnd")] protected static CompressEndFunc CompressEnd_;
[DynDllImport(libraryName: "lz4wrap.dll", "CompressUpdate")] protected static CompressUpdateFunc CompressUpdate_;
[DynDllImport(libraryName: "lz4wrap.dll", "CompressContextFree")] protected static CompressContextFreeFunc CompressContextFree_;
[DynDllImport(libraryName: "lz4wrap.dll", "DecompressBegin")] protected static DecompressBeginFunc DecompressBegin_;
[DynDllImport(libraryName: "lz4wrap.dll", "DecompressEnd")] protected static DecompressEndFunc DecompressEnd_;
[DynDllImport(libraryName: "lz4wrap.dll", "DecompressUpdate")] protected static DecompressUpdateFunc DecompressUpdate_;
[DynDllImport(libraryName: "lz4wrap.dll", "DecompressContextReset")] protected static DecompressContextResetFunc DecompressContextReset_;
}

View File

@@ -1,41 +1,17 @@
using System;
using System.Collections.Generic;
using System.IO;
using MonoMod.Utils;
namespace CompressSave.Wrapper;
public class NoneAPI: WrapperDefines
{
public static readonly bool Avaliable;
public static readonly NoneAPI Instance = new();
static NoneAPI()
{
Avaliable = true;
string assemblyPath = System.Reflection.Assembly.GetAssembly(typeof(NoneAPI)).Location;
string root = string.Empty;
try
{
if (!string.IsNullOrEmpty(assemblyPath))
{
root = Path.GetDirectoryName(assemblyPath) ?? string.Empty;
}
var map = new Dictionary<string, List<DynDllMapping>>
{
{
"nonewrap.dll", [
"nonewrap.dll",
"x64/nonewrap.dll",
"plugins/x64/nonewrap.dll",
"BepInEx/scripts/x64/nonewrap.dll",
Path.Combine(root, "nonewrap.dll"),
Path.Combine(root, "x64/nonewrap.dll"),
Path.Combine(root, "plugins/x64/nonewrap.dll")
]
},
};
typeof(NoneAPI).ResolveDynDllImports(map);
Avaliable = Instance.ResolveDllImports("nonewrap.dll");
}
catch (Exception e)
{
@@ -43,27 +19,4 @@ public class NoneAPI: WrapperDefines
Console.WriteLine($"Error: {e}");
}
}
public NoneAPI()
{
CompressBufferBound = CompressBufferBound_;
CompressBegin = CompressBegin_;
CompressEnd = CompressEnd_;
CompressUpdate = CompressUpdate_;
CompressContextFree = CompressContextFree_;
DecompressBegin = DecompressBegin_;
DecompressEnd = DecompressEnd_;
DecompressUpdate = DecompressUpdate_;
DecompressContextReset = DecompressContextReset_;
}
[DynDllImport(libraryName: "nonewrap.dll", "CompressBufferBound")] protected static CompressBufferBoundFunc CompressBufferBound_;
[DynDllImport(libraryName: "nonewrap.dll", "CompressBegin")] protected static CompressBeginFunc CompressBegin_;
[DynDllImport(libraryName: "nonewrap.dll", "CompressEnd")] protected static CompressEndFunc CompressEnd_;
[DynDllImport(libraryName: "nonewrap.dll", "CompressUpdate")] protected static CompressUpdateFunc CompressUpdate_;
[DynDllImport(libraryName: "nonewrap.dll", "CompressContextFree")] protected static CompressContextFreeFunc CompressContextFree_;
[DynDllImport(libraryName: "nonewrap.dll", "DecompressBegin")] protected static DecompressBeginFunc DecompressBegin_;
[DynDllImport(libraryName: "nonewrap.dll", "DecompressEnd")] protected static DecompressEndFunc DecompressEnd_;
[DynDllImport(libraryName: "nonewrap.dll", "DecompressUpdate")] protected static DecompressUpdateFunc DecompressUpdate_;
[DynDllImport(libraryName: "nonewrap.dll", "DecompressContextReset")] protected static DecompressContextResetFunc DecompressContextReset_;
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Runtime.InteropServices;
namespace CompressSave.Wrapper;
public static class WinApi
{
// LoadLibrary, GetProcAddress, FreeLibrary
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool FreeLibrary(IntPtr hModule);
}

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)
{

View File

@@ -1,41 +1,17 @@
using System;
using System.Collections.Generic;
using System.IO;
using MonoMod.Utils;
namespace CompressSave.Wrapper;
public class ZstdAPI: WrapperDefines
{
public static readonly bool Avaliable;
public static readonly ZstdAPI Instance = new();
static ZstdAPI()
{
Avaliable = true;
string assemblyPath = System.Reflection.Assembly.GetAssembly(typeof(ZstdAPI)).Location;
string root = string.Empty;
try
{
if (!string.IsNullOrEmpty(assemblyPath))
{
root = Path.GetDirectoryName(assemblyPath) ?? string.Empty;
}
var map = new Dictionary<string, List<DynDllMapping>>
{
{
"zstdwrap.dll", [
"zstdwrap.dll",
"x64/zstdwrap.dll",
"plugins/x64/zstdwrap.dll",
"BepInEx/scripts/x64/zstdwrap.dll",
Path.Combine(root, "zstdwrap.dll"),
Path.Combine(root, "x64/zstdwrap.dll"),
Path.Combine(root, "plugins/x64/zstdwrap.dll")
]
},
};
typeof(ZstdAPI).ResolveDynDllImports(map);
Avaliable = Instance.ResolveDllImports("zstdwrap.dll");
}
catch (Exception e)
{
@@ -43,27 +19,4 @@ public class ZstdAPI: WrapperDefines
Console.WriteLine($"Error: {e}");
}
}
public ZstdAPI()
{
CompressBufferBound = CompressBufferBound_;
CompressBegin = CompressBegin_;
CompressEnd = CompressEnd_;
CompressUpdate = CompressUpdate_;
CompressContextFree = CompressContextFree_;
DecompressBegin = DecompressBegin_;
DecompressEnd = DecompressEnd_;
DecompressUpdate = DecompressUpdate_;
DecompressContextReset = DecompressContextReset_;
}
[DynDllImport(libraryName: "zstdwrap.dll", "CompressBufferBound")] protected static CompressBufferBoundFunc CompressBufferBound_;
[DynDllImport(libraryName: "zstdwrap.dll", "CompressBegin")] protected static CompressBeginFunc CompressBegin_;
[DynDllImport(libraryName: "zstdwrap.dll", "CompressEnd")] protected static CompressEndFunc CompressEnd_;
[DynDllImport(libraryName: "zstdwrap.dll", "CompressUpdate")] protected static CompressUpdateFunc CompressUpdate_;
[DynDllImport(libraryName: "zstdwrap.dll", "CompressContextFree")] protected static CompressContextFreeFunc CompressContextFree_;
[DynDllImport(libraryName: "zstdwrap.dll", "DecompressBegin")] protected static DecompressBeginFunc DecompressBegin_;
[DynDllImport(libraryName: "zstdwrap.dll", "DecompressEnd")] protected static DecompressEndFunc DecompressEnd_;
[DynDllImport(libraryName: "zstdwrap.dll", "DecompressUpdate")] protected static DecompressUpdateFunc DecompressUpdate_;
[DynDllImport(libraryName: "zstdwrap.dll", "DecompressContextReset")] protected static DecompressContextResetFunc DecompressContextReset_;
}

View File

@@ -1,7 +1,7 @@
{
"name": "CompressSave",
"version_number": "1.3.6",
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/CompressSave",
"version_number": "1.3.7",
"website_url": "https://github.com/soarqin/DSP_Mods_TO/tree/master/CompressSave",
"description": "Compress game saves to reduce space use and boost save speed / 压缩游戏存档以降低空间使用并提升保存速度",
"dependencies": ["xiaoye97-BepInEx-5.4.17"]
}