├── .gitignore ├── BPRE.sym ├── LICENSE.md ├── README.md ├── assets ├── indicators.png └── mega_trigger.png ├── debug ├── insert.py ├── linker.lsc ├── makefile ├── mega_trigger.c ├── mega_trigger.h ├── mega_trigger_disabled.c ├── mega_trigger_disabled.h ├── mega_trigger_on.c ├── mega_trigger_on.h ├── notes.md ├── patch.py ├── src ├── ai_trigger.s ├── anim.s ├── anim_script.c ├── animscript.h ├── animscript.s ├── battle.h ├── bs_command.c ├── button.c ├── common.h ├── config.h ├── evo.h ├── exit_battle_hook.s ├── faint_hook.s ├── graphics.h ├── healthbar.c ├── healthbar_hooks.s ├── healthbar_shaker_hooks.s ├── images │ ├── indicators.c │ ├── indicators.h │ ├── mega_trigger.c │ ├── mega_trigger.h │ ├── mega_trigger_disabled.c │ ├── mega_trigger_disabled.h │ ├── mega_trigger_on.c │ └── mega_trigger_on.h ├── level_string_hook.s ├── mega.c ├── mega.h ├── mega_level_icon.s ├── move_exec_hook.s ├── move_menu_hook.s ├── objects.h ├── pokemon.h ├── strings.c ├── strings.h ├── tables.h ├── text.h └── types.h └── symbol.png /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | \#*\# 3 | /.emacs.desktop 4 | /.emacs.desktop.lock 5 | *.elc 6 | auto-save-list 7 | tramp 8 | .\#* 9 | 10 | *.sgm 11 | *.sav 12 | *.gba 13 | build 14 | *.gch 15 | *.zip 16 | *.bak 17 | *.exe 18 | *.ips 19 | *.pyc 20 | src/images/* -------------------------------------------------------------------------------- /BPRE.sym: -------------------------------------------------------------------------------- 1 | exec_completed_tbl1 = 0x0802E33D; 2 | exec_completed_tbl2 = 0x08036531; 3 | pokemon_getattr = 0x0803FBE9; 4 | pokemon_setattr = 0x0804037D; 5 | recalc_stats = 0x0803E47D; 6 | gf_strcat = 0x08008DA5; 7 | battle_show_message = 0x080D87BD; 8 | buffer_str = 0x080D77F5; 9 | move_anim_start = 0x080341D9; 10 | ability_something = 0x08019F19; 11 | ability_something_2 = 0x08014CD9; 12 | a_pressed_maybe = 0x08002E65; 13 | build_cmdbuf_mega = 0x0800E801; 14 | mark_buffer_for_execution = 0x08017249; 15 | move_anim_task_del = 0x08072761; 16 | refresh_graphics_maybe = 0x080351A9; 17 | play_cry_maybe = 0x08071E61; 18 | task_add = 0x0807741D; 19 | task_is_running = 0x08077651; 20 | task_find_id_by_funcptr = 0x08077689; 21 | battle_side_get_owner = 0x080751C5; 22 | template_instanciate_forward_search = 0x08006F8D; 23 | gpu_tile_obj_decompress_alloc_tag_and_upload = 0x0800F035; 24 | font_get_width_of_string = 0x08005ED5; 25 | memcpy = 0x081E5E79; 26 | gpu_pal_obj_alloc_tag_and_apply = 0x08008929; 27 | play_sound = 0x080722CD; 28 | play_song = 0x08071A75; 29 | get_pingpong = 0x08044E31; 30 | int_to_str = 0x08008E79; 31 | gpu_pal_tags_index_of = 0x080089E9; 32 | healthbar_draw_field = 0x08049D99; 33 | var_access = 0x0806E455; 34 | checkitem = 0x08099F41; 35 | 36 | dp11_ptr = 0x02024018; 37 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 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 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 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 | {project} Copyright (C) {year} {fullname} 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | # Mega Evolutions 4 | This is a hack written mostly in C, but some parts (hook code) are in ASM. It 5 | aims to allow changing of species mid-battle for Mega Evolutiion and similar 6 | mechanics (Primal Reversion, etc.) 7 | 8 | ## Unix-like Installation 9 | - Make sure you have DevKitARM installed and its binaries in your path. 10 | - You'll also need `make` and Python3 11 | - Place a clean FireRed ROM called 'BPRE0.gba' in the project root. 12 | - Create a directory called 'build' in the project root. 13 | - Run `make && ./insert.py`. This will create test.gba in the project root. 14 | - For future builds you might want to run `make && ./insert.py && vba-sdl-h test.gba` to run the emulator after a successful build. 15 | 16 | ## Windows Installation 17 | - Make sure you have devkitARM installed and its binaries in your path 18 | - You'll also need `make` (Use the devkitPro installer for this and devkitARM) and Python3 19 | - Create a directory called 'build' in the project root, to go along with the 'assets' and 'src' folders. 20 | - Place a clean FireRed ROM called 'BPRE0.gba' in the project root. 21 | - Run `make && ./insert.py` in the project root through Command Prompt (Shift + Right Click -> Open Command window here). This will create test.gba in the project root. 22 | - For future builds you might want to run `make && ./insert.py && vba-sdl-h test.gba` to run the emulator after a successful build if the emulator is also in the project root. 23 | 24 | ## Credits 25 | - MrDollSteak: Animation Script and Graphics 26 | - Bela: Graphics 27 | - daniilS: Miscellaneous code fixes 28 | -------------------------------------------------------------------------------- /assets/indicators.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Touched/MegaEvolution/d98cdbd2339a4110711705dd9e46135b41f70e08/assets/indicators.png -------------------------------------------------------------------------------- /assets/mega_trigger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Touched/MegaEvolution/d98cdbd2339a4110711705dd9e46135b41f70e08/assets/mega_trigger.png -------------------------------------------------------------------------------- /debug: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | make DEFS="-DDISABLE_KEYSTONE_CHECK" && ./insert.py --no-patch --debug 4 | -------------------------------------------------------------------------------- /insert.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import os 4 | import subprocess 5 | import sys 6 | import shutil 7 | import binascii 8 | import textwrap 9 | import sys 10 | import argparse 11 | import patch 12 | 13 | if sys.version_info < (3, 4): 14 | print('Python 3.4 or later is required.') 15 | sys.exit(1) 16 | 17 | # Parse arguments 18 | parser = argparse.ArgumentParser() 19 | parser.add_argument('--no-patch', action='store_true', 20 | help='disable uninstall patch generation') 21 | parser.add_argument('--offset', metavar='offset', type=int, 22 | help='offset to insert at', default=0x800000) 23 | parser.add_argument('--input', metavar='file', 24 | help='input filename', default='BPRE0.gba') 25 | parser.add_argument('--output', metavar='file', 26 | help='output filename', default='test.gba') 27 | parser.add_argument('--debug', action='store_true', 28 | help='print symbol table') 29 | 30 | args = parser.parse_args() 31 | 32 | OBJCOPY = 'arm-none-eabi-objcopy' 33 | OBJDUMP = 'arm-none-eabi-objdump' 34 | NM = 'arm-none-eabi-nm' 35 | AS = 'arm-none-eabi-as' 36 | CC = 'arm-none-eabi-gcc' 37 | CXX = 'arm-none-eabi-g++' 38 | 39 | def get_text_section(): 40 | # Dump sections 41 | out = subprocess.check_output([OBJDUMP, '-t', 'build/linked.o']) 42 | lines = out.decode().split('\n') 43 | 44 | # Find text section 45 | text = filter(lambda x: x.strip().endswith('.text'), lines) 46 | section = list(text)[0] 47 | 48 | # Get the offset 49 | offset = int(section.split(' ')[0], 16) 50 | 51 | return offset 52 | 53 | def symbols(subtract=0): 54 | out = subprocess.check_output([NM, 'build/linked.o']) 55 | lines = out.decode().split('\n') 56 | 57 | name = '' 58 | 59 | ret = {} 60 | for line in lines: 61 | parts = line.strip().split() 62 | 63 | if (len(parts) < 3): 64 | continue 65 | 66 | if (parts[1].lower() != 't'): 67 | continue 68 | 69 | offset = int(parts[0], 16) 70 | ret[parts[2]] = offset - subtract 71 | 72 | return ret 73 | 74 | def insert(rom): 75 | where = args.offset 76 | rom.seek(where) 77 | with open('build/output.bin', 'rb') as binary: 78 | data = binary.read() 79 | rom.write(data) 80 | return where 81 | 82 | def hook(rom, space, hook_at, register=0): 83 | # Align 2 84 | if hook_at & 1: 85 | hook_at -= 1 86 | 87 | rom.seek(hook_at) 88 | 89 | register &= 7 90 | 91 | if hook_at % 4: 92 | data = bytes([0x01, 0x48 | register, 0x00 | (register << 3), 0x47, 0x0, 0x0]) 93 | else: 94 | data = bytes([0x00, 0x48 | register, 0x00 | (register << 3), 0x47]) 95 | 96 | space += 0x08000001 97 | data += (space.to_bytes(4, 'little')) 98 | rom.write(bytes(data)) 99 | 100 | shutil.copyfile(args.input, args.output) 101 | with open(args.output, 'rb+') as rom: 102 | offset = get_text_section() 103 | table = symbols(offset) 104 | where = insert(rom) 105 | 106 | # Adjust symbol table 107 | for entry in table: 108 | table[entry] += where 109 | 110 | hook(rom, table['command'], 0x033224, 2) 111 | hook(rom, table['command'], 0x038A50, 2) # 08250A34 112 | hook(rom, table['move_button_hook'], 0x02EC10, 0) 113 | hook(rom, table['exit_battle_hook'], 0x0159DC, 0) 114 | hook(rom, table['faint_hook'], 0x0326C4, 3) 115 | hook(rom, table['level_string_hook'], 0x0483A4, 1) 116 | #hook(rom, table['mega_level_icon_hook'], 0x049E18, 1) 117 | hook(rom, table['load_graphics_hook'], 0x03495C, 1) 118 | #hook(rom, table['show_graphics_hook'], 0x047FD8, 1) 119 | # Add the fucking animation 120 | #loc = table['mega_animation_script_data'] + 0x08000000 121 | #move_index = 33 # tackle 122 | #rom.seek(move_index * 4 + 0x1C68F4) 123 | #rom.write(loc.to_bytes(4, 'little')) 124 | 125 | # AI 126 | hook(rom, table['ai_move_hook'], 0x038668, 0) 127 | 128 | # Stupid 129 | hook(rom, table['create_shaker_hook'], 0x04BE80, 3) 130 | hook(rom, table['objc_shaker_hook'], 0x04BEDC, 2) 131 | hook(rom, table['battle_menu_hook'], 0x02E438, 0) 132 | 133 | # Main 134 | #hook(rom, table['attack_canceller_hook'], 0x01DB00, 1) 135 | hook(rom, table['bc_pre_attacks_hook'], 0x0154A0, 0) 136 | 137 | if args.debug: 138 | width = max(map(len, table.keys())) + 1 139 | for key in sorted(table.keys()): 140 | fstr = ('{:' + str(width) + '} {:08X}') 141 | print(fstr.format(key + ':', table[key] + 0x08000000)) 142 | 143 | # Create a patch to remove these changes 144 | if not args.no_patch: 145 | patch.create(args.output, args.input, 'uninstall.ips', patch.ips) 146 | 147 | -------------------------------------------------------------------------------- /linker.lsc: -------------------------------------------------------------------------------- 1 | OUTPUT_ARCH(arm) 2 | MEMORY { 3 | 4 | rom : ORIGIN = 0x08800000, LENGTH = 32M 5 | ewram : ORIGIN = 0x02000000, LENGTH = 4M - 4k 6 | } 7 | 8 | SECTIONS { 9 | .text : { 10 | 11 | FILL (0xABCD) 12 | 13 | __text_start = . ; 14 | *(.init) 15 | *(.text) 16 | *(.ctors) 17 | *(.dtors) 18 | *(.rodata) 19 | *(.fini) 20 | *(COMMON) 21 | __text_end = . ; 22 | 23 | __bss_start__ = . ; 24 | *(.bss) 25 | __bss_end__ = . ; 26 | _end = __bss_end__ ; 27 | __end__ = __bss_end__ ; 28 | } >rom = 0xff 29 | } 30 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | CC=arm-none-eabi-gcc 2 | CXX=arm-none-eabi-gcc 3 | AS=arm-none-eabi-as 4 | LD=arm-none-eabi-ld 5 | OBJCOPY=arm-none-eabi-objcopy 6 | OBJDUMP=arm-none-eabi-objcopy 7 | 8 | DEFINES=-DBPRE -DSOFTWARE_VERSION=0 $(DEFS) 9 | CFLAGS=-mthumb -mno-thumb-interwork -mcpu=arm7tdmi -fno-inline -mlong-calls -march=armv4t -Wall -O2 $(DEFINES) 10 | CXXFLAGS=-mthumb -mthumb-interwork -mcpu=arm7tdmi -mlong-calls -march=armv4t -Wall -O2 $(DEFINES) 11 | ASFLAGS=-mthumb 12 | LDFLAGS=-z muldefs 13 | 14 | all: command move_exec_hook anim strings mega button revert_hook level_string_hook images static_assets shaker_hooks ai_hook 15 | $(LD) $(LDFLAGS) -T linker.lsc -T BPRE.sym -o build/linked.o build/bs_command.o build/anim.o build/anim_script.o build/animscript.o build/move_exec_hook.o build/strings.o build/mega.o build/move_menu_hook.o build/button.o build/exit_battle_hook.o build/faint_hook.o build/healthbar.o build/healthbar_hooks.o build/images_indicators.o build/images_mega_trigger.o build/level_string_hook.o build/healthbar_shaker_hooks.o build/ai_trigger.o 16 | $(OBJCOPY) -O binary build/linked.o build/output.bin 17 | 18 | static_assets: 19 | $(CC) $(CFLAGS) -c src/images/indicators.c -o build/images_indicators.o 20 | $(CC) $(CFLAGS) -c src/images/mega_trigger.c -o build/images_mega_trigger.o 21 | 22 | images: 23 | grit assets/indicators.png -gzl -gB 4 -ftc -fh -pe16 -pT4 -gu8 -o src/images/indicators.c 24 | grit assets/mega_trigger.png -gzl -gB 4 -ftc -fh -pe16 -pT9 -gu8 -o src/images/mega_trigger.c 25 | 26 | command: 27 | $(CC) $(CFLAGS) -c src/bs_command.c -o build/bs_command.o 28 | 29 | anim: 30 | $(AS) $(AFLAGS) -c src/anim.s -o build/anim.o 31 | $(AS) $(AFLAGS) -c src/animscript.s -o build/animscript.o 32 | $(CC) $(CFLAGS) -c src/anim_script.c -o build/anim_script.o 33 | 34 | strings: 35 | $(CC) $(CFLAGS) -c src/strings.c -o build/strings.o 36 | 37 | mega: 38 | $(CC) $(CFLAGS) -c src/mega.c -o build/mega.o 39 | 40 | move_exec_hook: 41 | $(AS) $(AFLAGS) -c src/move_exec_hook.s -o build/move_exec_hook.o 42 | $(CC) $(CFLAGS) -c src/button.c -o build/button.o 43 | 44 | level_string_hook: 45 | $(AS) $(AFLAGS) -c src/healthbar_hooks.s -o build/healthbar_hooks.o 46 | $(CC) $(CFLAGS) -c src/healthbar.c -o build/healthbar.o 47 | $(AS) $(AFLAGS) -c src/level_string_hook.s -o build/level_string_hook.o 48 | 49 | revert_hook: 50 | $(AS) $(AFLAGS) -c src/exit_battle_hook.s -o build/exit_battle_hook.o 51 | $(AS) $(AFLAGS) -c src/faint_hook.s -o build/faint_hook.o 52 | 53 | ai_hook: 54 | $(AS) $(AFLAGS) -c src/ai_trigger.s -o build/ai_trigger.o 55 | 56 | shaker_hooks: 57 | $(AS) $(AFLAGS) -c src/healthbar_shaker_hooks.s -o build/healthbar_shaker_hooks.o 58 | 59 | button: 60 | $(AS) $(AFLAGS) -c src/move_menu_hook.s -o build/move_menu_hook.o 61 | 62 | 63 | -------------------------------------------------------------------------------- /mega_trigger.c: -------------------------------------------------------------------------------- 1 | 2 | //{{BLOCK(mega_trigger) 3 | 4 | //====================================================================== 5 | // 6 | // mega_trigger, 32x32@4, 7 | // + palette 16 entries, not compressed 8 | // + 16 tiles lz77 compressed 9 | // Total size: 32 + 224 = 256 10 | // 11 | // Time-stamp: 2015-06-23, 20:50:16 12 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 13 | // ( http://www.coranac.com/projects/#grit ) 14 | // 15 | //====================================================================== 16 | 17 | const unsigned char mega_triggerTiles[224] __attribute__((aligned(4))) __attribute__((visibility("hidden")))= 18 | { 19 | 0x10,0x00,0x02,0x00,0x3E,0x00,0x00,0xF0,0x01,0xF0,0x01,0xF0,0x01,0xF0,0x01,0xA0, 20 | 0x05,0x82,0x0A,0x00,0x20,0x88,0x88,0x00,0x02,0x88,0xC0,0x1B,0x20,0xFF,0x00,0x1A, 21 | 0x00,0x15,0x70,0x02,0xF0,0x3B,0xE0,0x01,0x00,0x33,0x00,0x4F,0x00,0x50,0x17,0x00, 22 | 0x00,0x80,0x00,0x4F,0x82,0x00,0x53,0x10,0x57,0x30,0x03,0x80,0x30,0x4C,0xF8,0x33, 23 | 0x88,0xF8,0xE3,0xEE,0x88,0x00,0x7F,0x77,0x37,0x38,0xAA,0x3A,0xA3,0xF8,0x00,0xDD, 24 | 0xD3,0x33,0xD3,0x3D,0x33,0xDD,0x63,0x15,0x36,0x33,0x33,0x10,0x6C,0x83,0x00,0x67, 25 | 0xFE,0x00,0x04,0x00,0x33,0xF7,0x88,0x88,0xA3,0xAA,0x83,0x88,0x00,0xD3,0xDD,0x8F, 26 | 0x88,0x33,0xDD,0x3D,0x88,0x1F,0x36,0x66,0x36,0xF0,0x7F,0xE0,0x01,0x70,0x6B,0x30, 27 | 28 | 0x7B,0x10,0x83,0xC0,0x10,0x8B,0x10,0x93,0x00,0x20,0xB3,0xBB,0xB3,0x3B,0x00,0x1F, 29 | 0x11,0x33,0x13,0x38,0x44,0x34,0x33,0x02,0xF8,0x55,0x35,0x35,0x88,0x9F,0x00,0x73, 30 | 0xF8,0x28,0xCF,0xCC,0x00,0x93,0xFF,0x10,0xE8,0x33,0xB3,0x3B,0x00,0x88,0x33,0x13, 31 | 0xF1,0x88,0x34,0x44,0x83,0x00,0x88,0x53,0x55,0x8F,0x88,0x99,0xF9,0x88,0x07,0x88, 32 | 0xFC,0x8F,0x88,0x88,0x00,0x02,0xF0,0xFF,0xF0,0x01,0xFF,0xF0,0x01,0xD1,0x1C,0x10, 33 | 0x43,0x01,0x6B,0x40,0x8F,0xF0,0xBD,0x91,0x6B,0x20,0x27,0xC0,0x20,0xBB,0x60,0x01, 34 | }; 35 | 36 | const unsigned short mega_triggerPal[16] __attribute__((aligned(4))) __attribute__((visibility("hidden")))= 37 | { 38 | 0x0000,0x2680,0x424F,0x18C6,0x0EC8,0x0B30,0x5E80,0x55B7, 39 | 0x31AA,0x0777,0x5DF0,0x4280,0x23BC,0x6644,0x55FC,0x18C7, 40 | }; 41 | 42 | //}}BLOCK(mega_trigger) 43 | -------------------------------------------------------------------------------- /mega_trigger.h: -------------------------------------------------------------------------------- 1 | 2 | //{{BLOCK(mega_trigger) 3 | 4 | //====================================================================== 5 | // 6 | // mega_trigger, 32x32@4, 7 | // + palette 16 entries, not compressed 8 | // + 16 tiles lz77 compressed 9 | // Total size: 32 + 224 = 256 10 | // 11 | // Time-stamp: 2015-06-23, 20:50:16 12 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 13 | // ( http://www.coranac.com/projects/#grit ) 14 | // 15 | //====================================================================== 16 | 17 | #ifndef GRIT_MEGA_TRIGGER_H 18 | #define GRIT_MEGA_TRIGGER_H 19 | 20 | #define mega_triggerTilesLen 224 21 | extern const unsigned char mega_triggerTiles[224]; 22 | 23 | #define mega_triggerPalLen 32 24 | extern const unsigned short mega_triggerPal[16]; 25 | 26 | #endif // GRIT_MEGA_TRIGGER_H 27 | 28 | //}}BLOCK(mega_trigger) 29 | -------------------------------------------------------------------------------- /mega_trigger_disabled.c: -------------------------------------------------------------------------------- 1 | 2 | //{{BLOCK(mega_trigger_disabled) 3 | 4 | //====================================================================== 5 | // 6 | // mega_trigger_disabled, 32x32@4, 7 | // 8 | // Time-stamp: 2015-06-23, 20:49:00 9 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 10 | // ( http://www.coranac.com/projects/#grit ) 11 | // 12 | //====================================================================== 13 | 14 | //}}BLOCK(mega_trigger_disabled) 15 | -------------------------------------------------------------------------------- /mega_trigger_disabled.h: -------------------------------------------------------------------------------- 1 | 2 | //{{BLOCK(mega_trigger_disabled) 3 | 4 | //====================================================================== 5 | // 6 | // mega_trigger_disabled, 32x32@4, 7 | // 8 | // Time-stamp: 2015-06-23, 20:49:00 9 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 10 | // ( http://www.coranac.com/projects/#grit ) 11 | // 12 | //====================================================================== 13 | 14 | #ifndef GRIT_MEGA_TRIGGER_DISABLED_H 15 | #define GRIT_MEGA_TRIGGER_DISABLED_H 16 | 17 | #endif // GRIT_MEGA_TRIGGER_DISABLED_H 18 | 19 | //}}BLOCK(mega_trigger_disabled) 20 | -------------------------------------------------------------------------------- /mega_trigger_on.c: -------------------------------------------------------------------------------- 1 | 2 | //{{BLOCK(mega_trigger_on) 3 | 4 | //====================================================================== 5 | // 6 | // mega_trigger_on, 32x32@4, 7 | // 8 | // Time-stamp: 2015-06-23, 20:49:00 9 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 10 | // ( http://www.coranac.com/projects/#grit ) 11 | // 12 | //====================================================================== 13 | 14 | //}}BLOCK(mega_trigger_on) 15 | -------------------------------------------------------------------------------- /mega_trigger_on.h: -------------------------------------------------------------------------------- 1 | 2 | //{{BLOCK(mega_trigger_on) 3 | 4 | //====================================================================== 5 | // 6 | // mega_trigger_on, 32x32@4, 7 | // 8 | // Time-stamp: 2015-06-23, 20:49:00 9 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 10 | // ( http://www.coranac.com/projects/#grit ) 11 | // 12 | //====================================================================== 13 | 14 | #ifndef GRIT_MEGA_TRIGGER_ON_H 15 | #define GRIT_MEGA_TRIGGER_ON_H 16 | 17 | #endif // GRIT_MEGA_TRIGGER_ON_H 18 | 19 | //}}BLOCK(mega_trigger_on) 20 | -------------------------------------------------------------------------------- /notes.md: -------------------------------------------------------------------------------- 1 | # Bugs & Notes 2 | 3 | - Mega stones can be stolen, swapped, thrown, given or otherwise removed by Thief, Covet, Trick, Switcheroo, Knock Off, Bestow, Fling, etc. Should look at Sticky Hold or Suction Cups to fix. Mail might also hold some answers 4 | - 08020D26 and 0802C224 5 | - Primal Evolutions have not been added. -------------------------------------------------------------------------------- /patch.py: -------------------------------------------------------------------------------- 1 | def changesets(base, mod): 2 | length = 0 3 | loc = 0 4 | 5 | for off, change in enumerate(zip(base, mod)): 6 | if change[0] == change[1]: 7 | if length: 8 | yield loc, length 9 | length = 0 10 | else: 11 | if length: 12 | length += 1 13 | else: 14 | # Start counting 15 | loc = off 16 | length = 1 17 | 18 | 19 | def limit(changes, maxlen): 20 | for change in changes: 21 | if change[1] > maxlen: 22 | yield change[0], maxlen 23 | change = (change[0] + maxlen, change[1] - maxlen) 24 | yield change 25 | 26 | 27 | def ips(base, mod): 28 | # Get biggest filesize 29 | if len(base) != len(mod): 30 | raise ValueError('Files must be the same size') 31 | 32 | if len(base) > (2 ** 32): 33 | raise ValueError('Files are too large') 34 | 35 | # Check if we need 32 bit address space 36 | ips32 = len(base) > (2 ** 24) 37 | 38 | magic = 'IPS32' if ips32 else 'PATCH' 39 | yield magic.encode() 40 | 41 | # Look for changes 42 | changes = limit(changesets(base, mod), 0xFFFF) 43 | for change in changes: 44 | data = mod[change[0]:change[0] + change[1]] 45 | offset = change[0].to_bytes(4 if ips32 else 3, 'big') 46 | length = change[1].to_bytes(2, 'big') 47 | block = offset + length + data 48 | yield block 49 | 50 | footer = 'EOFF' if ips32 else 'EOF' 51 | yield footer.encode() 52 | 53 | 54 | def create(base_file, mod_file, patch_file, gen): 55 | with open(base_file, 'rb') as base: 56 | with open(mod_file, 'rb') as modf: 57 | with open(patch_file, 'wb') as patch: 58 | base = base.read() 59 | modf = modf.read() 60 | for blob in gen(base, modf): 61 | patch.write(blob) 62 | 63 | -------------------------------------------------------------------------------- /src/ai_trigger.s: -------------------------------------------------------------------------------- 1 | .thumb 2 | 3 | @ at 08038668 in r0 4 | .align 2 5 | ai_move_hook: 6 | bl ai_trigger_mega_evolution 7 | 8 | ldr r0, =(0x0803870E + 1) 9 | bx r0 10 | -------------------------------------------------------------------------------- /src/anim.s: -------------------------------------------------------------------------------- 1 | @ Modded function to load an animation script from a pointer rather than a table 2 | @ I was surpised that this didn't exist, but it appears GF has a fetish for code 3 | @ duplication. 4 | 5 | .thumb 6 | .global animation_script_start 7 | 8 | @ void animation_script_start(u8 *script, u8 attacker, u8 defender) 9 | .align 2 10 | 11 | @ Essential 12 | .thumb_func 13 | animation_script_start: 14 | push {r4, lr} 15 | 16 | ldr r3, =0x02037F1A 17 | strb r1, [r3] 18 | ldr r3, =0x02037F1B 19 | strb r2, [r3] 20 | 21 | @ Rest of the function needs this (after continue) 22 | mov r4, r1 23 | 24 | @ Create pointer to animation script (table with single entry) 25 | push {r0} 26 | 27 | @ Index zero (first entry in above created table) 28 | mov r1, #0 29 | 30 | @ Call function 31 | mov r0, sp 32 | mov r2, #0 33 | ldr r3, =(0x080725D4 + 1) 34 | bl call_via_r3 35 | 36 | @ Fix the stack 37 | pop {r0} 38 | 39 | @ Continue 40 | ldr r3, =(0x080341F6 + 1) 41 | bx r3 42 | 43 | call_via_r3: 44 | bx r3 45 | 46 | -------------------------------------------------------------------------------- /src/anim_script.c: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "animscript.h" 3 | #include "common.h" 4 | #include "battle.h" 5 | 6 | #define MEGA_ANIM_PARTICLE_RAINBOW 1 7 | #define MEGA_ANIM_PARTICLE_STONE 2 8 | #define MEGA_ANIM_PARTICLE_SYMBOL 3 9 | 10 | #define RAINBOW_X_LINE(a,b,c) 0x2, ANIM_LONG(anim_rainbow_y), \ 11 | 0x2, 0x3, a, b, c, 0xFF, 0xD, 0x0, 0x4, 0x3 12 | 13 | extern u8 *mega_animation_script; 14 | 15 | // 08071E60 - could be playing the cry 16 | u8 anim_script[] = { 17 | // Load Mega Stone 18 | 19 | 3, 20 | ANIM_LONG(0x080F1420 + 1), 21 | 2, 22 | 1, 23 | ANIM_SHORT(1), 24 | 25 | //4, 10, 26 | 27 | // Play cry 28 | // 0x3, ANIM_LONG(0x80DD148 + 1), 1, 2, ANIM_SHORT(0), ANIM_SHORT(0xFF), 29 | 8 30 | }; 31 | 32 | // From anim.s 33 | void animation_script_start(u8 *script, u8 attacker, u8 defender); 34 | 35 | // TODO: Verify this works for all abilities that should activate upon evolution 36 | u8 ability_fix_cb() { 37 | if (!(ability_something(0, 0, 0, 0, 0) << 24) ) { 38 | ability_something(0, 0, 0, b_attackers_in_order[*(dp08 + 0x4C)], 0); 39 | ability_something(9, 0, 0, b_attackers_in_order[*(dp08 + 0x4C)], 0); 40 | } 41 | 42 | *b_c = *bc_backup; 43 | } 44 | 45 | void ability_fix() { 46 | // Fixes abilities that run on enter (Drought, etc.) 47 | *(dp08 + 0x4C) = 0; 48 | *(dp08 + 0xD9) = 0; 49 | *(dp08 + 0xB6) = 0; 50 | 51 | // ability_something resets b_c, so Remember the old b_c 52 | *bc_backup = *b_c; 53 | 54 | // Use wrapper function 55 | *b_c = ((bxcb) ability_fix_cb); 56 | } 57 | 58 | void play_mega_evolution(u8 attacker, u8 defender) { 59 | animation_script_start(mega_animation_script, attacker, attacker); 60 | 61 | // Fix abilities that activate when switching (intimidate, weather abilities, etc.) 62 | // do not work 63 | ability_fix(); 64 | } 65 | 66 | // Declare the functions all here because lazy 67 | void move_anim_task_del(u8 index); 68 | void refresh_graphics_maybe(u8, u8, u8); 69 | 70 | typedef struct task { 71 | u32 function; 72 | u8 in_use; 73 | u8 prev; 74 | u8 next; 75 | u8 priority; 76 | u16 args[16]; 77 | } task; 78 | 79 | typedef void (*task_func)(u8); 80 | 81 | task *tasks = (task*) 0x03005090; 82 | u8 task_add(task_func, u8 priority); 83 | u8 task_find_id_by_funcptr(task_func); 84 | u8 task_is_running(u8 index); 85 | 86 | // Actual function 87 | void task_ma_swap_sprites(u8 index) { 88 | u8 s = battle_side_objid_P_and_priv5_for_dp11b3[*b_anim_attacker]; 89 | 90 | task *me = &tasks[index]; 91 | task *t; 92 | u8 find_index; 93 | u8 next = 0; 94 | 95 | switch (me->args[10]) { 96 | case 0: 97 | // To fix an annoying graphical glitch where the old sprite would flash 98 | // momentarily, we hide the sprite offscreen while we refresh it. 99 | // Remember the old position so we can go back to it later. 100 | me->args[11] = *(s16*)(0x0202063C + s * 0x44 + 0x20); 101 | *(s16*)(0x0202063C + s * 0x44 + 0x20) = -64; 102 | 103 | // Load the palette and graphics. Note this doesn't cause the sprite to 104 | // refresh 105 | refresh_graphics_maybe(*b_anim_attacker, 1, s); 106 | next = 1; 107 | break; 108 | case 1: 109 | // Actually update the sprite now 110 | *(u8*)(0x0202063C + s * 0x44 + 0x3E) &= 0xFB; 111 | t = &tasks[task_add((task_func) 0x0807331C + 1, 5)]; 112 | t->args[0] = 0; 113 | t->args[2] = *b_anim_attacker; 114 | next = 1; 115 | break; 116 | case 2: 117 | // Make sure the task is done. I'm not sure if this is necessary 118 | find_index = task_find_id_by_funcptr((task_func) 0x0807331C + 1); 119 | if (!task_is_running(find_index)) { 120 | next = 1; 121 | } 122 | break; 123 | case 3: 124 | // Restore the old X position and end the task 125 | *(s16*)(0x0202063C + s * 0x44 + 0x20) = me->args[11]; 126 | move_anim_task_del(index); 127 | break; 128 | } 129 | 130 | // Update the state 131 | if (next) { 132 | me->args[10]++; 133 | } 134 | } 135 | 136 | void play_cry_maybe(u16 species); 137 | u8 battle_side_get_owner(u8 index); 138 | u8 *b_pokemon_team_id_by_side = (u8*) 0x02023BCE; 139 | u8 *party_player = (u8*) 0x02024284; 140 | u8 *party_opponent = (u8*) 0x0202402C; 141 | 142 | void task_ma_cry(u8 index) { 143 | u16 species = b_data[*b_anim_attacker].species; 144 | 145 | // Play the cry and end the task immediately 146 | play_cry_maybe(species); 147 | move_anim_task_del(index); 148 | } 149 | -------------------------------------------------------------------------------- /src/animscript.h: -------------------------------------------------------------------------------- 1 | #ifndef ANIM_SCRIPT_H_ 2 | #define ANIM_SCRIPT_H_ 3 | 4 | #include "types.h" 5 | 6 | // Basic types 7 | #define ANIM_LONG(x) (u8) (((u32) (x)) & 0xFF), \ 8 | (u8) ((((u32) (x)) & 0xFF00) >> 8), \ 9 | (u8) ((((u32) (x)) & 0xFF0000) >> 16), \ 10 | (u8) ((((u32) (x)) & 0xFF000000) >> 24) 11 | 12 | #define ANIM_SHORT(x) (u8) (((u32) (x)) & 0xFF), \ 13 | (u8) ((((u32) (x)) & 0xFF00) >> 8) 14 | 15 | // Script commands 16 | // Table at 083ADF5C 17 | #define ANIM_LOAD_GRAPHICS(a, b) 0, ANIM_SHORT(a), ANIM_SHORT(b) 18 | // 1 19 | // 2 20 | 21 | // word: funcptr 22 | // byte: priority (of task) 23 | // byte: length 24 | // short[lenth]: data 25 | #define ANIM_CALLASM(a, b, c) ANIM_LONG(a), b, c // 17 bytes 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/animscript.s: -------------------------------------------------------------------------------- 1 | .global mega_animation_script 2 | 3 | .equ ANIM_XX, 0x27a3 4 | .equ ANIM_YY, 0x281b 5 | .equ ANIM_ZZ, 0x27d8 6 | 7 | .align 2 8 | anim_rainbow_y: 9 | .short ANIM_XX, ANIM_XX 10 | .byte 0x50, 0xcb, 0x3a, 0x8, 0x40, 0x2a, 0x3e, 0x8, 0x0, 0x0, 0x0, 0x0 11 | .byte 0x54, 0x2a, 0x3e, 0x8, 0x89, 0x23, 0xa, 0x8 12 | 13 | .align 2 14 | anim_rainbow_x: 15 | .byte 0x2 16 | .long anim_rainbow_y 17 | .byte 0x2, 0x3, 0x28, 0x0, 0xF6, 0xFF, 0xD, 0x0, 0x4, 0x3 18 | 19 | .byte 0x2 20 | .word anim_rainbow_y 21 | .byte 0x2, 0x3, 0xDD, 0xFF, 0xF6, 0xFF, 0xD, 0x0, 0x4, 0x3 22 | 23 | .byte 0x2 24 | .word anim_rainbow_y 25 | .byte 0x2, 0x3, 0xF, 0x0, 0xD8, 0xFF, 0xD, 0x0, 0x4, 0x3 26 | 27 | .byte 0x2 28 | .word anim_rainbow_y 29 | .byte 0x2, 0x3, 0xF6, 0xFF, 0xE0, 0xFF, 0xD, 0x0, 0x4, 0x3 30 | 31 | .byte 0x2 32 | .word anim_rainbow_y 33 | .byte 0x2, 0x3, 0x19, 0x0, 0xEC, 0xFF, 0xD, 0x0, 0x4, 0x3 34 | 35 | .byte 0x2 36 | .word anim_rainbow_y 37 | .byte 0x2, 0x3, 0xD8, 0xFF, 0xEC, 0xFF, 0xD, 0x0, 0x4, 0x3 38 | 39 | .byte 0x2 40 | .word anim_rainbow_y 41 | .byte 0x2, 0x3, 0x5, 0x0, 0xD8, 0xFF, 0xD, 0x0, 0x4, 0x3 42 | 43 | .byte 0xf 44 | 45 | .align 2 46 | anim_mega_stone_x: 47 | .short ANIM_YY, ANIM_YY 48 | .byte 0xc0, 0xcb, 0x3a, 0x8, 0xf0, 0x1c, 0x23, 0x8, 0x0, 0x0, 0x0, 0x0 49 | .byte 0x44, 0x71, 0x3e, 0x8, 0x9d, 0x5d, 0x7, 0x8 50 | 51 | .align 2 52 | anim_mega_symbol_x: 53 | .short ANIM_ZZ, ANIM_ZZ 54 | .byte 0xf8, 0xca, 0x3a, 0x8, 0xf0, 0x1c, 0x23, 0x8, 0x0, 0x0, 0x0, 0x0 55 | .byte 0xfc, 0x1c, 0x23, 0x8, 0xd5, 0x67, 0xb, 0x8 56 | 57 | .align 2 58 | mega_animation_script_data: 59 | @ Buffer particles 60 | .byte 0 61 | .short ANIM_XX 62 | .byte 0 63 | .short ANIM_YY 64 | .byte 0 65 | .short ANIM_ZZ 66 | 67 | @ Charge Rainbow Particles 68 | .byte 0xa, 0x2, 0xc, 0xc, 0x8, 0x1c, 0x85, 0x0, 0xc0, 0xd, 0x3, 0x3, 0xdd, 0x9b, 0xb, 0x8 69 | .byte 0x2, 0x6, 0x2, 0x0, 0x0, 0x0, 0x6, 0x0, 0x0, 0x0, 0xb, 0x0, 0xff, 0x2f 70 | .byte 0xE 71 | .word anim_rainbow_x 72 | .byte 0xE 73 | .word anim_rainbow_x 74 | .byte 0xE 75 | .word anim_rainbow_x 76 | .byte 0x5, 0xB 77 | 78 | @ Load Mega Stone 79 | .byte 0x2 @ leftover from previous? 80 | .byte 0xd 81 | .byte 0x4, 0x0 82 | .byte 0x17 83 | .byte 0xa, 0x0 84 | .byte 0xc, 0xc, 0x8 @ set_blend 85 | .byte 0x19, 0xc2, 0x0, 0xc0 @ play sound I guess 86 | .byte 0x2 @ init_template 87 | .word anim_mega_stone_x @ ... 88 | .byte 0x29, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 @ ... 89 | 90 | @ Whiteout Screen 91 | .byte 0x4, 0x14 @ wait 92 | .byte 0x3, 0x3d, 0xa8, 0xb, 0x8, 0x5, 0x5, 0x5, 0x0, 0x2, 0x0, 0x0, 0x0 @ something_template 93 | .byte 0x10, 0x0, 0xff, 0xff @ ... 94 | .byte 0x3, 0x21, 0xaa, 0xb, 0x8, 0x5, 0x5 @ something_template 95 | .short ANIM_YY @ ... 96 | .byte 0x2, 0x0, 0x0, 0x0 @ ... 97 | .byte 0x10, 0x0, 0xff, 0xff @ ... 98 | .byte 0x5 @ wait 99 | .byte 0x3, 0x21, 0xaa, 0xb, 0x8, 0x5 @ something_template 100 | .byte 0x0 101 | 102 | @ Yay Update Sprite 103 | .byte 3 104 | .word task_ma_swap_sprites + 1 @ C function in anim_script 105 | .byte 2, 0 106 | @.byte 0xb, 0x2 @ Trigger refresh 107 | @.byte 3 108 | @.word 0x80BAA4C + 1 109 | @.byte 3, 0 110 | 111 | @ Return Screen 112 | @.byte 0x5 @ wait 113 | @ 114 | .byte 0x3, 0x3d, 0xa8, 0xb, 0x8, 0x5, 0x5, 0x5, 0x0, 0x2, 0x0, 0x10, 0x0 @ something_template 115 | .byte 0x0, 0x0, 0xff, 0xff @ ... 116 | @ .byte 0x1, 0x0, 0x5 @ ??? 117 | @.byte 0x0, 0xe, 0x0 @ load_graphics 118 | .byte 0x5 @ wait 119 | 120 | .byte 0x3, 0xb5, 0x94, 0xb, 0x8, 0x5, 0x3, 0x1, 0x0, 0x5, 0x0, 0xe, 0x0 121 | 122 | @ Play cry of new species 123 | .byte 0x3 124 | .word task_ma_cry + 1 125 | .byte 1, 2 126 | .short 0, 0xFF 127 | 128 | .byte 0x5, 0xb 129 | @ Show Mega Evolution Symbol 130 | .byte 0x2 131 | @ 0x4, 0x1, 0xa, 0x3, 0x19, 0x72, 0x0, 0x3f 132 | .byte 0x2 133 | .word anim_mega_symbol_x 134 | .byte 0x82, 0x0 135 | .byte 0x5, 0xb, 0xd 136 | 137 | 138 | 139 | @ End 140 | .byte 0x8 141 | 142 | @ C function requires a pointer to the script data 143 | .align 2 144 | mega_animation_script: .long mega_animation_script_data 145 | -------------------------------------------------------------------------------- /src/battle.h: -------------------------------------------------------------------------------- 1 | #ifndef BATTLE_H_ 2 | #define BATTLE_H_ 3 | 4 | #include "types.h" 5 | 6 | #pragma pack(push, 1) 7 | typedef struct battle_data 8 | { 9 | u16 species; 10 | u16 stats[5]; 11 | u16 move_ids[4]; 12 | u32 ivs; 13 | u8 stat_buffs[8]; 14 | u8 ability_id; 15 | u8 type1; 16 | u8 type2; 17 | u8 padding; 18 | u8 current_pp[4]; 19 | u16 current_hp; 20 | u8 level; 21 | u8 happiness; 22 | u16 max_hp; 23 | u16 held_item; 24 | char name[11]; 25 | u8 field_3B; 26 | u8 trainer_name[8]; 27 | u32 padding3; 28 | u32 pid; 29 | u32 status1; 30 | u32 status2; 31 | u32 otid; 32 | } battle_data; 33 | #pragma pack(pop) 34 | 35 | typedef void (*bxcb)(void); 36 | 37 | u8 *b_active_side = (u8*) 0x02023BC4; 38 | u8 *b_attacker = (u8*) 0x02023D6B; 39 | u8 *b_defender = (u8*) 0x02023D6C; 40 | u8 *b_current_bank = (u8*) 0x02023D6F; 41 | u8 *team = (u8*) 0x02024284; 42 | u8 *enemy_team = (u8*) 0x0202402C; 43 | //battle_data *bdata = (battle_data *) (0x02023BE4); 44 | u32 *battle_type_flags = (u32*) (0x02022B4C); 45 | u8 *b_num_active_sides = (u8*) 0x02023BCC; 46 | u32 *b_x = (u32 *) 0x03004FE0; 47 | bxcb *b_c = (bxcb*) 0x03004F84; 48 | u8 **dp08_ptr = (u8**) 0x02023FE8; 49 | bxcb *bx = ((bxcb*) 0x03004FE0); 50 | u16 *team_index_by_side = (u16*) 0x02023BCE; 51 | u8 *battle_side_objid_P_and_priv5_for_dp11b3 = (u8*) 0x02023D44; 52 | u8 *b_anim_attacker = (u8*) 0x02037F1A; 53 | u8 *buffer_As = (u8*) 0x02022BC4; 54 | u8 *b_attackers_in_order = (u8 *) 0x02023BDE; 55 | battle_data *b_data = (battle_data *) 0x02023BE4; 56 | 57 | // u8 *b_attackers_in_order = (u8*) (0x02023BDE); 58 | 59 | #define dp08 (*dp08_ptr) 60 | 61 | // Some unused word in the memory - pick any 62 | // TODO: Clean up (malloc) 63 | bxcb *bc_backup = (bxcb*) 0x02023D78; 64 | 65 | #pragma pack(push, 1) 66 | typedef struct dp11b 67 | { 68 | u8 field0; 69 | u8 field1; 70 | u8 objid_2; 71 | u8 objid_3; 72 | u8 field4; 73 | u8 field5; 74 | u16 gap_6; 75 | u8 field8; 76 | u16 field9; 77 | u8 fieldB; 78 | } dp11b; 79 | #pragma pack(pop) 80 | 81 | typedef struct dp11 82 | { 83 | u32 *a; 84 | dp11b *b; 85 | u32 c; 86 | u32 d; 87 | } dp11; 88 | 89 | dp11 *dp11_ptr;// = (dp11*) 0x02024018; 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /src/bs_command.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Custom battle script command; it handles basically the entire mega evolution 3 | * transformation. 4 | */ 5 | 6 | #include "mega.h" 7 | #include "types.h" 8 | #include "common.h" 9 | #include "battle.h" 10 | #include "pokemon.h" 11 | #include "strings.h" 12 | #include "text.h" 13 | #include "evo.h" 14 | #include "config.h" 15 | #include "tables.h" 16 | 17 | #define CURRENT_BANK (*b_active_side) 18 | 19 | void set_species(u16 index); 20 | void show_message(char *buf); 21 | u8 *get_pokemon_data(); 22 | void buffer_str(); 23 | void special_strcpy(u8 *dest, u8 *src); 24 | 25 | void set_b_x_callback(bxcb callback); 26 | 27 | //void move_anim_start(u8,u8,u8,u8); 28 | void animation_script_start(u8 *script, u8 attacker, u8 defender); 29 | 30 | extern void play_mega_evolution(u8 attacker, u8 defender); 31 | 32 | evolution *get_evolution_data() { 33 | u8 *buffer_A = (u8*) (buffer_As + CURRENT_BANK * 0x200); 34 | return (evolution*) (buffer_A[3] | (buffer_A[4] << 8) | (buffer_A[5] << 16) | (buffer_A[6] << 24)); 35 | } 36 | 37 | battle_data *get_battle_data() { 38 | return &b_data[CURRENT_BANK]; 39 | } 40 | 41 | void healthbar_update(u8 bank); 42 | 43 | void wait_for_message(); 44 | void AGBPrint(const char *); 45 | 46 | extern u8 *string_buffer_maybe; 47 | void command() { 48 | // Wait for other Mega Evolutions to finish 49 | if (megadata->running) return; 50 | 51 | // Stop other Mega Evolutions, it's our turn 52 | megadata->running = 1; 53 | 54 | // Read species from the buffer 55 | evolution *evo = get_evolution_data(); 56 | 57 | set_species(evo->species); 58 | 59 | // Update health box (to hide level text) 60 | healthbar_update(CURRENT_BANK); 61 | 62 | // TODO: Support no message (for primals) 63 | special_strcpy((u8*) string_buffer_maybe, (u8*) str_before[evo->unknown]); 64 | show_message((char*) string_buffer_maybe); 65 | 66 | set_b_x_callback((bxcb) wait_for_message); 67 | } 68 | 69 | void set_species(u16 index) { 70 | u16 species = index; 71 | u8 *data = get_pokemon_data(); 72 | u8 i; 73 | 74 | pokemon_setattr(data, 0xB, (u8*) &species); 75 | recalc_stats(data); 76 | 77 | // TODO: Update healthbar? Mega's shouldn't change health so theres no need 78 | 79 | // Update battle data 80 | battle_data *bdata = get_battle_data(); 81 | 82 | bdata->species = species; 83 | 84 | // Update stats 85 | for (i = 0; i < 5; ++i) { 86 | bdata->stats[i] = pokemon_getattr(data, 0x3B + i, 0); 87 | //*((u16*)(battle_data + 2 + i * 2)) = pokemon_getattr(data, 0x3B + i, 0); 88 | } 89 | 90 | // Set ability 91 | // Megas only have one ability; don't bother with the second one 92 | bdata->ability_id = base_stats[index].ability1; 93 | 94 | // Type changes 95 | bdata->type1 = base_stats[index].type1; 96 | bdata->type2 = base_stats[index].type2; 97 | } 98 | 99 | char *item_name(u16 index) { 100 | return (char *) (item_names + index * 0x2C); 101 | } 102 | 103 | char *get_trainer_name() { 104 | if (CURRENT_BANK & 1) { 105 | u16 *trainer_flag = (u16*) 0x020386AE; 106 | u8 *trainer = trainers + *trainer_flag * 0x28; 107 | 108 | #ifdef BPRE 109 | #ifndef NO_RIVAL_NAME_SWAP // Optional 110 | // FireRed Rival Name for Champion and Rival classes 111 | u8 tclass = *(trainer + 1); 112 | if (tclass == 0x51 || tclass == 0x5A) { 113 | return (char*) (*saveblock1) + 0x3A4C; 114 | } 115 | #endif 116 | #endif 117 | 118 | return (char*) trainer + 4; 119 | } else { 120 | return (char*) *saveblock2; 121 | } 122 | } 123 | 124 | u16 get_keystone_index() { 125 | u16 *var; 126 | if (CURRENT_BANK & 1) { 127 | var = var_access(KEYSTONE_OPPONENT_VAR); 128 | } else { 129 | var = var_access(KEYSTONE_PLAYER_VAR); 130 | } 131 | 132 | u16 item = *var; 133 | return item ? item : KEYSTONE_DEFAULT; 134 | } 135 | 136 | char *get_species_name(u8 *pokemon_data) { 137 | u16 species = pokemon_getattr(pokemon_data, 0xB, 0); 138 | 139 | char *name = (char*) (pokemon_names + 0xB * species); 140 | return name; 141 | } 142 | 143 | void special_strcpy(u8 *dest, u8 *src) { 144 | u8 ch; 145 | u8 *data = get_pokemon_data(); 146 | char buffer[10]; 147 | char* buf = 0; 148 | 149 | battle_data *bdata = get_battle_data(); 150 | 151 | while ((ch = *src++) != 0xFF) { 152 | // Do something different for variables 153 | if (ch == 0xFD) { 154 | switch (*src++) { 155 | // Pokemon's nickname 156 | case 0: 157 | buf = (char*) buffer; 158 | pokemon_getattr(data, 2, buffer); 159 | break; 160 | // Held item 161 | case 1: 162 | buf = item_name(bdata->held_item); 163 | break; 164 | // Trainer's name 165 | case 2: 166 | // TODO: Load trainer name if enemy is mega evolving 167 | //buf = *((u8**) 0x0300500C); 168 | buf = get_trainer_name(); 169 | break; 170 | // Trainer's accessory 171 | case 3: 172 | // TODO: Support loading accessories from a table or something 173 | buf = item_name(get_keystone_index()); 174 | break; 175 | case 4: 176 | buf = get_species_name(data); 177 | break; 178 | } 179 | 180 | // Copy smaller buffer into string 181 | if(buf) { 182 | while ((*dest++ = (u8) *buf++) != 0xFF); 183 | } 184 | dest--; 185 | } else { 186 | *dest++ = ch; 187 | } 188 | } 189 | 190 | *dest = 0xFF; 191 | } 192 | 193 | void exec_completed() { 194 | megadata->running = 0; 195 | 196 | if (CURRENT_BANK & 1) { 197 | exec_completed_tbl2(); 198 | } else { 199 | exec_completed_tbl1(); 200 | } 201 | 202 | // If mutliple Mega Evolutions happen in a row, this doesn't get set. So force set it 203 | // TODO: Neaten up 204 | *((u32*) 0x03004F84) = (0x080155c9); 205 | }; 206 | 207 | void delay_before_end() { 208 | u16 *timer = (u16*) 0x02023D7E; 209 | 210 | if (*timer > 0) { 211 | (*timer)--; 212 | } else { 213 | exec_completed(); 214 | } 215 | } 216 | 217 | void wait_transformation_message() { 218 | u16 *timer = (u16*) 0x02023D7E; 219 | 220 | if (!a_pressed_maybe(0)) { 221 | *timer = 0x3F; 222 | set_b_x_callback((bxcb) delay_before_end); 223 | } 224 | } 225 | 226 | void transformation_message() { 227 | char *buffer = (char*) 0x0202298C; 228 | 229 | evolution *evo = get_evolution_data(); 230 | 231 | // TODO: Post transformation message 232 | special_strcpy((u8*) buffer, (u8*) str_after[evo->unknown]); 233 | show_message(buffer); 234 | 235 | set_b_x_callback((bxcb) wait_transformation_message); 236 | } 237 | 238 | void wait_for_animation() { 239 | u16 *timer = (u16*) 0x02023D7E; 240 | // move_anim_active_task_count 241 | if (*timer > 0) { 242 | (*timer)--; 243 | } else { 244 | if (*((u8*) 0x02037EE2) == 0) { 245 | set_b_x_callback((bxcb) transformation_message); 246 | } 247 | } 248 | } 249 | 250 | void delay_for_animation() { 251 | // Unused halfword - just pick any piece of padding 252 | u16 *timer = (u16*) 0x02023D7E; 253 | 254 | if (*timer > 0) { 255 | (*timer)--; 256 | } else { 257 | *timer = 0xFF; 258 | play_mega_evolution(CURRENT_BANK, 1); 259 | set_b_x_callback((bxcb) wait_for_animation); 260 | } 261 | } 262 | 263 | // Wait for message to finish printing before displaying the animation 264 | void wait_for_message() { 265 | // a_pressed_maybe is called immediately after the message is finished 266 | // rendering 267 | u16 *timer = (u16*) 0x02023D7E; 268 | 269 | if (!a_pressed_maybe(0)) { 270 | *timer = 0x30; 271 | set_b_x_callback((bxcb) delay_for_animation); 272 | } 273 | } 274 | 275 | void show_message(char *buf) { 276 | buffer_str(); 277 | 278 | // Set vblank 279 | *((u16*) 0x02022974) = 0; 280 | *((u16*) 0x02022976) = 0; 281 | 282 | // Display the message 283 | // TODO: Find out what second arg does 284 | battle_show_message(buf, 0x40); 285 | } 286 | 287 | void set_b_x_callback(bxcb callback) { 288 | bx[CURRENT_BANK] = callback; 289 | } 290 | 291 | u8 *get_pokemon_data() { 292 | u8 *current_team; 293 | 294 | if (CURRENT_BANK & 1) current_team = enemy_team; 295 | else current_team = team; 296 | 297 | current_team += (team_index_by_side[CURRENT_BANK]) * 100; 298 | return current_team; 299 | } 300 | -------------------------------------------------------------------------------- /src/button.c: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "mega.h" 3 | #include "battle.h" 4 | 5 | void play_sound(u16 sound_id); 6 | 7 | void trigger_mega_evolution() { 8 | if (!can_mega_evolve(&b_data[*b_current_bank])) { 9 | return; 10 | } 11 | 12 | if (!mega_evolution_enabled()) { 13 | return; 14 | } 15 | 16 | if (megadata->done[(*b_current_bank) & 1]) { 17 | return; 18 | } 19 | 20 | if (megadata->trigger[*b_current_bank]) { 21 | // Turn off 22 | play_sound(3); 23 | megadata->trigger[*b_current_bank] = 0; 24 | } else { 25 | // Turn on 26 | play_sound(2); 27 | megadata->trigger[*b_current_bank] = 1; 28 | } 29 | } 30 | 31 | void ai_trigger_mega_evolution() { 32 | if (can_mega_evolve(&b_data[*b_current_bank])) { 33 | megadata->trigger[*b_current_bank] = 1; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H_ 2 | #define COMMON_H_ 3 | 4 | void exec_completed_tbl1(); 5 | void exec_completed_tbl2(); 6 | u32 pokemon_getattr(u8 *data, u8 attr, void *ret); 7 | void pokemon_setattr(u8 *data, u8 attr, void *value); 8 | void gf_strcat(char *dest, char *src); 9 | void battle_show_message(char *msg, u8 arg); 10 | void ability_something_2(); 11 | int ability_something(u8,u8,u8,u8,u8); 12 | void recalc_stats(u8 *data); 13 | char *int_to_str(char *buffer, u8 lvl, u8 a, u8 b); 14 | u16 *var_access(u16 index); 15 | u8 checkitem(u16 index, u16 quanity); 16 | 17 | u8** saveblock1 = (u8**) 0x03005008; 18 | u8** saveblock2 = (u8**) 0x0300500C; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_H_ 2 | #define CONFIG_H_ 3 | 4 | /* Key stone variables */ 5 | 6 | #define KEYSTONE_PLAYER_VAR 0x4001 /* Variable that holds item index for player keystone */ 7 | #define KEYSTONE_OPPONENT_VAR 0x4002 /* Same as above but for partner */ 8 | #define KEYSTONE_DEFAULT 0x161 /* Default Key Stone item index */ 9 | 10 | /* Options */ 11 | /* Prevent rival name being substituted in for trainer class 0x51 and 0x5A */ 12 | // #define NO_RIVAL_NAME_SWAP 13 | 14 | /* Prevent keystone checking */ 15 | // #define DISABLE_KEYSTONE_CHECK 16 | 17 | /* Ignored colours for Mega Trigger */ 18 | 19 | #define TRIGGER_NUM_IGNORED_COLORS 0x4 /* Number of ignored colors in list below */ 20 | #define TRIGGER_IGNORED_COLORS 0x2147, 0x424F, 0x31AA, 0x00E4 /* List */ 21 | 22 | /* 0x7FFF,0x3757,0x7B97,0x31AA,0x72F1,0x424F,0x2147,0x429E, 23 | 0x4953,0x00E4,0x6ADB,0x37BD,0x0000,0x0000,0x0000,0x0000, */ 24 | #endif /* CONFIG_H_ */ 25 | -------------------------------------------------------------------------------- /src/evo.h: -------------------------------------------------------------------------------- 1 | #ifndef EVO_H_ 2 | #define EVO_H_ 3 | 4 | #include "types.h" 5 | 6 | typedef struct evolution { 7 | u16 type; 8 | u16 argument; 9 | u16 species; 10 | u16 unknown; 11 | } evolution; 12 | 13 | //evolution **evolution_table = (evolution**) 0x08259754; 14 | evolution ***evolution_table_ptr = ((evolution***) 0x08042F6C); 15 | #define evolution_table (*evolution_table_ptr) 16 | 17 | // an offsetstochangetonewminus1 offset in PokeRoms.ini from G3HS 18 | u8 *evos_per_poke = (u8*) 0x08043116; 19 | 20 | // The evolutionary type for Megas 21 | #define MEGA_EVOLUTION 0xFE 22 | 23 | // Mega evolution variants 24 | #define MEGA_VARIANT_STANDARD 0 25 | #define MEGA_VARIANT_PRIMAL 1 26 | #define MEGA_VARIANT_WISH 2 // Rayquaza 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/exit_battle_hook.s: -------------------------------------------------------------------------------- 1 | @ hook at 080159DC 2 | .thumb 3 | .align 2 4 | 5 | exit_battle_hook: 6 | bl revert_megas 7 | 8 | ldr r1, =(0x03004F84) 9 | ldr r0, =(0x08015A30 + 1) 10 | str r0, [r1] 11 | ldr r1, =(0x0300537C) 12 | 13 | ldr r0, =(0x080159E4 + 1) 14 | bx r0 15 | -------------------------------------------------------------------------------- /src/faint_hook.s: -------------------------------------------------------------------------------- 1 | @ Hook here 080326C4 2 | .thumb 3 | .align 2 4 | 5 | faint_hook: 6 | add r0, r2 7 | 8 | push {r0-r3} 9 | bl revert_mega 10 | pop {r0-r3} 11 | 12 | ldr r3, =(0x08035244 + 1) 13 | bl call_via_r3 14 | mov r1, #0x40 15 | 16 | ldr r3, =(0x080326CC + 1) 17 | call_via_r3: 18 | bx r3 19 | -------------------------------------------------------------------------------- /src/graphics.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICS_H_ 2 | #define GRAPHICS_H_ 3 | 4 | typedef struct colour { 5 | u16 r : 5; 6 | u16 g : 5; 7 | u16 b : 5; 8 | } color; 9 | 10 | typedef struct palette { 11 | u16 c[16]; 12 | } palette; 13 | 14 | palette *palette_bg_unfaded = (palette*) 0x020371F8; 15 | palette *palette_obj_unfaded = (palette*) 0x020373F8; 16 | palette *palette_bg_faded = (palette*) 0x020375F8; 17 | palette *palette_obj_faded = (palette*) 0x020377F8; 18 | 19 | u8 gpu_pal_tags_index_of(u16 tag); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/healthbar.c: -------------------------------------------------------------------------------- 1 | #include "objects.h" 2 | #include "battle.h" 3 | #include "common.h" 4 | #include "graphics.h" 5 | #include "mega.h" 6 | #include "config.h" 7 | #include "images/indicators.h" 8 | #include "images/mega_trigger.h" 9 | 10 | void healthbar_draw_field(u8, u8*, u8); 11 | 12 | //resource gfx_healthbar = {0x083EF524, 0x80, 0x1234}; 13 | resource gfx_indicator = {indicatorsTiles, 0x80, 0x1234}; 14 | resource pal_indicator = {indicatorsPal, 0x1234}; 15 | resource gfx_trigger = {mega_triggerTiles, 0x1C00, 0x2345}; 16 | resource pal_trigger = {mega_triggerPal, 0x2345}; 17 | // 083F6CBO - 32x32? 18 | 19 | sprite mega_indicator = {0, 0x0, 0x00, 0x0}; 20 | //sprite mega_icon = {0x0, 0x4000, 0x000, 0x0}; 21 | sprite mega_trigger = {0, 0x8000, 0x800, 0}; 22 | 23 | void healthbar_trigger_callback(object *self); 24 | void healthbar_indicator_callback(object *self); 25 | 26 | template template_indicator = {0x1234, 0x1234, &mega_indicator, (frame **) 0x08231CF0, 27 | 0, (rotscale_frame **) 0x08231CFC, healthbar_indicator_callback}; 28 | 29 | template template_trigger = {0x2345, 0x2345, &mega_trigger, (frame**) 0x08231CF0, 30 | 0, (rotscale_frame **) 0x08231CFC, healthbar_trigger_callback}; 31 | 32 | /* Declare the colors the trigger button ignores */ 33 | u16 ignored_cols[TRIGGER_NUM_IGNORED_COLORS] = { 34 | TRIGGER_IGNORED_COLORS 35 | }; 36 | 37 | /* Easy match function */ 38 | u8 ignored_trigger_color(u16 color) { 39 | u8 i; 40 | for (i = 0; i < TRIGGER_NUM_IGNORED_COLORS; ++i) { 41 | if (ignored_cols[i] == color) return 1; 42 | } 43 | return 0; 44 | } 45 | 46 | // charset: 0 - en, 1 -jp 47 | int font_get_width_of_string(u8 charset, char *string, u16 xcursor); 48 | void gpu_pal_obj_alloc_tag_and_apply(resource *pal); 49 | 50 | object *get_healthbox_objid(u8 bank) { 51 | u8 *healthbox_objid_by_side = (u8*) 0x03004FF0; 52 | u8 id = healthbox_objid_by_side[bank]; 53 | return &objects[id]; 54 | } 55 | 56 | s16 get_pingpong(s16 phase, s16 scale); 57 | 58 | u16 calcGrayscale(u16 color) { 59 | u32 r = color & 31, 60 | g = (color >> 5) & 31, 61 | b = (color >> 10) & 31; 62 | 63 | r *= 0x4C; 64 | g *= 0x96; 65 | b *= 0x1E; 66 | 67 | u16 gray = (r + g + b + 0x80) >> 8; 68 | 69 | return gray | (gray << 5) | (gray << 10); 70 | } 71 | 72 | u16 calcEnabled(u16 clra) { 73 | u16 clrb = 0x7FFF; 74 | 75 | u32 currentAlpha = 20; 76 | 77 | 78 | const u32 rbmask= ((0x1F)|(0x1F << 10)), gmask= 0x1F << 5; 79 | const u32 rbhalf= 0x4010, ghalf= 0x0200; 80 | 81 | // Red and blue 82 | u32 parta = clra & rbmask; 83 | u32 partb = clrb & rbmask; 84 | u32 part = (partb-parta) * (32 - ((currentAlpha < 0x100) ? currentAlpha : currentAlpha >> 12)) + parta*32 + rbhalf; 85 | u16 clr = (part >> 5) & rbmask; 86 | 87 | // Green 88 | parta = clra & gmask; 89 | partb = clrb & gmask; 90 | part = (partb-parta) * (32 - ((currentAlpha < 0x100) ? currentAlpha : currentAlpha >> 12)) + parta*32 + ghalf; 91 | clr |= (part >> 5) & gmask; 92 | 93 | return clr; 94 | } 95 | 96 | void healthbar_trigger_callback(object *self) { 97 | if (!can_mega_evolve(&b_data[*b_current_bank])) { 98 | self->x = -32; 99 | return; 100 | } 101 | 102 | s16 xshift, yshift; 103 | if (*battle_type_flags & 1) { 104 | xshift = -6; 105 | yshift = 0; 106 | } else { 107 | xshift = -5; 108 | yshift = 2; 109 | } 110 | 111 | // Find the health box object that this trigger is supposed to be attached to 112 | u8 *healthbox_objid_by_side = (u8*) 0x03004FF0; 113 | u8 id = healthbox_objid_by_side[*b_current_bank]; 114 | object *healthbox = &objects[id]; 115 | 116 | u8 y = (u8) healthbox->final_oam.attr0; 117 | 118 | u8 pingid = dp11_ptr->b[*b_current_bank].objid_2; 119 | object *ping = &objects[pingid]; 120 | if (y) { 121 | // Copy the healthbox's position (it has various animations) 122 | //self->y = healthbox->y + 20; 123 | self->x = (healthbox->final_oam.attr1 & 0x1FF) + xshift + self->private[3]; 124 | self->y2 = get_pingpong(ping->private[0], ping->private[2]); 125 | self->y = healthbox->y + yshift; 126 | } else { 127 | // The box is offscreen, so hide this one as well 128 | self->x = -32; 129 | } 130 | 131 | if (b_x[*b_current_bank] == 0x0802EA11) { 132 | if (self->private[3] > 0) { 133 | self->private[3] -= 2; 134 | } else { 135 | self->private[3] = 0; 136 | } 137 | } else { 138 | if (self->private[3] < 16) { 139 | self->private[3] += 2; 140 | } else { 141 | // Hide offscreen once invisible 142 | self->x = -32; 143 | return; 144 | } 145 | } 146 | 147 | if (megadata->done[*b_current_bank]) { 148 | self->private[1] = 3; 149 | } else { 150 | if (megadata->trigger[*b_current_bank]) { 151 | self->private[1] = 1; 152 | } else { 153 | self->private[1] = 2; 154 | } 155 | } 156 | 157 | // Only change the palette if the state has changed 158 | if (self->private[1] != self->private[2]) { 159 | palette *pal = &palette_obj_faded[gpu_pal_tags_index_of(0x2345)]; 160 | u8 i; 161 | 162 | for(i = 1; i < 16; i++) { 163 | if (ignored_trigger_color(mega_triggerPal[i])) continue; 164 | 165 | if (self->private[1] == 1) { 166 | pal->c[i] = calcEnabled(mega_triggerPal[i]); 167 | } else if (self->private[1] == 2) { 168 | pal->c[i] = mega_triggerPal[i]; 169 | } else if (self->private[1] == 3) { 170 | pal->c[i] = calcGrayscale(mega_triggerPal[i]); 171 | } 172 | } 173 | 174 | self->private[2] = self->private[1]; 175 | } 176 | } 177 | 178 | void healthbar_indicator_callback(object *self) { 179 | // Visibility 180 | if (!is_mega(&b_data[self->private[0]])) { 181 | self->x = -8; 182 | return; 183 | } 184 | object *healthbox = get_healthbox_objid(self->private[0]); 185 | 186 | if (healthbox->bitfield2 & 4) { 187 | self->x = -8; 188 | return; 189 | } 190 | 191 | u8 y = (u8) healthbox->final_oam.attr0, 192 | x = (healthbox->final_oam.attr1 & 0x1FF); 193 | 194 | // Mirror healthbox priority 195 | u8 priority = ((healthbox->final_oam.attr2 >> 10) & 3); 196 | self->final_oam.attr2 = (self->final_oam.attr2 & ~0xC00) | (priority << 10); 197 | 198 | if (y) { 199 | // Figure out the X position for the indicator - it differs depending on 200 | // the battle type and the side the healthbox represents. 201 | s16 shift = 64; // Halfway point for OAM 202 | 203 | if (self->private[0] & 1) { 204 | // enemy 205 | shift += 18; 206 | } else { 207 | // player 208 | shift += 26; 209 | } 210 | 211 | // Convert the level to a string to get how long it is 212 | char buf[10]; 213 | battle_data *data = &b_data[self->private[0]]; 214 | u8 stringlen = int_to_str(buf, data->level, 0, 3) - buf; 215 | 216 | // The x position depends on the X origin of the healthbox as well as 217 | // the string length 218 | self->x = x + shift - 5 * stringlen; 219 | 220 | u8 pingid = dp11_ptr->b[self->private[0]].objid_2; 221 | object *ping = &objects[pingid]; 222 | 223 | u8 pingpong_active = (dp11_ptr->b[self->private[0]].field0 & 6); 224 | u8 *shaker_data = (u8*) 0x02022AD0; 225 | 226 | object *shaker = &objects[shaker_data[1]]; 227 | u8 *healthbox_objid_by_side = (u8*) 0x03004FF0; 228 | u8 hbid = healthbox_objid_by_side[self->private[0]]; 229 | 230 | if (pingpong_active) { 231 | // objc_dp11b_pingpong 232 | self->y = healthbox->y - 4; 233 | self->y2 = get_pingpong(ping->private[0], ping->private[2]); 234 | return; 235 | } else if (shaker->private[1] == hbid && *shaker_data) { 236 | self->y2 = (shaker->private[2] & 1) ? -1 : 1; 237 | return; 238 | } 239 | 240 | // Fix indicator position 241 | self->y = healthbox->y - 5; 242 | self->y2 = 0; 243 | self->x2 = 0; 244 | } else { 245 | self->x = -8; 246 | } 247 | } 248 | 249 | void healthbar_load_graphics(u8 state) { 250 | u8 objid; 251 | 252 | if (state == 2) { 253 | gpu_pal_obj_alloc_tag_and_apply(&pal_indicator); 254 | gpu_pal_obj_alloc_tag_and_apply(&pal_trigger); 255 | 256 | gpu_tile_obj_decompress_alloc_tag_and_upload(&gfx_indicator); 257 | gpu_tile_obj_decompress_alloc_tag_and_upload(&gfx_trigger); 258 | 259 | 260 | // Create a Mega Indicator for every bank 261 | u8 bank; 262 | for (bank = 0; bank < *b_num_active_sides; ++bank) { 263 | objid = template_instanciate_forward_search(&template_indicator, 0, 0, 1); 264 | objects[objid].private[0] = bank; 265 | } 266 | 267 | if (mega_evolution_enabled()) { 268 | objid = template_instanciate_forward_search(&template_trigger, 130, 90, 1); 269 | } 270 | } 271 | } 272 | 273 | void healthbar_update(u8 bank) { 274 | u8 *healthbox_objid_by_side = (u8*) 0x03004FF0; 275 | 276 | u8 *current_team = (bank & 1) ? enemy_team : team; 277 | u8 id = team_index_by_side[bank]; 278 | 279 | healthbar_draw_field(healthbox_objid_by_side[bank], current_team + id * 100, 0); 280 | } 281 | 282 | void healthbar_display_graphics() { 283 | //gpu_tile_obj_decompress_alloc_tag_and_upload(&gfx_healthbar); 284 | //template_instanciate_forward_search(&template_healthbar, 10, 10, 1); 285 | } 286 | -------------------------------------------------------------------------------- /src/healthbar_hooks.s: -------------------------------------------------------------------------------- 1 | .align 2 2 | .thumb 3 | 4 | @ hook at 0803495A 5 | load_graphics_hook: 6 | push {r0} 7 | mov r0, r5 8 | bl healthbar_load_graphics 9 | pop {r0} 10 | 11 | pop {r4-r6} 12 | pop {r1} 13 | bx r1 14 | 15 | .align 2 16 | 17 | @ hook at 08047FD8 18 | show_graphics_hook: 19 | bl healthbar_display_graphics 20 | 21 | mov r10, r5 22 | pop {r4-r7} 23 | pop {r1} 24 | bx r1 25 | -------------------------------------------------------------------------------- /src/healthbar_shaker_hooks.s: -------------------------------------------------------------------------------- 1 | .thumb 2 | 3 | @ This is probably the stupidest part of the entire project, as well as the most 4 | @ tedious. Whenever a Pokemon gets hit with a damaging attack, the healthbox 5 | @ shakes a little. It does this by creating an invisible object that has a callback 6 | @ that alters the healthbox. These hooks save an index to those invisible objects 7 | @ so that we can actually move the box a bit. 8 | 9 | @ at 0804BE80 in r3 10 | .align 2 11 | create_shaker_hook: 12 | lsl r0, #0x18 13 | lsr r0, #0x18 14 | 15 | @ Save Index 16 | ldr r3, shaker_data 17 | strb r0, [r3, #1] 18 | 19 | @ Set boolean to true 20 | mov r2, #1 21 | strb r2, [r3] 22 | 23 | @ Return 24 | ldr r2, =(0x0202063C) 25 | lsl r1, r0, #4 26 | ldr r3, =(0x0804BE88 + 1) 27 | bx r3 28 | 29 | @ at 0804BEDC in r2 30 | .align 2 31 | objc_shaker_hook: 32 | mov r2, #0 33 | asr r0, #0x10 34 | cmp r0, #0x15 35 | bne return 36 | 37 | strh r2, [r1, #0x24] 38 | strh r2, [r1, #0x26] 39 | 40 | @ Set boolean to false 41 | ldr r1, shaker_data 42 | strb r2, [r1] 43 | 44 | ldr r2, =(0x0804BEE6 + 1) 45 | bx r2 46 | 47 | return: 48 | pop {r0} 49 | bx r0 50 | 51 | .align 2 52 | shaker_data: .word 0x02022AD0 @ 2 fre bytes 53 | -------------------------------------------------------------------------------- /src/images/indicators.c: -------------------------------------------------------------------------------- 1 | 2 | //{{BLOCK(indicators) 3 | 4 | //====================================================================== 5 | // 6 | // indicators, 24x8@4, 7 | // Transparent palette entry: 4. 8 | // + palette 16 entries, not compressed 9 | // + 3 tiles lz77 compressed 10 | // Total size: 32 + 112 = 144 11 | // 12 | // Time-stamp: 2015-07-26, 22:03:59 13 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 14 | // ( http://www.coranac.com/projects/#grit ) 15 | // 16 | //====================================================================== 17 | 18 | const unsigned char indicatorsTiles[112] __attribute__((aligned(4))) __attribute__((visibility("hidden")))= 19 | { 20 | 0x10,0x60,0x00,0x00,0x00,0x00,0x68,0x66,0x00,0x70,0x76,0x76,0x07,0x00,0x6B,0x66, 21 | 0x6B,0xBB,0x65,0x65,0x56,0x56,0x00,0x69,0x96,0x69,0x96,0x33,0x66,0x36,0x36,0x00, 22 | 0xC0,0x6C,0x6C,0x0C,0x00,0x66,0x86,0x00,0x00,0x00,0xCA,0x2C,0x00,0xA0,0x8C,0xCA, 23 | 0x02,0x00,0xC2,0x88,0xAA,0x2C,0xC2,0xAA,0xAA,0x2C,0x00,0xA2,0xAC,0xCA,0x2A,0xC8, 24 | 0xAC,0xCA,0x8C,0x00,0x80,0x22,0x22,0x08,0x00,0x22,0x22,0x00,0x00,0x00,0x11,0x44, 25 | 0x00,0x10,0x99,0x11,0x05,0x01,0x94,0x55,0x99,0x41,0x19,0x11,0x19,0x20,0x03,0x00, 26 | 0x94,0x11,0x99,0x44,0x40,0x99,0x44,0x05,0x00,0x00,0x44,0x44,0x00,0x0C,0x0C,0x08, 27 | }; 28 | 29 | const unsigned short indicatorsPal[16] __attribute__((aligned(4))) __attribute__((visibility("hidden")))= 30 | { 31 | 0x001F,0x6DE4,0x18B3,0x3757,0x4D22,0x72F1,0x1864,0x4953, 32 | 0x429E,0x7B97,0x353C,0x6ADB,0x37BD,0x0000,0x0000,0x0000, 33 | }; 34 | 35 | //}}BLOCK(indicators) 36 | -------------------------------------------------------------------------------- /src/images/indicators.h: -------------------------------------------------------------------------------- 1 | 2 | //{{BLOCK(indicators) 3 | 4 | //====================================================================== 5 | // 6 | // indicators, 24x8@4, 7 | // Transparent palette entry: 4. 8 | // + palette 16 entries, not compressed 9 | // + 3 tiles lz77 compressed 10 | // Total size: 32 + 112 = 144 11 | // 12 | // Time-stamp: 2015-07-26, 22:03:59 13 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 14 | // ( http://www.coranac.com/projects/#grit ) 15 | // 16 | //====================================================================== 17 | 18 | #ifndef GRIT_INDICATORS_H 19 | #define GRIT_INDICATORS_H 20 | 21 | #define indicatorsTilesLen 112 22 | extern const unsigned char indicatorsTiles[112]; 23 | 24 | #define indicatorsPalLen 32 25 | extern const unsigned short indicatorsPal[16]; 26 | 27 | #endif // GRIT_INDICATORS_H 28 | 29 | //}}BLOCK(indicators) 30 | -------------------------------------------------------------------------------- /src/images/mega_trigger.c: -------------------------------------------------------------------------------- 1 | 2 | //{{BLOCK(mega_trigger) 3 | 4 | //====================================================================== 5 | // 6 | // mega_trigger, 32x32@4, 7 | // Transparent palette entry: 9. 8 | // + palette 16 entries, not compressed 9 | // + 16 tiles lz77 compressed 10 | // Total size: 32 + 204 = 236 11 | // 12 | // Time-stamp: 2015-07-26, 22:03:59 13 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 14 | // ( http://www.coranac.com/projects/#grit ) 15 | // 16 | //====================================================================== 17 | 18 | const unsigned char mega_triggerTiles[204] __attribute__((aligned(4))) __attribute__((visibility("hidden")))= 19 | { 20 | 0x10,0x00,0x02,0x00,0x3F,0x00,0x00,0xF0,0x01,0xF0,0x01,0xF0,0x01,0xF0,0x01,0xF0, 21 | 0x01,0x00,0x0F,0x60,0x50,0xF0,0x13,0x20,0x0D,0x35,0x00,0x50,0x33,0x33,0xF6,0x10, 22 | 0x01,0xF0,0x1B,0xF0,0x01,0x80,0x4B,0x35,0x00,0x52,0x00,0x33,0x35,0xC6,0x00,0x37, 23 | 0x00,0x3B,0x50,0x33,0x93,0x10,0x0B,0x30,0x4A,0x99,0x00,0x99,0x33,0x99,0x77,0x77, 24 | 0x93,0x88,0x88,0x00,0x66,0x89,0x88,0x66,0x68,0xA9,0x6A,0x6A,0x06,0x66,0x44,0x66, 25 | 0x46,0x64,0x30,0x65,0x30,0x6B,0x99,0x80,0x00,0x72,0x86,0x39,0x33,0x33,0x88,0x98, 26 | 0x33,0x00,0x33,0xAA,0x9A,0x33,0x33,0x46,0x44,0x39,0xFF,0xF0,0x7F,0xE0,0x75,0x00, 27 | 0x63,0x50,0x03,0x10,0x73,0x20,0x7B,0x10,0x83,0x10,0x8B,0x00,0x00,0x50,0x44,0x66, 28 | 29 | 0x66,0x46,0x22,0x62,0x00,0x22,0x66,0x11,0x61,0x66,0x61,0x19,0x11,0x00,0x66,0x16, 30 | 0xB9,0xBB,0xB6,0x66,0x93,0x6B,0x39,0x66,0xB6,0x10,0x8B,0x10,0x93,0x10,0x63,0x66, 31 | 0x22,0x00,0x03,0x00,0x11,0x39,0x33,0x16,0x91,0x33,0x33,0xBB,0x7F,0x9B,0x00,0x03, 32 | 0x00,0x83,0x10,0x8B,0xF0,0xFF,0xF0,0x01,0xF0,0x01,0xD0,0x9E,0xFE,0x50,0x93,0xF1, 33 | 0x6B,0x10,0x0D,0x90,0xFF,0x11,0x73,0x40,0xB7,0x60,0x01,0xFF, 34 | }; 35 | 36 | const unsigned short mega_triggerPal[16] __attribute__((aligned(4))) __attribute__((visibility("hidden")))= 37 | { 38 | 0x7FFF,0x3757,0x7B97,0x31AA,0x72F1,0x424F,0x2147,0x429E, 39 | 0x4953,0x00E4,0x6ADB,0x37BD,0x0000,0x0000,0x0000,0x0000, 40 | }; 41 | 42 | //}}BLOCK(mega_trigger) 43 | -------------------------------------------------------------------------------- /src/images/mega_trigger.h: -------------------------------------------------------------------------------- 1 | 2 | //{{BLOCK(mega_trigger) 3 | 4 | //====================================================================== 5 | // 6 | // mega_trigger, 32x32@4, 7 | // Transparent palette entry: 9. 8 | // + palette 16 entries, not compressed 9 | // + 16 tiles lz77 compressed 10 | // Total size: 32 + 204 = 236 11 | // 12 | // Time-stamp: 2015-07-26, 22:03:59 13 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 14 | // ( http://www.coranac.com/projects/#grit ) 15 | // 16 | //====================================================================== 17 | 18 | #ifndef GRIT_MEGA_TRIGGER_H 19 | #define GRIT_MEGA_TRIGGER_H 20 | 21 | #define mega_triggerTilesLen 204 22 | extern const unsigned char mega_triggerTiles[204]; 23 | 24 | #define mega_triggerPalLen 32 25 | extern const unsigned short mega_triggerPal[16]; 26 | 27 | #endif // GRIT_MEGA_TRIGGER_H 28 | 29 | //}}BLOCK(mega_trigger) 30 | -------------------------------------------------------------------------------- /src/images/mega_trigger_disabled.c: -------------------------------------------------------------------------------- 1 | 2 | //{{BLOCK(mega_trigger_disabled) 3 | 4 | //====================================================================== 5 | // 6 | // mega_trigger_disabled, 32x32@4, 7 | // + palette 16 entries, not compressed 8 | // + regular map (flat), not compressed, 4x4 9 | // Total size: 32 + 32 = 64 10 | // 11 | // Time-stamp: 2015-06-23, 20:41:14 12 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 13 | // ( http://www.coranac.com/projects/#grit ) 14 | // 15 | //====================================================================== 16 | 17 | const unsigned short mega_trigger_disabledMap[16] __attribute__((aligned(4))) __attribute__((visibility("hidden")))= 18 | { 19 | 0x0000,0x0000,0x0001,0x0002,0x0000,0x0003,0x0004,0x0005, 20 | 0x0000,0x0006,0x0007,0x0008,0x0000,0x0000,0x0009,0x000A, 21 | }; 22 | 23 | const unsigned short mega_trigger_disabledPal[16] __attribute__((aligned(4))) __attribute__((visibility("hidden")))= 24 | { 25 | 0x0000,0x31AA,0x3DEF,0x18C6,0x56B5,0x6318,0x4A52,0x424F, 26 | 0x6F7B,0x4210,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 27 | }; 28 | 29 | //}}BLOCK(mega_trigger_disabled) 30 | -------------------------------------------------------------------------------- /src/images/mega_trigger_disabled.h: -------------------------------------------------------------------------------- 1 | 2 | //{{BLOCK(mega_trigger_disabled) 3 | 4 | //====================================================================== 5 | // 6 | // mega_trigger_disabled, 32x32@4, 7 | // + palette 16 entries, not compressed 8 | // + regular map (flat), not compressed, 4x4 9 | // Total size: 32 + 32 = 64 10 | // 11 | // Time-stamp: 2015-06-23, 20:41:14 12 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 13 | // ( http://www.coranac.com/projects/#grit ) 14 | // 15 | //====================================================================== 16 | 17 | #ifndef GRIT_MEGA_TRIGGER_DISABLED_H 18 | #define GRIT_MEGA_TRIGGER_DISABLED_H 19 | 20 | #define mega_trigger_disabledMapLen 32 21 | extern const unsigned short mega_trigger_disabledMap[16]; 22 | 23 | #define mega_trigger_disabledPalLen 32 24 | extern const unsigned short mega_trigger_disabledPal[16]; 25 | 26 | #endif // GRIT_MEGA_TRIGGER_DISABLED_H 27 | 28 | //}}BLOCK(mega_trigger_disabled) 29 | -------------------------------------------------------------------------------- /src/images/mega_trigger_on.c: -------------------------------------------------------------------------------- 1 | 2 | //{{BLOCK(mega_trigger_on) 3 | 4 | //====================================================================== 5 | // 6 | // mega_trigger_on, 32x32@4, 7 | // + palette 16 entries, not compressed 8 | // + 16 tiles lz77 compressed 9 | // Total size: 32 + 224 = 256 10 | // 11 | // Time-stamp: 2015-06-23, 20:42:19 12 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 13 | // ( http://www.coranac.com/projects/#grit ) 14 | // 15 | //====================================================================== 16 | 17 | const unsigned char mega_trigger_onTiles[224] __attribute__((aligned(4))) __attribute__((visibility("hidden")))= 18 | { 19 | 0x10,0x00,0x02,0x00,0x3E,0x00,0x00,0xF0,0x01,0xF0,0x01,0xF0,0x01,0xF0,0x01,0xA0, 20 | 0x05,0x25,0x0A,0x00,0x50,0x22,0x22,0x00,0x02,0x22,0xC0,0x1B,0x50,0xFF,0x00,0x1A, 21 | 0x00,0x15,0x70,0x02,0xF0,0x3B,0xE0,0x01,0x00,0x33,0x00,0x4F,0x00,0x50,0x17,0x00, 22 | 0x00,0x20,0x00,0x4F,0x25,0x00,0x53,0x10,0x57,0x30,0x03,0x80,0x30,0x4C,0xF2,0x44, 23 | 0x22,0xF2,0xE4,0xEE,0x22,0x00,0x8F,0x88,0x48,0x42,0x99,0x49,0x94,0xF2,0x00,0xCC, 24 | 0xC4,0x44,0xC4,0x4C,0x44,0xCC,0x64,0x15,0x46,0x44,0x44,0x10,0x6C,0x24,0x00,0x67, 25 | 0xFE,0x00,0x04,0x00,0x44,0xF8,0x22,0x22,0x94,0x99,0x24,0x22,0x00,0xC4,0xCC,0x2F, 26 | 0x22,0x44,0xCC,0x4C,0x22,0x1F,0x46,0x66,0x46,0xF0,0x7F,0xE0,0x01,0x70,0x6B,0x30, 27 | 28 | 0x7B,0x10,0x83,0xC0,0x10,0x8B,0x10,0x93,0x00,0x50,0xB4,0xBB,0xB4,0x4B,0x00,0x1F, 29 | 0x11,0x44,0x14,0x42,0x33,0x43,0x44,0x02,0xF2,0xAA,0x4A,0x4A,0x22,0x7F,0x00,0x73, 30 | 0xF2,0x28,0xDF,0xDD,0x00,0x93,0xFF,0x10,0xE8,0x44,0xB4,0x4B,0x00,0x22,0x44,0x14, 31 | 0xF1,0x22,0x43,0x33,0x24,0x00,0x22,0xA4,0xAA,0x2F,0x22,0x77,0xF7,0x22,0x07,0x22, 32 | 0xFD,0x2F,0x22,0x22,0x00,0x02,0xF0,0xFF,0xF0,0x01,0xFF,0xF0,0x01,0xD1,0x1C,0x10, 33 | 0x43,0x01,0x6B,0x40,0x8F,0xF0,0xBD,0x91,0x6B,0x20,0x27,0xC0,0x20,0xBB,0x60,0x01, 34 | }; 35 | 36 | const unsigned short mega_trigger_onPal[16] __attribute__((aligned(4))) __attribute__((visibility("hidden")))= 37 | { 38 | 0x0000,0x2F00,0x31AA,0x1309,0x18C6,0x424F,0x66C1,0x0B78, 39 | 0x51B7,0x59F0,0x0F51,0x5300,0x6665,0x239B,0x51BB,0x18C7, 40 | }; 41 | 42 | //}}BLOCK(mega_trigger_on) 43 | 44 | //{{BLOCK(mega_trigger) 45 | 46 | //====================================================================== 47 | // 48 | // mega_trigger, 32x32@4, 49 | // + palette 16 entries, not compressed 50 | // + 16 tiles lz77 compressed 51 | // Total size: 32 + 224 = 256 52 | // 53 | // Time-stamp: 2015-06-23, 20:42:19 54 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 55 | // ( http://www.coranac.com/projects/#grit ) 56 | // 57 | //====================================================================== 58 | 59 | const unsigned char mega_triggerTiles[224] __attribute__((aligned(4))) __attribute__((visibility("hidden")))= 60 | { 61 | 0x10,0x00,0x02,0x00,0x3E,0x00,0x00,0xF0,0x01,0xF0,0x01,0xF0,0x01,0xF0,0x01,0xA0, 62 | 0x05,0x82,0x0A,0x00,0x20,0x88,0x88,0x00,0x02,0x88,0xC0,0x1B,0x20,0xFF,0x00,0x1A, 63 | 0x00,0x15,0x70,0x02,0xF0,0x3B,0xE0,0x01,0x00,0x33,0x00,0x4F,0x00,0x50,0x17,0x00, 64 | 0x00,0x80,0x00,0x4F,0x82,0x00,0x53,0x10,0x57,0x30,0x03,0x80,0x30,0x4C,0xF8,0x33, 65 | 0x88,0xF8,0xE3,0xEE,0x88,0x00,0x7F,0x77,0x37,0x38,0xAA,0x3A,0xA3,0xF8,0x00,0xDD, 66 | 0xD3,0x33,0xD3,0x3D,0x33,0xDD,0x63,0x15,0x36,0x33,0x33,0x10,0x6C,0x83,0x00,0x67, 67 | 0xFE,0x00,0x04,0x00,0x33,0xF7,0x88,0x88,0xA3,0xAA,0x83,0x88,0x00,0xD3,0xDD,0x8F, 68 | 0x88,0x33,0xDD,0x3D,0x88,0x1F,0x36,0x66,0x36,0xF0,0x7F,0xE0,0x01,0x70,0x6B,0x30, 69 | 70 | 0x7B,0x10,0x83,0xC0,0x10,0x8B,0x10,0x93,0x00,0x20,0xB3,0xBB,0xB3,0x3B,0x00,0x1F, 71 | 0x11,0x33,0x13,0x38,0x44,0x34,0x33,0x02,0xF8,0x55,0x35,0x35,0x88,0x9F,0x00,0x73, 72 | 0xF8,0x28,0xCF,0xCC,0x00,0x93,0xFF,0x10,0xE8,0x33,0xB3,0x3B,0x00,0x88,0x33,0x13, 73 | 0xF1,0x88,0x34,0x44,0x83,0x00,0x88,0x53,0x55,0x8F,0x88,0x99,0xF9,0x88,0x07,0x88, 74 | 0xFC,0x8F,0x88,0x88,0x00,0x02,0xF0,0xFF,0xF0,0x01,0xFF,0xF0,0x01,0xD1,0x1C,0x10, 75 | 0x43,0x01,0x6B,0x40,0x8F,0xF0,0xBD,0x91,0x6B,0x20,0x27,0xC0,0x20,0xBB,0x60,0x01, 76 | }; 77 | 78 | const unsigned short mega_triggerPal[16] __attribute__((aligned(4))) __attribute__((visibility("hidden")))= 79 | { 80 | 0x0000,0x2680,0x424F,0x18C6,0x0EC8,0x0B30,0x5E80,0x55B7, 81 | 0x31AA,0x0777,0x5DF0,0x4280,0x23BC,0x6644,0x55FC,0x18C7, 82 | }; 83 | 84 | //}}BLOCK(mega_trigger) 85 | 86 | //{{BLOCK(mega_trigger_onShared) 87 | 88 | //====================================================================== 89 | // 90 | // mega_trigger_onShared, 0x0@8, 91 | // + palette 27 entries, not compressed 92 | // Total size: 54 = 54 93 | // 94 | // Time-stamp: 2015-06-23, 20:39:49 95 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 96 | // ( http://www.coranac.com/projects/#grit ) 97 | // 98 | //====================================================================== 99 | 100 | const unsigned short mega_trigger_onSharedPal[28] __attribute__((aligned(4))) __attribute__((visibility("hidden")))= 101 | { 102 | 0x0000,0x2F00,0x31AA,0x1309,0x18C6,0x424F,0x66C1,0x0B78, 103 | 0x51B7,0x59F0,0x0F51,0x5300,0x6665,0x239B,0x51BB,0x18C7, 104 | 0x2680,0x0EC8,0x0B30,0x5E80,0x55B7,0x0777,0x5DF0,0x4280, 105 | 0x23BC,0x6644,0x55FC, 106 | }; 107 | 108 | //}}BLOCK(mega_trigger_onShared) 109 | 110 | //{{BLOCK(mega_trigger_disabled) 111 | 112 | //====================================================================== 113 | // 114 | // mega_trigger_disabled, 32x32@4, 115 | // + palette 16 entries, not compressed 116 | // + 16 tiles lz77 compressed 117 | // Total size: 32 + 216 = 248 118 | // 119 | // Time-stamp: 2015-06-23, 20:42:19 120 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 121 | // ( http://www.coranac.com/projects/#grit ) 122 | // 123 | //====================================================================== 124 | 125 | const unsigned char mega_trigger_disabledTiles[216] __attribute__((aligned(4))) __attribute__((visibility("hidden")))= 126 | { 127 | 0x10,0x00,0x02,0x00,0x3E,0x00,0x00,0xF0,0x01,0xF0,0x01,0xF0,0x01,0xF0,0x01,0xA0, 128 | 0x05,0x17,0x0A,0x00,0x70,0x11,0x11,0x00,0x02,0x11,0xC0,0x1B,0x70,0xFF,0x00,0x1A, 129 | 0x00,0x15,0x70,0x02,0xF0,0x3B,0xE0,0x01,0x00,0x33,0x00,0x4F,0x00,0x50,0x17,0x00, 130 | 0x00,0x10,0x00,0x4F,0x17,0x00,0x53,0x10,0x57,0x30,0x03,0x80,0x30,0x4C,0x31,0x33, 131 | 0x11,0x31,0x63,0x66,0x11,0x00,0x23,0x22,0x32,0x31,0x99,0x39,0x93,0x31,0x01,0x99, 132 | 0x93,0x33,0x93,0x39,0x33,0x99,0x00,0x03,0x54,0x33,0x10,0x6C,0x13,0x00,0x67,0x36, 133 | 0x00,0x04,0x33,0x32,0x04,0x11,0x11,0x93,0x99,0x13,0x20,0x03,0x33,0x99,0x1F,0x39, 134 | 0x11,0x39,0x00,0x03,0xF0,0x6F,0xD0,0x01,0x70,0x6B,0x30,0x7B,0xE0,0x10,0x83,0x10, 135 | 136 | 0x8B,0x10,0x93,0x00,0x70,0x23,0x22,0x23,0x00,0x32,0x23,0x22,0x33,0x23,0x31,0x66, 137 | 0x36,0x01,0x33,0x31,0x44,0x34,0x34,0x11,0x53,0x00,0x73,0x18,0x31,0x83,0x88,0x20, 138 | 0x93,0x00,0xDF,0x33,0x23,0x32,0x80,0x20,0x03,0x36,0x66,0x13,0x11,0x43,0x44,0x13, 139 | 0x03,0x11,0x55,0x35,0x11,0x11,0x38,0x00,0x90,0x10,0x93,0xFF,0xF0,0xFF,0xF0,0x01, 140 | 0xF0,0x01,0xC1,0x50,0x10,0x43,0x01,0x6B,0x40,0x8F,0xF0,0xBD,0xF0,0x91,0x6B,0x20, 141 | 0x27,0x20,0xBB,0x60,0x01,0x68,0x50,0xFF, 142 | }; 143 | 144 | const unsigned short mega_trigger_disabledPal[16] __attribute__((aligned(4))) __attribute__((visibility("hidden")))= 145 | { 146 | 0x0000,0x31AA,0x3DEF,0x18C6,0x56B5,0x6318,0x4A52,0x424F, 147 | 0x6F7B,0x4210,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 148 | }; 149 | 150 | //}}BLOCK(mega_trigger_disabled) 151 | -------------------------------------------------------------------------------- /src/images/mega_trigger_on.h: -------------------------------------------------------------------------------- 1 | 2 | //{{BLOCK(mega_trigger_on) 3 | 4 | //====================================================================== 5 | // 6 | // mega_trigger_on, 32x32@4, 7 | // + palette 16 entries, not compressed 8 | // + 16 tiles lz77 compressed 9 | // Total size: 32 + 224 = 256 10 | // 11 | // Time-stamp: 2015-06-23, 20:42:19 12 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 13 | // ( http://www.coranac.com/projects/#grit ) 14 | // 15 | //====================================================================== 16 | 17 | #ifndef GRIT_MEGA_TRIGGER_ON_H 18 | #define GRIT_MEGA_TRIGGER_ON_H 19 | 20 | #define mega_trigger_onTilesLen 224 21 | extern const unsigned char mega_trigger_onTiles[224]; 22 | 23 | #define mega_trigger_onPalLen 32 24 | extern const unsigned short mega_trigger_onPal[16]; 25 | 26 | #endif // GRIT_MEGA_TRIGGER_ON_H 27 | 28 | //}}BLOCK(mega_trigger_on) 29 | 30 | //{{BLOCK(mega_trigger) 31 | 32 | //====================================================================== 33 | // 34 | // mega_trigger, 32x32@4, 35 | // + palette 16 entries, not compressed 36 | // + 16 tiles lz77 compressed 37 | // Total size: 32 + 224 = 256 38 | // 39 | // Time-stamp: 2015-06-23, 20:42:19 40 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 41 | // ( http://www.coranac.com/projects/#grit ) 42 | // 43 | //====================================================================== 44 | 45 | #ifndef GRIT_MEGA_TRIGGER_H 46 | #define GRIT_MEGA_TRIGGER_H 47 | 48 | #define mega_triggerTilesLen 224 49 | extern const unsigned char mega_triggerTiles[224]; 50 | 51 | #define mega_triggerPalLen 32 52 | extern const unsigned short mega_triggerPal[16]; 53 | 54 | #endif // GRIT_MEGA_TRIGGER_H 55 | 56 | //}}BLOCK(mega_trigger) 57 | 58 | //{{BLOCK(mega_trigger_onShared) 59 | 60 | //====================================================================== 61 | // 62 | // mega_trigger_onShared, 0x0@8, 63 | // + palette 27 entries, not compressed 64 | // Total size: 54 = 54 65 | // 66 | // Time-stamp: 2015-06-23, 20:39:49 67 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 68 | // ( http://www.coranac.com/projects/#grit ) 69 | // 70 | //====================================================================== 71 | 72 | #ifndef GRIT_MEGA_TRIGGER_ONSHARED_H 73 | #define GRIT_MEGA_TRIGGER_ONSHARED_H 74 | 75 | #define mega_trigger_onSharedPalLen 54 76 | extern const unsigned short mega_trigger_onSharedPal[28]; 77 | 78 | #endif // GRIT_MEGA_TRIGGER_ONSHARED_H 79 | 80 | //}}BLOCK(mega_trigger_onShared) 81 | 82 | //{{BLOCK(mega_trigger_disabled) 83 | 84 | //====================================================================== 85 | // 86 | // mega_trigger_disabled, 32x32@4, 87 | // + palette 16 entries, not compressed 88 | // + 16 tiles lz77 compressed 89 | // Total size: 32 + 216 = 248 90 | // 91 | // Time-stamp: 2015-06-23, 20:42:19 92 | // Exported by Cearn's GBA Image Transmogrifier, v0.8.12 93 | // ( http://www.coranac.com/projects/#grit ) 94 | // 95 | //====================================================================== 96 | 97 | #ifndef GRIT_MEGA_TRIGGER_DISABLED_H 98 | #define GRIT_MEGA_TRIGGER_DISABLED_H 99 | 100 | #define mega_trigger_disabledTilesLen 216 101 | extern const unsigned char mega_trigger_disabledTiles[216]; 102 | 103 | #define mega_trigger_disabledPalLen 32 104 | extern const unsigned short mega_trigger_disabledPal[16]; 105 | 106 | #endif // GRIT_MEGA_TRIGGER_DISABLED_H 107 | 108 | //}}BLOCK(mega_trigger_disabled) 109 | -------------------------------------------------------------------------------- /src/level_string_hook.s: -------------------------------------------------------------------------------- 1 | @ hook at 080483A4 2 | 3 | .thumb 4 | .align 2 5 | 6 | level_string_hook: 7 | lsl r4, #0x18 8 | lsr r4, #0x18 9 | 10 | @ Check if is mega 11 | ldr r0, battle_data 12 | 13 | @ Get owner of the health bar 14 | ldr r2, objects 15 | lsl r1, r5, #4 16 | add r1, r5 17 | lsl r1, r1, #2 18 | add r1, r2 19 | ldrh r1, [r1, #0x3A] 20 | 21 | mov r2, #0x58 22 | mul r1, r2 23 | add r0, r1 24 | bl is_mega 25 | cmp r1, #0 26 | bne load_special 27 | 28 | ldr r1, level_string 29 | mov r0, sp 30 | mov r2, #0x10 31 | bl memcpy 32 | mov r0, sp 33 | add r0, #2 34 | 35 | mov r1, r4 36 | mov r2, #0 37 | mov r3, #3 38 | bl int_to_str 39 | 40 | mov r1, r0 41 | sub r1, #2 42 | b return 43 | 44 | load_special: 45 | adr r1, special_string 46 | mov r0, sp 47 | mov r2, #0x10 48 | bl memcpy 49 | mov r0, sp 50 | add r0, #0 51 | 52 | mov r1, r4 53 | mov r2, #0 54 | mov r3, #3 55 | bl int_to_str 56 | 57 | mov r1, r0 58 | sub r1, #2 59 | 60 | @ 61 | mov r0, sp 62 | sub r1, r0 63 | mov r0, #3 64 | sub r0, r1 65 | lsl r1, r0, #2 66 | add r1, r1, r0 67 | sub r1, #2 68 | add r3, sp, #0x10 69 | mov r0, sp 70 | mov r2, #3 71 | ldr r6, =(0x080483D6 + 1) 72 | bx r6 73 | 74 | return: 75 | ldr r6, =(0x080483C4 + 1) 76 | bx r6 77 | 78 | int_to_str: 79 | ldr r6, =(0x08008E78 + 1) 80 | bx r6 81 | 82 | memcpy: 83 | ldr r3, =(0x081E5E78 + 1) 84 | bx r3 85 | 86 | .align 2 87 | level_string: .word 0x0826051C 88 | battle_data: .word 0x02023BE4 89 | b_current_bank: .word 0x02023D6F 90 | objects: .word 0x0202063C 91 | special_string: 92 | .byte 0xFF 93 | .rept 16 94 | .byte 0 95 | .endr 96 | -------------------------------------------------------------------------------- /src/mega.c: -------------------------------------------------------------------------------- 1 | // Mega evolution helper functions 2 | 3 | #include "mega.h" 4 | #include "common.h" 5 | #include "battle.h" 6 | #include "pokemon.h" 7 | #include "config.h" 8 | 9 | // Return all the evolution data, null otherwise 10 | evolution *can_mega_evolve(battle_data *pokemon) { 11 | // Cast to u32 for accurate calculation of the pointer 12 | evolution *evolutions = (evolution*) ((u32) evolution_table + pokemon->species * sizeof(evolution) * (*evos_per_poke + 1)); 13 | u8 i, j; 14 | 15 | for (i = 0; i <= *evos_per_poke; ++i) { 16 | if (evolutions[i].type == MEGA_EVOLUTION) { 17 | // Ignore reverison information 18 | if (evolutions[i].argument == 0) { 19 | continue; 20 | } 21 | 22 | // Check for held item 23 | if (evolutions[i].unknown == MEGA_VARIANT_STANDARD) { 24 | if (evolutions[i].argument == pokemon->held_item) { 25 | return &evolutions[i]; 26 | } 27 | } else if (evolutions[i].unknown == MEGA_VARIANT_WISH) { 28 | // Check learned moves 29 | for (j = 0; j < 4; ++j) { 30 | if (pokemon->move_ids[j] == evolutions[i].argument) { 31 | return &evolutions[i]; 32 | } 33 | } 34 | } 35 | } 36 | } 37 | 38 | // NULL 39 | return 0; 40 | } 41 | 42 | // TODO: Same as above but for primals 43 | 44 | u16 is_mega(battle_data *pokemon) { 45 | evolution *evolutions = (evolution*) ((u32) evolution_table + pokemon->species * sizeof(evolution) * (*evos_per_poke + 1)); 46 | u8 i; 47 | 48 | for (i = 0; i <= *evos_per_poke; ++i) { 49 | // Null argument means revert to that species 50 | // Match found 51 | if (evolutions[i].type == MEGA_EVOLUTION && evolutions[i].argument == 0) { 52 | return 1; 53 | } 54 | } 55 | 56 | return 0; 57 | } 58 | 59 | void build_cmdbuf_mega(u8 arg, u16 len, u8 **data); 60 | void mark_buffer_for_execution(u8 arg); 61 | 62 | void command(); 63 | void handle_mega_evolution() { 64 | u8 bank = *b_attacker; 65 | 66 | if (!megadata->trigger[bank]) return; 67 | 68 | if (megadata->done[bank & 1]) return; 69 | 70 | megadata->trigger[bank] = 0; 71 | 72 | battle_data *data = &b_data[bank]; 73 | evolution *evo = can_mega_evolve(data); 74 | 75 | // Make sure we only mega evolve once. Primals are exempt 76 | if (evo->unknown != MEGA_VARIANT_PRIMAL) { 77 | megadata->done[bank & 1] = 1; 78 | } 79 | 80 | // Null check 81 | if (evo) { 82 | *b_active_side = bank; 83 | build_cmdbuf_mega(0, 4, (u8**) &evo); 84 | 85 | *((u32*) 0x02023BC8) |= 1 << (bank); 86 | } 87 | 88 | } 89 | 90 | void handle_mega_evolutions() { 91 | u8 bank; 92 | 93 | u8 save = *b_active_side; 94 | 95 | for (bank = 0; bank < *b_num_active_sides; ++bank) { 96 | if (!megadata->trigger[bank]) continue; 97 | 98 | if (megadata->done[bank & 1]) continue; 99 | 100 | megadata->trigger[bank] = 0; 101 | 102 | battle_data *data = &b_data[bank]; 103 | evolution *evo = can_mega_evolve(data); 104 | 105 | // Make sure we only mega evolve once. Primals are exempt 106 | if (evo->unknown != MEGA_VARIANT_PRIMAL) { 107 | megadata->done[bank & 1] = 1; 108 | } 109 | 110 | // Null check 111 | if (evo) { 112 | *b_active_side = bank; 113 | build_cmdbuf_mega(0, 4, (u8**) &evo); 114 | *((u32*) 0x02023BC8) |= 1 << (bank); 115 | } 116 | } 117 | 118 | *b_active_side = save; 119 | } 120 | 121 | void revert_mega(u8 *poke) { 122 | u16 species = 0; 123 | u16 current_species = (u16) (u32) pokemon_getattr(poke, 0xB, 0); 124 | 125 | evolution *evolutions = (evolution*) ((u32) evolution_table + current_species 126 | * sizeof(evolution) * (*evos_per_poke + 1)); 127 | u8 i; 128 | 129 | for (i = 0; i <= *evos_per_poke; ++i) { 130 | // Null argument means revert to that species 131 | // Match found 132 | if (evolutions[i].type == MEGA_EVOLUTION && evolutions[i].argument == 0) { 133 | species = evolutions[i].species; 134 | } 135 | } 136 | 137 | // If a match was found 138 | if (species) { 139 | pokemon_setattr(poke, 0xB, (u8*) &species); 140 | recalc_stats(poke); 141 | } 142 | } 143 | 144 | void reset_mega(); 145 | 146 | void revert_megas() { 147 | u8 *player_party = (u8*) 0x02024284; 148 | u8 *poke_quantity = (u8*) 0x02024029; 149 | u8 i; 150 | 151 | for (i = 0; i < *poke_quantity; ++i) { 152 | revert_mega(player_party + i * 100); 153 | } 154 | 155 | reset_mega(); 156 | } 157 | 158 | void reset_mega() { 159 | u8 i; 160 | for(i = 0; i < 4; ++i) megadata->done[i] = 0; 161 | for(i = 0; i < 4; ++i) megadata->trigger[i] = 0; 162 | } 163 | 164 | u8 mega_evolution_enabled() { 165 | u16 *var = var_access(KEYSTONE_PLAYER_VAR); 166 | #ifndef DISABLE_KEYSTONE_CHECK 167 | if (!checkitem(*var, 1)) return 0; 168 | #endif 169 | 170 | return 1; 171 | } 172 | 173 | /* 174 | * Pokemon cannot be given the potential to Mega Evolve during battle. 175 | * You cannot give them their Mega Stone or take it away from them one the 176 | * battle has started. Switcheroo and other moves will just fail. 177 | */ 178 | 179 | // For thief, covet, knock-off, etc. 180 | u8 can_remove_item(u8 bank) { 181 | // Cannot remove stones held by appropriate Pokemon 182 | return 0; 183 | } 184 | 185 | // For switcheroo, trick, bestow, etc. 186 | u8 can_give_item(u8 bank, u16 item) { 187 | // Cannot give a Pokemon their own Mega Stone 188 | return 0; 189 | } 190 | 191 | void mega_reset_player_triggers() { 192 | megadata->trigger[0] = 0; 193 | megadata->trigger[2] = 0; 194 | } 195 | -------------------------------------------------------------------------------- /src/mega.h: -------------------------------------------------------------------------------- 1 | #ifndef MEGA_H_ 2 | #define MEGA_H_ 3 | 4 | #include "types.h" 5 | #include "battle.h" 6 | #include "evo.h" 7 | 8 | typedef struct mega_data { 9 | u8 trigger[4]; 10 | u8 done[4]; 11 | u8 running; 12 | } mega_data; 13 | 14 | // Some unused RAM again 15 | mega_data *megadata = (mega_data *) 0x02022B40; 16 | 17 | evolution *can_mega_evolve(battle_data *pokemon); 18 | u16 is_mega(battle_data *pokemon); 19 | u8 mega_evolution_enabled(); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/mega_level_icon.s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Touched/MegaEvolution/d98cdbd2339a4110711705dd9e46135b41f70e08/src/mega_level_icon.s -------------------------------------------------------------------------------- /src/move_exec_hook.s: -------------------------------------------------------------------------------- 1 | .thumb 2 | 3 | @ 0801DB00 in r1 4 | .align 2 5 | attack_canceller_hook: 6 | bl handle_mega_evolution 7 | mov r8, r3 8 | mov r9, r4 9 | pop {r4-r7} 10 | pop {r0} 11 | bx r0 12 | 13 | @ 080154A0 in r0 14 | .align 2 15 | bc_pre_attacks_hook: 16 | push {r4-r7, lr} 17 | ldr r0, =(0x02023DD0) 18 | ldr r0, [r0] 19 | ldr r1, =0x8000 20 | 21 | push {r0-r3} 22 | bl handle_mega_evolutions 23 | pop {r0-r3} 24 | 25 | ldr r2, =(0x080154AA + 1) 26 | bx r2 27 | -------------------------------------------------------------------------------- /src/move_menu_hook.s: -------------------------------------------------------------------------------- 1 | @ hook at 0802EC10 2 | 3 | .thumb 4 | .align 2 5 | 6 | move_button_hook: 7 | mov r7, #2 @ B Button 8 | mov r0, r7 9 | and r0, r1 10 | cmp r0, #0 11 | beq check_start 12 | 13 | @ Handle B button 14 | ldr r0, =(0x0802EC1A + 1) 15 | bx r0 16 | 17 | check_start: 18 | mov r0, #8 @ Start 19 | and r0, r1 20 | cmp r0, #0 21 | beq check_left 22 | 23 | @ Hook code here 24 | bl trigger_mega_evolution 25 | 26 | @ Return 27 | ldr r0, =(0x0802EDBA + 1) 28 | bx r0 29 | 30 | check_left: 31 | ldr r0, =(0x0802EC38 + 1) 32 | bx r0 33 | 34 | @ 0802E438 in r0 35 | battle_menu_hook: 36 | push {r4-r7, lr} 37 | mov r7, r8 38 | push {r7} 39 | 40 | bl mega_reset_player_triggers 41 | 42 | ldr r7, =(0x02022BC4) 43 | ldr r4, =(0x0802E440 + 1) 44 | bx r4 45 | 46 | -------------------------------------------------------------------------------- /src/objects.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTS_H_ 2 | #define OBJECTS_H_ 3 | 4 | #include "types.h" 5 | 6 | struct object; 7 | typedef struct object object; 8 | typedef void (*object_callback)(object*); 9 | 10 | typedef struct frame { 11 | u16 data; 12 | u16 duration; 13 | } frame; 14 | 15 | typedef struct rotscale_frame { 16 | u16 scale_delta_x; 17 | u16 scale_delta_y; 18 | u8 rot_delta; 19 | u8 duration; 20 | u16 field_6; 21 | } rotscale_frame; 22 | 23 | typedef struct sprite { 24 | u16 attr0; 25 | u16 attr1; 26 | u16 attr2; 27 | u16 rotscale; 28 | } sprite; 29 | 30 | typedef struct template { 31 | u16 tiles_tag; 32 | u16 pal_tag; 33 | sprite *oam; 34 | frame **animation; 35 | u32 *graphics; 36 | rotscale_frame **rotscale; 37 | object_callback callback; 38 | } template; 39 | 40 | typedef struct object { 41 | sprite final_oam; 42 | frame **animation_table; 43 | u32 *gfx_table; 44 | u32 *rotscale_table; 45 | template *template; 46 | u32 field18; 47 | u32 *callback; 48 | u16 x; 49 | u16 y; 50 | u16 x2; 51 | u16 y2; 52 | u8 x_centre; 53 | u8 y_centre; 54 | u8 anim_number; 55 | u8 anim_frame; 56 | u8 anim_delay; 57 | u8 counter; 58 | u16 private[8]; 59 | u8 bitfield2; 60 | u8 bitfield; 61 | u16 anim_data_offset; 62 | u8 field42; 63 | u8 field43; 64 | } object; 65 | 66 | typedef struct resource { 67 | const void *data; 68 | u16 size; 69 | u16 tag; 70 | } resource; 71 | 72 | u8 template_instanciate_forward_search(struct template *t, u16 x, u16 y, u8 b); 73 | u16 gpu_tile_obj_decompress_alloc_tag_and_upload(resource *src); 74 | object *objects = (object*) 0x0202063C; 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/pokemon.h: -------------------------------------------------------------------------------- 1 | #ifndef POKEMON_H_ 2 | #define POKEMON_H_ 3 | 4 | #include "types.h" 5 | 6 | typedef struct pokemon_base 7 | { 8 | u8 hp; 9 | u8 atk; 10 | u8 def; 11 | u8 spd; 12 | u8 spatk; 13 | u8 spdef; 14 | u8 type1; 15 | u8 type2; 16 | u8 catch_rate; 17 | u8 xp_yield; 18 | u16 effort_yield; 19 | u16 item1; 20 | u16 item2; 21 | u8 gender; 22 | u8 steps_to_hatch; 23 | u8 base_friendship; 24 | u8 exp_point_table_nr; 25 | u8 eggroup1; 26 | u8 eggroup2; 27 | u8 ability1; 28 | u8 ability2; 29 | u8 safari_zone_flee_rate; 30 | u8 color; 31 | u16 padding; 32 | } pokemon_base; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/strings.c: -------------------------------------------------------------------------------- 1 | #include "text.h" 2 | 3 | char str_mega_evo[] = { 4 | PC_BUFFER(0), PC_APOSTROPHE, PC_s, PC_SPACE, PC_BUFFER(1), 5 | PC_SPACE, 6 | PC_i, PC_s, 7 | PC_SPACE, 8 | PC_r, PC_e, PC_a, PC_c, PC_t, PC_i, PC_n, PC_g, 0xFE, 9 | PC_t, PC_o, 10 | PC_SPACE, 11 | PC_BUFFER(2), PC_APOSTROPHE, PC_s, PC_SPACE, PC_BUFFER(3), 12 | PC_EXCLAMATION, PC_END // ! 13 | }; 14 | 15 | char str_fervent_wish[] = { 16 | PC_BUFFER(2), PC_APOSTROPHE, PC_s, PC_SPACE, PC_f, PC_e, PC_r, PC_v, PC_e, PC_n, PC_t, 17 | PC_SPACE, PC_w, PC_i, PC_s, PC_h, PC_NEWLINE, PC_h, PC_a, PC_s, PC_SPACE, 18 | PC_r, PC_e, PC_a, PC_c, PC_h, PC_e, PC_d, PC_SPACE, PC_BUFFER(0), 19 | PC_EXCLAMATION, PC_END 20 | }; 21 | 22 | char str_post_mega[] = { 23 | PC_BUFFER(0), PC_SPACE, PC_M, PC_e, PC_g, PC_a, PC_SPACE, PC_E, PC_v, PC_o, 24 | PC_l, PC_v, PC_e, PC_d, PC_SPACE, PC_i, PC_n, PC_t, PC_o, PC_SPACE, 0xFE, 25 | PC_M, PC_e, PC_g, PC_a, PC_SPACE, PC_BUFFER(4), PC_EXCLAMATION, PC_END 26 | }; 27 | 28 | char *str_before[] = { 29 | str_mega_evo, 30 | 0, 31 | str_fervent_wish 32 | }; 33 | 34 | char *str_after[] = { 35 | str_post_mega, 36 | 0, 37 | str_post_mega 38 | }; 39 | -------------------------------------------------------------------------------- /src/strings.h: -------------------------------------------------------------------------------- 1 | #ifndef STRINGS_H_ 2 | #define STRINGS_H_ 3 | 4 | extern char *str_before[]; 5 | extern char *str_after[]; 6 | 7 | u8 a_pressed_maybe(u8); 8 | u8 *string_buffer_maybe = (u8*) 0x0202298C; 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/tables.h: -------------------------------------------------------------------------------- 1 | #ifndef TABLES_H_ 2 | #define TABLES_H_ 3 | 4 | #include "evo.h" 5 | 6 | char **pokemon_names_ptr = (char **) 0x08011450; 7 | char **item_names_ptr = (char **) 0x0809A944; 8 | u8 **trainers_ptr = (u8 **) 0x0800FC00; 9 | pokemon_base **base_stats_ptr= (pokemon_base**) 0x08136794; 10 | 11 | #define pokemon_names (*pokemon_names_ptr) 12 | #define item_names (*item_names_ptr) 13 | #define trainers (*trainers_ptr) 14 | #define base_stats (*base_stats_ptr) 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/text.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXT_H_ 2 | #define TEXT_H_ 3 | 4 | #define MSGBOX_LEN 35 5 | 6 | #define PC_BUFFER(x) 0xFD, x 7 | #define PC_END 0xFF 8 | #define PC_SPACE 0x0 9 | #define PC_NEWLINE 0xFE 10 | 11 | // Punctutation 12 | #define PC_EXCLAMATION 0xAB 13 | #define PC_APOSTROPHE 0xB4 14 | 15 | // Uppercase 16 | #define PC_A 0xBB 17 | #define PC_B 0xBC 18 | #define PC_C 0xBD 19 | #define PC_D 0xBE 20 | #define PC_E 0xBF 21 | #define PC_F 0xC0 22 | #define PC_G 0xC1 23 | #define PC_H 0xC2 24 | #define PC_I 0xC3 25 | #define PC_J 0xC4 26 | #define PC_K 0xC5 27 | #define PC_L 0xC6 28 | #define PC_M 0xC7 29 | #define PC_N 0xC8 30 | #define PC_O 0xC9 31 | #define PC_P 0xCA 32 | #define PC_Q 0xCB 33 | #define PC_R 0xCC 34 | #define PC_S 0xCD 35 | #define PC_T 0xCE 36 | #define PC_U 0xCF 37 | #define PC_V 0xD0 38 | #define PC_W 0xD1 39 | #define PC_X 0xD2 40 | #define PC_Y 0xD3 41 | #define PC_Z 0xD4 42 | 43 | // Lowercase 44 | #define PC_a 0xD5 45 | #define PC_b 0xD6 46 | #define PC_c 0xD7 47 | #define PC_d 0xD8 48 | #define PC_e 0xD9 49 | #define PC_f 0xDA 50 | #define PC_g 0xDB 51 | #define PC_h 0xDC 52 | #define PC_i 0xDD 53 | #define PC_j 0xDE 54 | #define PC_k 0xDF 55 | #define PC_l 0xE0 56 | #define PC_m 0xE1 57 | #define PC_n 0xE2 58 | #define PC_o 0xE3 59 | #define PC_p 0xE4 60 | #define PC_q 0xE5 61 | #define PC_r 0xE6 62 | #define PC_s 0xE7 63 | #define PC_t 0xE8 64 | #define PC_u 0xE9 65 | #define PC_v 0xEA 66 | #define PC_w 0xEB 67 | #define PC_x 0xEC 68 | #define PC_y 0xED 69 | #define PC_z 0xEE 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src/types.h: -------------------------------------------------------------------------------- 1 | #ifndef TYPES_H_ 2 | #define TYPES_H_ 3 | 4 | typedef unsigned char u8; 5 | typedef unsigned short int u16; 6 | typedef unsigned int u32; 7 | typedef unsigned long long int u64; 8 | 9 | typedef signed char s8; 10 | typedef signed short int s16; 11 | typedef signed int s32; 12 | typedef signed long long int s64; 13 | 14 | typedef float f32; 15 | typedef double f64; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /symbol.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Touched/MegaEvolution/d98cdbd2339a4110711705dd9e46135b41f70e08/symbol.png --------------------------------------------------------------------------------