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
7 changes: 7 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
"tcli"
],
"rollForward": true
},
"cake.tool": {
"version": "5.0.0",
"commands": [
"dotnet-cake"
],
"rollForward": false
}
}
}
16 changes: 5 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,14 @@ jobs:
- uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.0.x"
- name: Build
run: |
dotnet build -c Release
# Copy the built DLL to dist folder
mkdir -p ./bin/dist/
cp ./RenderiteHook/bin/Release/RenderiteHook.dll ./bin/dist/
- name: Create Thunderstore Package
run: |
dotnet tool restore
dotnet tcli build --package-version ${{ steps.info.outputs.version }}
- name: Install Cake Tool
run: dotnet tool restore
- name: Build with Cake
run: dotnet cake --target=Build --verbosity=normal
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: RenderiteHook-${{ steps.info.outputs.version }}-${{ steps.info.outputs.sha_short }}
path: |
./bin/dist/*.dll
./RenderiteHook/bin/Release/*.dll
./build/*.zip
11 changes: 4 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ jobs:
- uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.0.x"
- name: Build
run: |
dotnet build -c Release
- name: Create Thunderstore Package
run: |
dotnet tool restore
dotnet tcli build --package-version $VERSION
- name: Install Cake Tool
run: dotnet tool restore
- name: Build with Cake
run: dotnet cake --target=Build --verbosity=normal
- name: Publish to Thunderstore
run: |
ZIP_FILE=$(ls ./build/*.zip | head -1)
Expand Down
16 changes: 5 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,10 @@ jobs:
- uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.0.x"
- name: Build
run: |
dotnet build -c Release
# Copy the built DLL to dist folder for release
mkdir -p ./bin/dist/
cp ./RenderiteHook/bin/Release/RenderiteHook.dll ./bin/dist/
- name: Create Thunderstore Package
run: |
dotnet tool restore
dotnet tcli build
- name: Install Cake Tool
run: dotnet tool restore
- name: Build with Cake
run: dotnet cake --target=Build --verbosity=normal
- name: Create Git Tag (if needed)
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
Expand All @@ -71,7 +65,7 @@ jobs:
tag_name: v${{ steps.info.outputs.version }}
target_commitish: ${{ github.sha }}
files: |
./bin/dist/*.dll
./RenderiteHook/bin/Release/*.dll
./build/*.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56 changes: 53 additions & 3 deletions RenderiteHook/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace RenderiteHook;
[BepInDependency(BepInExResoniteShim.PluginMetadata.GUID, BepInDependency.DependencyFlags.HardDependency)]
public class Plugin : BasePlugin
{
internal static new ManualLogSource Log;
internal static new ManualLogSource Log = null!;

public override void Load()
{
Expand All @@ -31,7 +31,7 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
foreach (var code in codes)
{
yield return code;
if(code.operand is MethodInfo mi && mi.Name == "ToStringAndClear")
if (code.operand is MethodInfo mi && mi.Name == "ToStringAndClear")
{
patched = true;
yield return new CodeInstruction(OpCodes.Call, typeof(ArgumentsPatch).GetMethod(nameof(OnStartRenderer), BindingFlags.Static | BindingFlags.Public)); // Call our method
Expand All @@ -46,9 +46,59 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio

public static string OnStartRenderer(string args)
{
var newArgs = string.Join(' ', [args, ..Environment.GetCommandLineArgs().Skip(1)]);
CopyDoorstopFiles(Engine.Current.RenderSystem);
var newArgs = string.Join(' ', [args, .. Environment.GetCommandLineArgs().Skip(1)]);
Log.LogInfo($"Starting renderer with args: {newArgs}");
return newArgs;
}

private static void CopyDoorstopFiles(RenderSystem renderSystem)
{
try
{
var pluginLocation = Assembly.GetExecutingAssembly().Location;
var pluginDir = Path.GetDirectoryName(pluginLocation);

if (string.IsNullOrEmpty(pluginDir))
{
Log.LogError("Could not determine plugin directory");
return;
}

var doorstopSourceDir = Path.Combine(pluginDir, "Doorstop");

if (!Directory.Exists(doorstopSourceDir))
{
Log.LogWarning($"Doorstop directory not found at: {doorstopSourceDir}");
return;
}

var rendererPath = renderSystem.RendererPath;
var rendererDir = Path.GetDirectoryName(rendererPath);

if (string.IsNullOrEmpty(rendererDir))
{
Log.LogError("Could not determine renderer directory");
return;
}

Log.LogInfo($"Copying Doorstop files from {doorstopSourceDir} to {rendererDir}");

foreach (var file in Directory.GetFiles(doorstopSourceDir, "*", SearchOption.AllDirectories))
{
var relativePath = Path.GetRelativePath(doorstopSourceDir, file);
var destPath = Path.Combine(rendererDir, relativePath);

File.Copy(file, destPath, overwrite: true);
Log.LogInfo($"Copied: {relativePath}");
}

Log.LogInfo("Doorstop files copied successfully");
}
catch (Exception ex)
{
Log.LogError($"Failed to copy Doorstop files: {ex.Message}");
}
}
}
}
2 changes: 1 addition & 1 deletion RenderiteHook/RenderiteHook.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Nullable>enable</Nullable>
<Deterministic>true</Deterministic>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<CopyToPlugins>true</CopyToPlugins>
<CopyToPlugins>false</CopyToPlugins>
<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>
Expand Down
114 changes: 114 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
var doorstopVersion = "4.4.1";
var projectPath = "./RenderiteHook/RenderiteHook.csproj";

var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");

var packageVersion = XmlPeek(projectPath, "/Project/PropertyGroup/Version");

var distDir = Directory("./dist");
var extractDir = distDir + Directory("Doorstop");
var downloadUrl = $"https://github.com/NeighTools/UnityDoorstop/releases/download/v{doorstopVersion}/doorstop_win_release_{doorstopVersion}.zip";
var zipFile = distDir + File($"doorstop_win_release_{doorstopVersion}.zip");

Task("Clean")
.Does(() =>
{
if (DirectoryExists(distDir))
{
CleanDirectory(distDir);
}
else
{
CreateDirectory(distDir);
}
});

Task("DownloadDoorstop")
.IsDependentOn("Clean")
.Does(() =>
{
Information($"Downloading Doorstop v{doorstopVersion}...");

if (!FileExists(zipFile))
{
DownloadFile(downloadUrl, zipFile);
Information($"Downloaded to: {zipFile}");
}
else
{
Information("File already exists, skipping download.");
}
});

Task("ExtractDoorstop")
.IsDependentOn("DownloadDoorstop")
.Does(() =>
{
Information($"Extracting Doorstop to {extractDir}...");

if (!DirectoryExists(extractDir))
{
CreateDirectory(extractDir);
}

Unzip(zipFile, extractDir);
Information("Extraction completed.");

// Update doorstop_config.ini to point to BepInEx
var configFile = extractDir + File("x64/doorstop_config.ini");
if (FileExists(configFile))
{
Information("Updating doorstop_config.ini...");
var content = System.IO.File.ReadAllText(configFile);
content = content.Replace("target_assembly=Doorstop.dll", "target_assembly=BepInEx\\core\\BepInEx.Preloader.dll");
System.IO.File.WriteAllText(configFile, content);
Information("Config file updated successfully.");
}
else
{
Warning($"Config file not found at: {configFile}");
}
});

Task("BuildRenderiteHook")
.IsDependentOn("ExtractDoorstop")
.Does(() =>
{
Information($"Building RenderiteHook version {packageVersion}...");

// Build RenderiteHook project
DotNetBuild(projectPath, new DotNetBuildSettings
{
Configuration = configuration,
Verbosity = DotNetVerbosity.Minimal
});

Information("RenderiteHook build completed successfully.");
});

Task("Build")
.IsDependentOn("BuildRenderiteHook")
.Does(() =>
{
Information($"Building Thunderstore package with version {packageVersion}...");

// Run dotnet tcli build command
var exitCode = StartProcess("dotnet", new ProcessSettings
{
Arguments = $"tcli build --package-version {packageVersion}",
WorkingDirectory = Directory(".")
});

if (exitCode != 0)
{
throw new Exception($"dotnet tcli build failed with exit code {exitCode}");
}

Information("Thunderstore package build completed successfully.");
});

Task("Default")
.IsDependentOn("Build");

RunTarget(target);
4 changes: 4 additions & 0 deletions thunderstore.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ target = "plugins/RenderiteHook/"
source = "./RenderiteHook/bin/Release/RenderiteHook.pdb"
target = "plugins/RenderiteHook/"

[[build.copy]]
source = "./dist/Doorstop/x64"
target = "plugins/RenderiteHook/Doorstop"

# [[build.copy]]
# source = "./CHANGELOG.md"
# target = "/"
Expand Down