From f08e0b90fac02148017f281836b6ea3645265017 Mon Sep 17 00:00:00 2001
From: Huoji's <1296564236@qq.com>
Date: Tue, 3 Oct 2023 00:25:23 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0serverfunctionhash=E5=87=BD?=
=?UTF-8?q?=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
csgo2/csgo2.vcxproj | 4 ++
csgo2/csgo2.vcxproj.filters | 12 ++++
csgo2/events.cpp | 51 ++++++++++++---
csgo2/events.h | 12 +++-
csgo2/head.h | 16 +++--
csgo2/hooks.cpp | 15 +++--
csgo2/offset.cpp | 26 +++++---
csgo2/offset.h | 5 ++
csgo2/player_manager.cpp | 43 +++++++++++--
csgo2/player_manager.h | 1 +
csgo2/script_apis.cpp | 36 +++++++++++
csgo2/script_apis.h | 5 ++
csgo2/script_callbacks.cpp | 105 +++++++++++++++++++++++++++++++
csgo2/script_callbacks.h | 22 +++++++
csgo2/script_engine.cpp | 91 +++++++++++++++++++--------
csgo2/script_engine.h | 11 +++-
csgo2/sdk/gameevent/IGameEvent.h | 6 +-
csgo2/sdk/public/eiface.h | 96 ++++++++++++++++++++++++++++
csgo2/sdk_tools.h | 2 +
csgo2/tools.cpp | 86 ++++++++++++++++---------
csgo2/tools.h | 10 +--
21 files changed, 554 insertions(+), 101 deletions(-)
create mode 100644 csgo2/script_apis.cpp
create mode 100644 csgo2/script_apis.h
create mode 100644 csgo2/script_callbacks.cpp
create mode 100644 csgo2/script_callbacks.h
diff --git a/csgo2/csgo2.vcxproj b/csgo2/csgo2.vcxproj
index 5558845..285337a 100644
--- a/csgo2/csgo2.vcxproj
+++ b/csgo2/csgo2.vcxproj
@@ -205,6 +205,7 @@
+
@@ -224,6 +225,7 @@
+
@@ -280,6 +282,8 @@
Create
+
+
diff --git a/csgo2/csgo2.vcxproj.filters b/csgo2/csgo2.vcxproj.filters
index 9951e33..3257372 100644
--- a/csgo2/csgo2.vcxproj.filters
+++ b/csgo2/csgo2.vcxproj.filters
@@ -285,6 +285,12 @@
头文件\lua
+
+ 头文件\script_engine
+
+
+ 头文件\script_engine
+
@@ -452,6 +458,12 @@
头文件\lua
+
+ 源文件\script_engine
+
+
+ 源文件\script_engine
+
diff --git a/csgo2/events.cpp b/csgo2/events.cpp
index 8b0a85e..49917c6 100644
--- a/csgo2/events.cpp
+++ b/csgo2/events.cpp
@@ -4,24 +4,59 @@ namespace events {
auto OnPlayerDeathEvent(IGameEvent* event) -> void {
UnkGameEventStruct_t userIdNameParams{"userid"};
UnkGameEventStruct_t attackerNameParams{"attacker"};
-
- const auto victim = reinterpret_cast(
+ UnkGameEventStruct_t headshotNameParams{ 0 };
+ static const auto headShotStr = "headshot";
+ headshotNameParams.m_Unk = Offset::FnServerHashFunction(headShotStr, sizeof headShotStr, SERVER_HASH_FUCNTION_KEY);
+ headshotNameParams.m_Key = headShotStr;
+ const auto victimPawn = reinterpret_cast(
event->GetPlayerPawn(&userIdNameParams));
- const auto attacker = reinterpret_cast(
+ const auto attackerPawn = reinterpret_cast(
event->GetPlayerPawn(&attackerNameParams));
-
- //printf("player[%p] %s kill[%p] %llu\n", attacker, &attacker->m_iszPlayerName(), victim, &victim->m_steamID());
+ const auto isHeadShot = event->GetBool(&headshotNameParams);
+ if (victimPawn == nullptr || attackerPawn == nullptr) {
+ return;
+ }
+ if (victimPawn->IsBasePlayerController() == false ||
+ attackerPawn->IsBasePlayerController() == false) {
+ return;
+ }
+ const auto victim = victimPawn->GetPlayerController();
+ const auto attacker = attackerPawn->GetPlayerController();
+ if (victim == nullptr || attacker == nullptr) {
+ return;
+ }
+ const auto victimIndex = victim->GetRefEHandle().m_Index;
+ const auto attackerIndex = attacker->GetRefEHandle().m_Index;
+ LOG("is head shot: %d \n", isHeadShot);
+ ScriptCallBacks::luaCall_onPlayerDeath(victimIndex, attackerIndex);
+ // printf("player[%p] %s kill[%p] %llu\n", attacker,
+ // &attacker->m_iszPlayerName(), victim, &victim->m_steamID());
}
auto OnPlayerChat(CCSPlayerController* player, std::string message) -> bool {
- auto [procesChatSuccess, chatType, chatCtx] = SdkTools::ProcessChatString(message);
+ auto [procesChatSuccess, chatType, chatCtx] =
+ SdkTools::ProcessChatString(message);
if (procesChatSuccess == false) {
return false;
}
-
- LOG("player %s say[%d]: %s steamid: %llu\n", &player->m_iszPlayerName(), chatType ,chatCtx.c_str(), player->m_steamID());
if (chatCtx.at(0) == '/' || chatCtx.at(0) == '!') {
return true;
}
return false;
}
+auto OnPlayerConnect(int slot, const char* pszName, uint64_t xuid,
+ const char* pszNetworkID, const char* pszAddress,
+ bool bFakePlayer) -> void {
+ const auto PlayerIndex = PlayerSlot_to_EntityIndex(slot);
+ ScriptCallBacks::luaCall_onPlayerConnect(PlayerIndex, slot, pszName, xuid,
+ pszNetworkID, pszAddress,
+ bFakePlayer);
+}
+auto OnPlayerDisconnect(int slot, const char* pszName, uint64_t xuid,
+ const char* pszNetworkID, const char* pszAddress,
+ bool bFakePlayer) -> void {
+ const auto PlayerIndex = PlayerSlot_to_EntityIndex(slot);
+ ScriptCallBacks::luaCall_onPlayerDisconnect(PlayerIndex, slot, pszName,
+ xuid, pszNetworkID, pszAddress,
+ bFakePlayer);
+}
} // namespace events
diff --git a/csgo2/events.h b/csgo2/events.h
index 56bcc37..9c6f845 100644
--- a/csgo2/events.h
+++ b/csgo2/events.h
@@ -2,6 +2,12 @@
#include "head.h"
class CCSPlayerController;
namespace events {
- auto OnPlayerDeathEvent(IGameEvent* event) -> void;
- auto OnPlayerChat(CCSPlayerController* player, std::string message) -> bool;
-}
+auto OnPlayerDeathEvent(IGameEvent* event) -> void;
+auto OnPlayerChat(CCSPlayerController* player, std::string message) -> bool;
+auto OnPlayerConnect(int slot, const char* pszName, uint64_t xuid,
+ const char* pszNetworkID, const char* pszAddress,
+ bool bFakePlayer) -> void;
+auto OnPlayerDisconnect(int slot, const char* pszName, uint64_t xuid,
+ const char* pszNetworkID, const char* pszAddress,
+ bool bFakePlayer) -> void;
+} // namespace events
diff --git a/csgo2/head.h b/csgo2/head.h
index 887837c..ae87c81 100644
--- a/csgo2/head.h
+++ b/csgo2/head.h
@@ -8,28 +8,30 @@
#include