Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions soh/soh/Enhancements/Cheats/EasyESS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <libultraship/bridge.h>
#include <soh/OTRGlobals.h>
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#include "soh/ShipInit.hpp"
#include <cmath>

extern "C" {
extern PlayState* gPlayState;
#include "macros.h"
}

#define CVAR_EASY_ESS_NAME CVAR_CHEAT("EasyESS")
#define CVAR_EASY_ESS_DEFAULT 0
#define CVAR_EASY_ESS_VALUE CVarGetInteger(CVAR_EASY_ESS_NAME, CVAR_EASY_ESS_DEFAULT)

void OnGameStateMainStartEasyESS() {
if (!GameInteractor::IsSaveLoaded(true)) {
return;
}

Player* player = GET_PLAYER(gPlayState);
Input* input = &gPlayState->state.input[0];

if (player != nullptr && CHECK_BTN_ANY(input->cur.button, BTN_CUSTOM_MODIFIER1)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have combo system used for controls (adjusted speed etc) which should be used here

const int essValue = 18;
int x = input->cur.stick_x;
int y = input->cur.stick_y;
int magSq = x * x + y * y;
if (magSq > essValue * essValue) {
float mag = sqrtf(static_cast<float>(magSq));
input->cur.stick_x = static_cast<s8>((x / mag) * essValue);
input->cur.stick_y = static_cast<s8>((y / mag) * essValue);
input->rel.stick_x = input->cur.stick_x;
input->rel.stick_y = input->cur.stick_y;
}
}
}

void RegisterEasyESS() {
COND_HOOK(OnGameStateMainStart, CVAR_EASY_ESS_VALUE, OnGameStateMainStartEasyESS);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been considering something like an ESS slider interface to calibrate ESS range (2 sliders: a min value that gets raised into ESS range, & a max value that gets lowered into ESS range), could probably fit into this hook in future

}

static RegisterShipInitFunc initFunc(RegisterEasyESS, { CVAR_EASY_ESS_NAME });
20 changes: 16 additions & 4 deletions soh/soh/Enhancements/controls/InputViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,18 @@ void InputViewer::DrawElement() {
const bool analogStickIsInDeadzone = !pads[0].stick_x && !pads[0].stick_y;
const bool rightStickIsInDeadzone = !pads[0].right_stick_x && !pads[0].right_stick_y;

const int essValue = 18;
int stickX = pads[0].stick_x;
int stickY = pads[0].stick_y;
if ((pads[0].button & BTN_CUSTOM_MODIFIER1) && CVarGetInteger(CVAR_CHEAT("EasyESS"), 0)) {
int magSq = stickX * stickX + stickY * stickY;
if (magSq > essValue * essValue) {
float mag = sqrtf(static_cast<float>(magSq));
stickX = static_cast<int>((stickX / mag) * essValue);
stickY = static_cast<int>((stickY / mag) * essValue);
}
}

// Analog Stick
const int analogOutlineMode =
CVarGetInteger(CVAR_INPUT_VIEWER("AnalogStick.OutlineMode"), STICK_MODE_ALWAYS_SHOWN);
Expand All @@ -369,8 +381,8 @@ void InputViewer::DrawElement() {
(analogStickMode == STICK_MODE_HIDDEN_IN_DEADZONE && !analogStickIsInDeadzone)) {
ImGui::SetNextItemAllowOverlap();
ImGui::SetCursorPos(
ImVec2(aPos.x + maxStickDistance * ((float)(pads[0].stick_x) / MAX_AXIS_RANGE) * scale,
aPos.y - maxStickDistance * ((float)(pads[0].stick_y) / MAX_AXIS_RANGE) * scale));
ImVec2(aPos.x + maxStickDistance * ((float)(stickX) / MAX_AXIS_RANGE) * scale,
aPos.y - maxStickDistance * ((float)(stickY) / MAX_AXIS_RANGE) * scale));
ImGui::Image(
std::dynamic_pointer_cast<Fast::Fast3dGui>(Ship::Context::GetRawInstance()->GetWindow()->GetGui())
->GetTextureByName("Analog-Stick"),
Expand Down Expand Up @@ -415,7 +427,7 @@ void InputViewer::DrawElement() {
ImGui::PushFont(ImGui::GetFont());

// Calculate polar R coordinate from X and Y angles, squared to avoid sqrt
const int32_t rSquared = pads[0].stick_x * pads[0].stick_x + pads[0].stick_y * pads[0].stick_y;
const int32_t rSquared = stickX * stickX + stickY * stickY;

// ESS range
const int range1Min = CVarGetInteger(CVAR_INPUT_VIEWER("AnalogAngles.Range1.Min"), 8);
Expand All @@ -442,7 +454,7 @@ void InputViewer::DrawElement() {
}

// Render text
ImGui::Text("X: %-3d Y: %-3d", pads[0].stick_x, pads[0].stick_y);
ImGui::Text("X: %-3d Y: %-3d", stickX, stickY);
// Restore original color
ImGui::PopStyleColor();
// Restore original font scale
Expand Down
3 changes: 3 additions & 0 deletions soh/soh/SohGui/SohMenuEnhancements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,9 @@ void SohMenu::AddMenuEnhancements() {
AddWidget(path, "Easy QPA", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_CHEAT("EasyQPA"))
.Options(CheckboxOptions().Tooltip("Gives you the glitched damage value of the quick put away glitch."));
AddWidget(path, "Easy ESS", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_CHEAT("EasyESS"))
.Options(CheckboxOptions().Tooltip("Force ESS position while holding M1."));
AddWidget(path, "Clear Cutscene Pointer", WIDGET_BUTTON)
.Callback([](WidgetInfo& info) { GameInteractor::RawAction::ClearCutscenePointer(); })
.Options(ButtonOptions()
Expand Down