Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions AutoReplayUploader/AutoReplayUploaderPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ BAKKESMOD_PLUGIN(AutoReplayUploaderPlugin, "Auto replay uploader plugin", "0.2",
#define CVAR_BALLCHASING_AUTH_TEST_RESULT "cl_autoreplayupload_ballchasing_testkeyresult"
#define CVAR_BALLCHASING_REPLAY_VISIBILITY "cl_autoreplayupload_ballchasing_visibility"
#define CVAR_CALCULATED_REPLAY_VISIBILITY "cl_autoreplayupload_calculated_visibility"
#define CVAR_UPLOAD_ONLINE_FREEPLAY "cl_autoreplayupload_online_freeplay"

Player ConstructPlayer(PriWrapper wrapper)
{
Player p;
if (!wrapper.IsNull())
{
p.Name = wrapper.GetPlayerName().ToString();
p.UniqueId = wrapper.GetUniqueId().ID;
p.UniqueId = wrapper.GetUniqueIdWrapper().GetUID();
p.Team = wrapper.GetTeamNum();
p.Score = wrapper.GetScore();
p.Goals = wrapper.GetMatchGoals();
Expand All @@ -61,10 +62,10 @@ struct MMRCacheWrapper {
MMRData data;
bool addToAfter;

void AddPlayer(std::string name, SteamID id, float mmr, SkillRank extra, int platform) {
void AddPlayer(std::string name, UniqueIDWrapper id, float mmr, SkillRank extra, int platform) {
if (mmr < 101) return;
MMR newValue{ extra.Tier, extra.Division, extra.MatchesPlayed, mmr };
std::string sid = std::to_string(id.ID);
std::string sid = std::to_string(id.GetUID());
PlayerMMRData newPlayerData{ platform, sid, newValue };
newPlayerData.debug = name;
auto it = std::find_if(data.players.begin(), data.players.end(), [&](PlayerMMRData& p) { return p.id == sid; });
Expand Down Expand Up @@ -229,6 +230,9 @@ void AutoReplayUploaderPlugin::InitializeVariables()
// Set the default status of uploading replay to false
needToUploadReplay = false;

// Default to not uploading Online Freeplay replays
cvarManager->registerCvar(CVAR_UPLOAD_ONLINE_FREEPLAY, "0", "Upload replays from online freeplay matches", true, true, 0, true, 1).bindTo(uploadOnlineFreeplay);

// Calculated variables
cvarManager->registerCvar(CVAR_UPLOAD_TO_CALCULATED, "0", "Upload to replays to calculated.gg automatically", true, true, 0, true, 1).bindTo(uploadToCalculated);
cvarManager->registerCvar(CVAR_CALCULATED_REPLAY_VISIBILITY, "DEFAULT", "Replay visibility when uploading to calculated.gg", false, false, 0, false, 0, true).bindTo(calculated->visibility);
Expand Down Expand Up @@ -414,13 +418,13 @@ void AutoReplayUploaderPlugin::OnMMRSync()
cvarManager->log("got " + std::to_string(players.Count()) + " players");
for (size_t i = 0; i < players.Count(); i++)
{
auto player = players.Get(i);
auto player = players.Get(static_cast<int>(i));
if (!player) continue;
auto playerName = player.GetPlayerName().ToString();
auto platform = player.GetPlatform();
//cvarManager->log("Getting MMR for : "+ playerName);
auto playerSteam = player.GetUniqueId();
if (playerSteam.ID == 0) continue; //bot
auto playerSteam = player.GetUniqueIdWrapper();
if (playerSteam.GetUID() == 0) continue; //bot
if (!mmrWrapper.IsSyncing(playerSteam)) {
auto mmr = mmrWrapper.GetPlayerMMR(playerSteam, playlist);
auto extra = mmrWrapper.GetPlayerRank(playerSteam, playlist);
Expand All @@ -447,18 +451,18 @@ void AutoReplayUploaderPlugin::GetPlayerData(ServerWrapper caller, void* params,
* when uploading the replay, and that is why we save it in at start of the match. *
*****************************************************************************************/

//Function GameEvent_Soccar_TA.Active.StartRound -event will fire in all modes
//like freeplay, custom training etc. Set the needToUploadReplay flag replay only
//if we are in an online game.
if (gameWrapper->IsInOnlineGame()) {
needToUploadReplay = true;
} else {
//If we are not in online game, we are in freeplay, custom training etc
// We will set the needToUploadReplay flag to false and no need to save the player data.
needToUploadReplay = false;
return;
// Function GameEvent_Soccar_TA.Active.StartRound -event will fire in all modes
// like freeplay, custom training etc. Set the needToUploadReplay flag replay only
// if we are in an online game. Online freeplay is also an online game mode, but we will
// only upload those replays if CVAR_UPLOAD_ONLINE_FREEPLAY (bound to uploadOnlineFreeplay)
// has been set to true.

int playlistID = caller.GetPlaylist().GetPlaylistId();
needToUploadReplay = gameWrapper->IsInOnlineGame() && (playlistID != ONLINE_FREEPLAY_PLAYLIST_ID ? true : *uploadOnlineFreeplay);
if (!needToUploadReplay) {
return;
}

// We are in online game and now storing some important player data, if needed after the game
// When uploading the replay.
backupPlayerSteamID = std::to_string(gameWrapper->GetSteamID());
Expand Down
2 changes: 2 additions & 0 deletions AutoReplayUploader/AutoReplayUploaderPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#define DEAULT_EXPORT_PATH "./bakkesmod/data/"
#define DEFAULT_REPLAY_NAME_TEMPLATE "{YEAR}-{MONTH}-{DAY}.{HOUR}.{MIN} {PLAYER} {MODE} {WINLOSS}"
#define ONLINE_FREEPLAY_PLAYLIST_ID 73

// TODO: uncomment or remove #ifdef's when new Bakkes mod API becomes available that has Toast notifications
//#define TOAST
Expand All @@ -25,6 +26,7 @@ class AutoReplayUploaderPlugin : public BakkesMod::Plugin::BakkesModPlugin
std::shared_ptr<bool> uploadToCalculated = std::make_shared<bool>(false);
std::shared_ptr<bool> uploadToBallchasing = std::make_shared<bool>(false);
std::shared_ptr<bool> uploadToBallchasingMMR = std::make_shared<bool>(false);
std::shared_ptr<bool> uploadOnlineFreeplay = std::make_shared<bool>(false);

// Replay name template variables
std::shared_ptr<int> templateSequence = std::make_shared<int>(0);
Expand Down
2 changes: 1 addition & 1 deletion AutoReplayUploader/bakkesmod.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(BakkesModPath)\bakkesmodsdk\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>bakkesmod.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>pluginsdk.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>python "$(BakkesModPath)\bakkesmodsdk\bakkes_patchplugin.py" "$(TargetPath)"</Command>
Expand Down
5 changes: 4 additions & 1 deletion autoreplayuploader.set
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ Auto replay uploader
8|
1|Save all replay files to export filepath below|cl_autoreplayupload_save
12|Path to export replays to|cl_autoreplayupload_filepath
9|Note: For this to work, you do NOT have to have "save all replays" enabled!
9|Note: For this to work, you do NOT have to have "save all replays" enabled!
8|
1|Upload Online Freeplay replays|cl_autoreplayupload_online_freeplay
9|Note: You probably do not want to upload Online Freeplay replays.