Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.
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
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# https://EditorConfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
charset = utf-8
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
repository: neos-modding-group/Reference-Assemblies
path: Libs
ssh-key: ${{ secrets.REFERENCE_ASSEMBLIES_AUTH }}
- name: lint
run: dotnet format --verbosity detailed --verify-no-changes ./NeosModLoader.sln
- name: build
run: dotnet build ./NeosModLoader.sln
- name: lint
run: dotnet format --verify-no-changes --include-generated ./NeosModLoader.sln
32 changes: 16 additions & 16 deletions NeosModLoader.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeosModLoader", "NeosModLoader\NeosModLoader.csproj", "{D4627C7F-8091-477A-ABDC-F1465D94D8D9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {757072E6-E985-4EC2-AB38-C4D1588F6A15}
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {757072E6-E985-4EC2-AB38-C4D1588F6A15}
EndGlobalSection
EndGlobal
18 changes: 9 additions & 9 deletions NeosModLoader/AssemblyFile.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System.Reflection;
using System.Reflection;

namespace NeosModLoader
{
internal class AssemblyFile
internal class AssemblyFile
{
internal string File { get; }
internal Assembly Assembly { get; set; }
internal AssemblyFile(string file, Assembly assembly)
{
internal string File { get; }
internal Assembly Assembly { get; set; }
internal AssemblyFile(string file, Assembly assembly)
{
File = file;
Assembly = assembly;
}
File = file;
Assembly = assembly;
}
}
}
142 changes: 71 additions & 71 deletions NeosModLoader/AssemblyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,87 +5,87 @@

namespace NeosModLoader
{
internal static class AssemblyLoader
internal static class AssemblyLoader
{
private static string[]? GetAssemblyPathsFromDir(string dirName)
{
private static string[]? GetAssemblyPathsFromDir(string dirName)
{
string assembliesDirectory = Path.Combine(Directory.GetCurrentDirectory(), dirName);
string assembliesDirectory = Path.Combine(Directory.GetCurrentDirectory(), dirName);

Logger.MsgInternal($"loading assemblies from {dirName}");
Logger.MsgInternal($"loading assemblies from {dirName}");

string[]? assembliesToLoad = null;
try
{
assembliesToLoad = Directory.GetFiles(assembliesDirectory, "*.dll", SearchOption.AllDirectories);
Array.Sort(assembliesToLoad, (a, b) => string.CompareOrdinal(a, b));
}
catch (Exception e)
{
if (e is DirectoryNotFoundException)
{
Logger.MsgInternal($"{dirName} directory not found, creating it now.");
try
{
Directory.CreateDirectory(assembliesDirectory);
}
catch (Exception e2)
{
Logger.ErrorInternal($"Error creating ${dirName} directory:\n{e2}");
}
}
else
{
Logger.ErrorInternal($"Error enumerating ${dirName} directory:\n{e}");
}
}
return assembliesToLoad;
string[]? assembliesToLoad = null;
try
{
assembliesToLoad = Directory.GetFiles(assembliesDirectory, "*.dll", SearchOption.AllDirectories);
Array.Sort(assembliesToLoad, (a, b) => string.CompareOrdinal(a, b));
}
catch (Exception e)
{
if (e is DirectoryNotFoundException)
{
Logger.MsgInternal($"{dirName} directory not found, creating it now.");
try
{
Directory.CreateDirectory(assembliesDirectory);
}
catch (Exception e2)
{
Logger.ErrorInternal($"Error creating ${dirName} directory:\n{e2}");
}
}

private static Assembly? LoadAssembly(string filepath)
else
{
string filename = Path.GetFileName(filepath);
SplashChanger.SetCustom($"Loading file: {filename}");
Assembly assembly;
try
{
Logger.MsgInternal( $"load assembly {filename} with sha256hash: {Util.GenerateSHA256(filepath)}");
assembly = Assembly.LoadFile(filepath);
}
catch (Exception e)
{
Logger.ErrorInternal($"error loading assembly from {filepath}: {e}");
return null;
}
if (assembly == null)
{
Logger.ErrorInternal($"unexpected null loading assembly from {filepath}");
return null;
}
return assembly;
Logger.ErrorInternal($"Error enumerating ${dirName} directory:\n{e}");
}
}
return assembliesToLoad;
}

private static Assembly? LoadAssembly(string filepath)
{
string filename = Path.GetFileName(filepath);
SplashChanger.SetCustom($"Loading file: {filename}");
Assembly assembly;
try
{
Logger.MsgInternal($"load assembly {filename} with sha256hash: {Util.GenerateSHA256(filepath)}");
assembly = Assembly.LoadFile(filepath);
}
catch (Exception e)
{
Logger.ErrorInternal($"error loading assembly from {filepath}: {e}");
return null;
}
if (assembly == null)
{
Logger.ErrorInternal($"unexpected null loading assembly from {filepath}");
return null;
}
return assembly;
}

internal static AssemblyFile[] LoadAssembliesFromDir(string dirName)
internal static AssemblyFile[] LoadAssembliesFromDir(string dirName)
{
List<AssemblyFile> assemblyFiles = new();
if (GetAssemblyPathsFromDir(dirName) is string[] assemblyPaths)
{
foreach (string assemblyFilepath in assemblyPaths)
{
List<AssemblyFile> assemblyFiles = new();
if (GetAssemblyPathsFromDir(dirName) is string[] assemblyPaths)
try
{
if (LoadAssembly(assemblyFilepath) is Assembly assembly)
{
foreach (string assemblyFilepath in assemblyPaths)
{
try
{
if (LoadAssembly(assemblyFilepath) is Assembly assembly)
{
assemblyFiles.Add(new AssemblyFile(assemblyFilepath, assembly));
}
}
catch (Exception e)
{
Logger.ErrorInternal($"Unexpected exception loading assembly from {assemblyFilepath}:\n{e}");
}
}
assemblyFiles.Add(new AssemblyFile(assemblyFilepath, assembly));
}

return assemblyFiles.ToArray();
}
catch (Exception e)
{
Logger.ErrorInternal($"Unexpected exception loading assembly from {assemblyFilepath}:\n{e}");
}
}
}

return assemblyFiles.ToArray();
}
}
}
10 changes: 5 additions & 5 deletions NeosModLoader/AutoRegisterConfigKeyAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System;

namespace NeosModLoader
{
[AttributeUsage(AttributeTargets.Field)]
public class AutoRegisterConfigKeyAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Field)]
public class AutoRegisterConfigKeyAttribute : Attribute
{
}
}
42 changes: 21 additions & 21 deletions NeosModLoader/ConfigurationChangedEvent.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
namespace NeosModLoader
namespace NeosModLoader
{
public class ConfigurationChangedEvent
{
/// <summary>
/// The configuration the change occurred in
/// </summary>
public ModConfiguration Config { get; private set; }
public class ConfigurationChangedEvent
{
/// <summary>
/// The configuration the change occurred in
/// </summary>
public ModConfiguration Config { get; private set; }

/// <summary>
/// The specific key who's value changed
/// </summary>
public ModConfigurationKey Key { get; private set; }
/// <summary>
/// The specific key who's value changed
/// </summary>
public ModConfigurationKey Key { get; private set; }

/// <summary>
/// A custom label that may be set by whoever changed the configuration
/// </summary>
public string? Label { get; private set; }
/// <summary>
/// A custom label that may be set by whoever changed the configuration
/// </summary>
public string? Label { get; private set; }

internal ConfigurationChangedEvent(ModConfiguration config, ModConfigurationKey key, string? label)
{
Config = config;
Key = key;
Label = label;
}
internal ConfigurationChangedEvent(ModConfiguration config, ModConfigurationKey key, string? label)
{
Config = config;
Key = key;
Label = label;
}
}
}
34 changes: 17 additions & 17 deletions NeosModLoader/DebugInfo.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
using System;
using System;
using System.Reflection;
using System.Runtime.Versioning;

namespace NeosModLoader
{
internal class DebugInfo
internal class DebugInfo
{
internal static void Log()
{
internal static void Log()
{
Logger.MsgInternal($"NeosModLoader v{ModLoader.VERSION} starting up!{(ModLoaderConfiguration.Get().Debug ? " Debug logs will be shown." : "")}");
Logger.MsgInternal($"CLR v{Environment.Version}");
Logger.DebugFuncInternal(() => $"Using .NET Framework: \"{AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName}\"");
Logger.DebugFuncInternal(() => $"Using .NET Core: \"{Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName}\"");
Logger.MsgInternal($"Using Harmony v{GetAssemblyVersion(typeof(HarmonyLib.Harmony))}");
Logger.MsgInternal($"Using BaseX v{GetAssemblyVersion(typeof(BaseX.floatQ))}");
Logger.MsgInternal($"Using FrooxEngine v{GetAssemblyVersion(typeof(FrooxEngine.IComponent))}");
Logger.MsgInternal($"Using Json.NET v{GetAssemblyVersion(typeof(Newtonsoft.Json.JsonSerializer))}");
}
Logger.MsgInternal($"NeosModLoader v{ModLoader.VERSION} starting up!{(ModLoaderConfiguration.Get().Debug ? " Debug logs will be shown." : "")}");
Logger.MsgInternal($"CLR v{Environment.Version}");
Logger.DebugFuncInternal(() => $"Using .NET Framework: \"{AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName}\"");
Logger.DebugFuncInternal(() => $"Using .NET Core: \"{Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName}\"");
Logger.MsgInternal($"Using Harmony v{GetAssemblyVersion(typeof(HarmonyLib.Harmony))}");
Logger.MsgInternal($"Using BaseX v{GetAssemblyVersion(typeof(BaseX.floatQ))}");
Logger.MsgInternal($"Using FrooxEngine v{GetAssemblyVersion(typeof(FrooxEngine.IComponent))}");
Logger.MsgInternal($"Using Json.NET v{GetAssemblyVersion(typeof(Newtonsoft.Json.JsonSerializer))}");
}

private static string? GetAssemblyVersion(Type typeFromAssembly)
{
return typeFromAssembly.Assembly.GetName()?.Version?.ToString();
}
private static string? GetAssemblyVersion(Type typeFromAssembly)
{
return typeFromAssembly.Assembly.GetName()?.Version?.ToString();
}
}
}
Loading