Understanding the EPatchType Enum in Wand-Enhancer: Core Architecture for Modular Patching
The EPatchType enum in Wand-Enhancer serves as the central declarative system that defines, configures, and executes all JavaScript patches to the Wand Electron application, enabling type-safe selection, mapping to concrete patch definitions, and validation of patch completion.
The EPatchType enum in the k1tbyte/Wand-Enhancer repository represents the foundational abstraction that drives the entire modification pipeline. This C# enumeration transforms the patching process from manual file editing into a structured, configurable workflow where each value corresponds to a distinct functional alteration of the original Wand application.
What Is the EPatchType Enum?
Located in WandEnhancer/Models/PatchConfig.cs at lines 9–15, the EPatchType enumeration defines five distinct modification types using bitwise flag values. This design allows the system to represent multiple simultaneous selections through a single HashSet<EPatchType> while maintaining compile-time type safety.
public enum EPatchType
{
ActivatePro = 1,
DisableUpdates = 2,
DisableTelemetry = 4,
DevToolsOnF12 = 8,
RemoteWebPanelPreview = 16
}
Each value represents a specific capability: ActivatePro unlocks premium features, DisableUpdates prevents automatic application updates, DisableTelemetry stops analytics collection, DevToolsOnF12 enables Chrome Developer Tools via the F12 key, and RemoteWebPanelPreview activates remote web panel functionality. The powers-of-two values (1, 2, 4, 8, 16) follow the flag enum pattern, though the implementation primarily uses HashSet<EPatchType> for storage rather than bitwise operations.
How EPatchType Drives the Patch Pipeline
The enum operates as the primary key throughout three critical phases of the enhancement process: user selection, definition mapping, and execution validation.
User Selection and Configuration
The patch selection interface in WandEnhancer/View/Popups/PatchVectorsPopup.xaml.cs (lines 77–96) translates UI checkbox states into a strongly-typed HashSet<EPatchType>. This declarative approach ensures that only valid, predefined modifications can be selected.
var selected = new HashSet<EPatchType>();
if (ActivateProBox.IsChecked == true)
selected.Add(EPatchType.ActivatePro);
if (DisableUpdatesBox.IsChecked == true)
selected.Add(EPatchType.DisableUpdates);
if (DevToolsOnF12Box.IsChecked == true)
selected.Add(EPatchType.DevToolsOnF12);
if (RemoteWebPanelPreviewBox.IsChecked == true)
selected.Add(EPatchType.RemoteWebPanelPreview);
var config = new PatchConfig
{
PatchTypes = selected,
AutoApplyPatches = false
};
The PatchConfig class stores this selection in its PatchTypes property (lines 21–22 of PatchConfig.cs), creating a serializable configuration object that separates user intent from execution logic.
Mapping to PatchEntry Definitions
The EnhancerConfig.GetInstance() method in WandEnhancer/Core/EnhancerConfig.cs (lines 100–110) returns a comprehensive dictionary that maps each EPatchType value to one or more PatchEntry objects. This dictionary bridges the abstract enum values with concrete implementation details including regex patterns and JavaScript replacement code.
return new Dictionary<EPatchType, PatchEntry[]>()
{
{
EPatchType.ActivatePro,
new[]
{
new PatchEntry
{
SearchHints = new[] { "getUserAccount()", "/v3/account" },
Resolver = new ResolveContext
{
Handler = target => Regex.Match(target, @"return\s+this\.#(\w+)\.fetch").Groups[1].Value,
Placeholder = "<service_name>"
},
Name = "getUserAccount",
Target = new Regex(@"getUserAccount\(\)\{.*?return\s+this\.#\w+\.fetch\(\{.*?\}\)\}", RegexOptions.Singleline),
Patch = "getUserAccount(){return this.#<service_name>.fetch({endpoint:\"/v3/account\",method:\"GET\",name:\"/v3/account\",collectMetrics:0}).then(response=>{response.subscription={period:\"yearly\",state:\"active\"};return response;})}"
}
}
}
// ... additional mappings
};
Each PatchEntry contains the regex target, search hints for locating the code block, and the JavaScript patch string to inject. This architecture isolates the modification logic from the enum definition, allowing engineers to update patch implementations without changing the public API.
Execution and Validation
The Enhancer class in WandEnhancer/Core/Enhancer.cs orchestrates the actual file modification. Lines 33–55 demonstrate the engine iterating over the selected enum values, applying corresponding patches to the extracted Electron bundle files.
var remainingPatches = new HashSet<EPatchType>(_config.PatchTypes);
foreach (var entry in remainingPatches.ToList())
{
var patchEntries = enhancerConfig[entry];
bool patchApplied = false;
// Apply patches to target files
data = ApplyJsPatch(item, data, patchEntry, entry, out patchApplied);
if (patchApplied)
{
fileChanged = true;
remainingPatches.Remove(entry);
}
}
The engine maintains a remainingPatches tracking set to ensure complete application. Lines 73–78 implement the critical validation step: if any EPatchType values remain in the set after processing all files, the system throws an exception indicating the current Wand version lacks support for those specific modifications.
if (remainingPatches.Count > 0)
throw new Exception("[ENHANCER] Failed to apply patches: " +
string.Join(", ", remainingPatches));
Architectural Benefits of the Enum-Based Design
The EPatchType enum provides three structural advantages that make Wand-Enhancer maintainable and extensible:
-
Separation of concerns: The enum isolates what should be modified from how the modification occurs. UI components reference only the abstract type, while the
Enhancerclass handles file system operations and regex replacements. -
Type-safe extensibility: Adding new functionality requires only three steps: adding an enum value to
PatchConfig.cs, defining the correspondingPatchEntryarray inEnhancerConfig.cs, and optionally adding a UI checkbox. The compiler enforces exhaustiveness inswitchstatements and dictionary mappings. -
Validation and safety: By tracking unapplied patches through the
remainingPatchesmechanism, the system prevents partial modifications that could corrupt the application bundle or leave the user with inconsistent feature states.
Working with EPatchType in Practice
Selecting Patches Programmatically
When building custom tooling or automated workflows, you construct the configuration object directly using the enum values:
var aggressiveConfig = new PatchConfig
{
PatchTypes = new HashSet<EPatchType>
{
EPatchType.ActivatePro,
EPatchType.DisableTelemetry,
EPatchType.DisableUpdates
},
AutoApplyPatches = true
};
Executing Individual Patch Types
During the enhancement process, the engine passes the specific EPatchType to the application method for logging and tracking purposes:
bool wasApplied;
data = ApplyJsPatch(
fileEntry: targetFile,
content: bundleContent,
patch: patchDefinition,
type: EPatchType.DisableTelemetry,
applied: out wasApplied
);
Summary
-
The
EPatchTypeenum inPatchConfig.csdefines five distinct modification flags using powers-of-two values for potential bitwise operations, though the system primarily utilizesHashSet<EPatchType>. -
User selections in
PatchVectorsPopup.xaml.cscompile into strongly-typed enum sets that populate thePatchConfig.PatchTypesproperty. -
EnhancerConfig.csmaps each enum value to concretePatchEntryobjects containing regex patterns and JavaScript replacement code. -
The
Enhancer.csengine iterates through selected enum values, applies patches to bundle files, and validates completion via theremainingPatchestracking mechanism. -
The architecture supports safe extensibility by separating patch definition (enum), implementation (PatchEntry), and execution (Enhancer) into distinct layers.
Frequently Asked Questions
What does each EPatchType value represent?
ActivatePro unlocks premium subscription features by intercepting account API responses. DisableUpdates prevents the application from checking for or downloading new versions. DisableTelemetry stops analytics and usage data collection. DevToolsOnF12 enables Chrome Developer Tools when pressing the F12 key. RemoteWebPanelPreview activates experimental remote web panel capabilities. Each value corresponds to a specific JavaScript injection target defined in EnhancerConfig.cs.
Why are the EPatchType values defined as powers of two?
The values (1, 2, 4, 8, 16) follow the traditional flag enum pattern allowing bitwise combination into a single integer. While Wand-Enhancer currently uses HashSet<EPatchType> for storage and iteration, the flag values preserve compatibility with bitwise operations for compact serialization or database storage scenarios. This pattern also visually distinguishes the enum as representing composable options rather than sequential states.
How does Wand-Enhancer handle unsupported patches?
The system validates patch application through the remainingPatches HashSet in Enhancer.cs (lines 73–78). If the engine cannot locate the target code patterns for a selected patch type in the extracted bundle files, that enum value remains in the set after processing completes. The code explicitly checks if (remainingPatches.Count > 0) and throws an exception listing the unapplied patches, preventing the tool from producing a partially modified or broken application bundle.
Can developers extend EPatchType with custom patches?
Yes, the architecture supports extensibility through three specific modifications: First, add a new value to the EPatchType enum in PatchConfig.cs. Second, define the corresponding PatchEntry array in the dictionary returned by EnhancerConfig.GetInstance(), including the target regex and replacement JavaScript. Third, expose the selection option in the UI by adding a checkbox to PatchVectorsPopup.xaml and handling its state in PatchVectorsPopup.xaml.cs. The Enhancer engine automatically processes new enum values without requiring changes to the core execution logic.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →