From 190a5c1b1c6c6f49471315e6c44b1162f703d2c6 Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 11 Oct 2024 20:44:08 +0200 Subject: [PATCH] Allow response curve to be configured --- src/common.hpp | 1 + src/game_cyberpunk2077.cpp | 2 +- src/game_gta5.cpp | 2 +- src/main.cpp | 40 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/common.hpp b/src/common.hpp index ce0512d..3126463 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -12,4 +12,5 @@ inline wooting_analog_read_full_buffer_t wooting_analog_read_full_buffer; // Hooks +[[nodiscard]] extern float analogsense_transform_value(float value); extern void analogsense_on_input_tick(); diff --git a/src/game_cyberpunk2077.cpp b/src/game_cyberpunk2077.cpp index 6747472..025c256 100644 --- a/src/game_cyberpunk2077.cpp +++ b/src/game_cyberpunk2077.cpp @@ -68,7 +68,7 @@ static void __fastcall ContextManager_ProcessInput_detour(void* _this, float dt, std::lock_guard lock(map_mtx); for (const auto& e : map) { - *e.second = std::copysign(wooting_analog_read_analog(e.first), *e.second); + *e.second = std::copysign(analogsense_transform_value(wooting_analog_read_analog(e.first)), *e.second); } } diff --git a/src/game_gta5.cpp b/src/game_gta5.cpp index 3f78457..a4aa4ec 100644 --- a/src/game_gta5.cpp +++ b/src/game_gta5.cpp @@ -35,7 +35,7 @@ static void _fastcall rage_ioMapper_Update_detour(void* _this, unsigned int time { if (code_buffer[i] < COUNT(arr)) { - arr[code_buffer[i]] = analog_buffer[i]; + arr[code_buffer[i]] = analogsense_transform_value(analog_buffer[i]); } } } diff --git a/src/main.cpp b/src/main.cpp index 93b4fd9..5f69e50 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,10 @@ #include +#include +#include #include +#include +#include #include "common.hpp" #include "game_cyberpunk2077.hpp" @@ -9,6 +13,8 @@ static HMODULE this_lib; static HMODULE wooting_lib; +static soup::ResponseCurve curve; + using game_integration_init_t = void(*)(); using game_integration_deinit_t = void(*)(); @@ -66,11 +72,45 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID) wooting_analog_read_analog = (wooting_analog_read_analog_t)GetProcAddress(wooting_lib, "wooting_analog_read_analog"); wooting_analog_read_full_buffer = (wooting_analog_read_full_buffer_t)GetProcAddress(wooting_lib, "wooting_analog_read_full_buffer"); + { + const auto asdir = soup::filesystem::getProgramData() / "AnalogSense"; + if (!std::filesystem::exists(asdir)) + { + std::error_code ec; + std::filesystem::create_directory(asdir, ec); + } + + const auto curvefile = asdir / "curve_points.json"; + if (!std::filesystem::exists(curvefile)) + { + soup::string::toFile(curvefile, "[]"); + } + + if (auto jr = soup::json::decode(soup::string::fromFile(curvefile))) + { + for (const auto& jPoint : jr->asArr()) + { + curve.points.emplace_back( + static_cast(jPoint.asObj().at("x").toFloat()), + static_cast(jPoint.asObj().at("y").toFloat()) + ); + } + } + + std::cout << "Response curve has " << (curve.points.size() + 2) << " points." << std::endl; + } + game_integration_init(); + std::cout << "AnalogSense game integration has successfully initialised." << std::endl; } return TRUE; } +float analogsense_transform_value(float value) +{ + return curve.getY(value); +} + static int unload_counter = 0; void analogsense_on_input_tick()