From cf0f61d8eec776ba5d3fb6ed856619a330ccc0cb Mon Sep 17 00:00:00 2001 From: Faraphel Date: Mon, 11 Jul 2022 23:46:48 +0200 Subject: [PATCH] implemented bmg patch operation by id --- source/mkw/Patch/PatchOperation.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/source/mkw/Patch/PatchOperation.py b/source/mkw/Patch/PatchOperation.py index 982beec..4822737 100644 --- a/source/mkw/Patch/PatchOperation.py +++ b/source/mkw/Patch/PatchOperation.py @@ -1,3 +1,4 @@ +import re from abc import ABC, abstractmethod from io import BytesIO from typing import IO @@ -5,7 +6,7 @@ from typing import IO from PIL import Image, ImageDraw, ImageFont from source.mkw.Patch import * -from source.wt import img +from source.wt import img, bmg class PatchOperation: @@ -286,7 +287,15 @@ class PatchOperation: self.template = template def patch_bmg(self, patch: "Patch", file_content: IO) -> IO: - return file_content + decoded_bmg = bmg.decode_data(file_content.read()) + + decoded_bmg += "\n" + ("\n".join( + [f" {id}\t= {replacement}" for id, replacement in self.template.items()] + )) + "\n" + # add new bmg definition at the end of the bmg file, overwritting old id. + + patch_content = BytesIO(bmg.encode_data(decoded_bmg)) + return patch_content class RegexLayer(AbstractLayer): """