diff --git a/.gitmodules b/.gitmodules index 0fc17065..abb8fc02 100644 --- a/.gitmodules +++ b/.gitmodules @@ -29,3 +29,7 @@ [submodule "third-party/discord-rpc"] path = third-party/discord-rpc url = https://github.com/discord/discord-rpc +[submodule "third-party/toml11"] + path = third-party/toml11 + url = https://github.com/ToruNiina/toml11 + branch = master diff --git a/CMakeLists.txt b/CMakeLists.txt index accac029..f0a7fb03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,8 @@ add_executable(shadps4 src/GUI/ElfViewer.h src/Util/log.h src/Util/log.cpp + src/Util/config.cpp + src/Util/config.h src/Core/virtual_memory.cpp src/Core/virtual_memory.h src/Core/PS4/Linker.cpp diff --git a/src/Core/PS4/HLE/LibKernel.cpp b/src/Core/PS4/HLE/LibKernel.cpp index fae91318..30f54a34 100644 --- a/src/Core/PS4/HLE/LibKernel.cpp +++ b/src/Core/PS4/HLE/LibKernel.cpp @@ -6,6 +6,7 @@ #include "Kernel/memory_management.h" #include "../../../Util/Singleton.h" #include "Kernel/Objects/physical_memory.h" +#include "Util/config.h" namespace HLE::Libs::LibKernel { @@ -29,9 +30,9 @@ namespace HLE::Libs::LibKernel { } int PS4_SYSV_ABI sceKernelIsNeoMode() { - //BREAKPOINT(); - PRINT_DUMMY_FUNCTION_NAME(); - return 0; //it isn't PS4VR TODO + PRINT_FUNCTION_NAME(); + bool isNeo = Config::isNeoMode(); + return isNeo ? 1 : 0; } static PS4_SYSV_ABI void stack_chk_fail() { BREAKPOINT(); diff --git a/src/Util/config.cpp b/src/Util/config.cpp new file mode 100644 index 00000000..e6beab6d --- /dev/null +++ b/src/Util/config.cpp @@ -0,0 +1,62 @@ +#include "config.h" + +#include +#include +#include + +namespace Config { + +bool isNeo = false; + +bool isNeoMode() { return isNeo; } +void load(const std::filesystem::path& path) { + // If the configuration file does not exist, create it and return + std::error_code error; + if (!std::filesystem::exists(path, error)) { + save(path); + return; + } + + toml::value data; + + try { + data = toml::parse(path); + } catch (std::exception& ex) { + printf("Got exception trying to load config file. Exception: %s\n", ex.what()); + return; + } + + if (data.contains("General")) { + auto generalResult = toml::expect(data.at("General")); + if (generalResult.is_ok()) { + auto general = generalResult.unwrap(); + + isNeo = toml::find_or(general, "isPS4Pro", false); + } + } +} +void save(const std::filesystem::path& path) { + toml::basic_value data; + + std::error_code error; + if (std::filesystem::exists(path, error)) { + try { + data = toml::parse(path); + } catch (const std::exception& ex) { + printf("Exception trying to parse config file. Exception: %s\n", ex.what()); + return; + } + } else { + if (error) { + printf("Filesystem error accessing %s (error: %s)\n", path.string().c_str(), error.message().c_str()); + } + printf("Saving new configuration file %s\n", path.string().c_str()); + } + + data["General"]["isPS4Pro"] = isNeo; + + std::ofstream file(path, std::ios::out); + file << data; + file.close(); +} +} // namespace Config diff --git a/src/Util/config.h b/src/Util/config.h new file mode 100644 index 00000000..e243397f --- /dev/null +++ b/src/Util/config.h @@ -0,0 +1,9 @@ +#pragma once +#include + +namespace Config { +void load(const std::filesystem::path& path); +void save(const std::filesystem::path& path); + +bool isNeoMode(); +}; // namespace Config \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 20eec340..2e8af195 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,7 +32,7 @@ #include "Lib/Threads.h" #include #include "discord.h" - +#include // Main code int main(int argc, char* argv[]) { @@ -40,7 +40,7 @@ int main(int argc, char* argv[]) printf("Usage: %s \n", argv[0]); return -1; } - + Config::load("config.toml"); logging::init(true); // init logging Emulator::emuInit(); Lib::InitThreads(); @@ -49,7 +49,6 @@ int main(int argc, char* argv[]) auto* linker = Singleton::Instance(); HLE::Libs::Init_HLE_Libs(linker->getHLESymbols()); auto *module =linker->LoadModule(path);//load main executable - Lib::Thread mainthread( [](void*) { auto* linker = Singleton::Instance(); diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 7baa9562..a3ee0a2f 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -31,6 +31,8 @@ add_subdirectory(${zydis_DIR}) add_subdirectory(winpthread) #=================== discord-rpc =================== add_subdirectory(discord-rpc) +#=================== toml11 =================== +add_subdirectory(toml11) #=================== IMGUI =================== set(IMGUI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/imgui) diff --git a/third-party/toml11 b/third-party/toml11 new file mode 160000 index 00000000..087408a8 --- /dev/null +++ b/third-party/toml11 @@ -0,0 +1 @@ +Subproject commit 087408a8fbc8983d8c590eee9d3541400dfa34d9