Skip to content

Commit

Permalink
Allow response curve to be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Oct 11, 2024
1 parent 3d6db8a commit 190a5c1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
2 changes: 1 addition & 1 deletion src/game_cyberpunk2077.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/game_gta5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
}
Expand Down
40 changes: 40 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include <iostream>

#include <soup/filesystem.hpp>
#include <soup/json.hpp>
#include <soup/Process.hpp>
#include <soup/ResponseCurve.hpp>
#include <soup/string.hpp>

#include "common.hpp"
#include "game_cyberpunk2077.hpp"
Expand All @@ -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(*)();

Expand Down Expand Up @@ -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<float>(jPoint.asObj().at("x").toFloat()),
static_cast<float>(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()
Expand Down

0 comments on commit 190a5c1

Please sign in to comment.