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

feat: point_viewcontrol #306

Merged
merged 20 commits into from
Oct 19, 2024
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
2 changes: 2 additions & 0 deletions CS2Fixes.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,11 @@
<ClInclude Include="src\cs2_sdk\entity\clogiccase.h" />
<ClInclude Include="src\cs2_sdk\entity\cparticlesystem.h" />
<ClInclude Include="src\cs2_sdk\entity\cphysthruster.h" />
<ClInclude Include="src\cs2_sdk\entity\cpointviewcontrol.h" />
<ClInclude Include="src\cs2_sdk\entity\ctakedamageinfo.h" />
<ClInclude Include="src\cs2_sdk\entity\cteam.h" />
<ClInclude Include="src\cs2_sdk\entity\ctriggerpush.h" />
<ClInclude Include="src\cs2_sdk\entity\ctriggerteleport.h" />
<ClInclude Include="src\cs2_sdk\entity\cvotecontroller.h" />
<ClInclude Include="src\cs2_sdk\entity\globaltypes.h" />
<ClInclude Include="src\cs2_sdk\entity\lights.h" />
Expand Down
6 changes: 6 additions & 0 deletions CS2Fixes.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,11 @@
<ClInclude Include="src\cs2_sdk\entity\cenvhudhint.h">
<Filter>Header Files\cs2_sdk\entity</Filter>
</ClInclude>
<ClInclude Include="src\cs2_sdk\entity\cpointviewcontrol.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\cs2_sdk\entity\ctriggerteleport.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
12 changes: 12 additions & 0 deletions gamedata/cs2fixes.games.txt
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,18 @@
"windows" "\x48\x89\x5C\x24\x20\x48\x89\x4C\x24\x08\x55\x56\x41\x55"
"linux" "\x55\x48\x89\xE5\x41\x57\x41\x56\x49\x89\xCE\x41\x55\x4D\x89\xC5\x41\x54\x49\x89\xD4\x53\x4C\x89\xCB"
}
"CBasePlayerPawn_GetEyePosition"
{
"library" "server"
"windows" "\x48\x89\x5C\x24\x2A\x57\x48\x83\xEC\x2A\x48\x8B\xF9\x48\x8B\xDA\x48\x8B\x89\x2A\x2A\x2A\x2A\x48\x85\xC9\x74\x2A\x48\x8B\x01"
"linux" "\x55\x48\x89\xE5\x41\x54\x49\x89\xFC\x48\x83\xEC\x2A\x48\x8B\xBF\x2A\x2A\x2A\x2A\x48\x85\xFF\x74\x2A\x48\x8B\x07\x48\x8D\x15"
}
"CBasePlayerPawn_GetEyeAngles"
{
"library" "server"
"windows" "\x48\x89\x5C\x24\x2A\x57\x48\x81\xEC\x2A\x2A\x2A\x2A\x48\x8B\xF9\x48\x8B\xDA\x48\x8B\x89"
"linux" "\x55\x48\x89\xE5\x41\x55\x41\x54\x49\x89\xFC\x48\x83\xEC\x2A\x48\x8B\xBF\x2A\x2A\x2A\x2A\x48\x85\xFF\x0F\x84\x2A\x2A\x2A\x2A\x48\x8B\x07\x48\x8D\x15"
}
}
"Offsets"
{
Expand Down
14 changes: 14 additions & 0 deletions src/cs2_sdk/entity/cbaseentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern CGameConfig *g_GameConfig;

class CGameUI;
class CEnvHudHint;
class CPointViewControl;

class CGameSceneNode
{
Expand Down Expand Up @@ -291,6 +292,19 @@ class CBaseEntity : public CEntityInstance
return nullptr;
}

[[nodiscard]] CPointViewControl *AsPointViewControl()
{
if (V_strcasecmp(GetClassname(), "logic_relay") != 0)
return nullptr;

const auto tag = m_iszPrivateVScripts.IsValid() ? m_iszPrivateVScripts.String() : nullptr;

if (tag && V_strcasecmp(tag, "point_viewcontrol") == 0)
return reinterpret_cast<CPointViewControl *>(this);

return nullptr;
}

/* End Custom Entities Cast */
};

Expand Down
9 changes: 8 additions & 1 deletion src/cs2_sdk/entity/cbasemodelentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class CBaseModelEntity : public CBaseEntity
SCHEMA_FIELD(Color, m_clrRender)
SCHEMA_FIELD(RenderMode_t, m_nRenderMode)
SCHEMA_FIELD(float, m_flDissolveStartTime)

SCHEMA_FIELD(Vector, m_vecViewOffset)

void SetModel(const char *szModel)
{
addresses::CBaseModelEntity_SetModel(this, szModel);
Expand All @@ -48,4 +49,10 @@ class CBaseModelEntity : public CBaseEntity
{
return ((CSkeletonInstance*)m_CBodyComponent->m_pSceneNode.Get())->m_modelState().m_ModelName.Get().String();
}

Vector GetEyePosition()
{
const auto x = m_vecViewOffset();
return x + GetAbsOrigin();
}
};
1 change: 1 addition & 0 deletions src/cs2_sdk/entity/cbaseplayercontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CBasePlayerController : public CBaseEntity
SCHEMA_FIELD_POINTER(char, m_iszPlayerName)
SCHEMA_FIELD(PlayerConnectedState, m_iConnected)
SCHEMA_FIELD(bool, m_bIsHLTV)
SCHEMA_FIELD(uint, m_iDesiredFOV)

// Returns the current pawn, which could be one of those:
// - The player's actual pawn
Expand Down
2 changes: 2 additions & 0 deletions src/cs2_sdk/entity/cbaseplayerpawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class CBasePlayerPawn : public CBaseModelEntity
SCHEMA_FIELD(CCSPlayer_WeaponServices*, m_pWeaponServices)
SCHEMA_FIELD(CCSPlayer_ItemServices*, m_pItemServices)
SCHEMA_FIELD(CPlayer_ObserverServices*, m_pObserverServices)
SCHEMA_FIELD(CPlayer_CameraServices*, m_pCameraServices)
SCHEMA_FIELD(CHandle<CBasePlayerController>, m_hController)
SCHEMA_FIELD(QAngle, v_angle)

// Drops any map-spawned weapons the pawn is holding
// NOTE: Currently very broken with map items (entities parented to weapons?) due to a game bug..? Needs further investigation/work
Expand Down
5 changes: 5 additions & 0 deletions src/cs2_sdk/entity/ccsplayerpawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,9 @@ class CCSPlayerPawn : public CCSPlayerPawnBase

SCHEMA_FIELD(float, m_flVelocityModifier)
SCHEMA_FIELD(CCSPlayer_ActionTrackingServices*, m_pActionTrackingServices)

[[nodiscard]] CCSPlayer_CameraServices* GetCameraService()
{
return reinterpret_cast<CCSPlayer_CameraServices*>(m_pCameraServices());
}
};
10 changes: 10 additions & 0 deletions src/cs2_sdk/entity/ccsweaponbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "cbaseentity.h"

extern CGlobalVars* gpGlobals;

enum gear_slot_t : uint32_t
{
GEAR_SLOT_INVALID = 0xffffffff,
Expand Down Expand Up @@ -88,8 +90,16 @@ class CBasePlayerWeapon : public CEconEntity
{
public:
DECLARE_SCHEMA_CLASS(CBasePlayerWeapon)
SCHEMA_FIELD(int, m_nNextPrimaryAttackTick)
SCHEMA_FIELD(int, m_nNextSecondaryAttackTick)

CCSWeaponBaseVData* GetWeaponVData() { return (CCSWeaponBaseVData*)GetVData(); }

void Disarm()
{
m_nNextPrimaryAttackTick(MAX(m_nNextPrimaryAttackTick(), gpGlobals->tickcount + 24));
m_nNextSecondaryAttackTick(MAX(m_nNextSecondaryAttackTick(), gpGlobals->tickcount + 24));
}
};

class CCSWeaponBase : public CBasePlayerWeapon
Expand Down
1 change: 1 addition & 0 deletions src/cs2_sdk/entity/cgamerules.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class CCSGameRules : public CGameRules
SCHEMA_FIELD_POINTER(int, m_nEndMatchMapGroupVoteOptions)
SCHEMA_FIELD(int, m_nEndMatchMapVoteWinner)
SCHEMA_FIELD(int, m_iRoundTime)
SCHEMA_FIELD(bool, m_bFreezePeriod)
SCHEMA_FIELD_POINTER(CUtlVector<SpawnPoint*>, m_CTSpawnPoints)
SCHEMA_FIELD_POINTER(CUtlVector<SpawnPoint*>, m_TerroristSpawnPoints)

Expand Down
69 changes: 69 additions & 0 deletions src/cs2_sdk/entity/cpointviewcontrol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* =============================================================================
* CS2Fixes
* Copyright (C) 2023-2024 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 "../schema.h"
#include "cbaseentity.h"
#include "entity.h"

/* logic_relay */

class CPointViewControl : public CBaseEntity
{
DECLARE_SCHEMA_CLASS(CPointViewControl)

// hello, don't port my garbage code to cssharp :)

static constexpr int SF_POINT_VIEWCONTROL_FROZEN = 1 << 5;
static constexpr int SF_POINT_VIEWCONTROL_FOV = 1 << 6;
static constexpr int SF_POINT_VIEWCONTROL_DISARM = 1 << 7;

public:
[[nodiscard]] CBaseEntity* GetTargetCameraEntity()
{
const auto pTarget = UTIL_FindEntityByName(nullptr, m_target().String());
return pTarget && pTarget->m_pCollision() ? pTarget : nullptr;
}

[[nodiscard]] bool HasTargetCameraEntity()
{
return m_target().IsValid() && strlen(m_target().String()) >= 2;
}

[[nodiscard]] bool HasFrozen()
{
return !!(m_spawnflags() & SF_POINT_VIEWCONTROL_FROZEN);
}

[[nodiscard]] bool HasFOV()
{
return !!(m_spawnflags() & SF_POINT_VIEWCONTROL_FOV);
}

[[nodiscard]] bool HasDisarm()
{
return !!(m_spawnflags() & SF_POINT_VIEWCONTROL_DISARM);
}

[[nodiscard]] uint GetFOV()
{
return clamp(static_cast<uint>(m_iHealth()), 16, 179);
}
};
22 changes: 21 additions & 1 deletion src/cs2_sdk/entity/services.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,24 @@ class CPlayer_ObserverServices
SCHEMA_FIELD(CHandle<CBaseEntity>, m_hObserverTarget)
SCHEMA_FIELD(ObserverMode_t, m_iObserverLastMode)
SCHEMA_FIELD(bool, m_bForcedObserverMode)
};
};

class CPlayer_CameraServices
{
public:
DECLARE_SCHEMA_CLASS(CPlayer_CameraServices)

SCHEMA_FIELD(CHandle<CBaseEntity>, m_hViewEntity)
};

class CCSPlayerBase_CameraServices : public CPlayer_CameraServices
{
public:
DECLARE_SCHEMA_CLASS(CCSPlayerBase_CameraServices)

SCHEMA_FIELD(CHandle<CBaseEntity>, m_hZoomOwner)
SCHEMA_FIELD(uint, m_iFOV)
};

class CCSPlayer_CameraServices : public CCSPlayerBase_CameraServices
{};
7 changes: 7 additions & 0 deletions src/cs2fixes.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ class CS2Fixes : public ISmmPlugin, public IMetamodListener
void Hook_CreateWorkshopMapGroup(const char* name, const CUtlStringList& mapList);
void Hook_GoToIntermission(bool bAbortedMatch);
bool Hook_OnTakeDamage_Alive(CTakeDamageInfoContainer *pInfoContainer);
#ifdef PLATFORM_WINDOWS
Vector* Hook_GetEyePosition(Vector*);
QAngle* Hook_GetEyeAngles(QAngle*);
#else
Vector Hook_GetEyePosition();
QAngle Hook_GetEyeAngles();
#endif
void Hook_CheckMovingGround(double frametime);
int Hook_LoadEventsFromFile(const char *filename, bool bSearchAll);

Expand Down
Loading