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: 6 additions & 1 deletion NydusNetwork/GameClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ public void Initialize(bool asHost) {

public void LaunchClient(bool asHost) {
_isHost = asHost;
Process.Start(new ProcessStartInfo { FileName = _settings.ExecutableClientPath(),Arguments = _settings.ToArguments(_isHost),WorkingDirectory = _settings.WorkingDirectory() });
Process.Start(
new ProcessStartInfo {
FileName = _settings.ExecutableClientPath(),
Arguments = _settings.ToArguments(_isHost),
WorkingDirectory = _settings.WorkingDirectory(),
});
}
public bool ConnectToClient()
=> _connection.Connect(_settings.GetUri(_isHost));
Expand Down
6 changes: 3 additions & 3 deletions NydusNetwork/Services/GameSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static Request CreateGameRequest(this GameSettings gs) {
PlayerSetup = { gs.Opponents,new PlayerSetup { Type = PlayerType.Participant,Race = gs.ParticipantRace } }
}
};
if(File.Exists(gs.GameMap) || File.Exists($"{gs.FolderPath}\\Maps\\{gs.GameMap}"))
if (File.Exists(gs.GameMap) || File.Exists(Path.Combine(gs.FolderPath, "Maps", gs.GameMap)))
r.CreateGame.LocalMap = new LocalMap { MapPath = gs.GameMap };
else
r.CreateGame.BattlenetMapName = gs.GameMap;
Expand All @@ -74,11 +74,11 @@ public static Request CreateGameRequest(this GameSettings gs) {
public static Uri GetUri(this GameSettings gs,bool IsHost)
=> IsHost ? new Uri($"ws://{gs.ConnectionAddress}:{gs.ConnectionServerPort}/sc2api") : new Uri($"ws://{gs.ConnectionAddress}:{gs.ConnectionClientPort}/sc2api");

public static string WorkingDirectory(this GameSettings gs) => $"{gs.FolderPath}\\Support";
public static string WorkingDirectory(this GameSettings gs) => Path.Combine(gs.FolderPath, "Support");

public static string ExecutableClientPath(this GameSettings gs) {
if(System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX))
return Directory.GetDirectories(gs.FolderPath + @"\Versions\",@"Base*")[0] + @"\SC2.app";
return Directory.GetDirectories(gs.FolderPath + @"/Versions/",@"Base*")[0] + @"/SC2.app/Contents/MacOS/SC2";
else
return Directory.GetDirectories(gs.FolderPath + @"\Versions\",@"Base*")[0] + @"\SC2.exe";
}
Expand Down
14 changes: 7 additions & 7 deletions SC2Abathur/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class Program {
/// <param name="args">First argument will be used as datapath, second as logpath</param>
static void Main(string[] args) {
Console.Title = $"Abathur Framework v{AbathurVersion} and NydusNetwork v{NydusNetworkVersion}";
var dataPath = args.Length > 0 ? args[0] : Directory.GetCurrentDirectory() + "\\data\\";
var logPath = args.Length > 1 ? args[0] : Directory.GetCurrentDirectory() + "\\log\\";
var dataPath = args.Length > 0 ? args[0] : Path.Combine(Directory.GetCurrentDirectory(), "data");
var logPath = args.Length > 1 ? args[0] : Path.Combine(Directory.GetCurrentDirectory(), "log");
new Program().Run(dataPath, logPath);
}

Expand All @@ -58,16 +58,16 @@ public void Run(string dataPath,string logPath = null) {

// Check that the game settings file exist, or create it a default template.
log?.LogMessage("Checking game settings file:");
FileService.ValidateOrCreateJsonFile(dataPath + "gamesettings.json",Defaults.GameSettings,log);
GameSettings gameSettings = FileService.ReadFromJson<GameSettings>(dataPath + "gamesettings.json",log);
FileService.ValidateOrCreateJsonFile(Path.Combine(dataPath, "gamesettings.json") ,Defaults.GameSettings,log);
GameSettings gameSettings = FileService.ReadFromJson<GameSettings>(Path.Combine(dataPath, "gamesettings.json"), log);

// Load the Abathur setup file, this file is used to add/remove modules to the framework
log?.LogMessage("Checking setup file:");
FileService.ValidateOrCreateJsonFile(dataPath + "setup.json",Defaults.AbathurSetup,log);
AbathurSetup abathurSetup = FileService.ReadFromJson<AbathurSetup>(dataPath + "setup.json",log);
FileService.ValidateOrCreateJsonFile(Path.Combine(dataPath, "setup.json"), Defaults.AbathurSetup,log);
AbathurSetup abathurSetup = FileService.ReadFromJson<AbathurSetup>(Path.Combine(dataPath, "setup.json"), log);

// Load or create the 'essence file' - a file containing UnitTypeData, AbilityTypeData, BuffData, UpgradeData and manually coded tech-trees for each race.
var essence = EssenceService.LoadOrCreate(dataPath,log);
var essence = EssenceService.LoadOrCreate(dataPath,log,gameSettings);

// If a log path have been specified, check the directory and change add a filelogger (writes to files)
if(logPath != null) {
Expand Down
19 changes: 10 additions & 9 deletions SC2Abathur/Services/EssenceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Google.Protobuf;
using NydusNetwork.API.Protocol;
using NydusNetwork.Logging;
using NydusNetwork.Model;
using SC2Abathur.Settings;
using System;
using System.IO;

Expand All @@ -18,10 +20,10 @@ public class EssenceService {
/// <param name="dataPath">Valid path for data directory used by Abathur</param>
/// <param name="log">Optional log</param>
/// <returns></returns>
public static Essence LoadOrCreate(string dataPath, ILogger log = null) {
public static Essence LoadOrCreate(string dataPath, ILogger log = null, GameSettings gs = null) {
log?.LogMessage("Checking binary essence file:");
ValidateOrCreateBinaryFile(dataPath + "essence.data",() => FetchDataFromClient(log),log);
return Load(dataPath + "essence.data",log);
ValidateOrCreateBinaryFile(Path.Combine(dataPath, "essence.data"), gs ?? Defaults.GameSettings, log);
return Load(Path.Combine(dataPath, "essence.data"), log);
}

/// <summary>
Expand All @@ -45,15 +47,14 @@ public static Essence Load(string path,ILogger log = null) {
/// <param name="path">Path to validate</param>
/// <param name="content">Function to get content in case the file does not exist</param>
/// <param name="log">Optional log</param>
private static void ValidateOrCreateBinaryFile<T>(string path,Func<T> content,ILogger log = null) where T : IMessage {
private static void ValidateOrCreateBinaryFile(string path, GameSettings gs, ILogger log = null) {
try {
if(File.Exists(path)) {
log?.LogSuccess($"\tFOUND: {path}");
} else {
var msg = content.Invoke();
FileStream stream = File.Create(path);
var msg = FetchDataFromClient(gs, log);
using FileStream stream = File.Create(path);
msg.WriteTo(stream);
stream.Close();
log?.LogWarning($"\tCREATED: {path}");
}
} catch(Exception e) { log.LogError($"\tFAILED: {e.Message}"); }
Expand All @@ -64,9 +65,9 @@ private static void ValidateOrCreateBinaryFile<T>(string path,Func<T> content,IL
/// </summary>
/// <param name="log">Optional log</param>
/// <returns></returns>
private static Essence FetchDataFromClient(ILogger log = null) {
private static Essence FetchDataFromClient(GameSettings gs, ILogger log = null) {
var factory = new EssenceFactory(log);
return factory.FetchFromClient(Settings.Defaults.GameSettings);
return factory.FetchFromClient(gs);
}
}
}
18 changes: 13 additions & 5 deletions SC2Abathur/Settings/Defaults.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Abathur.Constants;
using SC2Abathur.Settings;
using NydusNetwork.API.Protocol;
using NydusNetwork.API.Protocol;
using NydusNetwork.Model;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand All @@ -16,12 +14,22 @@ public static class Defaults {
/// <summary>
/// Used for setting up the modules in the Abathur framework.
/// </summary>
public static AbathurSetup AbathurSetup => new AbathurSetup { IsParallelized = false, Modules = new List<string>{ "RandomDemo", "AutoHarvestGather", "AutoSupply" } };
public static AbathurSetup AbathurSetup => new AbathurSetup {
IsParallelized = false,
Modules = new List<string>{
"RandomDemo",
"AutoHarvestGather",
"AutoSupply"
}
};

/// <summary>
/// Stores game related settings used by the StarCraft II client.
/// </summary>
public static GameSettings GameSettings => new GameSettings {
FolderPath = @"C:\Program Files (x86)\StarCraft II",
FolderPath =
System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX)
? @"/Applications/StarCraft II" : @"C:\Program Files (x86)\StarCraft II",
ConnectionAddress = IPAddress.Loopback.ToString(),
ConnectionServerPort = 8165,
ConnectionClientPort = 8170,
Expand Down