-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Your Name
committed
Sep 14, 2018
1 parent
77eb2b9
commit 9f1fbf6
Showing
27 changed files
with
2,829 additions
and
895 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
struct player { | ||
const char* name; | ||
const char* type; | ||
const char* race; | ||
const char* result; | ||
}; | ||
|
||
struct APIState { | ||
std::vector<const char*> activeScreens; | ||
bool isReplay; | ||
double displayTime; | ||
std::vector<player*> players; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,53 @@ | ||
project(sc2switcher) | ||
|
||
project(sc2switcher3) | ||
include_directories(${OBS_JANSSON_INCLUDE_DIRS}) | ||
|
||
set(sc2switcher_HEADERS | ||
${sc2switcher_HEADERS} | ||
auto-scene-switcher.hpp | ||
tool-helpers.hpp | ||
set(sc2switcher3_HEADERS | ||
${sc2switcher3_HEADERS} | ||
SC2Data.h | ||
Observer.h | ||
SC2State.h | ||
Constants.h | ||
SceneSwitcher.h | ||
ScoreTracker.h | ||
Webhook.h | ||
Config.h | ||
forms/SettingsDialog.h | ||
) | ||
set(sc2switcher_SOURCES | ||
${sc2switcher_SOURCES} | ||
sc2switcher.c | ||
auto-scene-switcher.cpp | ||
set(sc2switcher3_SOURCES | ||
${sc2switcher3_SOURCES} | ||
sc2switcher.cpp | ||
SC2Data.cpp | ||
SC2State.cpp | ||
SceneSwitcher.cpp | ||
ScoreTracker.cpp | ||
Webhook.cpp | ||
Config.cpp | ||
forms/SettingsDialog.cpp | ||
) | ||
set(sc2switcher_UI | ||
${sc2switcher_UI} | ||
forms/auto-scene-switcher.ui | ||
set(sc2switcher3_UI | ||
${sc2switcher3_UI} | ||
forms/SettingsDialog.ui | ||
) | ||
set(sc2switcher_PLATFORM_LIBS | ||
set(sc2switcher3_PLATFORM_LIBS | ||
${OBS_JANSSON_IMPORT} | ||
) | ||
|
||
qt5_wrap_ui(sc2switcher_UI_HEADERS | ||
${sc2switcher_UI} | ||
${sc2switcher_PLATFORM_UI}) | ||
qt5_wrap_ui(sc2switcher3_UI_HEADERS | ||
${sc2switcher3_UI} | ||
${sc2switcher3_PLATFORM_UI}) | ||
|
||
add_library(sc2switcher MODULE | ||
${sc2switcher_HEADERS} | ||
${sc2switcher_SOURCES} | ||
${sc2switcher_UI_HEADERS} | ||
${sc2switcher_PLATFORM_SOURCES} | ||
${sc2switcher_PLATFORM_HEADERS} | ||
add_library(sc2switcher3 MODULE | ||
${sc2switcher3_HEADERS} | ||
${sc2switcher3_SOURCES} | ||
${sc2switcher3_UI_HEADERS} | ||
${sc2switcher3_PLATFORM_SOURCES} | ||
${sc2switcher3_PLATFORM_HEADERS} | ||
) | ||
target_link_libraries(sc2switcher | ||
${sc2switcher_PLATFORM_LIBS} | ||
target_link_libraries(sc2switcher3 | ||
${sc2switcher3_PLATFORM_LIBS} | ||
obs-frontend-api | ||
Qt5::Widgets | ||
libobs | ||
${LIBCURL_LIBRARIES}) | ||
${LIBCURL_LIBRARIES} | ||
libobs) | ||
|
||
install_obs_plugin(sc2switcher) | ||
install_obs_plugin(sc2switcher3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <curl/curl.h> | ||
#include <jansson.h> | ||
#include "Config.h" | ||
|
||
Config* Config::_instance = new Config(); | ||
|
||
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) | ||
{ | ||
((std::string*)userp)->append((char*)contents, size * nmemb); | ||
return size * nmemb; | ||
} | ||
|
||
Config::Config() : | ||
ipAddr(std::string("localhost")), | ||
scoreString(std::string("vT: ${tw}-${tl}\nvZ: ${zw}-${zl}\nvP: ${pw}-${pl}")), | ||
isRunning(false), | ||
switcherEnabled(false), | ||
scoresEnabled(false), | ||
popupsEnabled(true) {} | ||
|
||
Config* Config::Current() { | ||
return _instance; | ||
} | ||
|
||
Config::~Config() { | ||
delete _instance; | ||
} | ||
|
||
void Config::checkForUpdates() { | ||
CURL *curl; | ||
CURLcode res; | ||
std::string response; | ||
|
||
curl = curl_easy_init(); | ||
if (curl) { | ||
std::string reqURL = "https://api.github.com/repos/leigholiver/OBS-SC2Switcher/releases/latest"; | ||
|
||
struct curl_slist *chunk = NULL; | ||
|
||
curl_easy_setopt(curl, CURLOPT_URL, reqURL.c_str()); | ||
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 500); | ||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); | ||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); | ||
|
||
chunk = curl_slist_append(chunk, "User-Agent: OBS-SC2Switcher"); | ||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); | ||
|
||
res = curl_easy_perform(curl); | ||
curl_easy_cleanup(curl); | ||
if (res != CURLE_OK) { | ||
return; | ||
} | ||
} | ||
|
||
json_error_t error; | ||
json_t* root = json_loads(response.c_str(), 0, &error); | ||
if (!root) { | ||
return; | ||
} | ||
|
||
json_t* url = json_object_get(root, "tag_name"); | ||
const char *urlText = json_string_value(url); | ||
float latestVer = stof(urlText); | ||
float currentVer = 0.9; | ||
if(latestVer > currentVer) { | ||
json_t* url2 = json_object_get(root, "html_url"); | ||
const char *urlText2 = json_string_value(url2); | ||
updateURL = urlText2; | ||
|
||
json_t* patch = json_object_get(root, "body"); | ||
const char *patchText = json_string_value(patch); | ||
updateDescription = patchText; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
|
||
#pragma once | ||
#include <obs.hpp> | ||
#include <vector> | ||
#include <string> | ||
|
||
#include "Constants.h" | ||
#include "obs-util.h" | ||
#include <obs-frontend-api.h> | ||
|
||
using namespace std; | ||
|
||
class Config { | ||
public: | ||
Config(); | ||
~Config(); | ||
static Config* Current(); | ||
|
||
// sc2data | ||
std::string ipAddr; | ||
vector<std::string> usernames; | ||
vector<std::string> recentUsernames; | ||
|
||
// scene switcher | ||
OBSWeakSource inGameScene; | ||
OBSWeakSource outGameScene; | ||
OBSWeakSource replayScene; | ||
OBSWeakSource obsScene; | ||
OBSWeakSource menuScenes[10]; | ||
|
||
// score tracker | ||
std::string textSourceName; | ||
std::string scoreString; | ||
|
||
bool isRunning; | ||
|
||
std::string updateURL; | ||
std::string updateDescription; | ||
void checkForUpdates(); | ||
|
||
bool switcherEnabled; | ||
bool scoresEnabled; | ||
bool popupsEnabled; | ||
|
||
bool webhookEnabled; | ||
|
||
vector<std::string> webhookURLList; | ||
|
||
private: | ||
static Config* _instance; | ||
}; | ||
|
||
|
||
static void LoadSaveHandler(obs_data_t *save_data, bool saving, void *) { | ||
Config* cfg = Config::Current(); | ||
|
||
if (saving) { | ||
obs_data_t *obj = obs_data_create(); | ||
|
||
// settings | ||
obs_data_set_bool(obj, "is_running", cfg->isRunning); | ||
obs_data_set_bool(obj, "switcher_enabled", cfg->switcherEnabled); | ||
obs_data_set_bool(obj, "scores_enabled", cfg->scoresEnabled); | ||
obs_data_set_bool(obj, "popups_enabled", cfg->popupsEnabled); | ||
obs_data_set_string(obj, "ip_addr", cfg->ipAddr.c_str()); | ||
obs_data_set_bool(obj, "webhook_enabled", cfg->webhookEnabled); | ||
|
||
obs_data_array_t *array = obs_data_array_create(); | ||
for (string &s : cfg->webhookURLList) { | ||
obs_data_t *array_obj = obs_data_create(); | ||
obs_data_set_string(array_obj, "URL", s.c_str()); | ||
obs_data_array_push_back(array, array_obj); | ||
obs_data_release(array_obj); | ||
} | ||
obs_data_set_array(obj, "webhookURLs", array); | ||
obs_data_array_release(array); | ||
|
||
obs_data_array_t *array2 = obs_data_array_create(); | ||
for (string &s : cfg->usernames) { | ||
obs_data_t *array_obj = obs_data_create(); | ||
obs_data_set_string(array_obj, "username", s.c_str()); | ||
obs_data_array_push_back(array2, array_obj); | ||
obs_data_release(array_obj); | ||
} | ||
obs_data_set_array(obj, "usernames", array2); | ||
obs_data_array_release(array2); | ||
|
||
obs_data_set_string(obj, "textSourceName", cfg->textSourceName.c_str()); | ||
obs_data_set_string(obj, "scoreString", cfg->scoreString.c_str()); | ||
|
||
// scenes | ||
obs_data_set_string(obj, "in_game_scene", GetWeakSourceName(cfg->inGameScene).c_str()); | ||
obs_data_set_string(obj, "out_game_scene", GetWeakSourceName(cfg->outGameScene).c_str()); | ||
obs_data_set_string(obj, "replay_scene", GetWeakSourceName(cfg->replayScene).c_str()); | ||
obs_data_set_string(obj, "obs_scene", GetWeakSourceName(cfg->obsScene).c_str()); | ||
obs_data_set_string(obj, "MENU_SCORESCREEN", GetWeakSourceName(cfg->menuScenes[MENU_SCORESCREEN]).c_str()); | ||
obs_data_set_string(obj, "MENU_PROFILE", GetWeakSourceName(cfg->menuScenes[MENU_PROFILE]).c_str()); | ||
obs_data_set_string(obj, "MENU_LOBBY", GetWeakSourceName(cfg->menuScenes[MENU_LOBBY]).c_str()); | ||
obs_data_set_string(obj, "MENU_HOME", GetWeakSourceName(cfg->menuScenes[MENU_HOME]).c_str()); | ||
obs_data_set_string(obj, "MENU_CAMPAIGN", GetWeakSourceName(cfg->menuScenes[MENU_CAMPAIGN]).c_str()); | ||
obs_data_set_string(obj, "MENU_COLLECTION", GetWeakSourceName(cfg->menuScenes[MENU_COLLECTION]).c_str()); | ||
obs_data_set_string(obj, "MENU_COOP", GetWeakSourceName(cfg->menuScenes[MENU_COOP]).c_str()); | ||
obs_data_set_string(obj, "MENU_CUSTOM", GetWeakSourceName(cfg->menuScenes[MENU_CUSTOM]).c_str()); | ||
obs_data_set_string(obj, "MENU_REPLAYS", GetWeakSourceName(cfg->menuScenes[MENU_REPLAYS]).c_str()); | ||
obs_data_set_string(obj, "MENU_VERSUS", GetWeakSourceName(cfg->menuScenes[MENU_VERSUS]).c_str()); | ||
|
||
|
||
obs_data_set_obj(save_data, "sc2switcher2", obj); | ||
obs_data_release(obj); | ||
} | ||
else { | ||
obs_data_t *obj = obs_data_get_obj(save_data, "sc2switcher2"); | ||
if (!obj) { | ||
obj = obs_data_create(); | ||
} | ||
cfg->ipAddr = obs_data_get_string(obj, "ip_addr"); | ||
|
||
obs_data_array_t *array = obs_data_get_array(obj, "usernames"); | ||
size_t count = obs_data_array_count(array); | ||
for (size_t i = 0; i < count; i++) { | ||
obs_data_t *array_obj = obs_data_array_item(array, i); | ||
cfg->usernames.push_back(obs_data_get_string(array_obj, "username")); | ||
obs_data_release(array_obj); | ||
} | ||
obs_data_array_release(array); | ||
|
||
obs_data_array_t *array2 = obs_data_get_array(obj, "webhookURLs"); | ||
size_t count2 = obs_data_array_count(array2); | ||
for (size_t i = 0; i < count2; i++) { | ||
obs_data_t *array_obj = obs_data_array_item(array2, i); | ||
cfg->webhookURLList.push_back(obs_data_get_string(array_obj, "URL")); | ||
obs_data_release(array_obj); | ||
} | ||
obs_data_array_release(array2); | ||
|
||
cfg->textSourceName = obs_data_get_string(obj, "textSourceName"); | ||
|
||
|
||
string scoreString = obs_data_get_string(obj, "scoreString"); | ||
if (scoreString != "") { | ||
cfg->scoreString = scoreString; | ||
} | ||
|
||
cfg->isRunning = obs_data_get_bool(obj, "is_running"); | ||
cfg->switcherEnabled = obs_data_get_bool(obj, "switcher_enabled"); | ||
cfg->scoresEnabled = obs_data_get_bool(obj, "scores_enabled"); | ||
cfg->popupsEnabled = obs_data_get_bool(obj, "popups_enabled"); | ||
|
||
cfg->inGameScene = GetWeakSourceByName(obs_data_get_string(obj, "in_game_scene")); | ||
cfg->outGameScene = GetWeakSourceByName(obs_data_get_string(obj, "out_game_scene")); | ||
cfg->replayScene = GetWeakSourceByName(obs_data_get_string(obj, "replay_scene")); | ||
cfg->obsScene = GetWeakSourceByName(obs_data_get_string(obj, "obs_scene")); | ||
cfg->menuScenes[MENU_SCORESCREEN] = GetWeakSourceByName(obs_data_get_string(obj, "MENU_SCORESCREEN")); | ||
cfg->menuScenes[MENU_PROFILE] = GetWeakSourceByName(obs_data_get_string(obj, "MENU_PROFILE")); | ||
cfg->menuScenes[MENU_LOBBY] = GetWeakSourceByName(obs_data_get_string(obj, "MENU_LOBBY")); | ||
cfg->menuScenes[MENU_HOME] = GetWeakSourceByName(obs_data_get_string(obj, "MENU_HOME")); | ||
cfg->menuScenes[MENU_CAMPAIGN] = GetWeakSourceByName(obs_data_get_string(obj, "MENU_CAMPAIGN")); | ||
cfg->menuScenes[MENU_COLLECTION] = GetWeakSourceByName(obs_data_get_string(obj, "MENU_COLLECTION")); | ||
cfg->menuScenes[MENU_COOP] = GetWeakSourceByName(obs_data_get_string(obj, "MENU_COOP")); | ||
cfg->menuScenes[MENU_CUSTOM] = GetWeakSourceByName(obs_data_get_string(obj, "MENU_CUSTOM")); | ||
cfg->menuScenes[MENU_REPLAYS] = GetWeakSourceByName(obs_data_get_string(obj, "MENU_REPLAYS")); | ||
cfg->menuScenes[MENU_VERSUS] = GetWeakSourceByName(obs_data_get_string(obj, "MENU_VERSUS")); | ||
|
||
cfg->webhookEnabled = obs_data_get_bool(obj, "webhook_enabled"); | ||
|
||
obs_data_release(obj); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
// the order is important with these as the labels are not | ||
// in a consistent order in sc2. the scene switcher will | ||
// use whichever it comes accross first. menu consts must | ||
// go first so that they match up to the menuLabels array | ||
// properly. this is kind of bad? | ||
const int MENU_SCORESCREEN = 0; | ||
const int MENU_PROFILE = 1; | ||
const int MENU_LOBBY = 2; | ||
const int MENU_HOME = 3; | ||
const int MENU_CAMPAIGN = 4; | ||
const int MENU_COLLECTION = 5; | ||
const int MENU_COOP = 6; | ||
const int MENU_CUSTOM = 7; | ||
const int MENU_REPLAYS = 8; | ||
const int MENU_VERSUS = 9; | ||
const int MENU_NONE = 10; | ||
|
||
const char* const menuLabels[] = { | ||
"ScreenScore/ScreenScore", | ||
"ScreenUserProfile/ScreenUserProfile", | ||
"ScreenBattleLobby/ScreenBattleLobby", | ||
"ScreenHome/ScreenHome", | ||
"ScreenSingle/ScreenSingle", | ||
"ScreenCollection/ScreenCollection", | ||
"ScreenCoopCampaign/ScreenCoopCampaign", | ||
"ScreenCustom/ScreenCustom", | ||
"ScreenReplay/ScreenReplay", | ||
"ScreenMultiplayer/ScreenMultiplayer", | ||
}; | ||
|
||
const int APP_INGAME = 11; | ||
const int APP_MENU = 12; | ||
const int APP_LOADING = 13; | ||
|
||
const int GAME_INGAME = 14; | ||
const int GAME_OBS = 15; | ||
const int GAME_REPLAY = 16; |
Oops, something went wrong.