danielkrupinski / Osiris

Cross-platform game hack for Counter-Strike 2 with Panorama-based GUI.
MIT License
3.36k stars 961 forks source link

[CODE] Bomb timer #359

Closed NexSqaud closed 5 years ago

NexSqaud commented 5 years ago

misc.h

static float plantedTime = 0.0f;
    static float defusingTime = 0.0f;
    static bool plantingBomb = false;
    static bool defusingBomb = false;
    static bool haveDefusers = false;

    constexpr void bombEvents(GameEvent* event) noexcept
    {
        if (!config.misc.drawBombTimer) return;
        switch (fnv::hashRuntime(event->getName())) {
        case fnv::hash("bomb_beginplant"):
            plantingBomb = true;
            break;
        case fnv::hash("bomb_abortplant"):
            plantingBomb = false;
            break;
        case fnv::hash("bomb_planted"):
            plantedTime = memory.globalVars->currenttime;
            plantingBomb = false;
            break;
        case fnv::hash("bomb_begindefuse"):
            defusingBomb = true;
            defusingTime = memory.globalVars->currenttime;
            haveDefusers = event->getBool("haskit");
            break;
        case fnv::hash("bomb_abortdefuse"):
            defusingTime = 0.0f;
            defusingBomb = false;
            break;
        case fnv::hash("round_start"):
        case fnv::hash("bomb_exploded"):
        case fnv::hash("bomb_defused"):
            plantingBomb = false;
            defusingBomb = false;
            haveDefusers = false;
            plantedTime = 0.0f;
            defusingTime = 0.0f;
            break;
        }
    }

    static void drawTimer() noexcept
    {

        if (!interfaces.engine->isInGame()) return;
        auto local = interfaces.entityList->getEntity(interfaces.engine->getLocalPlayer());
        if (!local) return;
        static auto screen = interfaces.surface->getScreenSize();
        if (plantingBomb) {
            static auto text = interfaces.surface->getTextSize(Surface::font, L"Bomb is planting!");
            interfaces.surface->setTextFont(Surface::font);
            interfaces.surface->setTextPosition(5, (screen.second / 2) - (text.second / 2));
            if (local->getProperty<int>("m_iTeamNum") == 3) {
                interfaces.surface->setTextColor(255, 0, 0, 255);
            }
            else {
                interfaces.surface->setTextColor(0, 255, 0, 255);
            }
            interfaces.surface->printText(L"Bomb is planting!");
        }
        if (plantedTime > 0.0f) {
            float blowTime = plantedTime + interfaces.cvar->findVar("mp_c4timer")->getInt();
            float timer = blowTime - memory.globalVars->currenttime;

            if (timer > 0.0000f) {
                std::wstring timerText(L"Bomb timer: ");
                timerText += std::to_wstring(timer);
                static auto textSize = interfaces.surface->getTextSize(Surface::font, timerText.c_str());
                interfaces.surface->setTextFont(Surface::font);
                interfaces.surface->setTextPosition(5, (screen.second / 2) - textSize.second);
                if (local->getProperty<int>("m_iTeamNum") == 3) {
                    interfaces.surface->setTextColor(255, 0, 0, 255);
                }
                else {
                    interfaces.surface->setTextColor(0, 255, 0, 255);
                }
                interfaces.surface->printText(timerText.c_str());
                if(defusingBomb){
                    float defusedTime = (defusingTime + (haveDefusers ? 5 : 10));
                    float defuse = defusedTime - memory.globalVars->currenttime;
                    std::wstring defuseTimer(L"Defuse timer: ");
                    defuseTimer += std::to_wstring(defuse);
                    interfaces.surface->setTextFont(Surface::font);
                    interfaces.surface->setTextPosition(5, screen.second / 2);
                    if (local->getProperty<int>("m_iTeamNum") == 3) {
                        interfaces.surface->setTextColor(0, 255, 0, 255);
                    }
                    else {
                        interfaces.surface->setTextColor(255, 0, 0, 255);
                    }
                    interfaces.surface->printText(defuseTimer.c_str());
                }
            }
        }
    }

In hooks.cpp put bombEvents outside switch-case construstion in fireEventClientSide.

NexSqaud commented 5 years ago

@deprale put this in hooks.cpp in paintTraverse

Misc::drawTimer();

near of

Esp::render();

put bombEvent like on screenshot put this

bool drawBombTimer{ false };

in config.h near of

bool watermark{ false };

put this

if(miscJson.isMember("Draw bomb timer"))misc.drawBombTimer = miscJson["Draw bomb timer"].asBool();

in config.cpp in config::load near of

if (miscJson.isMember("Watermark")) misc.watermark = miscJson["Watermark"].asBool();

put this

miscJson["Draw bomb timer"] = misc.drawBombTimer;

in config.cpp in config::save near of

miscJson["Watermark"] = misc.watermark;

and finally put this

ImGui::Checkbox("Draw bomb timer", &config.misc.drawBombTimer);

in gui.cpp near of

ImGui::Checkbox("Watermark", &config.misc.watermark);
piterxyz commented 5 years ago

Thanks

OzymoGit commented 5 years ago

Got errors https://imgur.com/a/WEVmByM

NexSqaud commented 5 years ago

Oh, i forgot about that. gameevent.h in GameEvent class

constexpr auto getBool(const char* keyName) noexcept
    {
        return callVirtualMethod<bool, const char*, bool>(this, 5, keyName, false);
    }

and check includes in top of misc.h

#include "../Memory.h"
#include "../Interfaces.h"
#include "../SDK/FrameStage.h"
#include "../SDK/UserCmd.h"
#include "../SDK/WeaponId.h"
#include "../SDK/NetworkChannel.h"
#include "../SDK/Entity.h"
#include "../SDK/Client.h"
#include "../SDK/GameEvent.h"
#include "../SDK/GlobalVars.h"
#include "../SDK/Surface.h"
#include "../SDK/ConVar.h"
#include "../SDK/Cvar.h"
KyleIsDork commented 5 years ago

I'm an idiot, can someone provide screenshots for this? .-.

TIA, if not its fine I just don't know exactly what to do

piterxyz commented 5 years ago

I'm an idiot, can someone provide screenshots for this? .-.

TIA, if not its fine I just don't know exactly what to do

Everything is very well explained.

NexSqaud commented 5 years ago

@KyleIsDork t team: https://imgur.com/a/srnCVIx ct team: https://imgur.com/a/DEPJMo4

KyleIsDork commented 5 years ago

Thank you! @NexSqaud :D

KyleIsDork commented 5 years ago

I'll have to wait until someone compiles this for me :p hope Daniel incorporates it himself because I get 100+ errors. Thank you for your work though!

danielkrupinski commented 5 years ago

I think you can also get bombsite the bomb is being planted at.

NexSqaud commented 5 years ago

Bombsite index is different on all maps.

NexSqaud commented 5 years ago

I checked indexes on some maps:

Mirage:
A - 425
B - 426

Inferno:
A - 333
B - 422

Overpass:
A - 79
B - 507

Dust II:
A - 278
B - 279

Cobblestone:
A - 216
B - 107

Cache:
A - 317
B - 318

Train:
A - 93
B - 538

Nuke:
A - 153
B - 404

Vertigo:
A - 223
B - 278

The bombsite B index is usually greater than the bombsite A index, but not on cobblestone. Although cobblestone is still not in the MM map pool

OzymoGit commented 5 years ago

What about C4 damage prediction , I think it base on the distant from player to the bomb ( Vertigo has small bomb range )

deprale commented 5 years ago

https://i.imgur.com/kvtridR.png

@NexSqaud Did everything you said :s

OzymoGit commented 5 years ago

https://i.imgur.com/kvtridR.png

@NexSqaud Did everything you said :s

In misc.h Put the code in namespace misc, dont paste it outside

ghost commented 5 years ago

thanks @NexSqaud this post and your comments worked perfectly!

deprale commented 5 years ago

https://i.imgur.com/kvtridR.png @NexSqaud Did everything you said :s

In misc.h Put the code in namespace misc, dont paste it outside

Thanks bro, figured it out now.

I'm dumb! XD

EDIT: https://i.imgur.com/Y7RoZzO.png

2nd EDIT: Nvm I'm an idiot, I should have pasted everything into the namespace misc thingy. I just realised I can't even paste. lol.

ghost commented 5 years ago

I think you can also get bombsite the bomb is being planted at.

With radar hack on, the player can see where the bomb is planted.

sirxsniper commented 5 years ago

@NexSqaud i put everything you said. I don`t get any errors but is not showing me anything in game... any ideeas why?

Edit1: Now is showing the time but is not showing "Bomb is planting" or "Defuse time"

ghost commented 5 years ago

It works, but when the players aborts the bomb planting, the message still there. When this happened to me, the player aborted the bomb planting in the round restart delay time.

sirxsniper commented 5 years ago

For me is not showing Bomb is planting, is not show Defuse time.

NexSqaud commented 5 years ago

Make sure you correctly copied all variables and functions and you calling it right.

sirxsniper commented 5 years ago

I triple check them... If i replace this plantingBomb = false; defusingBomb = false; haveDefusers = false; with True, its showing just Bomb is planting and the time is bugged and is not dessapear after is defused or planted etc. So clearly is a problem somewhere and i dont understand where...

The code is put in misc.h after before last '}' .

NexSqaud commented 5 years ago

plantingBomb, defusingBomb and haveDefusers must be false. Check in hooks.cpp in fireEventClientSide you calling Misc::bombEvents() outside switch-case construction

sirxsniper commented 5 years ago

i have it like this


case fnv::hash("player_hurt"):
        Misc::playHitSound(event);
        Visuals::hitMarker(event);
        break;
    }
    Misc::bombEvents(event);
    return hooks.gameEventManager.callOriginal<bool, GameEvent*>(9, event);
NexSqaud commented 5 years ago

Idk, all works perfectly for me.

sirxsniper commented 5 years ago

for me dont... i dont understand why... i recheck it 3/4 times... can you upload your files to see the difference between them? thank you very much.

NexSqaud commented 5 years ago

misc.h hooks.cpp gameevent.h

sirxsniper commented 5 years ago

I swear i have everything like you... but is not showing me just the c4 timer after is planted is not showing me Bomb is planting, bomb is defusing etc....

NexSqaud commented 5 years ago

Where you testing? On community servers or official servers?

sirxsniper commented 5 years ago

Insecure, bots practice 😬 wingman/casual (offline with bots.)

NexSqaud commented 5 years ago

I tested with bots too.

sirxsniper commented 5 years ago

I dont know man... i dont get any errors in vs... and in game is just showing me the time after you plant the bomb... but i dont get the messages when somebody is trying to defuse or to plant

ghost commented 5 years ago

@NexSqaud I get the same problem as @cojo1989

kschou95 commented 5 years ago

@NexSqaud i got these errors

https://imgur.com/a/BGpb4w6

mercyples commented 5 years ago

It works perfectly for me why are you guys getting errors?

NexSqaud commented 5 years ago

@kschou95 you just copied my hooks.cpp? I have some unneeded stuff in this.

OzymoGit commented 5 years ago

@kschou95 you just copied my hooks.cpp? I have some unneeded stuff in this.

wow I models changer is sick, can u share it on your repositories ?

NexSqaud commented 5 years ago

@tirziz now it crash game.