[NullChecks] Catch crashes when loading corrupted coordinate files #86

Merged
ManlyMarco merged 3 commits from fix into master 2025-11-01 13:28:39 +00:00
ManlyMarco commented 2025-11-01 13:13:40 +00:00 (Migrated from github.com)
No description provided.
copilot-pull-request-reviewer[bot] (Migrated from github.com) reviewed 2025-11-01 13:16:35 +00:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) left a comment

Pull Request Overview

This PR adds protection against crashes when loading corrupted coordinate files in the NullChecks plugin. The changes implement exception handling for ChaFileCoordinate.LoadFile method to catch and log crashes gracefully instead of crashing the game.

  • Adds a new finalizer patch to catch exceptions when loading coordinate files
  • Implements a crash handler that logs warnings and returns false on failures
  • Dynamically locates the correct LoadFile method overload across different game versions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

## Pull Request Overview This PR adds protection against crashes when loading corrupted coordinate files in the NullChecks plugin. The changes implement exception handling for `ChaFileCoordinate.LoadFile` method to catch and log crashes gracefully instead of crashing the game. - Adds a new finalizer patch to catch exceptions when loading coordinate files - Implements a crash handler that logs warnings and returns false on failures - Dynamically locates the correct LoadFile method overload across different game versions --- 💡 <a href="/IllusionMods/IllusionFixes/new/master/.github/instructions?filename=*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
@ -39,6 +41,25 @@ namespace IllusionFixes
else
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2025-11-01 13:16:34 +00:00

The First() method will throw an InvalidOperationException if no matching method is found, making the null check on line 49 unreachable. Use FirstOrDefault() instead of First() to properly handle the case where the method is not found.

                                                  .FirstOrDefault(x => x.Name == nameof(ChaFileCoordinate.LoadFile) && x.GetParameters().FirstOrDefault()?.ParameterType == typeof(Stream));
The `First()` method will throw an `InvalidOperationException` if no matching method is found, making the null check on line 49 unreachable. Use `FirstOrDefault()` instead of `First()` to properly handle the case where the method is not found. ```suggestion .FirstOrDefault(x => x.Name == nameof(ChaFileCoordinate.LoadFile) && x.GetParameters().FirstOrDefault()?.ParameterType == typeof(Stream)); ```
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2025-11-01 13:16:35 +00:00

The finalizer variable references MethodNullRefEater, but the new method ChaFileCoordinate_LoadFile_CrashEater is defined and never used. The patch should use a finalizer pointing to ChaFileCoordinate_LoadFile_CrashEater instead, as MethodNullRefEater doesn't have the correct signature (missing Stream st and ref bool __result parameters) to handle this patch properly.

            var coordFinalizer = new HarmonyMethod(typeof(NullChecks), nameof(ChaFileCoordinate_LoadFile_CrashEater));
            h.Patch(target, finalizer: coordFinalizer);
The finalizer variable references `MethodNullRefEater`, but the new method `ChaFileCoordinate_LoadFile_CrashEater` is defined and never used. The patch should use a finalizer pointing to `ChaFileCoordinate_LoadFile_CrashEater` instead, as `MethodNullRefEater` doesn't have the correct signature (missing `Stream st` and `ref bool __result` parameters) to handle this patch properly. ```suggestion var coordFinalizer = new HarmonyMethod(typeof(NullChecks), nameof(ChaFileCoordinate_LoadFile_CrashEater)); h.Patch(target, finalizer: coordFinalizer); ```
Sign in to join this conversation.
No description provided.