Skip to content

Commit 149419c

Browse files
committed
implement ghost locator visuals
1 parent 355e3cb commit 149419c

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

src/Features/Demo/GhostRenderer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,6 @@ CON_COMMAND(ghost_locator, "ghost_locator - Sends a coop-like ping to other ghos
197197

198198
engine->TraceRay(engine->engineTrace->ThisPtr(), ray, MASK_SHOT_PORTAL, &filter, &tr);
199199

200+
client->ShowLocator(tr.endpos, tr.plane.normal, GhostEntity::set_color);
200201
networkManager.NotifyLocator(tr.endpos, tr.plane.normal);
201202
}

src/Features/Demo/NetworkGhostPlayer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,11 +1027,10 @@ void NetworkManager::Treat(sf::Packet &packet, bool udp) {
10271027
packet >> position >> normal;
10281028
auto ghost = this->GetGhostByID(ID);
10291029
addToNetDump("recv-locator", Utils::ssprintf("%d;%.1f,%.1f,%.1f;%.1f,%.1f,%.1f", ID, position.x, position.y, position.z, normal.x, normal.y, normal.z).c_str());
1030-
if (ghost) {
1030+
if (ghost && engine->GetCurrentMapName() == ghost->currentMap) {
10311031
Scheduler::OnMainThread([=]() {
10321032
if (this->AcknowledgeGhost(ghost)) {
1033-
console->Print("Locator from %s: Position (%.1f, %.1f, %.1f), Normal (%.1f, %.1f, %.1f)\n", ghost->name.c_str(), position.x, position.y, position.z, normal.x, normal.y, normal.z);
1034-
// TODO: Ping animation
1033+
client->ShowLocator(position, normal, ghost->color.value_or(Color(255,255,255)));
10351034
}
10361035
});
10371036
}

src/Modules/Client.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,19 @@ void Client::MultiColorChat(const std::vector<std::pair<Color, std::string>> &co
203203
client->ChatPrintf(client->g_HudChat->ThisPtr(), 0, 0, fmt.c_str());
204204
}
205205

206+
void Client::ShowLocator(Vector position, Vector normal, Color color) {
207+
Vector colorAsVector = {(float)color.r, (float)color.g, (float)color.b};
208+
QAngle angles;
209+
210+
Vector pseudoup = fabsf(normal.z) < 0.999f ? Vector{0, 0, 1} : Vector{1, 0, 0};
211+
212+
Math::VectorAngles(normal, pseudoup, &angles);
213+
angles.x += 90.0f;
214+
215+
PrecacheParticleSystem("command_target_ping");
216+
DispatchParticleEffect("command_target_ping", position, colorAsVector, angles, nullptr, 0, nullptr);
217+
}
218+
206219
void Client::SetMouseActivated(bool state) {
207220
if (state) {
208221
this->IN_ActivateMouse(g_Input->ThisPtr());
@@ -983,6 +996,9 @@ bool Client::Init() {
983996
this->GetAllClasses = this->g_ClientDLL->Original<_GetAllClasses>(Offsets::GetAllClasses, readJmp);
984997
this->FrameStageNotify = this->g_ClientDLL->Original<_FrameStageNotify>(Offsets::GetAllClasses + 27);
985998

999+
Client::DispatchParticleEffect = (Client::_DispatchParticleEffect)Memory::Scan(this->Name(), Offsets::DispatchParticleEffect);
1000+
Client::PrecacheParticleSystem = (Client::_PrecacheParticleSystem)Memory::Scan(this->Name(), Offsets::PrecacheParticleSystem);
1001+
9861002
this->g_ClientDLL->Hook(Client::LevelInitPreEntity_Hook, Client::LevelInitPreEntity, Offsets::LevelInitPreEntity);
9871003

9881004
using _GetHud = void *(__cdecl *)(int unk);

src/Modules/Client.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class Client : public Module {
4646
using _IN_ActivateMouse = void (*)(void *thisptr);
4747
using _IN_DeactivateMouse = void (*)(void *thisptr);
4848
using _AddAvatarPanelItem = void(__cdecl *)(void *pLeaderboard, void *pStatLists, const PortalLeaderboardItem_t *pData, int nScore, int nType, int nPlayerType, int nAvatarIndex, int nHeight, int nSlot, bool bHUDElement);
49+
using _PrecacheParticleSystem = int(__cdecl *)(const char *pszParticleName);
50+
using _DispatchParticleEffect = void (__cdecl *)(const char *pszParticleName, Vector vecOrigin, Vector vecStart, QAngle vecAngles, void *pEntity, int nSplitScreenPlayerSlot, void *filter);
51+
4952

5053
_GetClientEntity GetClientEntity = nullptr;
5154
_KeyDown KeyDown = nullptr;
@@ -58,6 +61,8 @@ class Client : public Module {
5861
_IN_ActivateMouse IN_ActivateMouse = nullptr;
5962
_IN_DeactivateMouse IN_DeactivateMouse = nullptr;
6063
_AddAvatarPanelItem AddAvatarPanelItem = nullptr;
64+
_DispatchParticleEffect DispatchParticleEffect = nullptr;
65+
_PrecacheParticleSystem PrecacheParticleSystem = nullptr;
6166

6267
ChapterContextData_t *g_ChapterContextNames;
6368
ChapterContextData_t *g_ChapterMPContextNames;
@@ -76,6 +81,7 @@ class Client : public Module {
7681
bool ShouldDrawCrosshair();
7782
void Chat(Color col, const char *str);
7883
void MultiColorChat(const std::vector<std::pair<Color, std::string>> &components);
84+
void ShowLocator(Vector position, Vector normal, Color color);
7985
void SetMouseActivated(bool state);
8086
CMStatus GetChallengeStatus();
8187
int GetSplitScreenPlayerSlot(void *entity);

src/Offsets/Portal 2 9568.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,12 @@ SIGSCAN_DEFAULT(GetChapterProgress, "56 8B 35 ? ? ? ? 57 8B F9 FF D6 8B 10 8B C8
436436
SIGSCAN_DEFAULT(LoadingProgress__SetupControlStatesInstruction, "66 C7 86 ? ? ? ? ? ? EB", "66 89 83 ? ? ? ? E9 ? ? ? ? ? ? ? ? ? ? ? 85 F6") // "vgui/loading_screens/loadingscreen_coop" xref -> LoadingProgress::SetupControlStates -> m_bDrawProgress set to 0
437437
OFFSET_DEFAULT(LoadingProgress__SetupControlStatesBoolOffset, 7, 5)
438438

439+
SIGSCAN_DEFAULT(PrecacheParticleSystem, "55 8B EC 8B 0D ? ? ? ? 8B 01 8B 50 ? 56 57",
440+
"56 53 83 EC 10 A1 ? ? ? ? 8B 74 24 ? 8B 10 6A 00 6A FF") // "electrical_arc_01" xref -> obvious FUN(string) with others -> CParticleSystemMgr::PrecacheParticleSystem
441+
442+
SIGSCAN_DEFAULT(DispatchParticleEffect, "55 8B EC 8B 45 ? 50 E8 ? ? ? ? 8B 4D ? 8B 55 ? F3 0F 7E 45 ? 83 C4 04 51 8B 4D ? 52 8B 55 ? 51 83 EC 0C 8B CC 66 0F D6 01 F3 0F 7E 45 ? 89 51 ? 8B 55 ? 83 EC 0C 8B CC 66 0F D6 01 F3 0F 7E 45",
443+
"53 81 EC 84 00 00 00 8B 9C 24 ? ? ? ? FF B4 24 ? ? ? ? E8 ? ? ? ? 31 D2 F3 0F 10 84 24 ? ? ? ? C7 44 24 ? FF FF FF FF") // "projected_wall_impact" xref -> either usage same function -> DispatchParticleEffect
444+
439445
// Engine
440446
SIGSCAN_DEFAULT(ParseSmoothingInfoSig, "55 8B EC 0F 57 C0 81 EC ? ? ? ? B9 ? ? ? ? 8D 85 ? ? ? ? EB", ""); // "cl_demosmootherpanel.cpp" xref -> CDemoSmootherPanel::ParseSmoothingInfo
441447
OFFSET_DEFAULT(ParseSmoothingInfoOff, 178, -1)

0 commit comments

Comments
 (0)