Add nusc struct and split into audio class
This commit is contained in:
parent
183d54d5a4
commit
c592bccad4
@ -69,8 +69,9 @@ library(
|
||||
'src/patches/jp_nov_2020.cpp',
|
||||
'src/patches/jp_apr_2023.cpp',
|
||||
'src/patches/cn_jun_2023.cpp',
|
||||
'src/patches/amauth.cpp',
|
||||
'src/patches/audio.cpp',
|
||||
'src/patches/qr.cpp',
|
||||
'src/patches/amauth.cpp',
|
||||
],
|
||||
name_prefix: ''
|
||||
)
|
||||
|
77
src/patches/audio.cpp
Normal file
77
src/patches/audio.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include "constants.h"
|
||||
#include "helpers.h"
|
||||
#include "patches.h"
|
||||
|
||||
extern GameVersion gameVersion;
|
||||
|
||||
namespace patches::Audio {
|
||||
|
||||
typedef struct nusc_init_config {
|
||||
uint32_t sample_rate;
|
||||
uint32_t buffer_size;
|
||||
uint32_t device_mode;
|
||||
uint32_t channel_count;
|
||||
const char *asio_driver_name;
|
||||
bool wasapi_disable_com;
|
||||
bool wasapi_exclusive;
|
||||
uint32_t wasapi_exclusive_buffer_size;
|
||||
void *wasapi_audioses;
|
||||
} nusc_init_config_t;
|
||||
|
||||
bool wasapiShared = true;
|
||||
bool asio = false;
|
||||
std::string asioDriver = "";
|
||||
|
||||
HOOK_DYNAMIC (i64, __fastcall, NUSCDeviceInit, void *a1, nusc_init_config_t *a2, nusc_init_config_t *a3, void *a4) {
|
||||
a2->device_mode = asio;
|
||||
a2->asio_driver_name = asio ? asioDriver.c_str () : "";
|
||||
a2->wasapi_exclusive = asio ? 1 : wasapiShared ? 0 : 1;
|
||||
return originalNUSCDeviceInit (a1, a2, a3, a4);
|
||||
}
|
||||
HOOK_DYNAMIC (bool, __fastcall, LoadASIODriver, void *a1, const char *a2) {
|
||||
auto result = originalLoadASIODriver (a1, a2);
|
||||
if (!result) {
|
||||
MessageBoxA (nullptr, "Failed to load ASIO driver", nullptr, MB_OK);
|
||||
ExitProcess (0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
Init () {
|
||||
auto configPath = std::filesystem::current_path () / "config.toml";
|
||||
std::unique_ptr<toml_table_t, void (*) (toml_table_t *)> config_ptr (openConfig (configPath), toml_free);
|
||||
if (config_ptr) {
|
||||
auto patches = openConfigSection (config_ptr.get (), "patches");
|
||||
if (patches) {
|
||||
auto audio = openConfigSection (patches, "audio");
|
||||
if (audio) {
|
||||
wasapiShared = readConfigBool (audio, "wasapi_shared", wasapiShared);
|
||||
asio = readConfigBool (audio, "asio", asio);
|
||||
asioDriver = readConfigString (audio, "asio_driver", asioDriver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (gameVersion) {
|
||||
case GameVersion::JP_NOV_2020: {
|
||||
INSTALL_HOOK_DYNAMIC (NUSCDeviceInit, ASLR (0x140692E00));
|
||||
INSTALL_HOOK_DYNAMIC (LoadASIODriver, ASLR (0x14069B750));
|
||||
break;
|
||||
}
|
||||
case GameVersion::JP_APR_2023: {
|
||||
INSTALL_HOOK_DYNAMIC (NUSCDeviceInit, ASLR (0x1407C8620));
|
||||
INSTALL_HOOK_DYNAMIC (LoadASIODriver, ASLR (0x1407D0F70));
|
||||
break;
|
||||
}
|
||||
case GameVersion::CN_JUN_2023: {
|
||||
INSTALL_HOOK_DYNAMIC (NUSCDeviceInit, ASLR (0x140777F70));
|
||||
INSTALL_HOOK_DYNAMIC (LoadASIODriver, ASLR (0x1407808C0));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace patches::Audio
|
@ -24,25 +24,6 @@ HOOK (i32, HaspRead, PROC_ADDRESS ("hasp_windows_x64.dll", "hasp_read"), i32, i3
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool wasapiShared = true;
|
||||
bool asio = false;
|
||||
std::string asioDriver = "";
|
||||
HOOK (i64, NUSCDeviceInit, ASLR (0x140777F70), void *a1, void *a2, void *a3, void *a4) {
|
||||
*(u32 *)((u8 *)a2 + 0x8) = asio;
|
||||
*(const char **)((u8 *)a2 + 0x10) = asio ? asioDriver.c_str () : "";
|
||||
*(u16 *)((u8 *)a2 + 0x18) = (!asio && wasapiShared) ? 0 : 256;
|
||||
*(u16 *)((u8 *)a2 + 0x1C) = (!asio && wasapiShared) ? 0 : 256;
|
||||
return originalNUSCDeviceInit (a1, a2, a3, a4);
|
||||
}
|
||||
HOOK (bool, LoadASIODriver, ASLR (0x1407808C0), void *a1, const char *a2) {
|
||||
auto result = originalLoadASIODriver (a1, a2);
|
||||
if (!result) {
|
||||
MessageBoxA (nullptr, "Failed to load ASIO driver", nullptr, MB_OK);
|
||||
ExitProcess (0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
i64 (__fastcall *lua_settop) (u64, u64) = (i64 (__fastcall *) (u64, u64))PROC_ADDRESS ("lua51.dll", "lua_settop");
|
||||
i64 (__fastcall *lua_pushboolean) (u64, u64) = (i64 (__fastcall *) (u64, u64))PROC_ADDRESS ("lua51.dll", "lua_pushboolean");
|
||||
i64 (__fastcall *lua_pushstring) (u64, u64) = (i64 (__fastcall *) (u64, u64))PROC_ADDRESS ("lua51.dll", "lua_pushstring");
|
||||
@ -154,12 +135,6 @@ Init () {
|
||||
}
|
||||
vsync = readConfigBool (patches, "vsync", vsync);
|
||||
unlockSongs = readConfigBool (patches, "unlock_songs", unlockSongs);
|
||||
auto audio = openConfigSection (patches, "audio");
|
||||
if (audio) {
|
||||
wasapiShared = readConfigBool (audio, "wasapi_shared", wasapiShared);
|
||||
asio = readConfigBool (audio, "asio", asio);
|
||||
asioDriver = readConfigString (audio, "asio_driver", asioDriver);
|
||||
}
|
||||
auto cn_jun_2023 = openConfigSection (patches, "cn_jun_2023");
|
||||
if (cn_jun_2023) {
|
||||
fixLanguage = readConfigBool (cn_jun_2023, "fix_language", fixLanguage);
|
||||
@ -176,10 +151,6 @@ Init () {
|
||||
if (!vsync) WRITE_MEMORY (ASLR (0x1405FC5B9), u8, 0xBA, 0x00, 0x00, 0x00, 0x00, 0x90);
|
||||
if (unlockSongs) WRITE_MEMORY (ASLR (0x140425BCD), u8, 0xB0, 0x01);
|
||||
|
||||
// Setting audio device
|
||||
INSTALL_HOOK (NUSCDeviceInit);
|
||||
INSTALL_HOOK (LoadASIODriver);
|
||||
|
||||
// Bypass errors
|
||||
WRITE_MEMORY (ASLR (0x14003F690), u8, 0xC3);
|
||||
|
||||
@ -246,6 +217,7 @@ Init () {
|
||||
WRITE_MEMORY (amHandle + 0x24DD1, u8, 0x90, 0x90, 0x90, 0x90, 0x90); // BackupDataPathA
|
||||
WRITE_MEMORY (amHandle + 0x24E47, u8, 0x90, 0x90, 0x90, 0x90, 0x90); // BackupDataPathB
|
||||
|
||||
patches::Audio::Init ();
|
||||
patches::Qr::Init ();
|
||||
}
|
||||
} // namespace patches::CN_JUN_2023
|
||||
|
@ -4,25 +4,6 @@
|
||||
|
||||
namespace patches::JP_APR_2023 {
|
||||
|
||||
bool wasapiShared = true;
|
||||
bool asio = false;
|
||||
std::string asioDriver = "";
|
||||
HOOK (i64, NUSCDeviceInit, ASLR (0x1407C8620), void *a1, void *a2, void *a3, void *a4) {
|
||||
*(u32 *)((u8 *)a2 + 0x8) = asio;
|
||||
*(const char **)((u8 *)a2 + 0x10) = asio ? asioDriver.c_str () : "";
|
||||
*(u16 *)((u8 *)a2 + 0x18) = (!asio && wasapiShared) ? 0 : 256;
|
||||
*(u16 *)((u8 *)a2 + 0x1C) = (!asio && wasapiShared) ? 0 : 256;
|
||||
return originalNUSCDeviceInit (a1, a2, a3, a4);
|
||||
}
|
||||
HOOK (bool, LoadASIODriver, ASLR (0x1407D0F70), void *a1, const char *a2) {
|
||||
auto result = originalLoadASIODriver (a1, a2);
|
||||
if (!result) {
|
||||
MessageBoxA (nullptr, "Failed to load ASIO driver", nullptr, MB_OK);
|
||||
ExitProcess (0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
HOOK_DYNAMIC (char, __fastcall, AMFWTerminate, i64) { return 0; }
|
||||
|
||||
HOOK_DYNAMIC (i64, __fastcall, curl_easy_setopt, i64 a1, i64 a2, i64 a3, i64 a4, i64 a5) {
|
||||
@ -78,12 +59,6 @@ Init () {
|
||||
}
|
||||
vsync = readConfigBool (patches, "vsync", vsync);
|
||||
unlockSongs = readConfigBool (patches, "unlock_songs", unlockSongs);
|
||||
auto audio = openConfigSection (patches, "audio");
|
||||
if (audio) {
|
||||
wasapiShared = readConfigBool (audio, "wasapi_shared", wasapiShared);
|
||||
asio = readConfigBool (audio, "asio", asio);
|
||||
asioDriver = readConfigString (audio, "asio_driver", asioDriver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,10 +68,6 @@ Init () {
|
||||
if (!vsync) WRITE_MEMORY (ASLR (0x14064C7E9), u8, 0xBA, 0x00, 0x00, 0x00, 0x00, 0x90);
|
||||
if (unlockSongs) WRITE_MEMORY (ASLR (0x1403F45CF), u8, 0xB0, 0x01);
|
||||
|
||||
// Setting audio device
|
||||
INSTALL_HOOK (NUSCDeviceInit);
|
||||
INSTALL_HOOK (LoadASIODriver);
|
||||
|
||||
// Bypass errors
|
||||
WRITE_MEMORY (ASLR (0x140041A00), u8, 0xC3);
|
||||
|
||||
@ -163,6 +134,7 @@ Init () {
|
||||
auto garmcHandle = (u64)GetModuleHandle ("garmc.dll");
|
||||
INSTALL_HOOK_DYNAMIC (curl_easy_setopt, (void *)(garmcHandle + 0x1FBBB0));
|
||||
|
||||
patches::Audio::Init ();
|
||||
patches::Qr::Init ();
|
||||
patches::AmAuth::Init ();
|
||||
}
|
||||
|
@ -13,25 +13,6 @@ void *song_data;
|
||||
|
||||
namespace patches::JP_NOV_2020 {
|
||||
|
||||
bool wasapiShared = true;
|
||||
bool asio = false;
|
||||
std::string asioDriver = "";
|
||||
HOOK (i64, NUSCDeviceInit, ASLR (0x140692E00), void *a1, void *a2, void *a3, void *a4) {
|
||||
*(u32 *)((u8 *)a2 + 0x8) = asio;
|
||||
*(const char **)((u8 *)a2 + 0x10) = asio ? asioDriver.c_str () : "";
|
||||
*(u16 *)((u8 *)a2 + 0x18) = (!asio && wasapiShared) ? 0 : 256;
|
||||
*(u16 *)((u8 *)a2 + 0x1C) = (!asio && wasapiShared) ? 0 : 256;
|
||||
return originalNUSCDeviceInit (a1, a2, a3, a4);
|
||||
}
|
||||
HOOK (bool, LoadASIODriver, ASLR (0x14069B750), void *a1, const char *a2) {
|
||||
auto result = originalLoadASIODriver (a1, a2);
|
||||
if (!result) {
|
||||
MessageBoxA (nullptr, "Failed to load ASIO driver", nullptr, MB_OK);
|
||||
ExitProcess (0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
HOOK_DYNAMIC (char, __fastcall, AMFWTerminate, i64) { return 0; }
|
||||
|
||||
const i32 datatableBufferSize = 1024 * 1024 * 12;
|
||||
@ -82,12 +63,6 @@ Init () {
|
||||
}
|
||||
vsync = readConfigBool (patches, "vsync", vsync);
|
||||
unlockSongs = readConfigBool (patches, "unlock_songs", unlockSongs);
|
||||
auto audio = openConfigSection (patches, "audio");
|
||||
if (audio) {
|
||||
wasapiShared = readConfigBool (audio, "wasapi_shared", wasapiShared);
|
||||
asio = readConfigBool (audio, "asio", asio);
|
||||
asioDriver = readConfigString (audio, "asio_driver", asioDriver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,10 +72,6 @@ Init () {
|
||||
if (!vsync) WRITE_MEMORY (ASLR (0x140517339), u8, 0xBA, 0x00, 0x00, 0x00, 0x00, 0x90);
|
||||
if (unlockSongs) WRITE_MEMORY (ASLR (0x140314E8D), u8, 0xB0, 0x01);
|
||||
|
||||
// Setting audio device
|
||||
INSTALL_HOOK (NUSCDeviceInit);
|
||||
INSTALL_HOOK (LoadASIODriver);
|
||||
|
||||
// Bypass errors
|
||||
WRITE_MEMORY (ASLR (0x1400239C0), u8, 0xC3);
|
||||
|
||||
@ -204,6 +175,7 @@ Init () {
|
||||
WRITE_MEMORY (amHandle + 0x3497A, u8, 0xEB); // BackupDataPathA
|
||||
WRITE_MEMORY (amHandle + 0x34ACD, u8, 0xEB); // BackupDataPathB
|
||||
|
||||
patches::Audio::Init ();
|
||||
patches::Qr::Init ();
|
||||
patches::AmAuth::Init ();
|
||||
}
|
||||
|
@ -8,11 +8,14 @@ void Init ();
|
||||
namespace CN_JUN_2023 {
|
||||
void Init ();
|
||||
} // namespace CN_JUN_2023
|
||||
namespace AmAuth {
|
||||
namespace Audio {
|
||||
void Init ();
|
||||
} // namespace AmAuth
|
||||
} // namespace Audio
|
||||
namespace Qr {
|
||||
void Init ();
|
||||
void Update ();
|
||||
} // namespace Qr
|
||||
namespace AmAuth {
|
||||
void Init ();
|
||||
} // namespace AmAuth
|
||||
} // namespace patches
|
||||
|
@ -18,7 +18,6 @@ extern Keybindings QR_DATA_READ;
|
||||
extern Keybindings QR_IMAGE_READ;
|
||||
extern char accessCode1[21];
|
||||
extern char accessCode2[21];
|
||||
bool qrEnabled = true;
|
||||
|
||||
namespace patches::Qr {
|
||||
|
||||
@ -27,6 +26,7 @@ enum class Mode { Card, Data, Image };
|
||||
State gState = State::Ready;
|
||||
Mode gMode = Mode::Card;
|
||||
std::string accessCode;
|
||||
bool qrEnabled = true;
|
||||
|
||||
HOOK_DYNAMIC (char, __fastcall, qrInit, i64) { return 1; }
|
||||
HOOK_DYNAMIC (char, __fastcall, qrRead, i64 a1) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user