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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,7 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

# Thunderstore CLI builds
/build
1 change: 1 addition & 0 deletions BepInExResoniteShim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void RunPatches()
HarmonyInstance.SafePatchCategory(nameof(GraphicalClientPatch));
HarmonyInstance.SafePatchCategory(nameof(WindowTitlePatcher));
HarmonyInstance.SafePatchCategory(nameof(LogAlerter));
HarmonyInstance.SafePatchCategory(nameof(RelativePathFixer));
}

[HarmonyPatch]
Expand Down
48 changes: 28 additions & 20 deletions BepInExResoniteShim.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,37 @@
<Nullable>enable</Nullable>
<Deterministic>true</Deterministic>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<CopyToPlugins>true</CopyToPlugins>
<CopyToPlugins>false</CopyToPlugins>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<DebugType>embedded</DebugType>
<GamePath Condition="'$(ResonitePath)' != ''">$(ResonitePath)/</GamePath>
<GamePath Condition="Exists('$(MSBuildProgramFiles32)\Steam\steamapps\common\Resonite\')">$(MSBuildProgramFiles32)\Steam\steamapps\common\Resonite\</GamePath>
<GamePath Condition="Exists('$(HOME)/.steam/steam/steamapps/common/Resonite/')">$(HOME)/.steam/steam/steamapps/common/Resonite/</GamePath>
<PluginTargetDir>$(GamePath)BepInEx\plugins\$(AssemblyName)</PluginTargetDir>
<GamePath Condition="'$(ResonitePath)' != ''">$(ResonitePath)/</GamePath>
<GamePath Condition="Exists('$(MSBuildProgramFiles32)\Steam\steamapps\common\Resonite\')">$(MSBuildProgramFiles32)\Steam\steamapps\common\Resonite\</GamePath>
<GamePath Condition="Exists('$(HOME)/.steam/steam/steamapps/common/Resonite/')">$(HOME)/.steam/steam/steamapps/common/Resonite/</GamePath>
<PluginTargetDir>$(GamePath)BepInEx\plugins\$(AssemblyName)</PluginTargetDir>
<RootNamespace>$(AssemblyName)</RootNamespace>
<RestoreAdditionalProjectSources>
https://nuget-modding.resonite.net/v3/index.json
</RestoreAdditionalProjectSources>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="BepInEx.NET.CoreCLR" Version="6.0.0-be.*" IncludeAssets="compile" />
<PackageReference Include="BepInEx.ResonitePluginInfoProps" Version="3.*" />
</ItemGroup>

<!-- NuGet fallback stripped game references -->
<ItemGroup Condition="!Exists('$(GamePath)')">
<PackageReference Include="Resonite.GameLibs" Version="2025.*" PrivateAssets="all" />
</ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="BepInEx.NET.CoreCLR" Version="6.0.0-be.*" IncludeAssets="compile" />
<PackageReference Include="BepInEx.ResonitePluginInfoProps" Version="3.*" />
<PackageReference Include="Krafs.Publicizer" Version="2.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<!-- Local game references -->
<ItemGroup Condition="Exists('$(GamePath)')">
<!-- NuGet fallback stripped game references -->
<ItemGroup Condition="!Exists('$(GamePath)')">
<PackageReference Include="Resonite.GameLibs" Version="2025.*" PrivateAssets="all" />
</ItemGroup>

<!-- Local game references -->
<ItemGroup Condition="Exists('$(GamePath)')">
<Reference Include="FrooxEngine">
<HintPath>$(GamePath)FrooxEngine.dll</HintPath>
<Private>False</Private>
Expand All @@ -50,15 +54,19 @@
<HintPath>$(GamePath)Elements.Core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Renderite.Host">
<HintPath>$(GamePath)Renderite.Host.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Renderite.Host">
<HintPath>$(GamePath)Renderite.Host.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Renderite.Shared">
<HintPath>$(GamePath)Renderite.Shared.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>

<ItemGroup>
<Publicize Include="Renderite.Host" />
</ItemGroup>

<!-- Post-build copy to game plugins folder -->
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(GITHUB_ACTIONS)' != 'true'">
Expand Down
65 changes: 65 additions & 0 deletions RelativePathFixer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using BepInEx;
using FrooxEngine;
using HarmonyLib;
using System.Reflection;
using System.Reflection.Emit;

namespace BepInExResoniteShim;

class RelativePathFixer
{
[HarmonyPatchCategory(nameof(RelativePathFixer))]
[HarmonyPatch(typeof(Program), "<Main>$", MethodType.Async)]
class RenderiteHostPathFixes
{
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> codes)
{
foreach (var code in codes)
{
if (code.Is(OpCodes.Ldstr, "Logs"))
{
yield return new(OpCodes.Ldstr, Path.Combine(Paths.GameRootPath, "Logs"));
continue;
}
if (code.Is(OpCodes.Ldstr, "Icon.png"))
{
yield return new(OpCodes.Ldstr, Path.Combine(Paths.GameRootPath, "Icon.png"));
continue;
}
if(code.operand is MethodInfo mf && mf.Name == nameof(File.WriteAllText))
{
yield return new(OpCodes.Call, AccessTools.Method(typeof(RenderiteHostPathFixes), nameof(FileWriteInjected)));
continue;
}
yield return code;
}
}

public static void FileWriteInjected(string path, string? contents)
{
if (!Path.IsPathRooted(path))
{
path = Path.Combine(Paths.GameRootPath, path);
}
File.WriteAllText(path, contents);
}
}

[HarmonyPatchCategory(nameof(RelativePathFixer))]
[HarmonyPatch(typeof(RenderSystem), "StartRenderer", MethodType.Async)]
public class RenderiteWorkingDirectoryFix
{
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> codes)
{
foreach (var code in codes)
{
if(code.Is(OpCodes.Ldstr, "Renderer"))
{
yield return new(OpCodes.Ldstr, Path.Combine(Paths.GameRootPath, "Renderer"));
continue;
}
yield return code;
}
}
}
}
Loading