Skip to content

Commit c583a5f

Browse files
committed
feat: janklord dip event stuff
1 parent d9f9b19 commit c583a5f

File tree

3 files changed

+70
-18
lines changed

3 files changed

+70
-18
lines changed

docs/cvars.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
|-ghost_list|cmd|-ghost_list - disable the ghost list HUD|
4444
|ghost_list|cmd|ghost_list - list all players in the current ghost server|
4545
|ghost_list_font|0|Font index for ghost list HUD.|
46-
|ghost_list_mode|0|Mode for ghost list HUD. 0 = all players, 1 = current map|
46+
|ghost_list_mode|0|Mode for ghost list HUD. 0 = all players, 1 = current map, 2 = dip|
4747
|ghost_list_show_map|0|Show the map name in the ghost list HUD.|
4848
|ghost_list_x|2|X position of ghost list HUD.|
4949
|ghost_list_y|-2|Y position of ghost list HUD.|
@@ -107,7 +107,9 @@
107107
|sar_avg_stop|cmd|sar_avg_stop - stops average calculation|
108108
|sar_bink_respect_host_time|1|Make BINK video playback respect host time.|
109109
|sar_cam_control|0|sar_cam_control \<type>: Change type of camera control.<br>0 = Default (camera is controlled by game engine),<br>1 = Drive mode (camera is separated and can be controlled by user input),<br>2 = Cinematic mode (camera is controlled by predefined path).<br>3 = Follow mode (Camera is following the player but not rotating, useful when strafing on gel).|
110-
|sar_cam_drive|1|Enables or disables camera drive mode in-game (turning it on is not required for demo player)|
110+
|sar_cam_drive|2|Enables or disables camera drive mode in-game (turning it on is not required for demo player)<br>1 = enabled when LMB is held<br>2 = always enabled|
111+
|sar_cam_drive_base_speed|175|Base speed of camera drive mode, in units per seconds.|
112+
|sar_cam_drive_buildup_scale|0.5|Defines how much to increase multiplier of drive speed over time of movement every second.|
111113
|sar_cam_force_eye_pos|0|Forces camera to be placed exactly on the player's eye position|
112114
|sar_cam_ortho|0|Enables or disables camera orthographic projection.|
113115
|sar_cam_ortho_nearz|1|Changes the near Z plane of orthographic projection.|
@@ -676,7 +678,7 @@
676678
|sar_transition_timer|0|Output how slow your dialogue fade was.|
677679
|sar_twitch_chat_channel||The Twitch channel to connect to.|
678680
|sar_twitch_chat_color|255 255 255|The color of the Twitch chat messages.|
679-
|sar_twitch_chat_enabled|0|Enables Twitch chat integration.|
681+
|sar_twitch_chat_enabled|0|Enables Twitch chat integration. 2 enables spectator command !spec|
680682
|sar_unlocked_chapters|-1|Max unlocked chapter.|
681683
|sar_update|cmd|sar_update [release\|pre\|canary] [exit\|restart] [force] - update SAR to the latest version. If exit is given, exit the game upon successful update; if force is given, always re-install, even if it may be a downgrade|
682684
|sar_velocitygraph|0|Shows velocity graph.|

src/Features/Demo/NetworkGhostPlayer.cpp

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ SyncUi syncUi;
132132

133133
Variable ghost_list_x("ghost_list_x", "2", "X position of ghost list HUD.\n", 0);
134134
Variable ghost_list_y("ghost_list_y", "-2", "Y position of ghost list HUD.\n", 0);
135-
Variable ghost_list_mode("ghost_list_mode", "0", 0, 1, "Mode for ghost list HUD. 0 = all players, 1 = current map\n");
135+
Variable ghost_list_mode("ghost_list_mode", "0", 0, 2, "Mode for ghost list HUD. 0 = all players, 1 = current map, 2 = dip\n");
136136
Variable ghost_list_show_map("ghost_list_show_map", "0", "Show the map name in the ghost list HUD.\n");
137137
Variable ghost_list_font("ghost_list_font", "0", 0, "Font index for ghost list HUD.\n");
138138

@@ -157,30 +157,52 @@ class PlayerListUi : public Hud {
157157
if (slot != 0 && !engine->IsOrange()) return;
158158
if (!networkManager.isConnected) return;
159159

160-
std::set<std::string> players;
160+
// HACKHACK: STUPIDEST JANK IVE EVER JANKED
161+
// for deep dip. free to revert when event ends.
162+
std::vector<std::pair<float, std::string>> players;
161163
networkManager.ghostPoolLock.lock();
162-
if (ghost_list_show_map.GetBool()) {
163-
players.insert(Utils::ssprintf("%s (%s)", networkManager.name.c_str(), engine->GetCurrentMapTitle().c_str()));
164+
const static float TOWER_BOTTOM_Z = -13103.97f;
165+
const static float TOWER_TOP_Z = 9632.03f;
166+
if (ghost_list_mode.GetInt() == 2) {
167+
if (!networkManager.spectator) {
168+
auto player = client->GetPlayer(GET_SLOT()+1);
169+
float percent = std::clamp((client->GetAbsOrigin((void *)player).z + 64.0f - TOWER_BOTTOM_Z) / (TOWER_TOP_Z - TOWER_BOTTOM_Z), 0.0f, 1.0f);
170+
players.push_back({percent, Utils::ssprintf("%s (%.2f%%)", networkManager.name.c_str(), percent * 100.0f)});
171+
}
164172
} else {
165-
players.insert(networkManager.name);
173+
if (ghost_list_show_map.GetBool()) {
174+
players.push_back({0, Utils::ssprintf("%s (%s)", networkManager.name.c_str(), engine->GetCurrentMapTitle().c_str())});
175+
} else {
176+
players.push_back({0, networkManager.name});
177+
}
166178
}
167179
for (auto &g : networkManager.ghostPool) {
168180
if (g->isDestroyed) continue;
169181
if (!networkManager.AcknowledgeGhost(g)) continue;
170-
if (ghost_list_mode.GetInt() == 1 && !g->sameMap) continue;
171-
if (ghost_list_show_map.GetBool()) {
172-
players.insert(Utils::ssprintf("%s (%s)", g->name.c_str(), engine->GetMapTitle(g->currentMap).c_str()));
182+
if (ghost_list_mode.GetInt() >= 1 && !g->sameMap) continue;
183+
if (ghost_list_mode.GetInt() == 2) {
184+
if (g->newPos.position.z == 0.0f) continue;
185+
float percent = std::clamp((g->newPos.position.z + 64.0f - TOWER_BOTTOM_Z) / (TOWER_TOP_Z - TOWER_BOTTOM_Z), 0.0f, 1.0f);
186+
players.push_back({percent, Utils::ssprintf("%s (%.2f%%)", g->name.c_str(), percent * 100.0f)});
173187
} else {
174-
players.insert(g->name);
188+
if (ghost_list_show_map.GetBool()) {
189+
players.push_back({0, Utils::ssprintf("%s (%s)", g->name.c_str(), engine->GetMapTitle(g->currentMap).c_str())});
190+
} else {
191+
players.push_back({0, g->name});
192+
}
175193
}
176194
}
177195
networkManager.ghostPoolLock.unlock();
178196

179197
long font = scheme->GetFontByID(ghost_list_font.GetInt());
180198

181199
int width = 0;
200+
// sort players by percentage descending
201+
std::sort(players.begin(), players.end(), [](const auto &a, const auto &b) {
202+
return a.first > b.first;
203+
});
182204
for (auto &p : players) {
183-
int w = surface->GetFontLength(font, "%s", p.c_str());
205+
int w = surface->GetFontLength(font, "%s", p.second.c_str());
184206
if (w > width) width = w;
185207
}
186208
width += 6; // Padding
@@ -199,7 +221,7 @@ class PlayerListUi : public Hud {
199221
y += 3;
200222

201223
for (auto &p : players) {
202-
surface->DrawTxt(font, x, y, { 255, 255, 255, 255 }, "%s", p.c_str());
224+
surface->DrawTxt(font, x, y, { 255, 255, 255, 255 }, "%s", p.second.c_str());
203225
y += surface->GetFontHeight(font) + 3;
204226
}
205227
}

src/Features/TwitchIntegration.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#include "Event.hpp"
22
#include "Modules/Client.hpp"
3+
#include "Modules/Engine.hpp"
34
#include "Utils/TwitchConnection.hpp"
45
#include "Variable.hpp"
56

6-
Variable sar_twitch_chat_enabled("sar_twitch_chat_enabled", "0", "Enables Twitch chat integration.\n");
7+
Variable sar_twitch_chat_enabled("sar_twitch_chat_enabled", "0", "Enables Twitch chat integration. 2 enables spectator command !spec\n");
78
Variable sar_twitch_chat_channel("sar_twitch_chat_channel", "", "The Twitch channel to connect to.\n");
89
Variable sar_twitch_chat_color("sar_twitch_chat_color", "255 255 255", "The color of the Twitch chat messages.\n");
910

@@ -25,9 +26,36 @@ ON_EVENT(PRE_TICK) {
2526
}
2627
auto twitchMsgs = twitchConnection.FetchNewMessages();
2728
for (auto msg : twitchMsgs) {
28-
std::string message = msg.username + ": " + msg.message;
29-
Color color = Utils::GetColor(sar_twitch_chat_color.GetString()).value_or(Color(255, 255, 255));
30-
client->Chat(color, message.c_str());
29+
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());
38+
if (Utils::StartsWith(message.c_str(), "!spec ")) {
39+
std::string specName = message.substr(6);
40+
if (specName.length() > 0) {
41+
specName = std::string("ghost_spec_pov \"") + specName.c_str() + "\"\n";
42+
engine->ExecuteCommand(specName.c_str(), true);
43+
}
44+
} else if (Utils::StartsWith(message.c_str(), "!cmd ") && Utils::ICompare(author, sar_twitch_chat_channel.GetString())) {
45+
std::string command = message.substr(5);
46+
if (command.length() > 0) {
47+
command = command + "\n";
48+
engine->ExecuteCommand(command.c_str(), true);
49+
}
50+
} else {
51+
std::string out = std::string("ghost_message \"(TTV) ") + author + ": " + message + "\"\n";
52+
engine->ExecuteCommand(out.c_str(), true);
53+
}
54+
} else {
55+
std::string message = msg.username + ": " + msg.message;
56+
Color color = Utils::GetColor(sar_twitch_chat_color.GetString()).value_or(Color(255, 255, 255));
57+
client->Chat(color, message.c_str());
58+
}
3159
}
3260
}
3361

0 commit comments

Comments
 (0)