Skip to content

Commit 4debfc0

Browse files
authored
Merge branch 'p2sr:master' into feat/ghost-voip
2 parents 07a1299 + 537fac3 commit 4debfc0

File tree

6 files changed

+48
-21
lines changed

6 files changed

+48
-21
lines changed

src/Features/Demo/GhostRenderer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ CON_COMMAND(ghost_locator, "ghost_locator - Sends a coop-like ping to other ghos
180180

181181
Vector dir;
182182
Math::AngleVectors(cam_ang, &dir);
183-
dir *= 2048.0f;
183+
dir *= 8192.0f;
184184

185185
CGameTrace tr;
186186

@@ -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 & 4 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
}
@@ -1171,7 +1170,6 @@ void NetworkManager::NotifyTaunt(const std::string name) {
11711170
void NetworkManager::NotifyLocator(Vector position, Vector normal) {
11721171
if (!this->isConnected) return;
11731172
addToNetDump("send-locator", Utils::ssprintf("%d;%.1f,%.1f,%.1f;%.1f,%.1f,%.1f", this->ID, position.x, position.y, position.z, normal.x, normal.y, normal.z).c_str());
1174-
console->Print("Locator: Position (%.1f, %.1f, %.1f), Normal (%.1f, %.1f, %.1f)\n", position.x, position.y, position.z, normal.x, normal.y, normal.z);
11751173
sf::Packet packet;
11761174
packet << HEADER::LOCATOR << this->ID << position << normal;
11771175
this->tcpSocket.send(packet);

src/Features/TwitchIntegration.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Event.hpp"
2+
#include "Features/Demo/NetworkGhostPlayer.hpp"
23
#include "Modules/Client.hpp"
34
#include "Modules/Engine.hpp"
45
#include "Utils/TwitchConnection.hpp"
@@ -26,17 +27,17 @@ ON_EVENT(PRE_TICK) {
2627
}
2728
auto twitchMsgs = twitchConnection.FetchNewMessages();
2829
for (auto msg : twitchMsgs) {
30+
std::string message = msg.message;
31+
std::string author = msg.username;
32+
if (message.length() == 0 || author.length() == 0)
33+
continue;
34+
2935
if (sar_twitch_chat_enabled.GetInt() == 2) {
30-
std::string message = msg.message;
31-
message.erase(remove_if(message.begin(), message.end(), [](char c) {
32-
return c == '"' || c == '\n' || c == '\r' || c == '\0';
33-
}), message.end());
34-
std::string author = msg.username;
35-
author.erase(remove_if(author.begin(), author.end(), [](char c) {
36-
return c == '"' || c == '\n' || c == '\r' || c == '\0';
37-
}), author.end());
3836
if (Utils::StartsWith(message.c_str(), "!spec ")) {
3937
std::string specName = message.substr(6);
38+
specName.erase(remove_if(specName.begin(), specName.end(), [](char c) {
39+
return c == '"' || c == '\n' || c == '\r' || c == '\0';
40+
}), specName.end());
4041
if (specName.length() > 0) {
4142
specName = std::string("ghost_spec_pov \"") + specName.c_str() + "\"\n";
4243
engine->ExecuteCommand(specName.c_str(), true);
@@ -56,7 +57,6 @@ ON_EVENT(PRE_TICK) {
5657
// i promise i can be trusted :P
5758
std::string command = message.substr(5);
5859
if (command.length() > 0) {
59-
command = command + "\n";
6060
engine->ExecuteCommand(command.c_str(), true);
6161
}
6262
} else {
@@ -65,16 +65,16 @@ ON_EVENT(PRE_TICK) {
6565
} else if (Utils::StartsWith(message.c_str(), "!") || Utils::ICompare(author, "nightbot") || Utils::ICompare(author, "streamelements")) {
6666
// Ignore bots and bot commands
6767
} else if (Utils::ICompare(author, sar_twitch_chat_channel.GetString())) {
68-
std::string out = std::string("ghost_message \"") + message + "\"\n";
69-
engine->ExecuteCommand(out.c_str(), true);
68+
networkManager.SendMessageToAll(message);
7069
} else {
71-
std::string out = std::string("ghost_message \"(TTV) ") + author + ": " + message + "\"\n";
72-
engine->ExecuteCommand(out.c_str(), true);
70+
networkManager.SendMessageToAll("(TTV) " + author + ": " + message);
7371
}
7472
} else {
75-
std::string message = msg.username + ": " + msg.message;
76-
Color color = Utils::GetColor(sar_twitch_chat_color.GetString()).value_or(Color(255, 255, 255));
77-
client->Chat(color, message.c_str());
73+
if (!(Utils::StartsWith(message.c_str(), "!") || Utils::ICompare(author, "nightbot") || Utils::ICompare(author, "streamelements"))) {
74+
std::string message = msg.username + ": " + msg.message;
75+
Color color = Utils::GetColor(sar_twitch_chat_color.GetString()).value_or(Color(255, 255, 255));
76+
client->Chat(color, message.c_str());
77+
}
7878
}
7979
}
8080
}

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)