Absolute paths for everything

This commit is contained in:
igor725 2024-05-03 22:15:56 +03:00
parent e144c04672
commit 4b53cd850a
No known key found for this signature in database
GPG Key ID: 46F13BBE46F8569D
11 changed files with 75 additions and 2751 deletions

View File

@ -39,6 +39,7 @@ target_link_libraries(core PRIVATE
libboost_thread libboost_thread
libboost_chrono libboost_chrono
libboost_program_options libboost_program_options
libboost_filesystem
sdl2 sdl2
psoff_render.lib psoff_render.lib
gamereport.lib gamereport.lib

View File

@ -11,6 +11,7 @@
#include "util/moduleLoader.h" #include "util/moduleLoader.h"
#include "util/plt.h" #include "util/plt.h"
#include "util/virtualmemory.h" #include "util/virtualmemory.h"
#include "utility/progloc.h"
#include "utility/utility.h" #include "utility/utility.h"
#include <boost/uuid/detail/sha1.hpp> #include <boost/uuid/detail/sha1.hpp>
@ -24,8 +25,8 @@ LOG_DEFINE_MODULE(RuntimeLinker);
namespace { namespace {
using atexit_func_t = SYSV_ABI void (*)(); using atexit_func_t = SYSV_ABI void (*)();
using entry_func_t = SYSV_ABI void (*)(EntryParams const* params, atexit_func_t atexit_func); using entry_func_t = SYSV_ABI void (*)(EntryParams const* params, atexit_func_t atexit_func);
using module_func_t = SYSV_ABI int (*)(size_t args, const void* argp, atexit_func_t atexit_func); using module_func_t = SYSV_ABI int (*)(size_t args, const void* argp, atexit_func_t atexit_func);
struct FrameS { struct FrameS {
FrameS* next; FrameS* next;
@ -489,13 +490,13 @@ void RuntimeLinker::loadModules(std::string_view libName) {
LOG_DEBUG(L"Needs library %S", name.data()); LOG_DEBUG(L"Needs library %S", name.data());
// 1/2 Sepcial case: old->new, build filepath // 1/2 Sepcial case: old->new, build filepath
std::string filepath = std::string("modules/"); auto filepath = std::format(L"{}/modules/", util::getProgramLoc());
if (name == "libSceGnmDriver") { if (name == "libSceGnmDriver") {
filepath += "libSceGraphicsDriver"; filepath += L"libSceGraphicsDriver";
} else { } else {
filepath += std::string(name); filepath += std::wstring(name.begin(), name.end());
} }
filepath += ".dll"; filepath += L".dll";
//- filepath //- filepath
if (std::filesystem::exists(filepath) && !m_libHandles.contains(name)) { if (std::filesystem::exists(filepath) && !m_libHandles.contains(name)) {
@ -854,4 +855,4 @@ uintptr_t RuntimeLinker::execute() {
IRuntimeLinker& accessRuntimeLinker() { IRuntimeLinker& accessRuntimeLinker() {
static RuntimeLinker inst; static RuntimeLinker inst;
return inst; return inst;
} }

View File

@ -12,10 +12,10 @@
LOG_DEFINE_MODULE(ModuleLoader); LOG_DEFINE_MODULE(ModuleLoader);
std::pair<void*, std::unique_ptr<Symbols::SymbolExport>> loadModule(const char* libName, const char* filepath, int libVersion) { std::pair<void*, std::unique_ptr<Symbols::SymbolExport>> loadModule(const char* libName, const wchar_t* filepath, int libVersion) {
LOG_USE_MODULE(ModuleLoader); LOG_USE_MODULE(ModuleLoader);
HMODULE hModule = LoadLibrary(filepath); HMODULE hModule = LoadLibraryW(filepath);
if (hModule == NULL) { if (hModule == NULL) {
LOG_ERR(L"Couldn't load library %S, err:%d", filepath, GetLastError()); LOG_ERR(L"Couldn't load library %S, err:%d", filepath, GetLastError());
return {}; return {};
@ -66,4 +66,4 @@ std::pair<void*, std::unique_ptr<Symbols::SymbolExport>> loadModule(const char*
void unloadModule(void* handle) { void unloadModule(void* handle) {
FreeLibrary((HMODULE)handle); FreeLibrary((HMODULE)handle);
} }

View File

@ -6,6 +6,6 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
std::pair<void*, std::unique_ptr<Symbols::SymbolExport>> loadModule(const char* name, const char* filepath, int libVersion); std::pair<void*, std::unique_ptr<Symbols::SymbolExport>> loadModule(const char* name, const wchar_t* filepath, int libVersion);
void unloadModule(void* handle); void unloadModule(void* handle);

View File

@ -6,11 +6,11 @@
#include "logging.h" #include "logging.h"
#include "modules_include/system_param.h" #include "modules_include/system_param.h"
#include "tools/config_emu/config_emu.h" #include "tools/config_emu/config_emu.h"
#include "xml3all.h"
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include <fstream> #include <fstream>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <xml3all.h>
#define TR_AES_BLOCK_SIZE 16 #define TR_AES_BLOCK_SIZE 16
// We don't need it there // We don't need it there
@ -67,7 +67,7 @@ class Trophies: public ITrophies {
if (vname == "id") { if (vname == "id") {
trpcb->data.id = chvar->GetValueInt(-1); trpcb->data.id = chvar->GetValueInt(-1);
} else if (vname == "hidden") { } else if (vname == "hidden") {
trpcb->data.hidden = chvar->GetValue() != "no"; trpcb->data.hidden = chvar->GetValue() == "yes";
} else if (vname == "ttype") { } else if (vname == "ttype") {
trpcb->data.type = chvar->GetValue().at(0); trpcb->data.type = chvar->GetValue().at(0);
} else if (vname == "gid") { } else if (vname == "gid") {
@ -118,7 +118,7 @@ class Trophies: public ITrophies {
} // element: trophyconf } // element: trophyconf
} // xml parser } // xml parser
return ErrCodes::CONTINUE; // todo: error checkers return ErrCodes::CONTINUE; // todo: check xml errors
} }
ErrCodes TRP_readentry(const trp_entry& ent, trp_entry& dent, std::ifstream& trfile, trp_grp_cb* grpcb, trp_ent_cb* trpcb, trp_png_cb* pngcb, ErrCodes TRP_readentry(const trp_entry& ent, trp_entry& dent, std::ifstream& trfile, trp_grp_cb* grpcb, trp_ent_cb* trpcb, trp_png_cb* pngcb,
@ -174,7 +174,7 @@ class Trophies: public ITrophies {
if (!trfile.read(mem.get(), ent.len)) return ErrCodes::IO_FAIL; if (!trfile.read(mem.get(), ent.len)) return ErrCodes::IO_FAIL;
} else { } else {
static constexpr int32_t IV_SIZE = TR_AES_BLOCK_SIZE; static constexpr int32_t IV_SIZE = TR_AES_BLOCK_SIZE;
static constexpr int32_t ENC_SCE_SIGN_SIZE = TR_AES_BLOCK_SIZE * 3; static constexpr int32_t ENC_SCE_SIGN_SIZE = TR_AES_BLOCK_SIZE * 3; // 384 encrypted bits is just enough to find interesting for us string
uint8_t d_iv[TR_AES_BLOCK_SIZE]; uint8_t d_iv[TR_AES_BLOCK_SIZE];
uint8_t kg_iv[TR_AES_BLOCK_SIZE]; uint8_t kg_iv[TR_AES_BLOCK_SIZE];
@ -182,8 +182,6 @@ class Trophies: public ITrophies {
::memset(kg_iv, 0, TR_AES_BLOCK_SIZE); ::memset(kg_iv, 0, TR_AES_BLOCK_SIZE);
if (!trfile.read((char*)d_iv, TR_AES_BLOCK_SIZE)) return ErrCodes::IO_FAIL; if (!trfile.read((char*)d_iv, TR_AES_BLOCK_SIZE)) return ErrCodes::IO_FAIL;
// 384 encrypted bits is just enough to find interesting for us string
if (!trfile.read((char*)enc_xmlh, ENC_SCE_SIGN_SIZE)) return ErrCodes::IO_FAIL; if (!trfile.read((char*)enc_xmlh, ENC_SCE_SIGN_SIZE)) return ErrCodes::IO_FAIL;
const auto trydecrypt = [this, &mem, &ent, d_iv, kg_iv, enc_xmlh, &trfile](uint32_t npid) -> bool { const auto trydecrypt = [this, &mem, &ent, d_iv, kg_iv, enc_xmlh, &trfile](uint32_t npid) -> bool {

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@ add_library(config_emu SHARED config_emu.cpp)
add_dependencies(config_emu third_party) add_dependencies(config_emu third_party)
target_link_libraries(config_emu PUBLIC libboost_thread) target_link_libraries(config_emu PUBLIC libboost_thread libboost_filesystem)
target_compile_definitions(config_emu PUBLIC BOOST_ALL_NO_LIB WIN32_LEAN_AND_MEAN) target_compile_definitions(config_emu PUBLIC BOOST_ALL_NO_LIB WIN32_LEAN_AND_MEAN)
target_compile_options(config_emu PRIVATE "/Zi") target_compile_options(config_emu PRIVATE "/Zi")

View File

@ -2,34 +2,36 @@
#include "config_emu.h" #include "config_emu.h"
#undef __APICALL_EXTERN #undef __APICALL_EXTERN
#include "utility/progloc.h"
#include <fstream> #include <fstream>
#include <future> #include <future>
namespace { namespace {
class Item { class Item {
public: public:
std::string_view const _name; std::wstring_view const _name;
bool _dontfix; // If this flag is set then load function won't try fix the file according to default object bool _dontfix; // If this flag is set then load function won't try fix the file according to default object
json _json; json _json;
boost::mutex _mutex; boost::mutex _mutex;
std::future<void> _future; std::future<void> _future;
Item(std::string_view name, bool df = false): _name(name), _dontfix(df) {} Item(std::wstring_view name, bool df = false): _name(name), _dontfix(df) {}
std::pair<boost::unique_lock<boost::mutex>, json*> access() { std::pair<boost::unique_lock<boost::mutex>, json*> access() {
_future.wait(); _future.wait();
return std::make_pair(boost::unique_lock(_mutex), &_json); return std::make_pair(boost::unique_lock(_mutex), &_json);
} }
bool save() { bool save(const std::wstring& root) {
auto path = std::string("./config/") + _name.data(); auto path = root + _name.data();
try { try {
std::ofstream json_file(path); std::ofstream json_file(path);
json_file << std::setw(2) << _json; json_file << std::setw(2) << _json;
return true; return true;
} catch (const json::exception& e) { } catch (const json::exception& e) {
printf("Failed to save %s: %s\n", _name.data(), e.what()); printf("Failed to save %ls: %s\n", _name.data(), e.what());
return false; return false;
} }
}; };
@ -41,13 +43,15 @@ static inline bool isJsonTypesSimilar(json& a, json& b) {
} // namespace } // namespace
class Config: public IConfig { class Config: public IConfig {
friend class Item;
std::wstring m_cfgroot;
Item m_logging = {"logging.json"}; Item m_logging = {L"logging.json"};
Item m_graphics = {"graphics.json"}; Item m_graphics = {L"graphics.json"};
Item m_audio = {"audio.json"}; Item m_audio = {L"audio.json"};
Item m_controls = {"controls.json"}; Item m_controls = {L"controls.json"};
Item m_general = {"general.json"}; Item m_general = {L"general.json"};
Item m_resolve = {"resolve.json", true /*dontfix flag*/}; Item m_resolve = {L"resolve.json", true /*dontfix flag*/};
public: public:
Config(); Config();
@ -80,20 +84,23 @@ bool Config::save(uint32_t flags) {
bool result = true; bool result = true;
if (!std::filesystem::is_directory("./config/")) std::filesystem::create_directory("./config/"); if (!std::filesystem::is_directory(m_cfgroot)) std::filesystem::create_directory(m_cfgroot);
if (flags & (uint32_t)ConfigModFlag::LOGGING) result &= m_logging.save(); if (flags & (uint32_t)ConfigModFlag::LOGGING) result &= m_logging.save(m_cfgroot);
if (flags & (uint32_t)ConfigModFlag::GRAPHICS) result &= m_graphics.save(); if (flags & (uint32_t)ConfigModFlag::GRAPHICS) result &= m_graphics.save(m_cfgroot);
if (flags & (uint32_t)ConfigModFlag::AUDIO) result &= m_audio.save(); if (flags & (uint32_t)ConfigModFlag::AUDIO) result &= m_audio.save(m_cfgroot);
if (flags & (uint32_t)ConfigModFlag::CONTROLS) result &= m_controls.save(); if (flags & (uint32_t)ConfigModFlag::CONTROLS) result &= m_controls.save(m_cfgroot);
if (flags & (uint32_t)ConfigModFlag::GENERAL) result &= m_general.save(); if (flags & (uint32_t)ConfigModFlag::GENERAL) result &= m_general.save(m_cfgroot);
if (flags & (uint32_t)ConfigModFlag::RESOLVE) result &= m_resolve.save(); if (flags & (uint32_t)ConfigModFlag::RESOLVE) result &= m_resolve.save(m_cfgroot);
return true; return true;
} }
Config::Config() { Config::Config() {
m_cfgroot = util::getProgramLoc();
m_cfgroot += L"/config/";
auto load = [this](Item* item, json defaults = {}, ConfigModFlag dflag = ConfigModFlag::NONE) { auto load = [this](Item* item, json defaults = {}, ConfigModFlag dflag = ConfigModFlag::NONE) {
auto path = std::string("./config/") + item->_name.data(); auto path = m_cfgroot + item->_name.data();
bool should_resave = false, should_backup = false; bool should_resave = false, should_backup = false;
try { try {
@ -101,13 +108,13 @@ Config::Config() {
item->_json = json::parse(json_file, nullptr, true, true); item->_json = json::parse(json_file, nullptr, true, true);
if ((item->_json).type() == defaults.type()) { if ((item->_json).type() == defaults.type()) {
printf("Config %s loaded successfully\n", item->_name.data()); printf("Config %ls loaded successfully\n", item->_name.data());
} else { } else {
should_backup = true; should_backup = true;
should_resave = true; should_resave = true;
} }
} catch (const json::exception& e) { } catch (const json::exception& e) {
if ((std::filesystem::exists(path))) printf("Failed to parse %s: %s\n", item->_name.data(), e.what()); if ((std::filesystem::exists(path))) printf("Failed to parse %ls: %s\n", item->_name.data(), e.what());
item->_json = defaults; item->_json = defaults;
should_resave = true; should_resave = true;
@ -170,7 +177,7 @@ Config::Config() {
if (!item->_dontfix && fixMissing(item->_json, defaults)) { if (!item->_dontfix && fixMissing(item->_json, defaults)) {
should_resave = true; should_resave = true;
printf("%s: some missing or invalid parameters has been fixed!\n", item->_name.data()); printf("%ls: some missing or invalid parameters has been fixed!\n", item->_name.data());
} }
// Just the same thing as above, but for removing unused keys this time // Just the same thing as above, but for removing unused keys this time
@ -198,7 +205,7 @@ Config::Config() {
if (!item->_dontfix && removeUnused(item->_json, defaults)) { if (!item->_dontfix && removeUnused(item->_json, defaults)) {
should_backup = true; should_backup = true;
should_resave = true; should_resave = true;
printf("%s: some unused parameters has been removed!\n", item->_name.data()); printf("%ls: some unused parameters has been removed!\n", item->_name.data());
} }
if (should_backup == true && std::filesystem::exists(path)) { if (should_backup == true && std::filesystem::exists(path)) {
@ -207,7 +214,7 @@ Config::Config() {
newp.replace_extension(".back"); newp.replace_extension(".back");
std::filesystem::rename(path, newp); std::filesystem::rename(path, newp);
} catch (const std::filesystem::filesystem_error& e) { } catch (const std::filesystem::filesystem_error& e) {
printf("%s: failed to create a backup: %s", path.c_str(), e.what()); printf("%ls: failed to create a backup: %s", path.c_str(), e.what());
} }
} }

22
utility/progloc.h Normal file
View File

@ -0,0 +1,22 @@
#pragma once
#ifndef BOOST_ALL_NO_LIB
#define BOOST_ALL_NO_LIB
#endif
#include <boost/dll/runtime_symbol_info.hpp>
namespace util {
inline std::wstring getProgramLoc() {
boost::system::error_code ec;
auto path = boost::dll::program_location(ec);
if (ec.failed()) {
printf("Failed to getProgramLoc(): %s", ec.message().c_str());
exit(1);
}
path.remove_filename();
return path.c_str();
}
} // namespace util

View File

@ -6,6 +6,7 @@
#include <fstream> #include <fstream>
#include <memory> #include <memory>
#include <windows.h> #include <windows.h>
LOG_DEFINE_MODULE(util); LOG_DEFINE_MODULE(util);
namespace util { namespace util {
@ -59,4 +60,4 @@ int getPageSize(void) {
}(); }();
return pageSize; return pageSize;
} }
} // namespace util } // namespace util

View File

@ -108,4 +108,4 @@ int getPageSize(void);
#define CLASS_NO_MOVE(name) \ #define CLASS_NO_MOVE(name) \
name(name&&) noexcept = delete; \ name(name&&) noexcept = delete; \
name& operator=(name&&) noexcept = delete name& operator=(name&&) noexcept = delete