Skip to content

Commit

Permalink
add High Resolution Timer switch
Browse files Browse the repository at this point in the history
add WARN for experimental function
  • Loading branch information
ryumiyax committed Dec 8, 2024
1 parent cb0d469 commit 7039829
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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 dll of TaikoArcadeLoader will be written in the `dist` folder.

(experimental) To enable `async update` / `async io`, you can add `-DASYNC_UPDATE` or `-DASYNC_IO` into add_definitions in CMakeLists.txt
The compiled dll of TaikoArcadeLoader will be written in the `dist` folder.
2 changes: 1 addition & 1 deletion dist/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ version = "auto" # Patch version
# | - JPN39: For use with Taiko JPN 39.06
# | - CHN00: For use with Taiko CHN 00.32
unlock_songs = true

high_res_timer = true # (experimental) Enable High Resolution Timer, which might improve judgement timing

[patches.chn00] # These patches are only available for version CHN00
fix_language = false # Sync test mode language to attract etc
Expand Down
2 changes: 1 addition & 1 deletion src/bnusio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ std::condition_variable syncCV;

void
UpdateLoop () {
LogMessage (LogLevel::WARN, "Using Async Update (experimental)!");
LogMessage (LogLevel::WARN, "(experimental) Using Async Update!");
std::unique_lock<std::mutex> syncLock(syncMtx);
while (exited < 120) {
syncCV.wait (syncLock);
Expand Down
12 changes: 9 additions & 3 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ char accessCode1[21] = "00000000000000000001";
char accessCode2[21] = "00000000000000000002";
char chipId1[33] = "00000000000000000000000000000001";
char chipId2[33] = "00000000000000000000000000000002";
bool highResTimer = true;
bool windowed = false;
bool autoIme = false;
bool jpLayout = false;
Expand Down Expand Up @@ -150,7 +151,7 @@ DllMain (HMODULE module, const DWORD reason, LPVOID reserved) {
LogMessage (LogLevel::INFO, "Loading config...");

#ifdef ASYNC_IO
LogMessage (LogLevel::WARN, "Using Async IO (experimental)!");
LogMessage (LogLevel::WARN, "(experimental) Using Async IO!");
InitializeKeyboard ();
#endif

Expand All @@ -176,7 +177,10 @@ DllMain (HMODULE module, const DWORD reason, LPVOID reserved) {
std::strcat (placeId, countryCode.c_str ());
std::strcat (placeId, "0FF0");
}
if (const auto patches = openConfigSection (config, "patches")) version = readConfigString (patches, "version", version);
if (const auto patches = openConfigSection (config, "patches")) {
version = readConfigString (patches, "version", version);
highResTimer = readConfigBool (patches, "high_res_timer", highResTimer);
}
if (const auto emulation = openConfigSection (config, "emulation")) {
emulateUsio = readConfigBool (emulation, "usio", emulateUsio);
emulateCardReader = readConfigBool (emulation, "card_reader", emulateCardReader);
Expand Down Expand Up @@ -266,7 +270,9 @@ DllMain (HMODULE module, const DWORD reason, LPVOID reserved) {
patches::LayeredFs::Init ();
patches::TestMode::Init ();

patches::Timer::Init ();
if (highResTimer) {
patches::Timer::Init ();
}

LogMessage (LogLevel::INFO, "==== Finished Loading patches!");
}
Expand Down
8 changes: 4 additions & 4 deletions src/patches/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ namespace patches::Timer {
NTSTATUS queryStatus = NtQueryTimerResolution(&currentResolution, &minimumResolution, &maximumResolution);
if (queryStatus == 0) {
bool setHighResolutionTimer = currentResolution > maximumResolution;
LogMessage (LogLevel::INFO, "Timer Resolution current: {}ms maximum: {}ms", currentResolution / 10000.0, maximumResolution / 10000.0);
LogMessage (LogLevel::WARN, "(experimental) Timer Resolution current: {}ms maximum: {}ms", currentResolution / 10000.0, maximumResolution / 10000.0);

if (setHighResolutionTimer) {
NTSTATUS status = NtSetTimerResolution(maximumResolution, TRUE, &currentResolution);
if (status == 0) {
LogMessage (LogLevel::INFO, "Successfully change Timer resolution to {}ms", maximumResolution / 10000.0);
LogMessage (LogLevel::WARN, "(experimental) Successfully change Timer resolution to {}ms", maximumResolution / 10000.0);
} else {
LogMessage (LogLevel::ERROR, "Failed to change Timer resolution, status={}", status);
LogMessage (LogLevel::ERROR, "(experimental) Failed to change Timer resolution, status={}", status);
}
atexit (Release);
}
} else LogMessage (LogLevel::ERROR, "Failed to query Timer resolution, status={}", queryStatus);
} else LogMessage (LogLevel::ERROR, "(experimental) Failed to query Timer resolution, status={}", queryStatus);
}
}
14 changes: 7 additions & 7 deletions src/patches/versions/JPN39.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,12 @@ HOOK (u64, EnsoGameManagerChechEnsoEnd, ASLR (0x1400E2A10), u64 a1, u64 a2, u64
return result;
}

HOOK (DWORD*, AcquireMostCompatibleDisplayMode, ASLR (0x14064C870), i64 a1, DWORD *a2, DWORD *a3) {
LogMessage (LogLevel::DEBUG, "AcquireMostCompatibleDisplayMode {:d} {:d} {:f} {:f}", a3[0], a3[1], (float)(int)a3[2], (float)(int)a3[3]);
a3[2] = (DWORD)(int)120.0f;
LogMessage (LogLevel::DEBUG, "AcquireMostCompatibleDisplayMode {:d} {:d} {:f} {:f}", a3[0], a3[1], (float)(int)a3[2], (float)(int)a3[3]);
return originalAcquireMostCompatibleDisplayMode (a1, a2, a3);
}
// HOOK (DWORD*, AcquireMostCompatibleDisplayMode, ASLR (0x14064C870), i64 a1, DWORD *a2, DWORD *a3) {
// LogMessage (LogLevel::DEBUG, "AcquireMostCompatibleDisplayMode {:d} {:d} {:f} {:f}", a3[0], a3[1], (float)(int)a3[2], (float)(int)a3[3]);
// a3[2] = (DWORD)(int)120.0f;
// LogMessage (LogLevel::DEBUG, "AcquireMostCompatibleDisplayMode {:d} {:d} {:f} {:f}", a3[0], a3[1], (float)(int)a3[2], (float)(int)a3[3]);
// return originalAcquireMostCompatibleDisplayMode (a1, a2, a3);
// }

HOOK (char, SceneTestModeLoading, ASLR (0x1404793D0), u64 a1, u64 a2, u64 a3) {
LogMessage (LogLevel::DEBUG, "Begin SceneTestModeLoading");
Expand Down Expand Up @@ -534,7 +534,7 @@ Init () {
INSTALL_HOOK (EnsoGraphicManagerPreparing);
INSTALL_HOOK (EnsoGameManagerStart);
INSTALL_HOOK (EnsoGameManagerChechEnsoEnd);
INSTALL_HOOK (AcquireMostCompatibleDisplayMode);
// INSTALL_HOOK (AcquireMostCompatibleDisplayMode);
INSTALL_HOOK (SceneTestModeLoading);

// Apply common config patch
Expand Down

0 comments on commit 7039829

Please sign in to comment.