Update to spice2x-25-04-25 (pre-apply)
> broken commit
This commit is contained in:
+21
-26
@@ -1,25 +1,24 @@
|
||||
#include "avshook.h"
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
|
||||
#include "avs/core.h"
|
||||
#include "avs/ea3.h"
|
||||
#include "avs/game.h"
|
||||
#include "external/layeredfs/hook.h"
|
||||
#include "util/detour.h"
|
||||
#include "util/fileutils.h"
|
||||
#include "util/logging.h"
|
||||
#include "util/utils.h"
|
||||
#include "external/layeredfs/hook.h"
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
static bool FAKE_FILE_OPEN = false;
|
||||
static bool ROM_FILE_OPEN = false;
|
||||
static const char *ROM_FILE_PATH = nullptr;
|
||||
static const char *ROM_FILE_CONTENTS = nullptr;
|
||||
|
||||
static std::map<std::string, std::string> ROM_FILE_MAP;
|
||||
static std::string *ROM_FILE_CONTENTS = nullptr;
|
||||
|
||||
namespace hooks::avs::config {
|
||||
bool DISABLE_VFS_DRIVE_REDIRECTION = false;
|
||||
@@ -62,10 +61,6 @@ static bool is_dest_spec_ea3_config(const char *name) {
|
||||
return !_stricmp(name, path.c_str());
|
||||
}
|
||||
|
||||
static bool is_rom_file(const char *name) {
|
||||
return ROM_FILE_PATH && _stricmp(name, ROM_FILE_PATH) == 0;
|
||||
}
|
||||
|
||||
static bool is_spam_file(const char *file) {
|
||||
static const char *spam_prefixes[] = {
|
||||
"/mnt/bm2d/ngp",
|
||||
@@ -85,9 +80,9 @@ static bool is_spam_file(const char *file) {
|
||||
}
|
||||
|
||||
static int avs_fs_fstat(avs::core::avs_file_t fd, struct avs::core::avs_stat *st) {
|
||||
if (is_fake_fd(fd) && ROM_FILE_OPEN) {
|
||||
if (is_fake_fd(fd) && ROM_FILE_CONTENTS) {
|
||||
if (st) {
|
||||
st->filesize = static_cast<uint32_t>(strlen(ROM_FILE_CONTENTS));
|
||||
st->filesize = static_cast<uint32_t>(ROM_FILE_CONTENTS->length());
|
||||
st->padding.st_dev = 0;
|
||||
}
|
||||
return 1;
|
||||
@@ -109,9 +104,7 @@ static int avs_fs_lstat(const char *name, struct avs::core::avs_stat *st) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto value = layeredfs::initialized
|
||||
? layeredfs::hook_avs_fs_lstat(name, st) : avs::core::avs_fs_lstat(name, st);
|
||||
|
||||
auto value = avs::core::avs_fs_lstat(name, st);
|
||||
if (!is_spam_file(name)) {
|
||||
WRAP_DEBUG_FMT("name: {}", name);
|
||||
}
|
||||
@@ -124,11 +117,11 @@ static avs::core::avs_file_t avs_fs_open(const char *name, uint16_t mode, int fl
|
||||
return avs::core::avs_fs_open(name, mode, flags);
|
||||
}
|
||||
|
||||
if (!FAKE_FILE_OPEN && (is_dest_file(name, mode) || is_rom_file(name))) {
|
||||
if (!FAKE_FILE_OPEN && (is_dest_file(name, mode) || ROM_FILE_MAP.contains(name))) {
|
||||
FAKE_FILE_OPEN = true;
|
||||
|
||||
if (is_rom_file(name)) {
|
||||
ROM_FILE_OPEN = true;
|
||||
if (ROM_FILE_MAP.contains(name)) {
|
||||
ROM_FILE_CONTENTS = &ROM_FILE_MAP.at(name);
|
||||
}
|
||||
|
||||
log_info("avshook", "opening fake file '{}'", name);
|
||||
@@ -136,8 +129,7 @@ static avs::core::avs_file_t avs_fs_open(const char *name, uint16_t mode, int fl
|
||||
return 1337;
|
||||
}
|
||||
|
||||
auto value = layeredfs::initialized
|
||||
? layeredfs::hook_avs_fs_open(name, mode, flags) : avs::core::avs_fs_open(name, mode, flags);
|
||||
auto value = avs::core::avs_fs_open(name, mode, flags);
|
||||
|
||||
if (!is_spam_file(name)) {
|
||||
WRAP_DEBUG_FMT("name: {} mode: {} flags: {}", name, mode, flags);
|
||||
@@ -149,7 +141,7 @@ static avs::core::avs_file_t avs_fs_open(const char *name, uint16_t mode, int fl
|
||||
static void avs_fs_close(avs::core::avs_file_t fd) {
|
||||
if (is_fake_fd(fd)) {
|
||||
FAKE_FILE_OPEN = false;
|
||||
ROM_FILE_OPEN = false;
|
||||
ROM_FILE_CONTENTS = nullptr;
|
||||
|
||||
log_info("hooks::avs", "closing fake fd");
|
||||
} else {
|
||||
@@ -180,7 +172,11 @@ static avs::core::avs_file_t avs_fs_opendir(const char *path) {
|
||||
}
|
||||
|
||||
static int avs_fs_mount(const char *mountpoint, const char *fsroot, const char *fstype, void *data) {
|
||||
if (mountpoint == nullptr || fsroot == nullptr || fstype == nullptr) {
|
||||
// avs redirection breaks ongaku paradise
|
||||
if (mountpoint == nullptr ||
|
||||
fsroot == nullptr ||
|
||||
fstype == nullptr ||
|
||||
avs::game::is_model("JC9")) {
|
||||
return avs::core::avs_fs_mount(mountpoint, fsroot, fstype, data);
|
||||
}
|
||||
|
||||
@@ -244,10 +240,10 @@ static int avs_fs_mount(const char *mountpoint, const char *fsroot, const char *
|
||||
}
|
||||
|
||||
static size_t avs_fs_read(avs::core::avs_file_t fd, uint8_t *data, uint32_t data_size) {
|
||||
if (is_fake_fd(fd) && ROM_FILE_OPEN) {
|
||||
const auto size = std::min(static_cast<size_t>(data_size), strlen(ROM_FILE_CONTENTS));
|
||||
if (is_fake_fd(fd) && ROM_FILE_CONTENTS) {
|
||||
const auto size = std::min(static_cast<size_t>(data_size), ROM_FILE_CONTENTS->length());
|
||||
|
||||
memcpy(data, ROM_FILE_CONTENTS, size);
|
||||
memcpy(data, ROM_FILE_CONTENTS->c_str(), size);
|
||||
|
||||
return size;
|
||||
}
|
||||
@@ -288,6 +284,5 @@ void hooks::avs::init() {
|
||||
}
|
||||
|
||||
void hooks::avs::set_rom(const char *path, const char *contents) {
|
||||
ROM_FILE_PATH = path;
|
||||
ROM_FILE_CONTENTS = contents;
|
||||
ROM_FILE_MAP.emplace(path, contents);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user