From c1ed6d1ad965ca50b34d90098d63885e26b135ac Mon Sep 17 00:00:00 2001 From: Huoji's <1296564236@qq.com> Date: Thu, 5 Oct 2023 03:24:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A7=BB=E9=99=A4=E7=89=A9?= =?UTF-8?q?=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- csgo2/csgo2.vcxproj | 2 + csgo2/csgo2.vcxproj.filters | 6 +++ csgo2/head.h | 1 + csgo2/hooks.cpp | 3 +- csgo2/native_sdk.cpp | 4 +- csgo2/native_sdk.h | 22 ++++++---- csgo2/offset.cpp | 19 +++++---- csgo2/offset.h | 22 ++++++++-- csgo2/player_manager.cpp | 2 +- csgo2/script_apis.cpp | 84 ++++++++++++++++++++++++++++++------- csgo2/weapon.cpp | 18 ++++++++ csgo2/weapon.h | 49 ++++++++++++++++++++++ 12 files changed, 194 insertions(+), 38 deletions(-) create mode 100644 csgo2/weapon.cpp create mode 100644 csgo2/weapon.h diff --git a/csgo2/csgo2.vcxproj b/csgo2/csgo2.vcxproj index 4de1031..35524cf 100644 --- a/csgo2/csgo2.vcxproj +++ b/csgo2/csgo2.vcxproj @@ -236,6 +236,7 @@ + @@ -301,6 +302,7 @@ + diff --git a/csgo2/csgo2.vcxproj.filters b/csgo2/csgo2.vcxproj.filters index 8b61b51..6d2f618 100644 --- a/csgo2/csgo2.vcxproj.filters +++ b/csgo2/csgo2.vcxproj.filters @@ -327,6 +327,9 @@ 头文件\game_time_system + + 头文件\native_sdk + @@ -503,6 +506,9 @@ 源文件 + + 源文件\native_sdk + diff --git a/csgo2/head.h b/csgo2/head.h index 9d4a975..a28841e 100644 --- a/csgo2/head.h +++ b/csgo2/head.h @@ -80,3 +80,4 @@ static void DebugPrintA(const char* format, ...) { #include "script_apis.h" #include "script_callbacks.h" #include "timer.h" +#include "weapon.h" diff --git a/csgo2/hooks.cpp b/csgo2/hooks.cpp index ab96989..b02680b 100644 --- a/csgo2/hooks.cpp +++ b/csgo2/hooks.cpp @@ -31,8 +31,7 @@ void __fastcall hook_GameFrame(void* rcx, bool simulating, bool bFirstTick, global::HasTicked = true; if (global::EntitySystem == nullptr) { - global::EntitySystem = Offset::InterFaces::GameResourceServiceServer - ->GetGameEntitySystem(); + global::EntitySystem = CGameEntitySystem::GetInstance(); } GameTimer::ExcuteTimers(); diff --git a/csgo2/native_sdk.cpp b/csgo2/native_sdk.cpp index d4f7414..0dd66c1 100644 --- a/csgo2/native_sdk.cpp +++ b/csgo2/native_sdk.cpp @@ -1,7 +1,7 @@ #include "native_sdk.h" CBaseEntity* CHandle::GetBaseEntity() const { - CGameEntitySystem* pEntitySystem = CGameEntitySystem::GetInstance(); + CGameEntitySystem* pEntitySystem = global::EntitySystem; if (!pEntitySystem) return nullptr; return pEntitySystem->GetBaseEntity(GetEntryIndex()); @@ -31,7 +31,7 @@ auto CBasePlayer::ForceRespawn() -> void { } auto CCSPlayerPawn::GetPlayerController() -> CCSPlayerController* { - CGameEntitySystem* pEntitySystem = CGameEntitySystem::GetInstance(); + CGameEntitySystem* pEntitySystem = global::EntitySystem; if (!pEntitySystem) { return nullptr; } diff --git a/csgo2/native_sdk.h b/csgo2/native_sdk.h index 969534f..25ff7a5 100644 --- a/csgo2/native_sdk.h +++ b/csgo2/native_sdk.h @@ -1,5 +1,6 @@ #pragma once #include "head.h" + class CEntityInstance; typedef void(__fastcall* StateChanged_t)(void* networkTransmitComponent, CEntityInstance* ent, uint64_t offset, @@ -263,6 +264,12 @@ class CCollisionProperty { SCHEMA_FIELD(uint8_t, m_usSolidFlags) SCHEMA_FIELD(uint8_t, m_CollisionGroup) }; +class CCSPlayerController_InGameMoneyServices { +public: + DECLARE_CLASS(CCSPlayerController_InGameMoneyServices); + + SCHEMA_FIELD(int, m_iAccount) +}; class CHandle { CBaseEntity* GetBaseEntity() const; @@ -335,6 +342,8 @@ class CCSPlayerController : public CBasePlayerController { SCHEMA_FIELD(uint32_t, m_iPawnHealth) SCHEMA_FIELD(bool, m_bPawnIsAlive) SCHEMA_FIELD(const char*, m_szClanName) + SCHEMA_FIELD(CCSPlayerController_InGameMoneyServices*, m_pInGameMoneyServices) + }; class CEconItemDefinition { @@ -418,6 +427,9 @@ class CPlayer_WeaponServices { SCHEMA_FIELD(CHandle, m_hActiveWeapon); SCHEMA_FIELD(uint16_t, m_iAmmo); + auto RemoveWeapon(CBasePlayerWeapon* weapon) { return CALL_VIRTUAL(void, 20, this, weapon, nullptr, nullptr); } + auto Remove() { return CALL_VIRTUAL(void, 13, this); } + }; class CBasePlayer { @@ -430,12 +442,6 @@ class CPlayer_MovementServices { DECLARE_CLASS(CPlayer_MovementServices); }; -class CCSPlayerController_InGameMoneyServices { - public: - DECLARE_CLASS(CCSPlayerController_InGameMoneyServices); - - SCHEMA_FIELD(int, m_iAccount) -}; class CBasePlayerPawn : public CBaseEntity { public: @@ -459,9 +465,7 @@ class CCSPlayerPawn : public CCSPlayerPawnBase { DECLARE_CLASS(CCSPlayerPawn); SCHEMA_FIELD(const char*, m_szLastPlaceName) auto GetPlayerController() -> CCSPlayerController*; - auto ForceRespawnPlayer() { - return CALL_VIRTUAL(void, 324, this); - } + auto ForceRespawnPlayer() { return CALL_VIRTUAL(void, 324, this); } }; class CGameEntitySystem; diff --git a/csgo2/offset.cpp b/csgo2/offset.cpp index 401bb0b..9d93ec5 100644 --- a/csgo2/offset.cpp +++ b/csgo2/offset.cpp @@ -12,7 +12,8 @@ HashFunction_t FnServerHashFunction; StateChanged_t FnStateChanged; NetworkStateChanged_t FnNetworkStateChanged; RespawnPlayer_t FnRespawnPlayer; - +GiveNamedItem_t FnGiveNamedItem; +EntityRemove_t FnEntityRemove; //CreateGameRuleInterFace_t FnCreateCCSGameRulesInterFace; bool InitOffsetSuccess = false; namespace InterFaces { @@ -40,10 +41,7 @@ auto SafeDelayInit(void* ctx) -> void { } InitOffsetSuccess = true; LOG("[huoji]InterFaces::CCSGameRulesInterFace : %llx \n", InterFaces::CCSGameRulesInterFace); - LOG("[huoji]InterFaces::CCSGameRulesInterFace->respawnPlayer : %llx \n", ((void**)InterFaces::CCSGameRulesInterFace)[110]); - LOG("m_bForceTeamChangeSilent: %d \n", InterFaces::CCSGameRulesInterFace->m_bForceTeamChangeSilent()); - } auto Init() -> bool { CModule server("server.dll"); @@ -69,7 +67,10 @@ auto Init() -> bool { .Get(CCSGameRulesInterFacePtr); 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); InterFaces::SchemaSystem = reinterpret_cast( @@ -109,6 +110,9 @@ auto Init() -> bool { LOG("[huoji]FnNetworkStateChanged : %llx \n", FnNetworkStateChanged); LOG("[huoji]FnServerHashFunction : %llx \n", FnServerHashFunction); LOG("[huoji]FnStateChanged : %llx \n", FnStateChanged); + LOG("[huoji]FnRespawnPlayer : %llx \n", FnRespawnPlayer); + LOG("[huoji]FnGiveNamedItem : %llx \n", FnGiveNamedItem); + LOG("[huoji]MaxGlobals : %d \n", global::MaxPlayers); LOG("[huoji]InterFaces::SchemaSystem : %llx \n", InterFaces::SchemaSystem); @@ -124,14 +128,15 @@ auto Init() -> bool { InterFaces::IVEngineServer); LOG("[huoji]InterFaces::ISource2ServerInterFace : %llx \n", InterFaces::ISource2ServerInterFace); - + LOG("[huoji] CGameEntitySystem::GetInstance : %llx \n", + CGameEntitySystem::GetInstance()); LOG("init offset success !\n"); CreateThread(NULL, 0, reinterpret_cast(SafeDelayInit), NULL, 0, NULL); // LOG("FnServerHashFunction: %llx \n", FnServerHashFunction("here", // sizeof("here") - 1, 0x31415926)); - return FnServerHashFunction && Host_SayPtr && InterFaces::IVEngineServer && + return FnEntityRemove && FnRespawnPlayer && FnGiveNamedItem && FnServerHashFunction && Host_SayPtr && InterFaces::IVEngineServer && InterFaces::GameResourceServiceServer && InterFaces::IServerGameClient && InterFaces::GameEventManager && InterFaces::SchemaSystem && FireEventServerSidePtr && FnNetworkStateChanged; diff --git a/csgo2/offset.h b/csgo2/offset.h index b1a87e2..3450d6f 100644 --- a/csgo2/offset.h +++ b/csgo2/offset.h @@ -3,6 +3,7 @@ #define SERVER_HASH_FUCNTION_KEY 0x31415926 class CEntityInstance; class CCSPlayerPawn; +class CGameEntitySystem; typedef uint64_t(__fastcall* HashFunction_t)(const char*, unsigned int, unsigned int); typedef void(__fastcall* StateChanged_t)(void* networkTransmitComponent, @@ -12,7 +13,11 @@ typedef void(__fastcall* NetworkStateChanged_t)(uintptr_t chainEntity, uintptr_t offset, uintptr_t a3); typedef void*(__fastcall* CreateGameRuleInterFace_t)(); typedef bool(__fastcall* RespawnPlayer_t)(CCSPlayerPawn* player); - +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); class CSchemaSystem; class CGameResourceService; class CLocalize; @@ -57,9 +62,18 @@ static const auto pattern_ServerHashFunctionPtr = THE_GAME_SIG( "88 44 ?? ?? 33 D2"); static const auto pattern_MaxPlayerNumsPtr = THE_GAME_SIG("41 3B 87 ?? ?? ?? ?? 0F 8E ?? ?? ?? ?? 8B 0D ?? ?? ?? ??"); +static const auto pattern_FnGiveNamedItemPtr = THE_GAME_SIG( + "48 89 5C 24 18 48 89 74 24 20 55 57 41 54 41 56 41 57 48 8D 6C 24 D9"); static const auto pattern_CreateCCSGameRulesInterFacePtr = THE_GAME_SIG( - "48 ?? ?? ?? ?? ?? ?? 48 8B 01 FF ?? ?? ?? ?? ?? 48 8D ?? ?? ?? E8 ?? ?? ?? ?? 4C 8D ?? ?? ?? 49 8B ?? ?? 49 8B ?? ?? 49 8B ?? ?? 49 8B E3 41 5F 41 5E 5F C3"); -static const auto pattern_FnRespawnPlayer = THE_GAME_SIG("48 89 ?? ?? ?? 57 48 ?? ?? ?? 48 8D ?? ?? ?? 48 8B F9 E8 ?? ?? ?? ?? 83 ?? ?? 74 ?? 48 ?? ?? ?? ?? ?? ?? 48 8B CF 48 8B 10 48 8B ?? ?? ?? ?? ?? 48 8D ?? ?? ?? E8 ?? ?? ?? ?? 48 ?? ?? ?? ?? ?? ??"); + "48 ?? ?? ?? ?? ?? ?? 48 8B 01 FF ?? ?? ?? ?? ?? 48 8D ?? ?? ?? E8 ?? ?? " + "?? ?? 4C 8D ?? ?? ?? 49 8B ?? ?? 49 8B ?? ?? 49 8B ?? ?? 49 8B E3 41 5F " + "41 5E 5F C3"); +static const auto pattern_FnRespawnPlayer = THE_GAME_SIG( + "48 89 ?? ?? ?? 57 48 ?? ?? ?? 48 8D ?? ?? ?? 48 8B F9 E8 ?? ?? ?? ?? 83 " + "?? ?? 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 ?? ?? ?? ??"); extern uint64_t GameResourceServicePtr; extern uint64_t FireEventServerSidePtr; extern uint64_t Module_tier0; @@ -69,6 +83,8 @@ extern HashFunction_t FnServerHashFunction; extern StateChanged_t FnStateChanged; extern NetworkStateChanged_t FnNetworkStateChanged; extern RespawnPlayer_t FnRespawnPlayer; +extern GiveNamedItem_t FnGiveNamedItem; +extern EntityRemove_t FnEntityRemove; extern bool InitOffsetSuccess; auto Init() -> bool; }; // namespace Offset diff --git a/csgo2/player_manager.cpp b/csgo2/player_manager.cpp index 0e98ce1..b0f3a33 100644 --- a/csgo2/player_manager.cpp +++ b/csgo2/player_manager.cpp @@ -61,7 +61,7 @@ auto GetPlayerByPlayerSlot(uint64_t playerSlot) -> CCSPlayerController* { if (PlayerSteamId == -1) { return nullptr; } - CGameEntitySystem* pEntitySystem = CGameEntitySystem::GetInstance(); + CGameEntitySystem* pEntitySystem = global::EntitySystem; if (!pEntitySystem) { return nullptr; } diff --git a/csgo2/script_apis.cpp b/csgo2/script_apis.cpp index e91a4d5..89b7318 100644 --- a/csgo2/script_apis.cpp +++ b/csgo2/script_apis.cpp @@ -68,7 +68,7 @@ auto luaApi_SetPlayerCurrentWeaponAmmo(lua_State* luaVm) -> int { const auto playerAmmoNum = lua_tointeger(luaVm, 2); const auto playerReserveAmmoNum = lua_tointeger(luaVm, 3); - CGameEntitySystem* EntitySystem = CGameEntitySystem::GetInstance(); + CGameEntitySystem* EntitySystem = global::EntitySystem; do { if (EntitySystem == nullptr || playerIndex == 0) { break; @@ -87,17 +87,22 @@ auto luaApi_SetPlayerCurrentWeaponAmmo(lua_State* luaVm) -> int { if (weaponServices == nullptr) { break; } + const auto activeWeapon = weaponServices->m_hActiveWeapon().Get(); if (activeWeapon == nullptr) { break; } + weaponServices->RemoveWeapon(activeWeapon); + Offset::FnEntityRemove(global::EntitySystem, activeWeapon, nullptr, -1); + /* if (playerAmmoNum != -1) { activeWeapon->m_iClip1(playerAmmoNum); } if (playerReserveAmmoNum != -1) { activeWeapon->m_pReserveAmmo(playerReserveAmmoNum); } + */ } while (false); lua_pop(luaVm, 3); return 0; @@ -105,7 +110,7 @@ auto luaApi_SetPlayerCurrentWeaponAmmo(lua_State* luaVm) -> int { auto luaApi_RespawnPlayer(lua_State* luaVm) -> int { const auto playerIndex = lua_tointeger(luaVm, 1); int playerArmorValue = 0; - CGameEntitySystem* EntitySystem = CGameEntitySystem::GetInstance(); + CGameEntitySystem* EntitySystem = global::EntitySystem; do { if (EntitySystem == nullptr || playerIndex == 0) { break; @@ -121,7 +126,7 @@ auto luaApi_RespawnPlayer(lua_State* luaVm) -> int { auto playerPawn = playerController->m_hPawn().Get(); LOG("respawn player: %llx \n", playerPawn); Offset::FnRespawnPlayer(playerPawn); - //playerPawn->ForceRespawnPlayer(); + // playerPawn->ForceRespawnPlayer(); } while (false); lua_pop(luaVm, 1); return 0; @@ -130,7 +135,7 @@ auto luaApi_SetPlayerArmorValue(lua_State* luaVm) -> int { const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerArmorValue = lua_tointeger(luaVm, 2); - CGameEntitySystem* EntitySystem = CGameEntitySystem::GetInstance(); + CGameEntitySystem* EntitySystem = global::EntitySystem; do { if (EntitySystem == nullptr || playerIndex == 0) { break; @@ -153,7 +158,7 @@ auto luaApi_GetPlayerArmorValue(lua_State* luaVm) -> int { const auto playerIndex = lua_tointeger(luaVm, 1); int playerArmorValue = 0; - CGameEntitySystem* EntitySystem = CGameEntitySystem::GetInstance(); + CGameEntitySystem* EntitySystem = global::EntitySystem; do { if (EntitySystem == nullptr || playerIndex == 0) { break; @@ -177,7 +182,7 @@ auto luaApi_GetPlayerHealth(lua_State* luaVm) -> int { const auto playerIndex = lua_tointeger(luaVm, 1); int playerHealth = 0; - CGameEntitySystem* EntitySystem = CGameEntitySystem::GetInstance(); + CGameEntitySystem* EntitySystem = global::EntitySystem; do { if (EntitySystem == nullptr || playerIndex == 0) { break; @@ -200,7 +205,7 @@ auto luaApi_SetPlayerHealth(lua_State* luaVm) -> int { const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerHealth = lua_tointeger(luaVm, 2); - CGameEntitySystem* EntitySystem = CGameEntitySystem::GetInstance(); + CGameEntitySystem* EntitySystem = global::EntitySystem; do { if (EntitySystem == nullptr || playerIndex == 0) { break; @@ -214,8 +219,6 @@ auto luaApi_SetPlayerHealth(lua_State* luaVm) -> int { if (player->IsBasePlayerController() == false) { break; } - LOG("luaApi_SetPlayerHealth :3 \n"); - auto playerController = reinterpret_cast(player); playerController->m_iHealth(playerHealth); } while (false); @@ -227,7 +230,7 @@ auto luaApi_GetPlayerCurrentWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo { const auto playerIndex = lua_tointeger(luaVm, 1); _luaApi_WeaponInfo info{0}; - CGameEntitySystem* EntitySystem = CGameEntitySystem::GetInstance(); + CGameEntitySystem* EntitySystem = global::EntitySystem; do { if (EntitySystem == nullptr || playerIndex == 0) { break; @@ -339,7 +342,7 @@ auto luaApi_CheckPlayerIsAlive(lua_State* luaVm) -> int { const auto playerIndex = lua_tointeger(luaVm, 1); auto isAlive = false; - CGameEntitySystem* EntitySystem = CGameEntitySystem::GetInstance(); + CGameEntitySystem* EntitySystem = global::EntitySystem; do { if (EntitySystem == nullptr || playerIndex == 0) { break; @@ -363,7 +366,7 @@ auto luaApi_GetPlayerTeam(lua_State* luaVm) -> int { const auto playerIndex = lua_tointeger(luaVm, 1); auto team = 0; - CGameEntitySystem* EntitySystem = CGameEntitySystem::GetInstance(); + CGameEntitySystem* EntitySystem = global::EntitySystem; do { if (EntitySystem == nullptr || playerIndex == 0) { break; @@ -388,7 +391,7 @@ auto luaApi_SetPlayerTeam(lua_State* luaVm) -> int { const auto team = lua_tointeger(luaVm, 2); auto isSuccess = false; - CGameEntitySystem* EntitySystem = CGameEntitySystem::GetInstance(); + CGameEntitySystem* EntitySystem = global::EntitySystem; do { if (EntitySystem == nullptr || playerIndex == 0) { break; @@ -413,7 +416,7 @@ auto luaApi_CheckPlayerIsInServer(lua_State* luaVm) -> int { const auto playerIndex = lua_tointeger(luaVm, 1); auto isInServer = false; - CGameEntitySystem* EntitySystem = CGameEntitySystem::GetInstance(); + CGameEntitySystem* EntitySystem = global::EntitySystem; do { if (EntitySystem == nullptr || playerIndex == 0) { break; @@ -431,6 +434,57 @@ auto luaApi_CheckPlayerIsInServer(lua_State* luaVm) -> int { lua_pushboolean(luaVm, isInServer); return 1; } +auto luaApi_GivePlayerWeapon(lua_State* luaVm) -> int { + // param: playerIndex:int, itemClass:string + const auto playerIndex = lua_tointeger(luaVm, 1); + const auto weaponName = lua_tostring(luaVm, 2); + auto isSuccess = false; + + CGameEntitySystem* EntitySystem = global::EntitySystem; + do { + if (EntitySystem == nullptr || playerIndex == 0) { + break; + } + auto player = EntitySystem->GetBaseEntity(playerIndex); + if (player == nullptr) { + break; + } + if (player->IsBasePlayerController() == false) { + break; + } + auto playerController = reinterpret_cast(player); + isSuccess = + GameWeapons::ParseWeaponCommand(playerController, weaponName); + } while (false); + lua_pop(luaVm, 2); + lua_pushboolean(luaVm, isSuccess); + return 1; +} +auto luaApi_RemovePlayerWeapon(lua_State* luaVm) -> int { + // param: playerIndex:int, itemClass:string + const auto playerIndex = lua_tointeger(luaVm, 1); + const auto weaponName = lua_tostring(luaVm, 2); + auto isSuccess = false; + + CGameEntitySystem* EntitySystem = global::EntitySystem; + do { + if (EntitySystem == nullptr || playerIndex == 0) { + break; + } + auto player = EntitySystem->GetBaseEntity(playerIndex); + if (player == nullptr) { + break; + } + if (player->IsBasePlayerController() == false) { + break; + } + auto playerController = reinterpret_cast(player); + + } while (false); + lua_pop(luaVm, 2); + lua_pushboolean(luaVm, isSuccess); + return 1; +} auto initFunciton(lua_State* luaVm) -> void { lua_register(luaVm, "ListenToGameEvent", luaApi_ListenToGameEvent); lua_register(luaVm, "luaApi_SetPlayerCurrentWeaponAmmo", @@ -450,6 +504,8 @@ auto initFunciton(lua_State* luaVm) -> void { lua_register(luaVm, "luaApi_SetPlayerTeam", luaApi_SetPlayerTeam); lua_register(luaVm, "luaApi_CheckPlayerIsInServer", luaApi_CheckPlayerIsInServer); + lua_register(luaVm, "luaApi_GivePlayerWeapon", luaApi_GivePlayerWeapon); + lua_register(luaVm, "luaApi_GivePlayerWeapon", luaApi_GivePlayerWeapon); // Ҳϲ luabridge::getGlobalNamespace(luaVm) .beginClass<_luaApi_WeaponInfo>("WeaponInfo") diff --git a/csgo2/weapon.cpp b/csgo2/weapon.cpp new file mode 100644 index 0000000..c97a50d --- /dev/null +++ b/csgo2/weapon.cpp @@ -0,0 +1,18 @@ +#include "weapon.h" +namespace GameWeapons { +auto ParseWeaponCommand(CCSPlayerController* pController, + std::string pszWeaponName) -> bool { + if (WeaponMap.find(pszWeaponName) == WeaponMap.end()) { + return false; + } + const auto [fullWeaponName, weaponPirce] = WeaponMap.at(pszWeaponName); + auto pItemServices = reinterpret_cast( + pController->m_hPawn().Get()->m_pItemServices()); + if (pItemServices == NULL) { + return false; + } + Offset::FnGiveNamedItem(pItemServices, fullWeaponName.c_str(), nullptr, + nullptr, nullptr, nullptr); + return true; +} +}; // namespace GameWeapons diff --git a/csgo2/weapon.h b/csgo2/weapon.h new file mode 100644 index 0000000..38c02b6 --- /dev/null +++ b/csgo2/weapon.h @@ -0,0 +1,49 @@ +#pragma once +#include "head.h" +class CCSPlayerController; +namespace GameWeapons { + +static const std::unordered_map> + WeaponMap = { + {"bizon", {"weapon_bizon", 1400}}, + {"mac10", {"weapon_mac10", 1400}}, + {"mp7", {"weapon_mp7", 1700}}, + {"mp9", {"weapon_mp9", 1250}}, + {"p90", {"weapon_p90", 2350}}, + {"ump45", {"weapon_ump45", 1700}}, + {"ak47", {"weapon_ak47", 2500}}, + {"aug", {"weapon_aug", 3500}}, + {"famas", {"weapon_famas", 2250}}, + {"galilar", {"weapon_galilar", 2000}}, + {"m4a4", {"weapon_m4a4", 3100}}, + {"m4a1_silencer", {"weapon_m4a1_silencer", 3100}}, + {"m4a1", {"weapon_m4a1_silencer", 3100}}, + {"a1", {"weapon_m4a1_silencer", 3100}}, + {"sg556", {"weapon_sg556", 3500}}, + {"awp", {"weapon_awp", 4750}}, + {"g3sg1", {"weapon_g3sg1", 5000}}, + {"scar20", {"weapon_scar20", 5000}}, + {"ssg08", {"weapon_ssg08", 2500}}, + {"mag7", {"weapon_mag7", 2000}}, + {"nova", {"weapon_nova", 1500}}, + {"sawedoff", {"weapon_sawedoff", 1500}}, + {"xm1014", {"weapon_xm1014", 3000}}, + {"m249", {"weapon_m249", 5750}}, + {"negev", {"weapon_negev", 5750}}, + {"deagle", {"weapon_deagle", 700}}, + {"elite", {"weapon_elite", 800}}, + {"fiveseven", {"weapon_fiveseven", 500}}, + {"glock", {"weapon_glock", 200}}, + {"hkp2000", {"weapon_hkp2000", 200}}, + {"p250", {"weapon_p250", 300}}, + {"tec9", {"weapon_tec9", 500}}, + {"usp_silencer", {"weapon_usp_silencer", 200}}, + {"cz75a", {"weapon_cz75a", 500}}, + {"revolver", {"weapon_revolver", 600}}, + {"kevlar", {"item_kevlar", 600}}, + {"he", {"weapon_hegrenade", 300}}, + {"molotov", {"weapon_hegrenade", 850}}, +}; +auto ParseWeaponCommand(CCSPlayerController* pController, + std::string pszWeaponName) -> bool; +}; // namespace GameWeapons