Skip to content

Commit

Permalink
Merge pull request #109 from seionmoya/client-modloader
Browse files Browse the repository at this point in the history
[WIP] Initial client modloader
  • Loading branch information
seionmoya authored Jan 6, 2025
2 parents 0f35e36 + a32909a commit 881cb64
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Fuyu.Client.NLog/Fuyu.Client.NLog.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Reference Include="NLog" HintPath="References/NLog.dll" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Fuyu.Common\Fuyu.Common.csproj" />
<ProjectReference Include="..\Fuyu.DependencyInjection\Fuyu.DependencyInjection.csproj" />
<ProjectReference Include="..\Fuyu.Modding\Fuyu.Modding.csproj" />
</ItemGroup>

</Project>
47 changes: 47 additions & 0 deletions Fuyu.Client.NLog/FuyuClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using NLog;
using NLog.Targets;
using Fuyu.Common.IO;
using Fuyu.DependencyInjection;
using Fuyu.Modding;

[Target(nameof(FuyuClient))]
public sealed class FuyuClient : TargetWithLayout
{
protected override void InitializeTarget()
{
var container = new DependencyContainer();

CheckIncompatibleSoftware();

Terminal.WriteLine("Loading mods...");
ModManager.Instance.AddMods("./Fuyu/Mods");
ModManager.Instance.Load(container).GetAwaiter().GetResult();
Terminal.WriteLine("Finished loading mods");

// TODO: OnApplicationQuit
// -- seionmoya, 20205-01-04
}

private void CheckIncompatibleSoftware()
{
var record = new Dictionary<string, string>()
{
{ "BepInEx/", "BepInEx" },
{ "MelonLoader/", "MelonLoader" },
{ "SPT.Launcher/", "SPTarkov" },
{ "monomod.exe", "MonoMod" },
{ "MonoMod.RuntimeDetour.HookGen.exe", "MonoMod" }
// TODO: UnityModManager, UMF
};

foreach (var kvp in record)
{
if (VFS.Exists(kvp.Key))
{
throw new Exception($"{kvp.Value} found. Please remove the software from the client before proceeding.");
}
}
}
}
49 changes: 49 additions & 0 deletions Fuyu.Client.NLog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Fuyu.Client.NLog

Fuyu mod loader for clients using NLog.

## Installation

1. Build the project
2. Place `Fuyu.Client.NLog` inside `<game data>/Managed/`
3. Place `NLog.dll` inside `<game data>/Managed/`, override when prompted
4. Add the following to `NLog/NLog.config`:

```xml
<?xml version="1.0" encoding="utf-8"?>

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="true"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">

<extensions>
<add assembly="Fuyu.Client.NLog"/>
</extensions>

<targets async="true">
<target name="FuyuTarget" xsi:type="FuyuTarget" />
<!-- ... -->
</targets>

<rules>
<logger name="FuyuTarget" minlevel="Off" writeTo="traceFile" />
<!-- ... -->
</rules>
</nlog>
```

## FAQ

> Why not BepInEx / Monomod / Unity Mod Manager / MelonLoader?
Fuyu is designed to function with as little dependencies as possible to run,
especially not depending on external projects. With it's own loader, Fuyu also
gains more control over mod loading.

> Why does the project include a NLog version?
EFT removed `LoadNLogExtensionAssemblies` in their build, thus we have to use
the version from the reference folder (NLog 4.7.15, netstandard2.0).
Binary file added Fuyu.Client.NLog/References/NLog.dll
Binary file not shown.
6 changes: 5 additions & 1 deletion Fuyu.Common/IO/VFS.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Concurrent;
using System.IO;

Expand All @@ -23,6 +22,11 @@ public static bool FileExists(string filepath)
return File.Exists(filepath);
}

public static bool Exists(string filepath)
{
return DirectoryExists(filepath) || FileExists(filepath);
}

public static string[] GetFiles(string path)
{
if (!Directory.Exists(path))
Expand Down
6 changes: 6 additions & 0 deletions Fuyu.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fuyu.DependencyInjection",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fuyu.Modding", "Fuyu.Modding\Fuyu.Modding.csproj", "{1687E80C-E174-4844-9939-7AAF6E1139F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fuyu.Client.NLog", "Fuyu.Client.NLog\Fuyu.Client.NLog.csproj", "{335E42B4-0EDD-4CDD-908A-C109272FB181}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -117,6 +119,10 @@ Global
{1687E80C-E174-4844-9939-7AAF6E1139F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1687E80C-E174-4844-9939-7AAF6E1139F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1687E80C-E174-4844-9939-7AAF6E1139F0}.Release|Any CPU.Build.0 = Release|Any CPU
{335E42B4-0EDD-4CDD-908A-C109272FB181}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{335E42B4-0EDD-4CDD-908A-C109272FB181}.Debug|Any CPU.Build.0 = Debug|Any CPU
{335E42B4-0EDD-4CDD-908A-C109272FB181}.Release|Any CPU.ActiveCfg = Release|Any CPU
{335E42B4-0EDD-4CDD-908A-C109272FB181}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 881cb64

Please sign in to comment.