From 7d03e90197df249da9638996c40f349f59fbdffe Mon Sep 17 00:00:00 2001 From: FutureRave Date: Thu, 11 May 2023 12:32:14 +0100 Subject: [PATCH] [Weapon]: Add very realistic FreezeControlsAllowLook --- src/Components/Modules/ClientCommand.cpp | 8 ++--- src/Components/Modules/GSC/Script.cpp | 2 +- .../Modules/GSC/ScriptExtension.cpp | 11 ------- .../Modules/GSC/ScriptExtension.hpp | 1 - src/Components/Modules/Voice.cpp | 2 +- src/Components/Modules/Weapon.cpp | 30 +++++++++++++++++-- src/Components/Modules/Weapon.hpp | 1 + src/Game/Functions.cpp | 6 ++-- src/Game/Structs.hpp | 8 +++-- 9 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/Components/Modules/ClientCommand.cpp b/src/Components/Modules/ClientCommand.cpp index ab3765a7..f80f9eb8 100644 --- a/src/Components/Modules/ClientCommand.cpp +++ b/src/Components/Modules/ClientCommand.cpp @@ -488,12 +488,12 @@ namespace Components if (!CheatsOk(ent)) return; - ent->client->flags ^= Game::PF_NOCLIP; + ent->client->flags ^= Game::CF_BIT_NOCLIP; const auto entNum = ent->s.number; Logger::Debug("Noclip toggled for entity {}", entNum); - Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"%s\"", 0x65, (ent->client->flags & Game::PF_NOCLIP) ? "GAME_NOCLIPON" : "GAME_NOCLIPOFF")); + Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"%s\"", 0x65, (ent->client->flags & Game::CF_BIT_NOCLIP) ? "GAME_NOCLIPON" : "GAME_NOCLIPOFF")); } void ClientCommand::Cmd_UFO_f(Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params) @@ -501,12 +501,12 @@ namespace Components if (!CheatsOk(ent)) return; - ent->client->flags ^= Game::PF_UFO; + ent->client->flags ^= Game::CF_BIT_UFO; const auto entNum = ent->s.number; Logger::Debug("UFO toggled for entity {}", entNum); - Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"%s\"", 0x65, (ent->client->flags & Game::PF_UFO) ? "GAME_UFOON" : "GAME_UFOOFF")); + Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"%s\"", 0x65, (ent->client->flags & Game::CF_BIT_UFO) ? "GAME_UFOON" : "GAME_UFOOFF")); } ClientCommand::ClientCommand() diff --git a/src/Components/Modules/GSC/Script.cpp b/src/Components/Modules/GSC/Script.cpp index 242f5436..0bcdd1b6 100644 --- a/src/Components/Modules/GSC/Script.cpp +++ b/src/Components/Modules/GSC/Script.cpp @@ -262,7 +262,7 @@ namespace Components::GSC auto* ent = &Game::g_entities[entref.entnum]; if (!ent->client) { - Game::Scr_ObjectError(Utils::String::VA("entity %i is not a player", entref.entnum)); + Game::Scr_ObjectError(Utils::String::VA("entity %hu is not a player", entref.entnum)); return nullptr; } diff --git a/src/Components/Modules/GSC/ScriptExtension.cpp b/src/Components/Modules/GSC/ScriptExtension.cpp index f83bdaae..f5497679 100644 --- a/src/Components/Modules/GSC/ScriptExtension.cpp +++ b/src/Components/Modules/GSC/ScriptExtension.cpp @@ -169,20 +169,9 @@ namespace Components::GSC }); } - void ScriptExtension::AddMethods() - { - // PlayerCmd_AreControlsFrozen GSC function from Black Ops 2 - Script::AddMethod("AreControlsFrozen", [](Game::scr_entref_t entref) // Usage: self AreControlsFrozen(); - { - const auto* ent = Script::Scr_GetPlayerEntity(entref); - Game::Scr_AddBool((ent->client->flags & Game::PF_FROZEN) != 0); - }); - } - ScriptExtension::ScriptExtension() { AddFunctions(); - AddMethods(); Utils::Hook(0x61E92E, VMExecuteInternalStub, HOOK_JUMP).install()->quick(); Utils::Hook::Nop(0x61E933, 1); diff --git a/src/Components/Modules/GSC/ScriptExtension.hpp b/src/Components/Modules/GSC/ScriptExtension.hpp index 18fa1ba3..323777ae 100644 --- a/src/Components/Modules/GSC/ScriptExtension.hpp +++ b/src/Components/Modules/GSC/ScriptExtension.hpp @@ -18,6 +18,5 @@ namespace Components::GSC static void VMExecuteInternalStub(); static void AddFunctions(); - static void AddMethods(); }; } diff --git a/src/Components/Modules/Voice.cpp b/src/Components/Modules/Voice.cpp index 5379eb6c..c7bf5448 100644 --- a/src/Components/Modules/Voice.cpp +++ b/src/Components/Modules/Voice.cpp @@ -391,7 +391,7 @@ namespace Components Events::OnSteamDisconnect(CL_ClearMutedList); Events::OnClientDisconnect(SV_UnmuteClient); - Events::OnClientConnect([](Game::client_s* cl) -> void + Events::OnClientConnect([](const Game::client_s* cl) -> void { if (Chat::IsMuted(cl)) { diff --git a/src/Components/Modules/Weapon.cpp b/src/Components/Modules/Weapon.cpp index f3842b19..2451420c 100644 --- a/src/Components/Modules/Weapon.cpp +++ b/src/Components/Modules/Weapon.cpp @@ -548,7 +548,7 @@ namespace Components } } - void Weapon::PlayerCmd_InitialWeaponRaise(Game::scr_entref_t entref) + void Weapon::PlayerCmd_InitialWeaponRaise(const Game::scr_entref_t entref) { auto* ent = GSC::Script::Scr_GetPlayerEntity(entref); const auto* weapon = Game::Scr_GetString(0); @@ -578,23 +578,47 @@ namespace Components Game::Player_SwitchToWeapon(ent); } + void Weapon::PlayerCmd_FreezeControlsAllowLook(const Game::scr_entref_t entref) + { + const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref); + + if (Game::Scr_GetInt(0)) + { + ent->client->ps.weapCommon.weapFlags |= Game::PWF_DISABLE_WEAPONS; + ent->client->flags |= Game::CF_BIT_DISABLE_USABILITY; + } + else + { + ent->client->ps.weapCommon.weapFlags &= ~Game::PWF_DISABLE_WEAPONS; + ent->client->flags &= ~Game::CF_BIT_DISABLE_USABILITY; + } + } + void Weapon::AddScriptMethods() { - GSC::Script::AddMethod("DisableWeaponPickup", [](Game::scr_entref_t entref) + GSC::Script::AddMethod("DisableWeaponPickup", [](const Game::scr_entref_t entref) { const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref); ent->client->ps.weapCommon.weapFlags |= Game::PWF_DISABLE_WEAPON_PICKUP; }); - GSC::Script::AddMethod("EnableWeaponPickup", [](Game::scr_entref_t entref) + GSC::Script::AddMethod("EnableWeaponPickup", [](const Game::scr_entref_t entref) { const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref); ent->client->ps.weapCommon.weapFlags &= ~Game::PWF_DISABLE_WEAPON_PICKUP; }); + // PlayerCmd_AreControlsFrozen GSC function from Black Ops 2 + GSC::Script::AddMethod("AreControlsFrozen", [](Game::scr_entref_t entref) // Usage: self AreControlsFrozen(); + { + const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref); + Game::Scr_AddBool((ent->client->flags & Game::CF_BIT_FROZEN) != 0); + }); + GSC::Script::AddMethod("InitialWeaponRaise", PlayerCmd_InitialWeaponRaise); + GSC::Script::AddMethod("FreezeControlsAllowLook", PlayerCmd_FreezeControlsAllowLook); } Weapon::Weapon() diff --git a/src/Components/Modules/Weapon.hpp b/src/Components/Modules/Weapon.hpp index 3c3e6e71..30af745b 100644 --- a/src/Components/Modules/Weapon.hpp +++ b/src/Components/Modules/Weapon.hpp @@ -36,6 +36,7 @@ namespace Components static void WeaponEntCanBeGrabbed_Stub(); static void PlayerCmd_InitialWeaponRaise(Game::scr_entref_t entref); + static void PlayerCmd_FreezeControlsAllowLook(Game::scr_entref_t entref); static void AddScriptMethods(); }; diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 86afc062..05b1efca 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -1156,7 +1156,7 @@ namespace Game int SEH_GetLocalizedTokenReference(char* token, const char* reference, const char* messageType, msgLocErrType_t errType) { static DWORD SEH_GetLocalizedTokenReference_t = 0x629BB0; - auto answer = 0; + auto result = 0; __asm { @@ -1167,11 +1167,11 @@ namespace Game push token call SEH_GetLocalizedTokenReference_t add esp, 0x4 - mov answer, eax + mov result, eax popad } - return answer; + return result; } void Player_SwitchToWeapon(gentity_s* player) diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 1b33367a..f488d115 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -7140,9 +7140,11 @@ namespace Game enum { - PF_NOCLIP = 1 << 0, - PF_UFO = 1 << 1, - PF_FROZEN = 1 << 2, + CF_BIT_NOCLIP = (1 << 0), + CF_BIT_UFO = (1 << 1), + CF_BIT_FROZEN = (1 << 2), + CF_BIT_DISABLE_USABILITY = (1 << 3), + CF_BIT_NO_KNOCKBACK = (1 << 4), }; enum sessionState_t