diff --git a/main.py b/main.py index 556f5fd..2c0bb02 100644 --- a/main.py +++ b/main.py @@ -113,6 +113,7 @@ class Patch: return True except Exception as e: print(f"Ошибка при применении патча {self.name}: {e}") + print(e.args) return False diff --git a/patches/application_icon.py b/patches/application_icon.py index a12b8ab..6b792ae 100644 --- a/patches/application_icon.py +++ b/patches/application_icon.py @@ -3,5 +3,5 @@ import time def apply(config: dict) -> bool: - time.sleep(1) + time.sleep(0.2) return False diff --git a/patches/color_theme.py b/patches/color_theme.py index 06ec150..740cffe 100644 --- a/patches/color_theme.py +++ b/patches/color_theme.py @@ -1,6 +1,6 @@ # Change application theme -import re +from lxml import etree def apply(config: dict) -> bool: @@ -24,34 +24,32 @@ def apply(config: dict) -> bool: for drawable_type in drawable_types: # Application logo gradient colors file_path = f"./decompiled/res/drawable{drawable_type}/$logo__0.xml" - with open(file_path, "r", encoding="utf-8") as file: - content = file.read() - pattern = r'android:startColor="(#[0-9a-fA-F]{8})"\s+android:endColor="(#[0-9a-fA-F]{8})"' + parser = etree.XMLParser(remove_blank_text=True) + tree = etree.parse(file_path, parser) + root = tree.getroot() - def replace_colors(match): - return ( - f'android:startColor="{gradient_from}" android:endColor="{gradient_to}"' - ) + # Change attributes with namespace + root.set(f"{{{config['xml_ns']['android']}}}startColor", gradient_from) + root.set(f"{{{config['xml_ns']['android']}}}endColor", gradient_to) - new_content = re.sub(pattern, replace_colors, content).replace("\n ", "") - - with open(file_path, "w", encoding="utf-8") as file: - file.write(new_content) + # Save back + tree.write(file_path, pretty_print=True, xml_declaration=True, encoding="utf-8") # Application logo anim color file_path = f"./decompiled/res/drawable{drawable_type}/$logo_splash_anim__0.xml" - with open(file_path, "r", encoding="utf-8") as file: - content = file.read() - pattern = r'android:name="path" android:fillColor="(#[0-9a-fA-F]{8})"' + parser = etree.XMLParser(remove_blank_text=True) + tree = etree.parse(file_path, parser) + root = tree.getroot() - def replace_colors(match): - return f'android:name="path" android:fillColor="{splash_color}"' + # Finding "path" + for el in root.findall("path", namespaces=config['xml_ns']): + name = el.get(f"{{{config['xml_ns']['android']}}}name") + if name == "path": + el.set(f"{{{config['xml_ns']['android']}}}fillColor", splash_color) - new_content = re.sub(pattern, replace_colors, content).replace("\n ", " ", 1) - - with open(file_path, "w", encoding="utf-8") as file: - file.write(new_content) + # Save back + tree.write(file_path, pretty_print=True, xml_declaration=True, encoding="utf-8") return True diff --git a/patches/config.json b/patches/config.json index 283fb11..f1fdd08 100644 --- a/patches/config.json +++ b/patches/config.json @@ -14,9 +14,37 @@ } }, "cleanup": { - "keep_dirs": [ - "META-INF", - "kotlin" + "keep_dirs": ["META-INF", "kotlin"] + }, + "settings_urls": { + "Мы в социальных сетях": [ + { + "title": "wowlikon", + "description": "Разработчик", + "url": "https://t.me/wowlikon", + "icon": "@drawable/ic_custom_telegram", + "icon_space_reserved": "false" + }, + { + "title": "Мы в Telegram", + "description": "Подпишитесь на канал, чтобы быть в курсе последних новостей.", + "url": "https://t.me/wowlikon", + "icon": "@drawable/ic_custom_telegram", + "icon_space_reserved": "false" + } + ], + "Прочее": [ + { + "title": "Поддержать проект", + "description": "После пожертвования вы сможете выбрать в своём профиле любую роль, например «Кошка-девочка», которая будет видна всем пользователям мода.", + "url": "https://t.me/wowlikon", + "icon": "@drawable/ic_custom_crown", + "icon_space_reserved": "false" + } ] + }, + "xml_ns": { + "android": "http://schemas.android.com/apk/res/android", + "app": "http://schemas.android.com/apk/res-auto" } } diff --git a/patches/insert_new.py b/patches/insert_new.py index dbc6621..5252e64 100644 --- a/patches/insert_new.py +++ b/patches/insert_new.py @@ -11,10 +11,9 @@ def apply(config: dict) -> bool: ) # Mod assets - shutil.copy("./patches/resources/wowlikon.png", "./decompiled/assets/wowlikon.png") shutil.copy( - "./patches/resources/ytsans_medium.ttf", - "./decompiled/res/font/ytsans_medium.ttf", + "./patches/resources/wowlikon.png", + "./decompiled/assets/wowlikon.png" ) shutil.copy( "./patches/resources/OpenSans-Regular.ttf", @@ -29,9 +28,20 @@ def apply(config: dict) -> bool: "./decompiled/res/drawable/ic_custom_telegram.xml", ) shutil.copy( - "./patches/resources/torlook-fs8.torlook-fs8.png", - "./decompiled/res/drawable/torlook-fs8.png", + "./patches/resources/ytsans_medium.ttf", + "./decompiled/res/font/ytsans_medium.ttf", + ) + os.remove("./decompiled/res/font/ytsans_medium.otf") + + # IDK + shutil.move( + "./decompiled/res/raw/bundled_cert.crt", + "./decompiled/res/raw/bundled_cert.cer", + ) + shutil.move( + "./decompiled/res/raw/sdkinternalca.crt", + "./decompiled/res/raw/sdkinternalca.cer", ) os.remove("./decompiled/res/font/ytsans_medium.otf") - return False + return True diff --git a/patches/resources/torlook-fs8.png b/patches/resources/torlook-fs8.png deleted file mode 100644 index 5604b9f..0000000 Binary files a/patches/resources/torlook-fs8.png and /dev/null differ diff --git a/patches/settings_urls.py b/patches/settings_urls.py new file mode 100644 index 0000000..d32324a --- /dev/null +++ b/patches/settings_urls.py @@ -0,0 +1,41 @@ +# Change application theme + +from lxml import etree + + +# Generate PreferenceCategory +def make_category(ns, name, items): + cat = etree.Element("PreferenceCategory", nsmap=ns) + cat.set(f"{{{ns['android']}}}title", name) + cat.set(f"{{{ns['app']}}}iconSpaceReserved", "false") + + for item in items: + pref = etree.SubElement(cat, "Preference", nsmap=ns) + pref.set(f"{{{ns['android']}}}title", item["title"]) + pref.set(f"{{{ns['android']}}}summary", item["description"]) + pref.set(f"{{{ns['app']}}}icon", item["icon"]) + pref.set(f"{{{ns['app']}}}iconSpaceReserved", item["icon_space_reserved"]) + + intent = etree.SubElement(pref, "intent", nsmap=ns) + intent.set(f"{{{ns['android']}}}action", "android.intent.action.VIEW") + intent.set(f"{{{ns['android']}}}data", item["url"]) + intent.set(f"{{{ns['app']}}}iconSpaceReserved", item["icon_space_reserved"]) + + return cat + +def apply(config: dict) -> bool: + file_path = "./decompiled/res/xml/preference_main.xml" + parser = etree.XMLParser(remove_blank_text=True) + tree = etree.parse(file_path, parser) + root = tree.getroot() + + # Insert new PreferenceCategory before the last element + last = root[-1] # last element + pos = root.index(last) + for section, items in config["settings_urls"].items(): + root.insert(pos, make_category(config["xml_ns"], section, items)) + pos += 1 + + # Save back + tree.write(file_path, pretty_print=True, xml_declaration=True, encoding="utf-8") + return True