Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- class IGameEvent
- {
- public:
- virtual ~IGameEvent() = 0;
- virtual const char* GetName() const = 0;
- virtual bool IsReliable() const = 0;
- virtual bool IsLocal() const = 0;
- virtual bool IsEmpty(const char* keyName = NULL) = 0;
- virtual bool GetBool(const char* keyName = NULL, bool defaultValue = false) = 0;
- virtual int GetInt(const char* keyName = NULL, int defaultValue = 0) = 0;
- virtual unsigned long GetUint64(const char* keyName = NULL, unsigned long defaultValue = 0) = 0;
- virtual float GetFloat(const char* keyName = NULL, float defaultValue = 0.0f) = 0;
- virtual const char* GetString(const char* keyName = NULL, const char* defaultValue = "") = 0;
- virtual const wchar_t* GetWString(const char* keyName, const wchar_t* defaultValue = L"") = 0;
- virtual void SetBool(const char* keyName, bool value) = 0;
- virtual void SetInt(const char* keyName, int value) = 0;
- virtual void SetUint64(const char* keyName, unsigned long value) = 0;
- virtual void SetFloat(const char* keyName, float value) = 0;
- virtual void SetString(const char* keyName, const char* value) = 0;
- virtual void SetWString(const char* keyName, const wchar_t* value) = 0;
- //const char* GetName(){
- // return CallVFunc<1, const char*>(this);
- //}
- //int GetInt(const char* szKeyName, int nDefault = 0){
- // return CallVFunc<6, int>(this, szKeyName, nDefault);
- //}
- //const char* GetString(const char* szKeyName){
- // return CallVFunc<9, const char*>(this, szKeyName, 0);
- //}
- //void SetInt(const char* szKeyName, int iValue){
- // return CallVFunc<13, void>(this, szKeyName, iValue);
- //}
- //void SetString(const char* szKeyName, const char* szValue){
- // return CallVFunc<16, void>(this, szKeyName, szValue);
- //}
- };
- class IGameEventListener {
- public:
- virtual ~IGameEventListener() {}
- virtual void FireGameEvent(IGameEvent* Event) = 0;
- virtual int GetEventDebugID() { return 42; }
- };
- class IGameEventManager2
- {
- public:
- virtual int __Unknown_1(int* dwUnknown) = 0;
- // load game event descriptions from a file eg "resource\gameevents.res"
- virtual int LoadEventsFromFile(const char* filename) = 0;
- // removes all and anything
- virtual void Reset() = 0;
- // adds a listener for a particular event
- virtual bool AddListener(IGameEventListener* listener, const char* name, bool bServerSide) = 0;
- // returns true if this listener is listens to given event
- virtual bool FindListener(IGameEventListener* listener, const char* name) = 0;
- // removes a listener
- virtual int RemoveListener(IGameEventListener* listener) = 0;
- // create an event by name, but doesn't fire it. returns NULL is event is not
- // known or no listener is registered for it. bForce forces the creation even if no listener is active
- virtual IGameEvent* CreateEvent(const char* name, bool bForce, unsigned int dwUnknown) = 0;
- // fires a server event created earlier, if bDontBroadcast is set, event is not send to clients
- virtual bool FireEvent(IGameEvent* event, bool bDontBroadcast = false) = 0;
- // fires an event for the local client only, should be used only by client code
- virtual bool FireEventClientSide(IGameEvent* event) = 0;
- // create a new copy of this event, must be free later
- virtual IGameEvent* DuplicateEvent(IGameEvent* event) = 0;
- // if an event was created but not fired for some reason, it has to bee freed, same UnserializeEvent
- virtual void FreeEvent(IGameEvent* event) = 0;
- // write/read event to/from bitbuffer
- virtual bool SerializeEvent(IGameEvent* event, bf_write* buf) = 0;
- // create new KeyValues, must be deleted
- virtual IGameEvent* UnserializeEvent(bf_read* buf) = 0;
- //IGameEvent* CreateEvents(const char *name){
- // return CallVFunc<7, IGameEvent*>(this, name, false);
- //}
- //bool FireEventClientSide(IGameEvent* pEvent){
- // return CallVFunc<9, bool>(this, pEvent);
- //}
- };
- ViewRenderBeams = *(IViewRenderBeams**)(PatternScan(cliente_mod, "A1 ? ? ? ? 56 8B F1 B9 ? ? ? ? FF 50 08") + 0x1);
- if (i_GameEventManager) {
- EventListenerHook* eventListener = new EventListenerHook();
- i_GameEventManager->AddListener(eventListener, "bullet_impact", false);
- i_GameEventManager->AddListener(eventListener, "player_death", false);
- }
- class EventListenerHook
- : public IGameEventListener
- {
- public:
- void FireGameEvent(IGameEvent* pEvent) {
- if (auto pLocalPlayer = ret_mPlayer()) {
- if (i_EngineClient->IsConnected() && i_EngineClient->IsInGame() && !_strcmp(pEvent->GetName(), "bullet_impact"))
- {
- int iUser = i_EngineClient->GetPlayerForUserID(pEvent->GetInt("userid"));
- if (auto entity = i_ClientEntityList->GetClientEntity(iUser))
- {
- float x = 0.f,
- y = 0.f,
- z = 0.f;
- x = pEvent->GetFloat("x");
- y = pEvent->GetFloat("y");
- z = pEvent->GetFloat("z");
- BulletImpact_t impact(entity, Vector3(x, y, z), i_GlobalVars->curtime, iUser == i_EngineClient->GetLocalPlayer() ? D3DCOLOR_ARGB(255, 0, 255, 0) : D3DCOLOR_ARGB(255, 255, 0, 0));
- Vars.visual.Impacts.push_back(impact);
- }
- }
- if (auto pWeap = ret_pWeapon(pLocalPlayer)) {
- if (auto cur_w = *pWeap->m_iItemDefinitionIndex()) {
- auto is_knife = IsWeaponKnife(cur_w);
- if (is_knife == true) {
- if (int nUserID = pEvent->GetInt("attacker")) {
- if (i_EngineClient->GetLocalPlayer() == i_EngineClient->GetPlayerForUserID(nUserID)) {
- if (!_strcmp(pEvent->GetName(), "player_death")) {
- pEvent->SetString("weapon", GetKillIconWeapon(cur_w));
- }
- }
- }
- }
- }
- }
- }
- }
- };
- #define getA(c) (((c)&0xff000000)>>24)
- #define getR(c) (((c)&0x00ff0000)>>16)
- #define getG(c) (((c)&0x0000ff00)>>8)
- #define getB(c) ((c)&0x000000ff)
- void DrawBulletBeams()
- {
- auto local_player = ret_mPlayer();
- if (!local_player) return;
- if (!i_EngineClient->IsInGame() || !local_player) { Vars.visual.Impacts.clear(); return; }
- if (Vars.visual.Impacts.size() > 30) Vars.visual.Impacts.pop_back();
- for (int i = 0; i < Vars.visual.Impacts.size(); i++)
- {
- auto current = Vars.visual.Impacts.at(i);
- if (auto pPlyer = current.pPlayer) {
- if (pPlyer->IsDormant() == false) {
- bool is_local_player = pPlyer == local_player;
- bool is_teammate = local_player->m_iTeamNum() == pPlyer->m_iTeamNum() && !is_local_player;
- if (pPlyer == local_player)
- current.color = D3DCOLOR_ARGB(255, 255, 255, 255);
- else if (pPlyer != local_player && !is_teammate)
- current.color = D3DCOLOR_ARGB(255, 255,10, 10);
- else if (pPlyer != local_player && is_teammate)
- current.color = D3DCOLOR_ARGB(255, 10, 255, 10);
- BeamInfo_t beamInfo;
- beamInfo.m_nType = TE_BEAMPOINTS;
- beamInfo.m_pszModelName = "sprites/purplelaser1.vmt";
- beamInfo.m_nModelIndex = -1;
- beamInfo.m_flHaloScale = 0.0f;
- beamInfo.m_flLife = 3.f;
- beamInfo.m_flWidth = 2.f;
- beamInfo.m_flEndWidth = 2.0f;
- beamInfo.m_flFadeLength = 0.0f;
- beamInfo.m_flAmplitude = 2.0f;
- beamInfo.m_flBrightness = 255.f;
- beamInfo.m_flSpeed = 0.2f;
- beamInfo.m_nStartFrame = 0;
- beamInfo.m_flFrameRate = 0.f;
- beamInfo.m_flRed = getR(current.color);
- beamInfo.m_flGreen = getG(current.color);
- beamInfo.m_flBlue = getB(current.color);
- beamInfo.m_nSegments = 2;
- beamInfo.m_bRenderable = true;
- beamInfo.m_nFlags = FBEAM_ONLYNOISEONCE | FBEAM_NOTILE | FBEAM_HALOBEAM;
- beamInfo.m_vecStart = pPlyer->GetEyePosition();
- beamInfo.m_vecEnd = current.vecImpactPos;
- if (auto beam = ViewRenderBeams->CreateBeamPoints(beamInfo))
- ViewRenderBeams->DrawBeam(beam);
- Vars.visual.Impacts.erase(Vars.visual.Impacts.begin() + i);
- }
- }
- }
- }
- if (stage == FRAME_NET_UPDATE_START)
- {
- DrawBulletBeams();
- }
- }
- struct BulletImpact_t
- {
- float flImpactTime;
- Vector3 vecImpactPos;
- D3DCOLOR color;
- IClientEntity* pPlayer;
- __forceinline BulletImpact_t()
- {
- vecImpactPos = { 0.0f, 0.0f, 0.0f };
- flImpactTime = 0.0f;
- color = D3DCOLOR_ARGB(255,255,255,255);
- pPlayer = nullptr;
- }
- __forceinline BulletImpact_t(IClientEntity* player, Vector3 pos, float time, D3DCOLOR col)
- {
- pPlayer = player;
- flImpactTime = time;
- vecImpactPos = pos;
- color = D3DCOLOR_ARGB(255, 255, 255, 255);
- }
- };
- std::deque<BulletImpact_t> Impacts;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement