Skip to content

Commit

Permalink
input buffer checkpoint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TobyAdd committed Oct 8, 2024
1 parent 8333b1c commit f759ab2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 26 deletions.
5 changes: 5 additions & 0 deletions src/hacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "gui.hpp"
#include "labels.hpp"
#include "replayEngine.hpp"
#include "practice_fixes.hpp"

std::filesystem::path hacks::folderShowcasesPath = hacks::folderPath / "Showcases";

Expand Down Expand Up @@ -533,7 +534,9 @@ void hacks::save(const std::vector<window>& windows, const std::filesystem::path
j["version_engine"] = engine.version_engine;

j["imgui_popup::enabled"] = imgui_popup::enabled;

j["practice_fix"] = engine.practice_fix;
j["input_buffer"] = input_buffer;

std::ofstream file(filename);
file << j.dump(4);
Expand Down Expand Up @@ -661,7 +664,9 @@ void hacks::load(const std::filesystem::path &filename, std::vector<window>& win
engine.version_engine = j.value("version_engine", 2);

imgui_popup::enabled = j.value("imgui_popup::enabled", true);

engine.practice_fix = j.value("practice_fix", true);
input_buffer = j.value("input_buffer", false);

file.close();
}
Expand Down
4 changes: 4 additions & 0 deletions src/practice_fixes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "practice_fixes.hpp"


bool input_buffer = false;
50 changes: 26 additions & 24 deletions src/practice_fixes.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "includes.hpp"

extern bool input_buffer;

struct checkpoint_data {
// cocos2d::CCNode* m_mainLayer;
bool m_wasTeleported;
Expand Down Expand Up @@ -154,11 +156,11 @@ struct checkpoint_data {
bool m_hasCustomGlowColor;
// cocos2d::ccColor3B m_glowColor;
bool m_maybeIsColliding;
// bool m_jumpBuffered;
bool m_jumpBuffered;
bool m_stateRingJump;
// bool m_wasJumpBuffered;
bool m_wasJumpBuffered;
bool m_wasRobotJump;
// unsigned char m_stateJumpBuffered;
unsigned char m_stateJumpBuffered;
bool m_stateRingJump2;
bool m_touchedRing;
bool m_touchedCustomRing;
Expand Down Expand Up @@ -188,7 +190,7 @@ struct checkpoint_data {
double m_maybeReverseSpeed;
double m_maybeReverseAcceleration;
float m_xVelocityRelated2;
// bool m_isDashing;
bool m_isDashing;
int m_unk9e8;
int m_groundObjectMaterial;
float m_vehicleSize;
Expand Down Expand Up @@ -237,8 +239,8 @@ struct checkpoint_data {
int m_maybeStateForce2;
int m_stateScale;
double m_platformerXVelocity;
// bool m_holdingRight;
// bool m_holdingLeft;
bool m_holdingRight;
bool m_holdingLeft;
bool m_leftPressedFirst;
double m_scaleXRelated;
bool m_maybeHasStopped;
Expand Down Expand Up @@ -451,11 +453,11 @@ static checkpoint_data create_checkpoint_p1(PlayLayer* self) {
result.m_hasCustomGlowColor = self->m_player1->m_hasCustomGlowColor;
// result.m_glowColor = self->m_player1->m_glowColor;
result.m_maybeIsColliding = self->m_player1->m_maybeIsColliding;
// result.m_jumpBuffered = self->m_player1->m_jumpBuffered;
result.m_jumpBuffered = self->m_player1->m_jumpBuffered;
result.m_stateRingJump = self->m_player1->m_stateRingJump;
// result.m_wasJumpBuffered = self->m_player1->m_wasJumpBuffered;
result.m_wasJumpBuffered = self->m_player1->m_wasJumpBuffered;
result.m_wasRobotJump = self->m_player1->m_wasRobotJump;
// result.m_stateJumpBuffered = self->m_player1->m_stateJumpBuffered;
result.m_stateJumpBuffered = self->m_player1->m_stateJumpBuffered;
result.m_stateRingJump2 = self->m_player1->m_stateRingJump2;
result.m_touchedRing = self->m_player1->m_touchedRing;
result.m_touchedCustomRing = self->m_player1->m_touchedCustomRing;
Expand Down Expand Up @@ -485,7 +487,7 @@ static checkpoint_data create_checkpoint_p1(PlayLayer* self) {
result.m_maybeReverseSpeed = self->m_player1->m_maybeReverseSpeed;
result.m_maybeReverseAcceleration = self->m_player1->m_maybeReverseAcceleration;
result.m_xVelocityRelated2 = self->m_player1->m_xVelocityRelated2;
// result.m_isDashing = self->m_player1->m_isDashing;
result.m_isDashing = self->m_player1->m_isDashing;
result.m_unk9e8 = self->m_player1->m_unk9e8;
result.m_groundObjectMaterial = self->m_player1->m_groundObjectMaterial;
result.m_vehicleSize = self->m_player1->m_vehicleSize;
Expand Down Expand Up @@ -534,8 +536,8 @@ static checkpoint_data create_checkpoint_p1(PlayLayer* self) {
result.m_maybeStateForce2 = self->m_player1->m_maybeStateForce2;
result.m_stateScale = self->m_player1->m_stateScale;
result.m_platformerXVelocity = self->m_player1->m_platformerXVelocity;
// result.m_holdingRight = self->m_player1->m_holdingRight;
// result.m_holdingLeft = self->m_player1->m_holdingLeft;
result.m_holdingRight = self->m_player1->m_holdingRight;
result.m_holdingLeft = self->m_player1->m_holdingLeft;
result.m_leftPressedFirst = self->m_player1->m_leftPressedFirst;
result.m_scaleXRelated = self->m_player1->m_scaleXRelated;
result.m_maybeHasStopped = self->m_player1->m_maybeHasStopped;
Expand Down Expand Up @@ -750,11 +752,11 @@ static checkpoint_data create_checkpoint_p2(PlayLayer* self) {
result.m_hasCustomGlowColor = self->m_player2->m_hasCustomGlowColor;
// result.m_glowColor = self->m_player2->m_glowColor;
result.m_maybeIsColliding = self->m_player2->m_maybeIsColliding;
// result.m_jumpBuffered = self->m_player2->m_jumpBuffered;
result.m_jumpBuffered = self->m_player2->m_jumpBuffered;
result.m_stateRingJump = self->m_player2->m_stateRingJump;
// result.m_wasJumpBuffered = self->m_player2->m_wasJumpBuffered;
result.m_wasJumpBuffered = self->m_player2->m_wasJumpBuffered;
result.m_wasRobotJump = self->m_player2->m_wasRobotJump;
// result.m_stateJumpBuffered = self->m_player2->m_stateJumpBuffered;
result.m_stateJumpBuffered = self->m_player2->m_stateJumpBuffered;
result.m_stateRingJump2 = self->m_player2->m_stateRingJump2;
result.m_touchedRing = self->m_player2->m_touchedRing;
result.m_touchedCustomRing = self->m_player2->m_touchedCustomRing;
Expand Down Expand Up @@ -784,7 +786,7 @@ static checkpoint_data create_checkpoint_p2(PlayLayer* self) {
result.m_maybeReverseSpeed = self->m_player2->m_maybeReverseSpeed;
result.m_maybeReverseAcceleration = self->m_player2->m_maybeReverseAcceleration;
result.m_xVelocityRelated2 = self->m_player2->m_xVelocityRelated2;
// result.m_isDashing = self->m_player2->m_isDashing;
result.m_isDashing = self->m_player2->m_isDashing;
result.m_unk9e8 = self->m_player2->m_unk9e8;
result.m_groundObjectMaterial = self->m_player2->m_groundObjectMaterial;
result.m_vehicleSize = self->m_player2->m_vehicleSize;
Expand Down Expand Up @@ -833,8 +835,8 @@ static checkpoint_data create_checkpoint_p2(PlayLayer* self) {
result.m_maybeStateForce2 = self->m_player2->m_maybeStateForce2;
result.m_stateScale = self->m_player2->m_stateScale;
result.m_platformerXVelocity = self->m_player2->m_platformerXVelocity;
// result.m_holdingRight = self->m_player2->m_holdingRight;
// result.m_holdingLeft = self->m_player2->m_holdingLeft;
result.m_holdingRight = self->m_player2->m_holdingRight;
result.m_holdingLeft = self->m_player2->m_holdingLeft;
result.m_leftPressedFirst = self->m_player2->m_leftPressedFirst;
result.m_scaleXRelated = self->m_player2->m_scaleXRelated;
result.m_maybeHasStopped = self->m_player2->m_maybeHasStopped;
Expand Down Expand Up @@ -1047,11 +1049,11 @@ static void apply_checkpoint(PlayerObject* player, checkpoint_data checkpoint) {
player->m_hasCustomGlowColor = checkpoint.m_hasCustomGlowColor;
// player->m_glowColor = checkpoint.m_glowColor;
player->m_maybeIsColliding = checkpoint.m_maybeIsColliding;
// player->m_jumpBuffered = checkpoint.m_jumpBuffered;
if (input_buffer) player->m_jumpBuffered = checkpoint.m_jumpBuffered;
player->m_stateRingJump = checkpoint.m_stateRingJump;
// player->m_wasJumpBuffered = checkpoint.m_wasJumpBuffered;
if (input_buffer) player->m_wasJumpBuffered = checkpoint.m_wasJumpBuffered;
player->m_wasRobotJump = checkpoint.m_wasRobotJump;
// player->m_stateJumpBuffered = checkpoint.m_stateJumpBuffered;
if (input_buffer) player->m_stateJumpBuffered = checkpoint.m_stateJumpBuffered;
player->m_stateRingJump2 = checkpoint.m_stateRingJump2;
player->m_touchedRing = checkpoint.m_touchedRing;
player->m_touchedCustomRing = checkpoint.m_touchedCustomRing;
Expand Down Expand Up @@ -1081,7 +1083,7 @@ static void apply_checkpoint(PlayerObject* player, checkpoint_data checkpoint) {
player->m_maybeReverseSpeed = checkpoint.m_maybeReverseSpeed;
player->m_maybeReverseAcceleration = checkpoint.m_maybeReverseAcceleration;
player->m_xVelocityRelated2 = checkpoint.m_xVelocityRelated2;
// player->m_isDashing = checkpoint.m_isDashing;
if (input_buffer) player->m_isDashing = checkpoint.m_isDashing;
player->m_unk9e8 = checkpoint.m_unk9e8;
player->m_groundObjectMaterial = checkpoint.m_groundObjectMaterial;
player->m_vehicleSize = checkpoint.m_vehicleSize;
Expand Down Expand Up @@ -1130,8 +1132,8 @@ static void apply_checkpoint(PlayerObject* player, checkpoint_data checkpoint) {
player->m_maybeStateForce2 = checkpoint.m_maybeStateForce2;
player->m_stateScale = checkpoint.m_stateScale;
player->m_platformerXVelocity = checkpoint.m_platformerXVelocity;
// player->m_holdingRight = checkpoint.m_holdingRight;
// player->m_holdingLeft = checkpoint.m_holdingLeft;
if (input_buffer) player->m_holdingRight = checkpoint.m_holdingRight;
if (input_buffer) player->m_holdingLeft = checkpoint.m_holdingLeft;
player->m_leftPressedFirst = checkpoint.m_leftPressedFirst;
player->m_scaleXRelated = checkpoint.m_scaleXRelated;
player->m_maybeHasStopped = checkpoint.m_maybeHasStopped;
Expand Down
14 changes: 12 additions & 2 deletions src/replayEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "hacks.hpp"
#include "gui.hpp"
#include "recorder.hpp"
#include "practice_fixes.hpp"
#include <shlobj.h>

ReplayEngine engine;
Expand Down Expand Up @@ -57,7 +58,7 @@ void ReplayEngine::handle_recording(GJBaseGameLayer* self, bool player) {
void ReplayEngine::handle_recording2(bool hold, int button, bool player) {
unsigned int frame = get_frame();

if (!replay2.empty() && hold && !replay2.back().hold && replay2.back().frame == frame) {
if (!input_buffer && !replay2.empty() && hold && !replay2.back().hold && replay2.back().frame == frame) {
replay2.pop_back();
return;
}
Expand Down Expand Up @@ -106,7 +107,7 @@ void ReplayEngine::handle_reseting(PlayLayer* self) {
if (mode == state::record) {
remove_actions(lastCheckpointFrame);

if (!replay2.empty() && replay2.back().hold) {
if (!input_buffer && !replay2.empty() && replay2.back().hold) {
handle_recording2(false, replay2.back().button, replay2.back().player);
if (version_engine == 2) {
replay2.back().frame++;
Expand Down Expand Up @@ -379,6 +380,15 @@ void ReplayEngine::render() {

ImGui::Checkbox("Practice Fix", &practice_fix);

if (practice_fix) {
ImGui::SameLine();
ImGui::Checkbox("Buffer click checkpoint (read desc)", &input_buffer);

if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Could improve accuracy in platformer levels for Engine v2\nAvoid setting checkpoints while holding the mouse to prevent double-clicks that can mess up the macro (unnecessary hold inputs)\nKeep Replay Size even to maintain Hold/Release order.\nOr perhaps it would be better to disable this fix and record platformer levels under Engine v1, which will be maintained under the accuracy fix");
}
}

ImGui::Spacing();
ImGui::Text("Replay System");
ImGui::Separator();
Expand Down

0 comments on commit f759ab2

Please sign in to comment.