Skip to content

Commit

Permalink
Merge pull request #14 from jixxed/dev-features
Browse files Browse the repository at this point in the history
add changelog
  • Loading branch information
jixxed authored Feb 5, 2024
2 parents e2dae8c + 872e97f commit 776d9e2
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 13 deletions.
4 changes: 2 additions & 2 deletions StationieersMods/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
using System.Runtime.InteropServices;

// Shared between projects
[assembly: AssemblyVersion("1.0.17.0")]
[assembly: AssemblyFileVersion("1.0.17.0")]
[assembly: AssemblyVersion("1.0.18.0")]
[assembly: AssemblyFileVersion("1.0.18.0")]
57 changes: 56 additions & 1 deletion StationieersMods/StationeersMods.Editor/DevelopmentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Threading.Tasks;
using Assets.Scripts.Objects.Pipes;
using HarmonyLib;
using StationeersMods.Shared;
using UnityEditor;
using UnityEngine;
Expand Down Expand Up @@ -123,8 +124,62 @@ public bool Draw(ExportSettings settings)
}
}
GUILayout.EndHorizontal();

GUILayout.Space(10);
GUILayout.BeginHorizontal();
if (GUILayout.Button("Copy game assemblies to project", GUILayout.Width(buttonWidth), GUILayout.Height(35)))
{
try
{
CopyAssemblies(settings);
EditorUtility.DisplayDialog("Complete", "All files have been copied.", "OK");
}
catch(ArgumentException ex)
{
EditorUtility.DisplayDialog("Error", ex.Message, "OK");
}
}
GUILayout.EndHorizontal();
return true;
}

private void CopyAssemblies(ExportSettings settings)
{
if (!Directory.Exists(settings.StationeersDirectory))
{
throw new ArgumentException("Did you configure the Stationeers directory? Could not find " + settings.StationeersDirectory);
}
var assembliesFolder = Path.Combine(Application.dataPath, "Assemblies");
var assemblies = Path.Combine(assembliesFolder, "copy.txt");
if (!File.Exists(assemblies))
{
throw new ArgumentException("Could not find " + assemblies);
}
List<string> errors = new List<string>();
foreach (var line in File.ReadLines(assemblies))
{
if (line == "")
{
continue;
}
var assemblyToCopy = Path.Combine(settings.StationeersDirectory, line);

if (File.Exists(assemblyToCopy))
{
Debug.Log("Copy: " + assemblyToCopy + " to " + assembliesFolder);
File.Copy(assemblyToCopy,Path.Combine(assembliesFolder, Path.GetFileName(assemblyToCopy)),true);
}
else
{
Debug.LogError("Error: " + assemblyToCopy + " doesn't exist");
errors.Add(assemblyToCopy);
}

}

if (errors.Count > 0)
{
throw new ArgumentException("Failed to copy the following assemblies:\n" + string.Join("\n", errors));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class StationeersTool
public static StationeersTool FIRE_EXTINGUISHER = new StationeersTool( "ItemFireExtinguisher");
public static StationeersTool LABELLER = new StationeersTool( "ItemLabeller");
public static StationeersTool WRENCH = new StationeersTool( "ItemWrench");
public static StationeersTool SCREWDRIVER = new StationeersTool( "ItemScrewdrive");
public static StationeersTool SCREWDRIVER = new StationeersTool( "ItemScrewdriver");
public string PrefabName { get; private set; }

public StationeersTool(string prefabName)
Expand Down
82 changes: 73 additions & 9 deletions StationieersMods/StationeersMods.Plugin/WorkshopMenuPatch.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Assets.Scripts.Networking.Transports;
using Assets.Scripts.Serialization;
using Assets.Scripts.UI;
using HarmonyLib;
using JetBrains.Annotations;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace StationeersMods.Plugin
Expand All @@ -29,10 +29,11 @@ public static void RefreshButtonsPostfix(WorkshopMenu __instance)
Debug.Log("stationeersmods file found.");
__instance.SelectedModButtonRight.GetComponent<Button>().onClick.RemoveAllListeners();
__instance.SelectedModButtonRight.GetComponent<Button>().onClick
.AddListener(() => PublishMod(currentInstance));
.AddListener(delegate() { PublishMod(currentInstance); });

}
}

public static void SelectModPostfix(WorkshopMenu __instance)
{
//if it is a StationeersMods mod
Expand All @@ -47,17 +48,80 @@ public static void SelectModPostfix(WorkshopMenu __instance)
}
}

public static void PublishMod(WorkshopMenu instance)
private static void SaveWorkShopFileHandle(
SteamTransport.WorkShopItemDetail ItemDetail,
ModData mod)
{
var type = typeof(WorkshopMenu);
var publishModMethod = type.GetMethod("PublishMod", BindingFlags.NonPublic | BindingFlags.Instance);
publishModMethod.Invoke(instance,null);
CustomModAbout aboutData = XmlSerialization.Deserialize<CustomModAbout>(mod.AboutXmlPath, "ModMetadata");
aboutData.WorkshopHandle = ItemDetail.PublishedFileId;
aboutData.SaveXml<CustomModAbout>(mod.AboutXmlPath);
}

private static async void PublishMod(WorkshopMenu instance)
{
Debug.Log("Publishing Mod");
ModData mod = GetSelectedModData(instance).Data;
CustomModAbout aboutData = XmlSerialization.Deserialize<CustomModAbout>(mod.AboutXmlPath, "ModMetadata");
string localPath = mod.LocalPath;
string image = localPath + "\\About\\thumb.png";
if(IsValidModData(aboutData, image))
{
SteamTransport.WorkShopItemDetail ItemDetail = new SteamTransport.WorkShopItemDetail()
{
Title = aboutData.Name,
Path = localPath,
PreviewPath = localPath + "\\About\\thumb.png",
Description = aboutData.Description,
PublishedFileId = aboutData.WorkshopHandle,
Type = SteamTransport.WorkshopType.Mod,
CustomTags = aboutData.Tags,
ChangeNote = aboutData.ChangeLog
};
ProgressPanel.ShowProgressBar(false);
var (success, fileId) = await SteamTransport.Workshop_PublishItemAsync(ItemDetail);
HideProgressBar();
if (!success)
return;

ItemDetail.PublishedFileId = fileId;
SaveWorkShopFileHandle(ItemDetail, mod);
AlertPanel.Instance.ShowAlert("Mod has been successfully published", AlertState.Alert);
}
}

private static bool IsValidModData(CustomModAbout aboutData, string image)
{
List<string> errorMessages = new List<string>();
if(aboutData.Name.Length > 128)
{
Debug.Log("Mod title exceeds 128 characters limit");
errorMessages.Add("Mod title exceeds 128 characters limit");
}
if(aboutData.Description.Length > 8000)
{
Debug.Log("Mod description exceeds 8000 characters limit");
errorMessages.Add("Mod description exceeds 8000 characters limit");
}
if(File.Exists(image) && new FileInfo(image).Length > (1024 * 1024))
{
Debug.Log("Mod image size exceeds 1MB limit");
errorMessages.Add("Mod image size exceeds 1MB limit");
}

if (errorMessages.Count == 0) return true;
AlertPanel.Instance.ShowAlert(string.Join("\n", errorMessages), AlertState.Alert);
return false;
}

private static WorkshopModListItem GetSelectedModData(WorkshopMenu instance)
{
var selectedModItem = instance.GetType().GetField("_selectedModItem", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(instance);
return (WorkshopModListItem) selectedModItem;
}
private static void HideProgressBar()
{
typeof(ProgressPanel).GetMethod("HideProgressBar", BindingFlags.NonPublic | BindingFlags.Instance)?.Invoke(ProgressPanel.Instance, null);

}
}
}
3 changes: 3 additions & 0 deletions StationieersMods/StationeersMods/CustomModAbout.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;

namespace StationeersMods.Plugin
Expand All @@ -21,6 +22,8 @@ public class CustomModAbout
[XmlElement]
public string InGameDescription;
[XmlElement]
public string ChangeLog;
[XmlElement]
public ulong WorkshopHandle;
[XmlArray("Tags")]
[XmlArrayItem("Tag")]
Expand Down

0 comments on commit 776d9e2

Please sign in to comment.