Skip to content

Commit 87fd320

Browse files
authored
Merge pull request #6 from Kapilarny/conn
autoupdater fixes
2 parents 703b9fd + df1b337 commit 87fd320

6 files changed

Lines changed: 66 additions & 4 deletions

File tree

updater/lib/src/downloader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <winhttp.h>
66

77
#include "logger.h"
8+
#include "game_type.h"
89

910
Version GetLatestJAPIVersion() {
1011
std::vector<uint8_t> buffer = DownloadFile("raw.githubusercontent.com/Kapilarny/JAPI/master/version.txt");
@@ -261,7 +262,7 @@ void DownloadJAPI(Version version) {
261262
void CreateSteamAppID() {
262263
// Create steam_appid.txt
263264
std::ofstream steam_appid("steam_appid.txt", std::ios::out | std::ios::trunc);
264-
steam_appid << "1372110";
265+
steam_appid << GetGameData().steam_appid;
265266
steam_appid.close();
266267

267268
JINFO("Created steam_appid.txt");

updater/lib/src/game_type.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "game_type.h"
2+
3+
#include <filesystem>
4+
5+
#include "logger.h"
6+
7+
GameData::GameData() {
8+
if(std::filesystem::exists("ASBR.exe")) {
9+
JINFO("Detected ASBR.exe, assuming ASBR");
10+
11+
this->game_type = GameType::ASBR;
12+
this->game_file = "ASBR.exe";
13+
this->steam_appid = "1372110";
14+
} else if(std::filesystem::exists("NSUNSC.exe")) {
15+
JINFO("Detected NSUNSC.exe, assuming Connections");
16+
17+
this->game_type = GameType::CONNECTIONS;
18+
this->game_file = "NSUNSC.exe";
19+
this->steam_appid = "1020790";
20+
} else {
21+
JFATAL("Could not detect game type");
22+
exit(1);
23+
}
24+
}
25+
26+
static GameData game_data;
27+
28+
GameData& GetGameData() {
29+
if(game_data.game_type == GameType::NONE) {
30+
game_data = GameData();
31+
}
32+
33+
return game_data;
34+
}

updater/lib/src/game_type.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <stdint.h>
5+
6+
enum class GameType {
7+
NONE = -1,
8+
ASBR = 0,
9+
CONNECTIONS = 1
10+
};
11+
12+
typedef struct GameData {
13+
GameData();
14+
15+
GameType game_type;
16+
std::string game_file;
17+
std::string steam_appid;
18+
} GameData;
19+
20+
GameData& GetGameData();

updater/lib/src/main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#define JAPI_UPDATER_MAJOR 1
99
#define JAPI_UPDATER_MINOR 1
10-
#define JAPI_UPDATER_PATCH 1
10+
#define JAPI_UPDATER_PATCH 2
1111

1212
typedef struct Version {
1313
uint32_t major;

updater/lib/src/updater.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@
99
#include "utils.h"
1010
#include "logger.h"
1111

12-
#include "updater.h"
12+
#include "game_type.h"
1313

1414
void SaveConfig(toml::table& config) {
1515
std::ofstream config_file("japi/config/updater.cfg", std::ios::out | std::ios::trunc);
1616
config_file << config;
1717
}
1818

1919
int UpdaterMain() {
20+
if(GetGameData().game_type == GameType::NONE) {
21+
JFATAL("Could not detect game type");
22+
return 1;
23+
}
24+
2025
// Check if japi/ exists
2126
if (!std::filesystem::exists("japi")) {
2227
std::filesystem::create_directory("japi");

updater/lib/src/utils.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stdio.h>
55

66
#include "logger.h"
7+
#include "game_type.h"
78

89
void LaunchGame() {
910
// Run ASBR.exe
@@ -19,7 +20,8 @@ void LaunchGame() {
1920
GetCurrentDirectoryA(MAX_PATH, current_directory);
2021

2122
// Append the ASBR.exe path
22-
strcat(current_directory, "\\ASBR.exe");
23+
std::string str = "\\" + GetGameData().game_file;
24+
strcat(current_directory, str.c_str());
2325

2426
JINFO(current_directory);
2527

0 commit comments

Comments
 (0)