Skip to content

Commit

Permalink
Fix for SE crossplay update.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gwindalmir committed Feb 11, 2021
1 parent 75b225c commit 7b055c8
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 72 deletions.
56 changes: 24 additions & 32 deletions SEWorkshopTool/SpaceGame.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using Phoenix.WorkshopTool;
using Sandbox;
using Sandbox.Engine.Networking;
using Sandbox.Game;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Reflection;
using VRage;
using VRage.GameServices;
using VRage.Mod.Io;
using VRage.Scripting;
using VRage.Steam;
using VRage.Utils;
using VRageRender;

Expand All @@ -33,23 +36,27 @@ protected override bool SetupBasicGameInfo()

var appDataPath = m_startup.GetAppDataPath();
VRage.Platform.Windows.MyVRageWindows.Init(MyPerGameSettings.BasicGameInfo.ApplicationName, MySandboxGame.Log, appDataPath, false);
MyVRage.Platform.InitScripting(MyVRageScripting.Create());
MyInitializer.InvokeBeforeRun(AppId, MyPerGameSettings.BasicGameInfo.ApplicationName + "ModTool", MyVRage.Platform.System.GetAppDataPath());
MyRenderProxy.Initialize((IMyRender)new MyNullRender());
MyInitializer.InitCheckSum();

if (m_startup.PerformColdStart()) return false;
if (!m_startup.Check64Bit()) return false;

m_steamService = VRage.Steam.MySteamGameService.Create(MySandboxGame.IsDedicated, AppId);
m_steamService = MySteamGameService.Create(MySandboxGame.IsDedicated, AppId);
MyServiceManager.Instance.AddService(m_steamService);
MyServiceManager.Instance.AddService(VRage.Steam.MySteamUgcService.Create(AppId, m_steamService));
MyServerDiscoveryAggregator serverDiscoveryAggregator = new MyServerDiscoveryAggregator();
MySteamGameService.InitNetworking(false, m_steamService, serverDiscoveryAggregator, true, true);

// If user specified --modio, set that as the "default" (added first)
var modioService = MyModIoService.Create(MyServiceManager.Instance.GetService<IMyGameService>(), ModIO_GameName, ModIO_GameID, ModIO_Key, ModIO_TestGameID, ModIO_TestKey, MyPlatformGameSettings.UGC_TEST_ENVIRONMENT);

if (m_useModIO)
{
MySandboxGame.Log.WriteLineAndConsole("Using mod.io service, instead of Steam.");
MyServiceManager.Instance.AddService(VRage.Mod.Io.MyModIoService.Create(MySandboxGame.IsDedicated, MyServiceManager.Instance.GetService<IMyGameService>(), ModIO_GameName, ModIO_GameID, ModIO_Key, ModIO_TestGameID, ModIO_TestKey, false));
}
MyGameService.WorkshopService.AddAggregate(modioService);
MyGameService.WorkshopService.AddAggregate(MySteamUgcService.Create(AppId, m_steamService));

if (!m_useModIO)
MyGameService.WorkshopService.AddAggregate(modioService);

SpaceEngineersGame.SetupPerGameSettings();
ManuallyAddDLCs();
Expand All @@ -63,26 +70,11 @@ protected override MySandboxGame InitGame()

protected void InitModIO()
{
var assemblyname = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(typeof(MySandboxGame).Assembly.Location), "SpaceEngineers.exe");
if (Assembly.ReflectionOnlyLoadFrom(assemblyname) is Assembly asm)
{
if(asm.GetType("SpaceEngineers.MyProgram", false) is Type program)
{
ModIO_GameName = program.GetField("MODIO_GAME_NAME", BindingFlags.NonPublic | BindingFlags.Static)?.GetRawConstantValue() as string;
ModIO_TestGameID = program.GetField("MODIO_TEST_GAMEID", BindingFlags.NonPublic | BindingFlags.Static)?.GetRawConstantValue() as string;
ModIO_TestKey = program.GetField("MODIO_TEST_APIKEY", BindingFlags.NonPublic | BindingFlags.Static)?.GetRawConstantValue() as string;
ModIO_GameID = program.GetField("MODIO_LIVE_GAMEID", BindingFlags.NonPublic | BindingFlags.Static)?.GetRawConstantValue() as string;
ModIO_Key = program.GetField("MODIO_LIVE_APIKEY", BindingFlags.NonPublic | BindingFlags.Static)?.GetRawConstantValue() as string;
}
else
{
MySandboxGame.Log.WriteLineAndConsole(string.Format(Constants.ERROR_Reflection, "SpaceEngineers.MyProgram"));
}
}
else
{
MySandboxGame.Log.WriteLineAndConsole(string.Format(Constants.ERROR_Reflection, "SpaceEngineers.exe"));
}
ModIO_GameName = MyPlatformGameSettings.MODIO_GAME_NAME;
ModIO_TestGameID = MyPlatformGameSettings.MODIO_TEST_GAMEID;
ModIO_TestKey = MyPlatformGameSettings.MODIO_TEST_APIKEY;
ModIO_GameID = MyPlatformGameSettings.MODIO_LIVE_GAMEID;
ModIO_Key = MyPlatformGameSettings.MODIO_LIVE_APIKEY;
}

protected override void AuthenticateWorkshop()
Expand Down Expand Up @@ -110,19 +102,19 @@ protected override void AuthenticateWorkshop()

if (string.IsNullOrEmpty(token))
{
Sandbox.Engine.Networking.MyGameService.WorkshopService.RequestSecurityCode(email, (r) =>
var clsMyModIo = typeof(VRage.Mod.Io.MyModIoService).Assembly.GetType("VRage.Mod.Io.MyModIo");
clsMyModIo.InvokeMember("EmailRequest", BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod, null, null, new object[]{email, (Action<MyGameServiceCallResult>)((r) =>
{
if (r == MyGameServiceCallResult.OK)
{
System.Console.WriteLine("Mod.io has sent security code to your email. It expires after 15 minutes.");
System.Console.Write("Enter Security code: ");
var code = System.Console.ReadLine();

Sandbox.Engine.Networking.MyGameService.WorkshopService.AuthenticateWithSecurityCode(code, (a) =>
clsMyModIo.InvokeMember("EmailExchange", BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod, null, null, new object[] { code, (Action<MyGameServiceCallResult>)((a) =>
{
if (a == MyGameServiceCallResult.OK)
{
var clsMyModIo = typeof(VRage.Mod.Io.MyModIoService).Assembly.GetType("VRage.Mod.Io.MyModIo");
System.Console.WriteLine("Authentication successful!");

var accessToken = clsMyModIo.GetField("m_authenticatedToken", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null);
Expand All @@ -137,9 +129,9 @@ protected override void AuthenticateWorkshop()
MySandboxGame.Log.WriteLineAndConsole($"Your authentication token has been saved in {config.FilePath}. Do not delete or replace this file, or you will need to authenticate again.");
PostAuthentication(token, expires);
}
});
})});
}
});
})});
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion WorkshopToolCommon/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public static class Constants
{
public const string Version = "0.7.8.*";
public const string Version = "0.7.9.*";
#if SE
public const string SEWT_Prefix = "[_SEWT_]";
#else
Expand Down
25 changes: 25 additions & 0 deletions WorkshopToolCommon/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,29 @@ public static void WriteLineToConsole(this MyLog log, string msg)
log.WriteLineAndConsole(msg);
}
}

public static class WorkshopIdHelper
{
#if SE
public static string AsString(this VRage.Game.WorkshopId[] ids)
{
var result = new StringBuilder();

if (ids is null)
return result.ToString();

foreach (var id in ids)
result.Append($"{id.ServiceName ?? string.Empty}/{id.Id};");

result.Remove(result.Length - 1, 1);

return result.ToString();
}
#else
public static string AsString(this ulong id)
{
return id.ToString();
}
#endif
}
}
21 changes: 17 additions & 4 deletions WorkshopToolCommon/GameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ static bool ProcessItemsUpload(WorkshopType type, List<string> paths, Options op
}

var mod = new Uploader(type, pathname, tags, options.ExcludeExtensions, options.IgnorePaths, options.Compile, options.DryRun, options.Development, options.Visibility, options.Force, options.Thumbnail, options.DLCs, options.Dependencies, description, options.Changelog);
if (options.UpdateOnly && mod.ModId == 0)
if (options.UpdateOnly && ((IMod)mod).ModId == 0)
{
MySandboxGame.Log.WriteLineAndConsole(string.Format("--update-only passed, skipping: {0}", mod.Title));
continue;
Expand All @@ -612,15 +612,20 @@ static bool ProcessItemsUpload(WorkshopType type, List<string> paths, Options op
}
else
{
if (mod.ModId == 0)
if (((IMod)mod).ModId == 0)
{
MySandboxGame.Log.WriteLineAndConsole(string.Format("Mod not published, skipping: {0}", mod.Title));
success = false;
}
else
{
MySandboxGame.Log.WriteLineAndConsole(string.Format("Not uploading: {0}", mod.Title));
#if SE
foreach (var item in mod.ModId)
mod.UpdatePreviewFileOrTags(item.Id, MyGameService.GetUGC(item.ServiceName).CreateWorkshopPublisher());
#else
mod.UpdatePreviewFileOrTags();
#endif
MySandboxGame.Log.WriteLineAndConsole(string.Format("Complete: {0}", mod.Title));
}
}
Expand Down Expand Up @@ -699,7 +704,11 @@ static bool ProcessItemsDownload(WorkshopType type, string[] paths, Options opti
var downloadPath = WorkshopHelper.GetWorkshopItemPath(type);

#if SE
if (MyWorkshop.GetItemsBlockingUGC(modids, items))
var workshopIds = new List<VRage.Game.WorkshopId>();
foreach (var id in modids)
workshopIds.Add(new VRage.Game.WorkshopId(id, MyGameService.GetDefaultUGC().ServiceName));

if (MyWorkshop.GetItemsBlockingUGC(workshopIds, items))
#else
if (MyWorkshop.GetItemsBlocking(modids, items))
#endif
Expand Down Expand Up @@ -809,7 +818,11 @@ static bool ProcessItemsDownload(WorkshopType type, string[] paths, Options opti
{
List<MyWorkshopItem> depItems = new List<MyWorkshopItem>();
#if SE
if (MyWorkshop.GetItemsBlockingUGC(item.Dependencies, depItems))
workshopIds.Clear();
foreach (var id in item.Dependencies)
workshopIds.Add(new VRage.Game.WorkshopId(id, MyGameService.GetDefaultUGC().ServiceName));

if (MyWorkshop.GetItemsBlockingUGC(workshopIds, depItems))
#else
if (MyWorkshop.GetItemsBlocking(item.Dependencies, depItems))
#endif
Expand Down
2 changes: 1 addition & 1 deletion WorkshopToolCommon/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public sealed class Options
public string[] DLCs { get; set; }

#if SE
[Option("modio", HelpText = "Use mod.io instead of Steam.")]
[Option("modio", HelpText = "Use mod.io by default.")]
#endif
public bool ModIO { get; set; } = false;

Expand Down
Loading

0 comments on commit 7b055c8

Please sign in to comment.