Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
finished
Browse files Browse the repository at this point in the history
  • Loading branch information
huoji120 committed Oct 20, 2023
1 parent 4a5a37b commit 31a3fe5
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 247 deletions.
1 change: 0 additions & 1 deletion csgo2/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ namespace global {
float m_flUniversalTime;
float m_flLastTickedTime;
bool IsMetaModInit;
bool IsDisableBlood;
}
1 change: 0 additions & 1 deletion csgo2/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ namespace global {
extern float m_flUniversalTime;
extern float m_flLastTickedTime;
extern bool IsMetaModInit;
extern bool IsDisableBlood;
}
68 changes: 52 additions & 16 deletions csgo2/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ GameFrame_t origin_GameFrame = NULL;
CCSWeaponBase_Spawn_t origin_CCSWeaponBase_Spawn = NULL;
UTIL_SayText2Filter_t origin_UTIL_SayText2Filter = NULL;
PostEventAbstract_t origin_PostEventAbstract = NULL;

void __fastcall hook_PostEventAbstract(
void* rcx,
CSplitScreenSlot nSlot,
Expand All @@ -28,26 +29,61 @@ void __fastcall hook_PostEventAbstract(
unsigned long nSize,
NetChannelBufType_t bufType)
{
/*
if (global::IsDisableBlood == true) {
do
{
if (global::EntitySystem == nullptr) {
break;
}
if (pEvent == nullptr) {
break;
}
NetMessageInfo_t* info = pEvent->GetNetMessageInfo();
if (info) {
if (info->m_MessageId == TE_WorldDecalId)
if (info == nullptr) {
break;
}
const auto isBloodAboutMessage = (info->m_MessageId == TE_WorldDecalId || info->m_MessageId == TE_EffectDispatchId);
if (isBloodAboutMessage == false/* && isWeaponAboutMessage == false */) {
break;
}
for (uint64 i = 0; i < global::MaxPlayers; i++)
{
if (!(*(uint64*)clients & ((uint64)1 << i))) {
continue;
}

const auto pEntity = global::EntitySystem->GetBaseEntity(i);
if (pEntity == nullptr) {
continue;
}

if (pEntity->IsBasePlayerController() == false) {
continue;
}
const auto player = reinterpret_cast<CCSPlayerController*>(pEntity);

const auto [isSuccess, playerSetting] = ExtendPlayerManager::GetPlayerSettingBySteamId(player->m_steamID());
if (isSuccess == false) {
continue;
}
bool skipTheEvent = false;
if (isBloodAboutMessage) {
skipTheEvent = (playerSetting.bloodSetting == _ExtendPlayerSetting_Blood::kDisableBloodEffectDispatch && info->m_MessageId == TE_EffectDispatchId) ||
(playerSetting.bloodSetting == _ExtendPlayerSetting_Blood::kDisableBloodWorldDecal && info->m_MessageId == TE_WorldDecalId) ||
(playerSetting.bloodSetting == _ExtendPlayerSetting_Blood::kDisableBloodWorldDecalAndEffectDispatch);
}
/*
else if (isWeaponAboutMessage)
{
LOG("delete the blood in here \n");
//*(uint64_t*)clients &= ~((uint64)1 << nSlot.Get());
skipTheEvent = (playerSetting.weaponSetting == _ExtendPlayerSetting_Weapon::kDisablebulletHole);
}
*/
if (skipTheEvent) {
*(uint64*)clients &= ~((uint64)1 << i);
nClientCount--;
}
}
}
*/
if (pEvent) {
NetMessageInfo_t* info = pEvent->GetNetMessageInfo();
if (info && info->m_MessageId != 0) {
LOG("1111:%d \n", info->m_MessageId);
}
}
return origin_PostEventAbstract(rcx, nSlot, bLocalOnly, nClientCount, clients, pEvent, pData, nSize, bufType);
} while (false);
origin_PostEventAbstract(rcx, nSlot, bLocalOnly, nClientCount, clients, pEvent, pData, nSize, bufType);
}
void __fastcall hook_UTIL_SayText2Filter(
IRecipientFilter& filter, CCSPlayerController* pEntity,
Expand Down
1 change: 1 addition & 0 deletions csgo2/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ typedef void(__fastcall* UTIL_SayText2Filter_t)(IRecipientFilter&,
const char*, const char*,
const char*, const char*,
const char*);
//typedef void(__fastcall* PostEventAbstract_t)(void*, CSplitScreenSlot, bool, IRecipientFilter*, INetworkSerializable*, const void*, unsigned long);
typedef void(__fastcall* PostEventAbstract_t)(void*, CSplitScreenSlot, bool, int, const uint64_t*, INetworkSerializable*, const void*, unsigned long, NetChannelBufType_t);
namespace hooks {
extern Host_Say_t original_Host_Say;
Expand Down
2 changes: 1 addition & 1 deletion csgo2/native_sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ auto CCSPlayerPawn::GetPlayerController() -> CCSPlayerController* {
if (!pEntitySystem) {
return nullptr;
}
for (int i = 1; i <= global::MaxPlayers; ++i) {
for (int i = 0; i <= global::MaxPlayers; ++i) {
CBaseEntity* pEntity = pEntitySystem->GetBaseEntity(i);
if (!pEntity) continue;
if (pEntity->IsBasePlayerController()) {
Expand Down
57 changes: 33 additions & 24 deletions csgo2/player_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,48 +1,57 @@
#include "player_manager.h"
namespace ExtendPlayerManager {
std::shared_mutex mutex_Table_PlayerSteamIdPlayerSlot;

std::unordered_map<uint64_t, uint64_t> Table_PlayerSteamIdPlayerSlot;

std::unordered_map<uint64_t, _ExtendPlayerSetting> Table_PlayerSteamIdPlayerSlot;
//GPT error fixed;
auto SteamIDStringToUInt64(const std::string& steamID) -> uint64_t {
std::istringstream iss(
steamID.substr(3, steamID.size() - 4)); // 去掉"[U:"和"]"
std::string tmp;
uint32_t instance, account_id;

// 读取 Account Instance
std::getline(iss, tmp, ':');
instance = std::stoi(tmp);

// 读取 Account ID
std::getline(iss, tmp);
account_id = std::stoi(tmp);

// 计算并返回结果
return (uint64_t(account_id) << 1 | instance) + 76561197960265728ULL;
std::size_t pos = steamID.find_last_of(":");
if (pos != std::string::npos) {
uint64_t x = std::stoull(steamID.substr(pos + 1));
return 76561197960265728 + x;
}
return -1;
}

auto AddSteamIdToPlayerSteamIdWithNameTable(uint64_t SteamId,
uint64_t PlayerSlot) -> void {
std::unique_lock<std::shared_mutex> lock(
mutex_Table_PlayerSteamIdPlayerSlot);
Table_PlayerSteamIdPlayerSlot.insert(std::make_pair(SteamId, PlayerSlot));
Table_PlayerSteamIdPlayerSlot.insert(std::make_pair(SteamId, _ExtendPlayerSetting{.playerSlot = PlayerSlot }));
}
auto UpdatePlayerSettingBySteamId(uint64_t SteamId, _ExtendPlayerSetting setting) -> void {
std::shared_lock<std::shared_mutex> lock(
mutex_Table_PlayerSteamIdPlayerSlot);

auto it = Table_PlayerSteamIdPlayerSlot.find(SteamId);
if (it != Table_PlayerSteamIdPlayerSlot.end()) {
it->second.bloodSetting = setting.bloodSetting;
it->second.weaponSetting = setting.weaponSetting;
}
}
auto GetPlayerSettingBySteamId(uint64_t SteamId) -> std::pair<bool, _ExtendPlayerSetting> {
std::shared_lock<std::shared_mutex> lock(
mutex_Table_PlayerSteamIdPlayerSlot);

auto it = Table_PlayerSteamIdPlayerSlot.find(SteamId);
if (it != Table_PlayerSteamIdPlayerSlot.end()) {
return { true, it->second };
}
return { false, {} };
}
auto GetPlayerSlotBySteamId(uint64_t SteamId) -> uint64_t {
std::shared_lock<std::shared_mutex> lock(
mutex_Table_PlayerSteamIdPlayerSlot);

auto it = Table_PlayerSteamIdPlayerSlot.find(SteamId);
if (it != Table_PlayerSteamIdPlayerSlot.end()) {
return it->second;
return it->second.playerSlot;
}
return -1;
}
auto GetPlayerSteamIdByPlayerSlot(uint64_t playerSlot) -> uint64_t {
std::shared_lock<std::shared_mutex> lock(
mutex_Table_PlayerSteamIdPlayerSlot);
for (auto& [SteamId, PlayerSlot] : Table_PlayerSteamIdPlayerSlot) {
if (PlayerSlot == playerSlot) {
for (auto& [SteamId, PlayerSetting] : Table_PlayerSteamIdPlayerSlot) {
if (PlayerSetting.playerSlot == playerSlot) {
return SteamId;
}
}
Expand All @@ -65,7 +74,7 @@ auto GetPlayerByPlayerSlot(uint64_t playerSlot) -> CCSPlayerController* {
if (!pEntitySystem) {
return nullptr;
}
for (int i = 1; i <= global::MaxPlayers; ++i) {
for (int i = 0; i <= global::MaxPlayers; ++i) {
CBaseEntity* pEntity = pEntitySystem->GetBaseEntity(i);
if (!pEntity) continue;
if (pEntity->IsBasePlayerController()) {
Expand Down
21 changes: 21 additions & 0 deletions csgo2/player_manager.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
#pragma once
#include "head.h"
enum class _ExtendPlayerSetting_Blood
{
kNone,
kDisableBloodWorldDecal,
kDisableBloodEffectDispatch,
kDisableBloodWorldDecalAndEffectDispatch,
kMax
};
enum class _ExtendPlayerSetting_Weapon
{
kNone,
kDisablebulletHole,
kMax
};
struct _ExtendPlayerSetting {
uint64_t playerSlot;
_ExtendPlayerSetting_Blood bloodSetting;
_ExtendPlayerSetting_Weapon weaponSetting;
};
namespace ExtendPlayerManager {
auto AddSteamIdToPlayerSteamIdWithNameTable(uint64_t SteamId,
uint64_t PlayerSlot) -> void;
auto GetPlayerSlotBySteamId(uint64_t SteamId) -> uint64_t;
auto SteamIDStringToUInt64(const std::string& steamID) -> uint64_t;
auto RemovePlayerSlotBySteamId(uint64_t SteamId) -> void;
auto GetPlayerByPlayerSlot(uint64_t playerSlot) -> CCSPlayerController*;
auto UpdatePlayerSettingBySteamId(uint64_t SteamId, _ExtendPlayerSetting setting) -> void;
auto GetPlayerSettingBySteamId(uint64_t SteamId)->std::pair<bool, _ExtendPlayerSetting>;
}; // namespace ExtendPlayerManager
69 changes: 63 additions & 6 deletions csgo2/script_apis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,11 +972,68 @@ auto luaApi_GetConVarObject(lua_State* luaVm) -> int {

return 1;
}
auto luaApi_SetPlayerWeaponEffectStatus(lua_State* luaVm) -> int {
const auto playerIndex = lua_tointeger(luaVm, 1);
const auto status = lua_tointeger(luaVm, 2);
auto playerSlot = EntityIndex_to_PlayerSlot(playerIndex);
do
{
if (status >= static_cast<int>(_ExtendPlayerSetting_Weapon::kMax)
|| status < static_cast<int>(_ExtendPlayerSetting_Weapon::kNone)) {
break;
}
if (playerSlot == -1) {
break;
}
auto player = ExtendPlayerManager::GetPlayerByPlayerSlot(playerSlot);
if (player == nullptr) {
break;
}
auto [isSuccess, playerSetting] = ExtendPlayerManager::GetPlayerSettingBySteamId(player->m_steamID());
if (isSuccess == false) {
LOG("can't get player setting, wtf bug?? \n");
break;
}
ExtendPlayerManager::UpdatePlayerSettingBySteamId(player->m_steamID(), _ExtendPlayerSetting{
.bloodSetting = playerSetting.bloodSetting,
.weaponSetting = static_cast<_ExtendPlayerSetting_Weapon>(status)
});

auto luaApi_SetServerBloodStatus(lua_State* luaVm) -> int {
// param: isEnableBoold:bool
global::IsDisableBlood = !lua_toboolean(luaVm, 1);
lua_pop(luaVm, 1);
} while (false);

lua_pop(luaVm, 2);
return 0;
}
auto luaApi_SetPlayerBloodStatus(lua_State* luaVm) -> int {
const auto playerIndex = lua_tointeger(luaVm, 1);
const auto status = lua_tointeger(luaVm, 2);
auto playerSlot = EntityIndex_to_PlayerSlot(playerIndex);
do
{
if (status >= static_cast<int>(_ExtendPlayerSetting_Blood::kMax)
|| status < static_cast<int>(_ExtendPlayerSetting_Blood::kNone)) {
break;
}
if (playerSlot == -1) {
break;
}
auto player = ExtendPlayerManager::GetPlayerByPlayerSlot(playerSlot);
if (player == nullptr) {
break;
}
auto [isSuccess, playerSetting] = ExtendPlayerManager::GetPlayerSettingBySteamId(player->m_steamID());
if (isSuccess == false) {
LOG("can't get player setting, wtf bug?? \n");
break;
}
ExtendPlayerManager::UpdatePlayerSettingBySteamId(player->m_steamID(), _ExtendPlayerSetting {
.bloodSetting = static_cast<_ExtendPlayerSetting_Blood>(status),
.weaponSetting = playerSetting.weaponSetting
});

} while (false);

lua_pop(luaVm, 2);
return 0;
}
auto initFunciton(lua_State* luaVm) -> void {
Expand Down Expand Up @@ -1038,8 +1095,8 @@ auto initFunciton(lua_State* luaVm) -> void {
lua_register(luaVm, "luaApi_GetPlayerName", luaApi_GetPlayerName);
lua_register(luaVm, "luaApi_SetPlayerNameSlient",
luaApi_SetPlayerNameSlient);
lua_register(luaVm, "luaApi_SetServerBloodStatus", luaApi_SetServerBloodStatus);

//lua_register(luaVm, "luaApi_SetPlayerWeaponEffectStatus", luaApi_SetPlayerWeaponEffectStatus);
lua_register(luaVm, "luaApi_SetPlayerBloodStatus", luaApi_SetPlayerBloodStatus);
// lua_register(luaVm, "luaApi_TeleportPlayer", luaApi_TeleportPlayer);

luabridge::getGlobalNamespace(luaVm)
Expand Down
24 changes: 13 additions & 11 deletions csgo2/sdk/public/igameeventsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ typedef uint NetworkCategoryId;

enum NetChannelBufType_t
{
kFuckOffAss
BUF_RELIABLE = 0,
BUF_UNRELIABLE,
BUF_VOICE,
};

enum NetworkValidationMode_t
{
kFuckOffAss_NetworkValidationMode
Expand Down Expand Up @@ -66,7 +67,7 @@ enum NetworkSerializationMode_t
NET_SERIALIZATION_MODE_SERVER = 0x0,
NET_SERIALIZATION_MODE_CLIENT = 0x1,
};
enum ETEProtobufIds_t {
enum ETEProtobufIds : int {
TE_EffectDispatchId = 400,
TE_ArmorRicochetId = 401,
TE_BeamEntPointId = 402,
Expand All @@ -92,28 +93,29 @@ enum ETEProtobufIds_t {
TE_PhysicsPropId = 423,
TE_PlayerDecalId = 424,
TE_ProjectedDecalId = 425,
TE_SmokeId = 426
TE_SmokeId = 426,
TE_BulletHold = 452
};
class INetworkSerializable
{
public:
virtual ~INetworkSerializable() = 0;

virtual const char* GetUnscopedName() = 0;
virtual NetMessageInfo_t* GetNetMessageInfo() = 0;
virtual const char *GetUnscopedName() = 0;
virtual NetMessageInfo_t *GetNetMessageInfo() = 0;

virtual void SetMessageId(unsigned short nMessageId) = 0;

virtual void AddCategoryMask(int nMask, bool) = 0;

virtual void SwitchMode(NetworkValidationMode_t nMode) = 0;

virtual void* AllocateMessage() = 0;
virtual void DeallocateMessage(void* pMsg) = 0;
virtual void* AllocateAndCopyConstructNetMessage(void const* pOther) = 0;
virtual void *AllocateMessage() = 0;
virtual void DeallocateMessage(void *pMsg) = 0;
virtual void *AllocateAndCopyConstructNetMessage(void const *pOther) = 0;

virtual bool Serialize(bf_write& pBuf, void const* pData, NetworkSerializationMode_t unused) = 0;
virtual bool Unserialize(bf_read& pBuf, void* pData, NetworkSerializationMode_t unused) = 0;
virtual bool Serialize(bf_write &pBuf, void const *pData, NetworkSerializationMode_t unused) = 0;
virtual bool Unserialize(bf_read &pBuf, void *pData, NetworkSerializationMode_t unused) = 0;
};

class IGameEventSystem : public IAppSystem
Expand Down
1 change: 1 addition & 0 deletions csgo2/sdk/sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define INCORRECT_PATH_SEPARATOR '/'
#define INCORRECT_PATH_SEPARATOR_S "/"
#define FMTFUNCTION(a, b)
#define DLL_CLASS_IMPORT __declspec( dllimport )

enum EStringConvertErrorPolicy {
_STRINGCONVERTFLAG_SKIP = 1,
Expand Down
Loading

0 comments on commit 31a3fe5

Please sign in to comment.