├── cot-logo.png ├── bin └── armips │ ├── armips-mac-x64 │ ├── armips-mac-arm64 │ ├── armips-win-x64.exe │ └── LICENSE.txt ├── .gitmodules ├── .gitignore ├── include ├── cot.h └── cot │ ├── basedefs.h │ ├── effects.h │ ├── custom_instructions.h │ ├── logging.h │ └── menus.h ├── patches ├── patch.asm └── internal.asm ├── src ├── main.c ├── special_processes.c ├── item_effects.c ├── move_effects.c ├── cot │ ├── effects.c │ ├── trampolines.s │ ├── instruction_hooks.c │ └── menu_hooks.c ├── ground_instructions.c └── menus.c ├── symbols ├── custom_EU.ld ├── custom_JP.ld └── custom_NA.ld ├── LICENSE_MIT ├── linker.ld ├── scripts ├── generate_linkerscript.py └── patch.py ├── install_linux.md ├── install_windows.md ├── install_macos.md ├── Makefile ├── README.md └── LICENSE_GPLv3 /cot-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkyTemple/c-of-time/HEAD/cot-logo.png -------------------------------------------------------------------------------- /bin/armips/armips-mac-x64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkyTemple/c-of-time/HEAD/bin/armips/armips-mac-x64 -------------------------------------------------------------------------------- /bin/armips/armips-mac-arm64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkyTemple/c-of-time/HEAD/bin/armips/armips-mac-arm64 -------------------------------------------------------------------------------- /bin/armips/armips-win-x64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkyTemple/c-of-time/HEAD/bin/armips/armips-win-x64.exe -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "pmdsky-debug"] 2 | path = pmdsky-debug 3 | url = https://github.com/UsernameFodder/pmdsky-debug 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /venv 3 | 4 | out.bin 5 | out.elf 6 | out.asm 7 | 8 | *.nds 9 | *.nds.skytemple 10 | 11 | symbols/generated_*.ld 12 | -------------------------------------------------------------------------------- /include/cot.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | -------------------------------------------------------------------------------- /include/cot/basedefs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Allow using the "true" and "false" keywords 4 | #define false 0 5 | #define true 1 6 | 7 | #define NULL 0 8 | 9 | #define ARRAY_LENGTH(array) (sizeof((array))/sizeof((array)[0])) 10 | -------------------------------------------------------------------------------- /patches/patch.asm: -------------------------------------------------------------------------------- 1 | // Replace the "GetMovePower" function with a custom one. 2 | // Since a branch is inserted at the start of the function, the function is practically 3 | // replaced with our own. The "b" instruction doesn't modify the link register, so 4 | // execution will continue after the call to `GetMovePower` once our function returns. 5 | 6 | .nds 7 | .include "symbols.asm" 8 | 9 | .open "overlay29.bin", overlay29_start 10 | .org GetMovePower 11 | // Remove the comment below to enable this example 12 | // b CustomGetMovePower 13 | .close 14 | -------------------------------------------------------------------------------- /include/cot/effects.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef struct move_effect_input { 4 | int move_id; 5 | int item_id; 6 | bool out_dealt_damage; 7 | } move_effect_input; 8 | 9 | // Custom effects handling functions. 10 | bool CustomApplyItemEffect(struct entity* user, struct entity* target, struct item* item, bool is_thrown); 11 | bool CustomApplyMoveEffect(move_effect_input* data, struct entity* user, struct entity* target, struct move* move); 12 | bool CustomScriptSpecialProcessCall(undefined4* unknown, uint32_t special_process_id, short arg1, short arg2, int* return_val); 13 | -------------------------------------------------------------------------------- /include/cot/custom_instructions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "basedefs.h" 4 | #include 5 | 6 | // Set this value to 1 to enable support for custom script engine instructions 7 | #define CUSTOM_GROUND_INSTRUCTIONS 0 8 | 9 | struct custom_instruction { 10 | int8_t n_params; 11 | void (*handler)(struct script_routine* routine, uint16_t* args); 12 | char *name; 13 | }; 14 | 15 | void DispatchCustomInstruction(int index, struct script_routine* routine, uint16_t* args); 16 | extern struct custom_instruction CUSTOM_INSTRUCTIONS[]; 17 | extern const int CUSTOM_INSTRUCTION_AMOUNT; 18 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Remove the comment in patches/patch.asm to enable this example patch. 5 | // `attribute((used))` is required to prevent the compiler from optimizing out the function 6 | // if it's only used in a patch. 7 | __attribute__((used)) int CustomGetMovePower(struct entity* entity, struct move* move) { 8 | // Randomize move power 9 | int rolledPower = RandRange(1, 100); 10 | 11 | // Print the rolled value to the message log 12 | char messageBuffer[32]; 13 | snprintf(messageBuffer, 32, "Rolled move power %d!", rolledPower); 14 | 15 | LogMessage(entity, messageBuffer, true); 16 | 17 | return rolledPower; 18 | } 19 | 20 | // You can add other patches here... 21 | -------------------------------------------------------------------------------- /symbols/custom_EU.ld: -------------------------------------------------------------------------------- 1 | /* !file overlay11 */ 2 | OpcodeCheck = 0x022DE714; 3 | GetParameterCount = 0x022DE6CC; 4 | ScriptEngineReturnTwo = 0x022E2DAC; 5 | ScriptMenuRequestDefaultCase = 0x022E6A30; 6 | ScriptMenuRequestFinalize = 0x022E71EC; 7 | ScriptMenuUpdateDefaultCase = 0x022E7238; 8 | ScriptMenuUpdateFinalize = 0x022E7798; 9 | IS_BASE_GAME_MENU_FINISHED = 0x023257DC; 10 | 11 | /* !file overlay29 */ 12 | ApplyMoveEffect = 0x0232F2A4; 13 | ApplyMoveEffectHookAddr = 0x023302E4; 14 | ApplyMoveEffectJumpAddr = 0x0233310C; 15 | ApplyItemEffectHookAddr = 0x0231C438; 16 | ApplyItemEffectJumpAddr = 0x0231D574; 17 | 18 | /* Add your own symbols here... */ 19 | 20 | /* !file arm9 */ 21 | ShowKeyboardTypeCase3 = 0x02036C10; 22 | ShowKeyboardTypeDefaultCase = 0x02036D3C; 23 | ShowKeyboardReturn = 0x02036FA8; 24 | PreprocessStringFromIdCallsite = 0x020396FC; 25 | -------------------------------------------------------------------------------- /symbols/custom_JP.ld: -------------------------------------------------------------------------------- 1 | /* !file overlay11 */ 2 | OpcodeCheck = 0x022DF474; 3 | GetParameterCount = 0x022DF42C; 4 | ScriptEngineReturnTwo = 0x022E3A98; 5 | ScriptMenuRequestDefaultCase = 0x022E771C; 6 | ScriptMenuRequestFinalize = 0x022E7ED8; 7 | ScriptMenuUpdateDefaultCase = 0x022E7F24; 8 | ScriptMenuUpdateFinalize = 0x022E8484; 9 | IS_BASE_GAME_MENU_FINISHED = 0x023261FC; 10 | 11 | /* !file overlay29 */ 12 | ApplyMoveEffect = 0x0232FC60; 13 | ApplyMoveEffectHookAddr = 0x02330C98; 14 | ApplyMoveEffectJumpAddr = 0x02333AC0; 15 | ApplyItemEffectHookAddr = 0x0231CEA4; 16 | ApplyItemEffectJumpAddr = 0x0231DFE0; 17 | 18 | /* Add your own symbols here... */ 19 | 20 | /* !file arm9 */ 21 | ShowKeyboardTypeCase3 = 0x02036C34; 22 | ShowKeyboardTypeDefaultCase = 0x02036D54; 23 | ShowKeyboardReturn = 0x02036FC0; 24 | PreprocessStringFromIdCallsite = 0x02039804; 25 | -------------------------------------------------------------------------------- /symbols/custom_NA.ld: -------------------------------------------------------------------------------- 1 | /* !file overlay11 */ 2 | OpcodeCheck = 0x022DDDD4; 3 | GetParameterCount = 0x022DDD8C; 4 | ScriptEngineReturnTwo = 0x022E246C; 5 | ScriptMenuRequestDefaultCase = 0x022E60F0; 6 | ScriptMenuRequestFinalize = 0x022E68AC; 7 | ScriptMenuUpdateDefaultCase = 0x022E68F8; 8 | ScriptMenuUpdateFinalize = 0x022E6E58; 9 | IS_BASE_GAME_MENU_FINISHED = 0x02324C9C; 10 | 11 | /* !file overlay29 */ 12 | ApplyMoveEffect = 0x0232E864; 13 | ApplyMoveEffectHookAddr = 0x0232F8A4; 14 | ApplyMoveEffectJumpAddr = 0x023326CC; 15 | ApplyItemEffectHookAddr = 0x0231B9D8; 16 | ApplyItemEffectJumpAddr = 0x0231CB14; 17 | 18 | /* Add your own symbols here... */ 19 | 20 | /* !file arm9 */ 21 | ShowKeyboardTypeCase3 = 0x02036914; 22 | ShowKeyboardTypeDefaultCase = 0x02036A40; 23 | ShowKeyboardReturn = 0x02036CAC; 24 | PreprocessStringFromIdCallsite = 0x02039400; 25 | -------------------------------------------------------------------------------- /src/special_processes.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Special process 100: Change border color 5 | // Based on https://github.com/SkyTemple/eos-move-effects/blob/master/example/process/set_frame_color.asm 6 | static int SpChangeBorderColor(short arg1) { 7 | SetBothScreensWindowsColor(arg1); 8 | return 0; 9 | } 10 | 11 | // Called for special process IDs 100 and greater. 12 | // 13 | // Set return_val to the return value that should be passed back to the game's script engine. Return true, 14 | // if the special process was handled. 15 | bool CustomScriptSpecialProcessCall(undefined4* unknown, uint32_t special_process_id, short arg1, short arg2, int* return_val) { 16 | switch (special_process_id) { 17 | case 100: 18 | *return_val = SpChangeBorderColor(arg1); 19 | return true; 20 | 21 | // Add your own SP's here... 22 | 23 | default: 24 | return false; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /LICENSE_MIT: -------------------------------------------------------------------------------- 1 | Copyright 2022 techticks 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /src/item_effects.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Elixir: Refills 10 PP of each move 5 | static void ItemElixir(struct entity* target) { 6 | if (target->type == ENTITY_MONSTER) { 7 | struct monster* target_monster = (struct monster*) target->info; 8 | for (int i = 0; i < 4; i++) { 9 | struct move* current_move = &target_monster->moves[i]; 10 | uint8_t max_pp = GetMaxPp(current_move); 11 | int new_pp = current_move->pp + 10; 12 | if (new_pp > max_pp) { 13 | new_pp = max_pp; 14 | } 15 | current_move->pp = new_pp; 16 | } 17 | } 18 | } 19 | 20 | // Called when using items. Should return true if a custom effect was applied. 21 | bool CustomApplyItemEffect( 22 | struct entity* user, struct entity* target, struct item* item, bool is_thrown 23 | ) { 24 | switch (item->id.val) { 25 | case ITEM_MAX_ELIXIR: 26 | // Replace item 99 (Max Elixir) with custom Elixir effect 27 | ItemElixir(target); 28 | // Return true to signal that we've handled the effect 29 | return true; 30 | default: 31 | return false; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /bin/armips/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2009-2014 Kingcom 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /patches/internal.asm: -------------------------------------------------------------------------------- 1 | .nds 2 | .include "symbols.asm" 3 | 4 | .open "arm9.bin", arm9_start 5 | .ifdef HookScriptMenuRequestCheck 6 | .org ShowKeyboard 7 | push {r3-r8,lr} 8 | bl HookKeyboardCheck 9 | 10 | .org ShowKeyboardTypeCase3 11 | b HookKeyboardCustomPrompt 12 | 13 | .org ShowKeyboardReturn 14 | pop {r3-r8,pc} 15 | 16 | .org PreprocessStringFromIdCallsite 17 | bl CustomPreprocessStringFromId 18 | .endif 19 | .close 20 | 21 | .open "overlay11.bin", overlay11_start 22 | .org ScriptSpecialProcessCall 23 | b cotInternalTrampolineScriptSpecialProcessCall 24 | 25 | .ifdef HookScriptMenuRequestCheck 26 | .org ScriptMenuRequestDefaultCase 27 | b HookScriptMenuRequestCheck 28 | 29 | .org ScriptMenuUpdateDefaultCase 30 | b HookScriptMenuUpdateCheck 31 | .endif 32 | 33 | .ifdef HookOpcodeCheck 34 | .org OpcodeCheck 35 | b HookOpcodeCheck 36 | 37 | .org GetParameterCount 38 | bl HookGetParameterCount 39 | .endif 40 | .close 41 | 42 | .open "overlay29.bin", overlay29_start 43 | .org ApplyItemEffectHookAddr 44 | b cotInternalTrampolineApplyItemEffect 45 | .org ApplyMoveEffectHookAddr 46 | b cotInternalTrampolineApplyMoveEffect 47 | .close 48 | -------------------------------------------------------------------------------- /src/move_effects.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Implements the "Body Press" move 5 | // Based on https://github.com/Adex-8x/EoS-ASM-Effects/blob/main/moves/gen8/body_press.asm 6 | // Deals damage based on the user's defense instead of attack stat 7 | static bool MoveBodyPress(struct entity *user, struct entity *target, struct move *move) 8 | { 9 | if (user->type == ENTITY_MONSTER) 10 | { 11 | struct monster *user_monster = (struct monster *)user->info; 12 | 13 | int old_attack = user_monster->offensive_stats[0]; 14 | user_monster->offensive_stats[0] = user_monster->defensive_stats[0]; 15 | 16 | bool dealt_damage = DealDamage(user, target, move, 0x100, ITEM_NOTHING); 17 | 18 | user_monster->offensive_stats[0] = old_attack; 19 | return dealt_damage; 20 | } 21 | return false; 22 | } 23 | 24 | // Called when using moves. Should return true if a custom effect was applied. 25 | // This function is only called if the move doesn't fail due to a missing target 26 | bool CustomApplyMoveEffect( 27 | move_effect_input *data, struct entity *user, struct entity *target, struct move *move) 28 | { 29 | switch (data->move_id) 30 | { 31 | case MOVE_SCRATCH: 32 | // Replace move 260 (Scratch) with custom Body Press effect 33 | data->out_dealt_damage = MoveBodyPress(user, target, move); 34 | // Return true to signal that we've handled the effect 35 | return true; 36 | default: 37 | return false; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/cot/effects.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Internal dispatch code for item and move effects and special processes to C and Rust. 5 | // These functions are called in trampolines.s. 6 | 7 | bool cotInternalDispatchApplyItemEffect( 8 | struct entity* user, struct entity* target, struct item* item, bool is_thrown 9 | ) { 10 | COT_LOGFMT(COT_LOG_CAT_EFFECTS, "Running item effect %d", item->id.val); 11 | 12 | return CustomApplyItemEffect(user, target, item, is_thrown); 13 | } 14 | 15 | bool cotInternalDispatchApplyMoveEffect( 16 | move_effect_input* data, struct entity* user, struct entity* target, struct move* move 17 | ) { 18 | COT_LOGFMT(COT_LOG_CAT_EFFECTS, "Running move effect %d", data->move_id); 19 | 20 | return CustomApplyMoveEffect(data, user, target, move); 21 | } 22 | 23 | int cotInternalDispatchScriptSpecialProcessCall( 24 | undefined4* unknown, uint32_t special_process_id, short arg1, short arg2 25 | ) { 26 | // TODO: arg2 doesn't seem to match the argument in the script engine? 27 | COT_LOGFMT(COT_LOG_CAT_SPECIAL_PROCESS, "Running special process %d (arg1=%d, arg2=%d)", 28 | special_process_id, arg1, arg2); 29 | 30 | int return_val = 0; 31 | bool handled = CustomScriptSpecialProcessCall(unknown, special_process_id, arg1, arg2, &return_val); 32 | if (!handled) { 33 | // Log a warning that the special processed went unhandled. 34 | COT_WARNFMT(COT_LOG_CAT_SPECIAL_PROCESS, "Unhandled special process ID %d", special_process_id); 35 | } 36 | return return_val; 37 | } 38 | -------------------------------------------------------------------------------- /include/cot/logging.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define COT_LOG_CAT_DEFAULT "cot" 4 | #define COT_LOG_CAT_SPECIAL_PROCESS "cot.special_process" 5 | #define COT_LOG_CAT_EFFECTS "cot.effects" 6 | #define COT_LOG_CAT_INSTRUCTIONS "cot.ground_instructions" 7 | #define COT_LOG_CAT_MENUS "cot.script_menus" 8 | 9 | // Needs two macros for some reason 10 | #define _COT_INTERNAL_STRINGIZE_DETAIL(x) #x 11 | #define _COT_INTERNAL_STRINGIZE(x) _COT_INTERNAL_STRINGIZE_DETAIL(x) 12 | 13 | #ifndef NDEBUG 14 | 15 | #define _COT_INTERNAL_LOG_MESSAGE(category, format) \ 16 | "[" category "] " format " (" __FILE__ ":" _COT_INTERNAL_STRINGIZE(__LINE__) ")" 17 | 18 | #define COT_LOG(category, format) DebugPrint(0, _COT_INTERNAL_LOG_MESSAGE(category, format)) 19 | #define COT_WARN(category, format) DebugPrint(1, _COT_INTERNAL_LOG_MESSAGE(category, format)) 20 | #define COT_ERROR(category, format) DebugPrint(2, _COT_INTERNAL_LOG_MESSAGE(category, format)) 21 | 22 | #define COT_LOGFMT(category, format, ...) DebugPrint(0, _COT_INTERNAL_LOG_MESSAGE(category, format), __VA_ARGS__) 23 | #define COT_WARNFMT(category, format, ...) DebugPrint(1, _COT_INTERNAL_LOG_MESSAGE(category, format), __VA_ARGS__) 24 | #define COT_ERRORFMT(category, format, ...) DebugPrint(2, _COT_INTERNAL_LOG_MESSAGE(category, format), __VA_ARGS__) 25 | 26 | #define COT_ASSERT(expr) \ 27 | if (!(expr)) {\ 28 | DebugPrint(2, "ASSERTION FAILED: " #expr " (" __FILE__ ":" _COT_INTERNAL_STRINGIZE(__LINE__) ")"); \ 29 | WaitForever(); \ 30 | } 31 | 32 | #else 33 | 34 | #define COT_LOG(category, format, ...) 35 | #define COT_WARN(category, format, ...) 36 | #define COT_ERROR(category, format, ...) 37 | 38 | #define COT_LOGFMT(category, format, ...) 39 | #define COT_WARNFMT(category, format, ...) 40 | #define COT_ERRORFMT(category, format, ...) 41 | 42 | #define COT_ASSERT(expr) 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /include/cot/menus.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "basedefs.h" 4 | #include 5 | 6 | // Set this value to 1 to enable support for custom script engine menus 7 | #define CUSTOM_SCRIPT_MENUS 0 8 | 9 | struct custom_menu { 10 | uint16_t keyboard_prompt_string_id; // The string used for the first keyboard menu prompt, e.g., "What is your partner's nickname?" 11 | uint16_t keyboard_confirm_string_id; // The string used for the final Yes/No confirmation prompt upon inputting a string, e.g., "Is the name [string0] OK?" 12 | void (*create)(); // Called only once; initializes the script menu. 13 | void (*close)(); // Called only once, when the update function returns true. 14 | bool (*update)(); // Called every frame while the script menu is active. Returns true if the script menu should close. 15 | }; 16 | 17 | struct global_menu_info { 18 | int id; // ID of the current custom script menu active! 19 | int state; // To track script menu progress! 20 | int return_val; // Value ultimately returned by message_Menu in a script! 21 | int previous_option; // Indicates the last option that was hovered over in a menu. A prime use case is changing another window based on if the player changes the option they're hovering the cursor on. 22 | struct portrait_params portrait_params; // Global portrait params to easily reference for portrait functions! 23 | int menu_results[20]; // To store previous results of menus across update calls! 24 | int window_ids[20]; // Maximum number of windows that can be active at a time. 25 | // Can add more fields here as necessary to use for custom script menus! 26 | }; 27 | 28 | void InitializeCustomScriptMenu(int index); 29 | bool DispatchCustomScriptMenu(int index, int* return_val); 30 | extern struct custom_menu CUSTOM_MENUS[]; 31 | extern struct global_menu_info GLOBAL_MENU_INFO; 32 | extern const int CUSTOM_MENU_AMOUNT; 33 | extern bool IS_BASE_GAME_MENU_FINISHED; 34 | -------------------------------------------------------------------------------- /linker.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_ARCH(arm) 2 | MEMORY { 3 | /* 4 | Overlay load address + offset to common area 5 | see https://docs.google.com/document/d/1Rs4icdYtiM6KYnWxMkdlw7jpWrH7qw5v6LOfDWIiYho 6 | */ 7 | main : ORIGIN = 0x23D7FF0, LENGTH = 0x8010 8 | /* Change/Add memory locations here */ 9 | /* NEW : ORIGIN = 0x2000000, LENGTH = 0x800 */ 10 | } 11 | 12 | SECTIONS { 13 | /* 14 | Add more sections for the linker, each section using a different memory location 15 | This allows to spread your code on different overlays 16 | You can change the section of one symbol (function or variable) in your C code using: __attribute__((section(".YOURSECTIONNAME"))) 17 | Note that section names are standardized and in the form ".text.OV.NB.SPECIAL" 18 | Where OV is between 'ov' (ARM9 Overlay) and 'arm' (Main ARM Binary) 19 | NB is the OV number (7 or 9 for 'arm', any ARM9 Overlay number for 'ov') 20 | SPECIAL is a distinct name, this is only to distinguish between 2 sections on the same overlay 21 | */ 22 | /*.text.OV.NB.SPECIAL : { 23 | *(.YOURSECTIONNAME) 24 | } >NEW = 0xff*/ 25 | /* 26 | Main Section (Default section, in ARM9 overlay 36) 27 | Note that you should add your special sections before that 28 | */ 29 | .text.ov.36.main : { 30 | *(.init) 31 | *(.text) 32 | *(.text.*) 33 | *(.fini) 34 | *(.ctors) 35 | *(.dtors) 36 | *(.rodata) 37 | *(.rodata.*) 38 | *(.data) 39 | *(.data.*) 40 | *(COMMON) 41 | . = ALIGN(4); 42 | *(.bss) 43 | } >main = 0xff 44 | } 45 | -------------------------------------------------------------------------------- /src/cot/trampolines.s: -------------------------------------------------------------------------------- 1 | .align 4 2 | cotInternalTrampolineScriptSpecialProcessCall: 3 | // If the special process ID is >= 100, handle it as a custom special process 4 | cmp r1, #100 5 | bge cotInternalDispatchScriptSpecialProcessCall 6 | 7 | // Otherwise, restore the instruction we've replaced in the patch 8 | // and run the original function 9 | push {r3, r4, r5, r6, r7, r8, r9, sl, fp, lr} 10 | b ScriptSpecialProcessCall+4 11 | 12 | .align 4 13 | cotInternalTrampolineApplyItemEffect: 14 | // Backup registers 15 | push {r0-r9, r11, r12} 16 | 17 | // Call the hook function 18 | mov r0, r8 19 | mov r1, r7 20 | mov r2, r6 21 | mov r3, r9 22 | bl cotInternalDispatchApplyItemEffect 23 | // Check if true was returned 24 | cmp r0, #1 25 | 26 | // Load saved registers 27 | popeq {r0-r9, r11, r12} 28 | 29 | // If yes, exit the original function 30 | beq ApplyItemEffectJumpAddr 31 | 32 | pop {r0-r9, r11, r12} 33 | 34 | // Restore the instruction that was replaced with the patch and call the original function 35 | cmp r0, #0 36 | b ApplyItemEffectHookAddr+4 37 | 38 | .align 4 39 | cotInternalTrampolineApplyMoveEffect: 40 | // Backup registers 41 | push {r0-r9, r11, r12} 42 | 43 | // Setup move_effect_input struct 44 | ldr r10, =move_effect_input 45 | str r6, [r10] // move_id 46 | str r7, [r10, #0x4] // item_id 47 | mov r0, #0 48 | str r0, [r10, #0x8] // out_dealt_damage 49 | 50 | // Call the hook function 51 | mov r0, r10 52 | mov r1, r9 53 | mov r2, r4 54 | mov r3, r8 55 | bl cotInternalDispatchApplyMoveEffect 56 | 57 | // Check if true was returned 58 | cmp r0, #1 59 | 60 | // Load saved registers 61 | popeq {r0-r9, r11, r12} 62 | ldreq r10, =move_effect_input_out_dealt_damage 63 | 64 | // If yes, exit the original function 65 | beq ApplyMoveEffectJumpAddr 66 | 67 | pop {r0-r9, r11, r12} 68 | 69 | // Restore the instruction that was replaced with the patch and call the original function 70 | mov r1, #0x1 71 | b ApplyMoveEffectHookAddr+4 72 | 73 | .align 4 74 | move_effect_input: 75 | .word 0 76 | .word 0 77 | move_effect_input_out_dealt_damage: 78 | .word 0 79 | -------------------------------------------------------------------------------- /src/cot/instruction_hooks.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | // Loosely based on https://github.com/Adex-8x/jam-patches/blob/master/strung-up-by-sketches/CustomOpcodes/asm_patches/patch_ov36.asm#L137 7 | 8 | #if CUSTOM_GROUND_INSTRUCTIONS 9 | 10 | // const instead of #define so the constant can be referenced in Assembly 11 | __attribute((used)) const int FIRST_CUSTOM_OPCODE = 0x1000; 12 | 13 | __attribute((naked)) void HookOpcodeCheck(void) { 14 | asm volatile("cmp r5,r7"); 15 | asm volatile("bge NewInstructions"); 16 | asm volatile("cmp r5,r0"); 17 | asm volatile("b OpcodeCheck+4"); 18 | } 19 | 20 | __attribute((naked)) void NewInstructions(void) { 21 | asm volatile("sub r5,r5,r7"); 22 | 23 | asm volatile("mov r0,r5"); // Opcode (offset from FIRST_CUSTOM_OPCODE) 24 | asm volatile("mov r1,r4"); // Current script routine pointer 25 | asm volatile("mov r2,r6"); // Argument list 26 | asm volatile("bl DispatchCustomInstruction"); 27 | 28 | asm volatile("b ScriptEngineReturnTwo"); 29 | } 30 | 31 | __attribute((naked)) void HookGetParameterCount(void) { 32 | asm volatile("ldr r7,=FIRST_CUSTOM_OPCODE"); 33 | asm volatile("ldr r7,[r7]"); 34 | asm volatile("cmp r5,r7"); 35 | asm volatile("ldrge r0,=CUSTOM_INSTRUCTIONS"); 36 | asm volatile("subge r1,r5,r7"); 37 | asm volatile("ldrge r8,=12"); // Struct size 38 | asm volatile("mulge r8,r1,r8"); // Scale index by struct size 39 | asm volatile("movge r1,r8"); 40 | asm volatile("ldrsb r0,[r0,r1]"); 41 | asm volatile("bx r14"); 42 | 43 | // workaround for "invalid literal constant: pool needs to be closer" 44 | asm volatile(".ltorg"); 45 | } 46 | 47 | __attribute((used)) void DispatchCustomInstruction(int index, struct script_routine* routine, uint16_t* args) { 48 | if (index < 0 || index >= CUSTOM_INSTRUCTION_AMOUNT) { 49 | COT_ERRORFMT(COT_LOG_CAT_INSTRUCTIONS, "Custom opcode %d out of bounds", index); 50 | return; 51 | } 52 | 53 | struct custom_instruction* instruction = &CUSTOM_INSTRUCTIONS[index]; 54 | COT_LOGFMT(COT_LOG_CAT_INSTRUCTIONS, "Running custom instruction '%s' with %d arguments (opcode %d, index %d)", instruction->name, instruction->n_params, FIRST_CUSTOM_OPCODE + index, index); 55 | instruction->handler(routine, args); 56 | } 57 | 58 | #endif -------------------------------------------------------------------------------- /scripts/generate_linkerscript.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import sys 3 | import glob 4 | from pathlib import Path 5 | 6 | from yaml import load, Loader 7 | 8 | region = sys.argv[1] 9 | itcm_region = region + "-ITCM" 10 | 11 | linkerscript_lines = [] 12 | all_symbols = set() 13 | 14 | linkerscript_lines.append("/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY! */") 15 | 16 | for yaml_file_path in Path("pmdsky-debug/symbols").rglob("*.yml"): 17 | with open(yaml_file_path, 'r', encoding="utf-8") as f: 18 | linkerscript_lines.append("") 19 | linkerscript_lines.append(f"/* --- {yaml_file_path} --- */") 20 | yaml_string = f.read() 21 | symbol_def = load(yaml_string, Loader) 22 | for file_name, contents in symbol_def.items(): 23 | linkerscript_lines.append("") 24 | linkerscript_lines.append(f"/* !file {file_name} */") 25 | if 'address' in contents: 26 | addresses = contents['address'] 27 | if region in addresses: 28 | symbol = f"{file_name.upper()}_LOAD_ADDR" 29 | 30 | # Overlay load addresses are duplicated, ignore the duplicates 31 | if not symbol in all_symbols: 32 | addr = addresses[region] 33 | linkerscript_lines.append(f"{symbol} = {hex(addr)};") 34 | all_symbols.add(symbol) 35 | 36 | symbols = [] 37 | if 'functions' in contents: 38 | symbols.extend(contents['functions']) 39 | if 'data' in contents: 40 | symbols.extend(contents['data']) 41 | 42 | for sym in symbols: 43 | # Define symbols for all aliases on this symbol 44 | names = [sym['name']] 45 | if 'aliases' in sym: 46 | names.extend(sym['aliases']) 47 | 48 | addresses = sym['address'] 49 | addr = None 50 | # *-ITCM regions are runtime overrides for the normal addresses 51 | if itcm_region in addresses: 52 | addr = addresses[itcm_region] 53 | elif region in addresses: 54 | addr = addresses[region] 55 | 56 | if addr is not None: 57 | if isinstance(addr, list): 58 | if len(addr) == 0: 59 | continue 60 | addr = addr[0] 61 | 62 | for name in names: 63 | if name in all_symbols: 64 | print(f"Warning: Duplicate symbol: '{name}'") 65 | linkerscript_lines.append(f"{name} = {hex(addr)};") 66 | all_symbols.add(name) 67 | 68 | with open(f"symbols/generated_{region}.ld", "w", encoding="utf-8") as f: 69 | for line in linkerscript_lines: 70 | f.write(line) 71 | f.write('\n') 72 | -------------------------------------------------------------------------------- /src/ground_instructions.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Custom script engine instructions are disabled by default. 5 | // Refer to README.md for more information. 6 | 7 | #if CUSTOM_GROUND_INSTRUCTIONS 8 | 9 | // Overwrites the default dialogue box attributes with the given values. 10 | // 11 | // # Arguments 12 | // - `x`: x position 13 | // - `y`: y position 14 | // - `width`: dialogue box width 15 | // - `height`: dialogue box height 16 | // - `screen`: 0 = bottom screen, 1 = top screen 17 | // - `frame`: 0xFD = default, 0xFA = invisible, ... 18 | void OpSetDialogueBoxAttributes(struct script_routine* routine, uint16_t* args) { 19 | int x = ScriptParamToInt(args[0]); 20 | int y = ScriptParamToInt(args[1]); 21 | int width = ScriptParamToInt(args[2]); 22 | int height = ScriptParamToInt(args[3]); 23 | int screen = ScriptParamToInt(args[4]); 24 | int frame = ScriptParamToInt(args[5]); 25 | 26 | DIALOGUE_BOX_DEFAULT_WINDOW_PARAMS.x_offset = x; 27 | DIALOGUE_BOX_DEFAULT_WINDOW_PARAMS.y_offset = y; 28 | DIALOGUE_BOX_DEFAULT_WINDOW_PARAMS.width = width; 29 | DIALOGUE_BOX_DEFAULT_WINDOW_PARAMS.height = height; 30 | DIALOGUE_BOX_DEFAULT_WINDOW_PARAMS.screen.val = screen; 31 | DIALOGUE_BOX_DEFAULT_WINDOW_PARAMS.box_type.val = frame; 32 | 33 | COT_LOGFMT(COT_LOG_CAT_INSTRUCTIONS, "Setting dialogue box attributes: x=%d, y=%d, width=%d, height=%d, screen=%d, frame=%d", x, y, width, height, screen, frame); 34 | } 35 | 36 | // Returns the set of held/pressed buttons as a bitfield. 37 | // 38 | // # Arguments 39 | // - `mode`: 0 = pressed buttons, 1 = held buttons 40 | void OpCheckInputStatus(struct script_routine* routine, uint16_t* args) { 41 | int mode = ScriptParamToInt(args[0]); 42 | 43 | int buttons = 0; 44 | if (mode == 0) { 45 | GetPressedButtons(0, (undefined*) &buttons); 46 | } else { 47 | GetHeldButtons(0, (undefined*) &buttons); 48 | } 49 | routine->states[0].ssb_info[0].next_opcode_addr = ScriptCaseProcess(routine, buttons); 50 | } 51 | 52 | // Add your custom instructions to the list below. 53 | // `handler` is a pointer to your handler function (see the examples above). 54 | // `n_params` must match the number of parameters used in your handler function 55 | // (must be 0 or a positive number, instructions with variadic arguments are not supported). 56 | // Custom instructions use ID 0x1000 + . 57 | // 58 | // Refer to README.md for instructions on how to access custom instructions in SkyTemple! 59 | struct custom_instruction CUSTOM_INSTRUCTIONS[] = { 60 | // ID 0x1000 61 | { 62 | .name = "SetDialogueBoxAttributes", 63 | .handler = OpSetDialogueBoxAttributes, 64 | .n_params = 6 65 | }, 66 | // ID 0x1001 67 | { 68 | .name = "CheckInputStatus", 69 | .handler = OpCheckInputStatus, 70 | .n_params = 1 71 | } 72 | }; 73 | 74 | __attribute((used)) const int CUSTOM_INSTRUCTION_AMOUNT = ARRAY_LENGTH(CUSTOM_INSTRUCTIONS); 75 | 76 | #endif -------------------------------------------------------------------------------- /src/cot/menu_hooks.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | // Loosely based on https://github.com/Adex-8x/mm5-patches/blob/main/src/menus.c 7 | 8 | #if CUSTOM_SCRIPT_MENUS 9 | 10 | // const instead of #define so the constant can be referenced in Assembly 11 | __attribute((used)) const int FIRST_CUSTOM_SCRIPT_MENU = 80; 12 | 13 | __attribute((naked)) void HookKeyboardCheck(void) { 14 | asm volatile("ldr r12,=FIRST_CUSTOM_SCRIPT_MENU"); 15 | asm volatile("ldr r12,[r12]"); 16 | asm volatile("mov r8,r0"); 17 | asm volatile("cmp r0,r12"); 18 | asm volatile("movlt r6,r0"); 19 | asm volatile("movge r6,#3"); // The base-game partner nickname menu goes unused and doesn't actually do anything when completed, so it gets repurposed here! 20 | asm volatile("bx r14"); 21 | 22 | asm volatile(".ltorg"); 23 | } 24 | 25 | __attribute((naked)) void HookKeyboardCustomPrompt(void) { 26 | asm volatile("ldr r12,=FIRST_CUSTOM_SCRIPT_MENU"); 27 | asm volatile("ldr r12,[r12]"); 28 | asm volatile("subs r12,r8,r12"); 29 | asm volatile("ldrpl r2,=CUSTOM_MENUS"); 30 | asm volatile("lslpl r12,r12,#0x4"); // Struct size 31 | asm volatile("ldrplh r12,[r2,r12]"); 32 | #ifdef REGION_NA 33 | asm volatile("ldrpl r0,[r1,#0x0]"); 34 | #elif REGION_EU 35 | asm volatile("ldrpl r0,[r0,#0x0]"); 36 | #else 37 | asm volatile("ldrpl r0,[r3,#0x0]"); 38 | #endif 39 | asm volatile("addpl r0,r0,#0x100"); 40 | asm volatile("strplh r12,[r0,#0xA6]"); // Text String used for the keyboard prompt 41 | asm volatile("b ShowKeyboardTypeDefaultCase"); 42 | 43 | asm volatile(".ltorg"); 44 | } 45 | 46 | __attribute((naked)) void HookScriptMenuRequestCheck(void) { 47 | asm volatile("mov r0,r5"); 48 | asm volatile("bl InitializeCustomScriptMenu"); 49 | asm volatile("b ScriptMenuRequestFinalize"); 50 | } 51 | 52 | __attribute((naked)) void HookScriptMenuUpdateCheck(void) { 53 | asm volatile("bl DispatchCustomScriptMenu"); 54 | asm volatile("b ScriptMenuUpdateFinalize"); 55 | } 56 | 57 | bool CustomMenuIsOutOfRange(int index) { 58 | return index < 0 || index >= CUSTOM_MENU_AMOUNT; 59 | } 60 | 61 | __attribute((used)) int CustomPreprocessStringFromId(char* output, int output_size, int string_id, struct preprocessor_flags flags, struct preprocessor_args* args) { 62 | int index = GLOBAL_MENU_INFO.id - FIRST_CUSTOM_SCRIPT_MENU; 63 | if (!CustomMenuIsOutOfRange(index)) { 64 | struct custom_menu* script_menu = &CUSTOM_MENUS[index]; 65 | string_id = script_menu->keyboard_confirm_string_id; 66 | } 67 | return PreprocessStringFromId(output, output_size, string_id, flags, args); 68 | } 69 | 70 | __attribute((used)) void InitializeCustomScriptMenu(int menu_id) { 71 | int index = menu_id - FIRST_CUSTOM_SCRIPT_MENU; 72 | if (CustomMenuIsOutOfRange(index)) { 73 | COT_ERRORFMT(COT_LOG_CAT_MENUS, "Custom request for script menu %d out of bounds", menu_id); 74 | return; 75 | } 76 | 77 | MemZero(&GLOBAL_MENU_INFO, sizeof(struct global_menu_info)); 78 | GLOBAL_MENU_INFO.id = menu_id; 79 | ArrayFill32(-1, GLOBAL_MENU_INFO.window_ids, sizeof(GLOBAL_MENU_INFO.window_ids)); 80 | struct custom_menu* script_menu = &CUSTOM_MENUS[index]; 81 | COT_LOGFMT(COT_LOG_CAT_MENUS, "Running custom script menu %d", menu_id); 82 | script_menu->create(); 83 | } 84 | 85 | __attribute((used)) bool DispatchCustomScriptMenu(int menu_id, int* return_val) { 86 | int index = menu_id - FIRST_CUSTOM_SCRIPT_MENU; 87 | if (CustomMenuIsOutOfRange(index)) { 88 | *return_val = -1; 89 | return true; 90 | } 91 | 92 | struct custom_menu* script_menu = &CUSTOM_MENUS[index]; 93 | bool is_menu_finished = script_menu->update(); 94 | if(is_menu_finished) { 95 | script_menu->close(); 96 | GLOBAL_MENU_INFO.id = 0; 97 | *return_val = GLOBAL_MENU_INFO.return_val; 98 | } 99 | return is_menu_finished; 100 | } 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /install_linux.md: -------------------------------------------------------------------------------- 1 | # Linux setup guide 2 | 3 | You can install c-of-time on Linux using the following methods. Instructions vary based on your Linux distribution. 4 | 5 | - [Ubuntu/Debian](#ubuntu-debian) 6 | - [Fedora](#fedora) 7 | - [Arch Linux](#arch-linux) 8 | - [Other methods (advanced)](#other-methods-advanced) 9 | 10 | ## Ubuntu/Debian 11 | 12 | You can install c-of-time on Ubuntu or Debian using the following methods. The steps detailed in this guide were tested on Ubuntu 22.04. 13 | 14 | 1. Open the Terminal app in your Applications menu. The exact steps might vary based on your desktop environment. 15 | 2. Run the following command to install the required tools: `sudo apt install build-essential cmake python3-pip gcc-arm-none-eabi binutils-arm-none-eabi`. You will need to enter your password during the installation. 16 | 3. Install Python dependencies: `pip3 install pyyaml ndspy` 17 | 4. Compile `armips`: 18 | 1. Run `git clone --recursive https://github.com/Kingcom/armips.git` to download the source code. 19 | 2. Run `cd armips` to enter the directory. 20 | 3. Run this command to compile the project: `mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build .` 21 | 4. Run `sudo cp armips /usr/local/bin` to install `armips`. 22 | 5. Run `cd ../..` to return to the previous directory. 23 | 5. Navigate to the directory where you want to install c-of-time. You can use `cd` to change the directory and `ls` to list the contents of the current directory. For example, if you want to install c-of-time to `/home/YourName/Documents/c-of-time`, run `cd /home/YourName/Documents`. 24 | - **Note:** You can also use the file manager to navigate to the directory where you want to install c-of-time. Right-click the name of the directory and select "Open in Terminal". 25 | 6. Download this repository by running `git clone --recursive https://github.com/SkyTemple/c-of-time.git` in the terminal. c-of-time will be downloaded in a folder called `c-of-time` inside the current directory. 26 | 7. Enter the `c-of-time` directory with `cd c-of-time`. 27 | 8. Copy the ROM you have prepared into the `c-of-time` directory and rename it to `rom.nds`. You can open the file manager in the current directory by running `xdg-open .` in the terminal. 28 | - **US ROM offsets are used by default.** If you're using a EU or JP ROM, change the `REGION` variable in `Makefile` to `EU` or `JP` accordingly. 29 | 9. Run `make headers` to add aliases and documentation comments to headers for increased compatibility. 30 | 10. Run `make patch` to build the project. The output ROM will be saved as `out.nds` by default. 31 | 32 | ## Fedora 33 | 34 | 1. Open the Terminal app in your Applications menu. The exact steps might vary based on your desktop environment. 35 | 2. Run the following command to install the required tools: `sudo dnf install @development-tools gcc-c++ cmake python3-pip arm-none-eabi-binutils-cs arm-none-eabi-gcc-cs`. You will need to enter your password during the installation. 36 | 3. You can now continue with the steps 3-10 of the Ubuntu/Debian method above. 37 | 38 | ## Arch Linux 39 | 40 | 1. Open the Terminal app. The exact steps vary based on your desktop environment. 41 | 2. Run the following command to install the required tools: `sudo pacman -Syu base-devel git python python-pip arm-none-eabi-gcc arm-none-eabi-binutils`. You will need to enter your password during the installation. 42 | 3. Install Python dependencies: `pip3 install pyyaml ndspy` 43 | 4. Install the [armips package](https://aur.archlinux.org/packages/armips) via the Arch User Repository (AUR). Please refer to the [Arch Wiki](https://wiki.archlinux.org/title/Arch_User_Repository) for instructions. 44 | 5. You can now continue with the steps 5-10 of the Ubuntu/Debian method above. 45 | 46 | ## Other methods (advanced) 47 | 48 | - You can use the official [ARM toolchain](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads) to build c-of-time. Make sure to add the toolchain to your `PATH` environment variable. You will need to install `make` and other Unix build tools as well. 49 | - [devkitpro](https://devkitpro.org/wiki/Getting_Started) provides an installer for a custom toolchain. Follow the instructions on their website to install it and make sure to add the toolchain to your `PATH` environment variable. 50 | -------------------------------------------------------------------------------- /install_windows.md: -------------------------------------------------------------------------------- 1 | # Windows setup guide 2 | 3 | You can install c-of-time on Windows using the following methods. The steps detailed in this guide were tested with Windows 11. This guide assumes that you have a 64-bit version of Windows installed. 4 | 5 | - [Method 1: WSL (recommended)](#method-1-wsl-recommended) 6 | - [Method 2: MSYS2](#method-2-msys2) 7 | - [Other methods (advanced)](#other-methods-advanced) 8 | 9 | ## Method 2: WSL (recommended) 10 | 11 | You can run c-of-time in the Windows Subsystem for Linux (WSL). WSL 2 is recommended for maximum compatibility. 12 | 13 | Refer to [this guide by Microsoft](https://learn.microsoft.com/en-us/windows/wsl/install) to install WSL. After the installation is finished, open a terminal such as the Windows Command Prompt or Windows PowerShell and run `wsl.exe` to enter WSL. You can now install follow the [setup instructions for Linux](./install_linux.md). 14 | 15 | ## Method 2: MSYS2 16 | 17 | MSYS2 is a Unix-like environment for Windows. It provides a terminal and a package manager that allows you to install the required tools on Windows with a few commands. This is the recommended method for installing c-of-time on Windows. 18 | 19 | Note: There are known issues with package installation using this method (see [this thread in the SkyTemple Discord server](https://discord.com/channels/710190644152369162/1320206615475130399/1320206615475130399)). 20 | 21 | 1. Download and install [MSYS2](https://www.msys2.org/wiki/MSYS2-installation/) by following the instructions on their website. This guide assumes that you installed MSYS2 to `C:\msys64`, adjust the paths accordingly if you installed it to a different location. 22 | 2. Press the Windows key, search for "MINGW64" and open the "MSYS2 MINGW64" shortcut to open a terminal. **Note that the other MSYS shortcuts will not work, always open the "MSYS2 MINGW64" one.** 23 | 3. Run `pacman -S git make mingw-w64-x86_64-arm-none-eabi-toolchain mingw-w64-x86_64-python-pip` to install Git, Make, the ARM toolchain and the Python package manager. Confirm that you want to install all packages by pressing enter, then type `y` and press Enter. 24 | 4. Install Python dependencies: `pip3 install pyyaml ndspy` 25 | 5. Navigate to the directory where you want to install c-of-time. You can use `cd` to change the directory and `ls` to list the contents of the current directory. For example, if you want to install c-of-time to `C:\Users\YourName\Documents\c-of-time`, run `cd /c/Users/YourName/Documents`. 26 | - **Note:** You can also use the Windows Explorer to navigate to the directory where you want to install c-of-time. Right-click in the directory and select "Open in Terminal", then run `C:\msys64\msys2_shell.cmd -mingw64 -here` to open a terminal in that directory. 27 | 6. Download this repository by running `git clone --recursive https://github.com/SkyTemple/c-of-time.git` in the MSYS2 terminal. c-of-time will be downloaded in a folder called `c-of-time` inside the current directory. 28 | 7. Enter the `c-of-time` directory with `cd c-of-time`. 29 | 8. Copy the ROM you have prepared into the `c-of-time` directory and rename it to `rom.nds`. You can open Windows Explorer in the current directory by running `explorer .` in the MSYS2 terminal. 30 | - **US ROM offsets are used by default.** If you're using a EU or JP ROM, change the `REGION` variable in `Makefile` to `EU` or `JP` accordingly. 31 | 9. Run `make headers` to add aliases and documentation comments to headers for increased compatibility. 32 | 10. Run `make patch` to build the project. The output ROM will be saved as `out.nds` by default. 33 | - If you are encountering errors with armips, you might need to install the [Visual C++ Redistributable for Visual Studio 2015](https://www.microsoft.com/en-US/download/details.aspx?id=48145). Make sure to download the 64-bit version (`vc_redist.x64.exe`). 34 | 35 | ## Other methods (advanced) 36 | 37 | - You can use the official [ARM toolchain](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads) to build c-of-time. Make sure to add the toolchain to your `PATH` environment variable. You will need to install `make` and other Unix build tools as well. 38 | - [devkitpro](https://devkitpro.org/wiki/Getting_Started) provides a Windows installer for a custom toolchain. Follow the instructions on their website to install it and make sure to add the toolchain to your `PATH` environment variable. 39 | -------------------------------------------------------------------------------- /install_macos.md: -------------------------------------------------------------------------------- 1 | # macOS setup guide 2 | 3 | You can install c-of-time on macOS using the following methods. The steps detailed in this guide were tested on macOS Sonoma (14.2). 4 | 5 | - [Method 1: Homebrew (recommended)](#method-1-homebrew-recommended) 6 | - [Method 2: Downloading the toolchain from ARM](#method-2-downloading-the-toolchain-from-arm) 7 | - [Other methods (advanced)](#other-methods-advanced) 8 | 9 | ## Method 1: Homebrew (recommended) 10 | 11 | [Homebrew](https://brew.sh) is a package manager for macOS that allows you to install the required tools with a few commands. This is the recommended method for installing c-of-time on macOS. 12 | 13 | 1. Open the Terminal app. You can find it in the Launchpad in the "Other" folder. 14 | 2. Install the command line tools for Xcode by running `xcode-select --install` in the terminal. Confirm the installation by clicking "Install" in the popup window. 15 | 3. Once the installation is finished, you can proceed with installing Homebrew. Refer to the section "Install Homebrew" of the [Homebrew website](https://brew.sh) for instructions (you will have to execute a command in the terminal). **After the installation is finished, make sure to follow the instructions printed by Homebrew to add the Homebrew directory to your `PATH` environment variable.** 16 | 4. Install the ARM toolchain by running `brew install --cask gcc-arm-embedded` in the terminal. You will need to enter your password during the installation. 17 | 5. Install Python dependencies: `pip3 install pyyaml ndspy` 18 | 6. Navigate to the directory where you want to install c-of-time. You can use `cd` to change the directory and `ls` to list the contents of the current directory. For example, if you want to install c-of-time to `/Users/YourName/Documents/c-of-time`, run `cd /Users/YourName/Documents`. 19 | - **Note:** You can also use the Finder to navigate to the directory where you want to install c-of-time. Right-click the name of the directory, hold the Option key and select "Copy [directory name] as Pathname". Then, run `cd ` in the terminal and paste the path by pressing Command+V. 20 | 5. Download this repository by running `git clone --recursive https://github.com/SkyTemple/c-of-time.git` in the terminal. c-of-time will be downloaded in a folder called `c-of-time` inside the current directory. 21 | 6. Enter the `c-of-time` directory with `cd c-of-time`. 22 | 7. Copy the ROM you have prepared into the `c-of-time` directory and rename it to `rom.nds`. 23 | - **US ROM offsets are used by default.** If you're using a EU or JP ROM, change the `REGION` variable in `Makefile` to `EU` or `JP` accordingly. 24 | 8. Run `make headers` to add aliases and documentation comments to headers for increased compatibility. 25 | 9. Run `make patch` to build the project. The output ROM will be saved as `out.nds` by default. 26 | 27 | ### Troubleshooting 28 | 29 | If you are encountering errors with armips, try the following: 30 | - Navigate to the folder `c-of-time/bin/armips` in Finder 31 | - Right-click `armips-mac-arm64` if you're on Apple Silicon or `armips-mac-x64` if you're on an Intel-based Mac, click "Open" and confirm 32 | 33 | ## Method 2: Downloading the toolchain from ARM 34 | 35 | You can install c-of-time on macOS by downloading the toolchain from ARM's website. 36 | This method is slightly more involved, but it's more lightweight and doesn't require you to install Homebrew. 37 | 38 | 1. Open the Terminal app. You can find it in the Launchpad in the "Other" folder. 39 | 2. Install the command line tools for Xcode by running `xcode-select --install` in the terminal. Confirm the installation by clicking "Install" in the popup window. 40 | 3. Once the installation is finished, you can proceed with downloading the toolchain. Download the latest version of the toolchain from [ARM's website](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads). 41 | - If you're using an Apple Silicon Mac, download the "Apple Silicon hosted" version. Otherwise, use the "x86_64 hosted" version. 42 | - You will need the "AArch32 bare-metal target" version, not the "AArch64 bare-metal target" version. 43 | - Download and open the `.pkg` file. Follow the instructions in the installer. 44 | 4. Run the command `export VERSION=` in the terminal, followed by the version number of the toolchain you just installed. This version number should match the folder name of the toolchain in `/Applications/ArmGNUToolchain`. For example, if you installed version 13.2.rel1, run `export VERSION=13.2.rel1`. Then, run `echo 'export PATH="/Applications/ArmGNUToolchain/$VERSION/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc` to add the toolchain to your `PATH` environment variable. 45 | - If you're using another shell than zsh (the default on macOS), replace `~/.zshrc` with the path to your shell's configuration file. For example, if you're using bash, replace `~/.zshrc` with `~/.bashrc`. 46 | 5. You can now continue with the steps 5-9 of the Homebrew method above. 47 | 48 | ## Other methods (advanced) 49 | 50 | - [devkitpro](https://devkitpro.org/wiki/Getting_Started) provides a macOS installer for a custom toolchain. Follow the instructions on their website to install it and make sure to add the toolchain to your `PATH` environment variable. 51 | -------------------------------------------------------------------------------- /scripts/patch.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import ndspy.rom 3 | import ndspy.code 4 | import sys 5 | import os 6 | import re 7 | from subprocess import Popen, PIPE 8 | import glob 9 | import platform 10 | import tempfile 11 | 12 | OVERLAY_EXTRA = 36 13 | 14 | region = sys.argv[1] 15 | rom_path = sys.argv[2] 16 | overlay_elf_path = sys.argv[3] 17 | rom_out_path = sys.argv[4] 18 | 19 | overlay_symbols_lookup = {} # Key = symbol_name: string, value = offset: int 20 | 21 | rom = ndspy.rom.NintendoDSRom.fromFile(rom_path) 22 | overlays = rom.loadArm9Overlays() 23 | 24 | def load_overlay_symbols(): 25 | process = Popen(["arm-none-eabi-nm", overlay_elf_path], stdout=PIPE) 26 | (stdout, stderr) = process.communicate() 27 | exit_code = process.wait() 28 | assert exit_code == 0, f"nm failed with code {exit_code}" 29 | 30 | lines = stdout.decode().split('\n') 31 | for line in lines: 32 | parts = line.strip().split() 33 | 34 | if (len(parts) < 3): 35 | continue 36 | 37 | offset = int(parts[0], 16) 38 | type = parts[1] 39 | name = parts[2] 40 | overlay_symbols_lookup[name] = offset 41 | 42 | 43 | def apply_overlay(): 44 | assert OVERLAY_EXTRA in overlays, "No overlay 36 found, apply the ExtraSpace patch first." 45 | 46 | # TODO: Find a better process to parse section info 47 | process = Popen(["arm-none-eabi-objdump", "-h", overlay_elf_path], stdout=PIPE) 48 | (stdout, stderr) = process.communicate() 49 | exit_code = process.wait() 50 | assert exit_code == 0, f"objdump failed with code {exit_code}" 51 | lines = stdout.decode().split('\n') 52 | readline = -1 53 | for line in lines: 54 | if line.startswith("Sections"): 55 | readline = 2 56 | if readline==0: 57 | readline = 2 58 | section = line.split() 59 | # Line: ID, Name, Size, VMA, LMA, Offset, Align 60 | if len(section)>0: 61 | if section[1].startswith(".text"): # Retrieve only text sections 62 | hierarchy = section[1].split(".") 63 | size = int(section[2], 16) 64 | vma = int(section[3], 16) 65 | offset = int(section[5], 16) 66 | bank_number = int(hierarchy[3]) 67 | if hierarchy[2] == "ov": 68 | overlay = overlays[bank_number] 69 | overlay_bytes = rom.files[overlay.fileID] 70 | ram_address = overlay.ramAddress 71 | elif hierarchy[2] == "arm": 72 | if bank_number == 9: 73 | overlay_bytes = rom.arm9 74 | ram_address = rom.arm9RamAddress 75 | elif bank_number == 7: 76 | overlay_bytes = rom.arm7 77 | ram_address = rom.arm7RamAddress 78 | else: 79 | raise ValueError("Invalid arm binary '%d'"%bank_number) 80 | else: 81 | raise ValueError("Invalid section '%s'"%hierarchy[2]) 82 | 83 | print("Applying C patch section to",hierarchy[2],bank_number,":", section[1], hex(vma), hex(vma+size)) 84 | 85 | with tempfile.TemporaryDirectory() as tmpdirname: 86 | binaryfile = os.path.join(tmpdirname, "temp.bin") 87 | process = Popen(["arm-none-eabi-objcopy", "-j", section[1], "-O", "binary", overlay_elf_path, binaryfile], stdout=PIPE) 88 | exit_code = process.wait() 89 | assert exit_code == 0, f"objdump failed with code {exit_code}" 90 | with open(binaryfile, "rb") as f: 91 | custom_code_bytes = f.read() 92 | 93 | assert size == len(custom_code_bytes), f"Size mismatch" 94 | 95 | # Combine the existing overlay bytes with the custom code 96 | padding = vma - ram_address 97 | new_overlay_bytes = bytearray(padding + size) 98 | new_overlay_bytes[0:len(overlay_bytes)] = overlay_bytes 99 | new_overlay_bytes[padding:padding + size] = custom_code_bytes 100 | 101 | if hierarchy[2] == "ov": 102 | overlay.data = new_overlay_bytes 103 | overlay.save() 104 | rom.files[overlay.fileID] = new_overlay_bytes 105 | rom.arm9OverlayTable = ndspy.code.saveOverlayTable(overlays) 106 | elif hierarchy[2] == "arm": 107 | if bank_number == 9: 108 | rom.arm9 = new_overlay_bytes 109 | elif bank_number == 7: 110 | rom.arm7 = new_overlay_bytes 111 | 112 | if readline>0: 113 | readline -= 1 114 | 115 | def apply_binary_patches(): 116 | if not os.path.exists("build/binaries"): 117 | os.mkdir("build/binaries") 118 | 119 | # Write all symbols to a file that can be included in patches 120 | with open("build/binaries/symbols.asm", "w", encoding="utf-8") as f: 121 | # Write symbols 122 | for symbol, offset in overlay_symbols_lookup.items(): 123 | f.write(f".definelabel {symbol},{hex(offset)}\n") 124 | 125 | # Write binary and overlay RAM offsets 126 | f.write(f"arm9_start equ {hex(rom.arm9RamAddress)}\n") 127 | f.write(f"arm9_end equ {hex(rom.arm9RamAddress + len(rom.arm9))}\n") 128 | f.write(f"arm7_start equ {hex(rom.arm7RamAddress)}\n") 129 | f.write(f"arm7_end equ {hex(rom.arm7RamAddress + len(rom.arm7))}\n") 130 | 131 | for index, overlay in overlays.items(): 132 | f.write(f"overlay{index}_start equ {hex(overlay.ramAddress)}\n") 133 | f.write(f"overlay{index}_end equ {hex(overlay.ramAddress + overlay.ramSize)}\n") 134 | 135 | # Write the main binaries 136 | with open("build/binaries/arm9.bin", "wb") as f: 137 | f.write(rom.arm9) 138 | with open("build/binaries/arm7.bin", "wb") as f: 139 | f.write(rom.arm7) 140 | 141 | # Write overlay binaries 142 | for index, overlay in overlays.items(): 143 | with open(f"build/binaries/overlay{index}.bin", "wb") as f: 144 | f.write(rom.files[overlay.fileID]) 145 | 146 | for file in glob.glob("patches/*.asm"): 147 | apply_binary_patch(file) 148 | 149 | # Apply the main binaries 150 | with open("build/binaries/arm9.bin", "rb") as f: 151 | rom.arm9 = f.read() 152 | with open("build/binaries/arm7.bin", "rb") as f: 153 | rom.arm7 = f.read() 154 | 155 | # Apply overlay binaries 156 | for index, overlay in overlays.items(): 157 | with open(f"build/binaries/overlay{index}.bin", "rb") as f: 158 | rom.files[overlay.fileID] = f.read() 159 | 160 | def apply_binary_patch(file_path): 161 | print("Applying binary patch:", file_path) 162 | 163 | armips_path = "armips" 164 | if platform.system() == 'Darwin': 165 | if platform.machine() == 'arm64': 166 | armips_path = "bin/armips/armips-mac-arm64" 167 | else: 168 | armips_path = "bin/armips/armips-mac-x64" 169 | elif platform.system() == 'Windows': 170 | armips_path = "bin/armips/armips-win-x64.exe" 171 | patch_file_path = os.path.join('../../', file_path) # Relative to the root `build/binaries` 172 | 173 | process = Popen([armips_path, patch_file_path, '-root', 'build/binaries']) 174 | exit_code = process.wait() 175 | 176 | assert exit_code == 0, f"armips failed with code {exit_code}" 177 | 178 | load_overlay_symbols() 179 | apply_overlay() 180 | apply_binary_patches() 181 | 182 | rom.saveToFile(rom_out_path) 183 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # This file is based off DevkitARM's Makefile template and the included DevkitARM make files. 2 | #--------------------------------------------------------------------------------- 3 | .SUFFIXES: 4 | #--------------------------------------------------------------------------------- 5 | 6 | #--------------------------------------------------------------------------------- 7 | # the prefix on the compiler executables 8 | #--------------------------------------------------------------------------------- 9 | PREFIX := arm-none-eabi- 10 | 11 | export CC := $(PREFIX)gcc 12 | export CXX := $(PREFIX)g++ 13 | export AS := $(PREFIX)as 14 | export AR := $(PREFIX)gcc-ar 15 | export OBJCOPY := $(PREFIX)objcopy 16 | export STRIP := $(PREFIX)strip 17 | export NM := $(PREFIX)gcc-nm 18 | export RANLIB := $(PREFIX)gcc-ranlib 19 | 20 | #--------------------------------------------------------------------------------- 21 | %.o: %.c 22 | $(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) -DREGION_$(REGION) -c $< -o $@ $(ERROR_FILTER) 23 | 24 | #--------------------------------------------------------------------------------- 25 | %.o: %.m 26 | $(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(OBJCFLAGS) -DREGION_$(REGION) -c $< -o $@ $(ERROR_FILTER) 27 | 28 | #--------------------------------------------------------------------------------- 29 | %.o: %.s 30 | $(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -DREGION_$(REGION) -c $< -o $@ $(ERROR_FILTER) 31 | 32 | #--------------------------------------------------------------------------------- 33 | %.o: %.S 34 | $(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -DREGION_$(REGION) -c $< -o $@ $(ERROR_FILTER) 35 | 36 | #--------------------------------------------------------------------------------- 37 | %.elf: 38 | echo linking $(notdir $@) 39 | $(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@ 40 | 41 | #--------------------------------------------------------------------------------- 42 | # TARGET is the name of the output 43 | # BUILD is the directory where object files & intermediate files will be placed 44 | # SOURCES is a list of directories containing source code 45 | # INCLUDES is a list of directories containing extra header files 46 | #--------------------------------------------------------------------------------- 47 | 48 | # <-- Change to EU or JP if required 49 | REGION := NA 50 | ROM := rom.nds 51 | ROM_OUT := out.nds 52 | 53 | TARGET := out 54 | BUILD := build 55 | SOURCES := src src/cot 56 | INCLUDES := include pmdsky-debug/headers 57 | OPT_LEVEL := -O2 58 | 59 | # Change to "RELEASE_CONFIG := -DNDEBUG" for release builds without asserts and logs 60 | RELEASE_CONFIG := -DDEBUG 61 | 62 | PYTHON := python3 63 | 64 | #--------------------------------------------------------------------------------- 65 | # options for code generation 66 | #--------------------------------------------------------------------------------- 67 | ARCH := -marm -mno-thumb-interwork 68 | 69 | CFLAGS := -g -Wall $(OPT_LEVEL) $(RELEASE_CONFIG) $(SP_EFFECT_COMPAT) \ 70 | -march=armv5te -mtune=arm946e-s -fomit-frame-pointer -fno-short-enums \ 71 | -ffast-math -fno-builtin \ 72 | -fmacro-prefix-map=$(realpath $(CURDIR)/..)=. \ 73 | $(ARCH) 74 | 75 | CFLAGS += $(INCLUDE) -DARM9 -flto 76 | 77 | # Those are to be set by command line arguments. 78 | CFLAGS += $(EXTRA_CFLAGS) 79 | 80 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions 81 | 82 | ASFLAGS := -g $(ARCH) 83 | LDFLAGS = -T $(CURDIR)/../symbols/generated_$(REGION).ld \ 84 | -T $(CURDIR)/../symbols/custom_$(REGION).ld -T $(CURDIR)/../linker.ld \ 85 | -g $(ARCH) -Wl,-Map,$(notdir $*.map) -Xlinker -no-enum-size-warning -nostdlib -Xlinker --no-check-sections 86 | 87 | #--------------------------------------------------------------------------------- 88 | # any extra libraries we wish to link with the project 89 | #--------------------------------------------------------------------------------- 90 | LIBS := 91 | 92 | 93 | #--------------------------------------------------------------------------------- 94 | # list of directories containing libraries, this must be the top level containing 95 | # include and lib 96 | #--------------------------------------------------------------------------------- 97 | LIBDIRS := 98 | 99 | #--------------------------------------------------------------------------------- 100 | # no real need to edit anything past this point unless you need to add additional 101 | # rules for different file extensions 102 | #--------------------------------------------------------------------------------- 103 | ifneq ($(BUILD),$(notdir $(CURDIR))) 104 | #--------------------------------------------------------------------------------- 105 | 106 | export OUTPUT := $(CURDIR)/$(TARGET) 107 | 108 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) 109 | export DEPSDIR := $(CURDIR)/$(BUILD) 110 | 111 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 112 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 113 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 114 | BINFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.bin))) 115 | 116 | #--------------------------------------------------------------------------------- 117 | # use CXX for linking C++ projects, CC for standard C 118 | #--------------------------------------------------------------------------------- 119 | ifeq ($(strip $(CPPFILES)),) 120 | #--------------------------------------------------------------------------------- 121 | export LD := $(CC) 122 | #--------------------------------------------------------------------------------- 123 | else 124 | #--------------------------------------------------------------------------------- 125 | export LD := $(CXX) 126 | #--------------------------------------------------------------------------------- 127 | endif 128 | #--------------------------------------------------------------------------------- 129 | 130 | export OFILES := $(BINFILES:.bin=.o) \ 131 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 132 | 133 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 134 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 135 | -I$(CURDIR)/$(BUILD) 136 | 137 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 138 | 139 | #--------------------------------------------------------------------------------- 140 | .PHONY: $(BUILD) 141 | $(BUILD): symbols/generated_$(REGION).ld 142 | @[ -d $@ ] || mkdir -p $@ 143 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 144 | 145 | .PHONY: buildobjs 146 | buildobjs: 147 | @[ -d $(BUILD) ] || mkdir -p $(BUILD) 148 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile buildobjs 149 | 150 | #--------------------------------------------------------------------------------- 151 | .PHONY: clean 152 | clean: 153 | @echo clean ... 154 | @rm -fr $(BUILD) $(TARGET).elf $(TARGET).asm $(ROM_OUT).nds symbols/generated_*.ld 155 | 156 | #--------------------------------------------------------------------------------- 157 | else 158 | 159 | DEPENDS := $(OFILES:.o=.d) 160 | 161 | #--------------------------------------------------------------------------------- 162 | # main targets 163 | #--------------------------------------------------------------------------------- 164 | 165 | $(OUTPUT).elf : $(CURDIR)/../linker.ld $(OFILES) 166 | 167 | .PHONY: buildobjs 168 | buildobjs: $(OFILES) 169 | 170 | -include $(DEPENDS) 171 | 172 | #--------------------------------------------------------------------------------------- 173 | endif 174 | #--------------------------------------------------------------------------------------- 175 | 176 | symbols/generated_$(REGION).ld: 177 | $(PYTHON) scripts/generate_linkerscript.py $(REGION) 178 | 179 | .PHONY: patch 180 | patch: build 181 | $(PYTHON) scripts/patch.py $(REGION) $(ROM) $(OUTPUT).elf $(ROM_OUT) 182 | 183 | .PHONY: asmdump 184 | asmdump: build 185 | arm-none-eabi-objdump -S -d $(OUTPUT).elf > $(OUTPUT).asm 186 | 187 | .PHONY: headers 188 | headers: 189 | cd pmdsky-debug/headers && $(PYTHON) augment_headers.py --aliases --deprecate-aliases --docstrings 190 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # c-of-time 2 | 3 | ![c-of-time logo by Irdkwia](./cot-logo.png) 4 | *Logo by [Irdkwia](https://github.com/irdkwia)* 5 | 6 | An environment for hooking and linking to Pokémon Mystery Dungeon: Explorers of Sky. 7 | 8 | ## Credits 9 | This project is loosely based on [EternalCode's template](https://github.com/EternalCode/Empty-Template). The build configuration is based on scripts provided by [devkitPro](https://devkitpro.org). The patch format was inspired by [Starlight](https://github.com/shadowninja108/Starlight). 10 | 11 | Special thanks to [UsernameFodder](https://github.com/UsernameFodder) for the [pmdsky-debug](https://github.com/UsernameFodder/pmdsky-debug) project, [Frostbyte](https://github.com/Frostbyte0x70) for the *ExtraSpace* patch and [irdkwia](https://github.com/irdkwia) for their research on item, move and special process effects. 12 | 13 | ## Rust subsystem 14 | **NOTE: The `main` branch does currently not contain the Rust subsystem anymore**, as it's support 15 | for symbols for `pmdsky-debug` is outdated and we eventually want to split the Rust subsytem 16 | off so we can keep `c-of-time` up-to-date with `pmdsky-debug` more easily. Use the `rust` branch 17 | if you want to use the Rust subsystem. 18 | 19 | c-of-time can also be used with Rust projects. If you want to use Rust (including mixed Rust + C projects), 20 | continue reading the `README.md` in the `rust` directory. 21 | 22 | If you want to build pure C projects, continue below. 23 | 24 | ## Project setup 25 | 26 | ### Preparing the ROM 27 | 28 | You need a US, EU, or JP ROM of Pokémon Mystery Dungeon: Explorers of Sky. The ROM must be patched with the [`ExtraSpace` patch by Frostbyte](https://github.com/Frostbyte0x70/EoS-asm-patches/blob/main/src/ExtraSpace.asm). You can apply the patch with [SkyTemple](https://skytemple.org): 29 | 1. Open the ROM in SkyTemple 30 | 2. Click *ASM Patches* (*Patches > ASM* in SkyTemple 1.4+) and switch to the *Utility* tab 31 | 3. Select the *ExtraSpace* patch and click *Apply* 32 | 33 | ### Installing dependencies 34 | 35 | Refer to the setup guide for your platform: 36 | - [Windows](./install_windows.md) 37 | - [Linux](./install_linux.md) 38 | - [macOS](./install_macos.md) 39 | 40 | ## Building 41 | To build the project, run `make patch`. This command will build your code, inject it into an overlay in the provided ROM and apply the patches in the `patches` directory. The output ROM will be saved as `out.nds` by default. 42 | 43 | If you want to check the generated assembly, run `make asmdump`. A file `out.asm` will be generated, which contains an assembly listing annotated with the corresponding source code lines. 44 | 45 | ## Usage 46 | Patches can be added to `.asm` files inside the `patches` directory. These patch files contain offsets into functions that should be patched and assembly instructions, which allow calling into custom code. See `src/main.c` and `patches/patches.asm` for examples. 47 | 48 | ### Logging and assertions 49 | You can use the logging macros `COT_LOG`, `COT_WARN` and `COT_ERROR`. To view the logs, open the ROM in the SkyTemple debugger and check "Game Internal" in the log window. A macro for assertions `COT_ASSERT(expr)` is also available. 50 | 51 | To disable assertions and logging globally and save some performance, change `RELEASE_CONFIG` in `Makefile`. 52 | 53 | ### Custom move/item effects and special processes 54 | To create custom special processes, add them into the `switch` statement in `CustomScriptSpecialProcessCall`. This function is only called for special process ID 100 and greater for compatibility with existing patches. 55 | 56 | You can add custom item or move effects in `CustomApplyItemEffect` and `CustomApplyMoveEffect`. 57 | 58 | Please note that custom move effects are currently *not* handled by the *Metronome* move. 59 | 60 | #### Compatiblity with existing patches 61 | 62 | **Note: ROMs patched with c-of-time currently experience crashes with the `ExtractItemCode` and `ExtractMoveCode` patch.** 63 | 64 | You can work around the crash by removing `.open "overlay29.bin", overlay29_start` and all following lines in `patches/internal.asm`. 65 | However, doing so will cause custom effects written in C to have no effect. 66 | 67 | Please reach out to us [on Discord](https://discord.gg/skytemple) for potential workarounds if you need to use the aforementioned patches while also adding effects via c-of-time. 68 | 69 | ### Custom script engine instructions 70 | 71 | Custom script engine instructions are a more complex, but more powerful alternative to special processes. 72 | 73 | Advantages over special processes include: 74 | - No frame delay (especially beneficial when building complex minigames or other real-time interactions) 75 | - Custom instructions can be used inside targeted routines, while `ProcessSpecial` doesn't work 76 | - Cleaner script code overall without resorting to macros 77 | - Performing entity-specific operations 78 | 79 | Disadvantages: 80 | - At the moment, routines cannot conditionally hang on custom instructions (as opposed to special processes, which can hang the routine and loop its code upon returning -1) 81 | - No built-in support in SkyTemple (workaround provided below) 82 | 83 | Like special processes, custom instructions are capable of returning a value that can then be checked with a switch-statement. For an example, see the custom instruction `CheckInputStatus` in `ground_instructions.c`. 84 | 85 | Custom instructions are disabled by default. To enable support for custom instructions in c-of-time, open the file `include/cot/custom_instructions.h` and change the line `#define CUSTOM_GROUND_INSTRUCTIONS 0` to `#define CUSTOM_GROUND_INSTRUCTIONS 1`. You can now add your own instructions to the `CUSTOM_INSTRUCTIONS` array in `ground_instructions.c`. 86 | 87 | #### Accessing custom script engine instructions in SkyTemple 88 | 89 | SkyTemple will not recognize custom script engine instructions by default. 90 | Trying to save a script that references a custom instruction will lead to an error, and scripts containing custom instructions won't decompile. 91 | To use custom instructions in SkyTemple, open the folder where SkyTemple is installed, edit the file 92 | `/skytemple_files/_resources/ppmdu_config/pmd2scriptdata.xml` and add the following lines under the `` tag: 93 | 94 | ```xml 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | (add additional instructions here...) 108 | 109 | ``` 110 | 111 | We're planning to provide a SkyTemple plug-in that will make this process easier in the future. 112 | 113 | ### Custom script menus 114 | 115 | Custom script engine menus are a method of creating new, complex menus that would otherwise be inefficient with special processes or custom script engine instructions. They also serve as a more powerful alternative to the script engine's existing `message_SwitchMenu` and `message_SwitchMenu2` instructions, which do allow for simple menus, but are limited in functionality. 116 | 117 | By default, the first new menu ID is 80; this can be changed in `src/cot/menu_hooks.c`. To call a custom script menu, simply use the `message_Menu` instruction in a script; custom menus also support return values, which can be checked with a switch-statement in ExplorerScript like: 118 | 119 | ```c 120 | switch(message_Menu(81)) { 121 | case 0: 122 | debug_Print("ACCESS GRANTED."); 123 | break; 124 | default: 125 | debug_Print("INCORRECT PASSWORD. CARD EJECTION IMMINENT."); 126 | } 127 | ``` 128 | 129 | Generally, custom script menus are more complicated to create than special processes or instructions. Instead of a single handler being defined for each menu, each menu has three functions to handle its creation, maintenance, and destruction. See `include/cot/menus.h` and `src/menus.c` for information regarding these functions, as well as the definition of a global menu information structure. 130 | 131 | Despite the name, a custom script "menu" could technically be used for anything that needs to follow this general outline: 132 | 1. An initial phase that calls a function once, meant to allocate or create certain structures 133 | 2. An update phase that calls a function every frame until it finally returns `true`, meant to continuously check the status of anything created in the initial phase 134 | 3. A final phase that calls a function once (only run after the update phase is complete), meant to deallocate any structures that were created in the initial phase 135 | 136 | Additionally, keep in mind that when a script calls `message_Menu`, the current routine will hang, waiting for the menu to complete the three aforementioned phases in order. 137 | 138 | Custom script menus are disabled by default. To enable support for custom menus in c-of-time, open the file `include/cot/menus.h` and change the line `#define CUSTOM_SCRIPT_MENUS 0` to `#define CUSTOM_SCRIPT_MENUS 1`. You can now add your own menus to the `CUSTOM_SCRIPT_MENUS` array in `menus.c`. 139 | 140 | ## Updating symbol definitions and headers 141 | To update symbol data from `pmdsky-debug`, run `git submodule foreach git pull origin master`, 142 | then clean the build with `make clean`. 143 | 144 | ## Adding custom symbols 145 | If you've found symbols that are currently missing, consider contributing them to [pmdsky-debug](https://github.com/UsernameFodder/pmdsky-debug). You can find instructions in the repository's [contribution docs](https://github.com/UsernameFodder/pmdsky-debug/blob/master/docs/contributing.md). 146 | 147 | For quick testing, you can also add symbols to `symbols/custom_[region].ld` (`symbols/generated_[region].ld` is auto-generated and should not be modified). You need to specify the file each symbol belongs to in comments: 148 | 149 | ``` 150 | /* !file arm9 */ 151 | MyCoolFunction = 0x200DABC; 152 | 153 | /* !file overlay29 */ 154 | SomeDungeonFunction = 0x22DEABC; 155 | SomeOtherDungeonFunction = 0x22DEEFF; 156 | ``` 157 | 158 | ## Code size constraints 159 | 160 | The built code gets injected into the custom overlay 36. The entire overlay is 228 KB big, most of which is reserved for common patches provided by SkyTemple. Your code will be placed in the last 32 KB, which are considered the "common area" . If the binary is larger than 32 KB, you will get the following linker error: 161 | ``` 162 | error "section '.text' will not fit in region 'out'" 163 | ``` 164 | 165 | ### Expanding the available space 166 | To work around this issue, you can extend the space allocated in the overlay. **If you decide to extend the space, you do so at your own risk. Be careful since this space might be used by future patches!** Check the [list of assigned areas](https://docs.google.com/document/d/1Rs4icdYtiM6KYnWxMkdlw7jpWrH7qw5v6LOfDWIiYho) to find out if patches used in your ROM are affected. 167 | 168 | The value of `ORIGIN` must a multiple of 16 (end with 0 in hexadecimal). Therefore, the amount of bytes added to `LENGTH` must also be a multiple of 16. 169 | 170 | To extend the allocated space, open `linker.ld` and edit the following line: 171 | ``` 172 | out : ORIGIN = 0x23D7FF0, LENGTH = 0x8010 173 | ``` 174 | 175 | Subtract the amount of additional bytes you want to allocate from `ORIGIN` and add them to `LENGTH`. Next, open `patches/patch.py` and set `START_ADDRESS` of the top of the file to the same value as `ORIGIN` in the linker script. 176 | 177 | ### Optimizing for size 178 | You can also change the compiler flags to optimize for size instead of speed. To do so, set `OPT_LEVEL := Os` in `Makefile`. Effectiveness varies per project. 179 | 180 | ## Licensing 181 | - Build scripts (everything under the `tools`) are licensed under GPLv3. Review the file `LICENSE_GPLv3` for more information. 182 | - All other code is licensed under MIT. Review the file `LICENSE_MIT` for more information. 183 | -------------------------------------------------------------------------------- /src/menus.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Custom script menus are disabled by default. 5 | // Refer to README.md for more information. 6 | 7 | #if CUSTOM_SCRIPT_MENUS 8 | 9 | // The "entry" function called for every single option of the Advanced Menu created by CreateRecruitAnyMonsterMenu. The resulting buffer will be used as the option string for the given `option_id`. 10 | // In this instance, the goal is to make a menu that consists of every Pokémon, so every option will need to show each Pokémon's name! 11 | // `option_id` starts at 0, but the first Pokémon (Bulbasaur) starts at 1, hence the +1. 12 | char* RecruitAnyMonsterOptionEntryFn(char* buffer, int option_id) { 13 | sprintf(buffer, "[CS:K]%s[CR]", GetNameString(option_id+1)); 14 | return buffer; 15 | } 16 | 17 | // The initial menu function called when `message_Menu(80);` is executed in a script, responsible for the creation of the main Advanced Menu and a portrait. 18 | // Like any `create` function, this is only called once. 19 | void CreateRecruitAnyMonsterMenu(void) { 20 | struct window_params menu_params = { .x_offset = 2, .y_offset = 2, .box_type = {0xFF} }; 21 | struct window_flags menu_flags = { .a_accept = true, .b_cancel = true, .se_on = true, .partial_menu = true, .menu_lower_bar = true, .no_accept_button = true }; 22 | struct portrait_params* portrait_params = &(GLOBAL_MENU_INFO.portrait_params); 23 | struct vec2 vec = { .x = 2, .y = -3 }; 24 | InitPortraitParamsWithMonsterId(portrait_params, 1); 25 | SetPortraitLayout(portrait_params, 4); 26 | SetPortraitOffset(portrait_params, &vec); 27 | GLOBAL_MENU_INFO.window_ids[0] = CreateAdvancedMenu(&menu_params, menu_flags, NULL, RecruitAnyMonsterOptionEntryFn, 534, 8); 28 | GLOBAL_MENU_INFO.window_ids[1] = CreatePortraitBox(0, 3, true); 29 | ShowPortraitInPortraitBox(GLOBAL_MENU_INFO.window_ids[1], portrait_params); 30 | } 31 | 32 | // The final menu function called when `message_Menu(80);` is executed in a script, responsible for the closing of any and all active windows. 33 | // Like any `close` function, this is only called once. 34 | void CloseRecruitAnyMonsterMenu(void) { 35 | if(GLOBAL_MENU_INFO.window_ids[0] >= 0) 36 | CloseAdvancedMenu(GLOBAL_MENU_INFO.window_ids[0]); 37 | if(GLOBAL_MENU_INFO.window_ids[1] >= 0) 38 | ClosePortraitBox(GLOBAL_MENU_INFO.window_ids[1]); 39 | if(GLOBAL_MENU_INFO.window_ids[2] >= 0) 40 | CloseSimpleMenu(GLOBAL_MENU_INFO.window_ids[2]); 41 | } 42 | 43 | // The menu function called repeatedly while `message_Menu(80);` is active in a script, responsible for continuously checking the status of any menus and handling the logic of what should occur upon player input. 44 | // Like any `update` function, this is called every frame until it returns true. 45 | bool UpdateRecruitAnyMonsterMenu(void) { 46 | bool is_menu_finished = false; 47 | int adv_menu_id = GLOBAL_MENU_INFO.window_ids[0]; 48 | int portrait_id = GLOBAL_MENU_INFO.window_ids[1]; 49 | int simple_menu_id = GLOBAL_MENU_INFO.window_ids[2]; 50 | int current_menu_option; 51 | int monster_id; 52 | // Menus in the base game follow a pattern of keeping a "state" of any overarching menu system, then having a switch-statement to track menu progress. 53 | // A similar convention is followed here. Menu states will start at 0. 54 | switch(GLOBAL_MENU_INFO.state) { 55 | case 0: 56 | // Beginning state; check if the Advanced Menu is still active. If not, save the result and proceed to the next state. 57 | if(!IsAdvancedMenuActive2(adv_menu_id)) { 58 | GLOBAL_MENU_INFO.menu_results[0] = GetAdvancedMenuResult(adv_menu_id); 59 | if(GLOBAL_MENU_INFO.menu_results[0] >= 0) 60 | GLOBAL_MENU_INFO.state = 1; 61 | else { 62 | // A value of -1 for `GetAdvancedMenuResult` indicates that the menu was exited without an option being selected (i.e., the B button was pressed). 63 | GLOBAL_MENU_INFO.state = -1; 64 | GLOBAL_MENU_INFO.return_val = -1; 65 | } 66 | } 67 | // If the menu is active, be sure to continuously update the portrait to show the correct monster! 68 | else { 69 | current_menu_option = GetAdvancedMenuCurrentOption(adv_menu_id); 70 | if(current_menu_option != GLOBAL_MENU_INFO.previous_option) { 71 | GLOBAL_MENU_INFO.portrait_params.monster_id.val = current_menu_option + 1; 72 | GLOBAL_MENU_INFO.previous_option = current_menu_option; 73 | ShowPortraitInPortraitBox(portrait_id, &(GLOBAL_MENU_INFO.portrait_params)); 74 | } 75 | } 76 | break; 77 | case 1: 78 | // Check if the selected monster has a valid secondary gender. If so, create another menu. If not, attempt to create a new `ground_monster`! 79 | monster_id = GLOBAL_MENU_INFO.menu_results[0]+1; 80 | int secondary_gender = GetMonsterGender(monster_id+600); 81 | if(secondary_gender == GENDER_INVALID) 82 | GLOBAL_MENU_INFO.state = 3; 83 | else { 84 | struct window_params simple_menu_params = { .x_offset = 16, .y_offset = 10, .width = 10, .box_type = {0xFF} }; 85 | struct window_flags simple_menu_flags = { .a_accept = true, .b_cancel = true, .se_on = true }; 86 | struct simple_menu_id_item simple_options[3]; 87 | int starting_text_string_id; 88 | // Male/Female Text Strings 89 | #ifdef REGION_NA 90 | starting_text_string_id = 15531; 91 | #elif REGION_EU 92 | starting_text_string_id = 15533; 93 | #else 94 | starting_text_string_id = 1106; 95 | #endif 96 | for(int i = 0; i < 2; i++) { 97 | simple_options[i].string_id = i+starting_text_string_id; 98 | simple_options[i]._padding = 0; 99 | simple_options[i].result_value = i+1; 100 | } 101 | simple_options[2].string_id = NULL; 102 | simple_options[2]._padding = NULL; 103 | simple_options[2].result_value = NULL; 104 | GLOBAL_MENU_INFO.window_ids[2] = CreateSimpleMenuFromStringIds(&simple_menu_params, simple_menu_flags, NULL, simple_options, 3); 105 | GLOBAL_MENU_INFO.state = 2; 106 | } 107 | break; 108 | case 2: 109 | // Repeatedly check the Simple Menu, which is made to decide the monster's gender. This state will only run if the selected Pokémon does not have the value GENDER_INVALID for its secondary form's gender. 110 | if(!IsSimpleMenuActive(simple_menu_id)) { 111 | GLOBAL_MENU_INFO.menu_results[2] = GetSimpleMenuResult(simple_menu_id); 112 | if(GLOBAL_MENU_INFO.menu_results[2] > 0) { 113 | // Simple Menus allow for setting custom result values per option, unlike Advanced Menus. Still, in this instance, we simply have 1 for Male and 2 for Female. 114 | if(GLOBAL_MENU_INFO.menu_results[2] == 2) 115 | GLOBAL_MENU_INFO.menu_results[0] += 600; 116 | GLOBAL_MENU_INFO.state = 3; 117 | } 118 | else { 119 | // If the Simple Menu is exited without selecting an option, close the Simple Menu and resume the Advanced Menu. 120 | // The Advanced Menu can only be resumed in conjunction with `ResumeAdvancedMenu` and the `menu_flags.partial_menu` flag set upon the Advanced Menu's creation. 121 | CloseSimpleMenu(simple_menu_id); 122 | ResumeAdvancedMenu(adv_menu_id); 123 | // Set the Window ID of our previously-active Simple Menu to -1. This is also another base game convention for windows that have been closed in a menu. 124 | // The reason this is necessary is that this Simple Menu isn't guaranteed to be active when this function returns "true." 125 | // For example, imagine if the player selects Smeargle first, sees the Male/Female menu, and then changes their mind to then select Mewtwo. 126 | // Mewtwo's secondary form has a gender of GENDER_INVALID, so the Simple Menu would never get created a second time. 127 | // Were it not for setting the Window ID to -1, we would maintain a stale ID, which may interact strangely if we kept using menu functions with this ID. 128 | GLOBAL_MENU_INFO.window_ids[2] = -1; 129 | GLOBAL_MENU_INFO.state = 0; 130 | } 131 | } 132 | break; 133 | case 3: 134 | // Try to add the selected monster to Chimecho Assembly as a new recruit! 135 | // Based off of https://github.com/marius851000/eos-marius-patch/blob/master/process/eu_fixed/new_add_recruitable.asm 136 | int index = GetFirstEmptyMemberIdx(0x214); 137 | monster_id = GLOBAL_MENU_INFO.menu_results[0]+1; 138 | // A negative index indicates that there is no more space available for this new recruit. 139 | if(index > -1) { 140 | struct ground_monster* new_recruit = GetTeamMember(index); 141 | new_recruit->is_valid = true; 142 | new_recruit->id.val = monster_id; 143 | new_recruit->level_at_first_evo = 0; 144 | new_recruit->level_at_second_evo = 0; 145 | new_recruit->joined_at.val = DUNGEON_TEST_DUNGEON; 146 | new_recruit->joined_at_floor = 1; 147 | StrncpyName(new_recruit->name, GetNameString(monster_id), 10); 148 | SetBaseStatsMovesGroundMonster(new_recruit); 149 | ApplyLevelUpBoostsToGroundMonster(new_recruit, 1, false); 150 | SetPokemonJoined(monster_id); 151 | GLOBAL_MENU_INFO.return_val = index; 152 | } 153 | else 154 | GLOBAL_MENU_INFO.return_val = -2; 155 | // Regardless of whether the new recruit could be added, finish the menu. 156 | GLOBAL_MENU_INFO.state = -1; 157 | break; 158 | default: 159 | // If we reach an unexpected state, just end the menu. 160 | is_menu_finished = true; 161 | } 162 | return is_menu_finished; 163 | } 164 | 165 | // The initial menu function called to show a keyboard prompt for the player to type in a string. 166 | // This is intended to be used by a variety of menus. 167 | void CreateSimpleKeyboardMenu(void) { 168 | SetupAndShowKeyboard(GLOBAL_MENU_INFO.id, NULL, NULL); 169 | } 170 | 171 | // The menu function called repeatedly to check if the player has finished entering a string. 172 | // This is intended to be used by a variety of menus. 173 | bool UpdateSimpleKeyboardMenu(void) { 174 | return IS_BASE_GAME_MENU_FINISHED; 175 | } 176 | 177 | // The final menu function called when `message_Menu(81);` is executed in a script, responsible for checking the result of the player-inputted string. 178 | // Simply does a `strncmp` with "shard" and the keyboard string, i.e., returns 0 if the player has inputted "shard" in the keyboard prompt. 179 | void ClosePasswordMenu(void) { 180 | #ifdef REGION_JP 181 | GLOBAL_MENU_INFO.return_val = strncmp((char*)GetKeyboardStringResult(), "L6(J.", 10); // This is still actually "shard" 182 | #else 183 | GLOBAL_MENU_INFO.return_val = strncmp((char*)GetKeyboardStringResult(), "shard", 10); 184 | #endif 185 | } 186 | 187 | // The final menu function called when `message_Menu(82);` is executed in a script, responsible for checking the result of the player-inputted string. 188 | // Renames the partner across both its `ground_monster` and `team_member` structs using the string the player inputted in the keyboard prompt. 189 | // Based off of https://github.com/Chesyon/StarterMenuTool/blob/main/skypatches/FixPartnerNameMenu.skypatch 190 | void ClosePartnerNameMenu(void) { 191 | char* result = (char*)GetKeyboardStringResult(); 192 | int index = GetMainCharacter2MemberIdx(); 193 | int roster_index = GetActiveRosterIndex(index); 194 | struct ground_monster* ground_monster = GetTeamMember(index); 195 | struct team_member* team_member = GetActiveTeamMember(roster_index); 196 | if(ground_monster != NULL) 197 | StrncpySimple(ground_monster->name, result, 10); 198 | if(team_member != NULL) 199 | StrncpySimple(team_member->name, result, 10); 200 | SaveScriptVariableValueBytes(VAR_PARTNER_FIRST_NAME, result, 10); 201 | GLOBAL_MENU_INFO.return_val = 0; 202 | } 203 | 204 | // Add your custom script menus to the list below. 205 | // `create` is a pointer to the initial function that will run only once when a custom `message_Menu` runs. This is typically responsible for the initial creation of any windows. 206 | // `close` is a pointer to the final function that will run only once when a custom `message_Menu` runs. This is typically responsible for the final closing of any windows, as well as setting a return value if not yet set. 207 | // `update` is pointer to the function that will continously get called every frame when a custom `message_Menu` runs. This is typically responsible for checking the status of any menus and implementing control flow, i.e., "what happens if the player selects an option?" 208 | // `keyboard_prompt_string_id` is the Text String ID shown when a keyboard prompt is displayed. This may not be necessary for all menus. 209 | // `keyboard_confirm_string_id` is the Text String ID shown when confirming the player's keyboard input. This may not be necessary for all menus. 210 | // Custom script menus use ID 80 + . 211 | // 212 | // Refer to menus.h for more information on the fields of `custom_menu` and `global_menu_info`! 213 | struct custom_menu CUSTOM_MENUS[] = { 214 | // ID 80 215 | // Attempts to add a chosen Pokémon as a new member of Chimecho Assembly! 216 | // Returns: Chimecho Assembly index of the new recruit if successful. -1 if the player exits the menu, -2 if a new recruit could not be added. 217 | { 218 | .create = CreateRecruitAnyMonsterMenu, 219 | .close = CloseRecruitAnyMonsterMenu, 220 | .update = UpdateRecruitAnyMonsterMenu 221 | }, 222 | // ID 81 223 | // Prompts the player to input a password. 224 | // Returns: 0 if the player enters "shard" in the keyboard prompt, else otherwise. 225 | { 226 | #ifdef REGION_JP 227 | .keyboard_prompt_string_id = 15586, 228 | .keyboard_confirm_string_id = 951, 229 | #else 230 | .keyboard_prompt_string_id = 263, 231 | .keyboard_confirm_string_id = 431, 232 | #endif 233 | .create = CreateSimpleKeyboardMenu, 234 | .close = ClosePasswordMenu, 235 | .update = UpdateSimpleKeyboardMenu 236 | }, 237 | // ID 82 238 | // Prompts the player to rename the partner. 239 | // Returns: Nothing. 240 | { 241 | #ifdef REGION_JP 242 | .keyboard_prompt_string_id = 12749, 243 | .keyboard_confirm_string_id = 12758, 244 | #else 245 | .keyboard_prompt_string_id = 283, 246 | .keyboard_confirm_string_id = 292, 247 | #endif 248 | .create = CreateSimpleKeyboardMenu, 249 | .close = ClosePartnerNameMenu, 250 | .update = UpdateSimpleKeyboardMenu 251 | } 252 | }; 253 | 254 | struct global_menu_info GLOBAL_MENU_INFO; 255 | const int CUSTOM_MENU_AMOUNT = ARRAY_LENGTH(CUSTOM_MENUS); 256 | 257 | #endif 258 | -------------------------------------------------------------------------------- /LICENSE_GPLv3: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------