完成
This commit is contained in:
@@ -465,6 +465,7 @@ public:
|
||||
|
||||
SCHEMA_FIELD(int, m_iAccount)
|
||||
};
|
||||
|
||||
class CBasePlayerPawn : public CBaseEntity {
|
||||
public:
|
||||
DECLARE_CLASS(CBasePlayerPawn);
|
||||
@@ -473,7 +474,16 @@ public:
|
||||
SCHEMA_FIELD(CPlayer_WeaponServices*, m_pWeaponServices)
|
||||
SCHEMA_FIELD(uint8_t**, m_pItemServices)
|
||||
};
|
||||
class CCSPlayerPawn : public CBasePlayerPawn {
|
||||
// Size: 0x1568
|
||||
class CCSPlayerPawnBase : public CBasePlayerPawn
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS(CCSPlayerPawnBase);
|
||||
SCHEMA_FIELD(bool, m_bRespawning)
|
||||
SCHEMA_FIELD(int, m_ArmorValue)
|
||||
|
||||
};
|
||||
class CCSPlayerPawn : public CCSPlayerPawnBase {
|
||||
public:
|
||||
DECLARE_CLASS(CCSPlayerPawn);
|
||||
SCHEMA_FIELD(const char*, m_szLastPlaceName)
|
||||
|
||||
@@ -61,11 +61,14 @@ auto luaApi_SetPlayerCurrentWeaponAmmo(lua_State* luaVm) -> int {
|
||||
break;
|
||||
}
|
||||
auto playerController = reinterpret_cast<CCSPlayerController*>(player);
|
||||
const auto weaponServices = playerController->m_hPawn().Get<CCSPlayerPawn>()->m_pWeaponServices();
|
||||
const auto weaponServices = playerController->m_hPawn()
|
||||
.Get<CCSPlayerPawn>()
|
||||
->m_pWeaponServices();
|
||||
if (weaponServices == nullptr) {
|
||||
break;
|
||||
}
|
||||
const auto activeWeapon = weaponServices->m_hActiveWeapon().Get<CBasePlayerWeapon>();
|
||||
const auto activeWeapon =
|
||||
weaponServices->m_hActiveWeapon().Get<CBasePlayerWeapon>();
|
||||
if (activeWeapon == nullptr) {
|
||||
break;
|
||||
}
|
||||
@@ -79,6 +82,124 @@ auto luaApi_SetPlayerCurrentWeaponAmmo(lua_State* luaVm) -> int {
|
||||
lua_pop(luaVm, 3);
|
||||
return 0;
|
||||
}
|
||||
auto luaApi_RespawnPlayer(lua_State* luaVm) -> int {
|
||||
const auto playerIndex = lua_tointeger(luaVm, 1);
|
||||
int playerArmorValue = 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);
|
||||
auto playerPawn = playerController->m_hPawn().Get<CCSPlayerPawn>();
|
||||
playerPawn->m_bRespawning(false);
|
||||
} while (false);
|
||||
lua_pop(luaVm, 1);
|
||||
return 0;
|
||||
}
|
||||
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();
|
||||
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>();
|
||||
playerPawn->m_ArmorValue(playerArmorValue);
|
||||
} while (false);
|
||||
lua_pop(luaVm, 2);
|
||||
return 0;
|
||||
}
|
||||
auto luaApi_GetPlayerArmorValue(lua_State* luaVm) -> int {
|
||||
const auto playerIndex = lua_tointeger(luaVm, 1);
|
||||
int playerArmorValue = 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);
|
||||
auto playerPawn = playerController->m_hPawn().Get<CCSPlayerPawn>();
|
||||
playerArmorValue = playerPawn->m_ArmorValue();
|
||||
} while (false);
|
||||
lua_pop(luaVm, 1);
|
||||
lua_pushinteger(luaVm, playerArmorValue);
|
||||
return 1;
|
||||
}
|
||||
auto luaApi_GetPlayerHealth(lua_State* luaVm) -> int {
|
||||
const auto playerIndex = lua_tointeger(luaVm, 1);
|
||||
int playerHealth = 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);
|
||||
playerHealth = playerController->m_iHealth();
|
||||
} while (false);
|
||||
lua_pop(luaVm, 1);
|
||||
lua_pushinteger(luaVm, playerHealth);
|
||||
return 1;
|
||||
}
|
||||
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();
|
||||
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;
|
||||
}
|
||||
LOG("luaApi_SetPlayerHealth :3 \n");
|
||||
|
||||
auto playerController = reinterpret_cast<CCSPlayerController*>(player);
|
||||
playerController->m_iHealth(playerHealth);
|
||||
} while (false);
|
||||
lua_pop(luaVm, 2);
|
||||
return 0;
|
||||
}
|
||||
auto luaApi_GetPlayerCurrentWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo {
|
||||
// param: playerIndex:int
|
||||
const auto playerIndex = lua_tointeger(luaVm, 1);
|
||||
@@ -97,11 +218,14 @@ auto luaApi_GetPlayerCurrentWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo {
|
||||
break;
|
||||
}
|
||||
auto playerController = reinterpret_cast<CCSPlayerController*>(player);
|
||||
const auto weaponServices = playerController->m_hPawn().Get<CCSPlayerPawn>()->m_pWeaponServices();
|
||||
const auto weaponServices = playerController->m_hPawn()
|
||||
.Get<CCSPlayerPawn>()
|
||||
->m_pWeaponServices();
|
||||
if (weaponServices == nullptr) {
|
||||
break;
|
||||
}
|
||||
const auto activeWeapon = weaponServices->m_hActiveWeapon().Get<CBasePlayerWeapon>();
|
||||
const auto activeWeapon =
|
||||
weaponServices->m_hActiveWeapon().Get<CBasePlayerWeapon>();
|
||||
if (activeWeapon == nullptr) {
|
||||
break;
|
||||
}
|
||||
@@ -117,7 +241,8 @@ auto luaApi_GetPlayerCurrentWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo {
|
||||
if (itemView == nullptr) {
|
||||
break;
|
||||
}
|
||||
const char* checkWeaponName = Offset::InterFaces::ILocalize->FindSafe(itemStaticData->m_pszItemBaseName);
|
||||
const char* checkWeaponName = Offset::InterFaces::ILocalize->FindSafe(
|
||||
itemStaticData->m_pszItemBaseName);
|
||||
if (checkWeaponName == nullptr || strlen(checkWeaponName) < 1) {
|
||||
break;
|
||||
}
|
||||
@@ -125,24 +250,38 @@ auto luaApi_GetPlayerCurrentWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo {
|
||||
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));
|
||||
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>
|
||||
lua_register(luaVm, "luaApi_SetPlayerCurrentWeaponAmmo",
|
||||
luaApi_SetPlayerCurrentWeaponAmmo);
|
||||
lua_register(luaVm, "luaApi_GetPlayerHealth", luaApi_GetPlayerHealth);
|
||||
lua_register(luaVm, "luaApi_SetPlayerHealth", luaApi_SetPlayerHealth);
|
||||
lua_register(luaVm, "luaApi_GetPlayerArmorValue",
|
||||
luaApi_GetPlayerArmorValue);
|
||||
lua_register(luaVm, "luaApi_SetPlayerArmorValue",
|
||||
luaApi_SetPlayerArmorValue);
|
||||
lua_register(luaVm, "luaApi_RespawnPlayer", luaApi_RespawnPlayer);
|
||||
|
||||
// <20>Ҳ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD>
|
||||
luabridge::getGlobalNamespace(luaVm)
|
||||
.beginClass<_luaApi_WeaponInfo>("WeaponInfo")
|
||||
.addConstructor<void(*) (void)>()
|
||||
.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);
|
||||
.addFunction("luaApi_GetPlayerCurrentWeaponInfo",
|
||||
&luaApi_GetPlayerCurrentWeaponInfo);
|
||||
}
|
||||
}; // namespace ScriptApis
|
||||
|
||||
@@ -54,6 +54,18 @@ auto initLuaScripts() -> void {
|
||||
}
|
||||
LOG("execute: %s\n", file.c_str());
|
||||
|
||||
std::string scriptDir = dirPath;
|
||||
lua_getglobal(L, "package");
|
||||
lua_getfield(L, -1, "path"); // get field "path" from table at top of stack (-1)
|
||||
std::string cur_path = lua_tostring(L, -1); // grab path string from top of stack
|
||||
cur_path.append(";"); // do your path magic here
|
||||
cur_path.append(scriptDir);
|
||||
cur_path.append("\\?.lua");
|
||||
lua_pop(L, 1); // get rid of the string on the stack we just pushed on line 5
|
||||
lua_pushstring(L, cur_path.c_str()); // push the new one
|
||||
lua_setfield(L, -2, "path"); // set the field "path" in table at -2 with value at top of stack
|
||||
lua_pop(L, 1); // get rid of package table from top of stack
|
||||
|
||||
if (luaL_dofile(L, file.c_str())) {
|
||||
LOG("dofile_err:%s\n\n", lua_tostring(L, -1));
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user