Skip to content

fix: skip patch types that have no definition instead of throwing - #173

Open
divya0795 wants to merge 1 commit into
k1tbyte:masterfrom
divya0795:fix/skip-unimplemented-patch-types
Open

fix: skip patch types that have no definition instead of throwing#173
divya0795 wants to merge 1 commit into
k1tbyte:masterfrom
divya0795:fix/skip-unimplemented-patch-types

Conversation

@divya0795

@divya0795 divya0795 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #172

Defensive hardening, not a live bug fix. As set out in the issue, this crash path is currently unreachable — no UI exposes DisableTelemetry and PatchConfig is never deserialised. I have no reproduction to offer, and I'd rather say so up front than dress this up as something it isn't. Close it if you'd prefer not to carry the guard.

Problem

EnhancerConfig.GetInstance() has entries for four of the five EPatchType members; DisableTelemetry = 4 has none. Both consumers indexed the dictionary directly:

var entries = enhancerConfig[entry];                    // Enhancer.cs:153
foreach (var patchEntry in enhancerConfig[patchType])   // Enhancer.cs:192

A PatchTypes set containing DisableTelemetry would abort the entire run with an unhandled KeyNotFoundException, discarding the other requested patches — and doing so after backups have been made and app.asar extracted.

Change

TryGetValue at both sites, skipping any type with no definition.

The skipped type is deliberately left in remainingPatches, so rather than being silently dropped it falls through to the existing end-of-run summary:

[ENHANCER] Failed to apply patches: DisableTelemetry. The version may not be supported.

That is the same channel an unmatched patch already reports through. PatchAsar additionally logs [ENHANCER] No patch definition for {entry}, skipping at ELogType.Warn.

I considered instead adding an empty DisableTelemetry entry to EnhancerConfig. That also stops the crash, but it makes a requested patch report success while doing nothing — worse than a clear failure.

Behaviour for all four implemented patch types is unchanged: they still resolve, apply, and clear from remainingPatches exactly as before. One file, +17 / -2.

Verification

No local Visual Studio/MSBuild environment, so this is not compile-verified locally. Compile evidence comes from dispatching this repo's own .github/workflows/build.yml (full build.ps1 → MSBuild, windows-latest) on my fork; run linked in a comment below.

There is no C# test project in the repo, and no licensed WeMod install here, so CONTRIBUTING.md's manual-testing step is not satisfied. Given the guarded path cannot currently be entered, the meaningful check is that the four live patch types are unaffected — which is what the build plus your normal patch run would confirm.

@divya0795

Copy link
Copy Markdown
Contributor Author

Compile verification: dispatched this repo's own build.yml against this branch on my fork. It runs the full build.ps1 - pnpm install, web-panel build, NuGet restore, then MSBuild of Wand-Enhancer.sln on windows-latest.

Result: success in ~1.7 min

https://github.com/divya0795/Wand-Enhancer/actions/runs/30205236146

That satisfies "your code compiles without errors" from CONTRIBUTING.md. The manual-testing-against-WeMod step remains outstanding on my side, as flagged in the PR description.

EnhancerConfig.GetInstance() returns entries for ActivatePro, DisableUpdates,
DevToolsOnF12 and RemoteWebPanelPreview. EPatchType also declares
DisableTelemetry = 4, which has no entry, and both lookups of that dictionary
indexed it directly:

    var entries = enhancerConfig[entry];            // PatchAsar
    foreach (var patchEntry in enhancerConfig[patchType])   // CouldFileContainRemainingPatch

A PatchConfig carrying DisableTelemetry would therefore abort the entire patch
run with an unhandled KeyNotFoundException, taking the other requested patches
with it.

This is not reachable today: PatchVectorsPopup exposes no control for
DisableTelemetry, and PatchConfig is only ever constructed there -- nothing
deserialises it -- so no supported path can put that value into PatchTypes.
It becomes reachable the moment a checkbox is added for it.

Look both lookups up with TryGetValue and skip a type that has no definition.
The type is deliberately left in remainingPatches, so instead of crashing the
run it now surfaces through the existing summary:

    [ENHANCER] Failed to apply patches: DisableTelemetry. The version may not be supported.

which is the same channel used when a real patch fails to match. PatchAsar also
logs a warning naming the skipped type. Behaviour for every implemented patch
type is unchanged.
@divya0795
divya0795 force-pushed the fix/skip-unimplemented-patch-types branch from 4b5ce01 to a4430f5 Compare July 26, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EPatchType.DisableTelemetry has no EnhancerConfig entry - unguarded lookup would throw KeyNotFoundException (latent)

1 participant