Skip to content

Commit

Permalink
feat: rework TAS proto for two-side communication
Browse files Browse the repository at this point in the history
+ add several protocol messages for bruteforce purposes

Co-authored-by: RainbowwPhoenixx <[email protected]>
  • Loading branch information
2 people authored and ThisAMJ committed Jul 21, 2024
1 parent 4f50689 commit c5c873e
Show file tree
Hide file tree
Showing 9 changed files with 830 additions and 604 deletions.
6 changes: 5 additions & 1 deletion docs/cvars.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,16 @@
|sar_tas_play|cmd|sar_tas_play \<filename> [filename2] - plays a TAS script with given name. If two script names are given, play coop|
|sar_tas_play_single|cmd|sar_tas_play_single \<filename> [slot] - plays a single coop TAS script, giving the player control of the other slot.|
|sar_tas_playback_rate|1.0|The rate at which to play back TAS scripts.|
|sar_tas_protocol_connect|cmd|sar_tas_protocol_connect \<ip address> \<port> - connect to the TAS protocol server.<br>ex: '127.0.0.1 5666' - '89.10.20.20 5666'.|
|sar_tas_protocol_reconnect_delay|0|A number of seconds after which reconnection to TAS protocol server should be made.<br>0 means no reconnect attempts will be made.|
|sar_tas_protocol_send_msg|cmd|sar_tas_protocol_send_msg \<message> - sends a message over TAS protocol.|
|sar_tas_protocol_server|cmd|sar_tas_protocol_server [port] - starts a TAS protocol server. Port is 6555 by default.|
|sar_tas_protocol_stop|cmd|sar_tas_protocol_stop - stops every TAS protocol related connection.|
|sar_tas_real_controller_debug|0|Debugs controller.|
|sar_tas_replay|cmd|sar_tas_replay - replays the last played TAS|
|sar_tas_restore_fps|1|Restore fps_max and host_framerate after TAS playback.|
|sar_tas_resume|cmd|sar_tas_resume - resumes TAS playback|
|sar_tas_save_raw|cmd|sar_tas_save_raw - saves a processed version of just processed script|
|sar_tas_server|0|Enable the remote TAS server. Setting this value to something higher than one will bind the server on that port.|
|sar_tas_skipto|0|Fast-forwards the TAS playback until given playback tick.|
|sar_tas_stop|cmd|sar_tas_stop - stop TAS playing|
|sar_tas_tools_enabled|1|Enables tool processing for TAS script making.|
Expand Down
13 changes: 9 additions & 4 deletions docs/tas_proto.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
TAS server protocol
TAS protocol
===================

Connect to a TCP socket on localhost:6555.
The following specification lists packets that can be sent between the player (SAR client capable of playing TAS scripts) and controller (external software capable of controlling the player through the protocol like VSC extension or bruteforcer server)
SAR (the player) can act as both the client (connecting to a controller server) and server (listening for controller client connections).

Every packet consists of a one-byte (u8) ID, followed by some extra data. the extra data is specified here under the packet name; if there's nothing specified, there's no extra data.

The server should always send a packet with ID 255 first; it'll never send this again.

server (SAR) -> client (VSC extension):
player -> controller:
[0] set active
len1: u32
filename1: [len1]u8 // relative to "Portal 2/tas/", so the same as the arg you'd give to sar_tas_play
Expand Down Expand Up @@ -47,7 +48,7 @@ server (SAR) -> client (VSC extension):
location: [len]u8 // a string like "/home/mlugg/.steam/steam/steamapps/common/Portal 2", used so that the plugin knows whether it has the right script folder open


client (VSC extension) -> server (SAR):
controller -> player:
[0] request playback
len1: u32
filename1: [len1]u8 // relative to "Portal 2/tas/", so the same as the arg you'd give to sar_tas_play
Expand Down Expand Up @@ -85,3 +86,7 @@ client (VSC extension) -> server (SAR):
[100] request entity info
len: u32
entity_selector: [len]u8

[101] set continuous entity info
len: u32
entity_selector: [len]u8 // send empty string to disable continuous entity info
14 changes: 7 additions & 7 deletions src/Features/Tas/TasPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "Features/Session.hpp"
#include "Features/Tas/TasParser.hpp"
#include "Features/Tas/TasTool.hpp"
#include "Features/Tas/TasServer.hpp"
#include "Features/Tas/TasProtocol.hpp"
#include "Features/Tas/TasTools/CheckTool.hpp"
#include "Features/Hud/Hud.hpp"
#include "Features/RNGManip.hpp"
Expand Down Expand Up @@ -467,7 +467,7 @@ void TasPlayer::SaveProcessedFramebulks() {
}
} else {
std::string slotScript = slotProcessed ? TasParser::SaveRawScriptToString(script) : "";
TasServer::SendProcessedScript((uint8_t)slot, slotScript);
TasProtocol::SendProcessedScript((uint8_t)slot, slotScript);
}
}
}
Expand Down Expand Up @@ -759,21 +759,21 @@ ON_EVENT(FRAME) {
}

void TasPlayer::UpdateServer() {
TasStatus status;
TasProtocol::Status status;

status.active = active;
status.tas_path[0] = playbackInfo.slots[0].name;
status.tas_path[1] = playbackInfo.IsCoop() ? playbackInfo.slots[1].name : "";
status.playback_state =
engine->IsAdvancing()
? PlaybackState::PAUSED
? TasProtocol::PlaybackState::PAUSED
: this->GetTick() < sar_tas_skipto.GetInt()
? PlaybackState::SKIPPING
: PlaybackState::PLAYING;
? TasProtocol::PlaybackState::SKIPPING
: TasProtocol::PlaybackState::PLAYING;
status.playback_rate = sar_tas_playback_rate.GetFloat();
status.playback_tick = this->GetTick();

TasServer::SetStatus(status);
TasProtocol::SetStatus(status);
}

DECL_COMMAND_FILE_COMPLETION(sar_tas_play, TAS_SCRIPT_EXT, TAS_SCRIPTS_DIR, 2)
Expand Down
Loading

0 comments on commit c5c873e

Please sign in to comment.