Commit Graph

57 Commits

Author SHA1 Message Date
GearsProgress
0577a450da Formatting (again) 2026-10-22 15:04:58 -04:00
GearsProgress
f1e2b62e4a Applying formatting and moving libraries into specific folders 2026-10-18 11:07:35 -04:00
Philippe Symons
00a2f1d55e Fix crash when transferring to Spanish Emerald
There was a problem with Spanish Emerald triggering a crash in mystery_gift_injector.cpp

The problem was that the section30 and script BPS patch FileContainers specify @chunkSize=4096 in their .containerdef files.

However, mystery_gift_injector.cpp didn't specify a chunkSize in the constructor of the FileContainerReader instances in reconstructPregeneratedPayloads()

This resulted in it falling back to DEFAULT_CHUNK_SIZE, which is 2048.

Fix: Specify chunkSize 4096 as a constructor argument!
2026-10-02 17:05:28 +02:00
Philippe Symons
91791243a1 Merge branch 'release-candidate' into have-build-lang-independent-gba-payload-translations 2026-09-30 17:07:30 +02:00
GearsProgress
503478d665 Adding global compression header 2026-09-28 16:15:09 -04:00
Philippe Symons
a6b34279f1 Work on multilang gba payloads (WIP/broken)
Do some more work for multilang gba payloads. Revise the patch structure and make it use the right RSEFRLG table.

But it's broken. For some reason the english text doesn't show up when running the payload. Don't ask me why yet.
2026-09-28 17:09:44 +02:00
Philippe Symons
f11c11d5bf Make gba payload translations independent from BUILD_LANG (WIP/untested) 2026-09-25 21:20:21 +02:00
Philippe Symons
1b0efc2166 Use a 4096 byte chunkSize for the bps patch containers to maximize compression 2026-09-25 09:25:29 +02:00
Philippe Symons
b49a0793db Fix bug 2026-09-24 16:07:41 +02:00
Philippe Symons
11a581061f Fix first_time text entries in payload (untested)
first_time entries would be longer, therefore the reference pointers inside the payload would shift.

To avoid that, we now reserve space for the longest entry, knowing that the texts will get stripped after
the payloads have been generated.

Doing so ensures that the text offsets remain constant, no matter if we're dealing with the first_time or othertimes payload.

This also means we need to take that reservation into account on the PTGB rom side of things of course.
To do so, I created a pair array indicating the first time entries and there non-first_time counterparts.

We'll determine which entry is the longest and ensure we use that length for the offset of the next entry.
2026-09-22 17:10:20 +02:00
Philippe Symons
12183e51d7 Bugfix: make sure to move data that is stored at the text insertion point out of the way.
We just overwrote it.
2026-09-22 15:45:27 +02:00
Philippe Symons
8015d8187b Merge branch 'isolate_mystery_gift_builder' into strip-texts-from-generated-payloads 2026-09-22 14:16:39 +02:00
Philippe Symons
0e5cf21010 Merge remote-tracking branch 'upstream/release-candidate' into isolate_mystery_gift_builder 2026-09-22 14:15:58 +02:00
Philippe Symons
2945baa71c Add comment 2026-09-17 16:33:41 +02:00
Philippe Symons
c8b95b418e There are only 8 entries in section30TextSequence 2026-09-17 16:32:09 +02:00
Philippe Symons
3579fe6658 Reinject RSEFRLG table entries into the GBA payload at runtime. (untested)
This commit makes mystery_gift_injector re-insert the text entries into the gba payload at runtime.

You may or may not remember that I made gba-payload-generator strip the text entries again after generating the payloads.
I did this to improve compression: it removes the variability of the text lengths. It also ensures that texts are not really part of the BPS patch files
that are generated to transform the base payload into a specific language and game variant.

Therefore, we don't run at risk of storing certain text entries multiple times (or partially multiple times) due to them being stored at FileContainer boundaries.
It should make patch files smaller and more predictable.

Stripping the text entries also made it easy to reinsert: almost every rom uses the same offset for the first entry.
We now only need to store each language variant of the RSEFRLG (variants aren't being generated yet) once. That should be a big boon.

By first generating the payloads and THEN stripping the texts, we also ensure that the pointers/references within the payload remain intact and will become valid
again once the texts get reinserted.

Anyway, this specific commit does the re-insertion of those text entries into the payload (script + section30) using the RSEFRLG table.

Because the text stripping takes out these variable length texts, the text insertion offsets always end up the same, no matter the language:

Section30: 0x97E
Script:
- Ruby/Sapphire: 0x268
- Fire Red/Leaf Green: 0x278
- Emerald: 0x298
2026-09-17 16:13:08 +02:00
Philippe Symons
ac257b314f Fix transfer issue in isolate_mystery_gift_builder branch
Problem: several variables were used in mystery_gift_builder before they were initialized.
Fix: initialize them.

I also made sure to memset the entire buffer before generating a payload to avoid garbage data to seep in.
2026-09-09 15:30:07 +02:00
Philippe Symons
82d394d1bb Eliminate some code duplication in reconstruct_pregenerated_payloads and rename generate_payloads.sh 2026-09-04 15:47:33 +02:00
Philippe Symons
3ed33fac2b Make sure to zero tempBuffer in between 2026-08-28 21:56:34 +02:00
Philippe Symons
e96821aed5 Fix bug and improve logs
Bugfix: do not apply the same base payload patch twice.

I also improved the mystery_gift_builder log messages a bit.
2026-08-28 16:15:11 +02:00
Philippe Symons
3145fe69d2 Make us have less base payloads.
For example, Fire Red and Leaf green are (almost?) identical. But if we create separate base payloads, it takes up way more space.
2026-08-28 15:12:39 +02:00
Philippe Symons
353359455a Integrate Pi's bps_patch function to apply bps patches to our base payloads and turn them into the game-specific ones. 2026-08-28 14:27:09 +02:00
Philippe Symons
75a0028cd2 Merge branch 'bugfix/gb-payload-lockup-on-transfer' into isolate_mystery_gift_builder
and convert PokeBox BEFORE injection (to separate IWRAM consumption)
2026-08-20 13:58:44 +02:00
Philippe Symons
5be8fd25ef No need to create another PokemonTables instance 2026-08-11 14:25:43 +02:00
Philippe Symons
b8b0dd25e4 Integrate the pregenerated payload into mystery_gift_injector (WIP, untested)
This commit integrates the pregenerated payload into mystery_gift_injector.

It currently hardcodes the English Ruby v1.2 payload for testing purposes though.

The next test I'll have to do is to see if the transfer process works with this specific rom.

If it works, I can start integrating Pi's work in regards to delta patching using BPS.
2026-08-11 13:40:07 +02:00
GearsProgress
927c0b7b7c Merge branch 'release-candidate' into gameboy-payload-update 2026-07-27 17:30:03 -04:00
GearsProgress
21702c135f Adding the ability to reset the PokeBox 2026-07-27 16:23:37 -04:00
Philippe Symons
2982b9ba93 Add debug menu entry to inject Celebi (WIP) 2026-03-25 21:49:41 +01:00
The Gears of Progress
9ca5c650d0 Working on debugging 2025-12-03 22:08:35 -05:00
The Gears of Progress
ba1a075701 Adding PCCS 2025-10-12 15:08:33 -04:00
Philippe Symons
eef173b0d2 Fix crash + unrelated buffer overflow + some optimizations
There was a crash happening with ptgb::vector when you'd press A on the CONFIRM button of the box screen. It only occurred on actual gba hardware and
was a real heisenbug: as soon as you'd add code to display logs on screen, the problem would disappear. So it was very difficult to figure this one
out. We're not even entirely sure why, but it looks like the malloc/realloc/free use in ptgb::vector would cause issues.

Maybe it was alignment, but after messing with the code we also saw a warning appear in the terminal telling us that realloc wouldn't properly
deal with non-POD types. It complained about this very thing while referring to the add_track() function, which stores ptgb::vectors inside another
ptgb::vector. We also didn't have a custom copy constructor yet to actually copy the buffer instead of its pointer.
All of these could potentially have led to the crash. But debugging during the link cable flow was difficult, so we were never able to confirm it in
a debugger, log or dump.

Because I suspected the high IWRAM consumption (especially now with ZX0 decompression) for a while, I also did an optimization in mystery_gift_builder
to pass global_memory_buffer as its section_30_data buffer instead. This reduces IWRAM consumption by 4 KB.

There was another problem I discovered during my crash hunt: the out_array (now payload_buffer) was allocated as a 672 byte array, but the payloads
were actually 707 bytes. Therefore writing this to the buffer caused a buffer overflow, thereby corrupting the global variables appearing after it in
IWRAM. It turned out eventually that none of these variables were really critical, but it could explain some minor bugs GearsProgress has seen.

I also did a few performance optimizations:

- At various stages in the code, for loops were used to copy data from one buffer into another byte-by-byte. This was far from optimal because the gba
cpu can load/copy 4 bytes at a time if you ask it to. So I replaced those with memcpy(), which is a hand-optimized assembly function to copy data
using this principle.

- generate_payload was being called twice: once at start_link and once at continue_link, giving the exact same result, even though it was already
being stored in a global buffer allocated in IWRAM. This was also a fairly heavy function. So I optimized the code to only initialize it once in
the script chain and then just retrieve the buffer.

- generate_payload was constructing the eventual payload twice even within the same call. That's because it first merged z80_rng_seed, z80_payload
and z80_patchlist into a full_data ptgb::vector, after which it then copied the data again to out_array (now called payload_buffer). I eliminated the
full_data vector now.
2025-06-18 10:23:03 +02:00
Philippe Symons
903ccb0d21 Some minor optimizations 2025-05-21 17:29:12 +02:00
Philippe Symons
26fd1e2dd3 Add compression for the text data, output stack usage .su files and rework script_array
Add a binary table format and convert the text entries into this format in text_helper/main.py. It then gets compressed with zx0.

The new text_data_table and streamed_data_table classes exist to read the various entries from this binary table. streamed_data_table specifically
exists to use a decompression buffer that is smaller than the actual binary table. But it requires a decompression buffer that is
still larger than ZX0_DEFAULT_WINDOW_SIZE (default: 2048 bytes) and will only be able to decompress in
chunks of (<decompression_buffer_size> - <ZX0_DEFAULT_WINDOW_SIZE>) bytes

Try to keep the binary text tables sufficiently small though, because since zx0 doesn't actually support random access,
getting to the last entry is significantly more expensive than reading the first one. And unless you use streamed_data_table,
it also requires <uncompressed_size> bytes of stack space, therefore IWRAM to decompress them.

I also had to rework script_array because it can no longer reference the strings directly. Instead we now reference the DIA_* "enum" values.
We also no longer store an array of script_obj instances, because these were getting stored in IWRAM since they're non-const global variables
originally. Instead we now have const arrays of script_obj_params structs, which should end up in .rodata -> therefore EWRAM.

Right now, script_obj only supports the PTGB text table (originally the dialogue array). But if the need arises to support other tables as well,
I'd consider adding a separate enum to script_obj_params to indicate the specific table.

The compilation process will also output .su files in the build folder from now on. These files indicate the stack frame size for every function in
every compilation unit, so be sure to check them from time to time. Note that they will only show the stack consumption for that specific function.
So to get the worst case stack consumption, you need to manually add all the functions in a certain stack flow.
2025-05-21 12:21:06 +02:00
Philippe Symons
532a095d77 Implement zx0 compression
Compress data tables with the ZX0 compression algorithm
2025-04-24 21:14:48 +02:00
The Gears of Progress
41f7fcb1aa *Finally* fixing the EXP bug 2024-12-19 18:15:04 -05:00
The Gears of Progress
b382aec0dc pre Pokemon and Party rewrite 2024-12-19 13:29:47 -05:00
The Gears of Progress
884ebc9216 Adding data packets to GSC 2024-10-31 10:59:36 -04:00
The Gears of Progress
9d3221ae8d Adding more debug features 2024-09-25 20:49:10 -04:00
The Gears of Progress
e3c5898683 Fixing contest hall data bug 2024-09-25 14:51:20 -04:00
The Gears of Progress
73fd2342e9 Last push before release (probably not actually though lol) 2024-08-20 23:31:07 -04:00
The Gears of Progress
1ec09842ad Updating tons of graphics 2024-08-19 14:47:29 -04:00
The Gears of Progress
7aa6933dd6 Fixing crash 2024-07-05 19:20:05 -04:00
The Gears of Progress
8f07b1ebdb Re-enabling the old event 2024-07-01 16:45:54 -04:00
The Gears of Progress
5950e53e88 Continuing work on updated event 2024-06-22 11:24:43 -04:00
Remnants of Forgotten Disney
a27f1c2c37 Continuing transfer menu implementation 2024-04-02 12:19:06 -05:00
Remnants of Forgotten Disney
53e7748d48 Organizing files 2024-03-19 13:52:23 -05:00
Remnants of Forgotten Disney
c825203e70 Modifying save data flags 2024-03-04 16:56:14 -06:00
Remnants of Forgotten Disney
4768f72a50 Moving Pokemon data to Sector 30 2024-03-03 17:42:59 -06:00
Remnants of Forgotten Disney
020d27433d Preparing for ASM rewrite 2024-02-24 14:53:12 -06:00
Remnants of Forgotten Disney
1b5f30087a Modifying Pokemon Injection 2024-02-19 08:29:37 -06:00