From 337bf4b5c69c818e924eb9318a25fb6ff151211f Mon Sep 17 00:00:00 2001 From: Huoji's <1296564236@qq.com> Date: Mon, 9 Oct 2023 01:13:16 +0800 Subject: [PATCH] add kickplayer --- csgo2/hooks.cpp | 3 +++ csgo2/script_apis.cpp | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/csgo2/hooks.cpp b/csgo2/hooks.cpp index 4300839..04f685d 100644 --- a/csgo2/hooks.cpp +++ b/csgo2/hooks.cpp @@ -258,6 +258,9 @@ auto initVmtHook() -> bool { return original_OnClientConnected && original_OnClientDisconnect && origin_StartServer && origin_GameFrame; } +auto initConVarHooks() -> void { + // Offset::InterFaces::IVEngineCvar->RegisterConVar +} auto init() -> bool { bool isSuccess = initMinHook() && initVmtHook(); // bool isSuccess = initVmtHook(); diff --git a/csgo2/script_apis.cpp b/csgo2/script_apis.cpp index ce0dcc6..9b6f489 100644 --- a/csgo2/script_apis.cpp +++ b/csgo2/script_apis.cpp @@ -672,10 +672,20 @@ auto luaApi_SetPlayerGlowEnable(lua_State* luaVm) -> int { const auto playerIndex = lua_tointeger(luaVm, 1); const auto isEnable = lua_toboolean(luaVm, 2); ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) { - LOG("glow set %d to %d \n", playerController->m_hPawn().Get()->m_Glow().m_bGlowing(), isEnable); - playerController->m_hPawn().Get()->m_Glow().m_bGlowing( + LOG("glow set %d to %d \n", + playerController->m_hPawn() + .Get() + ->m_Glow() + .m_bGlowing(), isEnable); - playerController->m_hPawn().Get()->m_Glow().m_iGlowType(3); + playerController->m_hPawn() + .Get() + ->m_Glow() + .m_bGlowing(isEnable); + playerController->m_hPawn() + .Get() + ->m_Glow() + .m_iGlowType(3); playerController->m_hPawn() .Get() ->m_Glow() @@ -690,6 +700,23 @@ auto luaApi_RunServerCommand(lua_State* luaVm) -> int { lua_pop(luaVm, 1); return 0; } +auto luaApi_KickPlayer(lua_State* luaVm) -> int { + const auto playerIndex = lua_tointeger(luaVm, 1); + const auto reason = lua_tostring(luaVm, 2); + ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) { + auto playerSlot = EntityIndex_to_PlayerSlot(playerIndex); + if (playerSlot == -1) { + return; + } + const auto theReason = + "You have kicked by server , reason: " + std::string(reason); + Offset::InterFaces::IVEngineServer->DisconnectClient(playerSlot, 39); + SdkTools::SentChatToClient(playerController, _HubType::kTalk, + theReason.c_str()); + }); + lua_pop(luaVm, 2); + return 0; +} auto luaApi_GetAllPlayerIndex(lua_State* luaVm) -> int { // param: playerIndex:int, style:int lua_newtable(luaVm); @@ -757,6 +784,7 @@ auto initFunciton(lua_State* luaVm) -> void { lua_register(luaVm, "luaApi_SetPlayerGlowColor", luaApi_SetPlayerGlowColor); lua_register(luaVm, "luaApi_GetAllPlayerIndex", luaApi_GetAllPlayerIndex); lua_register(luaVm, "luaApi_RunServerCommand", luaApi_RunServerCommand); + lua_register(luaVm, "luaApi_KickPlayer", luaApi_KickPlayer); luabridge::getGlobalNamespace(luaVm) .beginClass<_luaApi_WeaponInfo>("WeaponInfo")