Advertisement
Guest User

Untitled

a guest
May 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.87 KB | None | 0 0
  1. #pragma once
  2. #include "singleton.hpp"
  3. #include "MiscClasses.h"
  4. #include "Interfaces.h"
  5. #include "Interface.h"
  6. #include "Logging.h"
  7. #include "bulletshow.h"
  8. #include <sstream>
  9.  
  10. #pragma comment(lib, "winmm.lib")
  11. std::vector<cbullet_tracer_info> logs;
  12.  
  13. char* HitgroupToName(int hitgroup)
  14. {
  15. switch (hitgroup)
  16. {
  17. case 1:
  18. return "head";
  19. case 2:
  20. return "chest";
  21. case 3:
  22. return "stomach";
  23. case 4:
  24. return "left arm";
  25. case 5:
  26. return "right arm";
  27. case 6:
  28. return "left leg";
  29. case 7:
  30. return "right leg";
  31. default:
  32. return "body";
  33. }
  34. }
  35.  
  36. class item_purchase
  37.  
  38. : public singleton<item_purchase>
  39. {
  40. class item_purchase_listener
  41. : public IGameEventListener2
  42. {
  43. public:
  44. void start()
  45. {
  46. g_EventManager->AddListener(this, "item_purchase", false);
  47. g_EventManager->AddListener(this, "player_hurt", false);
  48. g_EventManager->AddListener(this, "bullet_impact", false);
  49. g_EventManager->AddListener(this, "weapon_fire", false);
  50. g_EventManager->AddListener(this, "player_death", false);
  51. g_EventManager->AddListener(this, "bomb_planted", false);
  52. g_EventManager->AddListener(this, "bomb_exploded", false);
  53. g_EventManager->AddListener(this, "bomb_dropped", false);
  54. g_EventManager->AddListener(this, "bomb_defused", false);
  55. g_EventManager->AddListener(this, "bomb_begindefuse", true);
  56. g_EventManager->AddListener(this, "bomb_abortdefuse", true);
  57. g_EventManager->AddListener(this, "round_freeze_end", false);
  58. g_EventManager->AddListener(this, "round_start", false);
  59.  
  60. }
  61. void stop()
  62. {
  63. g_EventManager->RemoveListener(this);
  64. }
  65. void FireGameEvent(IGameEvent *event) override
  66. {
  67. singleton()->on_fire_event(event, false);
  68. }
  69. int GetEventDebugID(void) override
  70. {
  71. return 42;
  72. }
  73. };
  74.  
  75. public:
  76.  
  77. static item_purchase* singleton()
  78. {
  79. static item_purchase* instance = new item_purchase;
  80. return instance;
  81. }
  82.  
  83. void initialize()
  84. {
  85. listener.start();
  86. }
  87.  
  88. void remove()
  89. {
  90. listener.stop();
  91. }
  92.  
  93. void on_fire_event(IGameEvent* event, bool drawing)
  94. {
  95. static AppLog log;
  96. if (drawing)
  97. {
  98.  
  99. }
  100. else
  101. {
  102.  
  103. }
  104.  
  105. if (g_Options.Misc.player_log) {
  106. g_Engine->ClientCmd_Unrestricted("con_filter_enable 2");
  107. static auto damagefilter = g_CVar->FindVar("con_filter_text");
  108. damagefilter->SetValue("SHOCKWAVE");
  109. }
  110. else {
  111. g_Engine->ClientCmd_Unrestricted("con_filter_enable 0");
  112. }
  113.  
  114. if (!drawing) {
  115. C_BaseEntity* local = g_EntityList->GetClientEntity(g_Engine->GetLocalPlayer());
  116. if (!strcmp(event->GetName(), "item_purchase")) {
  117. auto buyer = event->GetInt("userid");
  118. std::string gun = event->GetString("weapon");
  119.  
  120. if (strstr(gun.c_str(), "molotov")
  121. || strstr(gun.c_str(), "nade")
  122. || strstr(gun.c_str(), "kevlar")
  123. || strstr(gun.c_str(), "decoy")
  124. || strstr(gun.c_str(), "suit")
  125. || strstr(gun.c_str(), "flash")
  126. || strstr(gun.c_str(), "vest")
  127. || strstr(gun.c_str(), "cutter")
  128. || strstr(gun.c_str(), "defuse")
  129. ) return;
  130.  
  131. auto player_index = g_Engine->GetPlayerForUserID(buyer);
  132. C_BaseEntity* player = (C_BaseEntity*)g_EntityList->GetClientEntity(player_index);
  133. player_info_t pinfo;
  134.  
  135. if (player && local && g_Engine->GetPlayerInfo(player_index, &pinfo)) {
  136.  
  137. gun.erase(gun.find("weapon_"), 7);
  138. if (g_Options.Misc.player_log) {
  139. if (player->GetTeamNum() == local->GetTeamNum()) {
  140. g_CVar->ConsoleColorPrintf(Color(255, 50, 50), "[SHOCKWAVE] ");
  141. g_CVar->ConsoleColorPrintf(Color(255, 255, 255), """%s bought %s\n", pinfo.name, gun.c_str());
  142. std::stringstream string;
  143. string << " " << pinfo.name << " bought " << gun.c_str();
  144. visuals::instance().events.push_front(visuals::loginfo(string.str(), Color(255, 255, 255), g_Globals->curtime));
  145.  
  146. }
  147. }
  148. }
  149. }
  150.  
  151. if (!strcmp(event->GetName(), "round_start")) {
  152. if (g_Options.Misc.player_log) {
  153. g_CVar->ConsoleColorPrintf(Color(255, 50, 50), "[SHOCKWAVE] ");
  154. g_CVar->ConsoleColorPrintf(Color(255, 255, 255), """round has been started\n");
  155. std::stringstream string;
  156. string << " round has been started ";
  157. visuals::instance().events.push_front(visuals::loginfo(string.str(), Color(255, 255, 255), g_Globals->curtime));
  158. }
  159. }
  160.  
  161. if (!strcmp(event->GetName(), "bomb_dropped")) {
  162. if (g_Options.Misc.player_log) {
  163. g_CVar->ConsoleColorPrintf(Color(255, 50, 50), "[SHOCKWAVE] ");
  164. g_CVar->ConsoleColorPrintf(Color(255, 255, 255), """bomb has been dropped\n");
  165. std::stringstream string;
  166. string << " bomb has been dropped ";
  167. visuals::instance().events.push_front(visuals::loginfo(string.str(), Color(255, 255, 255), g_Globals->curtime));
  168. }
  169. }
  170.  
  171. if (!strcmp(event->GetName(), "bomb_planted")) {
  172. if (g_Options.Misc.player_log) {
  173. g_CVar->ConsoleColorPrintf(Color(255, 50, 50), "[SHOCKWAVE] ");
  174. g_CVar->ConsoleColorPrintf(Color(255, 255, 255), """bomb has been planted\n");
  175. std::stringstream string;
  176. string << " bomb has been planted ";
  177. visuals::instance().events.push_front(visuals::loginfo(string.str(), Color(255, 255, 255), g_Globals->curtime));
  178. }
  179. }
  180.  
  181. if (!strcmp(event->GetName(), "bomb_abortdefuse")) {
  182. if (g_Options.Misc.player_log) {
  183. g_CVar->ConsoleColorPrintf(Color(255, 50, 50), "[SHOCKWAVE] ");
  184. g_CVar->ConsoleColorPrintf(Color(255, 255, 255), """defuse has been aborted\n");
  185. std::stringstream string;
  186. string << " defuse has been aborted ";
  187. visuals::instance().events.push_front(visuals::loginfo(string.str(), Color(255, 255, 255), g_Globals->curtime));
  188. }
  189. }
  190.  
  191. if (!strcmp(event->GetName(), "bomb_defused")) {
  192. if (g_Options.Misc.player_log) {
  193. g_CVar->ConsoleColorPrintf(Color(255, 50, 50), "[SHOCKWAVE] ");
  194. g_CVar->ConsoleColorPrintf(Color(255, 255, 255), """bomb has been defused\n");
  195. std::stringstream string;
  196. string << " bomb has been defused ";
  197. visuals::instance().events.push_front(visuals::loginfo(string.str(), Color(255, 255, 255), g_Globals->curtime));
  198. }
  199. }
  200.  
  201. if (!strcmp(event->GetName(), "player_hurt")) {
  202. auto bitch = event->GetInt("userid");
  203. auto coolguy49 = event->GetInt("attacker");
  204.  
  205. int entityid = g_Engine->GetPlayerForUserID(coolguy49);
  206.  
  207. auto hitbox = HitgroupToName(event->GetInt("hitgroup"));
  208. int health = event->GetInt("health");
  209. int damage = event->GetInt("dmg_health");
  210.  
  211. auto bitch_index = g_Engine->GetPlayerForUserID(bitch);
  212. auto coolguy49_index = g_Engine->GetPlayerForUserID(coolguy49);
  213. C_BaseEntity* bitch_ = (C_BaseEntity*)g_EntityList->GetClientEntity(bitch_index);
  214. C_BaseEntity* coolguy49_ = (C_BaseEntity*)g_EntityList->GetClientEntity(coolguy49_index);
  215. player_info_t killed_info = GetInfo(g_Engine->GetPlayerForUserID(bitch));
  216. player_info_t bitch_info;
  217. player_info_t coolguy49_info;
  218.  
  219. if (coolguy49_ == local) {
  220. G::hitmarkeralpha = 1.f;
  221. if (g_Options.Misc.player_log) {
  222. g_Engine->ClientCmd_Unrestricted("play buttons\\arena_switch_press_02.wav");
  223. }
  224. }
  225.  
  226. if (entityid == g_Engine->GetLocalPlayer()) {
  227. if (coolguy49 || bitch) {
  228. if (g_Options.Misc.player_log) {
  229. g_CVar->ConsoleColorPrintf(Color(255, 50, 50), "[SHOCKWAVE] ");
  230. g_CVar->ConsoleColorPrintf(Color(255, 255, 255), """hit %s in the %s for %i (%i remaining)\n", killed_info.name, hitbox, damage, health);
  231. std::stringstream string;
  232. string << " hit " << killed_info.name << " in the " << hitbox << " for " << damage << " (" << health << " remaining)";
  233. visuals::instance().events.push_front(visuals::loginfo(string.str(), Color(255, 255, 255), g_Globals->curtime));
  234. }
  235. }
  236. }
  237. }
  238.  
  239. if (!strcmp(event->GetName(), "bullet_impact")) {
  240. C_BaseEntity* LocalPlayer = g_EntityList->GetClientEntity(g_Engine->GetLocalPlayer());
  241.  
  242. if (LocalPlayer) {
  243. auto index = g_Engine->GetPlayerForUserID(event->GetInt("userid"));
  244.  
  245. if (index != g_Engine->GetLocalPlayer())
  246. return;
  247.  
  248. auto local = static_cast<C_BaseEntity*>(g_EntityList->GetClientEntity(index));
  249. if (!local)
  250. return;
  251.  
  252. Vector position(event->GetFloat("x"), event->GetFloat("y"), event->GetFloat("z"));
  253.  
  254. Ray_t ray;
  255. ray.Init(local->GetEyePosition(), position);
  256.  
  257. CTraceFilter filter;
  258. filter.pSkip = local;
  259.  
  260. trace_t tr;
  261. g_EngineTrace->TraceRay(ray, MASK_SHOT, &filter, &tr);
  262.  
  263. logs.push_back(cbullet_tracer_info(local->GetEyePosition(), position, g_Globals->curtime, 255.0f));
  264.  
  265. if (!local)
  266. return;
  267.  
  268. for (size_t i = 0; i < logs.size(); i++) {
  269. auto current = logs.at(i);
  270. current.color = Color(255, 255, 255);
  271. BeamInfo_t beamInfo;
  272. beamInfo.m_nType = TE_BEAMPOINTS;
  273. beamInfo.m_pszModelName = "sprites/physbeam.vmt";
  274. beamInfo.m_nModelIndex = -1;
  275. beamInfo.m_flHaloScale = 0.0f;
  276. beamInfo.m_flLife = 3.f;
  277. beamInfo.m_flWidth = 1.f;
  278. beamInfo.m_flEndWidth = 1.f;
  279. beamInfo.m_flFadeLength = 0.0f;
  280. beamInfo.m_flAmplitude = 2.0f;
  281. beamInfo.m_flBrightness = 155.f;
  282. beamInfo.m_flSpeed = 0.2f;
  283. beamInfo.m_nStartFrame = 0;
  284. beamInfo.m_flFrameRate = 0.f;
  285. beamInfo.m_flRed = current.color.r();
  286. beamInfo.m_flGreen = current.color.g();
  287. beamInfo.m_flBlue = current.color.b();
  288. beamInfo.m_nSegments = 2;
  289. beamInfo.m_bRenderable = true;
  290. beamInfo.m_nFlags = FBEAM_ONLYNOISEONCE | FBEAM_NOTILE | FBEAM_HALOBEAM;
  291.  
  292. beamInfo.m_vecStart = LocalPlayer->GetEyePosition();
  293. beamInfo.m_vecEnd = current.dst;
  294.  
  295. if (g_Options.Misc.player_log) {
  296. auto beam = g_pViewRenderBeams->CreateBeamPoints(beamInfo);
  297. if (beam)
  298. g_pViewRenderBeams->DrawBeam(beam);
  299. }
  300.  
  301. logs.erase(logs.begin() + i);
  302. }
  303. }
  304. }
  305. }
  306. }
  307.  
  308. private:
  309. item_purchase_listener listener;
  310. };
  311.  
  312. item_purchase purchase;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement