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

Commit

Permalink
inner player hitbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Prevter committed Mar 27, 2024
1 parent e2c53ee commit 1fb1776
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/shared/gui/themes/gruvbox/gruvbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ namespace openhack::gui {
auto btnWidth = width > 0 ? width : ImGui::GetContentRegionAvail().x;
bool clicked = ImGui::Button(fmt::format("##{}", label).c_str(), ImVec2(btnWidth, 0));
auto buttonPos = ImGui::GetItemRectMin();
// get the text before ## if it exists
auto text = std::string(label);
auto hashPos = text.find("##");
if (hashPos != std::string::npos)
Expand Down
18 changes: 18 additions & 0 deletions src/shared/hacks/hitboxes/hitboxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ namespace openhack::hacks {
config::setIfEmpty("hack.hitboxes.solid_color", gui::Color(0, 0.247, 1));
config::setIfEmpty("hack.hitboxes.danger_color", gui::Color(1, 0, 0));
config::setIfEmpty("hack.hitboxes.player_color", gui::Color(1, 1, 0));
config::setIfEmpty("hack.hitboxes.inner_player_color", gui::Color(1, 0, 0.5f));
config::setIfEmpty("hack.hitboxes.other_color", gui::Color(0, 1, 0));

// Initialize the toggle component
Expand Down Expand Up @@ -147,6 +148,9 @@ namespace openhack::hacks {
gui::colorEdit("Player Color", "hack.hitboxes.player_color");
gui::tooltip("Color for the player hitbox.");

gui::colorEdit("Inner Player Color", "hack.hitboxes.inner_player_color");
gui::tooltip("Color for the inner player hitbox.\n(Only visible when accurate player hitbox is enabled.)");

gui::colorEdit("Other Color", "hack.hitboxes.other_color");
gui::tooltip("Color for other hitboxes (e.g. portals).");
}, ImVec2(0, 0), 140)) {
Expand Down Expand Up @@ -189,6 +193,14 @@ namespace openhack::hacks {
(const gd::cocos2d::_ccColor4F &) borderColor);
}

inline gd::cocos2d::CCRect scaleHitbox(const gd::cocos2d::CCRect &rect, float scale) {
auto width = rect.size.width * scale;
auto height = rect.size.height * scale;
auto x = rect.origin.x + (rect.size.width - width) / 2;
auto y = rect.origin.y + (rect.size.height - height) / 2;
return {x, y, width, height};
}

enum HitboxType {
Solid,
Danger,
Expand Down Expand Up @@ -263,20 +275,26 @@ namespace openhack::hacks {
auto fill = config::get<bool>("hack.hitboxes.fill", false);
auto fillAlpha = config::get<float>("hack.hitboxes.fill_alpha", 0.5f);
auto scale = config::get<float>("hack.hitboxes.scale", 1.0f);
auto innerColor = config::get<gui::Color>("hack.hitboxes.inner_player_color");
gui::Color borderColor = color;
gui::Color fillColor(color.r, color.g, color.b, fill ? fillAlpha : 0.f);
gui::Color innerFillColor(innerColor.r, innerColor.g, innerColor.b, fill ? fillAlpha : 0.f);
float borderWidth = 0.25f * scale;

auto *player1 = playLayer->m_player1();
if (player1) {
auto hitbox = getPlayerHitbox(player1);
drawRect(debugDrawNode, hitbox, fillColor, borderWidth, borderColor);
auto tinyHitbox = scaleHitbox(hitbox, player1->m_vehicleSize() >= 1.f ? 0.25f : 0.4f);
drawRect(debugDrawNode, tinyHitbox, innerFillColor, borderWidth, innerColor);
}

auto *player2 = playLayer->m_player2();
if (player2) {
auto hitbox = getPlayerHitbox(player2);
drawRect(debugDrawNode, hitbox, fillColor, borderWidth, borderColor);
auto tinyHitbox = scaleHitbox(hitbox, player2->m_vehicleSize() >= 1.f ? 0.25f : 0.4f);
drawRect(debugDrawNode, tinyHitbox, innerFillColor, borderWidth, innerColor);
}
}

Expand Down

0 comments on commit 1fb1776

Please sign in to comment.