Skip to content

Commit

Permalink
feat: exclude texture filenames to prevent watermarking or obfuscation
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Joker committed Feb 6, 2025
1 parent 8fdd0bf commit 6ab7f6f
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 168 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
custom:
- 'https://www.paypal.com/paypalme/Airkk426'
- 'https://afdian.com/a/Eric_Joker'
- 'https://github.com/Eric-Joker/Enigmata/blob/main/docs/receiving%20code.png'
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ Under certain conditions, you may be required to update the Vanilla Data. You ne

## Donation

Because I am still a minor, the policies in my area make it difficult for me to get money here. 😭
[PayPal](https://www.paypal.com/paypalme/Airkk426)

[afdian](https://afdian.com/a/Eric_Joker)

Thank you very much for your willingness to support the author. Your avatar will appear on my Github profile and in the Readme of this project.

## Thanks

Expand Down
15 changes: 9 additions & 6 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ packs:
# 为混淆时提供独特的命名空间,需与 `path` 一一对应
namespace: rhp
# 资源包目录下但不属于资源包的文件
excluded_files:
exclude_files:
- '.github/**'
- '.git/**'
- '.git*'
Expand Down Expand Up @@ -51,7 +51,7 @@ obfuscator:
json_funs:
# 依据自然顺序排序 Json 键值
sort: true
# 将 Json 键值中的字符串转为 Unicode,尽管是 Ascll 字符。遵循 `excluded_jsonui_names` 和 `excluded_entity_names`
# 将 Json 键值中的字符串转为 Unicode,尽管是 Ascll 字符。遵循 `exclude_jsonui_names` 和 `exclude_entity_names`
unicode: true
# 在 json 结尾处添加无意义空字典“{}”,不影响游戏解析但可能会影响 IDE 解析
empty_dict: true
Expand Down Expand Up @@ -128,7 +128,7 @@ obfuscator:
debug: false

# 不进行任何处理的 json
excluded_jsons:
exclude_jsons:
- manifest.json
- "**/loading_messages.json"
- "**/blocks.json"
Expand All @@ -141,14 +141,18 @@ obfuscator:
- "**/languages.json"
- "**/splashes.json"

# 不进行混淆或添加水印的贴图文件名
exclude_image_names:
- item_cell_rhp

# 不进行混淆、添加注释、转义、去格式化并且将顺序提前的 UI 一级控件、变量、绑定
excluded_jsonui_names:
exclude_jsonui_names:
- hotbar_grid_template
- setting_options_panel
- chest_label_panel

# 不在实体、模型、粒子、材质、动画、动画控制器、渲染控制器中进行混淆、转义、去格式化的键名和的 ID 及 Molang 变量名
excluded_entity_names:
exclude_entity_names:
- number_0
- number_1
- number_2
Expand Down Expand Up @@ -181,4 +185,3 @@ obfuscator:
- health_display_hide
- health_display_baby
- health_display_controller
- item_cell_rhp
52 changes: 31 additions & 21 deletions config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class EnigmataConfig:
HEADER_VERSION = []
MODULES_UUID = []
MODULES_VERSION = []
EXCLUDED_FILES = (".git*/**", ".mc*", "LICENSE", "README.md")
EXCLUDE_FILES = (".git*/**", ".mc*", "LICENSE", "README.md")
NOMEDIA = True
ZIP_NAME = []
NAMESPACE = []
Expand All @@ -67,7 +67,7 @@ class EnigmataConfig:
PACK_COMPRESS = 9
MTIME = (1989, 8, 10, 11, 45, 14)
DEBUG = False
EXCLUDED_JSONS = (
EXCLUDE_JSONS = (
"manifest.json",
"**/loading_messages.json",
"**/blocks.json",
Expand All @@ -80,8 +80,9 @@ class EnigmataConfig:
"**/languages.json",
"**/splashes.json",
)
EXCLUDED_JSONUI_NAMES = set()
EXCLUDED_ENTITY_NAMES = set()
EXCLUDE_IMAGE_NAMES = set()
EXCLUDE_JSONUI_NAMES = set()
EXCLUDE_ENTITY_NAMES = set()

def __init__(self):
self._add_arguments()
Expand Down Expand Up @@ -129,7 +130,7 @@ def _add_arguments(self):
argsGroup1.add_argument("--modules-version", nargs="*", type=str, help="For manifest.json.")
argsGroup2 = parser.add_argument_group("Script Parameters")
argsGroup2.add_argument(
"--excluded-files",
"--exclude-files",
nargs="*",
type=str,
help="Files in the resource pack directory but not part of the resource pack.",
Expand Down Expand Up @@ -159,7 +160,7 @@ def _add_arguments(self):
"--obfuscate-strs", "-s", nargs="*", type=str, help="Character pool for generating obfuscated strings."
)
argsGroup3.add_argument(
"--obfuscate-ascll", "-a", nargs="*", type=str, help="Character pool for generating obfuscated strings."
"--obfuscate-ascll", "-a", nargs="*", type=str, help="Entity key-value obfuscation charset."
)
argsGroup3.add_argument("--sort", type=str2bool, help="Sort JSON keys in natural order.")
argsGroup3.add_argument(
Expand Down Expand Up @@ -204,7 +205,7 @@ def _add_arguments(self):
"--watermark-paths",
nargs="*",
type=str,
help="Adds a string randomly split by namespace to all mapping filenames.",
help="Watermark targets.",
)
argsGroup3.add_argument(
"--wm-references",
Expand Down Expand Up @@ -242,22 +243,28 @@ def _add_arguments(self):
help="Modify the mtime of each file during packaging.",
)
argsGroup3.add_argument(
"--excluded-jsons",
"--exclude-jsons",
nargs="*",
type=str,
help="Json without any processing.",
)
argsGroup3.add_argument(
"--excluded-jsonui-names",
"--exclude-image-names",
nargs="*",
type=str,
help="JsonUI first-level control names, variable names, hard-bound names without obfuscation, annotation, escaping, de-formatting, and order advancement.",
help="Texture filenames that are not obfuscated or watermarked.",
)
argsGroup3.add_argument(
"--excluded-entity-names",
"--exclude-jsonui-names",
nargs="*",
type=str,
help="Key names and names of entity series ID, and molang variable names in them that are not obfuscated, escaped, or de-formatted in files.",
help="JsonUI first-level control names, variable names, binding names without obfuscation, annotation, escaping, de-formatting, and order advancement.",
)
argsGroup3.add_argument(
"--exclude-entity-names",
nargs="*",
type=str,
help="Key names and names of entity series ID, and molang variable names without obfuscation, escaping, or de-formatting.",
)
self.args = parser.parse_args()

Expand Down Expand Up @@ -327,19 +334,22 @@ def reload(self, file: str):

# typecasting and supplementary attrs
self.mtime = tuple(self.mtime) if self.mtime else self.MTIME
self.excluded_files = tuple(self.excluded_files) if self.excluded_files else self.EXCLUDED_FILES
self.exclude_files = tuple(self.exclude_files) if self.exclude_files else self.EXCLUDE_FILES
self.obfuscate_strs = tuple(self.obfuscate_strs) if self.obfuscate_strs else self.OBFUSCATE_STRS
self.obfuscate_ascll = tuple(self.obfuscate_ascll) if self.obfuscate_ascll else self.OBFUSCATE_ASCLL
self.watermark_paths = tuple(self.watermark_paths)
self.wm_references = tuple(self.wm_references)
self.obfuscate_paths = tuple(self.obfuscate_paths)
self.obf_references = tuple(self.obf_references)
self.excluded_jsons = tuple(self.excluded_jsons) if self.excluded_jsons else self.EXCLUDED_JSONS
self.excluded_jsonui_names = (
set(self.excluded_jsonui_names) if self.excluded_jsonui_names else self.EXCLUDED_JSONUI_NAMES
self.exclude_jsons = tuple(self.exclude_jsons) if self.exclude_jsons else self.EXCLUDE_JSONS
self.exclude_image_names = (
set(self.exclude_image_names) if self.exclude_image_names else self.EXCLUDE_IMAGE_NAMES
)
self.exclude_jsonui_names = (
set(self.exclude_jsonui_names) if self.exclude_jsonui_names else self.EXCLUDE_JSONUI_NAMES
)
self.excluded_entity_names = (
set(self.excluded_entity_names) if self.excluded_entity_names else self.EXCLUDED_ENTITY_NAMES
self.exclude_entity_names = (
set(self.exclude_entity_names) if self.exclude_entity_names else self.EXCLUDE_ENTITY_NAMES
)
self.additional_jsonui = tuple(self.additional_jsonui) if self.additional_jsonui else self.ADDITIONAL_JSONUI
self.path = self.path if isinstance(self.path, list) else (self.path,)
Expand All @@ -357,9 +367,9 @@ def reload(self, file: str):
self.unicode = False
self.sort = False
self.is_vanilla_data_needed = (self.obfuscate_jsonui or self.obfuscate_entity) and not self.extract
self.excluded_jsonui_names.add("namespace")
self.excluded_entity_names.update(("player.base", "format_version", "version"))
self.excluded_names = self.excluded_jsonui_names | self.excluded_entity_names
self.exclude_jsonui_names.add("namespace")
self.exclude_entity_names.update(("player.base", "format_version", "version"))
self.exclude_names = self.exclude_jsonui_names | self.exclude_entity_names
uuid_pattern = re.compile("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$")
if self.pack_name and len(self.path) != len(self.pack_name):
raise ValueError("The pack name needs to correspond to the resource package.")
Expand Down
36 changes: 20 additions & 16 deletions config_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,27 @@ log:
path: '.\logs'

packs:
# for resource packs that need to be obfuscated
# Resource packs that require obfuscation
# If you need to use the PNG compression feature, please ensure the path does not contain non-ASCII characters.
path:
- ''
# The final packaged file name must correspond to the path one-to-one.
# If it is an empty string, it will not be automatically packaged.
# Empty string disables auto-packaging.
zip_name:
- ''
# Provide a unique namespace for obfuscation, which must correspond to the path one-to-one.
namespace:
- rhp
# Files under the RP directory that do not belong to the RP.
excluded_files:
exclude_files:
- '.github/**'
- '.git/**'
- '.git*'
- '.mc*'
- 'LICENSE'
- 'README.md'
# Modify `manifest.json`, the values here must correspond one-to-one with `path`. If the value is False or an empty string, it will not be modified.
# For `manifest.json` bindings, values must match path 1:1.
# Setting as False/empty skips modification.
manifest:
name:
- ''
Expand All @@ -55,15 +56,15 @@ obfuscator:
- '0Oo°Οο⁰₀○。〇︒0Oo'
#- '0OoΟο○0Oo'

# Characters used to generate obfuscated strings for entity series keys and values.
# Entity series keys/values obfuscation character set
# Must be all ASCII characters.
obfuscate_ascll:
- 'abcdefghijklmn'

json_funs:
# Sort JSON keys in natural order.
sort: true
# Convert both the keys and values in JSON to Unicode, even if they are ASCII characters. Follow `excluded_jsonui_names` and `excluded_entity_names`.
# Convert both the keys and values in JSON to Unicode, even if they are ASCII characters. Follow `exclude_jsonui_names` and `exclude_entity_names`.
unicode: true
# Add a meaningless empty dict `{}` at the end of the JSON. This will not affect game parsing but may affect IDE parsing.
empty_dict: true
Expand All @@ -74,7 +75,7 @@ obfuscator:
# Merge the JSON files under /ui/`namespace` into a single file.
merge_jsonui:
enable: true
# The path of the merged file.
# Merged file path
path: 'font\.test.png'
# Add misleading key-value pairs to `_ui_defs.json`.
# It must be a JSON dict string or an empty string.
Expand All @@ -90,26 +91,26 @@ obfuscator:
# -

file_funs:
# Add a randomly segmented string from the `namespace` to the filenames of all texture files in `paths` not present in vanilla.
# Insert randomized `namespace` fragments into texture filenames of non-vanilla `paths`
filename_watermark:
enable: true
paths:
- '**/textures/blocks/**'
- '**/textures/items/**'
# JSON references the files to be watermarked
# Watermark target files (JSON references)
references:
- '**/textures/item_texture.json'
- '**/textures/terrain_texture.json'
- '**/textures/flipbook_textures.json'
# Replace the filenames of all texture files in `paths` not present in vanilla with randomly generated strings from `obfuscate_str`.
# Obfuscated texture replacement using `obfuscate_str`
# If `filename_watermark` is true, automatically exclude `filename_watermark.paths`.
filename_obfuscation:
enable: true
paths:
- '**/textures/ui/**'
- '**/textures/number/**'
- '**/textures/spawn_point/**'
# JSON references the files to be obfuscated
# Obfuscation target files (JSON references)
references:
- '**/ui/**/*.json'
- '**/entity/*.json'
Expand Down Expand Up @@ -140,7 +141,7 @@ obfuscator:
debug: false

# JSON without any processing.
excluded_jsons:
exclude_jsons:
- manifest.json
- "**/loading_messages.json"
- "**/blocks.json"
Expand All @@ -153,9 +154,12 @@ obfuscator:
- "**/languages.json"
- "**/splashes.json"

# UI primary controls, variables, and bindings that are not obfuscated, commented, escaped, unformatted, and moved to the front.
excluded_jsonui_names:
# Texture filenames (no obfuscation/watermark)
exclude_image_names:

# Key names, IDs, and Molang variable names in entities, models, particles, materials, animations, animation controllers, and render controllers that are not obfuscated, escaped, or unformatted.
excluded_entity_names:
# UI primary controls, variables, and bindings (no obfuscation/commenting/escaping/formatting/front-positioning)
exclude_jsonui_names:

# Key names, IDs, and Molang variables in entities, models, particles, materials, animations, animation controllers, and render controllers (no obfuscation/escaping/formatting)
exclude_entity_names:

6 changes: 6 additions & 0 deletions docs/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ python main.py

<img src='receiving code.png' width=400>

[PayPal](https://www.paypal.com/paypalme/Airkk426)

[爱发电](https://afdian.com/a/Eric_Joker)

非常感谢您的支持\~您的头像会出现在我的 Github 主页和本项目的 Readme 中\~

## 感谢

感谢此项目的所有贡献者!
Expand Down
Loading

0 comments on commit 6ab7f6f

Please sign in to comment.