Created
November 14, 2026 15:21
-
-
Save knowlet/ca362f94ebd6dbed6baf465602817610 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import re | |
| import shutil | |
| import argparse | |
| import json | |
| def backup_file(filepath): | |
| backup = f"{filepath}.bak" | |
| if not os.path.exists(backup): | |
| shutil.copy(filepath, backup) | |
| def fix_plugins_js(filepath): | |
| with open(filepath, 'r', encoding='utf-8') as f: | |
| content = f.read() | |
| new_content, count = re.subn( | |
| r'("name"\s*:\s*[\'"]OrangeGreenworks[\'"][^}]*?"status"\s*:\s*)true', | |
| r'\1false', | |
| content | |
| ) | |
| if count: | |
| print(f"✅ Disabled OrangeGreenworks in {filepath}") | |
| backup_file(filepath) | |
| with open(filepath, 'w', encoding='utf-8') as f: | |
| f.write(new_content) | |
| def remove_achievement_calls_json(jsonfile): | |
| # 將 data 資料夾下每個檔案出現 OrangeGreenworks.activateAchievement("...") class 事件自動移除 | |
| changed = False | |
| backup_file(jsonfile) | |
| try: | |
| with open(jsonfile, 'r', encoding='utf-8') as f: | |
| data = json.load(f) | |
| # 處理 RPG Maker 的事件串 class: "Game_Interpreter", code=355, parameters 裡有 OrangeGreenworks.activateAchievement | |
| def recursive_remove(obj): | |
| nonlocal changed | |
| if isinstance(obj, dict): | |
| for k, v in obj.items(): | |
| # 處理 parameters 字串刪除 | |
| if k == 'parameters' and isinstance(v, list): | |
| for i in range(len(v)): | |
| if isinstance(v[i], str) and "OrangeGreenworks.activateAchievement" in v[i]: | |
| changed = True | |
| v[i] = re.sub(r'OrangeGreenworks\.activateAchievement\([\'"].+?[\'"]\);?', '', v[i]) | |
| else: | |
| recursive_remove(v) | |
| elif isinstance(obj, list): | |
| for v in obj: | |
| recursive_remove(v) | |
| recursive_remove(data) | |
| if changed: | |
| with open(jsonfile, 'w', encoding='utf-8') as f: | |
| json.dump(data, f, ensure_ascii=False, indent=2) | |
| print(f"✅ Removed OrangeGreenworks.activateAchievement() in {jsonfile}") | |
| except Exception as e: | |
| print(f"⚠️ 錯誤於 {jsonfile}: {e}") | |
| def fix_color_index(jsfile): | |
| # 只針對 MPP_MessageEX.js | |
| try: | |
| with open(jsfile, 'r', encoding='utf-8') as f: | |
| lines = f.readlines() | |
| except Exception as e: | |
| print(f"❌ 開啟 {jsfile} 失敗: {e}") | |
| return | |
| changed = False | |
| i = 0 | |
| while i < len(lines): | |
| # 找出 Window_Base.prototype.initialize.call(this ...) 行的 index | |
| if re.search(r'Window_Base\.prototype\.initialize\.call\s*\(.*\)', lines[i]): | |
| # 搜尋這行後五行內有沒有 this._colorIndex = 0; | |
| for offset in range(1, 6): | |
| idx = i + offset | |
| if idx < len(lines) and re.search(r'this\._colorIndex\s*=\s*0\s*;', lines[idx]): | |
| if i > 0 and re.search(r'this\._colorIndex\s*=\s*0\s*;', lines[i-1]): | |
| break | |
| line = lines.pop(idx) | |
| lines.insert(i, line) | |
| changed = True | |
| print(f"✅ Moved _colorIndex init before Window_Base.initialize.call in {jsfile} at line {i+1}") | |
| break | |
| i += 1 | |
| if changed: | |
| backup_file(jsfile) | |
| with open(jsfile, 'w', encoding='utf-8') as f: | |
| f.writelines(lines) | |
| def remove_pixi_sourcemap(jsfile): | |
| try: | |
| with open(jsfile, 'r', encoding='utf-8') as f: | |
| content = f.read() | |
| new_content, count = re.subn(r'\/\/# sourceMappingURL=pixi\.js\.map\s*\n?', '', content) | |
| if count: | |
| print(f"✅ Removed pixi.js.map sourcemap comment in {jsfile}") | |
| backup_file(jsfile) | |
| with open(jsfile, 'w', encoding='utf-8') as f: | |
| f.write(new_content) | |
| except Exception as e: | |
| print(f"⚠️ 處理 {jsfile} 失敗: {e}") | |
| def set_name_to_www(pkgfile): | |
| try: | |
| with open(pkgfile, 'r', encoding='utf-8') as f: | |
| data = json.load(f) | |
| if data.get('name') == '': | |
| backup_file(pkgfile) | |
| data['name'] = 'www' | |
| with open(pkgfile, 'w', encoding='utf-8') as f: | |
| json.dump(data, f, ensure_ascii=False, indent=2) | |
| print(f"✅ 將 package.json 的 name 設為 'www':{pkgfile}") | |
| except Exception as e: | |
| print(f"⚠️ 處理 {pkgfile} 失敗: {e}") | |
| def main(): | |
| parser = argparse.ArgumentParser(description="精準修正 RPG Maker 常見 bug 腳本。") | |
| parser.add_argument('project_path', help="RPG Maker 專案根目錄(含 www)") | |
| args = parser.parse_args() | |
| proj = os.path.abspath(args.project_path) | |
| print(f"🔍 正在處理專案: {proj}") | |
| try: | |
| os.system(f"dot_clean '{proj}'") | |
| except Exception as e: | |
| print(f"⚠️ 執行 dot_clean 失敗: {e}") | |
| # set package.json name to 'www' | |
| pkgfile = os.path.join(proj, 'package.json') | |
| if os.path.exists(pkgfile): | |
| set_name_to_www(pkgfile) | |
| else: | |
| print("ℹ️ 未找到 package.json,略過。") | |
| # if there is www folder, use it | |
| www = os.path.join(proj, 'www') | |
| if os.path.exists(www): | |
| proj = www | |
| # plugins.js | |
| plugins_file = os.path.join(proj, 'js', 'plugins.js') | |
| if os.path.exists(plugins_file): | |
| fix_plugins_js(plugins_file) | |
| else: | |
| print("ℹ️ 未找到 js/plugins.js,略過。") | |
| # fix_color_index | |
| ex_file = os.path.join(proj, 'js', 'plugins', 'MPP_MessageEX.js') | |
| if os.path.exists(ex_file): | |
| fix_color_index(ex_file) | |
| else: | |
| print("ℹ️ 未找到 MPP_MessageEX.js,略過。") | |
| # remove pixi sourcemap | |
| pixi_file = os.path.join(proj, 'js', 'libs', 'pixi.js') | |
| if os.path.exists(pixi_file): | |
| remove_pixi_sourcemap(pixi_file) | |
| else: | |
| print("ℹ️ 未找到 pixi.js,略過。") | |
| # remove achievement calls (data 資料夾下所有 .json) | |
| data_dir = os.path.join(proj, 'data') | |
| if os.path.exists(data_dir): | |
| for fn in os.listdir(data_dir): | |
| if fn.startswith('._') or not fn.endswith('.json'): | |
| continue | |
| jsonfile = os.path.join(data_dir, fn) | |
| remove_achievement_calls_json(jsonfile) | |
| else: | |
| print("ℹ️ 未找到 data 資料夾,略過。") | |
| print("全部指定修正項目處理完畢。") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment