added configuration class

This commit is contained in:
wheremyfoodat 2023-08-14 20:17:01 +03:00 committed by georgemoralis
parent 6a5308d521
commit a0ab3dbc0c
8 changed files with 86 additions and 6 deletions

4
.gitmodules vendored
View File

@ -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

View File

@ -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

View File

@ -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();

62
src/Util/config.cpp Normal file
View File

@ -0,0 +1,62 @@
#include "config.h"
#include <fstream>
#include <string>
#include <toml11/toml.hpp>
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<toml::value>(data.at("General"));
if (generalResult.is_ok()) {
auto general = generalResult.unwrap();
isNeo = toml::find_or<toml::boolean>(general, "isPS4Pro", false);
}
}
}
void save(const std::filesystem::path& path) {
toml::basic_value<toml::preserve_comments> data;
std::error_code error;
if (std::filesystem::exists(path, error)) {
try {
data = toml::parse<toml::preserve_comments>(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

9
src/Util/config.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include <filesystem>
namespace Config {
void load(const std::filesystem::path& path);
void save(const std::filesystem::path& path);
bool isNeoMode();
}; // namespace Config

View File

@ -32,7 +32,7 @@
#include "Lib/Threads.h"
#include <emulator.h>
#include "discord.h"
#include <Util/config.h>
// Main code
int main(int argc, char* argv[])
{
@ -40,7 +40,7 @@ int main(int argc, char* argv[])
printf("Usage: %s <elf or eboot.bin path>\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<Linker>::Instance();
HLE::Libs::Init_HLE_Libs(linker->getHLESymbols());
auto *module =linker->LoadModule(path);//load main executable
Lib::Thread mainthread(
[](void*) {
auto* linker = Singleton<Linker>::Instance();

View File

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

1
third-party/toml11 vendored Submodule

@ -0,0 +1 @@
Subproject commit 087408a8fbc8983d8c590eee9d3541400dfa34d9