Skip to content

Commit

Permalink
ggez
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSillyDoggo committed Feb 26, 2024
1 parent 18687d6 commit bfd1e69
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 7 deletions.
36 changes: 35 additions & 1 deletion src/Client/AndroidUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,40 @@ class AndroidUI : public cocos2d::CCLayerColor {
this->removeFromParent();
}

template <class Num>
Result<Num> anumFromString(std::string_view const str, int base = 10) {
if constexpr (std::is_floating_point_v<Num>
#if defined(__cpp_lib_to_chars)
&& false
#endif
) {
Num val;
char* strEnd;
errno = 0;
if (std::setlocale(LC_NUMERIC, "C")) {
if constexpr (std::is_same_v<Num, float>) val = std::strtof(str.data(), &strEnd);
else if constexpr (std::is_same_v<Num, double>) val = std::strtod(str.data(), &strEnd);
else if constexpr (std::is_same_v<Num, long double>) val = std::strtold(str.data(), &strEnd);
if (errno == ERANGE) return Err("Number is too large to fit");
else if (strEnd == str.data()) return Err("String is not a number");
else return Ok(val);
}
else return Err("Failed to set locale");
}
else {
Num result;
std::from_chars_result res;
if constexpr (std::is_floating_point_v<Num>) res = std::from_chars(str.data(), str.data() + str.size(), result);
else res = std::from_chars(str.data(), str.data() + str.size(), result, base);

auto [_, ec] = res;
if (ec == std::errc()) return Ok(result);
else if (ec == std::errc::invalid_argument) return Err("String is not a number");
else if (ec == std::errc::result_out_of_range) return Err("Number is too large to fit");
else return Err("Unknown error");
}
}


CCAction* getEnterAction(CCNode* panel)
{
Expand All @@ -64,7 +98,7 @@ class AndroidUI : public cocos2d::CCLayerColor {
{
if (Client::GetModuleEnabled("speedhack-enabled"))
{
auto x = numFromString<float>(SpeedhackTop::instance->text);
auto x = anumFromString<float>(SpeedhackTop::instance->text);

if (x.isOk())
{
Expand Down
10 changes: 6 additions & 4 deletions src/Client/Replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ float dta;
}
};*/

class $modify (CheckpointObjectExt, CheckpointObject)
/*class $modify (CheckpointObjectExt, CheckpointObject)
{
float dt;
int frame;
Expand All @@ -45,7 +45,7 @@ class $modify (CheckpointObjectExt, CheckpointObject)
return true;
}
};/*
};*/

class $modify (PlayLayer)
{
Expand Down Expand Up @@ -92,6 +92,8 @@ class $modify (PlayLayer)
{
PlayLayer::loadFromCheckpoint(p0);

/*
GJReplayManager::dt = as<CheckpointObjectExt*>(p0)->m_fields->dt;
GJReplayManager::frame = as<CheckpointObjectExt*>(p0)->m_fields->frame;
Expand All @@ -108,7 +110,7 @@ class $modify (PlayLayer)
}
GJReplayManager::replay.inputs = myvec;
}
}*/
}
};

Expand All @@ -124,4 +126,4 @@ class $modify(GJBaseGameLayer) {

if (GJReplayManager::recording) GJReplayManager::replay.inputs.push_back(MyInput(m_gameState.m_unk1f8, button, !player1, push, plr->m_position.x, plr->m_position.y, GJReplayManager::dt, plr->m_platformerXVelocity, plr->m_yVelocity, plr->getRotation()));
}
};*/
};
2 changes: 1 addition & 1 deletion src/Client/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class Speedhack : public Window//, public TextInputDelegate
Num val;
char* strEnd;
errno = 0;
if (std::setlocale(LC_NUMERIC, /*"en_US.utf8"*/"C")) {
if (std::setlocale(LC_NUMERIC, "C")) {
if constexpr (std::is_same_v<Num, float>) val = std::strtof(str.data(), &strEnd);
else if constexpr (std::is_same_v<Num, double>) val = std::strtod(str.data(), &strEnd);
else if constexpr (std::is_same_v<Num, long double>) val = std::strtold(str.data(), &strEnd);
Expand Down
36 changes: 35 additions & 1 deletion src/Hacks/Speedhack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@ using namespace geode::prelude;

FMOD::ChannelGroup* masterGroup;

template <class Num>
Result<Num> anumFromString(std::string_view const str, int base = 10) {
if constexpr (std::is_floating_point_v<Num>
#if defined(__cpp_lib_to_chars)
&& false
#endif
) {
Num val;
char* strEnd;
errno = 0;
if (std::setlocale(LC_NUMERIC, "C")) {
if constexpr (std::is_same_v<Num, float>) val = std::strtof(str.data(), &strEnd);
else if constexpr (std::is_same_v<Num, double>) val = std::strtod(str.data(), &strEnd);
else if constexpr (std::is_same_v<Num, long double>) val = std::strtold(str.data(), &strEnd);
if (errno == ERANGE) return Err("Number is too large to fit");
else if (strEnd == str.data()) return Err("String is not a number");
else return Ok(val);
}
else return Err("Failed to set locale");
}
else {
Num result;
std::from_chars_result res;
if constexpr (std::is_floating_point_v<Num>) res = std::from_chars(str.data(), str.data() + str.size(), result);
else res = std::from_chars(str.data(), str.data() + str.size(), result, base);

auto [_, ec] = res;
if (ec == std::errc()) return Ok(result);
else if (ec == std::errc::invalid_argument) return Err("String is not a number");
else if (ec == std::errc::result_out_of_range) return Err("Number is too large to fit");
else return Err("Unknown error");
}
}

class $modify (CCScheduler)
{
void update(float dt)
Expand All @@ -24,7 +58,7 @@ class $modify (CCScheduler)
{
float v = 1.0f;

auto x = numFromString<float>(SpeedhackTop::instance->text);
auto x = anumFromString<float>(SpeedhackTop::instance->text);

if (x.isOk())
{
Expand Down

0 comments on commit bfd1e69

Please sign in to comment.