Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
add "Respawn Delay"
Browse files Browse the repository at this point in the history
  • Loading branch information
Prevter committed Mar 19, 2024
1 parent feed018 commit 902c834
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
4 changes: 4 additions & 0 deletions resources/hacks/level.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@
{
"type": "embedded",
"hack": "hitboxes"
},
{
"type": "embedded",
"hack": "respawn_delay"
}
]
}
2 changes: 2 additions & 0 deletions src/shared/hacks/hacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "random-seed/random-seed.hpp"
#include "menu-gameplay/menu-gameplay.hpp"
#include "hitboxes/hitboxes.hpp"
#include "respawn-delay/respawn-delay.hpp"

namespace openhack::hacks {
void ToggleComponent::onInit() {
Expand Down Expand Up @@ -243,6 +244,7 @@ namespace openhack::hacks {
new RandomSeed(),
new MenuGameplay(),
new Hitboxes(),
new RespawnDelay(),
};

std::vector<EmbeddedHack *> embeddedHacksCopy = embeddedHacks;
Expand Down
53 changes: 53 additions & 0 deletions src/shared/hacks/respawn-delay/respawn-delay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "respawn-delay.hpp"
#include "../../menu/menu.hpp"

namespace openhack::hacks {

float RespawnDelay::delay = 0.5f;
static ToggleComponent* s_respawnDelay = nullptr;

inline void togglePatch() {
if (!s_respawnDelay) return;
bool enabled = config::get<bool>("hack.respawn_delay.enabled");
s_respawnDelay->applyPatch(enabled);
}

void RespawnDelay::onInit() {
// Set default values
config::setIfEmpty("hack.respawn_delay.enabled", false);
config::setIfEmpty("hack.respawn_delay.delay", 0.5f);
delay = config::get<float>("hack.respawn_delay.delay");

// Initialize toggle
std::vector<gd::sigscan::Opcode> opcodes = gd::sigscan::match(
"F30F1005^????68????C6",
utils::bytesToHex(utils::getBytes((uintptr_t)&delay)));
auto customBypass = gd::sigscan::match("84C0^7410F30F10", "EB");

if (opcodes.empty() || customBypass.empty()) {
L_WARN("Failed to find signature for RespawnDelay");
return;
}

opcodes.push_back(customBypass[0]);
s_respawnDelay = new ToggleComponent("", "", opcodes);
togglePatch();
}

void RespawnDelay::onDraw() {
gui::callback([](){
gui::tooltip("Allows you to change the default respawn time");
});
if (gui::toggleSetting("Respawn Delay", "hack.respawn_delay.enabled", []() {
gui::width(100);
if (gui::inputFloat("Delay", "hack.respawn_delay.delay", 0.0f, FLT_MAX, "%.3f sec.")) {
delay = config::get<float>("hack.respawn_delay.delay");
}
gui::tooltip("The delay before respawning");
gui::width();
}, ImVec2(0, 0))) {
togglePatch();
}
}

}
21 changes: 21 additions & 0 deletions src/shared/hacks/respawn-delay/respawn-delay.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "../hacks.hpp"

namespace openhack::hacks {

/// @brief Allows to change default respawn time
class RespawnDelay : public EmbeddedHack {
public:
RespawnDelay() : EmbeddedHack("Respawn Delay", "respawn_delay") {}

void onInit() override;
void onDraw() override;
void update() override {}
bool isCheating() override { return false; }

public:
static float delay;
};

}
9 changes: 9 additions & 0 deletions src/shared/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,15 @@ namespace openhack::utils {
return (uintptr_t) strtol(hexCopy.c_str(), nullptr, 16);
}

/// @brief Convert a value to a vector of bytes.
/// @tparam T The type of the value.
/// @param value The value.
/// @return The vector of bytes.
template <typename T>
inline std::vector<uint8_t> getBytes(T value) {
return std::vector<uint8_t>((uint8_t *) &value, (uint8_t *) &value + sizeof(T));
}

/// @brief Convert a vector of bytes to a string of hex characters.
/// @param bytes The vector of bytes.
/// @return The string of hex characters.
Expand Down

6 comments on commit 902c834

@Rustring
Copy link

@Rustring Rustring commented on 902c834 Mar 20, 2024

Choose a reason for hiding this comment

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

Please Gimme the .geode file I don't want to build myself cuz windows is so slow

@Rustring
Copy link

Choose a reason for hiding this comment

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

@Prevter

Please Gimme the .geode file I don't want to build myself cuz windows is so slow

@Prevter
Copy link
Owner Author

Choose a reason for hiding this comment

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

Please Gimme the .geode file I don't want to build myself cuz windows is so slow

https://github.com/Prevter/GDOpenHack/actions/runs/8350835798

@Rustring
Copy link

Choose a reason for hiding this comment

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

@Prevter I'd recommend that under any commit which adds a feature or fixes a bug in the comments you give a download if possible, not forcing, just an idea

@Prevter
Copy link
Owner Author

Choose a reason for hiding this comment

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

@Prevter I'd recommend that under any commit which adds a feature or fixes a bug in the comments you give a download if possible, not forcing, just an idea

Anyone can just open "Actions" tab and download builds for any commit if they want to.

@Rustring
Copy link

Choose a reason for hiding this comment

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

Oh thank you I didn't know that

Please sign in to comment.