pub enum MemoryPatch {
ReplaceBytes {
replacements: Vec<BytesReplacement>,
},
ReplaceString {
replacements: Vec<StringReplacement>,
},
Script {
source: ScriptSource,
parameters: Vec<ModParameter>,
configuration: HashMap<String, Value>,
},
}Expand description
A single content modification applied to a file’s bytes before the game reads it.
Each variant carries a list of find/replace pairs so that a single
patch can update many parts of the same file at once, e.g. renaming
several level names in language.json when multiple custom levels are
hooked in together. All pairs in one patch are matched in a single left
-to-right pass over the data: they don’t cascade into each other (a
replacement’s output is never re-scanned against the other finds in the
same patch). If several MemoryPatch entries are applied in sequence
via apply_all, those do chain, each operating on the previous
patch’s output.
Variants§
ReplaceBytes
Replace literal (game-encoded) byte strings. Used for e.g. swapping several hardcoded level names for translated ones in a single pass. Lengths need not match: we’re producing a brand new temp file, not patching in place.
Fields
replacements: Vec<BytesReplacement>ReplaceString
Convenience form of ReplaceBytes for text replacements (e.g.
localized level names in a JSON/text asset). find/replace are
ordinary Rust (UTF-8) strings, but the game’s asset files are
Windows-1252 on disk, so both are transcoded to Windows-1252 bytes
before matching, otherwise any non-ASCII character (accents,
curly quotes, etc.) would never match the game’s actual bytes.
Fields
replacements: Vec<StringReplacement>Script
Run a Rhai script to transform the file contents. The script receives
the file contents as a UTF-8/Windows-1252-decoded String via the
input variable, plus file_path (the file’s stable rel_key) and
timestamp (current time), and must return a String.
Implementations§
Source§impl MemoryPatch
impl MemoryPatch
Sourcepub fn apply(&self, data: &[u8], rel_key: &str) -> Result<Vec<u8>, PatchError>
pub fn apply(&self, data: &[u8], rel_key: &str) -> Result<Vec<u8>, PatchError>
Applies this patch to data, returning the patched bytes.
rel_key identifies the file being patched (game-root-relative,
lowercase, forward-slashed – see the resolver’s rel_key
convention) and is only actually used by MemoryPatch::Script,
which exposes it to the script as file_path; the other variants
ignore it.
§Errors
Returns a PatchError if script execution or encoding fails.
Trait Implementations§
Source§impl Clone for MemoryPatch
impl Clone for MemoryPatch
Source§fn clone(&self) -> MemoryPatch
fn clone(&self) -> MemoryPatch
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MemoryPatch
impl Debug for MemoryPatch
Source§impl<'de> Deserialize<'de> for MemoryPatch
impl<'de> Deserialize<'de> for MemoryPatch
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for MemoryPatch
impl PartialEq for MemoryPatch
Source§fn eq(&self, other: &MemoryPatch) -> bool
fn eq(&self, other: &MemoryPatch) -> bool
self and other values to be equal, and is used by ==.