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: 6 additions & 3 deletions NeosModLoader/AssemblyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ internal static class AssemblyLoader
return assembly;
}

internal static AssemblyFile[] LoadAssembliesFromDir(string dirName) {
internal static AssemblyFile[] LoadAssembliesFromDir(string dirName)
{
List<AssemblyFile> assemblyFiles = new();
if (GetAssemblyPathsFromDir(dirName) is string[] assemblyPaths) {
if (GetAssemblyPathsFromDir(dirName) is string[] assemblyPaths)
{
foreach (string assemblyFilepath in assemblyPaths)
{
try
{
if (LoadAssembly(assemblyFilepath) is Assembly assembly) {
if (LoadAssembly(assemblyFilepath) is Assembly assembly)
{
assemblyFiles.Add(new AssemblyFile(assemblyFilepath, assembly));
}
}
Expand Down
14 changes: 12 additions & 2 deletions NeosModLoader/ModConfigurationKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,23 @@ public ModConfigurationKey(string name, string description = null, Func<T> compu
private readonly Func<T> ComputeDefault;
private readonly Predicate<T> IsValueValid;

/// <summary>
/// Get the type of this key's value
/// </summary>
/// <returns>the type of this key's value</returns>
public override Type ValueType() => typeof(T);

/// <summary>
/// Checks if a value is valid for this configuration item
/// </summary>
/// <param name="value">value to check</param>
/// <returns>true if the value is valid</returns>
public override bool Validate(object value)
{
if (value is T castValue)
// specifically allow nulls for class types
if (value is T || (value is null && !typeof(T).IsValueType))
{
return ValidateTyped(castValue);
return ValidateTyped((T)value);
}
else
{
Expand Down
7 changes: 5 additions & 2 deletions NeosModLoader/ModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ internal static void LoadMods()

// generate list of assemblies to load
AssemblyFile[] modsToLoad;
if (AssemblyLoader.LoadAssembliesFromDir("nml_mods") is AssemblyFile[] arr) {
if (AssemblyLoader.LoadAssembliesFromDir("nml_mods") is AssemblyFile[] arr)
{
modsToLoad = arr;
} else {
}
else
{
return;
}

Expand Down
32 changes: 22 additions & 10 deletions NeosModLoader/SplashChanger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ internal static class SplashChanger
private static bool failed = false;

private static MethodInfo? _updatePhase = null;
private static MethodInfo? UpdatePhase {
get {
if (_updatePhase is null) {
try {
private static MethodInfo? UpdatePhase
{
get
{
if (_updatePhase is null)
{
try
{
_updatePhase = typeof(Engine)
.GetMethod("UpdateInitPhase", BindingFlags.NonPublic | BindingFlags.Instance);
} catch (Exception ex) {
}
catch (Exception ex)
{
if (!failed)
{
Logger.WarnInternal("UpdatePhase not found: " + ex.ToString());
Expand All @@ -29,13 +35,19 @@ private static MethodInfo? UpdatePhase {
}
}
private static MethodInfo? _updateSubPhase = null;
private static MethodInfo? UpdateSubPhase {
get {
if (_updateSubPhase is null) {
try {
private static MethodInfo? UpdateSubPhase
{
get
{
if (_updateSubPhase is null)
{
try
{
_updateSubPhase = typeof(Engine)
.GetMethod("UpdateInitPhase", BindingFlags.NonPublic | BindingFlags.Instance);
} catch (Exception ex) {
}
catch (Exception ex)
{
if (!failed)
{
Logger.WarnInternal("UpdateSubPhase not found: " + ex.ToString());
Expand Down