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
7 changes: 4 additions & 3 deletions AutoReplayUploader/AutoReplayUploader.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>K:\bakkesmod\BakkesMod-rewrite\BakkesMod Rewrite;K:\bakkesmod\AutoReplayUploader\Uploader;..\Uploader;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  <AdditionalIncludeDirectories>K:\bakkesmod\BakkesMod-rewrite\PluginSDK;K:\bakkesmod\AutoReplayUploader\Uploader;..\Uploader;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

Write

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  <AdditionalIncludeDirectories>K:\bakkesmod\BakkesMod-rewrite\PluginSDK;K:\bakkesmod\AutoReplayUploader\Uploader;..\Uploader;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K:\bakkesmod\BakkesMod-rewrite\PluginSDK;K:\bakkesmod\AutoReplayUploader\Uploader;..\Uploader;%(AdditionalIncludeDirectories)

<PreprocessorDefinitions>_WINDLL;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;TOAST</PreprocessorDefinitions>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_WINDLL;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;TOAST;WIN32_MEAN_AND_LEAN;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_WINDLL;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;TOAST;WIN32_MEAN_AND_LEAN;

<AdditionalIncludeDirectories>K:\bakkesmod\BakkesMod-rewrite\PluginSDK;K:\bakkesmod\AutoReplayUploader\Uploader;..\Uploader;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  <AdditionalIncludeDirectories>K:\bakkesmod\BakkesMod-rewrite\PluginSDK;K:\bakkesmod\AutoReplayUploader\Uploader;..\Uploader;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

StreamLabsRocketLeagueRandomTeamCreator-master.zip

<PreprocessorDefinitions>_WINDLL;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;TOAST;WIN32_MEAN_AND_LEAN;</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<GenerateDebugInformation>False</GenerateDebugInformation>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>BakkesMod.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down
98 changes: 66 additions & 32 deletions AutoReplayUploader/AutoReplayUploaderPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ void AutoReplayUploaderPlugin::onLoad()

// Initialize notification plugin assets
#ifdef TOAST
gameWrapper->LoadToastTexture("calculated_logo", "./bakkesmod/data/assets/calculated_logo.tga");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gameWrapper->LoadToastTexture("calculated_logo", "./bakkesmod/data/assets/calculated_logo.tga");
gameWrapper->LoadToastTexture("calculated_logo", "./bakkesmod/data/assets/calculated_logo.tga");

gameWrapper->LoadToastTexture("ballchasing_logo", "./bakkesmod/data/assets/ballchasing_logo.tga");
gameWrapper->LoadToastTexture("calculated_logo", gameWrapper->FixRelativePath("./bakkesmod/data/assets/calculated_logo.tga"));
gameWrapper->LoadToastTexture("ballchasing_logo", gameWrapper->FixRelativePath("./bakkesmod/data/assets/ballchasing_logo.tga"));
#endif
}

Expand Down Expand Up @@ -199,10 +199,10 @@ void AutoReplayUploaderPlugin::InitializeVariables()

// Path to export replays to
cvarManager->registerCvar(CVAR_REPLAY_EXPORT, "0", "Save all replay files to export filepath above.", true, true, 0, true, 1).bindTo(saveReplay);
cvarManager->registerCvar(CVAR_REPLAY_EXPORT_PATH, DEAULT_EXPORT_PATH, "Path to export replays to.").bindTo(exportPath);
cvarManager->registerCvar(CVAR_REPLAY_EXPORT_PATH, DEFAULT_EXPORT_PATH, "Path to export replays to.").bindTo(exportPath);
cvarManager->getCvar(CVAR_REPLAY_EXPORT_PATH).addOnValueChanged([this](string oldVal, CVarWrapper cvar)
{
if (SanitizeExportPath(exportPath, DEAULT_EXPORT_PATH))
if (SanitizeExportPath(exportPath, DEFAULT_EXPORT_PATH))
{
cvarManager->getCvar(CVAR_REPLAY_EXPORT_PATH).setValue(*exportPath);
}
Expand Down Expand Up @@ -261,41 +261,46 @@ void AutoReplayUploaderPlugin::OnGameComplete(ServerWrapper caller, void * param
// If we have a template for the replay name then set the replay name based off that template else use default template
string replayName = SetReplayName(caller, soccarReplay);


cvarManager->log("Exporting replay!");
// Export the replay to a file for upload
string replayPath = ExportReplay(soccarReplay, replayName);

// If we are saving this with event Function TAGame.GameEvent_Soccar_TA.Destroyed
// the steamID might not be available. Using prestored steamID
string playerSteamID = to_string(gameWrapper->GetSteamID());
if (playerSteamID.length() < 1) {
playerSteamID = backupPlayerSteamID;
cvarManager->log("Using backup steamId to upload: " + playerSteamID);
std::filesystem::path replayPath = ExportReplay(soccarReplay, replayName);
if (!std::filesystem::exists(replayPath) || std::filesystem::is_directory(replayPath))
{
cvarManager->log("Failed exporting replay to " + replayPath.string());
return;
}


UniqueIDWrapper playerSteamID = gameWrapper->GetUniqueID();
std::string uploadID = std::to_string(playerSteamID.GetUID());
if (uploadID.size() < 1) {
uploadID = playerSteamID.str();
cvarManager->log("Using backup steamId to upload: " + uploadID);
} else {
cvarManager->log("Using steamId to upload: " + playerSteamID);
cvarManager->log("Using steamId to upload: " + uploadID);
}

// Upload replay
if (*uploadToCalculated)
{
calculated->UploadReplay(replayPath, playerSteamID);
calculated->UploadReplay(gameWrapper->GetBakkesModPath(), replayPath, uploadID);
}
if (*uploadToBallchasing)
{
ballchasing->UploadReplay(replayPath);
ballchasing->UploadReplay(gameWrapper->GetBakkesModPath(), replayPath);
}

// If we aren't saving the replay remove it after we've uploaded
if (!(*saveReplay))
{
cvarManager->log("Removing replay file: " + replayPath);
remove(replayPath.c_str());
cvarManager->log("Removing replay file: " + replayPath.string());
std::filesystem::remove(replayPath);
}
#ifdef TOAST
else if(*showNotifications)
{
bool exported = file_exists(replayPath);
string msg = exported ? "Exported replay to: " + replayPath : "Failed to export replay to: " + replayPath;
bool exported = std::filesystem::exists(replayPath);
string msg = exported ? "Exported replay to: " + replayPath.string() : "Failed to export replay to: " + replayPath.string();
gameWrapper->Toast("Autoreplayuploader", msg, "default", 3.5f, exported ? ToastType_OK : ToastType_Error);
}
#endif
Expand All @@ -307,7 +312,9 @@ Player ConstructPlayer(PriWrapper wrapper)
if (!wrapper.IsNull())
{
p.Name = wrapper.GetPlayerName().ToString();
p.UniqueId = wrapper.GetUniqueId().ID;
p.UniqueId = wrapper.GetUniqueIdWrapper().GetUID();
p.EpicID = wrapper.GetUniqueIdWrapper().GetEpicAccountID();

p.Team = wrapper.GetTeamNum();
p.Score = wrapper.GetScore();
p.Goals = wrapper.GetMatchGoals();
Expand Down Expand Up @@ -407,6 +414,7 @@ string AutoReplayUploaderPlugin::SetReplayName(ServerWrapper& server, ReplaySocc
cvarManager->log("Using prerecorder username for replay: " + backupMatchForReplayName.PrimaryPlayer.Name);
match.PrimaryPlayer.Name = backupMatchForReplayName.PrimaryPlayer.Name;
match.PrimaryPlayer.UniqueId = backupMatchForReplayName.PrimaryPlayer.UniqueId;
match.PrimaryPlayer.EpicID = backupMatchForReplayName.PrimaryPlayer.EpicID;
match.PrimaryPlayer.Team = backupMatchForReplayName.PrimaryPlayer.Team;
}

Expand All @@ -420,6 +428,20 @@ string AutoReplayUploaderPlugin::SetReplayName(ServerWrapper& server, ReplaySocc
// Get Team scores
match.Team0Score = soccarReplay.GetTeam0Score();
match.Team1Score = soccarReplay.GetTeam1Score();

if (auto matchWinner = server.GetMatchWinner(); !matchWinner.IsNull())
{
match.WinningTeam = matchWinner.GetTeamIndex();
}
else if (auto gameWinner = server.GetGameWinner(); !gameWinner.IsNull())
{
match.WinningTeam = gameWinner.GetTeamIndex();
}
else
{
match.WinningTeam = match.Team0Score > match.Team1Score ? 0 : 1;
}


// Get current Sequence number
auto seq = *templateSequence;
Expand All @@ -440,30 +462,42 @@ string AutoReplayUploaderPlugin::SetReplayName(ServerWrapper& server, ReplaySocc
return replayName;
}

string AutoReplayUploaderPlugin::ExportReplay(ReplaySoccarWrapper& soccarReplay, string replayName)
std::filesystem::path AutoReplayUploaderPlugin::ExportReplay(ReplaySoccarWrapper& soccarReplay, string replayName)
{
string replayPath = CalculateReplayPath(*exportPath, replayName);

std::filesystem::path replayPath = CalculateReplayPath(*exportPath, replayName);
cvarManager->log("Calculated replay path: " + replayPath.string());
if (replayPath.is_relative())
{
cvarManager->log("Path is a relative path, fixing it!");
replayPath = gameWrapper->FixRelativePath(replayPath);
cvarManager->log("Fixed path: " + replayPath.string());
}
// Remove file if it already exists
if (file_exists(replayPath))
if (std::filesystem::exists(replayPath))
{
cvarManager->log("Removing duplicate replay file: " + replayPath);
remove(replayPath.c_str());
cvarManager->log("Removing duplicate replay file: " + replayPath.string());
if (std::filesystem::is_directory(replayPath))
{
cvarManager->log("Calculated export path is somehow a directory. " + replayPath.string());
return replayPath / "err.replay";
}
std::filesystem::remove(replayPath);
cvarManager->log("File removed.");
}

// Export Replay

soccarReplay.ExportReplay(replayPath);
cvarManager->log("Exported replay to: " + replayPath);
cvarManager->log("Exported replay to: " + replayPath.string());

// Check to see if replay exists, if not then export to default path
if (!file_exists(replayPath))
if (!std::filesystem::exists(replayPath))
{
cvarManager->log("Export failed to path: " + replayPath + " exporting to default path.");
replayPath = string(DEAULT_EXPORT_PATH) + "autosaved.replay";
cvarManager->log("Export failed to path: " + replayPath.string() + " exporting to default path.");
replayPath = gameWrapper->GetDataFolder() / "autosaved.replay";

soccarReplay.ExportReplay(replayPath);
cvarManager->log("Exported replay to: " + replayPath);
cvarManager->log("Exported replay to: " + replayPath.string());
}

return replayPath;
Expand Down
8 changes: 4 additions & 4 deletions AutoReplayUploader/AutoReplayUploaderPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include "Ballchasing.h"
#include "Calculated.h"

#pragma comment( lib, "bakkesmod.lib" )
#pragma comment( lib, "pluginsdk.lib" )

using namespace std;

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

// TODO: uncomment or remove #ifdef's when new Bakkes mod API becomes available that has Toast notifications
Expand All @@ -34,13 +34,13 @@ class AutoReplayUploaderPlugin : public BakkesMod::Plugin::BakkesModPlugin

// Export replay variables
shared_ptr<bool> saveReplay = make_shared<bool>(false);
shared_ptr<string> exportPath = make_shared<string>(DEAULT_EXPORT_PATH);
shared_ptr<string> exportPath = make_shared<string>(DEFAULT_EXPORT_PATH);

// Initializes all variables from bakkes mod settings menu
void InitializeVariables();

string SetReplayName(ServerWrapper& server, ReplaySoccarWrapper& soccarReplay);
string ExportReplay(ReplaySoccarWrapper& soccarReplay, string replayName);
std::filesystem::path ExportReplay(ReplaySoccarWrapper& soccarReplay, string replayName);

public:
virtual void onLoad();
Expand Down
65 changes: 45 additions & 20 deletions Uploader/Ballchasing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void BallchasingRequestComplete(PostFileRequest* ctx)
}
ballchasing->NotifyUploadResult(ballchasing->Client, (ctx->Status >= 200 && ctx->Status < 300));

DeleteFile(ctx->FilePath.c_str());
std::filesystem::remove(ctx->FilePath);

delete ctx;
}
Expand All @@ -50,38 +50,63 @@ void BallchasingRequestComplete(GetRequest* ctx)
}
}

void Ballchasing::UploadReplay(string replayPath)
void Ballchasing::UploadReplay(std::filesystem::path startPath, std::filesystem::path replayPath)
{
if (UserAgent.empty() || authKey->empty() || visibility->empty() || replayPath.empty())
{
Log(Client, "Ballchasing::UploadReplay Parameters were empty.");
Log(Client, "UserAgent: " + UserAgent);
Log(Client, "ReplayPath: " + replayPath);
Log(Client, "ReplayPath: " + replayPath.string());
Log(Client, "AuthKey: " + *authKey);
Log(Client, "Visibility: " + *visibility);
return;
}
try
{
if (!std::filesystem::exists(replayPath))
{
Log(Client, "Replay path doesn't exist? " + replayPath.string());
return;
}
std::filesystem::path destPath = startPath / "data/ballchasing/temp.replay";
std::filesystem::path tempFolder = startPath / "data/ballchasing/";
if (!std::filesystem::exists(tempFolder))
{
std::filesystem::create_directory(tempFolder);
}
if (std::filesystem::exists(destPath))
{
Log(Client, "Destination path exists, removing " + destPath.string());
std::filesystem::remove(destPath);
}

string destPath = "./bakkesmod/data/ballchasing/temp.replay";
CreateDirectory("./bakkesmod/data/ballchasing", NULL);
bool resultOfCopy = CopyFile(replayPath.c_str(), destPath.c_str(), FALSE);
std::filesystem::copy(replayPath, destPath);

Log(Client, "ReplayPath: " + replayPath);
Log(Client, "DestPath: " + destPath);
Log(Client, "File copy success: " + std::string(resultOfCopy ? "true" : "false"));
Log(Client, "ReplayPath: " + replayPath.string());
Log(Client, "DestPath: " + destPath.string());
Log(Client, "File copy success: " + std::string(std::filesystem::exists(destPath) ? "true" : "false"));

PostFileRequest *request = new PostFileRequest();
request->Url = AppendGetParams("https://ballchasing.com/api/v2/upload", { {"visibility", *visibility} });
request->FilePath = destPath;
request->ParamName = "file";
request->Headers.push_back("Authorization: " + *authKey);
request->Headers.push_back("UserAgent: " + UserAgent);
request->RequestComplete = &BallchasingRequestComplete;
request->RequestId = 1;
request->Requester = this;
request->Message = "";
PostFileRequest* request = new PostFileRequest();
request->Url = AppendGetParams("https://ballchasing.com/api/v2/upload", { {"visibility", *visibility} });
request->FilePath = destPath;
request->ParamName = "file";
request->Headers.push_back("Authorization: " + *authKey);
request->Headers.push_back("UserAgent: " + UserAgent);
request->RequestComplete = &BallchasingRequestComplete;
request->RequestId = 1;
request->Requester = this;
request->Message = "";

PostFileAsync(request);
PostFileAsync(request);
}
catch (std::exception e)
{
Log(Client, "AutoreplayUploader ERR: " + std::string(e.what()));
}
catch (...)
{
Log(Client, "BAD AutoreplayUploader ERR!");
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Uploader/Ballchasing.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <iostream>

#include <filesystem>
using namespace std;

class Ballchasing
Expand All @@ -22,7 +22,7 @@ class Ballchasing
void(*NotifyUploadResult)(void* object, bool result);
void* Client;

void UploadReplay(string replayPath);
void UploadReplay(std::filesystem::path startPath, std::filesystem::path replayPath);
void TestAuthKey();
};

Loading