Skip to content
Merged
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
11 changes: 10 additions & 1 deletion .github/workflows/release-zip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ jobs:
exit 0
fi

echo "DEBUG: Previous tag: $prev"
echo "DEBUG: Current commit: $current"

diff=$(git diff --name-only "$prev" "$current")
echo "diff_files=$diff" >> $GITHUB_OUTPUT

Expand All @@ -131,6 +134,12 @@ jobs:
if: steps.api_check.outputs.changed == 'true'
run: |
dotnet restore StarMap.API/StarMap.API.csproj
dotnet pack StarMap.API/StarMap.API.csproj -c Release -o ./nupkg /p:PackageVersion=${{ steps.version.outputs.new }}
dotnet pack \
-c Release \
-o ./nupkg \
/p:PackageVersion=${{ steps.version.outputs.new }} \
/p:Version=${{ steps.version.outputs.new }} \
/p:AssemblyVersion=${{ steps.version.outputs.new }} \
/p:FileVersion=${{ steps.version.outputs.new }}
dotnet nuget add source --username "${{ github.actor }}" --password "${{ secrets.GITHUB_TOKEN }}" --store-password-in-clear-text --name github "${{ env.NUGET_SOURCE }}"
dotnet nuget push ./nupkg/*.nupkg --source github --api-key "${{ secrets.GITHUB_TOKEN }}" --skip-duplicate
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ It makes use of Assembly Load Contexts to ensure mod dependencies are managed se
## Installation

- Download and unzip release from [Releases](https://github.com/StarMapLoader/StarMap/releases/latest).
- Run StarMap.exe, this will fail and create a StarMapLoader.json.
- Open StarMapLoader.json and set the location of your KSA installation.
- `GameLocation` should be set to the location of your KSA.dll, pointing directly to that file (e.g. `C:\\games\\Kitten Space Agency\\KSA.dll`)
- `RepositoryLocation` can be kept empty
- Run StarMap.exe, this will fail and create a StarMapConfig.json.
- Open StarMapConfig.json and set the location of your KSA installation.
- `GameLocation` should be set to the location of your KSA.dll, pointing directly to that file (e.g. `C:\\games\\Kitten Space Agency\\KSA.dll`)
- `RepositoryLocation` can be kept empty
- Run StarMap.exe again, this should launch KSA and load your mods.

## Mod location
Expand All @@ -23,8 +23,8 @@ For more information on mod creation, check out the example mods: [StarMap-Examp

## Future plans

The goal is to create a modloader similar to the mod functionality in Factorio, where users can select mods in game taken from a remote repository, and that those mods than get installed after an automatic restart of the game
It currently does this by using two processes to host the game itself seperately so it can restart
The goal is to create a modloader similar to the mod functionality in Factorio, where users can select mods in game taken from a remote repository, and that those mods than get installed after an automatic restart of the game
It currently does this by using two processes to host the game itself seperately so it can restart
The idea would be to have the repository just be an index of mods, versions and download locations, and that the download locations themselves are seperate (for example github releases)

## Credits
Expand Down
6 changes: 6 additions & 0 deletions StarMap.API/IStarMapInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace StarMap.API
{
public interface IStarMapInterface
{
}
}
4 changes: 2 additions & 2 deletions StarMap.API/IStarMapMod.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace StarMap.Types
namespace StarMap.API
{
public interface IStarMapMod
public interface IStarMapMod : IStarMapInterface
{
bool ImmediateUnload { get; }
void OnImmediatLoad();
Expand Down
8 changes: 8 additions & 0 deletions StarMap.API/IStarMapOnUi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace StarMap.API
{
public interface IStarMapOnUi : IStarMapInterface
{
void OnBeforeUi(double dt);
void OnAfterUi(double dt);
}
}
42 changes: 0 additions & 42 deletions StarMap.Core/ModLoaderPatcher.cs

This file was deleted.

134 changes: 0 additions & 134 deletions StarMap.Core/ModManager.cs

This file was deleted.

93 changes: 93 additions & 0 deletions StarMap.Core/ModRepository/LoadedModRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using HarmonyLib;
using KSA;
using StarMap.API;
using System.Reflection;
using System.Runtime.Loader;

namespace StarMap.Core.ModRepository
{
internal class LoadedModRepository : IDisposable
{
private readonly AssemblyLoadContext _coreAssemblyLoadContext;
private readonly IEnumerable<Type> _registeredInterfaces = [];

private readonly ModRegistry _mods = new();
public ModRegistry Mods => _mods;

public LoadedModRepository(AssemblyLoadContext coreAssemblyLoadContext)
{
_coreAssemblyLoadContext = coreAssemblyLoadContext;

var baseInterface = typeof(IStarMapInterface);
Assembly starMapTypes = baseInterface.Assembly;

_registeredInterfaces = starMapTypes
.GetTypes()
.Where(
t => t.IsInterface &&
baseInterface.IsAssignableFrom(t) &&
t != baseInterface);
}

private bool IsStarMapMod(Type type)
{
return typeof(IStarMapMod).IsAssignableFrom(type) && !type.IsInterface;
}

public void LoadMod(Mod mod)
{
var fullPath = Path.GetFullPath(mod.DirectoryPath);
var filePath = Path.Combine(fullPath, $"{mod.Name}.dll");
var folderExists = Directory.Exists(fullPath);
var fileExists = File.Exists(filePath);

if (!folderExists || !fileExists) return;

var modLoadContext = new ModAssemblyLoadContext(mod, _coreAssemblyLoadContext);
var modAssembly = modLoadContext.LoadFromAssemblyName(new AssemblyName() { Name = mod.Name });

var modClass = modAssembly.GetTypes().FirstOrDefault(IsStarMapMod);
if (modClass is null) return;

if (modClass.CreateInstance() is not IStarMapInterface modObject) return;

foreach (var interfaceType in _registeredInterfaces)
{
if (interfaceType.IsAssignableFrom(modClass))
{
_mods.Add(interfaceType, modObject);
}
}

if (modObject is not IStarMapMod starMapMod) return;

starMapMod.OnImmediatLoad();

if (starMapMod.ImmediateUnload)
{
modLoadContext.Unload();
return;
}

Console.WriteLine($"Loaded mod: {mod.Name}");
}

public void OnAllModsLoaded()
{
foreach (var mod in _mods.Get<IStarMapMod>())
{
mod.OnFullyLoaded();
}
}

public void Dispose()
{
foreach (var mod in _mods.Get<IStarMapMod>())
{
mod.Unload();
}

_mods.Dispose();
}
}
}
Loading
Loading