增加移除物品
This commit is contained in:
@@ -236,6 +236,7 @@
|
||||
<ClInclude Include="vmt.h" />
|
||||
<ClInclude Include="vmthook.h" />
|
||||
<ClInclude Include="script_callbacks.h" />
|
||||
<ClInclude Include="weapon.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp" />
|
||||
@@ -301,6 +302,7 @@
|
||||
<ClCompile Include="timer.cpp" />
|
||||
<ClCompile Include="tools.cpp" />
|
||||
<ClCompile Include="vmthook.cpp" />
|
||||
<ClCompile Include="weapon.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="cpp.hint" />
|
||||
|
||||
@@ -327,6 +327,9 @@
|
||||
<ClInclude Include="timer.h">
|
||||
<Filter>头文件\game_time_system</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="weapon.h">
|
||||
<Filter>头文件\native_sdk</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp">
|
||||
@@ -503,6 +506,9 @@
|
||||
<ClCompile Include="tools.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="weapon.cpp">
|
||||
<Filter>源文件\native_sdk</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="cpp.hint" />
|
||||
|
||||
@@ -80,3 +80,4 @@ static void DebugPrintA(const char* format, ...) {
|
||||
#include "script_apis.h"
|
||||
#include "script_callbacks.h"
|
||||
#include "timer.h"
|
||||
#include "weapon.h"
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<CSchemaSystem*>(
|
||||
@@ -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<LPTHREAD_START_ROUTINE>(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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<CBasePlayerWeapon>();
|
||||
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<CCSPlayerPawn>();
|
||||
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<CCSPlayerController*>(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<CCSPlayerController*>(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<CCSPlayerController*>(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);
|
||||
// <20>Ҳ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD>
|
||||
luabridge::getGlobalNamespace(luaVm)
|
||||
.beginClass<_luaApi_WeaponInfo>("WeaponInfo")
|
||||
|
||||
18
csgo2/weapon.cpp
Normal file
18
csgo2/weapon.cpp
Normal file
@@ -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<void*>(
|
||||
pController->m_hPawn().Get<CCSPlayerPawn>()->m_pItemServices());
|
||||
if (pItemServices == NULL) {
|
||||
return false;
|
||||
}
|
||||
Offset::FnGiveNamedItem(pItemServices, fullWeaponName.c_str(), nullptr,
|
||||
nullptr, nullptr, nullptr);
|
||||
return true;
|
||||
}
|
||||
}; // namespace GameWeapons
|
||||
49
csgo2/weapon.h
Normal file
49
csgo2/weapon.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#include "head.h"
|
||||
class CCSPlayerController;
|
||||
namespace GameWeapons {
|
||||
|
||||
static const std::unordered_map<std::string, std::pair<std::string, int>>
|
||||
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
|
||||
Reference in New Issue
Block a user