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

Commit

Permalink
Use const std::string& and remove some hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaghettDev committed Jan 25, 2024
1 parent 3a3c493 commit 6fd61bd
Show file tree
Hide file tree
Showing 23 changed files with 241 additions and 241 deletions.
28 changes: 15 additions & 13 deletions src/DiscordRPCManager/DiscordRPCManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <Geode/modify/PlayLayer.hpp>
#include <Geode/modify/LevelEditorLayer.hpp>
#include <Geode/modify/MenuLayer.hpp>
#include <Geode/modify/EditorPauseLayer.hpp>

using namespace geode::prelude;
using namespace DiscordRPCManager;
Expand All @@ -21,12 +22,14 @@ class $modify(PlayLayer)
{
bool res = PlayLayer::init(level, unk1, unk2);
updateRPC(DiscordRPCManager::State::PLAYING_LEVEL, level);

return res;
}

void onQuit()
{
updateRPC(DiscordRPCManager::State::DEFAULT);

PlayLayer::onQuit();
}
};
Expand All @@ -36,6 +39,7 @@ class $modify(LevelEditorLayer)
bool init(GJGameLevel* level, bool unk)
{
updateRPC(DiscordRPCManager::State::EDITING_LEVEL, level);

return LevelEditorLayer::init(level, unk);
}
};
Expand All @@ -45,10 +49,21 @@ class $modify(MenuLayer)
bool init()
{
updateRPC(DiscordRPCManager::State::DEFAULT);

return MenuLayer::init();
}
};

class $modify(EditorPauseLayer)
{
void onExitEditor(CCObject* sender)
{
updateRPC(DiscordRPCManager::State::DEFAULT);

EditorPauseLayer::onExitEditor(sender);
}
};

void DiscordRPCManager::init()
{
DiscordEventHandlers handler;
Expand Down Expand Up @@ -196,16 +211,3 @@ void DiscordRPCManager::handleDiscordDisconnected(int errorCode, const char* mes
log::info("Error Code: {}", errorCode);
log::info("Message: {}", message);
}

// geode bindings pls accept my pr
void DiscordRPCManager::editorPauseLayerOnExitEditorHook(void* self, void* sender)
{
updateRPC(DiscordRPCManager::State::DEFAULT);

reinterpret_cast<void(__thiscall*)(void*, void*)>(base::get() + 0xA2EF0)(self, sender);
}

$execute
{
Mod::get()->hook(reinterpret_cast<void*>(base::get() + 0xA2EF0), &editorPauseLayerOnExitEditorHook, "EditorPauseLayer::onExitEditor", tulip::hook::TulipConvention::Thiscall);
}
2 changes: 0 additions & 2 deletions src/DiscordRPCManager/DiscordRPCManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ namespace DiscordRPCManager
void handleDiscordReady(const DiscordUser*);
void handleDiscordError(int, const char*);
void handleDiscordDisconnected(int, const char*);

void editorPauseLayerOnExitEditorHook(void*, void*);
};
12 changes: 6 additions & 6 deletions src/GUI/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class $modify(MenuLayer)
}
};

ImVec2 GUI::getJsonPosition(std::string name)
ImVec2 GUI::getJsonPosition(const std::string& name)
{
if (!windowPositions.contains(name))
{
Expand All @@ -79,13 +79,13 @@ ImVec2 GUI::getJsonPosition(std::string name)
return {windowPositions[name]["x"].get<float>(), windowPositions[name]["y"].get<float>()};
}

void GUI::setJsonPosition(std::string name, ImVec2 pos)
void GUI::setJsonPosition(const std::string& name, ImVec2 pos)
{
windowPositions[name]["x"] = pos.x;
windowPositions[name]["y"] = pos.y;
}

ImVec2 GUI::getJsonSize(std::string name, ImVec2 defaultSize)
ImVec2 GUI::getJsonSize(const std::string& name, ImVec2 defaultSize)
{
if (!windowPositions.contains(name) || !windowPositions[name].contains("w"))
{
Expand All @@ -96,7 +96,7 @@ ImVec2 GUI::getJsonSize(std::string name, ImVec2 defaultSize)
return {windowPositions[name]["w"].get<float>(), windowPositions[name]["h"].get<float>()};
}

void GUI::setJsonSize(std::string name, ImVec2 size)
void GUI::setJsonSize(const std::string& name, ImVec2 size)
{
windowPositions[name]["w"] = size.x;
windowPositions[name]["h"] = size.y;
Expand Down Expand Up @@ -297,14 +297,14 @@ void GUI::load()
f.close();
}

void GUI::saveStyle(std::string name)
void GUI::saveStyle(const std::string& name)
{
ImGuiStyle style = ImGui::GetStyle();
std::ofstream styleFile(name, std::ios::binary);
styleFile.write((const char*)&style, sizeof(ImGuiStyle));
styleFile.close();
}
void GUI::loadStyle(std::string name)
void GUI::loadStyle(const std::string& name)
{
ImGuiStyle& style = ImGui::GetStyle();
std::ifstream styleFile(name, std::ios::binary);
Expand Down
12 changes: 6 additions & 6 deletions src/GUI/GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ namespace GUI
inline bool(__thiscall* menuLayerInit)(int* self);
bool __fastcall menuLayerInitHook(int* self, void*);

ImVec2 getJsonPosition(std::string);
void setJsonPosition(std::string, ImVec2);
ImVec2 getJsonPosition(const std::string&);
void setJsonPosition(const std::string&, ImVec2);

ImVec2 getJsonSize(std::string, ImVec2 defaultSize);
void setJsonSize(std::string, ImVec2);
ImVec2 getJsonSize(const std::string&, ImVec2 defaultSize);
void setJsonSize(const std::string&, ImVec2);

void init();
void setLateInit(const std::function<void()>&func);
Expand All @@ -50,8 +50,8 @@ namespace GUI
void save();
void load();

void saveStyle(std::string name);
void loadStyle(std::string name);
void saveStyle(const std::string& name);
void loadStyle(const std::string& name);
void setStyle();

bool shouldRender();
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/Shortcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

int shortcutIndexKey = 0;

bool GUI::Shortcut::handleShortcut(std::string& name)
bool GUI::Shortcut::handleShortcut(const std::string& name)
{
if (GUI::shouldRender())
{
Expand Down
30 changes: 15 additions & 15 deletions src/GUI/Shortcut.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

namespace GUI
{
class Shortcut
{
public:
int key = 0;
std::string name;
public:
class Shortcut
{
public:
int key = 0;
std::string name;
public:

Shortcut() {}
Shortcut(int key, std::string name)
{
this->key = key;
this->name = name;
}
Shortcut() {}
Shortcut(int key, const std::string& name)
{
this->key = key;
this->name = name;
}

static bool handleShortcut(std::string&);
static void renderWindow();
};
static bool handleShortcut(const std::string&);
static void renderWindow();
};
};
34 changes: 17 additions & 17 deletions src/GUI/Widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ inline ImVec2 operator-(const ImVec2& a, const ImVec2& b)
return {a.x - b.x, a.y - b.y};
}

bool GUI::button(std::string name)
bool GUI::button(const std::string& name)
{
bool result = false;
if (GUI::shouldRender())
Expand All @@ -32,7 +32,7 @@ bool GUI::button(std::string name)
return result;
}

bool GUI::checkbox(std::string name, bool* value)
bool GUI::checkbox(const std::string& name, bool* value)
{
bool result = false;
if (GUI::shouldRender())
Expand All @@ -49,7 +49,7 @@ bool GUI::checkbox(std::string name, bool* value)
return result;
}

bool GUI::checkbox(std::string name, std::string settingName, bool default_value)
bool GUI::checkbox(const std::string& name, const std::string& settingName, bool default_value)
{
bool result = false;

Expand All @@ -72,7 +72,7 @@ bool GUI::checkbox(std::string name, std::string settingName, bool default_value
return result;
}

bool GUI::hotkey(std::string name, int* keyPointer, const ImVec2& size_arg)
bool GUI::hotkey(const std::string& name, int* keyPointer, const ImVec2& size_arg)
{
if(!shouldRender())
return false;
Expand Down Expand Up @@ -176,7 +176,7 @@ bool GUI::hotkey(std::string name, int* keyPointer, const ImVec2& size_arg)
return value_changed;
}

bool GUI::modalPopup(std::string name, const std::function<void()>& popupFunction, int flags)
bool GUI::modalPopup(const std::string& name, const std::function<void()>& popupFunction, int flags)
{
if (!GUI::isVisible || ImGui::BeginPopupModal(name.c_str(), NULL, flags) || GUI::shortcutLoop)
{
Expand All @@ -194,7 +194,7 @@ bool GUI::modalPopup(std::string name, const std::function<void()>& popupFunctio
return true;
}

bool GUI::alertPopup(std::string name, std::string content, const ButtonFunc& yesButton, const ButtonFunc& noButton,
bool GUI::alertPopup(const std::string& name, const std::string& content, const ButtonFunc& yesButton, const ButtonFunc& noButton,
int flags)
{
if (!ImGui::IsPopupOpen(name.c_str()))
Expand Down Expand Up @@ -231,7 +231,7 @@ bool GUI::alertPopup(std::string name, std::string content, const ButtonFunc& ye
return true;
}

void GUI::arrowButton(std::string popupName)
void GUI::arrowButton(const std::string& popupName)
{
if (!GUI::shouldRender())
return;
Expand All @@ -243,7 +243,7 @@ void GUI::arrowButton(std::string popupName)
ImGui::OpenPopup(popupName.c_str());
}

bool GUI::combo(std::string name, int* value, const char* const items[], int itemsCount)
bool GUI::combo(const std::string& name, int* value, const char* const items[], int itemsCount)
{
if (!GUI::shouldRender())
return false;
Expand All @@ -254,7 +254,7 @@ bool GUI::combo(std::string name, int* value, const char* const items[], int ite
return result;
}

bool GUI::inputInt(std::string name, int* value, int min, int max)
bool GUI::inputInt(const std::string& name, int* value, int min, int max)
{
bool result = false;
if (GUI::shouldRender())
Expand All @@ -272,7 +272,7 @@ bool GUI::inputInt(std::string name, int* value, int min, int max)
return result;
}

bool GUI::inputText(std::string name, std::string* value)
bool GUI::inputText(const std::string& name, std::string* value)
{
bool result = false;
if (GUI::shouldRender())
Expand All @@ -285,7 +285,7 @@ bool GUI::inputText(std::string name, std::string* value)
return result;
}

bool GUI::inputInt2(std::string name, int* value, int min1, int max1, int min2, int max2)
bool GUI::inputInt2(const std::string& name, int* value, int min1, int max1, int min2, int max2)
{
bool result = false;
if (GUI::shouldRender())
Expand All @@ -308,7 +308,7 @@ bool GUI::inputInt2(std::string name, int* value, int min1, int max1, int min2,
return result;
}

bool GUI::inputFloat(std::string name, float* value, float min, float max)
bool GUI::inputFloat(const std::string& name, float* value, float min, float max)
{
bool result = false;
if (GUI::shouldRender())
Expand All @@ -326,7 +326,7 @@ bool GUI::inputFloat(std::string name, float* value, float min, float max)
return result;
}

bool GUI::dragInt(std::string name, int* value, int min, int max)
bool GUI::dragInt(const std::string& name, int* value, int min, int max)
{
bool result = false;
if (GUI::shouldRender())
Expand All @@ -344,7 +344,7 @@ bool GUI::dragInt(std::string name, int* value, int min, int max)
return result;
}

bool GUI::dragFloat(std::string name, float* value, float min, float max)
bool GUI::dragFloat(const std::string& name, float* value, float min, float max)
{
bool result = false;
if (GUI::shouldRender())
Expand All @@ -362,7 +362,7 @@ bool GUI::dragFloat(std::string name, float* value, float min, float max)
return result;
}

bool GUI::colorEdit(std::string name, float* color, bool inputs, bool alpha)
bool GUI::colorEdit(const std::string& name, float* color, bool inputs, bool alpha)
{
if (!GUI::shouldRender())
return false;
Expand All @@ -377,7 +377,7 @@ bool GUI::colorEdit(std::string name, float* color, bool inputs, bool alpha)
return result;
}

void GUI::marker(std::string title, std::string description)
void GUI::marker(const std::string& title, const std::string& description)
{
if (!GUI::shouldRender())
return;
Expand All @@ -401,7 +401,7 @@ inline void AddUnderLine(ImColor col_)
ImGui::GetWindowDrawList()->AddLine(min, max, col_, 1.0f);
}

void GUI::textURL(std::string text, std::string link)
void GUI::textURL(const std::string& text, const std::string& link)
{
if (!GUI::shouldRender())
return;
Expand Down
Loading

0 comments on commit 6fd61bd

Please sign in to comment.