DisableWeaponPickup & EnableWeaponPickup

This commit is contained in:
Diavolo 2022-06-25 20:22:13 +02:00
parent d08717f418
commit 7b67a6d087
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
5 changed files with 67 additions and 8 deletions

View File

@ -1,4 +1,4 @@
#include <StdInclude.hpp>
#include <STDInclude.hpp>
#include "AssetInterfaces/IFont_s.hpp"
#include "AssetInterfaces/IWeapon.hpp"

View File

@ -226,11 +226,11 @@ namespace Components
// Ook, ook, eek
Logger::Warning(Game::CON_CHANNEL_SERVER, "You are using deprecated {}", (*SVMapRotationCurrent)->name);
RotationData currentRotation;
RotationData rotationCurrent;
try
{
Logger::Debug("Parsing {}", (*SVMapRotationCurrent)->name);
currentRotation.parse(data);
rotationCurrent.parse(data);
}
catch (const std::exception& ex)
{
@ -239,14 +239,14 @@ namespace Components
Game::Dvar_SetString(*SVMapRotationCurrent, "");
if (currentRotation.getEntriesSize() == 0)
if (rotationCurrent.getEntriesSize() == 0)
{
Logger::Print(Game::CON_CHANNEL_SERVER, "{} is empty or contains invalid data. Restarting map\n", (*SVMapRotationCurrent)->name);
RestartCurrentMap();
return;
}
ApplyRotation(currentRotation);
ApplyRotation(rotationCurrent);
}
void MapRotation::RandomizeMapRotation()

View File

@ -448,10 +448,57 @@ namespace Components
}
}
void __declspec(naked) Weapon::WeaponEntCanBeGrabbed_Stub()
{
using namespace Game;
__asm
{
cmp dword ptr [esp + 0x8], 0x0
jz touched
push 0x56E82C
retn
touched:
test dword ptr [edi + 0x2BC], PWF_DISABLE_WEAPON_PICKUP
jnz exit_func
// Game code
test eax, eax
jz continue_func
exit_func:
xor eax, eax
ret
continue_func:
push 0x56E84C
retn
}
}
void Weapon::AddScriptMethods()
{
Script::AddMethod("DisableWeaponPickup", [](Game::scr_entref_t entref)
{
const auto* ent = Game::GetPlayerEntity(entref);
ent->client->ps.weapCommon.weapFlags |= Game::PWF_DISABLE_WEAPON_PICKUP;
});
Script::AddMethod("EnableWeaponPickup", [](Game::scr_entref_t entref)
{
const auto* ent = Game::GetPlayerEntity(entref);
ent->client->ps.weapCommon.weapFlags &= ~Game::PWF_DISABLE_WEAPON_PICKUP;
});
}
Weapon::Weapon()
{
Weapon::PatchLimit();
Weapon::PatchConfigStrings();
PatchLimit();
PatchConfigStrings();
// Intercept weapon loading
AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_WEAPON, Weapon::WeaponFileLoad);
@ -466,7 +513,7 @@ namespace Components
// Weapon swap fix
Utils::Hook::Nop(0x4B3670, 5);
Utils::Hook(0x57B4F0, LoadNoneWeaponHookStub).install()->quick();
Utils::Hook(0x57B4F0, LoadNoneWeaponHookStub, HOOK_JUMP).install()->quick();
// Don't load bounce sounds for now, it causes crashes
// TODO: Actually check the weaponfiles and/or reset the soundtable correctly!
@ -477,5 +524,10 @@ namespace Components
// Clear weapons independently from fs_game
//Utils::Hook::Nop(0x452C1D, 2);
//Utils::Hook::Nop(0x452C24, 5);
AddScriptMethods();
AssertOffset(Game::playerState_s, Game::playerState_s::weapCommon.weapFlags, 0x2BC);
Utils::Hook(0x56E825, WeaponEntCanBeGrabbed_Stub, HOOK_JUMP).install()->quick();
}
}

View File

@ -25,5 +25,8 @@ namespace Components
static void ParseConfigStrings();
static int ParseWeaponConfigStrings();
static int ClearConfigStrings(void* dest, int value, int size);
static void WeaponEntCanBeGrabbed_Stub();
static void AddScriptMethods();
};
}

View File

@ -1367,6 +1367,8 @@ namespace Game
PWF_DISABLE_WEAPON_SWAPPING = 1 << 11,
PWF_DISABLE_OFFHAND_WEAPONS = 1 << 12,
PWF_SWITCHING_TO_RIOTSHIELD = 1 << 13,
// IW5 flags backported
PWF_DISABLE_WEAPON_PICKUP = 1 << 16
};
struct playerState_s
@ -1491,6 +1493,8 @@ namespace Game
int stunTime;
};
static_assert(sizeof(Game::playerState_s) == 0x311C);
enum LocSelInputState
{
LOC_SEL_INPUT_NONE = 0x0,