11#include " HSI.hpp"
22#include < Intro/HookGameEvents/HookGameEvents.hpp>
3+ #include < Buildup/CS2Hash/CS2Hash.hpp>
4+ #include < nlohmann/json.hpp>
35
46bool HSI::Init () {
57 this ->SubscribeSync (" Hook/FireEventClientSide/player_death" , [this ](MulNX::Message& msg) {
68 auto && [pEvent] = msg.Access <CS2 ::CGameEvent*>();
7- std::string test (" 游戏事件" );
8- this ->WebPost (test);
9+ this ->OnDeathEvent (pEvent);
10+ });
11+
12+ this ->SendTask (" Main" , " CSControl" , [this ]() {
13+ this ->Main ();
14+ return true ;
915 });
1016
1117 return true ;
18+ }
19+
20+ void HSI::OnDeathEvent (CS2 ::CGameEvent* event) {
21+ static CS2 ::CKV3MemberName attacker{ this ->CS2Hashs ->attacker , -1 , nullptr };
22+ static CS2 ::CKV3MemberName userid{ this ->CS2Hashs ->userid , -1 , nullptr };
23+ static CS2 ::CKV3MemberName assister{ this ->CS2Hashs ->assister , -1 , nullptr };
24+
25+ static CS2 ::CKV3MemberName assistedflash{ CS2Hashs->assistedflash , -1 , nullptr };
26+ static CS2 ::CKV3MemberName weapon{ CS2Hashs->weapon , -1 , nullptr };
27+ static CS2 ::CKV3MemberName headshot{ CS2Hashs->headshot , -1 , nullptr };
28+ static CS2 ::CKV3MemberName penetrated{ CS2Hashs->penetrated , -1 , nullptr };
29+ static CS2 ::CKV3MemberName noscope{ CS2Hashs->noscope , -1 , nullptr };
30+ static CS2 ::CKV3MemberName thrusmoke{ CS2Hashs->thrusmoke , -1 , nullptr };
31+ static CS2 ::CKV3MemberName attackerblind{ CS2Hashs->attackerblind , -1 , nullptr };
32+ static CS2 ::CKV3MemberName attackerinair{ CS2Hashs->attackerinair , -1 , nullptr };
33+
34+ // 读取并填充结构体
35+ KillEvent kEvent ;
36+ kEvent .assistedflash = event->GetInt (assistedflash);
37+ kEvent .headshot = event->GetInt (headshot);
38+ kEvent .penetrated = event->GetInt (penetrated);
39+ kEvent .noscope = event->GetInt (noscope);
40+ kEvent .thrusmoke = event->GetInt (thrusmoke);
41+ kEvent .attackerblind = event->GetInt (attackerblind);
42+ kEvent .attackerinair = event->GetInt (attackerinair);
43+ const char * weaponStr = event->GetString (weapon);
44+ kEvent .weapon = weaponStr ? weaponStr : " " ;
45+
46+ try {
47+ auto pAttacker = event->GetPlayerController (attacker);
48+ auto pVictim = event->GetPlayerController (userid);
49+ auto pAssister = event->GetPlayerController (assister);
50+
51+ kEvent .attacker = MulNX::MRead (pAttacker->m_steamID ());
52+ kEvent .victim = MulNX::MRead (pVictim->m_steamID ());
53+ if (pAssister)kEvent .assister = MulNX::MRead (pAssister->m_steamID ());
54+ else kEvent .assister = 0 ;
55+ }
56+ catch (MulNX::Exception& e) {
57+ this ->LogError (e);
58+ this ->LogError (" 丢失了一个击杀事件" );
59+ return ;
60+ }
61+
62+ this ->buffer .enqueue (std::move (kEvent ));
63+ }
64+
65+ void HSI::Main () {
66+ KillEvent kEvent ;
67+ if (!this ->buffer .try_dequeue (kEvent ))return ;
68+
69+ nlohmann::json j;
70+ j[" assistedflash" ] = kEvent .assistedflash ;
71+ j[" weapon" ] = kEvent .weapon ;
72+ j[" headshot" ] = kEvent .headshot ;
73+ j[" penetrated" ] = kEvent .penetrated ;
74+ j[" noscope" ] = kEvent .noscope ;
75+ j[" thrusmoke" ] = kEvent .thrusmoke ;
76+ j[" attackerblind" ] = kEvent .attackerblind ;
77+ j[" attackerinair" ] = kEvent .attackerinair ;
78+
79+ // SteamID 转为字符串,与原始 JSON 格式一致
80+ j[" attackerSteamId" ] = std::to_string (kEvent .attacker );
81+ j[" victimSteamId" ] = std::to_string (kEvent .victim );
82+ j[" assistSteamId" ] = std::to_string (kEvent .assister );
83+
84+ this ->WebPost (j.dump ());
1285}
0 commit comments