diff --git a/csgo2/csgo2.vcxproj b/csgo2/csgo2.vcxproj
index 35524cf..e464d5e 100644
--- a/csgo2/csgo2.vcxproj
+++ b/csgo2/csgo2.vcxproj
@@ -216,14 +216,18 @@
+
+
+
+
diff --git a/csgo2/csgo2.vcxproj.filters b/csgo2/csgo2.vcxproj.filters
index 6d2f618..69d8aeb 100644
--- a/csgo2/csgo2.vcxproj.filters
+++ b/csgo2/csgo2.vcxproj.filters
@@ -330,6 +330,18 @@
头文件\native_sdk
+
+ 头文件\sdk\public
+
+
+ 头文件\sdk\public
+
+
+ 头文件\sdk\tier1
+
+
+ 头文件\sdk\tier1
+
diff --git a/csgo2/events.cpp b/csgo2/events.cpp
index 307a817..49a7949 100644
--- a/csgo2/events.cpp
+++ b/csgo2/events.cpp
@@ -1,6 +1,20 @@
#include "events.h"
namespace events {
+auto OnPlayerSpawnEvent(IGameEvent* event) -> void {
+ UnkGameEventStruct_t userIdNameParams{"userid"};
+ const auto playerPawn = reinterpret_cast(
+ event->GetPlayerPawn(&userIdNameParams));
+ if (playerPawn == nullptr) {
+ return;
+ }
+ const auto player = playerPawn->GetPlayerController();
+ if (player == nullptr) {
+ return;
+ }
+ const auto playerIndex = player->GetRefEHandle().GetEntryIndex();
+ ScriptCallBacks::luaCall_onPlayerSpawn(playerIndex);
+}
auto OnPlayerDeathEvent(IGameEvent* event) -> void {
UnkGameEventStruct_t userIdNameParams{"userid"};
UnkGameEventStruct_t attackerNameParams{"attacker"};
diff --git a/csgo2/events.h b/csgo2/events.h
index 9c6f845..b693cac 100644
--- a/csgo2/events.h
+++ b/csgo2/events.h
@@ -10,4 +10,5 @@ auto OnPlayerConnect(int slot, const char* pszName, uint64_t xuid,
auto OnPlayerDisconnect(int slot, const char* pszName, uint64_t xuid,
const char* pszNetworkID, const char* pszAddress,
bool bFakePlayer) -> void;
+auto OnPlayerSpawnEvent(IGameEvent* event) -> void;
} // namespace events
diff --git a/csgo2/head.h b/csgo2/head.h
index a28841e..4abf661 100644
--- a/csgo2/head.h
+++ b/csgo2/head.h
@@ -37,28 +37,9 @@ static void DebugPrintA(const char* format, ...) {
#include "memory.h"
// sdk
-#include "sdk/gameevent/IGameEvent.h"
-#include "sdk/tier1/bufferstring.h"
-#include "sdk/public/eiface.h"
-#include "sdk/player/playerslot.h"
#include "sdk/sdk.h"
-#include "sdk/public/mathlib.h"
-#include "sdk/public/string_t.h"
-#include "sdk/tier1/UtlMemory.hpp"
-#include "sdk/tier1/utlfixedmemory.h"
-#include "sdk/tier1/utlblockmemory.h"
-#include "sdk/tier1/UtlString.hpp"
-#include "sdk/interfaces/interfaces.h"
-#include "sdk/public/eiface.h"
-#include "sdk/gameevent/IGameEvent.h"
-#include "sdk/convar/convar.hpp"
-#include "sdk/tier1/bufferstring.h"
-#include "sdk/public/bitvec.h"
-#include "sdk/public/iserver.h"
-#include "sdk/public/utlrbtree.h"
-#include "sdk/public/utlmap.h"
#include "offset.h"
#include "native_sdk.h"
diff --git a/csgo2/hooks.cpp b/csgo2/hooks.cpp
index b02680b..cb88f61 100644
--- a/csgo2/hooks.cpp
+++ b/csgo2/hooks.cpp
@@ -1,17 +1,17 @@
#include "hooks.h"
extern auto GetGameGlobals() -> CGlobalVars*;
+
+namespace hooks {
+// "player_connect"
+VMTHook* VMT_IServerGameClient;
+VMTHook* VMT_INetworkServerServiceInteFace;
+VMTHook* VMT_ISource2ServerInterFace;
FireEventServerSide_t original_FireEventServerSide = NULL;
OnClientConnect_t original_OnClientConnected = NULL;
OnClientDisconnect_t original_OnClientDisconnect = NULL;
Host_Say_t original_Host_Say = NULL;
StartupServer_t origin_StartServer = NULL;
GameFrame_t origin_GameFrame = NULL;
-namespace hooks {
-// "player_connect"
-VMTHook* VMT_IServerGameClient;
-VMTHook* VMT_INetworkServerServiceInteFace;
-VMTHook* VMT_ISource2ServerInterFace;
-
void __fastcall hook_GameFrame(void* rcx, bool simulating, bool bFirstTick,
bool bLastTick) {
/**
@@ -128,11 +128,16 @@ bool __fastcall hook_FireEventServerSide(CGameEventManager* rcx,
static constexpr auto player_death =
hash_32_fnv1a_const("player_death");
static constexpr auto player_chat = hash_32_fnv1a_const("player_chat");
+ static constexpr auto player_spawn =
+ hash_32_fnv1a_const("player_spawn");
switch (hash_32_fnv1a_const(eventName)) {
case player_death:
events::OnPlayerDeathEvent(event);
break;
+ case player_spawn:
+ events::OnPlayerSpawnEvent(event);
+ break;
// VÉçbug,Õâ²»»áÓÐÓÃ
/*
case player_chat:
diff --git a/csgo2/hooks.h b/csgo2/hooks.h
index d1c0447..e65d332 100644
--- a/csgo2/hooks.h
+++ b/csgo2/hooks.h
@@ -7,10 +7,8 @@ typedef void(__fastcall* OnClientConnect_t)(void*, CPlayerSlot, const char*, uin
typedef void(__fastcall* OnClientDisconnect_t)(void*, CPlayerSlot, int, const char*, uint64_t, const char*);
typedef void(__fastcall* StartupServer_t)(void*, const GameSessionConfiguration_t&, ISource2WorldSession*, const char*);
typedef void(__fastcall* GameFrame_t)(void*, bool, bool, bool);
-
-extern FireEventServerSide_t original_FireEventServerSide;
-extern Host_Say_t original_Host_Say;
namespace hooks {
+ extern Host_Say_t original_Host_Say;
auto init() -> bool;
auto unload() -> void;
}
\ No newline at end of file
diff --git a/csgo2/native_sdk.cpp b/csgo2/native_sdk.cpp
index 0dd66c1..4937536 100644
--- a/csgo2/native_sdk.cpp
+++ b/csgo2/native_sdk.cpp
@@ -23,7 +23,8 @@ auto CSchemaSystem::FindTypeScopeForModule(const char* module)
}
auto CBaseEntity::IsBasePlayerController() -> bool {
- return CALL_VIRTUAL(bool, 144, this);
+ return true;
+ //return CALL_VIRTUAL(bool, 146, this);
}
auto CBaseEntity::SpawnClientEntity() -> void { CALL_VIRTUAL(void, 19, this); }
auto CBasePlayer::ForceRespawn() -> void {
diff --git a/csgo2/offset.cpp b/csgo2/offset.cpp
index 9d93ec5..6cb149d 100644
--- a/csgo2/offset.cpp
+++ b/csgo2/offset.cpp
@@ -14,7 +14,10 @@ NetworkStateChanged_t FnNetworkStateChanged;
RespawnPlayer_t FnRespawnPlayer;
GiveNamedItem_t FnGiveNamedItem;
EntityRemove_t FnEntityRemove;
-//CreateGameRuleInterFace_t FnCreateCCSGameRulesInterFace;
+UTIL_SayTextFilter_t FnUTIL_SayTextFilter;
+UTIL_ClientPrintAll_t FnUTIL_ClientPrintAll;
+ClientPrint_t FnClientPrint;
+// CreateGameRuleInterFace_t FnCreateCCSGameRulesInterFace;
bool InitOffsetSuccess = false;
namespace InterFaces {
CSchemaSystem* SchemaSystem;
@@ -30,18 +33,19 @@ CCSGameRules* CCSGameRulesInterFace;
}; // namespace InterFaces
auto SafeDelayInit(void* ctx) -> void {
// ÐèÒªÓÎÏ·µ÷Óú¯Êý³õʼ»¯
- InterFaces::CCSGameRulesInterFace =
- reinterpret_cast(Memory::read(CCSGameRulesInterFacePtr));
+ InterFaces::CCSGameRulesInterFace = reinterpret_cast(
+ Memory::read(CCSGameRulesInterFacePtr));
- while (InterFaces::CCSGameRulesInterFace == 0)
- {
- InterFaces::CCSGameRulesInterFace =
- reinterpret_cast(Memory::read(CCSGameRulesInterFacePtr));
+ while (InterFaces::CCSGameRulesInterFace == 0) {
+ InterFaces::CCSGameRulesInterFace = reinterpret_cast(
+ Memory::read(CCSGameRulesInterFacePtr));
Sleep(100);
}
InitOffsetSuccess = true;
- LOG("[huoji]InterFaces::CCSGameRulesInterFace : %llx \n", InterFaces::CCSGameRulesInterFace);
- LOG("m_bForceTeamChangeSilent: %d \n", InterFaces::CCSGameRulesInterFace->m_bForceTeamChangeSilent());
+ LOG("[huoji]InterFaces::CCSGameRulesInterFace : %llx \n",
+ InterFaces::CCSGameRulesInterFace);
+ LOG("m_bForceTeamChangeSilent: %d \n",
+ InterFaces::CCSGameRulesInterFace->m_bForceTeamChangeSilent());
}
auto Init() -> bool {
CModule server("server.dll");
@@ -65,14 +69,15 @@ auto Init() -> bool {
server.FindPattern(pattern_CreateCCSGameRulesInterFacePtr)
.ToAbsolute(3, 0)
.Get(CCSGameRulesInterFacePtr);
- server.FindPattern(pattern_FnRespawnPlayer)
- .Get(FnRespawnPlayer);
- server.FindPattern(pattern_FnEntityRemove)
- .Get(FnEntityRemove);
- server.FindPattern(pattern_FnGiveNamedItemPtr)
- .Get(FnGiveNamedItem);
+ server.FindPattern(pattern_FnRespawnPlayer).Get(FnRespawnPlayer);
+ server.FindPattern(pattern_FnEntityRemove).Get(FnEntityRemove);
+ server.FindPattern(pattern_FnGiveNamedItemPtr).Get(FnGiveNamedItem);
server.FindPattern(pattern_fnHost_SayPtr).Get(Host_SayPtr);
server.FindPattern(pattern_ServerHashFunctionPtr).Get(FnServerHashFunction);
+ server.FindPattern(pattern_UTIL_ClientPrintAll).Get(FnUTIL_ClientPrintAll);
+ server.FindPattern(pattern_FnClientPrint).Get(FnClientPrint);
+
+ server.FindPattern(pattern_FnUTIL_SayTextFilter).Get(FnUTIL_SayTextFilter);
InterFaces::SchemaSystem = reinterpret_cast(
schemasystem.FindInterface("SchemaSystem_001").Get());
// InterFaces::GameEventManager = reinterpret_cast(
@@ -112,6 +117,8 @@ auto Init() -> bool {
LOG("[huoji]FnStateChanged : %llx \n", FnStateChanged);
LOG("[huoji]FnRespawnPlayer : %llx \n", FnRespawnPlayer);
LOG("[huoji]FnGiveNamedItem : %llx \n", FnGiveNamedItem);
+ LOG("[huoji]FnClientPrint : %llx \n", FnClientPrint);
+ LOG("[huoji]FnUTIL_ClientPrintAll : %llx \n", FnUTIL_ClientPrintAll);
LOG("[huoji]MaxGlobals : %d \n", global::MaxPlayers);
@@ -132,13 +139,15 @@ auto Init() -> bool {
CGameEntitySystem::GetInstance());
LOG("init offset success !\n");
CreateThread(NULL, 0,
- reinterpret_cast(SafeDelayInit),
- NULL, 0, NULL);
+ reinterpret_cast(SafeDelayInit), NULL,
+ 0, NULL);
// LOG("FnServerHashFunction: %llx \n", FnServerHashFunction("here",
// sizeof("here") - 1, 0x31415926));
- return FnEntityRemove && FnRespawnPlayer && FnGiveNamedItem && FnServerHashFunction && Host_SayPtr && InterFaces::IVEngineServer &&
+ return FnEntityRemove && FnRespawnPlayer && FnGiveNamedItem &&
+ FnServerHashFunction && Host_SayPtr && InterFaces::IVEngineServer &&
InterFaces::GameResourceServiceServer &&
InterFaces::IServerGameClient && InterFaces::GameEventManager &&
- InterFaces::SchemaSystem && FireEventServerSidePtr && FnNetworkStateChanged;
+ InterFaces::SchemaSystem && FireEventServerSidePtr &&
+ FnNetworkStateChanged;
}
} // namespace Offset
diff --git a/csgo2/offset.h b/csgo2/offset.h
index 3450d6f..5ecd8c0 100644
--- a/csgo2/offset.h
+++ b/csgo2/offset.h
@@ -4,6 +4,7 @@
class CEntityInstance;
class CCSPlayerPawn;
class CGameEntitySystem;
+class CCSPlayerController;
typedef uint64_t(__fastcall* HashFunction_t)(const char*, unsigned int,
unsigned int);
typedef void(__fastcall* StateChanged_t)(void* networkTransmitComponent,
@@ -17,7 +18,13 @@ typedef void(__fastcall* GiveNamedItem_t)(void* itemService,
const char* pchName, void* iSubType,
void* pScriptItem, void* a5,
void* a6);
-typedef void* (__fastcall* EntityRemove_t)(CGameEntitySystem*, void*, void*, uint64_t);
+typedef void*(__fastcall* EntityRemove_t)(CGameEntitySystem*, void*, void*,
+ uint64_t);
+typedef void*(__fastcall* UTIL_SayTextFilter_t)(IRecipientFilter&, const char*,
+ CCSPlayerController*, uint64_t);
+typedef void(__fastcall* UTIL_ClientPrintAll_t)(int msg_dest, const char* msg_name, const char* param1, const char* param2, const char* param3, const char* param4);
+typedef void(__fastcall* ClientPrint_t)(CCSPlayerController* player, int msg_dest, const char* msg_name, const char* param1, const char* param2, const char* param3, const char* param4);
+
class CSchemaSystem;
class CGameResourceService;
class CLocalize;
@@ -73,7 +80,16 @@ static const auto pattern_FnRespawnPlayer = THE_GAME_SIG(
"?? ?? 74 ?? 48 ?? ?? ?? ?? ?? ?? 48 8B CF 48 8B 10 48 8B ?? ?? ?? ?? ?? "
"48 8D ?? ?? ?? E8 ?? ?? ?? ?? 48 ?? ?? ?? ?? ?? ??");
static const auto pattern_FnEntityRemove = THE_GAME_SIG(
- "48 85 D2 0F ?? ?? ?? ?? ?? 57 48 ?? ?? ?? 48 89 ?? ?? ?? 48 8B F9 48 8B ?? ?? 48 85 DB 0F ?? ?? ?? ?? ?? 48 ?? ?? ?? 75 ?? 33 D2 48 8B CB E8 ?? ?? ?? ?? 48 8D ?? ?? 41 ?? ?? 48 8B D3 48 8B ?? ?? ?? 48 ?? ?? ?? 5F E9 ?? ?? ?? ??");
+ "48 85 D2 0F ?? ?? ?? ?? ?? 57 48 ?? ?? ?? 48 89 ?? ?? ?? 48 8B F9 48 8B "
+ "?? ?? 48 85 DB 0F ?? ?? ?? ?? ?? 48 ?? ?? ?? 75 ?? 33 D2 48 8B CB E8 ?? "
+ "?? ?? ?? 48 8D ?? ?? 41 ?? ?? 48 8B D3 48 8B ?? ?? ?? 48 ?? ?? ?? 5F E9 "
+ "?? ?? ?? ??");
+static const auto pattern_FnUTIL_SayTextFilter = THE_GAME_SIG(
+ "48 89 5C 24 ?? 55 56 57 48 8D 6C 24 ?? 48 81 EC ?? ?? ?? ?? 49 8B D8");
+static const auto pattern_UTIL_ClientPrintAll = THE_GAME_SIG(
+ "48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 48 81 EC 70 01 ?? ?? 8B E9");
+static const auto pattern_FnClientPrint = THE_GAME_SIG(
+ "48 85 C9 0F 84 ?? ?? ?? ?? 48 8B C4 48 89 58 18");
extern uint64_t GameResourceServicePtr;
extern uint64_t FireEventServerSidePtr;
extern uint64_t Module_tier0;
@@ -85,6 +101,9 @@ extern NetworkStateChanged_t FnNetworkStateChanged;
extern RespawnPlayer_t FnRespawnPlayer;
extern GiveNamedItem_t FnGiveNamedItem;
extern EntityRemove_t FnEntityRemove;
+extern UTIL_SayTextFilter_t FnUTIL_SayTextFilter;
+extern UTIL_ClientPrintAll_t FnUTIL_ClientPrintAll;
+extern ClientPrint_t FnClientPrint;
extern bool InitOffsetSuccess;
auto Init() -> bool;
}; // namespace Offset
diff --git a/csgo2/script_apis.cpp b/csgo2/script_apis.cpp
index 68b58ad..3e410d0 100644
--- a/csgo2/script_apis.cpp
+++ b/csgo2/script_apis.cpp
@@ -43,6 +43,7 @@ auto ExcutePlayerAction(int playerIndex,
break;
}
auto player = EntitySystem->GetBaseEntity(playerIndex);
+
if (player == nullptr) {
break;
}
@@ -119,7 +120,6 @@ auto luaApi_RespawnPlayer(lua_State* luaVm) -> int {
if (playerPawn == nullptr) {
return;
}
- LOG("respawn player: %llx \n", playerPawn);
Offset::FnRespawnPlayer(playerPawn);
});
return 0;
@@ -190,12 +190,13 @@ auto luaApi_GetPlayerWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo {
if (weapon == nullptr) {
continue;
}
- const auto weaponIndex =
+ const auto _weaponIndex =
weapon->GetRefEHandle().GetEntryIndex();
- if (weaponIndex != weaponIndex) {
+ if (weaponIndex != _weaponIndex) {
continue;
}
activeWeapon = handle->Get();
+ break;
}
if (activeWeapon == nullptr) {
break;
@@ -230,6 +231,7 @@ auto luaApi_GetPlayerWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo {
? _luaApi_WeaponType::kGun
: _luaApi_WeaponType::kOther));
info.weaponIndex = weaponIndex;
+ //LOG("luaApi_GetPlayerWeaponInfo: %s %s %s %d \n", info.weaponName.c_str(), info.weaponBaseName.c_str(), checkWeaponName, weaponIndex);
} while (false);
});
return info;
@@ -407,6 +409,65 @@ auto luaApi_GivePlayerWeapon(lua_State* luaVm) -> int {
auto luApi_GetPlayerAllWeaponIndex(lua_State* luaVm) -> int {
// param: playerIndex:int
const auto playerIndex = lua_tointeger(luaVm, 1);
+
+ // Create a new table on the Lua stack
+ lua_newtable(luaVm);
+
+ ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
+ do {
+ const auto weaponServices = playerController->m_hPawn()
+ .Get()
+ ->m_pWeaponServices();
+ if (weaponServices == nullptr) {
+ break;
+ }
+ const auto weapons = weaponServices->m_hMyWeapons();
+ int index = 1; // Lua tables start at index 1
+ for (CHandle* handle = weapons.begin(); handle < weapons.end();
+ ++handle) {
+ const auto weapon = handle->Get();
+ if (weapon == nullptr) {
+ continue;
+ }
+ const auto activeWeapon = handle->Get();
+ const auto attributeManager = activeWeapon->m_AttributeManager();
+ if (activeWeapon == nullptr) {
+ break;
+ }
+ const auto itemView = attributeManager->m_Item();
+ if (itemView == nullptr) {
+ break;
+ }
+ const auto itemStaticData = itemView->GetStaticData();
+ if (itemView == nullptr) {
+ break;
+ }
+ const char* checkWeaponName =
+ Offset::InterFaces::ILocalize->FindSafe(
+ itemStaticData->m_pszItemBaseName);
+ if (checkWeaponName == nullptr || strlen(checkWeaponName) < 1) {
+ break;
+ }
+ //printf("weapon name: %s \n", itemStaticData->GetSimpleWeaponName());
+ const auto weaponIndex =
+ weapon->GetRefEHandle().GetEntryIndex();
+
+ // Push the value onto the stack
+ lua_pushinteger(luaVm, weaponIndex);
+
+ // Set the table at index position
+ lua_rawseti(luaVm, -2, index++);
+ }
+ } while (false);
+ });
+
+ // Return the table regardless of success or failure
+ return 1;
+}
+auto luaApi_MakePlayerWeaponDrop(lua_State* luaVm) -> int {
+ // param: playerIndex:int, itemClass:string
+ const auto playerIndex = lua_tointeger(luaVm, 1);
+ const auto weaponIndex = lua_tointeger(luaVm, 2);
auto isSuccess = false;
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
do {
@@ -417,38 +478,28 @@ auto luApi_GetPlayerAllWeaponIndex(lua_State* luaVm) -> int {
break;
}
const auto weapons = weaponServices->m_hMyWeapons();
-
- // Create a new table on the Lua stack
- lua_newtable(luaVm);
-
- int index = 1; // Lua tables start at index 1
+ CBasePlayerWeapon* activeWeapon = 0;
for (CHandle* handle = weapons.begin(); handle < weapons.end();
++handle) {
- const auto weapon = handle->Get();
- if (weapon == nullptr) {
+ if (handle->GetEntryIndex() != weaponIndex) {
continue;
}
- const auto weaponIndex =
- weapon->GetRefEHandle().GetEntryIndex();
-
- // Push the index and then the value onto the stack
- lua_pushinteger(luaVm, index++);
- lua_pushinteger(luaVm, weaponIndex);
-
- // The table is now below the key-value pair in the stack,
- // so we use -3 to indicate its position
- lua_settable(luaVm, -3);
+ const auto weapon = handle->Get();
+ if (weapon == nullptr) {
+ break;
+ }
+ activeWeapon = weapon;
+ break;
}
+ if (activeWeapon == nullptr) {
+ break;
+ }
+ weaponServices->RemoveWeapon(activeWeapon);
isSuccess = true;
} while (false);
});
-
- if (!isSuccess) {
- // If unsuccessful, remove the table from the stack
- lua_pop(luaVm, 1);
- }
+ lua_pop(luaVm, 2);
lua_pushboolean(luaVm, isSuccess);
- // Return the number of results (either the table or false)
return 1;
}
auto luaApi_RemovePlayerWeapon(lua_State* luaVm) -> int {
@@ -476,6 +527,7 @@ auto luaApi_RemovePlayerWeapon(lua_State* luaVm) -> int {
continue;
}
activeWeapon = weapon;
+ break;
}
if (activeWeapon == nullptr) {
break;
@@ -488,8 +540,35 @@ auto luaApi_RemovePlayerWeapon(lua_State* luaVm) -> int {
});
lua_pop(luaVm, 2);
- lua_pushboolean(luaVm, isSuccess);
- return 1;
+ return 0;
+}
+auto luaApi_SendToPlayerChat(lua_State* luaVm) -> int {
+ // param: playerIndex:int, message:string
+ const auto playerIndex = lua_tointeger(luaVm, 1);
+ const auto hudType = lua_tointeger(luaVm, 2);
+ const auto message = lua_tostring(luaVm, 3);
+ if (hudType >= _HubType::kMax || hudType < _HubType::kNotify) {
+ lua_pop(luaVm, 3);
+ return 0;
+ }
+ ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
+ SdkTools::SentChatToClient(playerController,
+ static_cast<_HubType>(hudType), message);
+ });
+ lua_pop(luaVm, 3);
+ return 0;
+}
+auto luaApi_SentToAllPlayerChat(lua_State* luaVm) -> int {
+ // param: playerIndex:int, message:string
+ const auto message = lua_tostring(luaVm, 1);
+ const auto hudType = lua_tointeger(luaVm, 2);
+ if (hudType >= _HubType::kMax || hudType < _HubType::kNotify) {
+ lua_pop(luaVm, 3);
+ return 0;
+ }
+ SdkTools::SendConsoleChat(static_cast<_HubType>(hudType), message);
+ lua_pop(luaVm, 2);
+ return 0;
}
auto initFunciton(lua_State* luaVm) -> void {
lua_register(luaVm, "ListenToGameEvent", luaApi_ListenToGameEvent);
@@ -514,6 +593,12 @@ auto initFunciton(lua_State* luaVm) -> void {
lua_register(luaVm, "luApi_GetPlayerAllWeaponIndex",
luApi_GetPlayerAllWeaponIndex);
lua_register(luaVm, "luaApi_RemovePlayerWeapon", luaApi_RemovePlayerWeapon);
+ lua_register(luaVm, "luaApi_MakePlayerWeaponDrop",
+ luaApi_MakePlayerWeaponDrop);
+ lua_register(luaVm, "luaApi_SendToPlayerChat", luaApi_SendToPlayerChat);
+ lua_register(luaVm, "luaApi_SentToAllPlayerChat",
+ luaApi_SentToAllPlayerChat);
+
luabridge::getGlobalNamespace(luaVm)
.beginClass<_luaApi_WeaponInfo>("WeaponInfo")
.addConstructor()
diff --git a/csgo2/script_callbacks.cpp b/csgo2/script_callbacks.cpp
index f923877..a88e625 100644
--- a/csgo2/script_callbacks.cpp
+++ b/csgo2/script_callbacks.cpp
@@ -10,6 +10,8 @@ std::unordered_map callbackNameWithEnumMap{
_CallbackNames::kOnPlayerDisconnect},
{hash_32_fnv1a_const("player_death"), _CallbackNames::kOnPlayerDeath},
{hash_32_fnv1a_const("player_chat"), _CallbackNames::kOnPlayerSpeak},
+ {hash_32_fnv1a_const("player_spawn"), _CallbackNames::kOnPlayerSpawn},
+
};
auto CallBackNameToEnum(const char* name) -> _CallbackNames {
if (name == nullptr) {
@@ -35,7 +37,7 @@ auto ExcuteCallbackInAllLuaVm(_CallbackNames cbType,
if (luaVMCallbackLists.find(cbType) == luaVMCallbackLists.end()) {
continue;
}
- LOG("excute callback %d in %s \n", cbType, pluginName.c_str());
+ // LOG("excute callback %d in %s \n", cbType, pluginName.c_str());
const auto luaRefIndex = luaVMCallbackLists.at(cbType);
cb(luaVm, luaRefIndex);
}
@@ -129,4 +131,19 @@ auto luaCall_onPlayerSpeak(int speaker, int chatType, std::string message)
});
return result;
}
+auto luaCall_onPlayerSpawn(int player) -> void {
+ ExcuteCallbackInAllLuaVm(_CallbackNames::kOnPlayerSpawn,
+ [&](lua_State* luaVm, int refIndex) -> void {
+ lua_rawgeti(luaVm, LUA_REGISTRYINDEX,
+ refIndex);
+ if (lua_isfunction(luaVm, -1)) {
+ lua_pushinteger(luaVm, player);
+ if (lua_pcall(luaVm, 1, 0, 0) != LUA_OK) {
+ LOG("Error calling Lua callback: %s\n",
+ lua_tostring(luaVm, -1));
+ lua_pop(luaVm, 1);
+ }
+ }
+ });
+}
} // namespace ScriptCallBacks
diff --git a/csgo2/script_callbacks.h b/csgo2/script_callbacks.h
index 180e374..284a70d 100644
--- a/csgo2/script_callbacks.h
+++ b/csgo2/script_callbacks.h
@@ -7,7 +7,8 @@ enum class _CallbackNames {
kOnPlayerConnect,
kOnPlayerDisconnect,
kOnPlayerDeath,
- kOnPlayerSpeak
+ kOnPlayerSpeak,
+ kOnPlayerSpawn
};
extern std::unordered_map>
callbackList;
@@ -22,4 +23,5 @@ auto luaCall_onPlayerDisconnect(int player, int slot, const char* pszName,
auto luaCall_onPlayerDeath(int victim, int killer, bool isHeadShot) -> void;
auto luaCall_onPlayerSpeak(int speaker, int chatType, std::string message)
-> bool;
+auto luaCall_onPlayerSpawn(int player) -> void;
} // namespace ScriptCallBacks
diff --git a/csgo2/sdk/convar/convar.cpp b/csgo2/sdk/convar/convar.cpp
index 2bc9cca..0e21f48 100644
--- a/csgo2/sdk/convar/convar.cpp
+++ b/csgo2/sdk/convar/convar.cpp
@@ -1,18 +1,116 @@
#include "convar.hpp"
-inline const char** CCommand::ArgV() const
-{
- return ArgC() ? (const char**)m_Args.Base() : NULL;
+inline const char** CCommand::ArgV() const {
+ return ArgC() ? (const char**)m_Args.Base() : NULL;
}
-inline const char* CCommand::ArgS() const
-{
- return m_nArgv0Size ? (m_ArgSBuffer.Base() + m_nArgv0Size) : "";
+inline const char* CCommand::ArgS() const {
+ return m_nArgv0Size ? (m_ArgSBuffer.Base() + m_nArgv0Size) : "";
}
-
-
-inline const char* CCommand::operator[](int nIndex) const
-{
- return Arg(nIndex);
+inline const char* CCommand::operator[](int nIndex) const {
+ return Arg(nIndex);
+}
+static characterset_t s_BreakSet;
+static bool s_bBuiltBreakSet = false;
+void CharacterSetBuild(characterset_t* pSetBuffer, const char* pszSetString) {
+ int i = 0;
+
+ // Test our pointers
+ if (!pSetBuffer || !pszSetString) return;
+
+ memset(pSetBuffer->set, 0, sizeof(pSetBuffer->set));
+
+ while (pszSetString[i]) {
+ pSetBuffer->set[static_cast(pszSetString[i])] = 1;
+ i++;
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Tokenizer class
+//-----------------------------------------------------------------------------
+CCommand::CCommand() {
+ if (!s_bBuiltBreakSet) {
+ s_bBuiltBreakSet = true;
+ CharacterSetBuild(&s_BreakSet, "{}()':");
+ }
+
+ Reset();
+}
+
+CCommand::CCommand(int nArgC, const char** ppArgV) {
+ Assert(nArgC > 0);
+
+ if (!s_bBuiltBreakSet) {
+ s_bBuiltBreakSet = true;
+ CharacterSetBuild(&s_BreakSet, "{}()':");
+ }
+
+ Reset();
+
+ char* pBuf = m_ArgvBuffer.Base();
+ char* pSBuf = m_ArgSBuffer.Base();
+ for (int i = 0; i < nArgC; ++i) {
+ m_Args.AddToTail(pBuf);
+ int nLen = strlen(ppArgV[i]);
+ memcpy(pBuf, ppArgV[i], nLen + 1);
+ if (i == 0) {
+ m_nArgv0Size = nLen;
+ }
+ pBuf += nLen + 1;
+
+ bool bContainsSpace = strchr(ppArgV[i], ' ') != NULL;
+ if (bContainsSpace) {
+ *pSBuf++ = '\"';
+ }
+ memcpy(pSBuf, ppArgV[i], nLen);
+ pSBuf += nLen;
+ if (bContainsSpace) {
+ *pSBuf++ = '\"';
+ }
+
+ if (i != nArgC - 1) {
+ *pSBuf++ = ' ';
+ }
+ }
+}
+bool CCommand::Tokenize(const char* pCommand, characterset_t* pBreakSet) {
+ __debugbreak();
+ return false;
+}
+void CCommand::Reset() {
+ m_nArgv0Size = 0;
+ m_ArgSBuffer.RemoveAll();
+ m_ArgvBuffer.RemoveAll();
+ m_Args.RemoveAll();
+}
+
+characterset_t* CCommand::DefaultBreakSet() { return &s_BreakSet; }
+
+//-----------------------------------------------------------------------------
+// Helper function to parse arguments to commands.
+//-----------------------------------------------------------------------------
+int CCommand::FindArg(const char* pName) const {
+ int nArgC = ArgC();
+ for (int i = 1; i < nArgC; i++) {
+ if (!_stricmp(Arg(i), pName)) return (i + 1) < nArgC ? i + 1 : -1;
+ }
+ return -1;
+}
+
+int CCommand::FindArgInt(const char* pName, int nDefaultVal) const {
+ int idx = FindArg(pName);
+ if (idx != -1)
+ return atoi(m_Args[idx]);
+ else
+ return nDefaultVal;
+}
+
+//-----------------------------------------------------------------------------
+// Default console command autocompletion function
+//-----------------------------------------------------------------------------
+int DefaultCompletionFunc(const char* partial,
+ CUtlVector& commands) {
+ return 0;
}
diff --git a/csgo2/sdk/convar/convar.hpp b/csgo2/sdk/convar/convar.hpp
index d12a36b..2e90146 100644
--- a/csgo2/sdk/convar/convar.hpp
+++ b/csgo2/sdk/convar/convar.hpp
@@ -1,129 +1,83 @@
#pragma once
#include "../sdk.h"
-#include "../tier1/UtlVector.hpp"
-struct characterset_t
-{
- char set[256];
+struct characterset_t {
+ char set[256];
};
-class ConCommandBase
-{
- friend class CCvar;
- friend class ConCommand;
+class ConCommandBase {
+ friend class CCvar;
+ friend class ConCommand;
-protected:
- ConCommandBase(void);
-public:
+ protected:
+ ConCommandBase(void);
- ~ConCommandBase(void);
- // Check flag
- bool IsFlagSet(int64_t flag) const;
- // Set flag
- void AddFlags(int64_t flags);
- // Clear flag
- void RemoveFlags(int64_t flags);
+ public:
+ ~ConCommandBase(void);
+ // Check flag
+ bool IsFlagSet(int64_t flag) const;
+ // Set flag
+ void AddFlags(int64_t flags);
+ // Clear flag
+ void RemoveFlags(int64_t flags);
- int64_t GetFlags() const;
+ int64_t GetFlags() const;
- // Return name of cvar
- const char* GetName(void) const;
+ // Return name of cvar
+ const char* GetName(void) const;
- // Return help text for cvar
- const char* GetHelpText(void) const;
+ // Return help text for cvar
+ const char* GetHelpText(void) const;
-private:
- // Static data
- const char* m_pszName;
- const char* m_pszHelpString;
+ private:
+ // Static data
+ const char* m_pszName;
+ const char* m_pszHelpString;
- // ConVar flags
- int64_t m_nFlags;
+ // ConVar flags
+ int64_t m_nFlags;
};
-template< class T, size_t SIZE, class I = int >
-class CUtlMemoryFixedGrowable : public CUtlMemory< T, I >
-{
- typedef CUtlMemory< T, I > BaseClass;
+class CCommand {
+ public:
+ CCommand();
+ CCommand(int nArgC, const char** ppArgV);
+ virtual bool Tokenize(const char* pCommand,
+ characterset_t* pBreakSet = NULL);
+ virtual void Reset();
-public:
- CUtlMemoryFixedGrowable(int nGrowSize = 0, int nInitSize = SIZE) : BaseClass(m_pFixedMemory, SIZE)
- {
- Assert(nInitSize == 0 || nInitSize == SIZE);
- }
+ int ArgC() const { return m_Args.Count(); }
+ const char** ArgV() const;
+ const char* ArgS()
+ const; // All args that occur after the 0th arg, in string form
+ const char* GetCommandString() const {
+ return ArgC() ? m_ArgSBuffer.Base() : "";
+ }
+ const char* operator[](int nIndex) const; // Gets at arguments
+ const char* Arg(int nIndex) const {
+ // FIXME: Many command handlers appear to not be particularly careful
+ // about checking for valid argc range. For now, we're going to
+ // do the extra check and return an empty string if it's out of range
+ if (nIndex < 0 || nIndex >= ArgC()) return "";
+ return m_Args[nIndex];
+ }
- void EnsureCapacity(int num)
- {
- if (CUtlMemory::m_nAllocationCount >= num)
- return;
+ // Helper functions to parse arguments to commands.
+ //
+ // Returns index of argument, or -1 if no such argument.
+ int FindArg(const char* pName) const;
- BaseClass::EnsureCapacity(num);
- }
+ int FindArgInt(const char* pName, int nDefaultVal) const;
-private:
- T m_pFixedMemory[SIZE];
+ static int MaxCommandLength() { return COMMAND_MAX_LENGTH - 1; }
+ static characterset_t* DefaultBreakSet();
+
+ private:
+ enum {
+ COMMAND_MAX_ARGC = 64,
+ COMMAND_MAX_LENGTH = 512,
+ };
+
+ int m_nArgv0Size;
+ CUtlVectorFixedGrowable m_ArgSBuffer;
+ CUtlVectorFixedGrowable m_ArgvBuffer;
+ CUtlVectorFixedGrowable m_Args;
};
-
-template< class T, size_t MAX_SIZE >
-class CUtlVectorFixedGrowable : public CUtlVector< T, CUtlMemoryFixedGrowable >
-{
- typedef CUtlVector< T, CUtlMemoryFixedGrowable > BaseClass;
-
-public:
- // constructor, destructor
- CUtlVectorFixedGrowable(int growSize = 0) : BaseClass(growSize, MAX_SIZE) {}
-};
-
-
-class CCommand
-{
-public:
- CCommand();
- CCommand(int nArgC, const char** ppArgV);
- virtual bool Tokenize(const char* pCommand, characterset_t* pBreakSet = NULL);
- virtual void Reset();
-
- int ArgC() const {
- return m_Args.Count();
- }
- const char** ArgV() const;
- const char* ArgS() const; // All args that occur after the 0th arg, in string form
- const char* GetCommandString() const
- {
- return ArgC() ? m_ArgSBuffer.Base() : "";
- }
- const char* operator[](int nIndex) const; // Gets at arguments
- const char* Arg(int nIndex) const {
- // FIXME: Many command handlers appear to not be particularly careful
- // about checking for valid argc range. For now, we're going to
- // do the extra check and return an empty string if it's out of range
- if (nIndex < 0 || nIndex >= ArgC())
- return "";
- return m_Args[nIndex];
-
- }
-
- // Helper functions to parse arguments to commands.
- //
- // Returns index of argument, or -1 if no such argument.
- int FindArg(const char* pName) const;
-
- int FindArgInt(const char* pName, int nDefaultVal) const;
-
- static int MaxCommandLength()
- {
- return COMMAND_MAX_LENGTH - 1;
- }
- static characterset_t* DefaultBreakSet();
-
-private:
- enum
- {
- COMMAND_MAX_ARGC = 64,
- COMMAND_MAX_LENGTH = 512,
- };
-
- int m_nArgv0Size;
- CUtlVectorFixedGrowable m_ArgSBuffer;
- CUtlVectorFixedGrowable m_ArgvBuffer;
- CUtlVectorFixedGrowable m_Args;
-};
-
diff --git a/csgo2/sdk/public/bitvec.h b/csgo2/sdk/public/bitvec.h
index bdbf1d5..ddd55de 100644
--- a/csgo2/sdk/public/bitvec.h
+++ b/csgo2/sdk/public/bitvec.h
@@ -1,9 +1,3 @@
-//===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
-//
-// Purpose:
-//
-//===========================================================================//
-
#ifndef BITVEC_H
#define BITVEC_H
#ifdef _WIN32
diff --git a/csgo2/sdk/public/irecipientfilter.h b/csgo2/sdk/public/irecipientfilter.h
new file mode 100644
index 0000000..919b5c1
--- /dev/null
+++ b/csgo2/sdk/public/irecipientfilter.h
@@ -0,0 +1,17 @@
+#pragma once
+#include "eiface.h"
+
+//-----------------------------------------------------------------------------
+// Purpose: Generic interface for routing messages to users
+//-----------------------------------------------------------------------------
+class IRecipientFilter
+{
+public:
+ virtual ~IRecipientFilter() {}
+
+ virtual bool IsReliable(void) const = 0;
+ virtual bool IsInitMessage(void) const = 0;
+
+ virtual int GetRecipientCount(void) const = 0;
+ virtual CEntityIndex GetRecipientIndex(int slot) const = 0;
+};
\ No newline at end of file
diff --git a/csgo2/sdk/public/recipientfilters.h b/csgo2/sdk/public/recipientfilters.h
new file mode 100644
index 0000000..eda60dc
--- /dev/null
+++ b/csgo2/sdk/public/recipientfilters.h
@@ -0,0 +1,62 @@
+#pragma once
+#include "../sdk.h"
+
+class CSingleRecipientFilter : public IRecipientFilter
+{
+public:
+ CSingleRecipientFilter(int iRecipient, bool bReliable = true, bool bInitMessage = false) :
+ m_iRecipient(iRecipient), m_bReliable(bReliable), m_bInitMessage(bInitMessage) {}
+
+ ~CSingleRecipientFilter() override {}
+
+ bool IsReliable(void) const override { return m_bReliable; }
+
+ bool IsInitMessage(void) const override { return m_bInitMessage; }
+
+ int GetRecipientCount(void) const override { return 1; }
+
+ CEntityIndex GetRecipientIndex(int slot) const override { return CEntityIndex(m_iRecipient); }
+
+private:
+ bool m_bReliable;
+ bool m_bInitMessage;
+ int m_iRecipient;
+};
+
+class CCopyRecipientFilter : public IRecipientFilter
+{
+public:
+ CCopyRecipientFilter(IRecipientFilter *source, int iExcept)
+ {
+ m_bReliable = source->IsReliable();
+ m_bInitMessage = source->IsInitMessage();
+ m_Recipients.RemoveAll();
+
+ for (int i = 0; i < source->GetRecipientCount(); i++)
+ {
+ if (source->GetRecipientIndex(i).Get() != iExcept)
+ m_Recipients.AddToTail(source->GetRecipientIndex(i));
+ }
+ }
+
+ ~CCopyRecipientFilter() override {}
+
+ bool IsReliable(void) const override { return m_bReliable; }
+
+ bool IsInitMessage(void) const override { return m_bInitMessage; }
+
+ int GetRecipientCount(void) const override { return m_Recipients.Count(); }
+
+ CEntityIndex GetRecipientIndex(int slot) const override
+ {
+ if (slot < 0 || slot >= GetRecipientCount())
+ return CEntityIndex(-1);
+
+ return m_Recipients[slot];
+ }
+
+private:
+ bool m_bReliable;
+ bool m_bInitMessage;
+ CUtlVectorFixed m_Recipients;
+};
\ No newline at end of file
diff --git a/csgo2/sdk/public/utlrbtree.h b/csgo2/sdk/public/utlrbtree.h
index 1cf8fae..182096e 100644
--- a/csgo2/sdk/public/utlrbtree.h
+++ b/csgo2/sdk/public/utlrbtree.h
@@ -1,11 +1,3 @@
-//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
-//
-// Purpose:
-//
-// $Header: $
-// $NoKeywords: $
-//=============================================================================//
-
#ifndef UTLRBTREE_H
#define UTLRBTREE_H
diff --git a/csgo2/sdk/sdk.h b/csgo2/sdk/sdk.h
index 9838b4d..b3bbd01 100644
--- a/csgo2/sdk/sdk.h
+++ b/csgo2/sdk/sdk.h
@@ -1,61 +1,109 @@
#pragma once
+#include
+#include
+#include
+#include
+#include
+#include
+#include