Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Damage misc stuff #80

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CS2Fixes.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
<ClInclude Include="src\cs2_sdk\entity\ccsplayerpawn.h" />
<ClInclude Include="src\cs2_sdk\entity\ccsweaponbase.h" />
<ClInclude Include="src\cs2_sdk\entity\cgamerules.h" />
<ClInclude Include="src\cs2_sdk\entity\ctakedamageinfo.h" />
<ClInclude Include="src\cs2_sdk\entity\globaltypes.h" />
<ClInclude Include="src\cs2_sdk\entity\services.h" />
<ClInclude Include="src\cs2_sdk\interfaces\cgameresourceserviceserver.h" />
Expand Down
29 changes: 16 additions & 13 deletions CS2Fixes.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\utils\entity.cpp">
<Filter>Source Files\cs2_sdk\entity</Filter>
<Filter>Source Files\utils</Filter>
</ClCompile>
<ClCompile Include="src\events.cpp">
<Filter>Source Files</Filter>
Expand Down Expand Up @@ -151,12 +151,6 @@
<ClInclude Include="src\cs2_sdk\entity\ccollisionproperty.h">
<Filter>Header Files\cs2_sdk\entity</Filter>
</ClInclude>
<ClInclude Include="src\cs2_sdk\entity\centityidentity.h">
<Filter>Header Files\cs2_sdk\entity</Filter>
</ClInclude>
<ClInclude Include="src\cs2_sdk\entity\cglowproperty.h">
<Filter>Header Files\cs2_sdk\entity</Filter>
</ClInclude>
<ClInclude Include="src\cs2_sdk\entity\cbasemodelentity.h">
<Filter>Header Files\cs2_sdk\entity</Filter>
</ClInclude>
Expand Down Expand Up @@ -184,9 +178,6 @@
<ClInclude Include="src\recipientfilters.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\utils\entity.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\adminsystem.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand All @@ -199,8 +190,20 @@
<ClInclude Include="src\httpmanager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\votemanager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\votemanager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\cs2_sdk\entity\globaltypes.h">
<Filter>Header Files\cs2_sdk\entity</Filter>
</ClInclude>
<ClInclude Include="src\cs2_sdk\entity\cgamerules.h">
<Filter>Header Files\cs2_sdk\entity</Filter>
</ClInclude>
<ClInclude Include="src\utils\entity.h">
<Filter>Header Files\utils</Filter>
</ClInclude>
<ClInclude Include="src\cs2_sdk\entity\ctakedamageinfo.h">
<Filter>Header Files\cs2_sdk\entity</Filter>
</ClInclude>
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions gamedata/cs2fixes.games.txt
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@
"windows" "\x48\x81\xEC\x88\x2A\x2A\x2A\x4D\x85\xC0"
"linux" "\x48\x85\xD2\x74\x2A\x55\x48\x89\xE5\x41\x54"
}

// "CBaseEntity::TakeDamageOld"
"CBaseEntity_TakeDamageOld"
{
"library" "server"
"windows" "\x40\x56\x57\x48\x83\xEC\x58\x48\x8B\x41\x10"
"linux" "\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x41\x54\x49\x89\xFC\x53\x48\x83\xEC\x38\x4C\x8D\x2D\x6D\x70\x08\x01"
}
}
"Offsets"
{
Expand Down
2 changes: 1 addition & 1 deletion sdk
53 changes: 53 additions & 0 deletions src/adminsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,59 @@ CON_COMMAND_CHAT_FLAGS(slay, "slay a player", ADMFLAG_SLAY)
PrintMultiAdminAction(nType, pszCommandPlayerName, "slayed");
}

CON_COMMAND_CHAT_FLAGS(slap, "slap a player", ADMFLAG_SLAY)
{
if (args.ArgC() < 2)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !slap <name> <optional damage>");
return;
}

int iCommandPlayer = player ? player->GetPlayerSlot() : -1;
int iNumClients = 0;
int pSlots[MAXPLAYERS];

ETargetType nType = g_playerManager->TargetPlayerString(iCommandPlayer, args[1], iNumClients, pSlots);

if (!iNumClients)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Target not found.");
return;
}

const char *pszCommandPlayerName = player ? player->GetPlayerName() : "Console";

for (int i = 0; i < iNumClients; i++)
{
CBasePlayerController *pTarget = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlots[i] + 1));

if (!pTarget)
continue;

CBasePlayerPawn *pPawn = pTarget->m_hPawn();

if (!pPawn)
continue;

// Taken directly from sourcemod
Vector velocity = pPawn->m_vecAbsVelocity;
velocity.x += ((rand() % 180) + 50) * (((rand() % 2) == 1) ? -1 : 1);
velocity.y += ((rand() % 180) + 50) * (((rand() % 2) == 1) ? -1 : 1);
velocity.z += rand() % 200 + 100;
pPawn->SetAbsVelocity(velocity);

int iDamage = V_StringToInt32(args[2], 0);

if (iDamage > 0)
pPawn->TakeDamage(iDamage);

if (nType < ETargetType::ALL)
PrintSingleAdminAction(pszCommandPlayerName, pTarget->GetPlayerName(), "slapped");
}

PrintMultiAdminAction(nType, pszCommandPlayerName, "slapped");
}

CON_COMMAND_CHAT_FLAGS(goto, "teleport to a player", ADMFLAG_SLAY)
{
// Only players can use this command at all
Expand Down
11 changes: 10 additions & 1 deletion src/cs2_sdk/entity/cbaseentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

#pragma once

#include "../schema.h"
#include "schema.h"
#include "ccollisionproperty.h"
#include "globaltypes.h"
#include "ctakedamageinfo.h"
#include "mathlib/vector.h"
#include "ehandle.h"
#include "../../gameconfig.h"
Expand Down Expand Up @@ -116,6 +117,14 @@ class Z_CBaseEntity : public CBaseEntity
Vector GetAbsOrigin() { return m_CBodyComponent->m_pSceneNode->m_vecAbsOrigin; }
void SetAbsOrigin(Vector vecOrigin) { m_CBodyComponent->m_pSceneNode->m_vecAbsOrigin = vecOrigin; }

void SetAbsVelocity(Vector vecVelocity) { m_vecAbsVelocity = vecVelocity; }
void SetBaseVelocity(Vector vecVelocity) { m_vecBaseVelocity = vecVelocity; }

void TakeDamage(int iDamage)
{
m_iHealth = m_iHealth() - iDamage;
}

void Teleport(Vector *position, QAngle *angles, Vector *velocity)
{
static int offset = g_GameConfig->GetOffset("Teleport");
Expand Down
8 changes: 8 additions & 0 deletions src/cs2_sdk/entity/cbaseplayerpawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class CBasePlayerPawn : public CBaseModelEntity
SCHEMA_FIELD(CCSPlayer_ItemServices*, m_pItemServices)
SCHEMA_FIELD(CHandle<CBasePlayerController>, m_hController)

void TakeDamage(int iDamage)
{
if (m_iHealth() - iDamage <= 0)
CommitSuicide(false, true);
else
Z_CBaseEntity::TakeDamage(iDamage);
}

void CommitSuicide(bool bExplode, bool bForce)
{
static int offset = g_GameConfig->GetOffset("CBasePlayerPawn_CommitSuicide");
Expand Down
109 changes: 109 additions & 0 deletions src/cs2_sdk/entity/ctakedamageinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* =============================================================================
* CS2Fixes
* Copyright (C) 2023 Source2ZE
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once
#include <platform.h>
#include "ehandle.h"

enum DamageTypes_t : uint32_t
{
DMG_GENERIC = 0x0,
DMG_CRUSH = 0x1,
DMG_BULLET = 0x2,
DMG_SLASH = 0x4,
DMG_BURN = 0x8,
DMG_VEHICLE = 0x10,
DMG_FALL = 0x20,
DMG_BLAST = 0x40,
DMG_CLUB = 0x80,
DMG_SHOCK = 0x100,
DMG_SONIC = 0x200,
DMG_ENERGYBEAM = 0x400,
DMG_DROWN = 0x4000,
DMG_POISON = 0x8000,
DMG_RADIATION = 0x10000,
DMG_DROWNRECOVER = 0x20000,
DMG_ACID = 0x40000,
DMG_PHYSGUN = 0x100000,
DMG_DISSOLVE = 0x200000,
DMG_BLAST_SURFACE = 0x400000,
DMG_BUCKSHOT = 0x1000000,
DMG_LASTGENERICFLAG = 0x1000000,
DMG_HEADSHOT = 0x2000000,
DMG_DANGERZONE = 0x4000000,
};

enum TakeDamageFlags_t : uint32_t
{
DFLAG_NONE = 0x0,
DFLAG_SUPPRESS_HEALTH_CHANGES = 0x1,
DFLAG_SUPPRESS_PHYSICS_FORCE = 0x2,
DFLAG_SUPPRESS_EFFECTS = 0x4,
DFLAG_PREVENT_DEATH = 0x8,
DFLAG_FORCE_DEATH = 0x10,
DFLAG_ALWAYS_GIB = 0x20,
DFLAG_NEVER_GIB = 0x40,
DFLAG_REMOVE_NO_RAGDOLL = 0x80,
DFLAG_SUPPRESS_DAMAGE_MODIFICATION = 0x100,
DFLAG_ALWAYS_FIRE_DAMAGE_EVENTS = 0x200,
DFLAG_RADIUS_DMG = 0x400,
DMG_LASTDFLAG = 0x400,
DFLAG_IGNORE_ARMOR = 0x800,
};

class CTakeDamageInfo
{
private:
[[maybe_unused]] uint8_t __pad0000[0x8];

public:
Vector m_vecDamageForce;
Vector m_vecDamagePosition;
Vector m_vecReportedPosition;
Vector m_vecDamageDirection;
CHandle<CBaseEntity> m_hInflictor;
CHandle<CBaseEntity> m_hAttacker;
CHandle<CBaseEntity> m_hAbility;
float m_flDamage;
DamageTypes_t m_bitsDamageType;
int32_t m_iDamageCustom;
uint8_t m_iAmmoType;

private:
[[maybe_unused]] uint8_t __pad0051[0xf];

public:
float m_flOriginalDamage;
bool m_bShouldBleed;
bool m_bShouldSpark;

private:
[[maybe_unused]] uint8_t __pad0066[0xa];

public:
TakeDamageFlags_t m_nDamageFlags;
int32_t m_nNumObjectsPenetrated;
uint64_t m_hScriptInstance;

private:
[[maybe_unused]] uint8_t __pad0080[0x14];

public:
bool m_bInTakeDamageFlow;
};
26 changes: 15 additions & 11 deletions src/cs2fixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@

#include "tier0/memdbgon.h"

CEntitySystem* g_pEntitySystem = nullptr;

float g_flUniversalTime;
float g_flLastTickedTime;
bool g_bHasTicked;
Expand Down Expand Up @@ -125,14 +123,15 @@ CON_COMMAND_F(toggle_logs, "Toggle printing most logs and warnings", FCVAR_SPONL
ToggleLogs();
}

IGameEventSystem* g_gameEventSystem;
IGameEventManager2* g_gameEventManager = nullptr;
INetworkGameServer* g_pNetworkGameServer = nullptr;
CGlobalVars* gpGlobals = nullptr;
CPlayerManager* g_playerManager = nullptr;
IVEngineServer2* g_pEngineServer2;
IGameEventSystem *g_gameEventSystem = nullptr;
IGameEventManager2 *g_gameEventManager = nullptr;
INetworkGameServer *g_pNetworkGameServer = nullptr;
CEntitySystem *g_pEntitySystem = nullptr;
CGlobalVars *gpGlobals = nullptr;
CPlayerManager *g_playerManager = nullptr;
IVEngineServer2 *g_pEngineServer2 = nullptr;
CGameConfig *g_GameConfig = nullptr;
ISteamHTTP* g_http = nullptr;
ISteamHTTP *g_http = nullptr;
CSteamGameServerAPIContext g_steamAPI;
CCSGameRules *g_pGameRules = nullptr;

Expand Down Expand Up @@ -291,12 +290,17 @@ bool CS2Fixes::Unload(char *error, size_t maxlen)

void CS2Fixes::Hook_StartupServer(const GameSessionConfiguration_t& config, ISource2WorldSession*, const char*)
{
Message("startup server\n");

g_pNetworkGameServer = g_pNetworkServerService->GetIGameServer();
g_pEntitySystem = interfaces::pGameResourceServiceServer->GetGameEntitySystem();
gpGlobals = g_pNetworkGameServer->GetGlobals();

// exec a map cfg
Message("Hook_StartupServer: Running map config for %s\n", gpGlobals->mapname);

char cmd[MAX_PATH];
V_snprintf(cmd, sizeof(cmd), "exec maps/%s", gpGlobals->mapname);
g_pEngineServer2->ServerCommand(cmd);

if(g_bHasTicked)
RemoveMapTimers();

Expand Down
Loading