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
4 changes: 2 additions & 2 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
env:
DOTNET_VERSION: 9.0
DOTNET_VERSION: 10.0
PROJECT: StarMap/StarMap.csproj
NUGET_SOURCE: "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"

Expand All @@ -32,7 +32,7 @@ jobs:

- name: Restore dependencies
run: |
dotnet nuget add source --username "${{ secrets.ORG_PACKAGE_USERNAME }}" --password "${{ secrets.ORG_PACKAGE_TOKEN }}" --store-password-in-clear-text --name github "${{ env.NUGET_SOURCE }}"
dotnet nuget add source --username "${{ secrets.ORG_PACKAGE_USERNAME }}" --password "${{ secrets.ORG_PACKAGE_TOKEN }}" --store-password-in-clear-text --name StarMapGitHubNugetSource "${{ env.NUGET_SOURCE }}"
dotnet restore ${{ env.PROJECT }}

- name: Build
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/rc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
--username ${{ secrets.ORG_PACKAGE_USERNAME }} \
--password ${{ secrets.ORG_PACKAGE_TOKEN }} \
--store-password-in-clear-text \
--name github "${{ env.NUGET_SOURCE }}"
--name StarMapGitHubNugetSource "${{ env.NUGET_SOURCE }}"

- name: Build
run: |
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
--username ${{ secrets.ORG_PACKAGE_USERNAME }} \
--password ${{ secrets.ORG_PACKAGE_TOKEN }} \
--store-password-in-clear-text \
--name github "${{ env.NUGET_SOURCE }}"
--name StarMapGitHubNugetSource "${{ env.NUGET_SOURCE }}"

- name: Pack and push RC NuGet package
run: |
Expand All @@ -132,7 +132,7 @@ jobs:
/p:Version=${{ needs.build.outputs.new_version }} \
/p:InformationalVersion=${{ needs.build.outputs.hash_version }}
dotnet nuget push ./nupkg/*.nupkg \
--source github \
--source StarMapGitHubNugetSource \
--api-key "${{ secrets.GITHUB_TOKEN }}" \
--skip-duplicate

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
--username ${{ secrets.ORG_PACKAGE_USERNAME }} \
--password ${{ secrets.ORG_PACKAGE_TOKEN }} \
--store-password-in-clear-text \
--name github "${{ env.NUGET_SOURCE }}"
--name StarMapGitHubNugetSource "${{ env.NUGET_SOURCE }}"

- name: Build standalone
run: |
Expand Down Expand Up @@ -159,7 +159,7 @@ jobs:
--username ${{ secrets.ORG_PACKAGE_USERNAME }} \
--password ${{ secrets.ORG_PACKAGE_TOKEN }} \
--store-password-in-clear-text \
--name github "${{ env.NUGET_SOURCE }}"
--name StarMapGitHubNugetSource "${{ env.NUGET_SOURCE }}"

- name: Pack and push StarMap.API (if changed)
run: |
Expand Down
15 changes: 15 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
Comment thread
KlaasWhite marked this conversation as resolved.
</packageSource>
<packageSource key="LocalNuGets">
<package pattern="RocketWerkz.KSA" />
<package pattern="RocketWerkz.KSA.Ref" />
</packageSource>
<packageSource key="StarMapGitHubNugetSource">
<package pattern="RocketWerkz.KSA.Ref" />
</packageSource>
Comment thread
KlaasWhite marked this conversation as resolved.
</packageSourceMapping>
</configuration>
11 changes: 11 additions & 0 deletions StarMap.API/Interfaces/IModMenuService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace StarMap.API.Interfaces
{
public interface IModMenuService
{
IDisposable AddModMenuItem(string label, Action OnClick);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace StarMap.API.Interfaces
{

public interface IPatchHelper
public interface IPatchService
{
enum PatchType
{
Expand Down
1 change: 1 addition & 0 deletions StarMap.API/StarMap.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
23 changes: 23 additions & 0 deletions StarMap.Core/API/ModMenuService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using StarMap.API.Interfaces;
using StarMap.Core.UI;
using System;
using System.Collections.Generic;
using System.Text;

namespace StarMap.Core.API
{
internal class ModMenuService : IModMenuService
{
private readonly IModMenu _modMenu;

public ModMenuService(IModMenu modMenu)
{
_modMenu = modMenu;
}

public IDisposable AddModMenuItem(string label, Action OnClick)
{
return _modMenu.AddModMenuButton(label, OnClick);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@

namespace StarMap.Core.API
{
internal class PatchHelper : IPatchHelper
internal class PatchService : IPatchService
{
private IPatchManager _patchManager;
private IModContext _modContext;

public PatchHelper(IPatchManager patchManager, IModContext mod)
public PatchService(IPatchManager patchManager, IModContext mod)
{
_patchManager = patchManager;
_modContext = mod;
}

void IPatchHelper.RegisterInstancePatch<T, U>(IPatchHelper.PatchType type, MethodBase method, IPatchHelper.InstanceCallback<T, U> callback)
void IPatchService.RegisterInstancePatch<T, U>(IPatchService.PatchType type, MethodBase method, IPatchService.InstanceCallback<T, U> callback)

{
_patchManager.RegisterInstancePatch(type, _modContext.Mod, method, callback);
}

void IPatchHelper.RegisterInstanceVoidPatch<T>(IPatchHelper.PatchType type, MethodBase method, IPatchHelper.InstanceVoidCallback<T> callback)
void IPatchService.RegisterInstanceVoidPatch<T>(IPatchService.PatchType type, MethodBase method, IPatchService.InstanceVoidCallback<T> callback)
{
_patchManager.RegisterInstanceVoidPatch(type, _modContext.Mod, method, callback);
}

void IPatchHelper.RegisterStaticPatch<U>(IPatchHelper.PatchType type, MethodBase method, IPatchHelper.StaticCallback<U> callback)
void IPatchService.RegisterStaticPatch<U>(IPatchService.PatchType type, MethodBase method, IPatchService.StaticCallback<U> callback)
{
_patchManager.RegisterStaticPatch(type, _modContext.Mod, method, callback);
}

void IPatchHelper.RegisterStaticVoidPatch(IPatchHelper.PatchType type, MethodBase method, IPatchHelper.StaticVoidCallback callback)
void IPatchService.RegisterStaticVoidPatch(IPatchService.PatchType type, MethodBase method, IPatchService.StaticVoidCallback callback)
{
_patchManager.RegisterStaticVoidPatch(type, _modContext.Mod, method, callback);
}
Expand Down
10 changes: 5 additions & 5 deletions StarMap.Core/ModRepository/RuntimeMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public bool InitializeMod(ModRegistry modRegistry, ICoreService core, IPatchMana
modRegistry.AddModMethod(ModId, attr, modObject, classMethod);
break;
case StarMapAllModsLoadedAttribute:
patchManager.RegisterStaticVoidPatch(IPatchHelper.PatchType.Postfix, this, typeof(KSA.ModLibrary).GetMethod(nameof(ModLibrary.LoadAll))!,
patchManager.RegisterStaticVoidPatch(IPatchService.PatchType.Postfix, this, typeof(KSA.ModLibrary).GetMethod(nameof(ModLibrary.LoadAll))!,
args =>
{
classMethod.Invoke(modObject, args);
Expand All @@ -169,7 +169,7 @@ public bool InitializeMod(ModRegistry modRegistry, ICoreService core, IPatchMana
break;

case StarMapImmediateLoadAttribute:
patchManager.RegisterInstanceVoidPatch<Mod>(IPatchHelper.PatchType.Prefix, this, typeof(KSA.Mod).GetMethod(nameof(Mod.PrepareSystems))!,
patchManager.RegisterInstanceVoidPatch<Mod>(IPatchService.PatchType.Prefix, this, typeof(KSA.Mod).GetMethod(nameof(Mod.PrepareSystems))!,
(args, mod) =>
{
if (mod.Id.Equals(ModId))
Expand All @@ -179,7 +179,7 @@ public bool InitializeMod(ModRegistry modRegistry, ICoreService core, IPatchMana
});
break;
case StarMapAfterOnFrameAttribute:
patchManager.RegisterInstanceVoidPatch<Program>(IPatchHelper.PatchType.Postfix, this, typeof(Program).GetMethod("OnFrame")!,
patchManager.RegisterInstanceVoidPatch<Program>(IPatchService.PatchType.Postfix, this, typeof(Program).GetMethod("OnFrame")!,
(args, mod) =>
{
classMethod.Invoke(modObject, [args[0], args[1]]);
Expand All @@ -188,7 +188,7 @@ public bool InitializeMod(ModRegistry modRegistry, ICoreService core, IPatchMana
});
break;
case StarMapBeforeGuiAttribute:
patchManager.RegisterInstanceVoidPatch<Program>(IPatchHelper.PatchType.Prefix, this, typeof(Program).GetMethod("OnDrawUiFrame", BindingFlags.NonPublic | BindingFlags.Instance)!,
patchManager.RegisterInstanceVoidPatch<Program>(IPatchService.PatchType.Prefix, this, typeof(Program).GetMethod("OnDrawUiFrame", BindingFlags.NonPublic | BindingFlags.Instance)!,
(args, mod) =>
{
classMethod.Invoke(modObject, [args[0]]);
Expand All @@ -197,7 +197,7 @@ public bool InitializeMod(ModRegistry modRegistry, ICoreService core, IPatchMana
});
break;
case StarMapAfterGuiAttribute:
patchManager.RegisterInstanceVoidPatch<Program>(IPatchHelper.PatchType.Postfix, this, typeof(Program).GetMethod("OnDrawUiViewports", BindingFlags.NonPublic | BindingFlags.Instance)!,
patchManager.RegisterInstanceVoidPatch<Program>(IPatchService.PatchType.Postfix, this, typeof(Program).GetMethod("OnDrawUiViewports", BindingFlags.NonPublic | BindingFlags.Instance)!,
(args, mod) =>
{
classMethod.Invoke(modObject, [args[0]]);
Expand Down
36 changes: 18 additions & 18 deletions StarMap.Core/Patches/PatchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ namespace StarMap.Core.Patches
{
internal interface IPatchManager : IDisposable
{
void RegisterInstancePatch<T, U>(IPatchHelper.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchHelper.InstanceCallback<T, U> callback);
void RegisterInstanceVoidPatch<T>(IPatchHelper.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchHelper.InstanceVoidCallback<T> callback);
void RegisterStaticPatch<U>(IPatchHelper.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchHelper.StaticCallback<U> callback);
void RegisterStaticVoidPatch(IPatchHelper.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchHelper.StaticVoidCallback callback);
void RegisterInstancePatch<T, U>(IPatchService.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchService.InstanceCallback<T, U> callback);
void RegisterInstanceVoidPatch<T>(IPatchService.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchService.InstanceVoidCallback<T> callback);
void RegisterStaticPatch<U>(IPatchService.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchService.StaticCallback<U> callback);
void RegisterStaticVoidPatch(IPatchService.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchService.StaticVoidCallback callback);
}

internal class PatchManager : IPatchManager
Expand All @@ -33,21 +33,21 @@ public PatchManager()
_instance = this;
}

public void RegisterInstancePatch<T, U>(IPatchHelper.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchHelper.InstanceCallback<T, U> callback)
public void RegisterInstancePatch<T, U>(IPatchService.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchService.InstanceCallback<T, U> callback)
{
GetOrCreateMethodPatch(method).RegisterPatch(patchType, mod, new InstanceCallback<T, U>(callback));
}
public void RegisterInstanceVoidPatch<T>(IPatchHelper.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchHelper.InstanceVoidCallback<T> callback)
public void RegisterInstanceVoidPatch<T>(IPatchService.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchService.InstanceVoidCallback<T> callback)
{
GetOrCreateMethodPatch(method).RegisterPatch(patchType, mod, new InstanceVoidCallback<T>(callback));
}

public void RegisterStaticPatch<U>(IPatchHelper.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchHelper.StaticCallback<U> callback)
public void RegisterStaticPatch<U>(IPatchService.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchService.StaticCallback<U> callback)
{
GetOrCreateMethodPatch(method).RegisterPatch(patchType, mod, new StaticCallback<U>(callback));
}

public void RegisterStaticVoidPatch(IPatchHelper.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchHelper.StaticVoidCallback callback)
public void RegisterStaticVoidPatch(IPatchService.PatchType patchType, RuntimeMod? mod, MethodBase method, IPatchService.StaticVoidCallback callback)
{
GetOrCreateMethodPatch(method).RegisterPatch(patchType, mod, new StaticVoidCallback(callback));
}
Expand Down Expand Up @@ -176,7 +176,7 @@ internal interface IResultCallback : IPatchCallback
Type ResultType { get; }
}

internal class InstanceCallback<T, U>(IPatchHelper.InstanceCallback<T, U> callback) : IResultCallback
internal class InstanceCallback<T, U>(IPatchService.InstanceCallback<T, U> callback) : IResultCallback
{
public Type ResultType => typeof(U);

Expand All @@ -191,7 +191,7 @@ public bool Invoke(object[] args, object? instance, ref object? result)
}
}

internal class InstanceVoidCallback<T>(IPatchHelper.InstanceVoidCallback<T> callback) : IVoidCallback
internal class InstanceVoidCallback<T>(IPatchService.InstanceVoidCallback<T> callback) : IVoidCallback
{
public bool Invoke(object[] args, object? instance, ref object? result)
{
Expand All @@ -201,7 +201,7 @@ public bool Invoke(object[] args, object? instance, ref object? result)
}
}

internal class StaticCallback<U>(IPatchHelper.StaticCallback<U> callback) : IResultCallback
internal class StaticCallback<U>(IPatchService.StaticCallback<U> callback) : IResultCallback
{
public Type ResultType => typeof(U);

Expand All @@ -215,7 +215,7 @@ public bool Invoke(object[] args, object? instance, ref object? result)
}
}

internal class StaticVoidCallback(IPatchHelper.StaticVoidCallback callback) : IVoidCallback
internal class StaticVoidCallback(IPatchService.StaticVoidCallback callback) : IVoidCallback
{
public bool Invoke(object[] args, object? instance, ref object? result)
{
Expand All @@ -240,7 +240,7 @@ public MethodPatch(Harmony harmony, MethodBase method)
_method = method;
}

public void RegisterPatch(IPatchHelper.PatchType type, RuntimeMod? mod, IPatchCallback patchCallback)
public void RegisterPatch(IPatchService.PatchType type, RuntimeMod? mod, IPatchCallback patchCallback)
{
if (patchCallback is IResultCallback resultCallback && GetReturnType() != resultCallback.ResultType)
{
Expand All @@ -251,11 +251,11 @@ public void RegisterPatch(IPatchHelper.PatchType type, RuntimeMod? mod, IPatchCa

switch (type)
{
case IPatchHelper.PatchType.Prefix:
case IPatchService.PatchType.Prefix:
AddPrefix(mod, patchCallback);
break;

case IPatchHelper.PatchType.Postfix:
case IPatchService.PatchType.Postfix:
AddPostfix(mod, patchCallback);
break;

Expand All @@ -264,15 +264,15 @@ public void RegisterPatch(IPatchHelper.PatchType type, RuntimeMod? mod, IPatchCa
};
}

public void UnregisterPatch(IPatchHelper.PatchType type, RuntimeMod? mod)
public void UnregisterPatch(IPatchService.PatchType type, RuntimeMod? mod)
{
switch (type)
{
case IPatchHelper.PatchType.Prefix:
case IPatchService.PatchType.Prefix:
RemovePrefix(mod);
break;

case IPatchHelper.PatchType.Postfix:
case IPatchService.PatchType.Postfix:
RemovePostfix(mod);
break;

Expand Down
4 changes: 2 additions & 2 deletions StarMap.Core/Patches/StarMapPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public StarMapPatches(IPatchManager patchManager)

public void Init()
{
_patchManager.RegisterStaticVoidPatch(IPatchHelper.PatchType.Prefix, null, typeof(ModLibrary).GetMethod(nameof(ModLibrary.PrepareAll))!, BeforePrepareAll);
_patchManager.RegisterStaticVoidPatch(IPatchService.PatchType.Prefix, null, typeof(ModLibrary).GetMethod(nameof(ModLibrary.PrepareAll))!, BeforePrepareAll);

if (DocumentsPathOverride.ShouldApplyOverride())
_patchManager.RegisterStaticPatch<string>(IPatchHelper.PatchType.Prefix, null, AccessTools.PropertyGetter(typeof(Constants), nameof(Constants.DocumentsFolderPath)), DocumentsPathOverride.BeforeDocumentsFolderPath);
_patchManager.RegisterStaticPatch<string>(IPatchService.PatchType.Prefix, null, AccessTools.PropertyGetter(typeof(Constants), nameof(Constants.DocumentsFolderPath)), DocumentsPathOverride.BeforeDocumentsFolderPath);
}

private bool BeforePrepareAll(object[] _)
Expand Down
1 change: 1 addition & 0 deletions StarMap.Core/StarMap.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;SourceNuget</Configurations>
Expand Down
5 changes: 4 additions & 1 deletion StarMap.Core/StarMapCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using StarMap.Core.API;
using StarMap.Core.ModRepository;
using StarMap.Core.Patches;
using StarMap.Core.UI;
using StarMap.Types;
using System.Runtime.Loader;

Expand Down Expand Up @@ -33,9 +34,11 @@ public StarMapCore(AssemblyLoadContext coreAssemblyLoadContext)
serviceCollection.AddSingleton<IPatchManager, PatchManager>();
serviceCollection.AddSingleton<IModsLoader, ModsLoader>();
serviceCollection.AddSingleton<IStarMapPatches, StarMapPatches>();
serviceCollection.AddSingleton<IModMenu, ModMenu>();

serviceCollection.AddScoped<IModContext, ModContext>();
serviceCollection.AddScoped<IPatchHelper, PatchHelper>();
serviceCollection.AddScoped<IPatchService, PatchService>();
serviceCollection.AddScoped<IModMenuService, ModMenuService>();

_serviceProvider = serviceCollection.BuildServiceProvider();
}
Expand Down
2 changes: 1 addition & 1 deletion StarMap.Core/UI/ConfirmRestart/ConfirmRestart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public unsafe void OnFrame()
RenderPass = Program.MainPass.Pass,
Framebuffer = resources.Framebuffer,
RenderArea = new VkRect2D(this._renderer.Extent),
ClearValues = (VkClearValue*)Program.MainPass.ClearValues.Ptr,
ClearValues = (VkClearValue*)Program.MainPass.ClearValues!.Ptr,
ClearValueCount = 2
};
commandBuffer.Reset();
Expand Down
Loading
Loading