Move to C++ coding style, cleanup current code (#18)
Used CLion to unify our current code
This commit is contained in:
parent
cfefd5c38f
commit
0988da9268
5
.gitignore
vendored
5
.gitignore
vendored
@ -105,7 +105,6 @@ fabric.properties
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.dll
|
||||
|
||||
# Prerequisites
|
||||
*.d
|
||||
@ -132,7 +131,6 @@ CMakeUserPresets.json
|
||||
|
||||
# Leftovers from the old build system
|
||||
xpacks/
|
||||
compile_commands.json
|
||||
package.json
|
||||
.cache
|
||||
subprojects/packagecache
|
||||
@ -145,4 +143,5 @@ subprojects/stb
|
||||
subprojects/zlib
|
||||
subprojects/pugixml-1.14
|
||||
libtomcrypt-1.18.2
|
||||
dist.7z
|
||||
dist.7z
|
||||
/.idea
|
||||
|
@ -115,8 +115,9 @@ Enhanced original option:
|
||||
|
||||
To compile TaikoArcadeLoader, you'll need to install [MSVC](https://aka.ms/vs/17/release/vs_BuildTools.exe).
|
||||
|
||||
Loading this project in cliON or vscode with the cmake tools addon should then allow you to build the project.
|
||||
If you want to build yourself, here are some instructions on how to do this from a cmd shell.
|
||||
Loading this project in CLion or VSCode with the cmake tools addon should then allow you to build the project.
|
||||
Do note that the .sln files created after you run the configure command CAN be opened using Visual Studio or Rider.
|
||||
If you want to build yourself, here are some instructions on how to do this from a cmd shell.
|
||||
|
||||
Clone this repository, open *cmd* and run the following commands:
|
||||
|
||||
@ -131,4 +132,4 @@ cmake -B build -S . -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build build --config Release --target bnusio
|
||||
```
|
||||
|
||||
The compiled build of TaikoArcadeLoader will be written in the `dist` folder.
|
||||
The compiled dll of TaikoArcadeLoader will be written in the `dist` folder.
|
||||
|
@ -167,7 +167,8 @@ bnusio_GetAnalogIn (const u8 which) {
|
||||
if (isP1 && buttonWaitPeriodP1 > 0) {
|
||||
buttonQueueP1.push (which);
|
||||
return 0;
|
||||
} else if (!isP1 && buttonWaitPeriodP2 > 0) {
|
||||
}
|
||||
if (!isP1 && buttonWaitPeriodP2 > 0) {
|
||||
buttonQueueP2.push (which);
|
||||
return 0;
|
||||
}
|
||||
@ -177,9 +178,9 @@ bnusio_GetAnalogIn (const u8 which) {
|
||||
const u16 hitValue = !valueStates[which] ? 50 : 51;
|
||||
valueStates[which] = !valueStates[which];
|
||||
return (hitValue << 15) / 100 + 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u16 __fastcall bnusio_GetCoin (i32 a1) { return coin_count; }
|
||||
@ -257,7 +258,7 @@ FUNCTION_PTR (u64, bnusio_DecService_Original, PROC_ADDRESS ("bnusio_original.dl
|
||||
FUNCTION_PTR (i64, bnusio_ResetCoin_Original, PROC_ADDRESS ("bnusio_original.dll", "bnusio_ResetCoin"));
|
||||
|
||||
HOOK (u64, bngrw_Init, PROC_ADDRESS ("bngrw.dll", "BngRwInit")) { return 0; }
|
||||
HOOK (void, bngrw_Fin, PROC_ADDRESS ("bngrw.dll", "BngRwFin")) { return; }
|
||||
HOOK (void, bngrw_Fin, PROC_ADDRESS ("bngrw.dll", "BngRwFin")) {}
|
||||
HOOK (u64, bngrw_IsCmdExec, PROC_ADDRESS ("bngrw.dll", "BngRwIsCmdExec")) { return 0xFFFFFFFF; }
|
||||
HOOK (i32, bngrw_ReqCancel, PROC_ADDRESS ("bngrw.dll", "BngRwReqCancel")) { return 1; }
|
||||
HOOK (i32, bngrw_ReqSendUrl, PROC_ADDRESS ("bngrw.dll", "BngRwReqSendUrlTo")) { return 1; }
|
||||
@ -275,26 +276,26 @@ HOOK (i32, bngrw_ReqSendMail, PROC_ADDRESS ("bngrw.dll", "BngRwReqSendMailTo"))
|
||||
HOOK (i32, bngrw_ReqLatchID, PROC_ADDRESS ("bngrw.dll", "BngRwReqLatchID")) { return 1; }
|
||||
HOOK (u64, bngrw_ReqAiccAuth, PROC_ADDRESS ("bngrw.dll", "BngRwReqAiccAuth")) { return 1; }
|
||||
HOOK (u64, bngrw_DevReset, PROC_ADDRESS ("bngrw.dll", "BngRwDevReset")) { return 1; }
|
||||
HOOK (u64, bngrw_Attach, PROC_ADDRESS ("bngrw.dll", "BngRwAttach"), i32 a1, char *a2, i32 a3, i32 a4, callbackAttach callback, i32 *_attachData) {
|
||||
HOOK (u64, bngrw_Attach, PROC_ADDRESS ("bngrw.dll", "BngRwAttach"), i32 a1, char *a2, i32 a3, i32 a4, callbackAttach callback, i32 *attachDataH) {
|
||||
LogMessage (LogLevel::DEBUG, "BngRwAttach");
|
||||
// This is way too fucking jank
|
||||
attachCallback = callback;
|
||||
attachData = _attachData;
|
||||
attachData = attachDataH;
|
||||
return 1;
|
||||
}
|
||||
HOOK (u64, bngrw_ReqWaitTouch, PROC_ADDRESS ("bngrw.dll", "BngRwReqWaitTouch"), u32 a1, i32 a2, u32 a3, callbackTouch _callback, u64 _touchData) {
|
||||
HOOK (u64, bngrw_ReqWaitTouch, PROC_ADDRESS ("bngrw.dll", "BngRwReqWaitTouch"), u32 a1, i32 a2, u32 a3, callbackTouch callbackH, u64 touchDataH) {
|
||||
LogMessage (LogLevel::DEBUG, "BngRwReqWaitTouch");
|
||||
touchCallback = _callback;
|
||||
touchCallback = callbackH;
|
||||
if (emulateCardReader) {
|
||||
waitingForTouch = true;
|
||||
touchData = _touchData;
|
||||
touchData = touchDataH;
|
||||
for (const auto plugin : plugins)
|
||||
if (const FARPROC touchEvent = GetProcAddress (plugin, "WaitTouch"))
|
||||
reinterpret_cast<waitTouchEvent *> (touchEvent) (_callback, _touchData);
|
||||
reinterpret_cast<waitTouchEvent *> (touchEvent) (callbackH, touchDataH);
|
||||
return 1;
|
||||
}
|
||||
// This is called when we use an original card reader and acceptInvalidCards is set to true
|
||||
return originalbngrw_ReqWaitTouch (a1, a2, a3, InspectWaitTouch, _touchData);
|
||||
return originalbngrw_ReqWaitTouch (a1, a2, a3, InspectWaitTouch, touchDataH);
|
||||
}
|
||||
|
||||
void
|
||||
@ -306,7 +307,7 @@ Init () {
|
||||
if (config_ptr) {
|
||||
const toml_table_t *config = config_ptr.get ();
|
||||
if (const auto controller = openConfigSection (config, "controller")) {
|
||||
drumWaitPeriod = (u16)readConfigInt (controller, "wait_period", drumWaitPeriod);
|
||||
drumWaitPeriod = static_cast<u16> (readConfigInt (controller, "wait_period", drumWaitPeriod));
|
||||
analogInput = readConfigBool (controller, "analog_input", analogInput);
|
||||
if (analogInput) LogMessage (LogLevel::WARN, "Using analog input mode. All the keyboard drum inputs have been disabled.");
|
||||
}
|
||||
@ -340,7 +341,7 @@ Init () {
|
||||
SetConfigValue (keyConfig, "P2_RIGHT_BLUE", &P2_RIGHT_BLUE);
|
||||
}
|
||||
|
||||
if (!emulateUsio && !std::filesystem::exists (std::filesystem::current_path () / "bnusio_original.dll")) {
|
||||
if (!emulateUsio && !exists (std::filesystem::current_path () / "bnusio_original.dll")) {
|
||||
emulateUsio = true;
|
||||
LogMessage (LogLevel::ERROR, "bnusio_original.dll not found! usio emulation enabled");
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ std::string chassisId = "284111080000";
|
||||
std::string shopId = "TAIKO ARCADE LOADER";
|
||||
std::string gameVerNum = "00.00";
|
||||
std::string countryCode = "JPN";
|
||||
char fullAddress[256] = {'\0'};
|
||||
char placeId[16] = {'\0'};
|
||||
char fullAddress[256] = {};
|
||||
char placeId[16] = {};
|
||||
char accessCode1[21] = "00000000000000000001";
|
||||
char accessCode2[21] = "00000000000000000002";
|
||||
char chipId1[33] = "00000000000000000000000000000001";
|
||||
@ -55,8 +55,8 @@ HOOK (bool, SetWindowPosition, PROC_ADDRESS ("user32.dll", "SetWindowPos"), HWND
|
||||
RECT rw, rc;
|
||||
GetWindowRect (hWnd, &rw);
|
||||
GetClientRect (hWnd, &rc);
|
||||
cx = (rw.right - rw.left) - (rc.right - rc.left) + cx;
|
||||
cy = (rw.bottom - rw.top) - (rc.bottom - rc.top) + cy;
|
||||
cx = rw.right - rw.left - (rc.right - rc.left) + cx;
|
||||
cy = rw.bottom - rw.top - (rc.bottom - rc.top) + cy;
|
||||
}
|
||||
return originalSetWindowPosition (hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
|
||||
}
|
||||
@ -89,7 +89,7 @@ GetGameVersion () {
|
||||
GetModuleFileNameW (nullptr, w_path, MAX_PATH);
|
||||
const std::filesystem::path path (w_path);
|
||||
|
||||
if (!std::filesystem::exists (path) || !path.has_filename ()) {
|
||||
if (!exists (path) || !path.has_filename ()) {
|
||||
MessageBoxA (nullptr, "Failed to find executable", nullptr, MB_OK);
|
||||
ExitProcess (0);
|
||||
}
|
||||
@ -125,23 +125,23 @@ void
|
||||
CreateCard () {
|
||||
LogMessage (LogLevel::INFO, "Creating card.ini");
|
||||
constexpr char hexCharacterTable[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
char buf[64] = {0};
|
||||
srand ((unsigned int)time (nullptr));
|
||||
char buf[64] = {};
|
||||
srand (static_cast<unsigned int> (time (nullptr)));
|
||||
|
||||
std::generate_n (buf, 20, [&] () { return hexCharacterTable[rand () % 10]; });
|
||||
std::generate_n (buf, 20, [&] { return hexCharacterTable[rand () % 10]; });
|
||||
WritePrivateProfileStringA ("card", "accessCode1", buf, ".\\card.ini");
|
||||
std::generate_n (buf, 32, [&] () { return hexCharacterTable[rand () % 16]; });
|
||||
std::generate_n (buf, 32, [&] { return hexCharacterTable[rand () % 16]; });
|
||||
WritePrivateProfileStringA ("card", "chipId1", buf, ".\\card.ini");
|
||||
std::generate_n (buf, 20, [&] () { return hexCharacterTable[rand () % 10]; });
|
||||
std::generate_n (buf, 20, [&] { return hexCharacterTable[rand () % 10]; });
|
||||
WritePrivateProfileStringA ("card", "accessCode2", buf, ".\\card.ini");
|
||||
std::generate_n (buf, 32, [&] () { return hexCharacterTable[rand () % 16]; });
|
||||
std::generate_n (buf, 32, [&] { return hexCharacterTable[rand () % 16]; });
|
||||
WritePrivateProfileStringA ("card", "chipId2", buf, ".\\card.ini");
|
||||
}
|
||||
|
||||
BOOL
|
||||
DllMain (HMODULE module, const DWORD reason, LPVOID reserved) {
|
||||
if (reason == DLL_PROCESS_ATTACH) {
|
||||
// This is bad, dont do this
|
||||
// This is bad, don't do this
|
||||
// I/O in DllMain can easily cause a deadlock
|
||||
|
||||
// Init logger for loading config
|
||||
@ -162,7 +162,7 @@ DllMain (HMODULE module, const DWORD reason, LPVOID reserved) {
|
||||
countryCode = readConfigString (amauthConfig, "country_code", countryCode);
|
||||
|
||||
std::strcat (fullAddress, server.c_str ());
|
||||
if (port != "") {
|
||||
if (!port.empty ()) {
|
||||
std::strcat (fullAddress, ":");
|
||||
std::strcat (fullAddress, port.c_str ());
|
||||
}
|
||||
@ -210,7 +210,7 @@ DllMain (HMODULE module, const DWORD reason, LPVOID reserved) {
|
||||
}
|
||||
LogMessage (LogLevel::INFO, "GameVersion is %s", GameVersionToString (gameVersion));
|
||||
|
||||
if (const auto pluginPath = std::filesystem::current_path () / "plugins"; std::filesystem::exists (pluginPath)) {
|
||||
if (const auto pluginPath = std::filesystem::current_path () / "plugins"; exists (pluginPath)) {
|
||||
for (const auto &entry : std::filesystem::directory_iterator (pluginPath)) {
|
||||
if (entry.path ().extension () == ".dll") {
|
||||
auto name = entry.path ().wstring ();
|
||||
|
@ -1,20 +1,16 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
// ReSharper disable once CppUnusedIncludeDirective
|
||||
#include <safetyhook.hpp>
|
||||
#include <toml.h>
|
||||
#include <windows.h>
|
||||
// ReSharper disable once CppUnusedIncludeDirective
|
||||
#include <MinHook.h>
|
||||
|
||||
#include <string>
|
||||
#include <toml.h>
|
||||
#include <windows.h>
|
||||
#include "constants.h"
|
||||
#include "logger.h"
|
||||
|
||||
|
@ -1,19 +1,4 @@
|
||||
/*
|
||||
// Copyright (c) 2019 Onur Dundar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "logger.h"
|
||||
|
||||
static Logger *loggerInstance = nullptr;
|
||||
|
@ -1,9 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "helpers.h"
|
||||
#include <ctime>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <source_location>
|
||||
#include <string_view>
|
||||
#include <wincon.h>
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include <winsock2.h>
|
||||
#include "helpers.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
/*
|
||||
@ -257,6 +257,7 @@ enum daemon_mode {
|
||||
DAEMON_MODE_STANDALONE,
|
||||
};
|
||||
|
||||
// ReSharper disable once CppClassCanBeFinal
|
||||
class CAuth : public IUnknown {
|
||||
public:
|
||||
STDMETHODIMP
|
||||
@ -298,12 +299,12 @@ public:
|
||||
virtual i32 IAuth_GetUpdaterState (amcus_state_t *arr) {
|
||||
memset (arr, 0, sizeof (*arr));
|
||||
// Convert gameVerNum from string to double
|
||||
const double ver_d = std::stod (gameVerNum.c_str ());
|
||||
const double ver_d = std::stod (gameVerNum);
|
||||
|
||||
const int ver_top = static_cast<int> (ver_d);
|
||||
int ver_btm = static_cast<int> (ver_d * 100);
|
||||
|
||||
if (ver_top != 0) ver_btm %= (ver_top * 100);
|
||||
if (ver_top != 0) ver_btm %= ver_top * 100;
|
||||
|
||||
arr->allnet_state = DAEMON_IDLE;
|
||||
arr->allnet_auth_state = 2;
|
||||
@ -487,7 +488,7 @@ public:
|
||||
|
||||
virtual void Unk33 () {}
|
||||
|
||||
CAuth () {}
|
||||
CAuth () = default;
|
||||
|
||||
virtual ~CAuth () {}
|
||||
|
||||
@ -531,9 +532,9 @@ CoCreateInstanceHook (const IID *const rclsid, const LPUNKNOWN pUnkOuter, const
|
||||
HRESULT result;
|
||||
|
||||
LPOLESTR clsidStr = nullptr;
|
||||
LPOLESTR iidStr = nullptr;
|
||||
// const LPOLESTR iidStr = nullptr;
|
||||
[[maybe_unused]] auto _ = StringFromIID (*rclsid, &clsidStr);
|
||||
_ = StringFromIID (*riid, &iidStr);
|
||||
// _ = StringFromIID (*riid, &iidStr);
|
||||
|
||||
if (IsEqualGUID (*rclsid, IID_CAuthFactory) && IsEqualGUID (*riid, IID_CAuth)) {
|
||||
const auto cauth = new CAuth ();
|
||||
@ -543,7 +544,7 @@ CoCreateInstanceHook (const IID *const rclsid, const LPUNKNOWN pUnkOuter, const
|
||||
}
|
||||
|
||||
CoTaskMemFree (clsidStr);
|
||||
CoTaskMemFree (iidStr);
|
||||
// CoTaskMemFree (iidStr);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -15,15 +15,15 @@ typedef struct nusc_init_config {
|
||||
bool wasapi_disable_com;
|
||||
bool wasapi_exclusive;
|
||||
u32 wasapi_exclusive_buffer_size;
|
||||
void *wasapi_audioses;
|
||||
void *wasapi_audioSes;
|
||||
} nusc_init_config_t;
|
||||
|
||||
bool wasapiShared = true;
|
||||
bool asio = false;
|
||||
std::string asioDriver = "";
|
||||
std::string asioDriver;
|
||||
|
||||
HOOK_DYNAMIC (i64, NUSCDeviceInit, void *a1, nusc_init_config_t *a2, nusc_init_config_t *a3, void *a4) {
|
||||
LogMessage (LogLevel::INFO, (std::string ("Device mode is ") + (asio ? "ASIO" : (wasapiShared ? "wasapi shared" : "wasapi exclusive"))).c_str ());
|
||||
LogMessage (LogLevel::INFO, std::string ("Device mode is ") + (asio ? "ASIO" : wasapiShared ? "wasapi shared" : "wasapi exclusive"));
|
||||
if (asio) LogMessage (LogLevel::INFO, (std::string ("ASIO driver is ") + asioDriver).c_str ());
|
||||
a2->device_mode = asio;
|
||||
a2->asio_driver_name = asio ? asioDriver.c_str () : "";
|
||||
@ -47,8 +47,7 @@ Init () {
|
||||
const auto configPath = std::filesystem::current_path () / "config.toml";
|
||||
const std::unique_ptr<toml_table_t, void (*) (toml_table_t *)> config_ptr (openConfig (configPath), toml_free);
|
||||
if (config_ptr) {
|
||||
const auto audio = openConfigSection (config_ptr.get (), "audio");
|
||||
if (audio) {
|
||||
if (const auto audio = openConfigSection (config_ptr.get (), "audio")) {
|
||||
wasapiShared = readConfigBool (audio, "wasapi_shared", wasapiShared);
|
||||
asio = readConfigBool (audio, "asio", asio);
|
||||
asioDriver = readConfigString (audio, "asio_driver", asioDriver);
|
||||
|
@ -62,7 +62,7 @@ static HRESULT WINAPI D3D11CreateDeviceAndSwapChainWrap (IDXGIAdapter *pAdapter,
|
||||
|
||||
// Functions
|
||||
template <typename T>
|
||||
inline T
|
||||
T
|
||||
HookVtableFunction (T *functionPtr, T target) {
|
||||
if (*functionPtr == target) return nullptr;
|
||||
|
||||
@ -79,7 +79,7 @@ CreateSwapChainWrap (IDXGIFactory *This, IUnknown *pDevice, DXGI_SWAP_CHAIN_DESC
|
||||
if (*ppSwapChain) {
|
||||
if (FpsLimiterEnable) {
|
||||
const auto old2 = HookVtableFunction (&(*ppSwapChain)->lpVtbl->Present, PresentWrap);
|
||||
g_oldPresentWrap = (old2) ? old2 : g_oldPresentWrap;
|
||||
g_oldPresentWrap = old2 ? old2 : g_oldPresentWrap;
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ CreateSwapChainForHwndWrap (IDXGIFactory2 *This, IUnknown *pDevice, const HWND h
|
||||
if (*ppSwapChain) {
|
||||
if (FpsLimiterEnable) {
|
||||
const auto old2 = HookVtableFunction (&(*ppSwapChain)->lpVtbl->Present, Present1Wrap);
|
||||
g_oldPresent1Wrap = (old2) ? old2 : g_oldPresent1Wrap;
|
||||
g_oldPresent1Wrap = old2 ? old2 : g_oldPresent1Wrap;
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ CreateSwapChainForHwndWrap (IDXGIFactory2 *This, IUnknown *pDevice, const HWND h
|
||||
|
||||
static HRESULT STDMETHODCALLTYPE
|
||||
PresentWrap (IDXGISwapChain *pSwapChain, const UINT SyncInterval, const UINT Flags) {
|
||||
if (FpsLimiterEnable) patches::FpsLimiter::Update ();
|
||||
if (FpsLimiterEnable) FpsLimiter::Update ();
|
||||
|
||||
bnusio::Update ();
|
||||
|
||||
@ -112,7 +112,7 @@ PresentWrap (IDXGISwapChain *pSwapChain, const UINT SyncInterval, const UINT Fla
|
||||
|
||||
static HRESULT STDMETHODCALLTYPE
|
||||
Present1Wrap (IDXGISwapChain1 *pSwapChain, const UINT SyncInterval, const UINT Flags) {
|
||||
if (FpsLimiterEnable) patches::FpsLimiter::Update ();
|
||||
if (FpsLimiterEnable) FpsLimiter::Update ();
|
||||
|
||||
bnusio::Update ();
|
||||
|
||||
@ -126,7 +126,7 @@ CreateSwapChain2Wrap (IDXGIFactory2 *This, IUnknown *pDevice, DXGI_SWAP_CHAIN_DE
|
||||
if (*ppSwapChain) {
|
||||
if (FpsLimiterEnable) {
|
||||
const auto old2 = HookVtableFunction (&(*ppSwapChain)->lpVtbl->Present, PresentWrap);
|
||||
g_oldPresentWrap = (old2) ? old2 : g_oldPresentWrap;
|
||||
g_oldPresentWrap = old2 ? old2 : g_oldPresentWrap;
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ CreateDXGIFactory2Wrap (const UINT Flags, REFIID riid, void **ppFactory) {
|
||||
const IDXGIFactory2 *factory = static_cast<IDXGIFactory2 *> (*ppFactory);
|
||||
|
||||
const auto old = HookVtableFunction (&factory->lpVtbl->CreateSwapChain, CreateSwapChain2Wrap);
|
||||
g_oldCreateSwapChain2 = (old) ? old : g_oldCreateSwapChain2;
|
||||
g_oldCreateSwapChain2 = old ? old : g_oldCreateSwapChain2;
|
||||
}
|
||||
|
||||
return hr;
|
||||
@ -162,18 +162,19 @@ CreateDXGIFactoryWrap (REFIID riid, _COM_Outptr_ void **ppFactory) {
|
||||
else if (IsEqualIID (riid, IID_IDXGIFactory6)) factoryType = 6;
|
||||
else if (IsEqualIID (riid, IID_IDXGIFactory7)) factoryType = 7;
|
||||
|
||||
// ReSharper disable once CppDFAConstantConditions
|
||||
if (factoryType >= 0) {
|
||||
const IDXGIFactory *factory = static_cast<IDXGIFactory *> (*ppFactory);
|
||||
|
||||
const auto old = HookVtableFunction (&factory->lpVtbl->CreateSwapChain, CreateSwapChainWrap);
|
||||
g_oldCreateSwapChain = (old) ? old : g_oldCreateSwapChain;
|
||||
g_oldCreateSwapChain = old ? old : g_oldCreateSwapChain;
|
||||
}
|
||||
|
||||
if (factoryType >= 2) {
|
||||
const IDXGIFactory2 *factory = static_cast<IDXGIFactory2 *> (*ppFactory);
|
||||
|
||||
const auto old = HookVtableFunction (&factory->lpVtbl->CreateSwapChainForHwnd, CreateSwapChainForHwndWrap);
|
||||
g_oldCreateSwapChainForHwnd = (old) ? old : g_oldCreateSwapChainForHwnd;
|
||||
g_oldCreateSwapChainForHwnd = old ? old : g_oldCreateSwapChainForHwnd;
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,7 +192,7 @@ D3D11CreateDeviceAndSwapChainWrap (IDXGIAdapter *pAdapter, const D3D_DRIVER_TYPE
|
||||
if (ppSwapChain) {
|
||||
if (FpsLimiterEnable) {
|
||||
const auto old2 = HookVtableFunction (&(*ppSwapChain)->lpVtbl->Present, PresentWrap);
|
||||
g_oldPresentWrap = (old2) ? old2 : g_oldPresentWrap;
|
||||
g_oldPresentWrap = old2 ? old2 : g_oldPresentWrap;
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,18 +207,20 @@ Init () {
|
||||
const auto configPath = std::filesystem::current_path () / "config.toml";
|
||||
const std::unique_ptr<toml_table_t, void (*) (toml_table_t *)> config_ptr (openConfig (configPath), toml_free);
|
||||
if (config_ptr) {
|
||||
const auto graphics = openConfigSection (config_ptr.get (), "graphics");
|
||||
if (graphics) fpsLimit = (i32)readConfigInt (graphics, "fpslimit", fpsLimit);
|
||||
if (const auto graphics = openConfigSection (config_ptr.get (), "graphics"))
|
||||
fpsLimit = static_cast<i32> (readConfigInt (graphics, "fpslimit", fpsLimit));
|
||||
}
|
||||
|
||||
FpsLimiterEnable = fpsLimit > 0;
|
||||
patches::FpsLimiter::Init (static_cast<float> (fpsLimit));
|
||||
FpsLimiter::Init (static_cast<float> (fpsLimit));
|
||||
|
||||
MH_Initialize ();
|
||||
MH_CreateHookApi (L"dxgi.dll", "CreateDXGIFactory", (LPVOID)CreateDXGIFactoryWrap, (void **)&g_origCreateDXGIFactory);
|
||||
MH_CreateHookApi (L"dxgi.dll", "CreateDXGIFactory2", (LPVOID)CreateDXGIFactory2Wrap, (void **)&g_origCreateDXGIFactory2);
|
||||
MH_CreateHookApi (L"d3d11.dll", "D3D11CreateDeviceAndSwapChain", (LPVOID)D3D11CreateDeviceAndSwapChainWrap,
|
||||
(void **)&g_origD3D11CreateDeviceAndSwapChain);
|
||||
MH_CreateHookApi (L"dxgi.dll", "CreateDXGIFactory", reinterpret_cast<LPVOID> (CreateDXGIFactoryWrap),
|
||||
reinterpret_cast<void **> (&g_origCreateDXGIFactory));
|
||||
MH_CreateHookApi (L"dxgi.dll", "CreateDXGIFactory2", reinterpret_cast<LPVOID> (CreateDXGIFactory2Wrap),
|
||||
reinterpret_cast<void **> (&g_origCreateDXGIFactory2));
|
||||
MH_CreateHookApi (L"d3d11.dll", "D3D11CreateDeviceAndSwapChain", reinterpret_cast<LPVOID> (D3D11CreateDeviceAndSwapChainWrap),
|
||||
reinterpret_cast<void **> (&g_origD3D11CreateDeviceAndSwapChain));
|
||||
MH_EnableHook (nullptr);
|
||||
}
|
||||
|
||||
|
@ -40,8 +40,7 @@ Update () {
|
||||
QueryPerformanceFrequency (&PerformanceCount3);
|
||||
i = 0;
|
||||
t = 1000.0 / static_cast<double> (PerformanceCount3.QuadPart);
|
||||
auto v = t * 2147483648.0;
|
||||
if (60000.0 > v) {
|
||||
if (auto v = t * 2147483648.0; 60000.0 > v) {
|
||||
while (true) {
|
||||
++i;
|
||||
v *= 2.0;
|
||||
@ -54,7 +53,7 @@ Update () {
|
||||
break;
|
||||
}
|
||||
|
||||
if ((static_cast<double> ((PerformanceCount2.QuadPart >> i) - PerformanceCount1.QuadPart) * t) >= targetFrameTime) break;
|
||||
if (static_cast<double> ((PerformanceCount2.QuadPart >> i) - PerformanceCount1.QuadPart) * t >= targetFrameTime) break;
|
||||
|
||||
SleepEx (0, 1);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace patches::LayeredFs {
|
||||
class RegisteredHandler {
|
||||
public:
|
||||
std::function<std::string (std::string, std::string)> handlerMethod;
|
||||
RegisteredHandler (const std::function<std::string (std::string, std::string)> &handlerMethod) { this->handlerMethod = handlerMethod; }
|
||||
explicit RegisteredHandler (const std::function<std::string (std::string, std::string)> &handlerMethod) { this->handlerMethod = handlerMethod; }
|
||||
};
|
||||
|
||||
std::vector<RegisteredHandler *> beforeHandlers = {};
|
||||
@ -22,13 +22,12 @@ std::vector<RegisteredHandler *> afterHandlers = {};
|
||||
|
||||
u32
|
||||
CRC32C (u32 crc, const unsigned char *buf, size_t len) {
|
||||
int k;
|
||||
|
||||
crc = ~crc;
|
||||
while (len--) {
|
||||
crc ^= *buf++;
|
||||
for (k = 0; k < 8; k++)
|
||||
crc = (crc >> 1) ^ (CRCPOLY & (0 - (crc & 1)));
|
||||
for (int k = 0; k < 8; k++)
|
||||
crc = crc >> 1 ^ CRCPOLY & 0 - (crc & 1);
|
||||
}
|
||||
return ~crc;
|
||||
}
|
||||
@ -39,10 +38,10 @@ CheckCRC (const std::string &path, const u32 crc) {
|
||||
std::filesystem::path crc_path = path;
|
||||
crc_path.replace_extension (".crc");
|
||||
std::ifstream crc_file (crc_path, std::ios::binary);
|
||||
const std::string crc_content ((std::istreambuf_iterator<char> (crc_file)), std::istreambuf_iterator<char> ());
|
||||
const std::string crc_content ((std::istreambuf_iterator (crc_file)), std::istreambuf_iterator<char> ());
|
||||
return std::stoul (crc_content) != crc;
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
@ -62,8 +61,7 @@ CreateDirectories (const std::string &path) {
|
||||
|
||||
void
|
||||
WriteFile (const std::string &filename, const std::vector<u8> &data, u32 original_crc) {
|
||||
std::string::size_type pos = filename.find_last_of ("\\");
|
||||
if (pos != std::string::npos) {
|
||||
if (std::string::size_type pos = filename.find_last_of ('\\'); pos != std::string::npos) {
|
||||
std::string directory = filename.substr (0, pos);
|
||||
CreateDirectories (directory);
|
||||
}
|
||||
@ -84,15 +82,15 @@ GZip_Compress (const std::vector<unsigned char> &data) {
|
||||
deflate_stream.zalloc = nullptr;
|
||||
deflate_stream.zfree = nullptr;
|
||||
deflate_stream.opaque = nullptr;
|
||||
deflate_stream.avail_in = (uInt)data.size ();
|
||||
deflate_stream.avail_in = static_cast<uInt> (data.size ());
|
||||
deflate_stream.next_in = const_cast<Bytef *> (data.data ());
|
||||
|
||||
deflateInit2 (&deflate_stream, Z_BEST_COMPRESSION, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY);
|
||||
|
||||
std::vector<unsigned char> compressed_data;
|
||||
compressed_data.resize (deflateBound (&deflate_stream, (uLong)data.size ()));
|
||||
compressed_data.resize (deflateBound (&deflate_stream, static_cast<uLong> (data.size ())));
|
||||
|
||||
deflate_stream.avail_out = (uInt)compressed_data.size ();
|
||||
deflate_stream.avail_out = static_cast<uInt> (compressed_data.size ());
|
||||
deflate_stream.next_out = compressed_data.data ();
|
||||
|
||||
deflate (&deflate_stream, Z_FINISH);
|
||||
@ -105,7 +103,7 @@ GZip_Compress (const std::vector<unsigned char> &data) {
|
||||
// Function to pad data according to PKCS7
|
||||
std::vector<u8>
|
||||
Pad_Data (const std::vector<u8> &data, const size_t block_size) {
|
||||
const size_t padding = block_size - (data.size () % block_size);
|
||||
const size_t padding = block_size - data.size () % block_size;
|
||||
std::vector<u8> padded_data = data;
|
||||
padded_data.insert (padded_data.end (), padding, static_cast<u8> (padding));
|
||||
return padded_data;
|
||||
@ -134,7 +132,7 @@ EncryptFile (const std::string &input_file, const std::string &hex_key) {
|
||||
// Read the entire file into memory
|
||||
std::ifstream file (input_file, std::ios::binary);
|
||||
|
||||
const std::vector<u8> data ((std::istreambuf_iterator<char> (file)), std::istreambuf_iterator<char> ());
|
||||
const std::vector<u8> data ((std::istreambuf_iterator (file)), std::istreambuf_iterator<char> ());
|
||||
|
||||
// Compress the data
|
||||
const std::vector<u8> compressed_data = GZip_Compress (data);
|
||||
@ -144,11 +142,11 @@ EncryptFile (const std::string &input_file, const std::string &hex_key) {
|
||||
|
||||
// Encrypt the data
|
||||
symmetric_CBC cbc;
|
||||
if (cbc_start (find_cipher ("aes"), iv.data (), key.data (), (int)key.size (), 0, &cbc) != CRYPT_OK)
|
||||
if (cbc_start (find_cipher ("aes"), iv.data (), key.data (), static_cast<int> (key.size ()), 0, &cbc) != CRYPT_OK)
|
||||
throw std::runtime_error ("Error initializing CBC");
|
||||
|
||||
std::vector<u8> encrypted_data (padded_data.size ());
|
||||
if (cbc_encrypt (padded_data.data (), encrypted_data.data (), (unsigned long)padded_data.size (), &cbc) != CRYPT_OK)
|
||||
if (cbc_encrypt (padded_data.data (), encrypted_data.data (), static_cast<unsigned long> (padded_data.size ()), &cbc) != CRYPT_OK)
|
||||
throw std::runtime_error ("Error during encryption");
|
||||
|
||||
cbc_done (&cbc);
|
||||
@ -177,9 +175,9 @@ IsFumenEncrypted (const std::string &filename) {
|
||||
}
|
||||
|
||||
std::string
|
||||
LayeredFsHandler (const std::string originalFileName, const std::string currentFileName) {
|
||||
LayeredFsHandler (const std::string &originalFileName, const std::string ¤tFileName) {
|
||||
std::filesystem::path path (originalFileName.c_str ());
|
||||
if (!path.is_absolute ()) path = std::filesystem::absolute (path);
|
||||
if (!path.is_absolute ()) path = absolute (path);
|
||||
auto originalDataFolder = std::filesystem::current_path ().parent_path ().parent_path () / "Data" / "x64";
|
||||
auto originalLayeredFsFolder = std::filesystem::current_path ().parent_path ().parent_path () / "Data_mods" / "x64";
|
||||
auto encryptedLayeredFsFolder = std::filesystem::current_path ().parent_path ().parent_path () / "Data_mods" / "x64_enc";
|
||||
@ -191,41 +189,40 @@ LayeredFsHandler (const std::string originalFileName, const std::string currentF
|
||||
encPath.replace (0, originalDataFolder.string ().length (), encryptedLayeredFsFolder.string ());
|
||||
|
||||
// The following code handles file redirection and if need be, file encryption.
|
||||
// It's a bit of a mess but it works well ! -Kit
|
||||
// It's a bit of a mess, but it works well ! -Kit
|
||||
|
||||
if (std::filesystem::exists (newPath)) { // If a file exists in the datamod folder
|
||||
if (IsFumenEncrypted (newPath)) { // And if it's an encrypted fumen or a different type of file, use it.
|
||||
LogMessage (LogLevel::DEBUG, ("Redirecting " + std::filesystem::relative (path).string ()).c_str ());
|
||||
LogMessage (LogLevel::DEBUG, ("Redirecting " + relative (path).string ()).c_str ());
|
||||
return newPath;
|
||||
} else { // Otherwise if it's an unencrypted fumen.
|
||||
if (!std::filesystem::exists (encPath)) { // We check if we don't already have a cached file.
|
||||
if (fumenKey.length () == 64) {
|
||||
LogMessage (LogLevel::DEBUG,
|
||||
("Encrypting " + std::filesystem::relative (newPath).string ()).c_str ()); // If we don't we encrypt the file
|
||||
std::ifstream crc_file (newPath, std::ios::binary);
|
||||
std::vector<u8> crc_vector ((std::istreambuf_iterator<char> (crc_file)), std::istreambuf_iterator<char> ());
|
||||
u32 crc = CRC32C (0, crc_vector.data (), crc_vector.size ());
|
||||
WriteFile (encPath, EncryptFile (newPath, fumenKey), crc); // And we save it
|
||||
} else {
|
||||
LogMessage (
|
||||
LogLevel::ERROR,
|
||||
("Missing or invalid fumen key: " + std::filesystem::relative (newPath).string () + " couldn't be encrypted.").c_str ());
|
||||
encPath = path.string ();
|
||||
}
|
||||
} else LogMessage (LogLevel::DEBUG, ("Using cached file for: " + std::filesystem::relative (newPath).string ()).c_str ());
|
||||
return encPath;
|
||||
}
|
||||
} // Otherwise if it's an unencrypted fumen.
|
||||
if (!std::filesystem::exists (encPath)) { // We check if we don't already have a cached file.
|
||||
if (fumenKey.length () == 64) {
|
||||
LogMessage (LogLevel::DEBUG,
|
||||
("Encrypting " + std::filesystem::relative (newPath).string ()).c_str ()); // If we don't we encrypt the file
|
||||
std::ifstream crc_file (newPath, std::ios::binary);
|
||||
std::vector<u8> crc_vector ((std::istreambuf_iterator (crc_file)), std::istreambuf_iterator<char> ());
|
||||
u32 crc = CRC32C (0, crc_vector.data (), crc_vector.size ());
|
||||
WriteFile (encPath, EncryptFile (newPath, fumenKey), crc); // And we save it
|
||||
} else {
|
||||
LogMessage (
|
||||
LogLevel::ERROR,
|
||||
("Missing or invalid fumen key: " + std::filesystem::relative (newPath).string () + " couldn't be encrypted.").c_str ());
|
||||
encPath = path.string ();
|
||||
}
|
||||
} else LogMessage (LogLevel::DEBUG, ("Using cached file for: " + std::filesystem::relative (newPath).string ()).c_str ());
|
||||
return encPath;
|
||||
}
|
||||
|
||||
// We check separately for unencrypted json files.
|
||||
std::filesystem::path json_path = newPath;
|
||||
json_path.replace_extension (".json");
|
||||
if (std::filesystem::exists (json_path)) { // If a json file exists in the folder
|
||||
if (exists (json_path)) { // If a json file exists in the folder
|
||||
bool crcBool = false;
|
||||
|
||||
if (std::filesystem::exists (encPath)) {
|
||||
std::ifstream crc_file (json_path, std::ios::binary);
|
||||
std::vector<u8> crc_vector ((std::istreambuf_iterator<char> (crc_file)), std::istreambuf_iterator<char> ());
|
||||
std::vector<u8> crc_vector ((std::istreambuf_iterator (crc_file)), std::istreambuf_iterator<char> ());
|
||||
u32 crc = CRC32C (0, crc_vector.data (), crc_vector.size ());
|
||||
crcBool = CheckCRC (encPath, crc);
|
||||
}
|
||||
@ -233,9 +230,9 @@ LayeredFsHandler (const std::string originalFileName, const std::string currentF
|
||||
if (!std::filesystem::exists (encPath) || crcBool) { // And if it hasn't been encrypted before
|
||||
if (datatableKey.length () == 64) {
|
||||
// Encrypt the file
|
||||
LogMessage (LogLevel::DEBUG, ("Encrypting " + std::filesystem::relative (json_path).string ()).c_str ());
|
||||
LogMessage (LogLevel::DEBUG, ("Encrypting " + relative (json_path).string ()).c_str ());
|
||||
std::ifstream crc_file (json_path.string (), std::ios::binary);
|
||||
std::vector<u8> crc_vector ((std::istreambuf_iterator<char> (crc_file)), std::istreambuf_iterator<char> ());
|
||||
std::vector<u8> crc_vector ((std::istreambuf_iterator (crc_file)), std::istreambuf_iterator<char> ());
|
||||
u32 crc = CRC32C (0, crc_vector.data (), crc_vector.size ());
|
||||
WriteFile (encPath, EncryptFile (json_path.string (), datatableKey), crc); // And save it
|
||||
} else {
|
||||
@ -246,7 +243,7 @@ LayeredFsHandler (const std::string originalFileName, const std::string currentF
|
||||
}
|
||||
} else
|
||||
// Otherwise use the already encrypted file.
|
||||
LogMessage (LogLevel::DEBUG, ("Using cached file for: " + std::filesystem::relative (json_path).string ()).c_str ());
|
||||
LogMessage (LogLevel::DEBUG, ("Using cached file for: " + relative (json_path).string ()).c_str ());
|
||||
return encPath;
|
||||
}
|
||||
}
|
||||
@ -256,8 +253,8 @@ LayeredFsHandler (const std::string originalFileName, const std::string currentF
|
||||
|
||||
HOOK (HANDLE, CreateFileAHook, PROC_ADDRESS ("kernel32.dll", "CreateFileA"), LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
|
||||
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) {
|
||||
const std::string originalFileName = std::string (lpFileName);
|
||||
std::string currentFileName = originalFileName;
|
||||
const auto originalFileName = std::string (lpFileName);
|
||||
std::string currentFileName = originalFileName;
|
||||
LogMessage (LogLevel::HOOKS, ("CreateFileA: " + originalFileName).c_str ());
|
||||
|
||||
if (!beforeHandlers.empty ()) {
|
||||
@ -283,33 +280,6 @@ HOOK (HANDLE, CreateFileAHook, PROC_ADDRESS ("kernel32.dll", "CreateFileA"), LPC
|
||||
dwFlagsAndAttributes, hTemplateFile);
|
||||
}
|
||||
|
||||
// HOOK (HANDLE, CreateFileWHook, PROC_ADDRESS ("kernel32.dll", "CreateFileW"), LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
|
||||
// LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) {
|
||||
// std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
|
||||
// std::string strFileName = converter.to_bytes (lpFileName);
|
||||
|
||||
// std::filesystem::path path (strFileName);
|
||||
// if (!path.is_absolute ()) path = std::filesystem::absolute (path);
|
||||
|
||||
// auto originalDataFolder = std::filesystem::current_path ().parent_path ().parent_path () / "Data" / "x64";
|
||||
// auto originalLayeredFsFolder = std::filesystem::current_path ().parent_path ().parent_path () / "Data_mods" / "x64";
|
||||
|
||||
// if (path.string ().find (originalDataFolder.string ()) != std::string::npos) {
|
||||
// auto newPath = path.string ();
|
||||
// newPath.replace (0, originalDataFolder.string ().length (), originalLayeredFsFolder.string ());
|
||||
|
||||
// if (std::filesystem::exists (newPath)) {
|
||||
// std::wstring wNewPath = converter.from_bytes (newPath);
|
||||
// std::wcout << L"Redirecting " << lpFileName << L" to " << wNewPath << std::endl;
|
||||
// return originalCreateFileWHook (wNewPath.c_str (), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition,
|
||||
// dwFlagsAndAttributes, hTemplateFile);
|
||||
// }
|
||||
// }
|
||||
|
||||
// return originalCreateFileWHook (lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes,
|
||||
// hTemplateFile);
|
||||
// }
|
||||
|
||||
void
|
||||
Init () {
|
||||
LogMessage (LogLevel::INFO, "Init LayeredFs patches");
|
||||
@ -317,21 +287,20 @@ Init () {
|
||||
const auto configPath = std::filesystem::current_path () / "config.toml";
|
||||
const std::unique_ptr<toml_table_t, void (*) (toml_table_t *)> config_ptr (openConfig (configPath), toml_free);
|
||||
if (config_ptr) {
|
||||
const auto layeredFs = openConfigSection (config_ptr.get (), "layeredfs");
|
||||
if (layeredFs) useLayeredFs = readConfigBool (layeredFs, "enabled", useLayeredFs);
|
||||
if (const auto layeredFs = openConfigSection (config_ptr.get (), "layeredfs"))
|
||||
useLayeredFs = readConfigBool (layeredFs, "enabled", useLayeredFs);
|
||||
}
|
||||
register_cipher (&aes_desc);
|
||||
INSTALL_HOOK (CreateFileAHook);
|
||||
// INSTALL_HOOK (CreateFileWHook);
|
||||
}
|
||||
|
||||
void
|
||||
RegisterBefore (const std::function<std::string (const std::string, const std::string)> &fileHandler) {
|
||||
RegisterBefore (const std::function<std::string (std::string, std::string)> &fileHandler) {
|
||||
beforeHandlers.push_back (new RegisteredHandler (fileHandler));
|
||||
}
|
||||
|
||||
void
|
||||
RegisterAfter (const std::function<std::string (const std::string, const std::string)> &fileHandler) {
|
||||
RegisterAfter (const std::function<std::string (std::string, std::string)> &fileHandler) {
|
||||
afterHandlers.push_back (new RegisteredHandler (fileHandler));
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@ namespace patches::Qr {
|
||||
|
||||
enum class State { Ready, CopyWait };
|
||||
enum class Mode { Card, Data, Image, Plugin };
|
||||
State gState = State::Ready;
|
||||
Mode gMode = Mode::Card;
|
||||
auto gState = State::Ready;
|
||||
auto gMode = Mode::Card;
|
||||
HMODULE gPlugin;
|
||||
std::string accessCode;
|
||||
|
||||
@ -66,7 +66,8 @@ HOOK_DYNAMIC (i64, CopyData, i64, void *dest, int length) {
|
||||
memcpy (dest, accessCode.c_str (), accessCode.size () + 1);
|
||||
gState = State::Ready;
|
||||
return accessCode.size () + 1;
|
||||
} else if (gMode == Mode::Data) {
|
||||
}
|
||||
if (gMode == Mode::Data) {
|
||||
std::string serial = "";
|
||||
u16 type = 0;
|
||||
std::vector<i64> songNoes;
|
||||
@ -75,7 +76,7 @@ HOOK_DYNAMIC (i64, CopyData, i64, void *dest, int length) {
|
||||
if (auto qr = openConfigSection (config_ptr.get (), "qr")) {
|
||||
if (auto data = openConfigSection (qr, "data")) {
|
||||
serial = readConfigString (data, "serial", "");
|
||||
type = (u16)readConfigInt (data, "type", 0);
|
||||
type = static_cast<u16> (readConfigInt (data, "type", 0));
|
||||
songNoes = readConfigIntArray (data, "song_no", songNoes);
|
||||
}
|
||||
}
|
||||
@ -93,11 +94,11 @@ HOOK_DYNAMIC (i64, CopyData, i64, void *dest, int length) {
|
||||
folderData.push_back (static_cast<u8> (songNoes.size ()) * 2);
|
||||
|
||||
folderData.push_back (static_cast<u8> (type & 0xFF));
|
||||
folderData.push_back (static_cast<u8> ((type >> 8) & 0xFF));
|
||||
folderData.push_back (static_cast<u8> (type >> 8 & 0xFF));
|
||||
|
||||
for (i64 songNo : songNoes) {
|
||||
folderData.push_back (static_cast<u8> (songNo & 0xFF));
|
||||
folderData.push_back (static_cast<u8> ((songNo >> 8) & 0xFF));
|
||||
folderData.push_back (static_cast<u8> (songNo >> 8 & 0xFF));
|
||||
}
|
||||
|
||||
for (auto c : folderData)
|
||||
@ -115,7 +116,8 @@ HOOK_DYNAMIC (i64, CopyData, i64, void *dest, int length) {
|
||||
memcpy (dest, byteBuffer.data (), byteBuffer.size ());
|
||||
gState = State::Ready;
|
||||
return byteBuffer.size ();
|
||||
} else if (gMode == Mode::Image) {
|
||||
}
|
||||
if (gMode == Mode::Image) {
|
||||
std::string imagePath = "";
|
||||
|
||||
if (config_ptr) {
|
||||
@ -124,7 +126,7 @@ HOOK_DYNAMIC (i64, CopyData, i64, void *dest, int length) {
|
||||
|
||||
std::u8string u8PathStr (imagePath.begin (), imagePath.end ());
|
||||
std::filesystem::path u8Path (u8PathStr);
|
||||
if (!std::filesystem::is_regular_file (u8Path)) {
|
||||
if (!is_regular_file (u8Path)) {
|
||||
LogMessage (LogLevel::ERROR, ("Failed to open image: " + u8Path.string () + " (file not found)").c_str ());
|
||||
gState = State::Ready;
|
||||
return 0;
|
||||
@ -155,7 +157,8 @@ HOOK_DYNAMIC (i64, CopyData, i64, void *dest, int length) {
|
||||
memcpy (dest, byteData.data (), dataSize);
|
||||
gState = State::Ready;
|
||||
return dataSize;
|
||||
} else if (gMode == Mode::Plugin) {
|
||||
}
|
||||
if (gMode == Mode::Plugin) {
|
||||
if (FARPROC getEvent = GetProcAddress (gPlugin, "GetQr")) {
|
||||
std::vector<unsigned char> plugin_data (length);
|
||||
int buf_len = reinterpret_cast<getQrEvent *> (getEvent) (length, plugin_data.data ());
|
||||
@ -163,21 +166,20 @@ HOOK_DYNAMIC (i64, CopyData, i64, void *dest, int length) {
|
||||
std::stringstream hexStream;
|
||||
for (int i = 0; i < buf_len; i++)
|
||||
hexStream << std::hex << std::uppercase << std::setfill ('0') << std::setw (2) << static_cast<int> (plugin_data[i]) << " ";
|
||||
LogMessage (LogLevel::INFO, ("QR dump: " + hexStream.str ()).c_str ());
|
||||
LogMessage (LogLevel::INFO, "QR dump: " + hexStream.str ());
|
||||
memcpy (dest, plugin_data.data (), buf_len);
|
||||
} else {
|
||||
LogMessage (LogLevel::ERROR, ("QR discard! Length invalid: " + std::to_string (buf_len) + ", valid range: 0~").c_str ());
|
||||
}
|
||||
gState = State::Ready;
|
||||
return buf_len;
|
||||
} else {
|
||||
gState = State::Ready;
|
||||
return 0;
|
||||
}
|
||||
gState = State::Ready;
|
||||
return 0;
|
||||
}
|
||||
} else if (qrPluginRegistered) {
|
||||
for (auto plugin : qrPlugins)
|
||||
if (FARPROC usingQrEvent = GetProcAddress (plugin, "UsingQr")) ((event *)usingQrEvent) ();
|
||||
if (FARPROC usingQrEvent = GetProcAddress (plugin, "UsingQr")) reinterpret_cast<event *> (usingQrEvent) ();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -207,8 +209,7 @@ Update () {
|
||||
gMode = Mode::Image;
|
||||
} else if (qrPluginRegistered) {
|
||||
for (const auto plugin : qrPlugins) {
|
||||
const FARPROC checkEvent = GetProcAddress (plugin, "CheckQr");
|
||||
if (checkEvent && ((checkQrEvent *)checkEvent) ()) {
|
||||
if (const FARPROC checkEvent = GetProcAddress (plugin, "CheckQr"); checkEvent && reinterpret_cast<checkQrEvent *> (checkEvent) ()) {
|
||||
gState = State::CopyWait;
|
||||
gMode = Mode::Plugin;
|
||||
gPlugin = plugin;
|
||||
@ -229,11 +230,8 @@ Init () {
|
||||
}
|
||||
|
||||
for (auto plugin : plugins) {
|
||||
const FARPROC initEvent = GetProcAddress (plugin, "InitQr");
|
||||
if (initEvent) ((initQrEvent *)initEvent) (gameVersion);
|
||||
|
||||
const FARPROC usingQrEvent = GetProcAddress (plugin, "UsingQr");
|
||||
if (usingQrEvent) qrPlugins.push_back (plugin);
|
||||
if (const FARPROC initEvent = GetProcAddress (plugin, "InitQr")) reinterpret_cast<initQrEvent *> (initEvent) (gameVersion);
|
||||
if (GetProcAddress (plugin, "UsingQr")) qrPlugins.push_back (plugin);
|
||||
}
|
||||
if (qrPlugins.size () > 0) {
|
||||
|
||||
@ -242,54 +240,54 @@ Init () {
|
||||
}
|
||||
|
||||
SetConsoleOutputCP (CP_UTF8);
|
||||
const auto amHandle = (u64)GetModuleHandle ("AMFrameWork.dll");
|
||||
const auto amHandle = reinterpret_cast<u64> (GetModuleHandle ("AMFrameWork.dll"));
|
||||
switch (gameVersion) {
|
||||
case GameVersion::JPN00: {
|
||||
INSTALL_HOOK_DYNAMIC (QrInit, (LPVOID)(amHandle + 0x1B3E0));
|
||||
INSTALL_HOOK_DYNAMIC (QrClose, (LPVOID)(amHandle + 0x1B5B0));
|
||||
INSTALL_HOOK_DYNAMIC (QrRead, (LPVOID)(amHandle + 0x1B600));
|
||||
INSTALL_HOOK_DYNAMIC (CallQrUnknown, (LPVOID)(amHandle + 0xFD40));
|
||||
INSTALL_HOOK_DYNAMIC (Send1, (LPVOID)(amHandle + 0x1BBB0));
|
||||
INSTALL_HOOK_DYNAMIC (Send2, (LPVOID)(amHandle + 0x1BBF0));
|
||||
INSTALL_HOOK_DYNAMIC (Send3, (LPVOID)(amHandle + 0x1BC60));
|
||||
INSTALL_HOOK_DYNAMIC (QrInit, reinterpret_cast<LPVOID> (amHandle + 0x1B3E0));
|
||||
INSTALL_HOOK_DYNAMIC (QrClose, reinterpret_cast<LPVOID> (amHandle + 0x1B5B0));
|
||||
INSTALL_HOOK_DYNAMIC (QrRead, reinterpret_cast<LPVOID> (amHandle + 0x1B600));
|
||||
INSTALL_HOOK_DYNAMIC (CallQrUnknown, reinterpret_cast<LPVOID> (amHandle + 0xFD40));
|
||||
INSTALL_HOOK_DYNAMIC (Send1, reinterpret_cast<LPVOID> (amHandle + 0x1BBB0));
|
||||
INSTALL_HOOK_DYNAMIC (Send2, reinterpret_cast<LPVOID> (amHandle + 0x1BBF0));
|
||||
INSTALL_HOOK_DYNAMIC (Send3, reinterpret_cast<LPVOID> (amHandle + 0x1BC60));
|
||||
// JPN00 has no Send4
|
||||
INSTALL_HOOK_DYNAMIC (CopyData, (LPVOID)(amHandle + 0x1BC30));
|
||||
INSTALL_HOOK_DYNAMIC (CopyData, reinterpret_cast<LPVOID> (amHandle + 0x1BC30));
|
||||
break;
|
||||
}
|
||||
case GameVersion::JPN08: {
|
||||
INSTALL_HOOK_DYNAMIC (QrInit, reinterpret_cast<LPVOID> (amHandle + 0x1BA00));
|
||||
INSTALL_HOOK_DYNAMIC (QrClose, reinterpret_cast<LPVOID> (amHandle + 0x1BBD0));
|
||||
INSTALL_HOOK_DYNAMIC (QrRead, (LPVOID)(amHandle + 0x1BC20));
|
||||
INSTALL_HOOK_DYNAMIC (CallQrUnknown, (LPVOID)(amHandle + 0xFD40));
|
||||
INSTALL_HOOK_DYNAMIC (Send1, (LPVOID)(amHandle + 0x1C220));
|
||||
INSTALL_HOOK_DYNAMIC (Send2, (LPVOID)(amHandle + 0x1C260));
|
||||
INSTALL_HOOK_DYNAMIC (Send3, (LPVOID)(amHandle + 0x1C2D0));
|
||||
INSTALL_HOOK_DYNAMIC (QrRead, reinterpret_cast<LPVOID> (amHandle + 0x1BC20));
|
||||
INSTALL_HOOK_DYNAMIC (CallQrUnknown, reinterpret_cast<LPVOID> (amHandle + 0xFD40));
|
||||
INSTALL_HOOK_DYNAMIC (Send1, reinterpret_cast<LPVOID> (amHandle + 0x1C220));
|
||||
INSTALL_HOOK_DYNAMIC (Send2, reinterpret_cast<LPVOID> (amHandle + 0x1C260));
|
||||
INSTALL_HOOK_DYNAMIC (Send3, reinterpret_cast<LPVOID> (amHandle + 0x1C2D0));
|
||||
// JPN08 has no Send4
|
||||
INSTALL_HOOK_DYNAMIC (CopyData, (LPVOID)(amHandle + 0x1C2A0));
|
||||
INSTALL_HOOK_DYNAMIC (CopyData, reinterpret_cast<LPVOID> (amHandle + 0x1C2A0));
|
||||
break;
|
||||
}
|
||||
case GameVersion::JPN39: {
|
||||
INSTALL_HOOK_DYNAMIC (QrInit, (LPVOID)(amHandle + 0x1EDC0));
|
||||
INSTALL_HOOK_DYNAMIC (QrClose, (LPVOID)(amHandle + 0x1EF60));
|
||||
INSTALL_HOOK_DYNAMIC (QrRead, (LPVOID)(amHandle + 0x1EFB0));
|
||||
INSTALL_HOOK_DYNAMIC (CallQrUnknown, (LPVOID)(amHandle + 0x11A70));
|
||||
INSTALL_HOOK_DYNAMIC (Send1, (LPVOID)(amHandle + 0x1F5B0));
|
||||
INSTALL_HOOK_DYNAMIC (Send2, (LPVOID)(amHandle + 0x1F5F0));
|
||||
INSTALL_HOOK_DYNAMIC (Send3, (LPVOID)(amHandle + 0x1F660));
|
||||
INSTALL_HOOK_DYNAMIC (Send4, (LPVOID)(amHandle + 0x1F690));
|
||||
INSTALL_HOOK_DYNAMIC (CopyData, (LPVOID)(amHandle + 0x1F630));
|
||||
INSTALL_HOOK_DYNAMIC (QrInit, reinterpret_cast<LPVOID> (amHandle + 0x1EDC0));
|
||||
INSTALL_HOOK_DYNAMIC (QrClose, reinterpret_cast<LPVOID> (amHandle + 0x1EF60));
|
||||
INSTALL_HOOK_DYNAMIC (QrRead, reinterpret_cast<LPVOID> (amHandle + 0x1EFB0));
|
||||
INSTALL_HOOK_DYNAMIC (CallQrUnknown, reinterpret_cast<LPVOID> (amHandle + 0x11A70));
|
||||
INSTALL_HOOK_DYNAMIC (Send1, reinterpret_cast<LPVOID> (amHandle + 0x1F5B0));
|
||||
INSTALL_HOOK_DYNAMIC (Send2, reinterpret_cast<LPVOID> (amHandle + 0x1F5F0));
|
||||
INSTALL_HOOK_DYNAMIC (Send3, reinterpret_cast<LPVOID> (amHandle + 0x1F660));
|
||||
INSTALL_HOOK_DYNAMIC (Send4, reinterpret_cast<LPVOID> (amHandle + 0x1F690));
|
||||
INSTALL_HOOK_DYNAMIC (CopyData, reinterpret_cast<LPVOID> (amHandle + 0x1F630));
|
||||
break;
|
||||
}
|
||||
case GameVersion::CHN00: {
|
||||
INSTALL_HOOK_DYNAMIC (QrInit, (LPVOID)(amHandle + 0x161B0));
|
||||
INSTALL_HOOK_DYNAMIC (QrClose, (LPVOID)(amHandle + 0x16350));
|
||||
INSTALL_HOOK_DYNAMIC (QrRead, (LPVOID)(amHandle + 0x163A0));
|
||||
INSTALL_HOOK_DYNAMIC (CallQrUnknown, (LPVOID)(amHandle + 0x8F60));
|
||||
INSTALL_HOOK_DYNAMIC (Send1, (LPVOID)(amHandle + 0x16940));
|
||||
INSTALL_HOOK_DYNAMIC (Send2, (LPVOID)(amHandle + 0x16990));
|
||||
INSTALL_HOOK_DYNAMIC (Send3, (LPVOID)(amHandle + 0x16A00));
|
||||
INSTALL_HOOK_DYNAMIC (Send4, (LPVOID)(amHandle + 0x16A30));
|
||||
INSTALL_HOOK_DYNAMIC (CopyData, (LPVOID)(amHandle + 0x169D0));
|
||||
INSTALL_HOOK_DYNAMIC (QrInit, reinterpret_cast<LPVOID> (amHandle + 0x161B0));
|
||||
INSTALL_HOOK_DYNAMIC (QrClose, reinterpret_cast<LPVOID> (amHandle + 0x16350));
|
||||
INSTALL_HOOK_DYNAMIC (QrRead, reinterpret_cast<LPVOID> (amHandle + 0x163A0));
|
||||
INSTALL_HOOK_DYNAMIC (CallQrUnknown, reinterpret_cast<LPVOID> (amHandle + 0x8F60));
|
||||
INSTALL_HOOK_DYNAMIC (Send1, reinterpret_cast<LPVOID> (amHandle + 0x16940));
|
||||
INSTALL_HOOK_DYNAMIC (Send2, reinterpret_cast<LPVOID> (amHandle + 0x16990));
|
||||
INSTALL_HOOK_DYNAMIC (Send3, reinterpret_cast<LPVOID> (amHandle + 0x16A00));
|
||||
INSTALL_HOOK_DYNAMIC (Send4, reinterpret_cast<LPVOID> (amHandle + 0x16A30));
|
||||
INSTALL_HOOK_DYNAMIC (CopyData, reinterpret_cast<LPVOID> (amHandle + 0x169D0));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
@ -38,9 +38,10 @@ u64 appAccessor = 0;
|
||||
RefTestModeMain refTestMode = nullptr;
|
||||
|
||||
pugi::xml_document &
|
||||
CreateMenu (pugi::xml_document &menuMain, std::wstring menuId, std::wstring menuName, std::vector<std::wstring> items, std::wstring backId) {
|
||||
CreateMenu (pugi::xml_document &menuMain, const std::wstring &menuId, const std::wstring &menuName, const std::vector<std::wstring> &items,
|
||||
const std::wstring &backId) {
|
||||
LogMessage (LogLevel::DEBUG, L"Create Menu " + menuName);
|
||||
std::wstring menuBasicLine = L"<menu id=\"" + menuId + L"\"></menu>";
|
||||
const std::wstring menuBasicLine = L"<menu id=\"" + menuId + L"\"></menu>";
|
||||
if (menuMain.load_string (menuBasicLine.c_str ())) {
|
||||
pugi::xml_node menu = menuMain.first_child ();
|
||||
pugi::xml_node menuHeader = menu.append_child (L"layout");
|
||||
@ -50,7 +51,7 @@ CreateMenu (pugi::xml_document &menuMain, std::wstring menuId, std::wstring menu
|
||||
menuHeader.append_attribute (L"type") = L"Header";
|
||||
menuHeader.append_child (L"break-item");
|
||||
pugi::xml_node menuTitle = menuHeader.append_child (L"text-item");
|
||||
std::wstring menuNameFull = L" " + menuName;
|
||||
const std::wstring menuNameFull = L" " + menuName;
|
||||
menuTitle.append_attribute (L"label") = menuNameFull.c_str ();
|
||||
menuHeader.append_child (L"break-item");
|
||||
menuHeader.append_child (L"break-item");
|
||||
@ -61,7 +62,7 @@ CreateMenu (pugi::xml_document &menuMain, std::wstring menuId, std::wstring menu
|
||||
// Mod Manager Menu Center
|
||||
menuCenter.append_attribute (L"type") = L"Center";
|
||||
menuCenter.append_attribute (L"padding-x") = L"23";
|
||||
for (std::wstring item : items) {
|
||||
for (const std::wstring& item : items) {
|
||||
std::wstring itemLine = L"<root>" + item + L"</root>";
|
||||
if (pugi::xml_document menuItem; menuItem.load_string (itemLine.c_str ())) menuCenter.append_copy (menuItem.first_child ().first_child ());
|
||||
else LogMessage (LogLevel::ERROR, L"Failed to parse option line: " + item);
|
||||
@ -96,7 +97,7 @@ ReadXMLFileSwitcher (std::wstring &fileName) {
|
||||
}
|
||||
|
||||
HOOK_DYNAMIC (void, TestModeSetMenuHook, u64 testModeLibrary, const wchar_t *lFileName) {
|
||||
auto originalFileName = std::wstring (lFileName);
|
||||
const auto originalFileName = std::wstring (lFileName);
|
||||
std::wstring fileName = originalFileName;
|
||||
if (fileName.ends_with (L"DeviceInitialize.xml") || fileName.ends_with (L"DeviceInitialize_asia.xml")
|
||||
|| fileName.ends_with (L"DeviceInitialize_china.xml")) {
|
||||
@ -106,11 +107,11 @@ HOOK_DYNAMIC (void, TestModeSetMenuHook, u64 testModeLibrary, const wchar_t *lFi
|
||||
LogMessage (LogLevel::ERROR, L"Loading DeviceInitialize structure failed! path: " + fileName);
|
||||
moddedInitial = fileName;
|
||||
} else {
|
||||
std::wstring modFileName
|
||||
const std::wstring modFileName
|
||||
= replace (replace (replace (fileName, L"lize_asia.xml", L"lize_mod.xml"), L"lize_china.xml", L"lize_mod.xml"), L"lize.xml",
|
||||
L"lize_mod.xml");
|
||||
auto dongleQuery = pugi::xpath_query (L"/root/menu[@id='TopMenu']/layout[@type='Center']/select-item[@id='DongleItem']");
|
||||
pugi::xml_node dongleItem = doc.select_node (dongleQuery).node ();
|
||||
const auto dongleQuery = pugi::xpath_query (L"/root/menu[@id='TopMenu']/layout[@type='Center']/select-item[@id='DongleItem']");
|
||||
const pugi::xml_node dongleItem = doc.select_node (dongleQuery).node ();
|
||||
pugi::xml_node talItem = dongleItem.parent ().append_copy (dongleItem);
|
||||
talItem.attribute (L"label").set_value (L"TAIKOARCADELOADER");
|
||||
talItem.attribute (L"id").set_value (L"TaikoArcadeLoader");
|
||||
@ -130,10 +131,11 @@ HOOK_DYNAMIC (void, TestModeSetMenuHook, u64 testModeLibrary, const wchar_t *lFi
|
||||
LogMessage (LogLevel::ERROR, L"Loading TestMode structure failed! path: " + fileName);
|
||||
modded = fileName;
|
||||
} else {
|
||||
std::wstring modFileName
|
||||
const std::wstring modFileName
|
||||
= replace (replace (replace (fileName, L"Mode_asia.xml", L"Mode_mod.xml"), L"Mode_china.xml", L"Mode_mod.xml"), L"Mode.xml",
|
||||
L"Mode_mod.xml");
|
||||
if (!registeredItems.empty ()) { auto menuQuery
|
||||
if (!registeredItems.empty ()) {
|
||||
const auto menuQuery
|
||||
= pugi::xpath_query (L"/root/menu[@id='TopMenu']/layout[@type='Center']/menu-item[@menu='GameOptionsMenu']");
|
||||
pugi::xml_node menuItem = doc.select_node (menuQuery).node ();
|
||||
menuItem = menuItem.next_sibling ();
|
||||
@ -144,18 +146,18 @@ HOOK_DYNAMIC (void, TestModeSetMenuHook, u64 testModeLibrary, const wchar_t *lFi
|
||||
|
||||
pugi::xml_document modMenu;
|
||||
std::vector<std::wstring> toInsertItems = {};
|
||||
for (RegisteredItem *item : registeredItems) {
|
||||
for (const RegisteredItem *item : registeredItems) {
|
||||
toInsertItems.push_back (item->selectItem);
|
||||
item->registerInit ();
|
||||
}
|
||||
CreateMenu (modMenu, L"ModManagerMenu", L"MOD MANAGER", toInsertItems, L"TopMenu");
|
||||
auto topMenuQuery = pugi::xpath_query (L"/root/menu[@id='TopMenu']");
|
||||
pugi::xml_node topMenu = doc.select_node (topMenuQuery).node ();
|
||||
const auto topMenuQuery = pugi::xpath_query (L"/root/menu[@id='TopMenu']");
|
||||
const pugi::xml_node topMenu = doc.select_node (topMenuQuery).node ();
|
||||
topMenu.parent ().insert_copy_after (modMenu.first_child (), topMenu);
|
||||
}
|
||||
|
||||
if (!registeredModifies.empty ()) {
|
||||
for (RegisteredModify *modify : registeredModifies) { auto modifyQuery = pugi::xpath_query (modify->query.c_str ());
|
||||
for (const RegisteredModify *modify : registeredModifies) { auto modifyQuery = pugi::xpath_query (modify->query.c_str ());
|
||||
try {
|
||||
if (pugi::xml_node modifyNode = doc.select_node (modifyQuery).node ()) {
|
||||
modify->nodeModify (modifyNode);
|
||||
@ -180,103 +182,98 @@ HOOK_DYNAMIC (void, TestModeSetMenuHook, u64 testModeLibrary, const wchar_t *lFi
|
||||
void
|
||||
CommonModify () {
|
||||
// Default off Close time
|
||||
TestMode::RegisterModify (
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='CloseTimeSettingMenu']/layout[@type='Center']/select-item[@id='ScheduleTypeItem']",
|
||||
[&] (const pugi::xml_node &node) { node.attribute (L"default").set_value (L"0"); }, [&] () {});
|
||||
[&] (const pugi::xml_node &node) { node.attribute (L"default").set_value (L"0"); }, [&] {});
|
||||
}
|
||||
|
||||
void
|
||||
LocalizationCHT () {
|
||||
TestMode::RegisterModify (
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='TopMenu']/layout[@type='Center']/menu-item[@menu='ModManagerMenu']",
|
||||
[&] (const pugi::xml_node &node) { node.attribute (L"label").set_value (L"模組管理"); }, [] () {});
|
||||
TestMode::RegisterModify (
|
||||
[&] (const pugi::xml_node &node) { node.attribute (L"label").set_value (L"模組管理"); }, [] {});
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='ModManagerMenu']/layout[@type='Header']/text-item",
|
||||
[&] (const pugi::xml_node &node) { node.attribute (L"label").set_value (L"模組管理"); }, [] () {});
|
||||
TestMode::RegisterModify (
|
||||
[&] (const pugi::xml_node &node) { node.attribute (L"label").set_value (L"模組管理"); }, [] {});
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='ModManagerMenu']/layout[@type='Center']/select-item[@id='ModFreezeTimer']",
|
||||
[&] (const pugi::xml_node &node) {
|
||||
node.attribute (L"label").set_value (L"凍結計時");
|
||||
node.attribute (L"replace-text").set_value (L"0:關閉, 1:開啓");
|
||||
},
|
||||
[] () {});
|
||||
TestMode::RegisterModify (
|
||||
[] {});
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='ModManagerMenu']/layout[@type='Center']/select-item[@id='ModModeCollabo024']",
|
||||
[&] (const pugi::xml_node &node) {
|
||||
node.attribute (L"label").set_value (L"鬼滅之刃模式");
|
||||
node.attribute (L"replace-text").set_value (L"0:黙認, 1:啓用, 2:僅刷卡");
|
||||
},
|
||||
[] () {});
|
||||
TestMode::RegisterModify (
|
||||
[] {});
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='ModManagerMenu']/layout[@type='Center']/select-item[@id='ModModeCollabo025']",
|
||||
[&] (const pugi::xml_node &node) {
|
||||
node.attribute (L"label").set_value (L"航海王模式");
|
||||
node.attribute (L"replace-text").set_value (L"0:黙認, 1:啓用, 2:僅刷卡");
|
||||
},
|
||||
[] () {});
|
||||
TestMode::RegisterModify (
|
||||
[] {});
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='ModManagerMenu']/layout[@type='Center']/select-item[@id='ModModeCollabo026']",
|
||||
[&] (const pugi::xml_node &node) {
|
||||
node.attribute (L"label").set_value (L"AI粗品模式");
|
||||
node.attribute (L"replace-text").set_value (L"0:黙認, 1:啓用, 2:僅刷卡");
|
||||
},
|
||||
[] () {});
|
||||
TestMode::RegisterModify (
|
||||
[] {});
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='ModManagerMenu']/layout[@type='Center']/select-item[@id='ModModeAprilFool001']",
|
||||
[&] (const pugi::xml_node &node) {
|
||||
node.attribute (L"label").set_value (L"青春之達人模式");
|
||||
node.attribute (L"replace-text").set_value (L"0:黙認, 1:啓用, 2:僅刷卡");
|
||||
},
|
||||
[] () {});
|
||||
TestMode::RegisterModify (
|
||||
[] {});
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='ModManagerMenu']/layout[@type='Center']/menu-item[@menu='TopMenu']",
|
||||
[&] (const pugi::xml_node &node) { node.attribute (L"label").set_value (L"離開"); }, [] () {});
|
||||
[&] (const pugi::xml_node &node) { node.attribute (L"label").set_value (L"離開"); }, [] {});
|
||||
}
|
||||
|
||||
void
|
||||
LocalizationCHS () {
|
||||
TestMode::RegisterModify (
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='TopMenu']/layout[@type='Center']/menu-item[@menu='ModManagerMenu']",
|
||||
[&] (const pugi::xml_node &node) { node.attribute (L"label").set_value (L"模组管理"); }, [] () {});
|
||||
TestMode::RegisterModify (
|
||||
[&] (const pugi::xml_node &node) { node.attribute (L"label").set_value (L"模组管理"); }, [] {});
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='ModManagerMenu']/layout[@type='Header']/text-item",
|
||||
[&] (const pugi::xml_node &node) { node.attribute (L"label").set_value (L"模组管理"); }, [] () {});
|
||||
TestMode::RegisterModify (
|
||||
[&] (const pugi::xml_node &node) { node.attribute (L"label").set_value (L"模组管理"); }, [] {});
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='ModManagerMenu']/layout[@type='Center']/select-item[@id='ModFreezeTimer']",
|
||||
[&] (const pugi::xml_node &node) {
|
||||
node.attribute (L"label").set_value (L"冻结计时");
|
||||
node.attribute (L"replace-text").set_value (L"0:禁用, 1:启用");
|
||||
},
|
||||
[] () {});
|
||||
TestMode::RegisterModify (
|
||||
[] {});
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='ModManagerMenu']/layout[@type='Center']/select-item[@id='ModModeCollabo024']",
|
||||
[&] (const pugi::xml_node &node) {
|
||||
node.attribute (L"label").set_value (L"鬼灭之刃模式");
|
||||
node.attribute (L"replace-text").set_value (L"0:默认, 1:启用, 2:仅刷卡");
|
||||
},
|
||||
[] () {});
|
||||
TestMode::RegisterModify (
|
||||
[] {});
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='ModManagerMenu']/layout[@type='Center']/select-item[@id='ModModeCollabo025']",
|
||||
[&] (const pugi::xml_node &node) {
|
||||
node.attribute (L"label").set_value (L"航海王模式");
|
||||
node.attribute (L"replace-text").set_value (L"0:默认, 1:启用, 2:仅刷卡");
|
||||
},
|
||||
[] () {});
|
||||
TestMode::RegisterModify (
|
||||
[] {});
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='ModManagerMenu']/layout[@type='Center']/select-item[@id='ModModeCollabo026']",
|
||||
[&] (const pugi::xml_node &node) {
|
||||
node.attribute (L"label").set_value (L"AI粗品模式");
|
||||
node.attribute (L"replace-text").set_value (L"0:默认, 1:启用, 2:仅刷卡");
|
||||
},
|
||||
[] () {});
|
||||
// TestMode::RegisterModify(
|
||||
// L"/root/menu[@id='ModManagerMenu']/layout[@type='Center']/select-item[@id='ModModeAprilFool001']",
|
||||
// [&](pugi::xml_node &node) { node.attribute(L"label").set_value(L"青春之达人模式"); node.attribute(L"replace-text").set_value(L"0:默认,
|
||||
// 1:启用, 2:仅刷卡"); }, [](){}
|
||||
// );
|
||||
TestMode::RegisterModify (
|
||||
[] {});
|
||||
RegisterModify (
|
||||
L"/root/menu[@id='ModManagerMenu']/layout[@type='Center']/menu-item[@menu='TopMenu']",
|
||||
[&] (const pugi::xml_node &node) { node.attribute (L"label").set_value (L"离开"); }, [] () {});
|
||||
[&] (const pugi::xml_node &node) { node.attribute (L"label").set_value (L"离开"); }, [] {});
|
||||
}
|
||||
|
||||
void
|
||||
@ -309,8 +306,8 @@ Init () {
|
||||
|
||||
void
|
||||
SetupAccessor (const u64 appAccessor, const RefTestModeMain refTestMode) {
|
||||
patches::TestMode::appAccessor = appAccessor;
|
||||
patches::TestMode::refTestMode = refTestMode;
|
||||
TestMode::appAccessor = appAccessor;
|
||||
TestMode::refTestMode = refTestMode;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -142,8 +142,8 @@ Init () {
|
||||
|
||||
if (const auto graphics = openConfigSection (config_ptr.get (), "graphics")) {
|
||||
if (const auto res = openConfigSection (graphics, "res")) {
|
||||
xRes = (i32)readConfigInt (res, "x", xRes);
|
||||
yRes = (i32)readConfigInt (res, "y", yRes);
|
||||
xRes = static_cast<i32> (readConfigInt (res, "x", xRes));
|
||||
yRes = static_cast<i32> (readConfigInt (res, "y", yRes));
|
||||
}
|
||||
vsync = readConfigBool (graphics, "vsync", vsync);
|
||||
}
|
||||
@ -181,11 +181,11 @@ Init () {
|
||||
WRITE_MEMORY (ASLR (address) + 2, i32, datatableBufferSize);
|
||||
|
||||
auto bufferBase = MODULE_HANDLE - 0x03000000;
|
||||
AllocateStaticBufferNear ((void *)bufferBase, datatableBufferSize, &datatableBuffer1);
|
||||
AllocateStaticBufferNear (bufferBase, datatableBufferSize, &datatableBuffer1);
|
||||
bufferBase += datatableBufferSize;
|
||||
AllocateStaticBufferNear ((void *)bufferBase, datatableBufferSize, &datatableBuffer2);
|
||||
AllocateStaticBufferNear (bufferBase, datatableBufferSize, &datatableBuffer2);
|
||||
bufferBase += datatableBufferSize;
|
||||
AllocateStaticBufferNear ((void *)bufferBase, datatableBufferSize, &datatableBuffer3);
|
||||
AllocateStaticBufferNear (bufferBase, datatableBufferSize, &datatableBuffer3);
|
||||
|
||||
ReplaceLeaBufferAddress (datatableBuffer1Addresses, datatableBuffer1.data ());
|
||||
ReplaceLeaBufferAddress (datatableBuffer2Addresses, datatableBuffer2.data ());
|
||||
|
@ -50,8 +50,8 @@ Init () {
|
||||
|
||||
if (const auto graphics = openConfigSection (config_ptr.get (), "graphics")) {
|
||||
if (const auto res = openConfigSection (graphics, "res")) {
|
||||
xRes = (i32)readConfigInt (res, "x", xRes);
|
||||
yRes = (i32)readConfigInt (res, "y", yRes);
|
||||
xRes = static_cast<i32> (readConfigInt (res, "x", xRes));
|
||||
yRes = static_cast<i32> (readConfigInt (res, "y", yRes));
|
||||
}
|
||||
vsync = readConfigBool (graphics, "vsync", vsync);
|
||||
}
|
||||
@ -81,7 +81,7 @@ Init () {
|
||||
WRITE_MEMORY (ASLR (address) + 2, i32, datatableBufferSize);
|
||||
|
||||
const auto bufferBase = MODULE_HANDLE - 0x01000000;
|
||||
AllocateStaticBufferNear ((void *)bufferBase, datatableBufferSize, &datatableBuffer);
|
||||
AllocateStaticBufferNear (bufferBase, datatableBufferSize, &datatableBuffer);
|
||||
|
||||
ReplaceLeaBufferAddress (datatableBufferAddresses, datatableBuffer.data ());
|
||||
}
|
||||
|
@ -60,8 +60,8 @@ Init () {
|
||||
|
||||
if (auto graphics = openConfigSection (config_ptr.get (), "graphics")) {
|
||||
if (auto res = openConfigSection (graphics, "res")) {
|
||||
xRes = (i32)readConfigInt (res, "x", xRes);
|
||||
yRes = (i32)readConfigInt (res, "y", yRes);
|
||||
xRes = static_cast<i32> (readConfigInt (res, "x", xRes));
|
||||
yRes = static_cast<i32> (readConfigInt (res, "y", yRes));
|
||||
}
|
||||
vsync = readConfigBool (graphics, "vsync", vsync);
|
||||
}
|
||||
@ -91,7 +91,7 @@ Init () {
|
||||
WRITE_MEMORY (ASLR (address) + 2, i32, datatableBufferSize);
|
||||
|
||||
auto bufferBase = MODULE_HANDLE - 0x01000000;
|
||||
AllocateStaticBufferNear ((void *)bufferBase, datatableBufferSize, &datatableBuffer);
|
||||
AllocateStaticBufferNear (bufferBase, datatableBufferSize, &datatableBuffer);
|
||||
|
||||
ReplaceLeaBufferAddress (datatableBufferAddresses, datatableBuffer.data ());
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// ReSharper disable CppTooWideScopeInitStatement
|
||||
#include "helpers.h"
|
||||
#include "../patches.h"
|
||||
#include <map>
|
||||
|
||||
namespace patches::JPN39 {
|
||||
int language = 0;
|
||||
@ -254,7 +255,7 @@ check_voice_tail (const std::string &bankName, u8 *pBinfBlock, std::map<std::str
|
||||
|
||||
MID_HOOK (GenNus3bankId, ASLR (0x1407B97BD), SafetyHookContext &ctx) {
|
||||
LogMessage (LogLevel::HOOKS, "GenNus3bankId was called");
|
||||
std::lock_guard<std::mutex> lock (nus3bankMtx);
|
||||
std::lock_guard lock (nus3bankMtx);
|
||||
if (reinterpret_cast<u8 **> (ctx.rcx + 8) != nullptr) {
|
||||
u8 *pNus3bankFile = *reinterpret_cast<u8 **> (ctx.rcx + 8);
|
||||
if (pNus3bankFile[0] == 'N' && pNus3bankFile[1] == 'U' && pNus3bankFile[2] == 'S' && pNus3bankFile[3] == '3') {
|
||||
@ -352,7 +353,7 @@ HOOK (i64, LoadedBankAll, ASLR (0x1404C69F0), i64 a1) {
|
||||
float soundRate = 1.0F;
|
||||
HOOK (i32, SetMasterVolumeSpeaker, ASLR (0x140160330), i32 a1) {
|
||||
LogMessage (LogLevel::HOOKS, "SetMasterVolumeSpeaker was called");
|
||||
soundRate = (float)(a1 <= 100 ? 1.0F : a1 / 100.0);
|
||||
soundRate = static_cast<float> (a1 <= 100 ? 1.0F : a1 / 100.0);
|
||||
return originalSetMasterVolumeSpeaker (a1 > 100 ? 100 : a1);
|
||||
}
|
||||
|
||||
@ -428,8 +429,8 @@ Init () {
|
||||
|
||||
if (auto graphics = openConfigSection (config_ptr.get (), "graphics")) {
|
||||
if (auto res = openConfigSection (graphics, "res")) {
|
||||
xRes = (i32)readConfigInt (res, "x", xRes);
|
||||
yRes = (i32)readConfigInt (res, "y", yRes);
|
||||
xRes = static_cast<i32> (readConfigInt (res, "x", xRes));
|
||||
yRes = static_cast<i32> (readConfigInt (res, "y", yRes));
|
||||
}
|
||||
vsync = readConfigBool (graphics, "vsync", vsync);
|
||||
}
|
||||
@ -487,11 +488,11 @@ Init () {
|
||||
WRITE_MEMORY (ASLR (address) + 2, i32, datatableBufferSize);
|
||||
|
||||
auto bufferBase = MODULE_HANDLE - 0x03000000;
|
||||
AllocateStaticBufferNear ((void *)bufferBase, datatableBufferSize, &datatableBuffer1);
|
||||
AllocateStaticBufferNear (bufferBase, datatableBufferSize, &datatableBuffer1);
|
||||
bufferBase += datatableBufferSize;
|
||||
AllocateStaticBufferNear ((void *)bufferBase, datatableBufferSize, &datatableBuffer2);
|
||||
AllocateStaticBufferNear (bufferBase, datatableBufferSize, &datatableBuffer2);
|
||||
bufferBase += datatableBufferSize;
|
||||
AllocateStaticBufferNear ((void *)bufferBase, datatableBufferSize, &datatableBuffer3);
|
||||
AllocateStaticBufferNear (bufferBase, datatableBufferSize, &datatableBuffer3);
|
||||
|
||||
ReplaceLeaBufferAddress (datatableBuffer1Addresses, datatableBuffer1.data ());
|
||||
ReplaceLeaBufferAddress (datatableBuffer2Addresses, datatableBuffer2.data ());
|
||||
@ -501,23 +502,23 @@ Init () {
|
||||
// Freeze Timer
|
||||
TestMode::RegisterItem (L"<select-item label=\"FREEZE TIMER\" param-offset-x=\"35\" replace-text=\"0:OFF, 1:ON\" "
|
||||
L"group=\"Setting\" id=\"ModFreezeTimer\" max=\"1\" min=\"0\" default=\"0\"/>",
|
||||
[&] () { INSTALL_MID_HOOK (FreezeTimer); });
|
||||
[&] { INSTALL_MID_HOOK (FreezeTimer); });
|
||||
// Mode Unlock
|
||||
TestMode::RegisterItem (L"<select-item label=\"KIMETSU MODE\" param-offset-x=\"35\" replace-text=\"0:DEFAULT, 1:ENABLE, "
|
||||
L"2:CARD ONLY\" group=\"Setting\" id=\"ModModeCollabo024\" max=\"1\" min=\"0\" default=\"0\"/>",
|
||||
[&] () { INSTALL_HOOK (AvailableMode_Collabo024); });
|
||||
[&] { INSTALL_HOOK (AvailableMode_Collabo024); });
|
||||
TestMode::RegisterItem (L"<select-item label=\"ONE PIECE MODE\" param-offset-x=\"35\" replace-text=\"0:DEFAULT, "
|
||||
L"1:ENABLE, 2:CARD ONLY\" group=\"Setting\" id=\"ModModeCollabo025\" max=\"1\" min=\"0\" default=\"0\"/>",
|
||||
[&] () { INSTALL_HOOK (AvailableMode_Collabo025); });
|
||||
[&] { INSTALL_HOOK (AvailableMode_Collabo025); });
|
||||
TestMode::RegisterItem (L"<select-item label=\"AI SOSHINA MODE\" param-offset-x=\"35\" replace-text=\"0:DEFAULT, "
|
||||
L"1:ENABLE, 2:CARD ONLY\" group=\"Setting\" id=\"ModModeCollabo026\" max=\"1\" min=\"0\" default=\"0\"/>",
|
||||
[&] () { INSTALL_HOOK (AvailableMode_Collabo026); });
|
||||
[&] { INSTALL_HOOK (AvailableMode_Collabo026); });
|
||||
TestMode::RegisterItem (L"<select-item label=\"AOHARU MODE\" param-offset-x=\"35\" replace-text=\"0:DEFAULT, 1:ENABLE, "
|
||||
L"2:CARD ONLY\" group=\"Setting\" id=\"ModModeAprilFool001\" max=\"1\" min=\"0\" default=\"0\"/>",
|
||||
[&] () { INSTALL_HOOK (AvailableMode_AprilFool001); });
|
||||
[&] { INSTALL_HOOK (AvailableMode_AprilFool001); });
|
||||
TestMode::RegisterItem (L"<select-item label=\"INSTANT RESULT\" param-offset-x=\"35\" replace-text=\"0:OFF, 1:ON\" "
|
||||
L"group=\"Setting\" id=\"ModInstantResult\" max=\"1\" min=\"0\" default=\"0\"/>",
|
||||
[&] () {
|
||||
[&] {
|
||||
INSTALL_HOOK (SceneResultInitialize_Enso);
|
||||
INSTALL_HOOK (SceneResultInitialize_AI);
|
||||
INSTALL_HOOK (SceneResultInitialize_Collabo025);
|
||||
@ -585,7 +586,7 @@ Init () {
|
||||
std::string fileName = currentFileName;
|
||||
fileName = replace (fileName, "\\lumen\\", "\\lumen_cn\\");
|
||||
if (std::filesystem::exists (fileName)) return fileName;
|
||||
else return currentFileName;
|
||||
return currentFileName;
|
||||
});
|
||||
}
|
||||
|
||||
|
17
src/poll.cpp
17
src/poll.cpp
@ -384,7 +384,7 @@ SetConfigValue (const toml_table_t *table, const char *key, Keybindings *key_bin
|
||||
}
|
||||
|
||||
bool
|
||||
InitializePoll (HWND windowHandle) {
|
||||
InitializePoll (const HWND windowHandle) {
|
||||
bool hasRumble = true;
|
||||
SDL_SetMainReady ();
|
||||
|
||||
@ -404,8 +404,9 @@ InitializePoll (HWND windowHandle) {
|
||||
}
|
||||
}
|
||||
|
||||
const auto configPath = std::filesystem::current_path () / "gamecontrollerdb.txt";
|
||||
if (SDL_GameControllerAddMappingsFromFile (configPath.string ().c_str ()) == -1) LogMessage (LogLevel::ERROR, "Cannot read gamecontrollerdb.txt");
|
||||
if (const auto configPath = std::filesystem::current_path () / "gamecontrollerdb.txt";
|
||||
SDL_GameControllerAddMappingsFromFile (configPath.string ().c_str ()) == -1)
|
||||
LogMessage (LogLevel::ERROR, "Cannot read gamecontrollerdb.txt");
|
||||
SDL_GameControllerEventState (SDL_ENABLE);
|
||||
SDL_JoystickEventState (SDL_ENABLE);
|
||||
|
||||
@ -428,7 +429,7 @@ InitializePoll (HWND windowHandle) {
|
||||
}
|
||||
|
||||
void
|
||||
UpdatePoll (HWND windowHandle) {
|
||||
UpdatePoll (const HWND windowHandle) {
|
||||
if (windowHandle == nullptr || GetForegroundWindow () != windowHandle) return;
|
||||
|
||||
memcpy (lastKeyboardState, currentKeyboardState, 255);
|
||||
@ -560,7 +561,7 @@ StringToConfigEnum (const char *value) {
|
||||
|
||||
InternalButtonState
|
||||
GetInternalButtonState (const Keybindings &bindings) {
|
||||
InternalButtonState buttons = {0};
|
||||
InternalButtonState buttons = {};
|
||||
|
||||
for (size_t i = 0; i < ConfigKeyboardButtonsCount; i++) {
|
||||
if (bindings.keycodes[i] == 0) continue;
|
||||
@ -670,19 +671,19 @@ GetWasMouseScrollDown () {
|
||||
bool
|
||||
GetMouseScrollIsReleased (const Scroll scroll) {
|
||||
if (scroll == MOUSE_SCROLL_UP) return !GetMouseScrollUp () && GetWasMouseScrollUp ();
|
||||
else return !GetMouseScrollDown () && GetWasMouseScrollDown ();
|
||||
return !GetMouseScrollDown () && GetWasMouseScrollDown ();
|
||||
}
|
||||
|
||||
bool
|
||||
GetMouseScrollIsDown (const Scroll scroll) {
|
||||
if (scroll == MOUSE_SCROLL_UP) return GetMouseScrollUp ();
|
||||
else return GetMouseScrollDown ();
|
||||
return GetMouseScrollDown ();
|
||||
}
|
||||
|
||||
bool
|
||||
GetMouseScrollIsTapped (const Scroll scroll) {
|
||||
if (scroll == MOUSE_SCROLL_UP) return GetMouseScrollUp () && !GetWasMouseScrollUp ();
|
||||
else return GetMouseScrollDown () && !GetWasMouseScrollDown ();
|
||||
return GetMouseScrollDown () && !GetWasMouseScrollDown ();
|
||||
}
|
||||
|
||||
bool
|
||||
|
Loading…
Reference in New Issue
Block a user