This commit is contained in:
Huoji's
2023-10-21 04:24:28 +08:00
parent 4a5a37ba95
commit 31a3fe5428
13 changed files with 192 additions and 247 deletions

View File

@@ -8,5 +8,4 @@ namespace global {
float m_flUniversalTime;
float m_flLastTickedTime;
bool IsMetaModInit;
bool IsDisableBlood;
}

View File

@@ -11,5 +11,4 @@ namespace global {
extern float m_flUniversalTime;
extern float m_flLastTickedTime;
extern bool IsMetaModInit;
extern bool IsDisableBlood;
}

View File

@@ -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,
@@ -28,26 +29,61 @@ void __fastcall hook_PostEventAbstract(
unsigned long nSize,
NetChannelBufType_t bufType)
{
/*
if (global::IsDisableBlood == true) {
NetMessageInfo_t* info = pEvent->GetNetMessageInfo();
if (info) {
if (info->m_MessageId == TE_WorldDecalId)
do
{
LOG("delete the blood in here \n");
//*(uint64_t*)clients &= ~((uint64)1 << nSlot.Get());
if (global::EntitySystem == nullptr) {
break;
}
if (pEvent == nullptr) {
break;
}
NetMessageInfo_t* info = pEvent->GetNetMessageInfo();
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)
{
skipTheEvent = (playerSetting.weaponSetting == _ExtendPlayerSetting_Weapon::kDisablebulletHole);
}
*/
if (pEvent) {
NetMessageInfo_t* info = pEvent->GetNetMessageInfo();
if (info && info->m_MessageId != 0) {
LOG("1111:%d \n", info->m_MessageId);
if (skipTheEvent) {
*(uint64*)clients &= ~((uint64)1 << i);
nClientCount--;
}
}
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,

View File

@@ -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;

View File

@@ -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()) {

View File

@@ -1,32 +1,41 @@
#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(
@@ -34,15 +43,15 @@ auto GetPlayerSlotBySteamId(uint64_t SteamId) -> uint64_t {
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;
}
}
@@ -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()) {

View File

@@ -1,5 +1,24 @@
#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;
@@ -7,4 +26,6 @@ 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

View File

@@ -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 {
@@ -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)

View File

@@ -9,9 +9,10 @@ typedef uint NetworkCategoryId;
enum NetChannelBufType_t
{
kFuckOffAss
BUF_RELIABLE = 0,
BUF_UNRELIABLE,
BUF_VOICE,
};
enum NetworkValidationMode_t
{
kFuckOffAss_NetworkValidationMode
@@ -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,
@@ -92,7 +93,8 @@ enum ETEProtobufIds_t {
TE_PhysicsPropId = 423,
TE_PlayerDecalId = 424,
TE_ProjectedDecalId = 425,
TE_SmokeId = 426
TE_SmokeId = 426,
TE_BulletHold = 452
};
class INetworkSerializable
{

View File

@@ -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,

View File

@@ -116,195 +116,15 @@ CUtlString::CUtlString(const CUtlString& string)
{
Set(string.Get());
}
// Attaches the string to external memory. Useful for avoiding a copy
CUtlString::CUtlString(void* pMemory, int nSizeInBytes, int nInitialLength) : m_Storage(pMemory, nSizeInBytes, nInitialLength)
inline const char* CUtlString::Get() const
{
}
CUtlString::CUtlString(const void* pMemory, int nSizeInBytes) : m_Storage(pMemory, nSizeInBytes)
if (!m_pString)
{
}
void CUtlString::Set(const char *pValue)
{
_UtlString_assert(!m_Storage.IsReadOnly());
int nLen = pValue ? strlen(pValue) + 1 : 0;
m_Storage.Set(pValue, nLen);
}
// Returns strlen
int CUtlString::Length() const
{
return m_Storage.Length() ? m_Storage.Length() - 1 : 0;
}
// Sets the length (used to serialize into the buffer )
void CUtlString::SetLength(int nLen)
{
_UtlString_assert(!m_Storage.IsReadOnly());
// Add 1 to account for the NULL
m_Storage.SetLength(nLen > 0 ? nLen + 1 : 0);
}
const char *CUtlString::Get() const
{
if(m_Storage.Length() == 0) {
return "";
}
return reinterpret_cast<const char*>(m_Storage.Get());
return m_pString;
}
// Converts to c-strings
CUtlString::operator const char*() const
inline void CUtlString::Set(const char* pValue)
{
return Get();
}
char *CUtlString::Get()
{
_UtlString_assert(!m_Storage.IsReadOnly());
if(m_Storage.Length() == 0) {
// In general, we optimise away small mallocs for empty strings
// but if you ask for the non-const bytes, they must be writable
// so we can't return "" here, like we do for the const version - jd
m_Storage.SetLength(1);
m_Storage[0] = '\0';
}
return reinterpret_cast<char*>(m_Storage.Get());
}
CUtlString &CUtlString::operator=(const CUtlString &src)
{
_UtlString_assert(!m_Storage.IsReadOnly());
m_Storage = src.m_Storage;
return *this;
}
CUtlString &CUtlString::operator=(const char *src)
{
_UtlString_assert(!m_Storage.IsReadOnly());
Set(src);
return *this;
}
bool CUtlString::operator==(const CUtlString &src) const
{
return m_Storage == src.m_Storage;
}
bool CUtlString::operator==(const char *src) const
{
return (strcmp(Get(), src) == 0);
}
CUtlString &CUtlString::operator+=(const CUtlString &rhs)
{
_UtlString_assert(!m_Storage.IsReadOnly());
const int lhsLength(Length());
const int rhsLength(rhs.Length());
const int requestedLength(lhsLength + rhsLength);
SetLength(requestedLength);
const int allocatedLength(Length());
const int copyLength(allocatedLength - lhsLength < rhsLength ? allocatedLength - lhsLength : rhsLength);
memcpy(Get() + lhsLength, rhs.Get(), copyLength);
m_Storage[allocatedLength] = '\0';
return *this;
}
CUtlString &CUtlString::operator+=(const char *rhs)
{
_UtlString_assert(!m_Storage.IsReadOnly());
const int lhsLength(Length());
const int rhsLength(strlen(rhs));
const int requestedLength(lhsLength + rhsLength);
SetLength(requestedLength);
const int allocatedLength(Length());
const int copyLength(allocatedLength - lhsLength < rhsLength ? allocatedLength - lhsLength : rhsLength);
memcpy(Get() + lhsLength, rhs, copyLength);
m_Storage[allocatedLength] = '\0';
return *this;
}
CUtlString &CUtlString::operator+=(char c)
{
_UtlString_assert(!m_Storage.IsReadOnly());
int nLength = Length();
SetLength(nLength + 1);
m_Storage[nLength] = c;
m_Storage[nLength + 1] = '\0';
return *this;
}
CUtlString &CUtlString::operator+=(int rhs)
{
_UtlString_assert(!m_Storage.IsReadOnly());
_UtlString_assert(sizeof(rhs) == 4);
char tmpBuf[12]; // Sufficient for a signed 32 bit integer [ -2147483648 to +2147483647 ]
snprintf(tmpBuf, sizeof(tmpBuf), "%d", rhs);
tmpBuf[sizeof(tmpBuf) - 1] = '\0';
return operator+=(tmpBuf);
}
CUtlString &CUtlString::operator+=(double rhs)
{
_UtlString_assert(!m_Storage.IsReadOnly());
char tmpBuf[256]; // How big can doubles be??? Dunno.
snprintf(tmpBuf, sizeof(tmpBuf), "%lg", rhs);
tmpBuf[sizeof(tmpBuf) - 1] = '\0';
return operator+=(tmpBuf);
}
int CUtlString::Format(const char *pFormat, ...)
{
_UtlString_assert(!m_Storage.IsReadOnly());
char tmpBuf[4096]; //< Nice big 4k buffer, as much memory as my first computer had, a Radio Shack Color Computer
va_list marker;
va_start(marker, pFormat);
int len = _vsnprintf_s(tmpBuf, 4096, sizeof(tmpBuf) - 1, pFormat, marker);
va_end(marker);
// Len < 0 represents an overflow
if(len < 0) {
len = sizeof(tmpBuf) - 1;
tmpBuf[sizeof(tmpBuf) - 1] = 0;
}
Set(tmpBuf);
return len;
}
//-----------------------------------------------------------------------------
// Strips the trailing slash
//-----------------------------------------------------------------------------
void CUtlString::StripTrailingSlash()
{
if(IsEmpty())
return;
int nLastChar = Length() - 1;
char c = m_Storage[nLastChar];
if(c == '\\' || c == '/') {
m_Storage[nLastChar] = 0;
m_Storage.SetLength(m_Storage.Length() - 1);
}
}

View File

@@ -181,7 +181,8 @@ public:
static int __cdecl SortCaseSensitive(const CUtlString *pString1, const CUtlString *pString2);
private:
CUtlBinaryBlock m_Storage;
//CUtlBinaryBlock m_Storage;
char* m_pString;
};

View File

@@ -1,6 +1,5 @@
#pragma once
#include "../sdk.h"
#define DLL_CLASS_IMPORT __declspec( dllimport )
class CFormatStringElement;
class IFormatOutputStream;