This commit is contained in:
Huoji's
2023-10-05 04:24:29 +08:00
parent eba91d741a
commit 40fc60e481

View File

@@ -34,6 +34,25 @@ auto TimerCallBack(_GameTimer* timer) -> void {
luaL_unref(timer->m_luaVm, LUA_REGISTRYINDEX, timer->m_iParamIndex); luaL_unref(timer->m_luaVm, LUA_REGISTRYINDEX, timer->m_iParamIndex);
} }
} }
auto ExcutePlayerAction(int playerIndex,
std::function<void(CCSPlayerController*)> function)
-> void {
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);
function(playerController);
} while (false);
}
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>Ҫ<EFBFBD>Լ<EFBFBD>push<73><68>stack<63><6B> // <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>Ҫ<EFBFBD>Լ<EFBFBD>push<73><68>stack<63><6B>
auto luaApi_ListenToGameEvent(lua_State* luaVm) -> int { auto luaApi_ListenToGameEvent(lua_State* luaVm) -> int {
const auto eventName = lua_tostring(luaVm, 1); const auto eventName = lua_tostring(luaVm, 1);
@@ -69,30 +88,17 @@ auto luaApi_SetPlayerCurrentWeaponAmmo(lua_State* luaVm) -> int {
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
const auto playerAmmoNum = lua_tointeger(luaVm, 2); const auto playerAmmoNum = lua_tointeger(luaVm, 2);
const auto playerReserveAmmoNum = lua_tointeger(luaVm, 3); const auto playerReserveAmmoNum = lua_tointeger(luaVm, 3);
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
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);
const auto weaponServices = playerController->m_hPawn() const auto weaponServices = playerController->m_hPawn()
.Get<CCSPlayerPawn>() .Get<CCSPlayerPawn>()
->m_pWeaponServices(); ->m_pWeaponServices();
if (weaponServices == nullptr) { if (weaponServices == nullptr) {
break; return;
} }
const auto activeWeapon = const auto activeWeapon =
weaponServices->m_hActiveWeapon().Get<CBasePlayerWeapon>(); weaponServices->m_hActiveWeapon().Get<CBasePlayerWeapon>();
if (activeWeapon == nullptr) { if (activeWeapon == nullptr) {
break; return;
} }
if (playerAmmoNum != -1) { if (playerAmmoNum != -1) {
activeWeapon->m_iClip1(playerAmmoNum); activeWeapon->m_iClip1(playerAmmoNum);
@@ -100,77 +106,41 @@ auto luaApi_SetPlayerCurrentWeaponAmmo(lua_State* luaVm) -> int {
if (playerReserveAmmoNum != -1) { if (playerReserveAmmoNum != -1) {
activeWeapon->m_pReserveAmmo(playerReserveAmmoNum); activeWeapon->m_pReserveAmmo(playerReserveAmmoNum);
} }
} while (false); });
lua_pop(luaVm, 3); lua_pop(luaVm, 3);
return 0; return 0;
} }
auto luaApi_RespawnPlayer(lua_State* luaVm) -> int { auto luaApi_RespawnPlayer(lua_State* luaVm) -> int {
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
int playerArmorValue = 0; int playerArmorValue = 0;
CGameEntitySystem* EntitySystem = global::EntitySystem; ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
do { const auto playerPawn =
if (EntitySystem == nullptr || playerIndex == 0) { playerController->m_hPawn().Get<CCSPlayerPawn>();
break; if (playerPawn == nullptr) {
return;
} }
auto player = EntitySystem->GetBaseEntity(playerIndex);
if (player == nullptr) {
break;
}
if (player->IsBasePlayerController() == false) {
break;
}
auto playerController = reinterpret_cast<CCSPlayerController*>(player);
auto playerPawn = playerController->m_hPawn().Get<CCSPlayerPawn>();
LOG("respawn player: %llx \n", playerPawn); LOG("respawn player: %llx \n", playerPawn);
Offset::FnRespawnPlayer(playerPawn); Offset::FnRespawnPlayer(playerPawn);
// playerPawn->ForceRespawnPlayer(); });
} while (false);
lua_pop(luaVm, 1);
return 0; return 0;
} }
auto luaApi_SetPlayerArmorValue(lua_State* luaVm) -> int { auto luaApi_SetPlayerArmorValue(lua_State* luaVm) -> int {
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
const auto playerArmorValue = lua_tointeger(luaVm, 2); const auto playerArmorValue = lua_tointeger(luaVm, 2);
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
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);
auto playerPawn = playerController->m_hPawn().Get<CCSPlayerPawn>(); auto playerPawn = playerController->m_hPawn().Get<CCSPlayerPawn>();
playerPawn->m_ArmorValue(playerArmorValue); playerPawn->m_ArmorValue(playerArmorValue);
} while (false); });
lua_pop(luaVm, 2); lua_pop(luaVm, 2);
return 0; return 0;
} }
auto luaApi_GetPlayerArmorValue(lua_State* luaVm) -> int { auto luaApi_GetPlayerArmorValue(lua_State* luaVm) -> int {
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
int playerArmorValue = 0; int playerArmorValue = 0;
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
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);
auto playerPawn = playerController->m_hPawn().Get<CCSPlayerPawn>(); auto playerPawn = playerController->m_hPawn().Get<CCSPlayerPawn>();
playerArmorValue = playerPawn->m_ArmorValue(); playerArmorValue = playerPawn->m_ArmorValue();
} while (false); });
lua_pop(luaVm, 1); lua_pop(luaVm, 1);
lua_pushinteger(luaVm, playerArmorValue); lua_pushinteger(luaVm, playerArmorValue);
return 1; return 1;
@@ -178,23 +148,10 @@ auto luaApi_GetPlayerArmorValue(lua_State* luaVm) -> int {
auto luaApi_GetPlayerHealth(lua_State* luaVm) -> int { auto luaApi_GetPlayerHealth(lua_State* luaVm) -> int {
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
int playerHealth = 0; int playerHealth = 0;
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
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);
auto playerPawn = playerController->m_hPawn().Get<CCSPlayerPawn>(); auto playerPawn = playerController->m_hPawn().Get<CCSPlayerPawn>();
playerHealth = playerPawn->m_iHealth(); playerHealth = playerPawn->m_iHealth();
} while (false); });
lua_pop(luaVm, 1); lua_pop(luaVm, 1);
lua_pushinteger(luaVm, playerHealth); lua_pushinteger(luaVm, playerHealth);
return 1; return 1;
@@ -202,24 +159,9 @@ auto luaApi_GetPlayerHealth(lua_State* luaVm) -> int {
auto luaApi_SetPlayerHealth(lua_State* luaVm) -> int { auto luaApi_SetPlayerHealth(lua_State* luaVm) -> int {
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
const auto playerHealth = lua_tointeger(luaVm, 2); const auto playerHealth = lua_tointeger(luaVm, 2);
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
CGameEntitySystem* EntitySystem = global::EntitySystem;
do {
if (EntitySystem == nullptr || playerIndex == 0) {
break;
}
LOG("luaApi_SetPlayerHealth :2 \n");
auto player = EntitySystem->GetBaseEntity(playerIndex);
if (player == nullptr) {
break;
}
if (player->IsBasePlayerController() == false) {
break;
}
auto playerController = reinterpret_cast<CCSPlayerController*>(player);
playerController->m_hPawn().Get()->m_iHealth(playerHealth); playerController->m_hPawn().Get()->m_iHealth(playerHealth);
} while (false); });
lua_pop(luaVm, 2); lua_pop(luaVm, 2);
return 0; return 0;
} }
@@ -227,23 +169,11 @@ auto luaApi_GetPlayerWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo {
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
const auto weaponIndex = lua_tointeger(luaVm, 2); const auto weaponIndex = lua_tointeger(luaVm, 2);
_luaApi_WeaponInfo info{0}; _luaApi_WeaponInfo info{0};
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
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);
const auto weaponServices = playerController->m_hPawn() const auto weaponServices = playerController->m_hPawn()
.Get<CCSPlayerPawn>() .Get<CCSPlayerPawn>()
->m_pWeaponServices(); ->m_pWeaponServices();
do {
if (weaponServices == nullptr) { if (weaponServices == nullptr) {
break; break;
} }
@@ -260,7 +190,8 @@ auto luaApi_GetPlayerWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo {
if (weapon == nullptr) { if (weapon == nullptr) {
continue; continue;
} }
const auto weaponIndex = weapon->GetRefEHandle().GetEntryIndex(); const auto weaponIndex =
weapon->GetRefEHandle().GetEntryIndex();
if (weaponIndex != weaponIndex) { if (weaponIndex != weaponIndex) {
continue; continue;
} }
@@ -281,7 +212,8 @@ auto luaApi_GetPlayerWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo {
if (itemView == nullptr) { if (itemView == nullptr) {
break; break;
} }
const char* checkWeaponName = Offset::InterFaces::ILocalize->FindSafe( const char* checkWeaponName =
Offset::InterFaces::ILocalize->FindSafe(
itemStaticData->m_pszItemBaseName); itemStaticData->m_pszItemBaseName);
if (checkWeaponName == nullptr || strlen(checkWeaponName) < 1) { if (checkWeaponName == nullptr || strlen(checkWeaponName) < 1) {
break; break;
@@ -291,33 +223,23 @@ auto luaApi_GetPlayerWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo {
info.ReserveAmmo = activeWeapon->m_pReserveAmmo(); info.ReserveAmmo = activeWeapon->m_pReserveAmmo();
info.weaponName = itemStaticData->GetSimpleWeaponName(); info.weaponName = itemStaticData->GetSimpleWeaponName();
info.weaponBaseName = itemStaticData->m_pszItemBaseName; info.weaponBaseName = itemStaticData->m_pszItemBaseName;
info.weaponType = static_cast<int>( info.weaponType =
itemStaticData->IsKnife(false) static_cast<int>(itemStaticData->IsKnife(false)
? _luaApi_WeaponType::kKnife ? _luaApi_WeaponType::kKnife
: (itemStaticData->IsWeapon() ? _luaApi_WeaponType::kGun : (itemStaticData->IsWeapon()
? _luaApi_WeaponType::kGun
: _luaApi_WeaponType::kOther)); : _luaApi_WeaponType::kOther));
info.weaponIndex = weaponIndex; info.weaponIndex = weaponIndex;
} while (false); } while (false);
});
return info; return info;
} }
auto luaApi_GetPlayerCurrentWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo { auto luaApi_GetPlayerCurrentWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo {
// param: playerIndex:int // param: playerIndex:int
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
_luaApi_WeaponInfo info{0}; _luaApi_WeaponInfo info{0};
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
CGameEntitySystem* EntitySystem = global::EntitySystem;
do { 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);
const auto weaponServices = playerController->m_hPawn() const auto weaponServices = playerController->m_hPawn()
.Get<CCSPlayerPawn>() .Get<CCSPlayerPawn>()
->m_pWeaponServices(); ->m_pWeaponServices();
@@ -341,7 +263,8 @@ auto luaApi_GetPlayerCurrentWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo {
if (itemView == nullptr) { if (itemView == nullptr) {
break; break;
} }
const char* checkWeaponName = Offset::InterFaces::ILocalize->FindSafe( const char* checkWeaponName =
Offset::InterFaces::ILocalize->FindSafe(
itemStaticData->m_pszItemBaseName); itemStaticData->m_pszItemBaseName);
if (checkWeaponName == nullptr || strlen(checkWeaponName) < 1) { if (checkWeaponName == nullptr || strlen(checkWeaponName) < 1) {
break; break;
@@ -352,16 +275,19 @@ auto luaApi_GetPlayerCurrentWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo {
info.weaponName = itemStaticData->GetSimpleWeaponName(); info.weaponName = itemStaticData->GetSimpleWeaponName();
info.weaponBaseName = itemStaticData->m_pszItemBaseName; info.weaponBaseName = itemStaticData->m_pszItemBaseName;
info.weaponType = static_cast<int>( info.weaponType =
itemStaticData->IsKnife(false) static_cast<int>(itemStaticData->IsKnife(false)
? _luaApi_WeaponType::kKnife ? _luaApi_WeaponType::kKnife
: (itemStaticData->IsWeapon() ? _luaApi_WeaponType::kGun : (itemStaticData->IsWeapon()
? _luaApi_WeaponType::kGun
: _luaApi_WeaponType::kOther)); : _luaApi_WeaponType::kOther));
info.weaponIndex = weaponServices->m_hActiveWeapon() info.weaponIndex = weaponServices->m_hActiveWeapon()
.Get() .Get()
->GetRefEHandle() ->GetRefEHandle()
.GetEntryIndex(); .GetEntryIndex();
} while (false); } while (false);
});
return info; return info;
} }
auto luaApi_CreateTickRunFunction(lua_State* luaVm) -> int { auto luaApi_CreateTickRunFunction(lua_State* luaVm) -> int {
@@ -422,22 +348,9 @@ auto luaApi_CheckPlayerIsAlive(lua_State* luaVm) -> int {
// param: playerIndex:int // param: playerIndex:int
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
auto isAlive = false; auto isAlive = false;
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
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);
isAlive = playerController->m_bPawnIsAlive(); isAlive = playerController->m_bPawnIsAlive();
} while (false); });
lua_pop(luaVm, 1); lua_pop(luaVm, 1);
lua_pushboolean(luaVm, isAlive); lua_pushboolean(luaVm, isAlive);
return 1; return 1;
@@ -446,22 +359,9 @@ auto luaApi_GetPlayerTeam(lua_State* luaVm) -> int {
// param: playerIndex:int // param: playerIndex:int
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
auto team = 0; auto team = 0;
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
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);
team = playerController->m_iTeamNum(); team = playerController->m_iTeamNum();
} while (false); });
lua_pop(luaVm, 1); lua_pop(luaVm, 1);
lua_pushinteger(luaVm, team); lua_pushinteger(luaVm, team);
return 1; return 1;
@@ -471,23 +371,10 @@ auto luaApi_SetPlayerTeam(lua_State* luaVm) -> int {
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
const auto team = lua_tointeger(luaVm, 2); const auto team = lua_tointeger(luaVm, 2);
auto isSuccess = false; auto isSuccess = false;
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
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);
playerController->m_iTeamNum(team); playerController->m_iTeamNum(team);
isSuccess = true; isSuccess = true;
} while (false); });
lua_pop(luaVm, 2); lua_pop(luaVm, 2);
lua_pushboolean(luaVm, isSuccess); lua_pushboolean(luaVm, isSuccess);
return 1; return 1;
@@ -496,21 +383,10 @@ auto luaApi_CheckPlayerIsInServer(lua_State* luaVm) -> int {
// param: playerIndex:int // param: playerIndex:int
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
auto isInServer = false; auto isInServer = false;
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
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;
}
isInServer = true; isInServer = true;
} while (false); });
lua_pop(luaVm, 1); lua_pop(luaVm, 1);
lua_pushboolean(luaVm, isInServer); lua_pushboolean(luaVm, isInServer);
return 1; return 1;
@@ -520,23 +396,10 @@ auto luaApi_GivePlayerWeapon(lua_State* luaVm) -> int {
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
const auto weaponName = lua_tostring(luaVm, 2); const auto weaponName = lua_tostring(luaVm, 2);
auto isSuccess = false; auto isSuccess = false;
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
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 = isSuccess =
GameWeapons::ParseWeaponCommand(playerController, weaponName); GameWeapons::ParseWeaponCommand(playerController, weaponName);
} while (false); });
lua_pop(luaVm, 2); lua_pop(luaVm, 2);
lua_pushboolean(luaVm, isSuccess); lua_pushboolean(luaVm, isSuccess);
return 1; return 1;
@@ -545,20 +408,8 @@ auto luApi_GetPlayerAllWeaponIndex(lua_State* luaVm) -> int {
// param: playerIndex:int // param: playerIndex:int
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
auto isSuccess = false; auto isSuccess = false;
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
CGameEntitySystem* EntitySystem = global::EntitySystem;
do { 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);
const auto weaponServices = playerController->m_hPawn() const auto weaponServices = playerController->m_hPawn()
.Get<CCSPlayerPawn>() .Get<CCSPlayerPawn>()
->m_pWeaponServices(); ->m_pWeaponServices();
@@ -577,7 +428,8 @@ auto luApi_GetPlayerAllWeaponIndex(lua_State* luaVm) -> int {
if (weapon == nullptr) { if (weapon == nullptr) {
continue; continue;
} }
const auto weaponIndex = weapon->GetRefEHandle().GetEntryIndex(); const auto weaponIndex =
weapon->GetRefEHandle().GetEntryIndex();
// Push the index and then the value onto the stack // Push the index and then the value onto the stack
lua_pushinteger(luaVm, index++); lua_pushinteger(luaVm, index++);
@@ -589,14 +441,13 @@ auto luApi_GetPlayerAllWeaponIndex(lua_State* luaVm) -> int {
} }
isSuccess = true; isSuccess = true;
} while (false); } while (false);
});
if (!isSuccess) { if (!isSuccess) {
// If unsuccessful, remove the table from the stack // If unsuccessful, remove the table from the stack
lua_pop(luaVm, 1); lua_pop(luaVm, 1);
// And push false instead
lua_pushboolean(luaVm, isSuccess);
} }
lua_pushboolean(luaVm, isSuccess);
// Return the number of results (either the table or false) // Return the number of results (either the table or false)
return 1; return 1;
} }
@@ -605,20 +456,8 @@ auto luaApi_RemovePlayerWeapon(lua_State* luaVm) -> int {
const auto playerIndex = lua_tointeger(luaVm, 1); const auto playerIndex = lua_tointeger(luaVm, 1);
const auto weaponIndex = lua_tointeger(luaVm, 2); const auto weaponIndex = lua_tointeger(luaVm, 2);
auto isSuccess = false; auto isSuccess = false;
ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) {
CGameEntitySystem* EntitySystem = global::EntitySystem;
do { 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);
const auto weaponServices = playerController->m_hPawn() const auto weaponServices = playerController->m_hPawn()
.Get<CCSPlayerPawn>() .Get<CCSPlayerPawn>()
->m_pWeaponServices(); ->m_pWeaponServices();
@@ -642,9 +481,12 @@ auto luaApi_RemovePlayerWeapon(lua_State* luaVm) -> int {
break; break;
} }
weaponServices->RemoveWeapon(activeWeapon); weaponServices->RemoveWeapon(activeWeapon);
Offset::FnEntityRemove(global::EntitySystem, activeWeapon, nullptr, -1); Offset::FnEntityRemove(global::EntitySystem, activeWeapon, nullptr,
-1);
isSuccess = true; isSuccess = true;
} while (false); } while (false);
});
lua_pop(luaVm, 2); lua_pop(luaVm, 2);
lua_pushboolean(luaVm, isSuccess); lua_pushboolean(luaVm, isSuccess);
return 1; return 1;