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

Commit

Permalink
omg, android IS real
Browse files Browse the repository at this point in the history
  • Loading branch information
Prevter committed Apr 21, 2024
1 parent 04b2780 commit eaef22b
Show file tree
Hide file tree
Showing 30 changed files with 284 additions and 119 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@
[submodule "libs/zephyrus"]
path = libs/zephyrus
url = https://github.com/Prevter/Zephyrus
[submodule "libs/sinaps"]
path = libs/sinaps
url = https://github.com/prevter/sinaps
17 changes: 14 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,28 @@ target_include_directories(
${PROJECT_NAME}
INTERFACE
${CMAKE_BINARY_DIR}
libs/glew/include
)

target_link_libraries(
${PROJECT_NAME}
INTERFACE
external_libs
opengl32
${CMAKE_SOURCE_DIR}/libs/glew/lib/Release/Win32/glew32.lib
)

if (WIN32)
# Add GLEW for Windows
target_include_directories(
${PROJECT_NAME}
INTERFACE
libs/glew/include
)
target_link_libraries(
${PROJECT_NAME}
INTERFACE
${CMAKE_SOURCE_DIR}/libs/glew/lib/Release/Win32/glew32.lib
)
endif ()

if (PROJECT_IS_TOP_LEVEL)
target_compile_definitions(${PROJECT_NAME} INTERFACE OPENHACK_EXPORT)
endif()
Expand Down
4 changes: 4 additions & 0 deletions api/openhack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
#include <string>
#include <functional>

#ifdef WIN32
#if OPENHACK_EXPORT
#define OPENHACK_DLL __declspec(dllexport)
#else
#define OPENHACK_DLL __declspec(dllimport)
#endif
#else
#define OPENHACK_DLL
#endif

#ifdef GEODE_IS_WINDOWS
#define LOG_ERROR(message) geode::log::error(message)
Expand Down
14 changes: 6 additions & 8 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,30 @@ target_include_directories(
imgui/backends
)

target_link_libraries(
imgui PUBLIC
opengl32
)

# Other libraries
add_subdirectory(gd.hpp)
add_subdirectory(json)
add_subdirectory(discord-rpc)
add_subdirectory(zephyrus)
add_subdirectory(gd.hpp)
add_subdirectory(sinaps)

# Link all external libraries
target_link_libraries(
external_libs INTERFACE
imgui
gd.hpp
nlohmann_json::nlohmann_json
discord-rpc
Zephyrus
sinaps
)

if (WIN32)
# GLFW
add_subdirectory(glfw)
add_subdirectory(discord-rpc)

target_link_libraries(
external_libs INTERFACE
glfw
discord-rpc
)
endif()
2 changes: 1 addition & 1 deletion libs/gd.hpp
1 change: 1 addition & 0 deletions libs/sinaps
Submodule sinaps added at 5c04f8
7 changes: 4 additions & 3 deletions src/geode/hooks/GJBaseGameLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ namespace openhack::hooks::GJBaseGameLayerHook {
hacks::NoclipLimit::processCommands();
reinterpret_cast<gd::GJBaseGameLayer *>(self)->processCommands();
hacks::Hitboxes::processCommands();
hacks::Zephyrus::GJBaseGameLayerProcessCommands();
ON_WINDOWS(hacks::Zephyrus::GJBaseGameLayerProcessCommands();)
}
}

namespace openhack::hooks {
struct GJBaseGameLayerHook2 : geode::Modify<GJBaseGameLayerHook2, GJBaseGameLayer> {
void update(float dt) {
hacks::FrameStepper::gameUpdate(&dt);
hacks::Display::schedulerUpdate(dt, [&](float dt) {
ON_WINDOWS(hacks::Display::schedulerUpdate(dt, [&](float dt) {
GJBaseGameLayer::update(dt);
});
});)
ON_ANDROID(GJBaseGameLayer::update(dt);)
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/geode/hooks/MainGameLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace openhack::hooks::MenuGameLayerHook {

struct MenuGameLayerHook2 : geode::Modify<MenuGameLayerHook2, MenuGameLayer> {
void update(float dt) {
hacks::MenuGameplay::menuUpdate(reinterpret_cast<gd::PlayerObject *>(m_playerObject));
// hacks::MenuGameplay::menuUpdate(reinterpret_cast<gd::PlayerObject *>(m_playerObject));
MenuGameLayer::update(dt);
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/geode/hooks/PlayLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace openhack::hooks {
hacks::AutoPickupCoins::resetLevel();
hacks::StartPosSwitcher::resetLevel();
config::setGlobal("fromPercent", getCurrentPercentInt());
hacks::Zephyrus::PlayLayerResetLevel();
ON_WINDOWS(hacks::Zephyrus::PlayLayerResetLevel();)
hacks::RandomSeed::resetLevel();
}

Expand Down Expand Up @@ -72,12 +72,12 @@ namespace openhack::hooks {
}

void playEndAnimationToPos(cocos2d::CCPoint pos) {
hacks::Zephyrus::endAnimation();
ON_WINDOWS(hacks::Zephyrus::endAnimation();)
PlayLayer::playEndAnimationToPos(pos);
}

void playPlatformerEndAnimationToPos(cocos2d::CCPoint pos, bool unk) {
hacks::Zephyrus::endAnimation();
ON_WINDOWS(hacks::Zephyrus::endAnimation();)
PlayLayer::playPlatformerEndAnimationToPos(pos, unk);
}

Expand Down
4 changes: 2 additions & 2 deletions src/geode/hooks/PlayerObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
namespace openhack::hooks {
struct PlayerObjectHook : geode::Modify<PlayerObjectHook, PlayerObject> {
void pushButton(PlayerButton btn) {
hacks::Zephyrus::PlayerObjectPushButton(reinterpret_cast<gd::PlayerObject*>(this), static_cast<int>(btn));
ON_WINDOWS(hacks::Zephyrus::PlayerObjectPushButton(reinterpret_cast<gd::PlayerObject*>(this), static_cast<int>(btn));)
hacks::Labels::pushButton(reinterpret_cast<gd::PlayerObject*>(this));
PlayerObject::pushButton(btn);
}

void releaseButton(PlayerButton btn) {
hacks::Zephyrus::PlayerObjectReleaseButton(reinterpret_cast<gd::PlayerObject*>(this), static_cast<int>(btn));
ON_WINDOWS(hacks::Zephyrus::PlayerObjectReleaseButton(reinterpret_cast<gd::PlayerObject*>(this), static_cast<int>(btn));)
hacks::Labels::releaseButton(reinterpret_cast<gd::PlayerObject*>(this));
PlayerObject::releaseButton(btn);
}
Expand Down
4 changes: 4 additions & 0 deletions src/shared/gui/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ namespace openhack::gui {
/// @return New color
static Color fromString(const char *color) {
uint32_t c;
#ifdef WIN32
sscanf_s(color, "%X", &c);
#else
sscanf(color, "%X", &c);
#endif
return fromInt(c);
}

Expand Down
2 changes: 1 addition & 1 deletion src/shared/gui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace openhack::gui {
}

void init() {
utils::resetWindowHandle();
ON_WINDOWS(utils::resetWindowHandle();)

// Load all fonts from "OPENHACK_DIRECTORY/fonts/"
auto fontDir = utils::getModFontsDirectory();
Expand Down
4 changes: 3 additions & 1 deletion src/shared/hacks/auto-deafen/auto-deafen.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "auto-deafen.hpp"
#include "../../menu/menu.hpp"

#ifdef PLATFORM_WINDOWS
#include "../accurate-percentage/accurate-percentage.hpp"

namespace openhack::hacks {
Expand Down Expand Up @@ -80,4 +81,5 @@ namespace openhack::hacks {
setState(percentage >= startPercentage && percentage <= endPercentage);
}

}
}
#endif
4 changes: 3 additions & 1 deletion src/shared/hacks/discord-rpc/discord-rpc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "discord-rpc.hpp"
#include "../../menu/menu.hpp"
#include "../labels/labels.hpp"
#ifdef PLATFORM_WINDOWS

#include <discord_rpc.h>

Expand Down Expand Up @@ -287,4 +288,5 @@ namespace openhack::hacks {
Discord_UpdatePresence(&presence);
}

}
}
#endif
10 changes: 5 additions & 5 deletions src/shared/hacks/display/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ namespace openhack::hacks {
static ToggleComponent* s_fpsLimitBypass = nullptr;

void Display::onInit() {
config::setGlobal("physicsTickAddr", gd::sigscan::findPattern("8988883B"));
config::setGlobal("physicsTickAddr", sinaps::find("8988883B"));
config::setIfEmpty("hack.display.tps", 240.0f);
config::setIfEmpty("hack.display.tps_bypass", false);

// Patch to remove minimum 60 FPS limit
auto match = gd::sigscan::match("0F2F05????^762AFF15", "9090");
if (match.empty())
L_WARN("Failed to find signature for Display");
auto match = sinaps::match("0F2F05????^762AFF15", "9090");
if (match.isErr())
L_WARN("Failed to find signature for Display: {}", match.err());
else
s_fpsLimitBypass = new ToggleComponent("", "", match);
s_fpsLimitBypass = new ToggleComponent("", "", { match.val() });

// Create window
menu::addWindow("Display", [&]() {
Expand Down
8 changes: 4 additions & 4 deletions src/shared/hacks/hack-list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ namespace openhack::hacks {
/// @brief List of all hacks.
static std::vector<EmbeddedHack*> s_allHacks = {
new SpeedHack(),
new Display(),
ON_WINDOWS(new Display(),)
new Shortcuts(),
new AutoSafemode(),
new InstantComplete(),
new AutoPickupCoins(),
new StartPosSwitcher(),
new DiscordRPC(),
ON_WINDOWS(new DiscordRPC(),)
new ClickTeleport(),
new Labels(),
new NoclipLimit(),
new RGBIcons(),
new Zephyrus(),
ON_WINDOWS(new Zephyrus(),)
new FrameStepper(),
new RandomSeed(),
new MenuGameplay(),
new Hitboxes(),
new RespawnDelay(),
new AutoDeafen(),
ON_WINDOWS(new AutoDeafen(),)
new SmartStartPos(),
new AutoKill(),
new AutoSave(),
Expand Down
56 changes: 23 additions & 33 deletions src/shared/hacks/hacks.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "hacks.hpp"
#include "../openhack.hpp"
#include <dash/sigscan.hpp>
#include "hack-list.hpp"

namespace openhack::hacks {
Expand Down Expand Up @@ -67,7 +66,7 @@ namespace openhack::hacks {
static std::vector<ToggleComponent *> hacks;

/// @brief Read an opcode from a JSON object
gd::sigscan::Opcode readOpcode(const nlohmann::json &opcode) {
sinaps::patch_t readOpcode(const nlohmann::json &opcode) {
auto addrStr = opcode.at("addr").get<std::string>();
auto onStr = opcode.at("on").get<std::string>();
auto offStr = opcode.at("off").get<std::string>();
Expand All @@ -80,10 +79,19 @@ namespace openhack::hacks {
library = opcode.at("lib").get<std::string>();
}

return {utils::hexToAddr(addrStr), library, off, on};
auto offset = utils::hexToAddr(addrStr);

auto base = utils::getModuleHandle(library.c_str());
void* address = reinterpret_cast<void *>(base + offset);

sinaps::patch_t patch(address, off, on);
patch.module = library;
patch.offset = offset;

return patch;
}

using Opcodes = std::vector<gd::sigscan::Opcode>;
using Opcodes = std::vector<sinaps::patch_t>;
using MaskMap = std::unordered_map<std::string, Opcodes>;
using PatternMap = std::unordered_map<std::string, MaskMap>;

Expand Down Expand Up @@ -183,10 +191,10 @@ namespace openhack::hacks {
nlohmann::json opcodeList;
for (const auto &opcode: opcodes) {
nlohmann::json opcodeJson;
opcodeJson["addr"] = fmt::format("0x{:X}", opcode.address);
opcodeJson["on"] = utils::bytesToHex(opcode.patched);
opcodeJson["addr"] = fmt::format("0x{:X}", (uintptr_t) opcode.address);
opcodeJson["on"] = utils::bytesToHex(opcode.patch);
opcodeJson["off"] = utils::bytesToHex(opcode.original);
opcodeJson["lib"] = opcode.library;
opcodeJson["lib"] = opcode.module;
opcodeList.push_back(opcodeJson);
}
maskMap[mask] = opcodeList;
Expand Down Expand Up @@ -231,7 +239,7 @@ namespace openhack::hacks {
PatternMap cache = tryGetCache(title);
PatternMap newCache;

L_BENCHMARK(title,
//L_BENCHMARK(title,
for (const auto &component: json.at("items")) {
if (component.contains("version")) {
auto version = component.at("version").get<std::string>();
Expand All @@ -246,7 +254,7 @@ namespace openhack::hacks {
} else if (type == "toggle") {
auto toggleTitle = component.at("title").get<std::string>();
auto id = component.at("id").get<std::string>();
std::vector<gd::sigscan::Opcode> opcodes;
std::vector<sinaps::patch_t> opcodes;
bool warn = false;
for (const auto &opcode: component.at("opcodes")) {
if (opcode.contains("version")) {
Expand Down Expand Up @@ -283,7 +291,7 @@ namespace openhack::hacks {

if (!found || !verified) {
// Scan for the addresses
opc = gd::sigscan::match(pattern, mask, library);
opc = sinaps::matchAll(pattern, mask, utils::getModule(library));
if (opc.empty()) {
warn = true;
break;
Expand Down Expand Up @@ -345,7 +353,7 @@ namespace openhack::hacks {
}
}
}
);
//);

// Sort the components
std::sort(windowComponents.begin(), windowComponents.end(), [](const auto &a, const auto &b) {
Expand Down Expand Up @@ -405,30 +413,12 @@ namespace openhack::hacks {
return s_allHacks;
}

bool applyOpcode(const gd::sigscan::Opcode &opcode, bool enable) {
uintptr_t handle;
if (opcode.library.empty()) {
handle = utils::getModuleHandle();
} else {
handle = utils::getModuleHandle(opcode.library.c_str());
}

uintptr_t address = handle + opcode.address;

std::vector<uint8_t> bytes = enable ? opcode.patched : opcode.original;
return utils::patchMemory(address, bytes);
bool applyOpcode(const sinaps::patch_t &opcode, bool enable) {
return opcode.write(enable);
}

bool verifyOpcode(const gd::sigscan::Opcode &opcode) {
uintptr_t handle;
if (opcode.library.empty()) {
handle = utils::getModuleHandle();
} else {
handle = utils::getModuleHandle(opcode.library.c_str());
}

uintptr_t address = handle + opcode.address;

bool verifyOpcode(const sinaps::patch_t &opcode) {
auto address = reinterpret_cast<uintptr_t>(opcode.address);
std::vector<uint8_t> bytes = utils::readMemory(address, opcode.original.size());
return bytes == opcode.original;
}
Expand Down
Loading

0 comments on commit eaef22b

Please sign in to comment.