Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.27 KB | None | 0 0
  1. #pragma once
  2. class IGameEvent
  3. {
  4. public:
  5.  
  6.     virtual ~IGameEvent() = 0;
  7.     virtual const char* GetName() const = 0;
  8.  
  9.     virtual bool  IsReliable() const = 0;
  10.     virtual bool  IsLocal() const = 0;
  11.     virtual bool  IsEmpty(const char* keyName = NULL) = 0;
  12.  
  13.     virtual bool  GetBool(const char* keyName = NULL, bool defaultValue = false) = 0;
  14.     virtual int   GetInt(const char* keyName = NULL, int defaultValue = 0) = 0;
  15.     virtual unsigned long GetUint64(const char* keyName = NULL, unsigned long defaultValue = 0) = 0;
  16.     virtual float GetFloat(const char* keyName = NULL, float defaultValue = 0.0f) = 0;
  17.     virtual const char* GetString(const char* keyName = NULL, const char* defaultValue = "") = 0;
  18.     virtual const wchar_t* GetWString(const char* keyName, const wchar_t* defaultValue = L"") = 0;
  19.  
  20.     virtual void SetBool(const char* keyName, bool value) = 0;
  21.     virtual void SetInt(const char* keyName, int value) = 0;
  22.     virtual void SetUint64(const char* keyName, unsigned long value) = 0;
  23.     virtual void SetFloat(const char* keyName, float value) = 0;
  24.     virtual void SetString(const char* keyName, const char* value) = 0;
  25.     virtual void SetWString(const char* keyName, const wchar_t* value) = 0;
  26.  
  27.     //const char* GetName(){
  28.     //  return CallVFunc<1, const char*>(this);
  29.     //}
  30.  
  31.     //int GetInt(const char* szKeyName, int nDefault = 0){
  32.     //  return CallVFunc<6, int>(this, szKeyName, nDefault);
  33.     //}
  34.  
  35.     //const char* GetString(const char* szKeyName){
  36.     //  return CallVFunc<9, const char*>(this, szKeyName, 0);
  37.     //}
  38.  
  39.     //void SetInt(const char* szKeyName, int iValue){
  40.     //  return CallVFunc<13, void>(this, szKeyName, iValue);
  41.     //}
  42.  
  43.     //void SetString(const char* szKeyName, const char* szValue){
  44.     //  return CallVFunc<16, void>(this, szKeyName, szValue);
  45.     //}
  46. };
  47.  
  48. class IGameEventListener {
  49. public:
  50.     virtual ~IGameEventListener() {}
  51.     virtual void FireGameEvent(IGameEvent* Event) = 0;
  52.     virtual int GetEventDebugID() { return 42; }
  53. };
  54.  
  55. class IGameEventManager2
  56. {
  57. public:
  58.  
  59.     virtual int __Unknown_1(int* dwUnknown) = 0;
  60.  
  61.     // load game event descriptions from a file eg "resource\gameevents.res"
  62.     virtual int LoadEventsFromFile(const char* filename) = 0;
  63.  
  64.     // removes all and anything
  65.     virtual void Reset() = 0;
  66.  
  67.     // adds a listener for a particular event
  68.     virtual bool AddListener(IGameEventListener* listener, const char* name, bool bServerSide) = 0;
  69.  
  70.     // returns true if this listener is listens to given event
  71.     virtual bool FindListener(IGameEventListener* listener, const char* name) = 0;
  72.  
  73.     // removes a listener
  74.     virtual int RemoveListener(IGameEventListener* listener) = 0;
  75.  
  76.     // create an event by name, but doesn't fire it. returns NULL is event is not
  77.     // known or no listener is registered for it. bForce forces the creation even if no listener is active
  78.     virtual IGameEvent* CreateEvent(const char* name, bool bForce, unsigned int dwUnknown) = 0;
  79.  
  80.     // fires a server event created earlier, if bDontBroadcast is set, event is not send to clients
  81.     virtual bool FireEvent(IGameEvent* event, bool bDontBroadcast = false) = 0;
  82.  
  83.     // fires an event for the local client only, should be used only by client code
  84.     virtual bool FireEventClientSide(IGameEvent* event) = 0;
  85.  
  86.     // create a new copy of this event, must be free later
  87.     virtual IGameEvent* DuplicateEvent(IGameEvent* event) = 0;
  88.  
  89.     // if an event was created but not fired for some reason, it has to bee freed, same UnserializeEvent
  90.     virtual void FreeEvent(IGameEvent* event) = 0;
  91.  
  92.     // write/read event to/from bitbuffer
  93.     virtual bool SerializeEvent(IGameEvent* event, bf_write* buf) = 0;
  94.  
  95.     // create new KeyValues, must be deleted
  96.     virtual IGameEvent* UnserializeEvent(bf_read* buf) = 0;
  97.     //IGameEvent* CreateEvents(const char *name){
  98.     //  return CallVFunc<7, IGameEvent*>(this, name, false);
  99.     //}
  100.  
  101.     //bool FireEventClientSide(IGameEvent* pEvent){
  102.     //  return CallVFunc<9, bool>(this, pEvent);
  103.     //}
  104. };
  105.  
  106.  
  107. ViewRenderBeams = *(IViewRenderBeams**)(PatternScan(cliente_mod, "A1 ? ? ? ? 56 8B F1 B9 ? ? ? ? FF 50 08") + 0x1);
  108.  
  109.  
  110. if (i_GameEventManager) {
  111.                             EventListenerHook* eventListener = new EventListenerHook();
  112.                             i_GameEventManager->AddListener(eventListener, "bullet_impact", false);
  113.                             i_GameEventManager->AddListener(eventListener, "player_death", false);
  114.                         }
  115.  
  116.  
  117. class EventListenerHook
  118.     : public IGameEventListener
  119. {
  120. public:
  121.     void FireGameEvent(IGameEvent* pEvent) {
  122.  
  123.         if (auto pLocalPlayer = ret_mPlayer()) {
  124.  
  125.             if (i_EngineClient->IsConnected() && i_EngineClient->IsInGame() && !_strcmp(pEvent->GetName(), "bullet_impact"))
  126.             {
  127.                 int iUser = i_EngineClient->GetPlayerForUserID(pEvent->GetInt("userid"));
  128.  
  129.                 if (auto entity = i_ClientEntityList->GetClientEntity(iUser))
  130.                 {
  131.                     float x = 0.f,
  132.                         y = 0.f,
  133.                         z = 0.f;
  134.  
  135.                     x = pEvent->GetFloat("x");
  136.                     y = pEvent->GetFloat("y");
  137.                     z = pEvent->GetFloat("z");
  138.  
  139.                     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));
  140.                     Vars.visual.Impacts.push_back(impact);
  141.                 }
  142.  
  143.             }
  144.  
  145.             if (auto pWeap = ret_pWeapon(pLocalPlayer)) {
  146.                 if (auto cur_w = *pWeap->m_iItemDefinitionIndex()) {
  147.                     auto is_knife = IsWeaponKnife(cur_w);
  148.                     if (is_knife == true) {
  149.                         if (int nUserID = pEvent->GetInt("attacker")) {
  150.                             if (i_EngineClient->GetLocalPlayer() == i_EngineClient->GetPlayerForUserID(nUserID)) {
  151.                                 if (!_strcmp(pEvent->GetName(), "player_death")) {
  152.                                     pEvent->SetString("weapon", GetKillIconWeapon(cur_w));
  153.                                 }
  154.                             }
  155.                         }
  156.                     }
  157.                 }
  158.             }
  159.            
  160.         }
  161.     }
  162. };
  163.  
  164.  
  165. #define getA(c) (((c)&0xff000000)>>24)
  166. #define getR(c) (((c)&0x00ff0000)>>16)
  167. #define getG(c) (((c)&0x0000ff00)>>8)
  168. #define getB(c) ((c)&0x000000ff)
  169.  
  170. void DrawBulletBeams()
  171. {
  172.     auto local_player = ret_mPlayer();
  173.  
  174.     if (!local_player) return;
  175.  
  176.     if (!i_EngineClient->IsInGame() || !local_player) { Vars.visual.Impacts.clear(); return; }
  177.     if (Vars.visual.Impacts.size() > 30) Vars.visual.Impacts.pop_back();
  178.  
  179.     for (int i = 0; i < Vars.visual.Impacts.size(); i++)
  180.     {
  181.         auto current = Vars.visual.Impacts.at(i);
  182.  
  183.         if (auto pPlyer = current.pPlayer) {
  184.  
  185.             if (pPlyer->IsDormant() == false) {
  186.                 bool is_local_player = pPlyer == local_player;
  187.                 bool is_teammate = local_player->m_iTeamNum() == pPlyer->m_iTeamNum() && !is_local_player;
  188.  
  189.                 if (pPlyer == local_player)
  190.                     current.color = D3DCOLOR_ARGB(255, 255, 255, 255);
  191.                 else if (pPlyer != local_player && !is_teammate)
  192.                     current.color = D3DCOLOR_ARGB(255, 255,10, 10);
  193.                 else if (pPlyer != local_player && is_teammate)
  194.                     current.color = D3DCOLOR_ARGB(255, 10, 255, 10);
  195.  
  196.                 BeamInfo_t beamInfo;
  197.                 beamInfo.m_nType = TE_BEAMPOINTS;
  198.                 beamInfo.m_pszModelName = "sprites/purplelaser1.vmt";
  199.                 beamInfo.m_nModelIndex = -1;
  200.                 beamInfo.m_flHaloScale = 0.0f;
  201.                 beamInfo.m_flLife = 3.f;
  202.                 beamInfo.m_flWidth = 2.f;
  203.                 beamInfo.m_flEndWidth = 2.0f;
  204.                 beamInfo.m_flFadeLength = 0.0f;
  205.                 beamInfo.m_flAmplitude = 2.0f;
  206.                 beamInfo.m_flBrightness = 255.f;
  207.                 beamInfo.m_flSpeed = 0.2f;
  208.                 beamInfo.m_nStartFrame = 0;
  209.                 beamInfo.m_flFrameRate = 0.f;
  210.                 beamInfo.m_flRed = getR(current.color);
  211.                 beamInfo.m_flGreen = getG(current.color);
  212.                 beamInfo.m_flBlue = getB(current.color);
  213.                 beamInfo.m_nSegments = 2;
  214.                 beamInfo.m_bRenderable = true;
  215.                 beamInfo.m_nFlags = FBEAM_ONLYNOISEONCE | FBEAM_NOTILE | FBEAM_HALOBEAM;
  216.  
  217.                 beamInfo.m_vecStart = pPlyer->GetEyePosition();
  218.                 beamInfo.m_vecEnd = current.vecImpactPos;
  219.  
  220.                 if (auto beam = ViewRenderBeams->CreateBeamPoints(beamInfo))
  221.                     ViewRenderBeams->DrawBeam(beam);
  222.  
  223.                 Vars.visual.Impacts.erase(Vars.visual.Impacts.begin() + i);
  224.  
  225.             }
  226.         }
  227.     }
  228. }
  229.  
  230. if (stage == FRAME_NET_UPDATE_START)
  231.         {
  232.             DrawBulletBeams();
  233.         }
  234. }
  235.  
  236. struct BulletImpact_t
  237. {
  238.     float           flImpactTime;
  239.     Vector3         vecImpactPos;
  240.     D3DCOLOR            color;
  241.     IClientEntity* pPlayer;
  242.  
  243.     __forceinline BulletImpact_t()
  244.     {
  245.         vecImpactPos = { 0.0f, 0.0f, 0.0f };
  246.         flImpactTime = 0.0f;
  247.         color = D3DCOLOR_ARGB(255,255,255,255);
  248.         pPlayer = nullptr;
  249.     }
  250.  
  251.     __forceinline BulletImpact_t(IClientEntity* player, Vector3 pos, float time, D3DCOLOR col)
  252.     {
  253.         pPlayer = player;
  254.         flImpactTime = time;
  255.         vecImpactPos = pos;
  256.         color = D3DCOLOR_ARGB(255, 255, 255, 255);
  257.     }
  258. };
  259.  
  260.  
  261.     std::deque<BulletImpact_t>              Impacts;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement