大改
This commit is contained in:
@@ -1,4 +1,16 @@
|
||||
#include "script_apis.h"
|
||||
enum class _luaApi_WeaponType {
|
||||
kOther,
|
||||
kKnife,
|
||||
kGun,
|
||||
};
|
||||
struct _luaApi_WeaponInfo {
|
||||
bool isSuccess;
|
||||
int Ammo;
|
||||
int ReserveAmmo;
|
||||
std::string weaponName;
|
||||
int weaponType;
|
||||
};
|
||||
namespace ScriptApis {
|
||||
// <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 {
|
||||
@@ -21,7 +33,8 @@ auto luaApi_ListenToGameEvent(lua_State* luaVm) -> int {
|
||||
}
|
||||
// <20><><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD>ӵ<EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD>
|
||||
std::unique_lock lock(ScriptCallBacks::mutex_callbackList);
|
||||
ScriptCallBacks::callbackList[luaVm][callbackType] = luaL_ref(luaVm, LUA_REGISTRYINDEX);
|
||||
ScriptCallBacks::callbackList[luaVm][callbackType] =
|
||||
luaL_ref(luaVm, LUA_REGISTRYINDEX);
|
||||
|
||||
LOG("luaApi_ListenToGameEvent eventName:%s callback added\n",
|
||||
eventName);
|
||||
@@ -30,7 +43,106 @@ auto luaApi_ListenToGameEvent(lua_State* luaVm) -> int {
|
||||
lua_pop(luaVm, 2); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ
|
||||
return 0;
|
||||
}
|
||||
auto luaApi_SetPlayerCurrentWeaponAmmo(lua_State* luaVm) -> int {
|
||||
const auto playerIndex = lua_tointeger(luaVm, 1);
|
||||
const auto playerAmmoNum = lua_tointeger(luaVm, 2);
|
||||
const auto playerReserveAmmoNum = lua_tointeger(luaVm, 3);
|
||||
|
||||
CGameEntitySystem* EntitySystem = CGameEntitySystem::GetInstance();
|
||||
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().Get<CCSPlayerPawn>()->m_pWeaponServices();
|
||||
if (weaponServices == nullptr) {
|
||||
break;
|
||||
}
|
||||
const auto activeWeapon = weaponServices->m_hActiveWeapon().Get<CBasePlayerWeapon>();
|
||||
if (activeWeapon == nullptr) {
|
||||
break;
|
||||
}
|
||||
if (playerAmmoNum != -1) {
|
||||
activeWeapon->m_iClip1(playerAmmoNum);
|
||||
}
|
||||
if (playerReserveAmmoNum != -1) {
|
||||
activeWeapon->m_pReserveAmmo(playerReserveAmmoNum);
|
||||
}
|
||||
} while (false);
|
||||
lua_pop(luaVm, 3);
|
||||
return 0;
|
||||
}
|
||||
auto luaApi_GetPlayerCurrentWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo {
|
||||
// param: playerIndex:int
|
||||
const auto playerIndex = lua_tointeger(luaVm, 1);
|
||||
_luaApi_WeaponInfo info{0};
|
||||
|
||||
CGameEntitySystem* EntitySystem = CGameEntitySystem::GetInstance();
|
||||
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().Get<CCSPlayerPawn>()->m_pWeaponServices();
|
||||
if (weaponServices == nullptr) {
|
||||
break;
|
||||
}
|
||||
const auto activeWeapon = weaponServices->m_hActiveWeapon().Get<CBasePlayerWeapon>();
|
||||
if (activeWeapon == nullptr) {
|
||||
break;
|
||||
}
|
||||
const auto attributeManager = activeWeapon->m_AttributeManager();
|
||||
if (activeWeapon == nullptr) {
|
||||
break;
|
||||
}
|
||||
const auto itemView = attributeManager->m_Item();
|
||||
if (itemView == nullptr) {
|
||||
break;
|
||||
}
|
||||
const auto itemStaticData = itemView->GetStaticData();
|
||||
if (itemView == nullptr) {
|
||||
break;
|
||||
}
|
||||
const char* checkWeaponName = Offset::InterFaces::ILocalize->FindSafe(itemStaticData->m_pszItemBaseName);
|
||||
if (checkWeaponName == nullptr || strlen(checkWeaponName) < 1) {
|
||||
break;
|
||||
}
|
||||
info.isSuccess = true;
|
||||
info.Ammo = activeWeapon->m_iClip1();
|
||||
info.ReserveAmmo = activeWeapon->m_pReserveAmmo();
|
||||
info.weaponName = itemStaticData->GetSimpleWeaponName();
|
||||
info.weaponType = static_cast<int>(itemStaticData->IsKnife(false) ? _luaApi_WeaponType::kKnife : (itemStaticData->IsWeapon() ? _luaApi_WeaponType::kGun : _luaApi_WeaponType::kOther));
|
||||
} while (false);
|
||||
|
||||
return info;
|
||||
}
|
||||
auto initFunciton(lua_State* luaVm) -> void {
|
||||
lua_register(luaVm, "ListenToGameEvent", luaApi_ListenToGameEvent);
|
||||
lua_register(luaVm, "luaApi_SetPlayerCurrentWeaponAmmo", luaApi_SetPlayerCurrentWeaponAmmo);
|
||||
//<2F>Ҳ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD>
|
||||
luabridge::getGlobalNamespace(luaVm)
|
||||
.beginClass<_luaApi_WeaponInfo>("WeaponInfo")
|
||||
.addConstructor<void(*) (void)>()
|
||||
.addData("isSuccess", &_luaApi_WeaponInfo::isSuccess)
|
||||
.addData("Ammo", &_luaApi_WeaponInfo::Ammo)
|
||||
.addData("ReserveAmmo", &_luaApi_WeaponInfo::ReserveAmmo)
|
||||
.addData("weaponName", &_luaApi_WeaponInfo::weaponName)
|
||||
.addData("weaponType", &_luaApi_WeaponInfo::weaponType)
|
||||
.endClass()
|
||||
.addFunction("luaApi_GetPlayerCurrentWeaponInfo", &luaApi_GetPlayerCurrentWeaponInfo);
|
||||
}
|
||||
}; // namespace ScriptApis
|
||||
|
||||
Reference in New Issue
Block a user