#!/usr/bin/env python3 import re from pathlib import Path root = Path(__file__).resolve().parents[1] app_cpp = root / "upstream/ava2-client/UserInterface/PythonApplicationModule.cpp" with open(app_cpp, "r", encoding="latin1") as f: content = f.read() initapp_idx = content.find("void initapp()") if initapp_idx == -1: raise RuntimeError("initapp() not found") initapp_body = content[initapp_idx:] cursor_map = { "CPythonApplication::CURSOR_SHAPE_NORMAL": "0", "CPythonApplication::CURSOR_SHAPE_ATTACK": "1", "CPythonApplication::CURSOR_SHAPE_TARGET": "2", "CPythonApplication::CURSOR_SHAPE_TALK": "3", "CPythonApplication::CURSOR_SHAPE_CANT_GO": "4", "CPythonApplication::CURSOR_SHAPE_PICK": "5", "CPythonApplication::CURSOR_SHAPE_DOOR": "6", "CPythonApplication::CURSOR_SHAPE_CHAIR": "7", "CPythonApplication::CURSOR_SHAPE_MAGIC": "8", "CPythonApplication::CURSOR_SHAPE_BUY": "9", "CPythonApplication::CURSOR_SHAPE_SELL": "10", "CPythonApplication::CURSOR_SHAPE_CAMERA_ROTATE": "11", "CPythonApplication::CURSOR_SHAPE_HSIZE": "12", "CPythonApplication::CURSOR_SHAPE_VSIZE": "13", "CPythonApplication::CURSOR_SHAPE_HVSIZE": "14", "CPythonApplication::CURSOR_SHAPE_FISH": "15", "CPythonApplication::CURSOR_SHAPE_COUNT": "16", "CPythonApplication::CAMERA_TO_POSITIVE": "1", "CPythonApplication::CAMERA_TO_NEGITIVE": "-1", "CPythonApplication::CAMERA_STOP": "0", "CPythonApplication::INFO_ITEM": "0", "CPythonApplication::INFO_ACTOR": "1", "CPythonApplication::INFO_EFFECT": "2", "CPythonApplication::INFO_TEXTTAIL": "3", "CPythonApplication::LOCALE_DEFAULT": "0", "CPythonApplication::LOCALE_EN": "0", "CPythonApplication::LOCALE_DE": "1", "CPythonApplication::LOCALE_TR": "2", "CPythonApplication::LOCALE_PT": "3", "CPythonApplication::LOCALE_ES": "4", "CPythonApplication::LOCALE_FR": "5", "CPythonApplication::LOCALE_RO": "6", "CPythonApplication::LOCALE_PL": "7", "CPythonApplication::LOCALE_IT": "8", "CPythonApplication::LOCALE_CZ": "9", "CPythonApplication::LOCALE_HU": "10", "CPythonApplication::LOCALE_MAX_NUM": "11", "PLAYER_PER_ACCOUNT5": "5", "PLAYER_PER_ACCOUNT4": "4", "DEGREE_DIRECTION_SAME": "0", "DEGREE_DIRECTION_RIGHT": "1", "DEGREE_DIRECTION_LEFT": "2", "VK_LEFT": "0x25", "VK_UP": "0x26", "VK_RIGHT": "0x27", "VK_DOWN": "0x28", "VK_HOME": "0x24", "VK_END": "0x23", "VK_DELETE": "0x2E", } extra_diks = { "DIK_NEXTTRACK": "0x99", "DIK_MUTE": "0xA0", "DIK_CALCULATOR": "0xA1", "DIK_PLAYPAUSE": "0xA2", "DIK_MEDIASTOP": "0xA4", "DIK_VOLUMEDOWN": "0xAE", "DIK_VOLUMEUP": "0xB0", "DIK_WEBHOME": "0xB2", "DIK_NUMPADCOMMA": "0xB3", "DIK_LWIN": "0xDB", "DIK_RWIN": "0xDC", "DIK_APPS": "0xDD", "DIK_KANJI": "0x94", "DIK_AX": "0x96", "DIK_UNLABELED": "0x97", "DIK_ABNT_C2": "0x7E", "DIK_PREVTRACK": "0x90", "DIK_YEN": "0x7D", } output_lines = [] for line in initapp_body.splitlines(): stripped = line.strip() if stripped.startswith("#if") or stripped.startswith("#else") or stripped.startswith("#endif"): output_lines.append(stripped) elif "PyModule_AddIntConstant" in stripped: subbed = re.sub(r'PyModule_AddIntConstant\s*\(\s*\w+\s*,', 'PyModule_AddIntConstant(module,', stripped) for k, v in cursor_map.items(): subbed = subbed.replace(k, v) for k, v in extra_diks.items(): subbed = re.sub(r'\b' + k + r'\b', v, subbed) output_lines.append(" " + subbed) header = """// Auto-generated AVA2 app constants from upstream PythonApplicationModule.cpp // 1:1 strictly matched to AVA2 definition. #pragma once #include #include "../upstream/ava2-client/UserInterface/Locale_inc.h" #ifndef DIK_ESCAPE #define DIK_ESCAPE 0x01 #define DIK_1 0x02 #define DIK_2 0x03 #define DIK_3 0x04 #define DIK_4 0x05 #define DIK_5 0x06 #define DIK_6 0x07 #define DIK_7 0x08 #define DIK_8 0x09 #define DIK_9 0x0A #define DIK_0 0x0B #define DIK_MINUS 0x0C #define DIK_EQUALS 0x0D #define DIK_BACK 0x0E #define DIK_TAB 0x0F #define DIK_Q 0x10 #define DIK_W 0x11 #define DIK_E 0x12 #define DIK_R 0x13 #define DIK_T 0x14 #define DIK_Y 0x15 #define DIK_U 0x16 #define DIK_I 0x17 #define DIK_O 0x18 #define DIK_P 0x19 #define DIK_LBRACKET 0x1A #define DIK_RBRACKET 0x1B #define DIK_RETURN 0x1C #define DIK_LCONTROL 0x1D #define DIK_A 0x1E #define DIK_S 0x1F #define DIK_D 0x20 #define DIK_F 0x21 #define DIK_G 0x22 #define DIK_H 0x23 #define DIK_J 0x24 #define DIK_K 0x25 #define DIK_L 0x26 #define DIK_SEMICOLON 0x27 #define DIK_APOSTROPHE 0x28 #define DIK_GRAVE 0x29 #define DIK_LSHIFT 0x2A #define DIK_BACKSLASH 0x2B #define DIK_Z 0x2C #define DIK_X 0x2D #define DIK_C 0x2E #define DIK_V 0x2F #define DIK_B 0x30 #define DIK_N 0x31 #define DIK_M 0x32 #define DIK_COMMA 0x33 #define DIK_PERIOD 0x34 #define DIK_SLASH 0x35 #define DIK_RSHIFT 0x36 #define DIK_MULTIPLY 0x37 #define DIK_LMENU 0x38 #define DIK_SPACE 0x39 #define DIK_CAPITAL 0x3A #define DIK_F1 0x3B #define DIK_F2 0x3C #define DIK_F3 0x3D #define DIK_F4 0x3E #define DIK_F5 0x3F #define DIK_F6 0x40 #define DIK_F7 0x41 #define DIK_F8 0x42 #define DIK_F9 0x43 #define DIK_F10 0x44 #define DIK_NUMLOCK 0x45 #define DIK_SCROLL 0x46 #define DIK_NUMPAD7 0x47 #define DIK_NUMPAD8 0x48 #define DIK_NUMPAD9 0x49 #define DIK_SUBTRACT 0x4A #define DIK_NUMPAD4 0x4B #define DIK_NUMPAD5 0x4C #define DIK_NUMPAD6 0x4D #define DIK_ADD 0x4E #define DIK_NUMPAD1 0x4F #define DIK_NUMPAD2 0x50 #define DIK_NUMPAD3 0x51 #define DIK_NUMPAD0 0x52 #define DIK_DECIMAL 0x53 #define DIK_F11 0x57 #define DIK_F12 0x58 #define DIK_NUMPADENTER 0x9C #define DIK_RCONTROL 0x9D #define DIK_DIVIDE 0xB5 #define DIK_SYSRQ 0xB7 #define DIK_RMENU 0xB8 #define DIK_PAUSE 0xC5 #define DIK_HOME 0xC7 #define DIK_UP 0xC8 #define DIK_PRIOR 0xC9 #define DIK_LEFT 0xCB #define DIK_RIGHT 0xCD #define DIK_END 0xCF #define DIK_DOWN 0xD0 #define DIK_NEXT 0xD1 #define DIK_INSERT 0xD2 #define DIK_DELETE 0xD3 #endif namespace ava2 { inline void register_app_constants(PyObject* module) { """ footer = """ } } """ out_file = root / "src/generated_app_constants.h" out_file.write_text(header + "\n".join(output_lines) + footer) print(f"Generated {out_file} with {len(output_lines)} lines.")