Isn't needed but is relevant; earlier commit da47ee2f3c fixes the issue directly but this also fixes (and properly modifies all relevant aspects of the object).
da47ee2f3c
pk3DS: A package of Pokémon X/Y/OR/AS ROM Editing Tools by various contributors.