Skip to content

Commit

Permalink
Converted Common, InjectorRunner and Injector to netstandard2.0 based…
Browse files Browse the repository at this point in the history
… projects.
  • Loading branch information
CptMoore committed Dec 23, 2024
1 parent 8d6ea33 commit e48e3d0
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 28 deletions.
25 changes: 10 additions & 15 deletions Common.props
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
<Project InitialTargets="ValidateBattleTechGameDir">
<Target Name="ValidateBattleTechGameDir" Condition="'$(BattleTechGameDir)' == '' Or !Exists('$(BattleTechGameDir)')">
<Error Text="BattleTechGameDir variable not set properly" />
</Target>
<!-- includes references to BT, Unity and only System dlls provided there -->
<Project>
<Import Project=".\CommonBase.props" />

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net472</TargetFramework>
<LangVersion>13</LangVersion>
<AssemblySearchPaths>
{HintPathFromItem};
$(BattleTechGameDir)\BattleTech_Data\Managed
</AssemblySearchPaths>
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
<DebugType>embedded</DebugType>
<NoWarn>CS0436</NoWarn>
</PropertyGroup>

<PropertyGroup>
<ModTekLibDir>$(BattleTechGameDir)\Mods\ModTek\lib\</ModTekLibDir>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GitVersion.MsBuild">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="PolySharp">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<!-- DisableImplicitFrameworkReferences -->
<ItemGroup>
<Reference Include="mscorlib">
<Private>False</Private>
</Reference>
<Reference Include="System">
<Private>False</Private>
</Reference>
Expand Down
22 changes: 22 additions & 0 deletions CommonBase.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- shared properties between Common and CommonStandard -->
<Project InitialTargets="ValidateBattleTechGameDir">
<Target Name="ValidateBattleTechGameDir" Condition="'$(BattleTechGameDir)' == '' Or !Exists('$(BattleTechGameDir)')">
<Error Text="BattleTechGameDir variable not set properly" />
</Target>

<PropertyGroup>
<OutputType>Library</OutputType>
<LangVersion>13</LangVersion>
</PropertyGroup>

<PropertyGroup>
<ModTekLibDir>$(BattleTechGameDir)\Mods\ModTek\lib\</ModTekLibDir>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PolySharp">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
12 changes: 12 additions & 0 deletions CommonStandard.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!--
required to make netstandard2.0 compilation work:
- don't use managed directory via AssemblySearchPaths
- don't specify libs explicitly using DisableImplicitFrameworkReferences
-->
<Project>
<Import Project=".\CommonBase.props" />

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion ModTek.Common/ModTek.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\Common.props" />
<Import Project="..\CommonStandard.props" />

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
14 changes: 13 additions & 1 deletion ModTek.InjectorRunner/Injector/InjectorsRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,21 @@ namespace ModTek.InjectorRunner.Injector;

internal class InjectorsRunner : IDisposable
{
internal static void Run()
{
using var injectorsRunner = new InjectorsRunner();
if (injectorsRunner.IsUpToDate)
{
return;
}

injectorsRunner.RunInjectors();
injectorsRunner.SaveToDisk();
}

private readonly AssemblyCache _assemblyCache;
private readonly InjectionCacheManifest _injectionCacheManifest;
internal InjectorsRunner()
private InjectorsRunner()
{
_assemblyCache = new AssemblyCache();
_injectionCacheManifest = new InjectionCacheManifest();
Expand Down
2 changes: 1 addition & 1 deletion ModTek.InjectorRunner/ModTek.InjectorRunner.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\Common.props" />
<Import Project="..\CommonStandard.props" />

<ItemGroup>
<InternalsVisibleTo Include="ModTek.Preloader" />
Expand Down
22 changes: 22 additions & 0 deletions ModTek.Preloader/Entrypoint.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Linq;
using System.Reflection;
using ModTek.Preloader.Loader;
using Logger = ModTek.Preloader.Logger;

Expand All @@ -18,6 +20,26 @@ public static void Start()
catch (Exception e)
{
var message = "Exiting the game, preloader failed: " + e;
if (e is BadImageFormatException e3)
{
message += "\n" + e3.FileName + " " + e3.FusionLog;
}
if (e is ReflectionTypeLoadException e2)
{
message += Environment.NewLine + e2.Message;
if (e2.Types != null)
{
try
{
message += string.Join(Environment.NewLine, e2.Types.Select(t => t.FullName));
}
catch (Exception ex)
{
message += Environment.NewLine + ex;
}
}
message += string.Join(Environment.NewLine, e2.LoaderExceptions.Select(x => x.ToString()));
}
try { Console.Error.WriteLine(message); } catch { /* ignored */ }
try { Logger.Main.Log(message); } catch { /* ignored */ }
Environment.Exit(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using ModTek.Common.Globals;
using ModTek.InjectorRunner.Injector;

namespace ModTek.InjectorRunner.Injector;
namespace ModTek.Preloader;

internal class InjectorsAppDomain : MarshalByRefObject
{
Expand Down Expand Up @@ -35,13 +36,6 @@ internal static void Run()

private void RunInjectors()
{
using var injectorsRunner = new InjectorsRunner();
if (injectorsRunner.IsUpToDate)
{
return;
}

injectorsRunner.RunInjectors();
injectorsRunner.SaveToDisk();
InjectorsRunner.Run();
}
}
3 changes: 2 additions & 1 deletion ModTekInjector/ModTekInjector.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\Common.props" />
<Import Project="..\CommonStandard.props" />

<Target Name="CopyFilesToGame" AfterTargets="CopyFilesToOutputDirectory">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(BattleTechGameDir)\Mods\ModTek\Injectors\" />
</Target>

<ItemGroup>
<!-- we only need Mono.Cecil, but HarmonyX pins the version we need -->
<PackageReference Include="HarmonyX">
<PrivateAssets>All</PrivateAssets>
<ExcludeAssets>runtime</ExcludeAssets>
Expand Down

0 comments on commit e48e3d0

Please sign in to comment.