Automatically apply RSA patch

This commit is contained in:
Thoronium
2023-02-27 17:15:21 -07:00
committed by GitHub
parent 55fa0a8d3c
commit 62a97d86cb
23 changed files with 184 additions and 468 deletions

View File

@@ -33,11 +33,9 @@ A game launcher designed to easily proxy traffic from anime game to private serv
- [Screenshots](#screenshots)
- [Credits](#credits)
# Client Patching Notice
# Client Patching Notice - RSA
## This information is only for game versions 2.8/3.0. Newer versions do not use metadata patching.
For game versions 2.8 and above, Cultivation automatically makes a small patch to your game client when launching using Grasscutter, and restores it upon closing the game. In theory, you should still be totally safe, however it would be dishonest to not explicitly state that **modifying the game client could, theoretically, lead to a ban if you connect to official servers with it**. It is extremely unlikely AND there are no instances known of it happening, but the possibility exists.
For game versions 3.1 and above, Cultivation automatically makes a small patch to your game client when launching using Grasscutter, and restores it upon closing the game. In theory, you should still be totally safe, however it would be dishonest to not explicitly state that **modifying the game client could, theoretically, lead to a ban if you connect to official servers with it**. It is extremely unlikely AND there are no instances known of it happening, but the possibility exists.
# Download

View File

@@ -36,9 +36,7 @@
# 客户端修补通知
## 此信息仅适用于游戏版本 2.8/3.0。 较新的版本不使用元数据修补。
对于游戏版本为 2.8 及以上时,使用 Grasscutter 启动时Cultivation 会自动为您的游戏客户端制作一个小补丁,并在关闭游戏时恢复它。 从理论上讲,你应该是完全安全的,但是不明确**如果您使用它连接到官方服务器,修改游戏客户端可能会导致封号**,但可能性是非常小的,并且从未接到发生过此类情况的问题,但存在这种可能性!
对于游戏版本为 3.1 及以上时,使用 Grasscutter 启动时Cultivation 会自动为您的游戏客户端制作一个小补丁,并在关闭游戏时恢复它。 从理论上讲,你应该是完全安全的,但是不明确**如果您使用它连接到官方服务器,修改游戏客户端可能会导致封号**,但可能性是非常小的,并且从未接到发生过此类情况的问题,但存在这种可能性!
# 下载

View File

@@ -2,7 +2,7 @@
# 客戶端修補通知
對於遊戲版本為 2.8 及以上時,使用 Grasscutter 啟動時Cultivation 會自動為您的遊戲客戶端製作一個小修補,並在關閉遊戲時恢復它。 從理論上講,你應該是完全安全的,但是不明確**如果您使用它連接到官方伺服器,修改遊戲客戶端可能會導致封號**,但可能性是非常小的,並且從未接到發生過此類情況的問題,但存在這種可能性!
對於遊戲版本為 3.1 及以上時,使用 Grasscutter 啟動時Cultivation 會自動為您的遊戲客戶端製作一個小修補,並在關閉遊戲時恢復它。 從理論上講,你應該是完全安全的,但是不明確**如果您使用它連接到官方伺服器,修改遊戲客戶端可能會導致封號**,但可能性是非常小的,並且從未接到發生過此類情況的問題,但存在這種可能性!
# Cultivation: Thorny 版本

View File

@@ -16,7 +16,7 @@
"game_path": "选择游戏安装路径",
"game_command": "启动游戏的命令行",
"game_executable": "选择游戏可执行文件",
"recover_metadata": "紧急情况下恢复元数据文件",
"recover_rsa": "紧急情况下删除补丁文件",
"grasscutter_jar": "选择 Grasscutter JAR 文件",
"toggle_encryption": "启用加密",
"install_certificate": "安装代理证书",
@@ -25,7 +25,7 @@
"language": "选择语言",
"background": "设置自定义背景(链接或文件)",
"theme": "设置主题",
"patch_metadata": "自动修改元数据",
"patch_rsa": "自动修改RSA",
"use_proxy": "使用内置代理",
"wipe_login": "清除登录缓存",
"horny_mode": "Horny 模式"
@@ -72,9 +72,9 @@
"gc_dev_data": "下载最新的 Grasscutter 开发版数据,不包括 JAR 文件。此选项在更新时有帮助。",
"encryption": "此项设置通常应该处于关闭状态。",
"resources": "资源文件在运行 Grasscutter 服务器时是必要的。此选项在已经存在资源文件时不可选。",
"emergency_metadata": "在出现意外情况时自动将元数据恢复原始版本",
"emergency_rsa": "在出现意外情况时自动将 RSA 恢复原始版本",
"use_proxy": "使用 Cultivation 的内置代理。除非你使用 Fiddler 等软件,否则应启用此项。",
"patch_metadata": "自动修改和恢复游戏元数据。除非要游玩旧版/非官方版本,抑或你已经手动修改了元数据,否则应启用此。"
"patch_rsa": "自动修改和恢复 RSA 补丁。 除非您玩的是旧版/非官方版本,或者您手动修改了 RSA,否则应启用此功能。"
},
"swag": {
"akebi_name": "Akebi",

View File

@@ -16,7 +16,7 @@
"game_path": "選擇遊戲安裝路徑",
"game_command": "遊戲啟動命令",
"game_executable": "選擇遊戲執行檔",
"recover_metadata": "緊急恢復Metadata",
"recover_rsa": "緊急恢復RSA",
"grasscutter_jar": "選擇伺服器JAR檔案",
"toggle_encryption": "設定加密",
"install_certificate": "安裝代理憑證",
@@ -25,7 +25,7 @@
"language": "語言",
"background": "選擇自定義背景(網址或檔案)",
"theme": "選擇主題",
"patch_metadata": "自動修補Metadata",
"patch_rsa": "自動修補RSA",
"use_proxy": "使用內建代理伺服器",
"wipe_login": "擦除登錄緩存",
"horny_mode": "Horny模式"
@@ -72,9 +72,9 @@
"gc_dev_data": "下載當前最新的Grasscutter開發版本的資料文件其中不會附帶JAR文件。這個選項在更新時很有用。",
"encryption": "在正常情況下,此選項應該被關閉。",
"resources": "資源文件在架設一個Grasscutter伺服器時是必要的。 這個選項會在您已經有裡面有檔案的資源資料夾時不可選。",
"emergency_metadata": "一旦有東西出了問題,此選項可以把您的Metadata恢復成官方版本。",
"emergency_rsa": "一旦有東西出了問題,此選項可以把您的rsa恢復成官方版本。",
"use_proxy": "使用Cultivation內建的代理伺服器。此選項應該被啟用除非你使用其他的代理伺服器。",
"patch_metadata": "自動修補和恢復Metadata。除非您的遊戲版本是舊的或者是非官方的,此選項應該被啟用。"
"patch_rsa": "自動修補和恢復RSA。除非您的遊戲版本是舊的或者是非官方的,此選項應該被啟用。"
},
"swag": {
"akebi_name": "Akebi",

View File

@@ -15,7 +15,7 @@
"disabled": "Deaktiviert",
"game_path": "Spielpfad",
"game_executable": "Spiel Datei auswählen",
"recover_metadata": "Notfall Wiederherstellung der Metadaten",
"recover_rsa": "Notfall Wiederherstellung der RSA",
"grasscutter_jar": "Grasscuter JAR auswählen",
"toggle_encryption": "Verschlüsselung umschalten",
"install_certificate": "Installeer proxy certificaat",
@@ -24,7 +24,7 @@
"language": "Sprache auswählen",
"background": "Benutzerdefinierten Hintergrund festlegen (link oder bild)",
"theme": "Theme auswählen",
"patch_metadata": "Metadaten automatisch patchen",
"patch_rsa": "RSA automatisch patchen",
"use_proxy": "Gebruik interne proxy",
"wipe_login": "Wis de inlogcache",
"horny_mode": "Geile modus"
@@ -70,9 +70,9 @@
"gc_stable_data": "Laden Sie die stabilen Grasscutter Daten herunter, welche keine Jar-Datei enthalten. Dies ist nützlich zum Aktualisieren.",
"gc_dev_data": "Laden Sie die neuesten Grasscutter-Entwicklungsdateien herunter, welche keine Jar-Datei enthält. Dies ist nützlich zum Aktualisieren.",
"resources": "Diese werden auch benötigt, um einen Grasscutter-Server auszuführen. Diese Schaltfläche ist grau, wenn Sie einen bestehenden Ressourcenordner mit Inhalten haben",
"emergency_metadata": "Im Fall, dass etwas schief laufen sollte, kannst du deine Metadaten auf die letzte offizielle Version zurücksetzen",
"emergency_rsa": "Im Fall, dass etwas schief laufen sollte, kannst du deine RSA auf die letzte offizielle Version zurücksetzen",
"use_proxy": "Nutze den internen Proxy von Cultivation. Du solltest dies aktivieren, es sei denn du nutzt Programme wie Fiddler",
"patch_metadata": "Patche und aktualisiere deine Metadaten automatisch. Solange du nicht mit einer alten/nicht offiziellen Version spielst oder deine Metadaten manuell gepatcht hast, sollte dies aktiviert sein."
"patch_rsa": "Patche und aktualisiere deine RSA automatisch. Solange du nicht mit einer alten/nicht offiziellen Version spielst oder deine RSA manuell gepatcht hast, sollte dies aktiviert sein."
},
"swag": {
"akebi_name": "Akebi",

View File

@@ -16,7 +16,7 @@
"game_path": "Set Game Install Path",
"game_command": "Game Launch Command",
"game_executable": "Set Game Executable",
"recover_metadata": "Emergency Metadata Recovery",
"recover_rsa": "Emergency Delete RSA",
"grasscutter_jar": "Set Grasscutter JAR",
"toggle_encryption": "Toggle Encryption",
"install_certificate": "Install Proxy Certificate",
@@ -25,7 +25,7 @@
"language": "Select Language",
"background": "Set Custom Background (link or image file)",
"theme": "Set Theme",
"patch_metadata": "Automatically Patch Metadata",
"patch_rsa": "Automatically Patch RSA",
"use_proxy": "Use Internal Proxy",
"wipe_login": "Wipe Login Cache",
"horny_mode": "Horny Mode"
@@ -72,9 +72,9 @@
"gc_dev_data": "Download the latest development Grasscutter data files, which does not come with a jar file. This is useful for updating.",
"encryption": "This should usually be disabled.",
"resources": "These are also required to run a Grasscutter server. This button will be grey if you have an existing resources folder with contents inside",
"emergency_metadata": "In case something went wrong, restore your metadata to the latest official versions metadata. Only for 2.8/3.0",
"emergency_rsa": "In case something went wrong, force delete RSA patch.",
"use_proxy": "Use the Cultivation internal proxy. You should have this enabled unless you use something like Fiddler",
"patch_metadata": "Patch and unpatch your game metadata automatically. Unless playing with old/non-official versions (2.8/3.0), this should be disabled."
"patch_rsa": "Patch and unpatch your game RSA automatically. Unless playing with old/non-official versions (3.0 and older), this should be enabled."
},
"swag": {
"akebi_name": "Akebi",

View File

@@ -16,7 +16,7 @@
"game_path": "Ruta de instalación del juego",
"game_command": "Comando de lanzamiento del juego",
"game_executable": "Establecer ejecutable del juego",
"recover_metadata": "Recuperación de Metadatos de Emergencia",
"recover_rsa": "Recuperación de RSA de Emergencia",
"grasscutter_jar": "Establecer JAR de Grasscutter",
"toggle_encryption": "Alternar Cifrado",
"install_certificate": "Instalar Certificado Proxie",
@@ -24,7 +24,7 @@
"grasscutter_with_game": "Iniciar automáticamente Grasscutter con el juego",
"language": "Seleccionar Idioma",
"background": "Establecer Fondo Personalizado (link o archivo de imagen)",
"patch_metadata": "Automatically Patch Metadata",
"patch_rsa": "Parchear RSA automáticamente",
"theme": "Establecer Tema",
"use_proxy": "Use Internal Proxy",
"wipe_login": "Wipe Login Cache",

View File

@@ -16,7 +16,7 @@
"game_path": "Définir le chemin d'installation du jeu",
"game_command": "Commande de lancement du jeu",
"game_executable": "definir l'executable du jeu",
"recover_metadata": "Récupération d'urgence des métadonnées",
"recover_rsa": "Récupération d'urgence des RSA",
"grasscutter_jar": "definir le Jar Grasscutter",
"toggle_encryption": "activer l'encryption",
"install_certificate": "Installer le certificat du proxy",
@@ -25,7 +25,7 @@
"language": "Choisir la langue",
"background": "definir un arriere plan personnalise (lien ou fichier image)",
"theme": "definir un theme",
"patch_metadata": "Corriger automatiquement les métadonnées",
"patch_rsa": "Corriger automatiquement les RSA",
"use_proxy": "Utiliser un proxy interne",
"wipe_login": "Effacer le cache de connexion",
"horny_mode": "Mode excitation"

View File

@@ -15,7 +15,7 @@
"game_path": "Mengatur jalur penginstalan game",
"game_command": "Perintah peluncuran game",
"game_executable": "Mengatur game yang dapat dieksekusi",
"recover_metadata": "Pemulihan metadata darurat",
"recover_rsa": "Pemulihan RSA darurat",
"grasscutter_jar": "Path ke Grasscutter JAR",
"toggle_encryption": "Alihkan enkripsi",
"install_certificate": "Instal sertifikat proxy",
@@ -24,7 +24,7 @@
"language": "Pilih Bahasa",
"background": "Atur Kustom Latar Belakang (link atau gambar file)",
"theme": "Atur Tema",
"patch_metadata": "Automatically Patch Metadata",
"patch_rsa": "Automatically Patch RSA",
"use_proxy": "Gunakan Proxy Internal",
"wipe_login": "Menghapus Cache Login",
"horny_mode": "Mode Terangsang"

View File

@@ -16,7 +16,7 @@
"game_path": "게임 설치 경로 설정",
"game_command": "게임 시작 명령",
"game_executable": "게임 실행 파일 설정",
"recover_metadata": "긴급 메타데이터",
"recover_rsa": "긴급 RSA",
"grasscutter_jar": "그래스커터 JAR 설정",
"toggle_encryption": "암호화 전환",
"install_certificate": "프록시 인증서 설치",
@@ -25,7 +25,7 @@
"language": "언어 선택",
"background": "사용자 지정 배경 설정(링크 또는 이미지 파일)",
"theme": "테마 설정",
"patch_metadata": "자동으로 메타데이터 패치 적용",
"patch_rsa": "RSA 패치 자동 적용",
"use_proxy": "내부 프록시 사용",
"wipe_login": "로그인 캐시 지우기",
"horny_mode": "Horny 모드"
@@ -72,9 +72,9 @@
"gc_dev_data": "jar 파일과 함께 제공되지 않는 최신 개발 Grasscuter 데이터 파일을 다운로드합니다. 이것은 업데이트하는 데 유용합니다.",
"encryption": "일반적으로 이 기능을 사용하지 않도록 설정해야 합니다.",
"resources": "또한 Grasscutter 서버를 실행하는 데도 필요합니다. 내용이 포함된 기존 리소스 폴더가 있는 경우 이 버튼은 회색으로 표시됩니다",
"emergency_metadata": "문제가 발생한 경우 메타데이터를 최신 공식 버전 메타데이터로 복원합니다.",
"emergency_rsa": "문제가 있는 경우 RSA 패치를 제거하십시오.",
"use_proxy": "Culturation 내부 프록시를 사용합니다. 피들러와 같은 것을 사용하지 않는 한 이 기능을 활성화해야 합니다",
"patch_metadata": "게임 메타데이터를 자동으로 패치 및 패치 해제합니다. 이전/비공식 버전으로 재생하거나 메타데이터를 수동으로 패치한 경우를 제외하고는 이 기능을 사용하도록 설정해야 합니다."
"patch_rsa": "게임 RSA를 자동으로 패치 및 패치 해제합니다. 이전/비공식 버전을 사용하거나 RSA를 수동으로 패치하지 않은 경우 이 기능을 활성화해야 합니다."
},
"swag": {
"akebi_name": "Akebi",

View File

@@ -14,7 +14,7 @@
"enabled": "Iespējots",
"disabled": "Atspējots",
"game_executable": "Iestatīt spēles izpildāmu",
"recover_metadata": "Avārijas metadatu atjaunošana",
"recover_rsa": "Avārijas RSA atjaunošana",
"grasscutter_jar": "Iestatiet Grasscutter JAR",
"toggle_encryption": "Pārslēgt Šifrēšanu",
"install_certificate": "Proxy sertifikāta instalēšana",
@@ -23,7 +23,7 @@
"language": "Izvēlēties valodu",
"background": "Iestatīt pielāgotu fonu (saite vai attēla fails)",
"theme": "Iestatīt tēmu",
"patch_metadata": "Automātiski ielāpot metadatus",
"patch_rsa": "Automātiski ielāpot RSA",
"use_proxy": "Izmantot iekšējo starpniekserveri",
"wipe_login": "Noslaucīt pieteikšanās kešatmiņu",
"horny_mode": "Uzbudināts režīms"

View File

@@ -15,7 +15,7 @@
"disabled": "Uitgeschakeld",
"game_path": "Spel Installatie Pad Instellen",
"game_executable": "Stel De Exe Van Het Spel In",
"recover_metadata": "Noodherstel Van De Metadata",
"recover_rsa": "Noodherstel Van De RSA",
"grasscutter_jar": "Stel De Grasscutter JAR In",
"toggle_encryption": "Versleuteling Inschakelen",
"install_certificate": "Proxy-certificaat installeren",
@@ -24,7 +24,7 @@
"language": "Selecteer Taal",
"background": "Aangepaste Achtergrond Instellen (link of afbeeldingsbestand)",
"theme": "Thema instellen",
"patch_metadata": "Metadata Automatisch Bijwerken",
"patch_rsa": "RSA Automatisch Bijwerken",
"use_proxy": "Gebruik Interne Proxy",
"wipe_login": "Login cache wissen",
"horny_mode": "Geile modus"
@@ -71,9 +71,9 @@
"gc_dev_data": "Download de nieuwste versie van de Grasscutter data bestanden, die niet met een jar file komen. Dit is handig voor het bijwerken.",
"encryption": "Dit wordt meestal uitgeschakeld.",
"resources": "Deze zijn ook nodig om een Grasscutter server te draaien. Deze knop zal grijs zijn als u een bestaande resources map heeft met inhoud erin",
"emergency_metadata": "Voor het geval er iets fout is gegaan, herstel uw metadata naar de laatste offici<63>le versies metadata.",
"emergency_rsa": "Voor het geval er iets fout is gegaan, herstel uw rsa naar de laatste offici<63>le versies rsa.",
"use_proxy": "Gebruik de Cultivation interne proxy. U zou dit ingeschakeld moeten hebben, tenzij u iets als Fiddler gebruikt",
"patch_metadata": "Patch en unpatch je spel metadata automatisch. Tenzij je met oude/niet-offici<63>le versies speelt, of je hebt je metadata handmatig gepatcht, zou dit ingeschakeld moeten zijn."
"patch_rsa": "Patch en unpatch je spel rsa automatisch. Tenzij je met oude/niet-offici<63>le versies speelt, of je hebt je rsa handmatig gepatcht, zou dit ingeschakeld moeten zijn."
},
"swag": {
"akebi_name": "Akebi",

View File

@@ -15,7 +15,7 @@
"disabled": "Выключено",
"game_path": "Установить путь к файлам игры",
"game_executable": "Установить исполняемый файл игры",
"recover_metadata": "Принудительное восстановление Метаданных",
"recover_rsa": "Принудительное удаление RSA",
"grasscutter_jar": "Установить Grasscutter JAR",
"toggle_encryption": "Переключить шифрование",
"install_certificate": "Установить сертификат для работы Прокси",
@@ -24,7 +24,7 @@
"language": "Установить язык",
"background": "Установить свой фон (ссылка или файл)",
"theme": "Установить тему",
"patch_metadata": "Автоматический патч Метаданных при запуске",
"patch_rsa": "Автоматическое исправление RSA",
"use_proxy": "Использовать встроенный Прокси",
"wipe_login": "Очистить кэш входа в систему",
"horny_mode": "роговой режим"
@@ -71,9 +71,9 @@
"gc_dev_data": "Скачать последнюю версию для разработки Grasscutter, в которой нету jar файла. Это полезно для обновления.",
"encryption": "Обычно это должно быть выключено.",
"resources": "Это необходимо для запуска сервера Grasscutter. Эта кнопка будет серой, если у Вас уже есть не пустая папка с ресурсами.",
"emergency_metadata": "Если что-то пошло не так, восстановит Метаданные до последней официальной версии.",
"emergency_rsa": "Если что-то пошло не так, восстановит RSA до последней официальной версии.",
"use_proxy": "Использовать встроенный Прокси. Отключите если используете Fiddler или подобную программу",
"patch_metadata": "Патчит и восстанавливает Метаданные автоматически. Если вы не играете на старых/модифицированых версиях, или сами в ручную патчите Метаданные, эта опция должна быть включена."
"patch_rsa": "Патчит и восстанавливает RSA автоматически. Если вы не играете на старых/модифицированых версиях, или сами в ручную патчите Метаданные, эта опция должна быть включена."
},
"swag": {
"akebi_name": "Akebi",

View File

@@ -16,7 +16,7 @@
"game_path": "Đường dẫn cài game",
"game_command": "Lệnh khởi chạy game",
"game_executable": "Tập tin thực thi game",
"recover_metadata": "Khôi phục metadata khẩn cấp",
"recover_rsa": "Khôi phục RSA khẩn cấp",
"grasscutter_jar": "Tập tin JAR Grasscutter",
"toggle_encryption": "Bật/tắt mã hóa",
"install_certificate": "Cài chứng chỉ proxy",
@@ -25,7 +25,7 @@
"language": "Ngôn ngữ",
"background": "Hình nền tùy chỉnh (liên kết hoặc tập tin hình ảnh)",
"theme": "Giao diện",
"patch_metadata": "Tự động vá metadata",
"patch_rsa": "Tự động vá RSA",
"use_proxy": "Sử dụng proxy nội bộ",
"wipe_login": "Tẩy sạch cache đăng nhập",
"horny_mode": "Chế độ hứng tình"
@@ -72,9 +72,9 @@
"gc_dev_data": "Tải xuống tệp dữ liệu phiên bản mới nhất của Grasscutter. Bản này không đi kèm với tập tin jar, hữu dụng khi muốn cập nhật.",
"encryption": "Mục này nên được tắt.",
"resources": "Tài nguyên được yêu cầu để chạy máy chủ Grasscutter. Nút này sẽ có màu xám nếu bạn đã có sẵn một thư mục tài nguyên (resources) có nội dung bên trong",
"emergency_metadata": "Trong trường hợp gặp vấn đề, khôi phục lại metadata về phiên bản chính thức mới nhất.",
"emergency_rsa": "Trong trường hợp gặp vấn đề, khôi phục lại RSA về phiên bản chính thức mới nhất.",
"use_proxy": "Sử dụng proxy nội bộ của Cultivation. Nên bật tùy chọn này trừ khi bạn đang sử dụng một ứng dụng khác, như Fiddler",
"patch_metadata": "Tự động vá và sửa lại metadata của game. Tùy chọn này nên được bật trừ khi bạn đang sử dụng phiên bản cũ, phiên bản không chính thức hoặc bạn đã tự vá metadata rồi."
"patch_rsa": "Tự động vá và sửa lại RSA của game. Tùy chọn này nên được bật trừ khi bạn đang sử dụng phiên bản cũ, phiên bản không chính thức hoặc bạn đã tự vá rsa rồi."
},
"swag": {
"akebi_name": "Akebi",

View File

@@ -22,7 +22,6 @@ mod downloader;
mod file_helpers;
mod gamebanana;
mod lang;
mod metadata_patcher;
mod proxy;
mod system_helpers;
mod unzip;
@@ -119,8 +118,7 @@ fn main() {
web::web_get,
gamebanana::get_download_links,
gamebanana::list_submissions,
gamebanana::list_mods,
metadata_patcher::patch_metadata
gamebanana::list_mods
])
.run(tauri::generate_context!())
.expect("error while running tauri application");

View File

@@ -1,153 +0,0 @@
use regex::Regex;
use std::{fs, fs::File, fs::OpenOptions, io::Read, io::Write, path::Path};
// For these two functions, a non-zero return value indicates failure.
extern "C" {
fn decrypt_global_metadata(data: *mut u8, size: usize) -> i32;
fn encrypt_global_metadata(data: *mut u8, size: usize) -> i32;
}
#[tauri::command]
pub fn patch_metadata(metadata_folder: &str) -> bool {
let metadata_file = &(metadata_folder.to_owned() + "\\global-metadata-unpatched.dat");
// check if metadata_file exists
if !Path::new(metadata_file).exists() {
println!("Metadata file not found");
return false;
}
println!("Patching metadata file: {}", metadata_file);
let decrypted = decrypt_metadata(metadata_file);
if do_vecs_match(&decrypted, &Vec::new()) {
println!("Failed to decrypt metadata file.");
return false;
}
let modified = replace_keys(&decrypted);
if do_vecs_match(&modified, &Vec::new()) {
println!("Failed to replace keys in metadata file.");
return false;
}
let encrypted = encrypt_metadata(&modified);
if do_vecs_match(&encrypted, &Vec::new()) {
println!("Failed to re-encrypt metadata file.");
return false;
}
//write encrypted to file
let mut file = match OpenOptions::new()
.create(true)
.write(true)
.open(&(metadata_folder.to_owned() + "\\global-metadata-patched.dat"))
{
Ok(file) => file,
Err(e) => {
println!("Failed to open global-metadata: {}", e);
return false;
}
};
file.write_all(&encrypted).unwrap();
true
}
fn decrypt_metadata(file_path: &str) -> Vec<u8> {
let mut file = match File::open(file_path) {
Ok(file) => file,
Err(e) => {
println!("Failed to open global-metadata: {}", e);
return Vec::new();
}
};
let mut data = Vec::new();
// Read metadata file
match file.read_to_end(&mut data) {
Ok(_) => (),
Err(e) => {
println!("Failed to read global-metadata: {}", e);
return Vec::new();
}
}
// Decrypt metadata file
let success = unsafe { decrypt_global_metadata(data.as_mut_ptr(), data.len()) } == 0;
if success {
println!("Successfully decrypted global-metadata");
data
} else {
println!("Failed to decrypt global-metadata");
Vec::new()
}
}
fn replace_keys(data: &[u8]) -> Vec<u8> {
let mut new_data = String::new();
unsafe {
let data_str = String::from_utf8_unchecked(data.to_vec());
let re = Regex::new(r"<RSAKeyValue>((.|\n|\r)*?)</RSAKeyValue>").unwrap();
let matches = re.find_iter(&data_str);
// dispatch key is index 3
// password key is index 2
for (i, rmatch) in matches.enumerate() {
let key = rmatch.as_str();
if i == 2 {
println!("Replacing password key");
new_data = replace_rsa_key(&data_str, key, "passwordKey.txt");
} else if i == 3 {
println!("Replacing dispatch key");
new_data = replace_rsa_key(&new_data, key, "dispatchKey.txt");
}
}
}
return new_data.as_bytes().to_vec();
}
fn replace_rsa_key(old_data: &str, to_replace: &str, file_name: &str) -> String {
// Read dispatch key file
unsafe {
// Get key path from current directory
let key_file_path = std::env::current_dir()
.unwrap()
.join("keys")
.join(file_name);
let key_data = match fs::read(&key_file_path) {
Ok(file) => file,
Err(e) => {
println!("Failed to open {}: {}", key_file_path.to_str().unwrap(), e);
return String::new();
}
};
let new_key = String::from_utf8_unchecked(key_data.to_vec());
// Replace old key with new key
old_data.replace(to_replace, &new_key)
}
}
fn encrypt_metadata(old_data: &[u8]) -> Vec<u8> {
let mut data = old_data.to_vec();
let success = unsafe { encrypt_global_metadata(data.as_mut_ptr(), data.len()) } == 0;
if success {
println!("Successfully encrypted global-metadata");
data
} else {
println!("Failed to encrypt global-metadata");
Vec::new()
}
}
fn do_vecs_match<T: PartialEq>(a: &Vec<T>, b: &Vec<T>) -> bool {
a == b
}

View File

@@ -17,7 +17,7 @@ import { invoke } from '@tauri-apps/api'
import { listen } from '@tauri-apps/api/event'
import { dataDir } from '@tauri-apps/api/path'
import { appWindow } from '@tauri-apps/api/window'
import { unpatchGame } from '../utils/metadata'
import { unpatchGame } from '../utils/rsa'
import DownloadHandler from '../utils/download'
// Graphics
@@ -65,16 +65,16 @@ export class Main extends React.Component<IProps, IState> {
setConfigOption('grasscutter_path', payload)
})
// Emitted for metadata replacing-purposes
// Emitted for rsa replacing-purposes
listen('game_closed', async () => {
const wasPatched = await getConfigOption('patch_metadata')
const wasPatched = await getConfigOption('patch_rsa')
if (wasPatched) {
const unpatched = await unpatchGame()
if (!unpatched) {
alert(
`Could not unpatch game! (You should be able to find your metadata backup in ${await dataDir()}\\cultivation\\)`
`Could not unpatch game! (Delete version.dll in your game folder)`
)
}
}

View File

@@ -13,7 +13,7 @@ import Plus from '../../resources/icons/plus.svg'
import './ServerLaunchSection.css'
import { dataDir } from '@tauri-apps/api/path'
import { getGameExecutable, getGameVersion } from '../../utils/game'
import { patchGame, unpatchGame } from '../../utils/metadata'
import { patchGame, unpatchGame } from '../../utils/rsa'
interface IProps {
openExtras: (playGame: () => void) => void
@@ -109,7 +109,7 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
// Connect to proxy
if (config.toggle_grasscutter) {
if (config.patch_metadata) {
if (config.patch_rsa) {
const gameVersion = await getGameVersion()
console.log(gameVersion)
@@ -120,16 +120,16 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
return
}
if (gameVersion?.major == 2 && gameVersion?.minor < 8) {
if (gameVersion?.major == 2 && gameVersion?.minor < 9) {
alert(
'Game version is too old for metadata patching. Please disable metadata patching in the settings and try again.'
'Game version is too old for RSA patching. Please disable RSA patching in the settings and try again.'
)
return
}
if (gameVersion?.major == 3 && gameVersion?.minor >= 1) {
if (gameVersion?.major == 3 && gameVersion?.minor < 1) {
alert(
'Game version is too new for metadata patching. TO FIX: Please disable metadata patching in the settings menu to launch the game!! \nNOTE: You will require an RSA patch to play the game.'
'Game version is too old for RSA patching. Please disable RSA patching in the settings and try again.'
)
return
}
@@ -179,7 +179,7 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
if (!unpatched) {
alert(
`Could not unpatch game, aborting launch! (You can find your metadata backup in ${await dataDir()}\\cultivation\\)`
`Could not unpatch game, aborting launch! (You can unpatch in your game install folder, either remove version.dll or repair mhypbase.dll in launcher)`
)
return
}

View File

@@ -13,7 +13,7 @@ import * as server from '../../../utils/server'
import './Options.css'
import BigButton from '../common/BigButton'
import DownloadHandler from '../../../utils/download'
import * as meta from '../../../utils/metadata'
import * as meta from '../../../utils/rsa'
import HelpButton from '../common/HelpButton'
import TextInput from '../common/TextInput'
@@ -33,7 +33,7 @@ interface IState {
themes: string[]
theme: string
encryption: boolean
patch_metadata: boolean
patch_rsa: boolean
use_internal_proxy: boolean
wipe_login: boolean
horny_mode: boolean
@@ -61,7 +61,7 @@ export default class Options extends React.Component<IProps, IState> {
themes: ['default'],
theme: '',
encryption: false,
patch_metadata: false,
patch_rsa: false,
use_internal_proxy: false,
wipe_login: false,
horny_mode: false,
@@ -82,7 +82,7 @@ export default class Options extends React.Component<IProps, IState> {
this.toggleGrasscutterWithGame = this.toggleGrasscutterWithGame.bind(this)
this.setCustomBackground = this.setCustomBackground.bind(this)
this.toggleEncryption = this.toggleEncryption.bind(this)
this.restoreMetadata = this.restoreMetadata.bind(this)
this.removeRSA = this.removeRSA.bind(this)
}
async componentDidMount() {
@@ -108,7 +108,7 @@ export default class Options extends React.Component<IProps, IState> {
themes: (await getThemeList()).map((t) => t.name),
theme: config.theme || 'default',
encryption: await translate(encEnabled ? 'options.enabled' : 'options.disabled'),
patch_metadata: config.patch_metadata || false,
patch_rsa: config.patch_rsa || false,
use_internal_proxy: config.use_internal_proxy || false,
wipe_login: config.wipe_login || false,
horny_mode: config.horny_mode || false,
@@ -266,8 +266,8 @@ export default class Options extends React.Component<IProps, IState> {
})
}
async restoreMetadata() {
await meta.restoreMetadata(this.props.downloadManager)
async removeRSA() {
await meta.unpatchGame()
}
async installCert() {
@@ -311,24 +311,24 @@ export default class Options extends React.Component<IProps, IState> {
)}
<div className="OptionSection" id="menuOptionsContainermetaDownload">
<div className="OptionLabel" id="menuOptionsLabelmetaDownload">
<Tr text="options.recover_metadata" />
<HelpButton contents="help.emergency_metadata" />
<Tr text="options.recover_rsa" />
<HelpButton contents="help.emergency_rsa" />
</div>
<div className="OptionValue" id="menuOptionsButtonmetaDownload">
<BigButton onClick={this.restoreMetadata} id="metaDownload">
<BigButton onClick={this.removeRSA} id="metaDownload">
<Tr text="components.download" />
</BigButton>
</div>
</div>
<div className="OptionSection" id="menuOptionsContainerPatchMeta">
<div className="OptionLabel" id="menuOptionsLabelPatchMeta">
<Tr text="options.patch_metadata" />
<HelpButton contents="help.patch_metadata" />
<Tr text="options.patch_rsa" />
<HelpButton contents="help.patch_rsa" />
</div>
<div className="OptionValue" id="menuOptionsCheckboxPatchMeta">
<Checkbox
onChange={() => this.toggleOption('patch_metadata')}
checked={this.state?.patch_metadata}
onChange={() => this.toggleOption('patch_rsa')}
checked={this.state?.patch_rsa}
id="patchMeta"
/>
</div>

View File

@@ -20,7 +20,7 @@ let defaultConfig: Configuration
theme: 'default',
https_enabled: false,
debug_enabled: false,
patch_metadata: false,
patch_rsa: true,
use_internal_proxy: true,
wipe_login: false,
horny_mode: false,
@@ -46,7 +46,7 @@ export interface Configuration {
theme: string
https_enabled: boolean
debug_enabled: boolean
patch_metadata: boolean
patch_rsa: boolean
use_internal_proxy: boolean
wipe_login: boolean
horny_mode: boolean

View File

@@ -1,237 +0,0 @@
import { invoke } from '@tauri-apps/api'
import { dataDir } from '@tauri-apps/api/path'
import DownloadHandler from './download'
import { getGameDataFolder } from './game'
export async function patchMetadata() {
const metadataExists = await invoke('dir_exists', {
path: (await getGameMetadataPath()) + '\\global-metadata.dat',
})
if (!metadataExists) {
return false
}
console.log('Copying unpatched metadata to backup location')
// Copy unpatched metadata to backup location
const copiedMeta = await invoke('copy_file_with_new_name', {
path: (await getGameMetadataPath()) + '\\global-metadata.dat',
newPath: await getBackupMetadataPath(),
newName: 'global-metadata-unpatched.dat',
})
if (!copiedMeta) {
console.log(await getBackupMetadataPath())
return false
}
// backup was successful! Time to patch
console.log('Patching backedup metadata')
const patchedMeta = await invoke('patch_metadata', {
metadataFolder: await getBackupMetadataPath(),
})
if (!patchedMeta) {
// Remove metadata backup, in case it invalid or something
await invoke('delete_file', {
path: (await getBackupMetadataPath()) + '\\global-metadata-unpatched.dat',
})
return false
}
// Patch also worked! Time to replace
console.log('Replacing unpatched game metadata with patched metadata')
const replacedMeta = await invoke('copy_file_with_new_name', {
path: (await getBackupMetadataPath()) + '\\global-metadata-patched.dat',
newPath: await getGameMetadataPath(),
newName: 'global-metadata.dat',
})
if (!replacedMeta) {
return false
}
console.log('Replacement successful!')
return true
}
export async function patchGame() {
const backupExists = await invoke('dir_exists', {
path: (await getBackupMetadataPath()) + '\\global-metadata-unpatched.dat',
})
if (!backupExists) {
// No backup found? Patching creates one
const patched = await patchMetadata()
if (!patched) {
return false
}
}
// Do we have a patch already?
const patchedExists = await invoke('dir_exists', {
path: (await getBackupMetadataPath()) + '\\global-metadata-patched.dat',
})
if (!patchedExists) {
// No patch found? Patching creates one
const patched = await patchMetadata()
if (!patched) {
return false
}
}
// Are we already patched? If so, that's fine, just continue as normal
const gameIsPatched = await invoke('are_files_identical', {
path1: (await getBackupMetadataPath()) + '\\global-metadata-patched.dat',
path2: (await getGameMetadataPath()) + '\\global-metadata.dat',
})
if (gameIsPatched) {
return true
}
// Is the current backup the same as the games current metadata?
const backupIsCurrent = await invoke('are_files_identical', {
path1: (await getBackupMetadataPath()) + '\\global-metadata-unpatched.dat',
path2: (await getGameMetadataPath()) + '\\global-metadata.dat',
})
// Game has probably been updated. We need to repatch the game...
if (!backupIsCurrent) {
const deletedOldBackup = await invoke('delete_file', {
path: (await getBackupMetadataPath()) + '\\global-metadata-unpatched.dat',
})
const deletedOldPatched = await invoke('delete_file', {
path: (await getBackupMetadataPath()) + '\\global-metadata-patched.dat',
})
// It's fine if these deletes fail. The game will be replaced anyway.
if (!deletedOldBackup) {
console.log('Warning: Failed to delete old backup!')
}
if (!deletedOldPatched) {
console.log('Warning: Failed to delete old patched metadata!')
}
console.log('Patching Metadata')
const patched = await patchMetadata()
if (!patched) {
return false
}
return true
}
console.log('Metadata is not patched')
console.log('Replacing unpatched metadata')
// Finally, replace the unpatched metadata with the patched one
const replaced = await invoke('copy_file_with_new_name', {
path: (await getBackupMetadataPath()) + '\\global-metadata-patched.dat',
newPath: await getGameMetadataPath(),
newName: 'global-metadata.dat',
})
if (!replaced) {
return false
}
return true
}
export async function unpatchGame() {
const backupExists = await invoke('dir_exists', {
path: (await getBackupMetadataPath()) + '\\global-metadata-unpatched.dat',
})
if (!backupExists) {
// Let's just hope the game isn't on a patched metadata since we don't have a backup...
return true
}
const replaced = await invoke('copy_file_with_new_name', {
path: (await getBackupMetadataPath()) + '\\global-metadata-unpatched.dat',
newPath: await getGameMetadataPath(),
newName: 'global-metadata.dat',
})
return replaced
}
export async function getGameMetadataPath() {
const gameData = await getGameDataFolder()
if (!gameData) {
return null
}
return (gameData + '\\Managed\\Metadata').replace(/\\/g, '/')
}
export async function getBackupMetadataPath() {
return (await dataDir()) + 'cultivation\\metadata'
}
export async function globalMetadataLink() {
// TODO: Get metadata based on current game version.
const versionAPIUrl =
'https://sdk-os-static.mihoyo.com/hk4e_global/mdk/launcher/api/resource?channel_id=1&key=gcStgarh&launcher_id=10&sub_channel_id=0'
// Get versions from API
const versions = JSON.parse(
await invoke('web_get', {
url: versionAPIUrl,
})
)
if (!versions || versions.retcode !== 0) {
console.log('Failed to get versions from API')
return null
}
// Get latest version
const latest = versions.data.game.latest
return (latest.decompressed_path as string) + '/GenshinImpact_Data/Managed/Metadata/global-metadata.dat'
}
export async function restoreMetadata(manager: DownloadHandler) {
const metaLink = await globalMetadataLink()
if (!metaLink) {
console.log('Could not get global metadata link!')
return false
}
// Should make sure metadata path exists since the user may have deleted it
await invoke('dir_create', {
path: await getBackupMetadataPath(),
})
// It is possible the unpatched backup is mistakenly patched
await invoke('delete_file', {
path: (await getBackupMetadataPath()) + '\\global-metadata-unpatched.dat',
})
// Download the file
manager.addDownload(metaLink, (await getBackupMetadataPath()) + '\\global-metadata-unpatched.dat', () => {
unpatchGame()
})
console.log('Restoring backedup metadata')
await unpatchGame()
return true
}

112
src/utils/rsa.ts Normal file
View File

@@ -0,0 +1,112 @@
import { invoke } from '@tauri-apps/api'
import { dataDir } from '@tauri-apps/api/path'
import DownloadHandler from './download'
import { getGameFolder } from './game'
interface IProps {
downloadHandler: DownloadHandler
}
export async function patchRSA() {
const rsaExists = await invoke('dir_exists', {
path: (await getBackupRSAPath()) + '\\version.dll',
})
if (rsaExists) {
// Already patched
return true
}
console.log('Downloading rsa patch to backup location')
// Download RSA patch to backup location
const downloadedRSA = await downloadRSA(this.props.downloadHandler)
if (!downloadedRSA) {
console.log(await getBackupRSAPath())
return false
}
console.log('RSA download successful!')
return true
}
export async function patchGame() {
// Do we have a patch already?
const patchedExists = await invoke('dir_exists', {
path: (await getBackupRSAPath()) + '\\version.dll',
})
if (!patchedExists) {
// No patch found? Patching creates one
const patched = await patchRSA()
if (!patched) {
return false
}
}
// Are we already patched with mhypbase? If so, that's fine, just continue as normal
const gameIsPatched = await invoke('are_files_identical', {
path1: (await getBackupRSAPath()) + '\\version.dll',
path2: (await getGameRSAPath()) + '\\mhypbase.dll',
})
// Tell user they won't be unpatched with manual mhypbase patch
if (gameIsPatched) {
console.log('You are already patched using mhypbase, so you will not be auto patched and unpatched!')
return true
}
// Copy the patch to game files
const replaced = await invoke('copy_file', {
path: (await getBackupRSAPath()) + '\\version.dll',
newPath: await getGameRSAPath(),
})
if (!replaced) {
return false
}
return true
}
export async function unpatchGame() {
// Just delete patch since it's not replacing any existing file
const deleted = await invoke('delete_file', {
path: (await getGameRSAPath()) + '\\version.dll',
})
return deleted
}
export async function getGameRSAPath() {
const gameData = await getGameFolder()
if (!gameData) {
return null
}
return gameData
}
export async function getBackupRSAPath() {
return (await dataDir()) + 'cultivation\\rsa'
}
export async function downloadRSA(manager: DownloadHandler) {
const rsaLink = 'https://github.com/34736384/RSAPatch/releases/download/v1.1.0/RSAPatch.dll'
// Should make sure rsa path exists
await invoke('dir_create', {
path: await getBackupRSAPath(),
})
// Download the file
manager.addDownload(rsaLink, (await getBackupRSAPath()) + '\\version.dll', () => {
null
})
return true
}