Skip to content

Commit c99572d

Browse files
committed
feat: Implemented CPortal_Player class file
1 parent b4ebe7e commit c99572d

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

src/modules/cportal_player.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*******************************************************************
2+
* @file cportal_player.cpp
3+
* @brief CPortal_Player class recreation.
4+
* @author Orsell
5+
* @date 06 2025
6+
*********************************************************************/
7+
8+
#include "stdafx.hpp"
9+
#include "modules/cportal_player.h"
10+
11+
#include <const.h>
12+
13+
#include "utils/loggingsystem.hpp"
14+
#include "utils/memory.hpp"
15+
16+
#include "modules/cbaseplayer.h"
17+
#include "modules/utils.h"
18+
19+
/**
20+
* @brief Respawn a player where ever their spawn point is set.
21+
* @param playerEntityIndex Player entity index.
22+
*/
23+
void CPortal_Player::RespawnPlayer(const int playerEntityIndex)
24+
{
25+
CPortal_Player* pPlayer = reinterpret_cast<CPortal_Player*>(Utils::PlayerByIndex(playerEntityIndex));
26+
if (!pPlayer)
27+
{
28+
Log(WARNING, false, "Couldn't get player to respawn! playerIndex: %i", playerEntityIndex);
29+
return;
30+
}
31+
32+
static auto respawnPlayer = reinterpret_cast<void(__thiscall*)(CPortal_Player*)>(Memory::Scan<void*>(SERVER, "0F 57 C0 56 8B F1 57 8D 8E"));
33+
respawnPlayer(pPlayer);
34+
}
35+
36+
/**
37+
* @brief Set the flashlight state for a player.
38+
* @note Not a function in the CPortal_Player class, just more grouping it with the
39+
* class. This does the same thing as the FlashlightTurnOn and FlashlightTurnOff
40+
* functions in CPortal_Player but done in one function.
41+
* @param playerEntityIndex Player entity index.
42+
* @param enabled Should flashlight be enabled or not.
43+
*/
44+
void CPortal_Player::SetFlashlightState(const int playerEntityIndex, const bool enabled)
45+
{
46+
CBasePlayer* pPlayer = Utils::PlayerByIndex(playerEntityIndex);
47+
if (!pPlayer)
48+
{
49+
Log(WARNING, true, "Couldn't get player to set flashlight state! playerIndex: %i enable: %i", playerEntityIndex, !!enabled);
50+
return;
51+
}
52+
53+
if (enabled)
54+
reinterpret_cast<void(__thiscall*)(CBaseEntity*, int)>(Memory::Scan<void*>(SERVER, "55 8B EC 53 8B D9 8B 83 A8"))(reinterpret_cast<CBaseEntity*>(pPlayer), EF_DIMLIGHT);
55+
else
56+
reinterpret_cast<void(__thiscall*)(CBaseEntity*, int)>(Memory::Scan<void*>(SERVER, "55 8B EC 53 56 8B 75 08 8B D9 8B 83"))(reinterpret_cast<CBaseEntity*>(pPlayer), EF_DIMLIGHT);
57+
}

src/modules/cportal_player.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*******************************************************************
2+
* @file cportal_player.h
3+
* @brief CPortal_Player class recreation.
4+
* @author Orsell
5+
* @date 06 2025
6+
*********************************************************************/
7+
8+
#pragma once
9+
10+
#ifndef CPORTAL_PLAYER_H
11+
#define CPORTAL_PLAYER_H
12+
13+
class CPortal_Player
14+
{
15+
public: // MARK: CPortal_Player Public Members
16+
#pragma region Public Members
17+
18+
static void RespawnPlayer(int playerEntityIndex);
19+
static void SetFlashlightState(int playerEntityIndex, bool enabled);
20+
21+
#pragma endregion
22+
23+
private: // MARK: CPortal_Player Private Members
24+
#pragma region Private Members
25+
#pragma endregion
26+
};
27+
28+
#endif

0 commit comments

Comments
 (0)