Cheats: Use libzip for reading archive
This commit is contained in:
parent
761c8bdf7f
commit
a8d846ac8f
|
@ -20,6 +20,7 @@ find_package(lunasvg 2.4.1 REQUIRED)
|
||||||
find_package(cpuinfo REQUIRED)
|
find_package(cpuinfo REQUIRED)
|
||||||
find_package(DiscordRPC 3.4.0 REQUIRED)
|
find_package(DiscordRPC 3.4.0 REQUIRED)
|
||||||
find_package(SoundTouch 2.3.3 REQUIRED)
|
find_package(SoundTouch 2.3.3 REQUIRED)
|
||||||
|
find_package(libzip 1.11.1 REQUIRED)
|
||||||
|
|
||||||
if(NOT WIN32)
|
if(NOT WIN32)
|
||||||
find_package(CURL REQUIRED)
|
find_package(CURL REQUIRED)
|
||||||
|
|
|
@ -140,7 +140,7 @@ target_precompile_headers(core PRIVATE "pch.h")
|
||||||
target_include_directories(core PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
target_include_directories(core PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||||
target_include_directories(core PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
target_include_directories(core PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||||
target_link_libraries(core PUBLIC Threads::Threads common util)
|
target_link_libraries(core PUBLIC Threads::Threads common util)
|
||||||
target_link_libraries(core PRIVATE xxhash imgui minizip rapidyaml rcheevos cpuinfo::cpuinfo ZLIB::ZLIB Zstd::Zstd)
|
target_link_libraries(core PRIVATE xxhash imgui rapidyaml rcheevos cpuinfo::cpuinfo ZLIB::ZLIB Zstd::Zstd libzip::zip)
|
||||||
|
|
||||||
if(CPU_ARCH_X64)
|
if(CPU_ARCH_X64)
|
||||||
target_compile_definitions(core PUBLIC "ENABLE_RECOMPILER=1" "ENABLE_NEWREC=1" "ENABLE_MMAP_FASTMEM=1")
|
target_compile_definitions(core PUBLIC "ENABLE_RECOMPILER=1" "ENABLE_NEWREC=1" "ENABLE_MMAP_FASTMEM=1")
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
#include "common/error.h"
|
#include "common/error.h"
|
||||||
#include "common/file_system.h"
|
#include "common/file_system.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/minizip_helpers.h"
|
|
||||||
#include "common/path.h"
|
#include "common/path.h"
|
||||||
#include "common/small_string.h"
|
#include "common/small_string.h"
|
||||||
#include "common/string_util.h"
|
#include "common/string_util.h"
|
||||||
|
#include "common/zip_helpers.h"
|
||||||
|
|
||||||
#include "IconsEmoji.h"
|
#include "IconsEmoji.h"
|
||||||
#include "IconsFontAwesome5.h"
|
#include "IconsFontAwesome5.h"
|
||||||
|
@ -99,29 +99,31 @@ class CheatArchive
|
||||||
public:
|
public:
|
||||||
~CheatArchive()
|
~CheatArchive()
|
||||||
{
|
{
|
||||||
if (m_unz_file)
|
// zip has to be destroyed before data
|
||||||
unzClose(m_unz_file);
|
m_zip.reset();
|
||||||
|
m_data.deallocate();
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE bool IsOpen() const { return (m_unz_file != nullptr); }
|
ALWAYS_INLINE bool IsOpen() const { return static_cast<bool>(m_zip); }
|
||||||
|
|
||||||
bool Open(const char* name)
|
bool Open(const char* name)
|
||||||
{
|
{
|
||||||
if (m_unz_file)
|
if (m_zip)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
std::optional<DynamicHeapArray<u8>> data = Host::ReadResourceFile(name, false);
|
Error error;
|
||||||
|
std::optional<DynamicHeapArray<u8>> data = Host::ReadResourceFile(name, false, &error);
|
||||||
if (!data.has_value())
|
if (!data.has_value())
|
||||||
{
|
{
|
||||||
ERROR_LOG("Failed to read cheat archive {}.", name);
|
ERROR_LOG("Failed to read cheat archive {}: {}", name, error.GetDescription());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_data = std::move(data.value());
|
m_data = std::move(data.value());
|
||||||
m_unz_file = MinizipHelpers::OpenUnzMemoryFile(m_data.data(), m_data.size());
|
m_zip = ZipHelpers::OpenManagedZipBuffer(m_data.data(), m_data.size(), 0, false, &error);
|
||||||
if (!m_unz_file) [[unlikely]]
|
if (!m_zip) [[unlikely]]
|
||||||
{
|
{
|
||||||
ERROR_LOG("Failed to open cheat archive {}.", name);
|
ERROR_LOG("Failed to open cheat archive {}: {}", name, error.GetDescription());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +133,7 @@ public:
|
||||||
std::optional<std::string> ReadFile(const char* name) const
|
std::optional<std::string> ReadFile(const char* name) const
|
||||||
{
|
{
|
||||||
Error error;
|
Error error;
|
||||||
std::optional<std::string> ret = MinizipHelpers::ReadZipFileToString(m_unz_file, name, false, &error);
|
std::optional<std::string> ret = ZipHelpers::ReadFileInZipToString(m_zip.get(), name, true, &error);
|
||||||
if (!ret.has_value())
|
if (!ret.has_value())
|
||||||
DEV_LOG("Failed to read {} from zip: {}", name, error.GetDescription());
|
DEV_LOG("Failed to read {} from zip: {}", name, error.GetDescription());
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -141,7 +143,7 @@ private:
|
||||||
// Maybe counter-intuitive, but it ends up faster for reading a single game's cheats if we keep a
|
// Maybe counter-intuitive, but it ends up faster for reading a single game's cheats if we keep a
|
||||||
// copy of the archive in memory, as opposed to reading from disk.
|
// copy of the archive in memory, as opposed to reading from disk.
|
||||||
DynamicHeapArray<u8> m_data;
|
DynamicHeapArray<u8> m_data;
|
||||||
unzFile m_unz_file = nullptr;
|
ZipHelpers::ManagedZipT m_zip;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -22,4 +22,10 @@
|
||||||
<AdditionalIncludeDirectories Condition="'$(Platform)'=='ARM' Or '$(Platform)'=='ARM64'">%(AdditionalIncludeDirectories);$(SolutionDir)dep\vixl\include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories Condition="'$(Platform)'=='ARM' Or '$(Platform)'=='ARM64'">%(AdditionalIncludeDirectories);$(SolutionDir)dep\vixl\include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
|
|
||||||
|
<ItemDefinitionGroup>
|
||||||
|
<Link>
|
||||||
|
<AdditionalDependencies>%(AdditionalDependencies);cpuinfo.lib;zip.lib</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -174,9 +174,6 @@
|
||||||
<ProjectReference Include="..\..\dep\imgui\imgui.vcxproj">
|
<ProjectReference Include="..\..\dep\imgui\imgui.vcxproj">
|
||||||
<Project>{bb08260f-6fbc-46af-8924-090ee71360c6}</Project>
|
<Project>{bb08260f-6fbc-46af-8924-090ee71360c6}</Project>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\..\dep\minizip\minizip.vcxproj">
|
|
||||||
<Project>{8bda439c-6358-45fb-9994-2ff083babe06}</Project>
|
|
||||||
</ProjectReference>
|
|
||||||
<ProjectReference Include="..\..\dep\rainterface\rainterface.vcxproj" Condition="'$(Platform)'!='ARM64'">
|
<ProjectReference Include="..\..\dep\rainterface\rainterface.vcxproj" Condition="'$(Platform)'!='ARM64'">
|
||||||
<Project>{e4357877-d459-45c7-b8f6-dcbb587bb528}</Project>
|
<Project>{e4357877-d459-45c7-b8f6-dcbb587bb528}</Project>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
@ -214,7 +211,6 @@
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<PreprocessorDefinitions Condition="'$(Platform)'=='x64' And $(Configuration.Contains('Debug'))">ZYDIS_DISABLE_ENCODER;ZYDIS_DISABLE_AVX512;ZYDIS_DISABLE_KNC;ZYDIS_STATIC_BUILD;ZYCORE_STATIC_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions Condition="'$(Platform)'=='x64' And $(Configuration.Contains('Debug'))">ZYDIS_DISABLE_ENCODER;ZYDIS_DISABLE_AVX512;ZYDIS_DISABLE_KNC;ZYDIS_STATIC_BUILD;ZYCORE_STATIC_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalIncludeDirectories Condition="'$(Platform)'=='x64' And $(Configuration.Contains('Debug'))">%(AdditionalIncludeDirectories);$(SolutionDir)dep\zydis\include;$(SolutionDir)dep\zydis\dependencies\zycore\include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories Condition="'$(Platform)'=='x64' And $(Configuration.Contains('Debug'))">%(AdditionalIncludeDirectories);$(SolutionDir)dep\zydis\include;$(SolutionDir)dep\zydis\dependencies\zycore\include</AdditionalIncludeDirectories>
|
||||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SolutionDir)dep\minizip\include</AdditionalIncludeDirectories>
|
|
||||||
<ObjectFileName>$(IntDir)/%(RelativeDir)/</ObjectFileName>
|
<ObjectFileName>$(IntDir)/%(RelativeDir)/</ObjectFileName>
|
||||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DepsIncludeDir)SDL2;$(DepsIncludeDir)spirv_cross</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DepsIncludeDir)SDL2;$(DepsIncludeDir)spirv_cross</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>%(AdditionalDependencies);cpuinfo.lib;freetype.lib;jpeg.lib;libpng16.lib;libwebp.lib;lunasvg.lib;SDL2.lib;soundtouch.lib;zlib.lib;zstd.lib</AdditionalDependencies>
|
<AdditionalDependencies>%(AdditionalDependencies);freetype.lib;jpeg.lib;libpng16.lib;libwebp.lib;lunasvg.lib;SDL2.lib;soundtouch.lib;zlib.lib;zstd.lib</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -44,6 +44,7 @@
|
||||||
<DepsDLLs Include="$(DepsBinDir)shaderc_shared.dll" />
|
<DepsDLLs Include="$(DepsBinDir)shaderc_shared.dll" />
|
||||||
<DepsDLLs Include="$(DepsBinDir)soundtouch.dll" />
|
<DepsDLLs Include="$(DepsBinDir)soundtouch.dll" />
|
||||||
<DepsDLLs Include="$(DepsBinDir)spirv-cross-c-shared.dll" />
|
<DepsDLLs Include="$(DepsBinDir)spirv-cross-c-shared.dll" />
|
||||||
|
<DepsDLLs Include="$(DepsBinDir)zip.dll" />
|
||||||
<DepsDLLs Include="$(DepsBinDir)zlib1.dll" />
|
<DepsDLLs Include="$(DepsBinDir)zlib1.dll" />
|
||||||
<DepsDLLs Include="$(DepsBinDir)zstd.dll" />
|
<DepsDLLs Include="$(DepsBinDir)zstd.dll" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
Loading…
Reference in New Issue