Skip to content

Commit

Permalink
I'm dumb and forgot to actually load the dependencies lol
Browse files Browse the repository at this point in the history
  • Loading branch information
RainOrigami committed Sep 5, 2023
1 parent 8fc95d0 commit 64bc39f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion BattleBitAPIRunner/BattleBitAPIRunner.csproj
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyVersion>0.4.12.2</AssemblyVersion>
<AssemblyVersion>0.4.12.3</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
</PropertyGroup>

Expand Down
8 changes: 8 additions & 0 deletions BattleBitAPIRunner/Module.cs
Expand Up @@ -36,6 +36,14 @@ internal class Module
private SyntaxTree syntaxTree;
private string code;

public static void LoadDependencies(string[] dependencies)
{
foreach (string dependency in dependencies)
{
moduleContext.LoadFromAssemblyPath(Path.GetFullPath(dependency));
}
}

public static void UnloadContext()
{
moduleContext.Unload();
Expand Down
18 changes: 14 additions & 4 deletions BattleBitAPIRunner/Program.cs
@@ -1,6 +1,7 @@
using BattleBitAPI.Common;
using BattleBitAPI.Server;
using BBRAPIModules;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Operations;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
Expand Down Expand Up @@ -84,7 +85,7 @@ private void fileWatchers()
try
{
changedModule = new(moduleFile);
changedModule.Compile();
changedModule.Compile(this.binaryDependencies);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -142,12 +143,20 @@ private void loadDependencies()
Directory.CreateDirectory(this.configuration.DependencyPath);
}

List<PortableExecutableReference> binaryDependencies = new();

foreach (string dependency in Directory.GetFiles(this.configuration.DependencyPath, "*.dll"))
{
Assembly.LoadFrom(dependency);
binaryDependencies.Add(MetadataReference.CreateFromFile(dependency));
}

this.binaryDependencies = binaryDependencies.ToArray();

Module.LoadDependencies(Directory.GetFiles(this.configuration.DependencyPath, "*.dll"));
}

private PortableExecutableReference[] binaryDependencies = Array.Empty<PortableExecutableReference>();

private void consoleCommandHandler()
{
if (Console.In is null)
Expand Down Expand Up @@ -230,7 +239,7 @@ private void consoleCommandHandler()
try
{
loadedModule = new(moduleToLoad.ModuleFilePath);
loadedModule.Compile();
loadedModule.Compile(this.binaryDependencies);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -274,6 +283,7 @@ private void unloadModules()
}

Module.UnloadContext();
Module.LoadDependencies(Directory.GetFiles(this.configuration.DependencyPath, "*.dll"));
}

private void loadModules()
Expand Down Expand Up @@ -342,7 +352,7 @@ private void loadModules()

if (module.AssemblyBytes is null)
{
module.Compile();
module.Compile(this.binaryDependencies);
compiledModuleCount++;
}

Expand Down

0 comments on commit 64bc39f

Please sign in to comment.