Restructure asset processor

This commit is contained in:
octorock 2021-11-07 18:38:04 +01:00
parent 473bc5f260
commit e44d0e3fc9
45 changed files with 3832 additions and 2522 deletions

View File

@ -149,8 +149,8 @@ MAKEFLAGS += --no-print-directory
AUTO_GEN_TARGETS :=
# TODO do we really need this extra step just so that extractassets always runs at first?
all: extractassets
# TODO do we really need this extra step just so that the assets are always extracted at first?
all: build/extracted_assets_$(GAME_VERSION)
@$(MAKE) target GAME_VERSION=$(GAME_VERSION)
target: $(ROM)
@ -162,10 +162,13 @@ compare: $(ROM)
setup: $(TOOLDIRS)
# TODO temporary workaround to have translation bins as dependencies manually here as scaninc somehow does not work?
extractassets: translations/USA.bin translations/English.bin translations/French.bin translations/German.bin translations/Spanish.bin translations/Italian.bin
build/extracted_assets_%: assets/assets.json assets/gfx.json assets/map.json assets/samples.json assets/sounds.json
tools/asset_processor/asset_processor extract $(GAME_VERSION) $(ASSET_BUILDDIR)
# python3 tools/asset_extractor/asset_extractor.py $(GAME_VERSION) $(ASSET_BUILDDIR)
touch $@
# Extract assets to human readable form
extractassets:
tools/asset_processor/asset_processor convert $(GAME_VERSION) $(ASSET_BUILDDIR)
$(TOOLDIRS):
@$(MAKE) -C $@

View File

@ -43915,829 +43915,829 @@
"path": "sprites/gSpriteFrames_1.bin",
"start": 1134488,
"size": 1012,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_2.bin",
"start": 1135500,
"size": 920,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_3.bin",
"start": 1136420,
"size": 980,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_4.bin",
"start": 1137400,
"size": 932,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_5.bin",
"start": 1138332,
"size": 996,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_6.bin",
"start": 1139328,
"size": 688,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_7.bin",
"start": 1140016,
"size": 856,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_8.bin",
"start": 1140872,
"size": 532,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_9.bin",
"start": 1141404,
"size": 624,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Object4.bin",
"start": 1142028,
"size": 200,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Object6.bin",
"start": 1142228,
"size": 400,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_12.bin",
"start": 1142628,
"size": 676,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_13.bin",
"start": 1143304,
"size": 56,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_14.bin",
"start": 1143360,
"size": 924,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_15.bin",
"start": 1144284,
"size": 724,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_16.bin",
"start": 1145008,
"size": 724,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_17.bin",
"start": 1145732,
"size": 480,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_18.bin",
"start": 1146212,
"size": 220,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_19.bin",
"start": 1146432,
"size": 296,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_20.bin",
"start": 1146728,
"size": 108,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_21.bin",
"start": 1146836,
"size": 480,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_22.bin",
"start": 1147316,
"size": 48,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_24.bin",
"start": 1147364,
"size": 84,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_25.bin",
"start": 1147448,
"size": 44,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_26.bin",
"start": 1147492,
"size": 52,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_27.bin",
"start": 1147544,
"size": 256,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_28.bin",
"start": 1147800,
"size": 36,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_29.bin",
"start": 1147836,
"size": 176,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_30.bin",
"start": 1148012,
"size": 60,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_31.bin",
"start": 1148072,
"size": 176,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_32.bin",
"start": 1148248,
"size": 456,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_33.bin",
"start": 1148704,
"size": 72,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Object6A_0.bin",
"start": 1148776,
"size": 24,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Object6A_1.bin",
"start": 1148800,
"size": 8,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Object6A_2.bin",
"start": 1148808,
"size": 12,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_MinishEzlo.bin",
"start": 1148820,
"size": 300,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Object6A_3.bin",
"start": 1149120,
"size": 136,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Din.bin",
"start": 1149256,
"size": 24,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Nayru.bin",
"start": 1149280,
"size": 20,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Farore.bin",
"start": 1149300,
"size": 20,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Npc5.bin",
"start": 1149320,
"size": 632,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_GuardWithSpear.bin",
"start": 1149952,
"size": 312,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_KingDaltus.bin",
"start": 1150264,
"size": 108,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_MinisterPotho.bin",
"start": 1150372,
"size": 44,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Npc26.bin",
"start": 1150416,
"size": 12,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Maid.bin",
"start": 1150428,
"size": 128,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_TingleSiblings.bin",
"start": 1150556,
"size": 168,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Beedle.bin",
"start": 1150724,
"size": 56,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Brocco.bin",
"start": 1150780,
"size": 40,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Pina.bin",
"start": 1150820,
"size": 52,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Postman.bin",
"start": 1150872,
"size": 264,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Malon.bin",
"start": 1151136,
"size": 68,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Epona.bin",
"start": 1151204,
"size": 56,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_MilkCart.bin",
"start": 1151260,
"size": 16,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Smith.bin",
"start": 1151276,
"size": 92,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Townsperson.bin",
"start": 1151368,
"size": 288,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_58.bin",
"start": 1151656,
"size": 672,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Kid.bin",
"start": 1152328,
"size": 636,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Mailbox.bin",
"start": 1152964,
"size": 48,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_SittingPerson.bin",
"start": 1153012,
"size": 208,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Mutoh.bin",
"start": 1153220,
"size": 40,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Carpenter.bin",
"start": 1153260,
"size": 184,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Gorman.bin",
"start": 1153444,
"size": 84,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Cat.bin",
"start": 1153528,
"size": 124,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_66.bin",
"start": 1153652,
"size": 124,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Dog.bin",
"start": 1153776,
"size": 140,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_68.bin",
"start": 1153916,
"size": 116,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_69.bin",
"start": 1154032,
"size": 116,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Syrup.bin",
"start": 1154148,
"size": 144,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Percy.bin",
"start": 1154292,
"size": 96,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Farmers_0.bin",
"start": 1154388,
"size": 84,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Farmers_1.bin",
"start": 1154472,
"size": 84,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Dampe.bin",
"start": 1154556,
"size": 28,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_KingGustaf.bin",
"start": 1154584,
"size": 44,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Gina.bin",
"start": 1154628,
"size": 108,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Simon.bin",
"start": 1154736,
"size": 40,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Mama.bin",
"start": 1154776,
"size": 168,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Teachers.bin",
"start": 1154944,
"size": 36,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_80.bin",
"start": 1154980,
"size": 48,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_WindTribespeople_0.bin",
"start": 1155028,
"size": 72,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_WindTribespeople_1.bin",
"start": 1155100,
"size": 48,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_WindTribespeople_2.bin",
"start": 1155148,
"size": 28,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_WindTribespeople_3.bin",
"start": 1155176,
"size": 60,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_WindTribespeople_4.bin",
"start": 1155236,
"size": 40,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_WindTribespeople_5.bin",
"start": 1155276,
"size": 24,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_MayorHagen.bin",
"start": 1155300,
"size": 64,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_GhostBrothers.bin",
"start": 1155364,
"size": 32,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_HurdyGurdyMan.bin",
"start": 1155396,
"size": 56,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Cow.bin",
"start": 1155452,
"size": 76,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_GoronMerchant.bin",
"start": 1155528,
"size": 48,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_92.bin",
"start": 1155576,
"size": 48,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Goron.bin",
"start": 1155624,
"size": 88,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_CastorWildsStatue.bin",
"start": 1155712,
"size": 12,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Npc4F.bin",
"start": 1155724,
"size": 28,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Object6A_4.bin",
"start": 1155752,
"size": 40,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_97.bin",
"start": 1155792,
"size": 44,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_DarkNut_0.bin",
"start": 1155836,
"size": 532,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_DarkNut_1.bin",
"start": 1156368,
"size": 588,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_ChuchuBoss_0.bin",
"start": 1156956,
"size": 76,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_DeathFx_0.bin",
"start": 1157032,
"size": 196,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Madderpillar_0.bin",
"start": 1157228,
"size": 96,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Gleerok_0.bin",
"start": 1157324,
"size": 232,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Keaton.bin",
"start": 1157556,
"size": 120,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_MazaalHand.bin",
"start": 1157676,
"size": 80,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_ScissorsBeetle.bin",
"start": 1157756,
"size": 156,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_MandiblesProjectile.bin",
"start": 1157912,
"size": 224,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Stalfos.bin",
"start": 1158136,
"size": 300,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Gibdo.bin",
"start": 1158436,
"size": 168,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Lakitu.bin",
"start": 1158604,
"size": 228,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_LakituCloudProjectile.bin",
"start": 1158832,
"size": 40,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_VaatiRebornEnemy_0.bin",
"start": 1158872,
"size": 76,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_VaatiRebornEnemy_1.bin",
"start": 1158948,
"size": 16,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_VaatiRebornEnemy_2.bin",
"start": 1158964,
"size": 48,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_VaatiRebornEnemy_3.bin",
"start": 1159012,
"size": 40,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_VaatiBall.bin",
"start": 1159052,
"size": 48,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_VaatiTransfigured_0.bin",
"start": 1159100,
"size": 20,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_VaatiTransfigured_1.bin",
"start": 1159120,
"size": 48,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_VaatiTransfigured_2.bin",
"start": 1159168,
"size": 28,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_VaatiTransfigured_3.bin",
"start": 1159196,
"size": 16,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_VaatiArm.bin",
"start": 1159212,
"size": 132,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_VaatiWrath.bin",
"start": 1159344,
"size": 128,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_VaatiReborn.bin",
"start": 1159472,
"size": 72,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_MoblinLady_1.bin",
"start": 1159544,
"size": 24,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_BallChainSoldier.bin",
"start": 1159568,
"size": 132,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_GyorgMale.bin",
"start": 1159700,
"size": 68,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_JarPortal.bin",
"start": 1159768,
"size": 60,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Beanstalk_0.bin",
"start": 1159828,
"size": 104,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Minecart.bin",
"start": 1159932,
"size": 80,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_LavaPlatform_1.bin",
"start": 1160012,
"size": 72,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_BigVortex.bin",
"start": 1160084,
"size": 16,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_MacroBook.bin",
"start": 1160100,
"size": 16,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_GentariCurtains.bin",
"start": 1160116,
"size": 20,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_SpiderWeb.bin",
"start": 1160136,
"size": 64,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Object79.bin",
"start": 1160200,
"size": 312,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_OctorokBoss_0.bin",
"start": 1160512,
"size": 36,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Bell.bin",
"start": 1160548,
"size": 20,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_322.bin",
"start": 1160568,
"size": 968,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "sprites/gSpriteFrames_Vaati_1.bin",
"start": 1161536,
"size": 76,
"type": "sprite_frames"
"type": "sprite_frame"
},
{
"path": "playerItem12/gUnk_0811B9A0.bin",
@ -57151,7 +57151,7 @@
"starts": {
"EU": 3093600
},
"size": 199564,
"size": 199561,
"type": "frame_obj_lists"
},
{
@ -57163,7 +57163,7 @@
"DEMO_JP"
],
"start": 3095924,
"size": 200048,
"size": 200045,
"type": "frame_obj_lists"
},
{

File diff suppressed because it is too large Load Diff

View File

@ -2,13 +2,20 @@
CXX = g++
CXXFLAGS = -O3 -Wall -Wextra -std=c++17
#CXXFLAGS += -g # debug
INCLUDES = -I include/
SRCS = src/main.cpp src/asset.cpp src/animation.cpp src/spriteframe.cpp src/reader.cpp src/exitlist.cpp src/frameobjlists.cpp src/midi.cpp src/aif.cpp src/gfx.cpp src/util.cpp src/tileset.cpp src/palette.cpp
SRCS = $(wildcard *.cpp)
HEADERS = $(wildcard *.h)
SRCS += $(wildcard assets/*.cpp)
HEADERS += $(wildcard assets/*.h)
INCLUDES = -I./
.PHONY: all clean
all: asset_processor
asset_processor: $(SRCS)
asset_processor: $(SRCS) $(HEADERS)
$(CXX) $(CXXFLAGS) $(INCLUDES) -o asset_processor $(SRCS) -lstdc++fs
clean:
rm asset_processor
$(RM) asset_processor asset_processor.exe

View File

@ -0,0 +1,27 @@
#include "aif.h"
#include "util.h"
std::filesystem::path AifAsset::generateAssetPath() {
std::filesystem::path path = this->path;
return path.replace_extension(".aif");
}
void AifAsset::convertToHumanReadable(const std::vector<char>& baserom) {
(void)baserom;
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
cmd.push_back(toolsPath / "aif2pcm" / "aif2pcm");
cmd.push_back(this->path);
cmd.push_back(this->assetPath);
check_call(cmd);
}
void AifAsset::buildToBinary() {
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
cmd.push_back(toolsPath / "aif2pcm" / "aif2pcm");
cmd.push_back(this->assetPath);
cmd.push_back(this->path);
check_call(cmd);
}

View File

@ -1,7 +1,11 @@
#include "asset.h"
class AifAsset : public BaseAsset {
public:
public:
using BaseAsset::BaseAsset;
virtual void convertToHumanReadable(const std::vector<char>& baserom);
virtual void buildToBinary();
private:
virtual std::filesystem::path generateAssetPath();
};

View File

@ -1,7 +1,7 @@
#include "animation.h"
#include "reader.h"
#include <iostream>
#include <fstream>
#include <iostream>
void AnimationAsset::convertToHumanReadable(const std::vector<char>& baserom) {
Reader reader(baserom, this->start, this->size);
@ -28,9 +28,9 @@ void AnimationAsset::convertToHumanReadable(const std::vector<char>& baserom) {
u8 keyframe_count = reader.read_u8();
lines.push_back(string_format("\t.byte %d @ keyframe count\n", keyframe_count));
}
std::ofstream out(this->path.replace_extension("s"));
std::ofstream out(this->assetPath);
for (const auto& line : lines) {
out << line;
}
out.close();
}
}

View File

@ -0,0 +1,7 @@
#include "macroasm.h"
class AnimationAsset : public BaseMacroAsmAsset {
public:
using BaseMacroAsmAsset::BaseMacroAsmAsset;
virtual void convertToHumanReadable(const std::vector<char>& baserom);
};

View File

@ -1,11 +1,11 @@
#include <fstream>
#include "asset.h"
#include <fstream>
void BaseAsset::extractBinary(const std::vector<char>& baserom) {
auto first = baserom.begin() + this->start;
auto last = baserom.begin() + this->start + this->size;
std::vector<char> data(first, last);
std::fstream file(this->binaryPath, std::ios::out | std::ios::binary);
std::fstream file(this->path, std::ios::out | std::ios::binary);
file.write(&data[0], data.size());
file.close();
}

View File

@ -0,0 +1,64 @@
#ifndef ASSET_H
#define ASSET_H
#include "util.h"
#include <filesystem>
#include <json.hpp>
#include <string>
#include <iostream>
class BaseAsset {
public:
BaseAsset(std::filesystem::path path, int start, int size, nlohmann::json asset)
: path(path), start(start), size(size), asset(asset) {
}
void setup() {
// Cannot call virtual functions in constructor, so another function call is necessary
assetPath = this->generateAssetPath();
buildPath = this->generateBuildPath();
}
// Extract the binary segment for this asset from the baserom and store it in a separate file.
virtual void extractBinary(const std::vector<char>& baserom);
// Convert the binary data for this asset to a human readable form.
virtual void convertToHumanReadable(const std::vector<char>& baserom) {
(void)baserom;
}
// Build the asset from the human readable form back to the binary.
virtual void buildToBinary() {
}
// Returns the path to the binary file extracted from the baserom.
std::filesystem::path getPath() const {
return path;
}
// Returns the path to the human readable asset file.
std::filesystem::path getAssetPath() const {
return assetPath;
}
// Returns the path to the resulting file after building.
std::filesystem::path getBuildPath() const {
return buildPath;
}
protected:
std::filesystem::path path;
std::filesystem::path assetPath;
std::filesystem::path buildPath;
int start;
int size;
nlohmann::json asset;
private:
virtual std::filesystem::path generateAssetPath() {
return this->path;
}
virtual std::filesystem::path generateBuildPath() {
return this->path;
}
};
#endif

View File

@ -1,7 +1,7 @@
#include "exitlist.h"
#include "reader.h"
#include <iostream>
#include <fstream>
#include <iostream>
void ExitListAsset::convertToHumanReadable(const std::vector<char>& baserom) {
Reader reader(baserom, this->start, this->size);
@ -40,7 +40,7 @@ void ExitListAsset::convertToHumanReadable(const std::vector<char>& baserom) {
lines.push_back("\n");
}
std::ofstream out(this->path.replace_extension("s"));
std::ofstream out(this->assetPath);
for (const auto& line : lines) {
out << line;
}

View File

@ -0,0 +1,7 @@
#include "macroasm.h"
class ExitListAsset : public BaseMacroAsmAsset {
public:
using BaseMacroAsmAsset::BaseMacroAsmAsset;
virtual void convertToHumanReadable(const std::vector<char>& baserom);
};

View File

@ -1,8 +1,8 @@
#include "frameobjlists.h"
#include "reader.h"
#include <iostream>
#include <fstream>
#include <algorithm>
#include <fstream>
#include <iostream>
void FrameObjListsAsset::convertToHumanReadable(const std::vector<char>& baserom) {
Reader reader(baserom, this->start, this->size);
@ -19,21 +19,7 @@ void FrameObjListsAsset::convertToHumanReadable(const std::vector<char>& baserom
break;
}
// std::cout << string_format("0x%x", reader.read_u8()) << std::endl;
// std::cout << string_format("0x%x", reader.read_u8()) << std::endl;
// std::cout << string_format("0x%x", reader.read_u8()) << std::endl;
// std::cout << string_format("0x%x", reader.read_u8()) << std::endl;
// reader.cursor -= 4;
u32 pointer = reader.read_u32();
// std::cout << pointer << std::endl;
// std::cout << string_format("0x%x", pointer) << std::endl;
// if (pointer > 0x10000 || pointer == 0xec0) {
// assert(false);
// }
first_level.push_back(pointer);
lines.push_back(string_format("\t.4byte 0x%x\n", pointer));
}
@ -86,10 +72,9 @@ void FrameObjListsAsset::convertToHumanReadable(const std::vector<char>& baserom
}
}
std::ofstream out(this->path.replace_extension("s"));
std::ofstream out(this->assetPath);
for (const auto& line : lines) {
out << line;
}
out.close();
// assert(false);
}

View File

@ -0,0 +1,7 @@
#include "macroasm.h"
class FrameObjListsAsset : public BaseMacroAsmAsset {
public:
using BaseMacroAsmAsset::BaseMacroAsmAsset;
virtual void convertToHumanReadable(const std::vector<char>& baserom);
};

View File

@ -1,23 +1,35 @@
#include "gfx.h"
#include "util.h"
void GfxAsset::convertToHumanReadable(const std::vector<char>& baserom) {
(void)baserom;
std::filesystem::path GfxAsset::generateAssetPath() {
std::filesystem::path pngPath = this->path;
if (pngPath.extension() == ".lz") {
pngPath.replace_extension("");
}
pngPath.replace_extension(".png");
return pngPath;
}
void GfxAsset::convertToHumanReadable(const std::vector<char>& baserom) {
(void)baserom;
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
cmd.push_back(toolsPath / "gbagfx" / "gbagfx");
cmd.push_back(this->path);
cmd.push_back(pngPath);
cmd.push_back(this->assetPath);
for (const auto& it : this->asset["options"].items()) {
cmd.push_back("-" + it.key());
cmd.push_back(to_string(it.value()));
}
check_call(cmd);
}
void GfxAsset::buildToBinary() {
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
cmd.push_back(toolsPath / "gbagfx" / "gbagfx");
cmd.push_back(this->assetPath);
cmd.push_back(this->path);
check_call(cmd);
}

View File

@ -1,7 +1,11 @@
#include "asset.h"
class GfxAsset : public BaseAsset {
public:
public:
using BaseAsset::BaseAsset;
virtual void convertToHumanReadable(const std::vector<char>& baserom);
virtual void buildToBinary();
private:
virtual std::filesystem::path generateAssetPath();
};

View File

@ -0,0 +1,20 @@
#include "macroasm.h"
#include <fstream>
std::filesystem::path BaseMacroAsmAsset::generateAssetPath() {
std::filesystem::path path = this->path;
return path.replace_extension(".s");
}
std::filesystem::path BaseMacroAsmAsset::generateBuildPath() {
std::filesystem::path path = this->path;
return path.replace_extension(".s");
}
void BaseMacroAsmAsset::extractBinary(const std::vector<char>& baserom) {
BaseAsset::extractBinary(baserom);
// Create dummy .s file that just incbins the .bin file.
std::ofstream out(this->assetPath);
out << "\t.incbin " << this->path << "\n";
out.close();
}

View File

@ -0,0 +1,17 @@
#ifndef MACROASM_H
#define MACROASM_H
#include "asset.h"
// Common class for all assets that are converted to asm files consisting of macros.
class BaseMacroAsmAsset : public BaseAsset {
using BaseAsset::BaseAsset;
public:
virtual void extractBinary(const std::vector<char>& baserom);
private:
virtual std::filesystem::path generateAssetPath();
virtual std::filesystem::path generateBuildPath();
};
#endif

View File

@ -1,16 +1,60 @@
#include "midi.h"
#include "main.h"
#include "reader.h"
#include "util.h"
#include <filesystem>
#include <iostream>
#include "midi.h"
#include "reader.h"
#include "main.h"
#include "util.h"
#include <fstream>
void MidiAsset::convertToHumanReadable(const std::vector<char>& baserom) {
(void)baserom;
std::filesystem::path MidiAsset::generateAssetPath() {
std::filesystem::path path = this->path;
return path.replace_extension(".mid");
}
// Convert the options
std::vector<std::string> commonParams;
std::vector<std::string> agb2midParams;
std::filesystem::path MidiAsset::generateBuildPath() {
std::filesystem::path path = this->path;
return path.replace_extension(".s");
}
void MidiAsset::extractBinary(const std::vector<char>& baserom) {
// Custom extraction as we need a label in the middle.
std::string label = this->path.stem();
std::filesystem::path tracksPath = this->path;
tracksPath.replace_filename(label + "_tracks.bin");
std::filesystem::path headerPath = this->path;
headerPath.replace_filename(label + "_header.bin");
int headerOffset = this->asset["options"]["headerOffset"];
// Extract tracks
{
auto first = baserom.begin() + this->start;
auto last = baserom.begin() + this->start + headerOffset;
std::vector<char> data(first, last);
std::fstream file(tracksPath, std::ios::out | std::ios::binary);
file.write(&data[0], data.size());
file.close();
}
// Extract header
{
auto first = baserom.begin() + this->start + headerOffset;
auto last = baserom.begin() + this->start + this->size;
std::vector<char> data(first, last);
std::fstream file(headerPath, std::ios::out | std::ios::binary);
file.write(&data[0], data.size());
file.close();
}
// Create dummy .s file.
std::ofstream out(this->buildPath);
out << "\t.incbin " << tracksPath << "\n";
out << label << "::\n";
out << "\t.incbin " << headerPath << "\n";
out.close();
}
void MidiAsset::parseOptions(std::vector<std::string>& commonParams, std::vector<std::string>& agb2midParams) {
bool exactGateTime = true;
for (const auto& it : this->asset["options"].items()) {
@ -52,6 +96,8 @@ void MidiAsset::convertToHumanReadable(const std::vector<char>& baserom) {
} else {
exactGateTime = false;
}
} else if (key == "headerOffset") {
// ignore here
} else {
commonParams.push_back("-" + key);
commonParams.push_back(to_string(it.value()));
@ -61,26 +107,48 @@ void MidiAsset::convertToHumanReadable(const std::vector<char>& baserom) {
if (exactGateTime) {
commonParams.push_back("-E");
}
}
void MidiAsset::convertToHumanReadable(const std::vector<char>& baserom) {
(void)baserom;
// Convert the options
std::vector<std::string> commonParams;
std::vector<std::string> agb2midParams;
this->parseOptions(commonParams, agb2midParams);
int headerOffset = this->asset["options"]["headerOffset"];
std::filesystem::path toolPath = "tools";
std::filesystem::path midPath = this->path;
midPath.replace_extension(".mid");
std::vector<std::string> cmd;
cmd.push_back(toolPath / "agb2mid" / "agb2mid");
cmd.push_back(gBaseromPath);
cmd.push_back(string_format("0x%x", this->start));
cmd.push_back(string_format("0x%x", this->start + headerOffset));
cmd.push_back(gBaseromPath); // TODO deduplicate?
cmd.push_back(midPath);
cmd.push_back(this->assetPath);
cmd.insert(cmd.end(), commonParams.begin(), commonParams.end());
cmd.insert(cmd.end(), agb2midParams.begin(), agb2midParams.end());
check_call(cmd);
// We also need to build the mid to an s file here, so we get shiftability after converting.
cmd.clear();
cmd.push_back(toolPath / "mid2agb" / "mid2agb");
cmd.push_back(midPath);
cmd.push_back(this->path);
cmd.push_back(this->assetPath);
cmd.push_back(this->buildPath);
cmd.insert(cmd.end(), commonParams.begin(), commonParams.end());
check_call(cmd);
}
void MidiAsset::buildToBinary() {
// Convert the options
std::vector<std::string> commonParams;
std::vector<std::string> agb2midParams;
this->parseOptions(commonParams, agb2midParams);
std::filesystem::path toolPath = "tools";
std::vector<std::string> cmd;
cmd.push_back(toolPath / "mid2agb" / "mid2agb");
cmd.push_back(this->assetPath);
cmd.push_back(this->buildPath);
cmd.insert(cmd.end(), commonParams.begin(), commonParams.end());
check_call(cmd);
}

View File

@ -0,0 +1,14 @@
#include "asset.h"
class MidiAsset : public BaseAsset {
public:
using BaseAsset::BaseAsset;
virtual void extractBinary(const std::vector<char>& baserom);
virtual void convertToHumanReadable(const std::vector<char>& baserom);
virtual void buildToBinary();
private:
void parseOptions(std::vector<std::string>& commonParams, std::vector<std::string>& agb2midParams);
virtual std::filesystem::path generateAssetPath();
virtual std::filesystem::path generateBuildPath();
};

View File

@ -0,0 +1,27 @@
#include "palette.h"
#include "util.h"
std::filesystem::path PaletteAsset::generateAssetPath() {
std::filesystem::path path = this->path;
return path.replace_extension(".pal");
}
void PaletteAsset::convertToHumanReadable(const std::vector<char>& baserom) {
(void)baserom;
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
cmd.push_back(toolsPath / "gbagfx" / "gbagfx");
cmd.push_back(this->path);
cmd.push_back(this->assetPath);
check_call(cmd);
}
void PaletteAsset::buildToBinary() {
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
cmd.push_back(toolsPath / "gbagfx" / "gbagfx");
cmd.push_back(this->assetPath);
cmd.push_back(this->path);
check_call(cmd);
}

View File

@ -1,7 +1,11 @@
#include "asset.h"
class PaletteAsset : public BaseAsset {
public:
public:
using BaseAsset::BaseAsset;
virtual void convertToHumanReadable(const std::vector<char>& baserom);
virtual void buildToBinary();
private:
virtual std::filesystem::path generateAssetPath();
};

View File

@ -1,7 +1,7 @@
#include "spriteframe.h"
#include "reader.h"
#include <iostream>
#include <fstream>
#include <iostream>
void SpriteFrameAsset::convertToHumanReadable(const std::vector<char>& baserom) {
Reader reader(baserom, this->start, this->size);
@ -17,7 +17,7 @@ void SpriteFrameAsset::convertToHumanReadable(const std::vector<char>& baserom)
lines.push_back("\n");
}
std::ofstream out(this->path.replace_extension("s"));
std::ofstream out(this->assetPath);
for (const auto& line : lines) {
out << line;
}

View File

@ -0,0 +1,7 @@
#include "macroasm.h"
class SpriteFrameAsset : public BaseMacroAsmAsset {
public:
using BaseMacroAsmAsset::BaseMacroAsmAsset;
virtual void convertToHumanReadable(const std::vector<char>& baserom);
};

View File

@ -1,21 +1,33 @@
#include "tileset.h"
#include "util.h"
void TilesetAsset::convertToHumanReadable(const std::vector<char>& baserom) {
(void)baserom;
std::filesystem::path TilesetAsset::generateAssetPath() {
std::filesystem::path pngPath = this->path;
if (pngPath.extension() == ".lz") {
pngPath.replace_extension("");
}
pngPath.replace_extension(".png");
return pngPath;
}
void TilesetAsset::convertToHumanReadable(const std::vector<char>& baserom) {
(void)baserom;
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
cmd.push_back(toolsPath / "gbagfx" / "gbagfx");
cmd.push_back(this->path);
cmd.push_back(pngPath);
cmd.push_back(this->assetPath);
cmd.push_back("-mwidth");
cmd.push_back("32");
check_call(cmd);
}
void TilesetAsset::buildToBinary() {
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
cmd.push_back(toolsPath / "gbagfx" / "gbagfx");
cmd.push_back(this->assetPath);
cmd.push_back(this->path);
check_call(cmd);
}

View File

@ -4,4 +4,8 @@ class TilesetAsset : public BaseAsset {
public:
using BaseAsset::BaseAsset;
virtual void convertToHumanReadable(const std::vector<char>& baserom);
virtual void buildToBinary();
private:
virtual std::filesystem::path generateAssetPath();
};

View File

@ -1,7 +0,0 @@
#include "asset.h"
class AnimationAsset : public BaseAsset {
public:
using BaseAsset::BaseAsset;
virtual void convertToHumanReadable(const std::vector<char>& baserom);
};

View File

@ -1,34 +0,0 @@
#ifndef ASSET_H
#define ASSET_H
#include <assert.h>
#include <string>
#include <filesystem>
#include <json.hpp>
#include "util.h"
class BaseAsset {
public:
BaseAsset(std::filesystem::path path, int start, int size, nlohmann::json asset)
: path(path), start(start), size(size), asset(asset) {
binaryPath = path;//.replace_extension("bin");
}
virtual void extractBinary(const std::vector<char>& baserom);
virtual void convertToHumanReadable(const std::vector<char>& baserom) {
(void)baserom;
assert("not implemented");
}
virtual void convertToBinary() {
assert("not implemented");
}
protected:
std::filesystem::path path;
std::filesystem::path binaryPath;
int start;
int size;
nlohmann::json asset;
};
#endif

View File

@ -1,7 +0,0 @@
#include "asset.h"
class ExitListAsset : public BaseAsset {
public:
using BaseAsset::BaseAsset;
virtual void convertToHumanReadable(const std::vector<char>& baserom);
};

View File

@ -1,7 +0,0 @@
#include "asset.h"
class FrameObjListsAsset : public BaseAsset {
public:
using BaseAsset::BaseAsset;
virtual void convertToHumanReadable(const std::vector<char>& baserom);
};

View File

@ -1,21 +0,0 @@
#ifndef MAIN_H
#define MAIN_H
#include "util.h"
bool shouldExtractFile(const std::filesystem::path& path, const std::filesystem::file_time_type& configModified);
void extractFile(const std::filesystem::path& path, const nlohmann::json& asset, const int& start, const std::vector<char>& baserom);
enum Mode {
EXTRACT,
CONVERT,
BUILD
};
// Arguments
extern bool gVerbose;
extern Mode gMode;
extern std::string gVariant;
extern std::string gAssetsFolder;
extern std::string gBaseromPath;
#endif

View File

@ -1,7 +0,0 @@
#include "asset.h"
class MidiAsset : public BaseAsset {
public:
using BaseAsset::BaseAsset;
virtual void convertToHumanReadable(const std::vector<char>& baserom);
};

View File

@ -1,7 +0,0 @@
#include "asset.h"
class SpriteFrameAsset : public BaseAsset {
public:
using BaseAsset::BaseAsset;
virtual void convertToHumanReadable(const std::vector<char>& baserom);
};

View File

@ -1,23 +0,0 @@
#ifndef UTIL_H
#define UTIL_H
#include <stdint.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <json.hpp>
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
void check_call(const std::vector<std::string>& cmd);
std::string to_string(const nlohmann::json& j);
#endif

View File

@ -1,17 +1,17 @@
#include <iostream>
#include <fstream>
#include <filesystem>
#include <json.hpp>
#include "main.h"
#include "tileset.h"
#include "animation.h"
#include "spriteframe.h"
#include "exitlist.h"
#include "frameobjlists.h"
#include "midi.h"
#include "aif.h"
#include "gfx.h"
#include "palette.h"
#include "assets/aif.h"
#include "assets/animation.h"
#include "assets/exitlist.h"
#include "assets/frameobjlists.h"
#include "assets/gfx.h"
#include "assets/midi.h"
#include "assets/palette.h"
#include "assets/spriteframe.h"
#include "assets/tileset.h"
#include <filesystem>
#include <fstream>
#include <iostream>
#include <json.hpp>
using nlohmann::json;
@ -20,24 +20,23 @@ using nlohmann::json;
void usage() {
std::cout << "Usage: asset_processor [options] MODE VARIANT BUILD_PATH\n"
<< "\n"
<< "MODE Mode to execute\n"
<< "VARIANT Variant to build. One of USA, JP, EU, DEMO_USA, DEMO_JP\n"
<< "BUILD_PATH Path to the build folder\n"
<< "\n"
<< "Modes:\n"
<< "extract Extract binary data from baserom\n"
<< "convert TODO Convert data to human readable format\n"
<< "build TODO Build binary from assets\n"
<< "\n"
<< "Options:\n"
<< "-v Print verbose output\n"
<< "-h Show this help\n"
<< "-f Force extraction of all assets (even if unmodified)\n";
<< "\n"
<< "MODE Mode to execute\n"
<< "VARIANT Variant to build. One of USA, JP, EU, DEMO_USA, DEMO_JP\n"
<< "BUILD_PATH Path to the build folder\n"
<< "\n"
<< "Modes:\n"
<< "extract Extract binary data from baserom\n"
<< "convert Convert data to human readable format\n"
<< "build Build binary data from assets\n"
<< "\n"
<< "Options:\n"
<< "-v Print verbose output\n"
<< "-h Show this help\n"
<< "-f Force extraction of all assets (even if unmodified)\n";
std::exit(1);
}
bool gVerbose = false;
bool gForceExtraction = false;
Mode gMode;
@ -45,18 +44,15 @@ std::string gVariant;
std::string gAssetsFolder;
std::string gBaseromPath;
static std::map<std::string, std::string> baseroms = {
{"USA", "baserom.gba"},
{"EU", "baserom_eu.gba"},
{"JP", "baserom_jp.gba"},
{"DEMO_USA", "baserom_demo.gba"},
{"DEMO_JP", "baserom_demo_jp.gba"}
};
static std::map<std::string, std::string> baseroms = { { "USA", "baserom.gba" },
{ "EU", "baserom_eu.gba" },
{ "JP", "baserom_jp.gba" },
{ "DEMO_USA", "baserom_demo.gba" },
{ "DEMO_JP", "baserom_demo_jp.gba" } };
int main(int argc, char** argv) {
// Parse options.
int argCount = argc - 1; // Skip program name
char** args = &argv[1];
@ -65,11 +61,11 @@ int main(int argc, char** argv) {
gVerbose = true;
argCount--;
args++;
} else if(strcmp(args[0], "-h") == 0) {
} else if (strcmp(args[0], "-h") == 0) {
argCount--;
args++;
usage();
} else if(strcmp(args[0], "-f") == 0) {
} else if (strcmp(args[0], "-f") == 0) {
gForceExtraction = true;
argCount--;
args++;
@ -80,7 +76,7 @@ int main(int argc, char** argv) {
}
if (argCount != 3) {
std::cerr << "Not enough arguments: " << argCount << std::endl;
std::cerr << "Not enough arguments. expected: 3, actual: " << argCount << std::endl;
usage();
}
@ -88,34 +84,34 @@ int main(int argc, char** argv) {
gMode = EXTRACT;
} else if (strcmp(args[0], "convert") == 0) {
gMode = CONVERT;
std::cerr << "Mode `convert` not yet implemented." << std::endl;
std::exit(1);
} else if (strcmp(args[0], "build") == 0) {
gMode = BUILD;
std::cerr << "Mode `build` not yet implemented." << std::endl;
std::exit(1);
} else {
std::cerr << "Unsupported mode `" << args[0] << "`" << std::endl;
std::exit(1);
}
gVariant = args[1]; // TODO check valid variant
gVariant = args[1];
if (gVariant != "USA" && gVariant != "EU" && gVariant != "JP" && gVariant != "DEMO_USA" && gVariant != "DEMO_JP") {
std::cerr << "Unsupported variant `" << gVariant << "`" << std::endl;
std::exit(1);
}
gAssetsFolder = args[2];
gBaseromPath = baseroms[gVariant];
// Read baserom.
std::ifstream file(gBaseromPath, std::ios::binary | std::ios::ate);
std::streamsize size = file.tellg();
file.seekg(0, std::ios::beg);
std::vector<char> baserom(size);
if (!file.read(baserom.data(), size)) {
assert(false); // Could not read baserom
std::cerr << "Could not read baserom " << gBaseromPath << std::endl;
std::exit(1);
}
file.close();
// Gather all json configs from assets folder.
std::vector<std::filesystem::path> configs;
std::string configFolder = "assets";
for (const auto& entry : std::filesystem::directory_iterator(configFolder)) {
@ -152,25 +148,41 @@ int main(int argc, char** argv) {
}
}
std::filesystem::path path = gAssetsFolder;
path = path / asset["path"];
// std::cout << path << std::endl;
if (shouldExtractFile(path, configModified)) {
if (gVerbose) {
std::cout << "Extracting " << path << "..." << std::endl;
}
switch (gMode) {
case EXTRACT: {
if (shouldExtractAsset(path, configModified)) {
if (gVerbose) {
std::cout << "Extracting " << path << "..." << std::endl;
}
int start = 0;
if (asset.contains("start")) {
// Apply offset to the start of the USA variant
start = asset["start"].get<int>() + currentOffset;
} else if (asset.contains("starts")) {
// Use start for the current variant
start = asset["starts"][gVariant];
std::unique_ptr<BaseAsset> assetHandler = getAssetHandlerByType(path, asset, currentOffset);
extractAsset(assetHandler, baserom);
}
break;
}
case CONVERT: {
std::unique_ptr<BaseAsset> assetHandler = getAssetHandlerByType(path, asset, currentOffset);
if (shouldConvertAsset(assetHandler)) {
if (gVerbose) {
std::cout << "Converting " << assetHandler->getAssetPath() << "..." << std::endl;
}
convertAsset(assetHandler, baserom);
}
break;
}
case BUILD: {
std::unique_ptr<BaseAsset> assetHandler = getAssetHandlerByType(path, asset, currentOffset);
if (shouldBuildAsset(assetHandler)) {
if (gVerbose) {
std::cout << "Building " << assetHandler->getAssetPath() << "..." << std::endl;
}
buildAsset(assetHandler);
}
break;
}
extractFile(path, asset, start, baserom);
}
}
}
@ -181,7 +193,65 @@ int main(int argc, char** argv) {
}
}
bool shouldExtractFile(const std::filesystem::path& path, const std::filesystem::file_time_type& configModified) {
std::unique_ptr<BaseAsset> getAssetHandlerByType(const std::filesystem::path& path, const json& asset,
const int& currentOffset) {
int start = 0;
if (asset.contains("start")) {
// Apply offset to the start of the USA variant
start = asset["start"].get<int>() + currentOffset;
} else if (asset.contains("starts")) {
// Use start for the current variant
start = asset["starts"][gVariant];
}
std::string type = "";
if (asset.contains("type")) {
type = asset["type"];
}
int size = 0;
if (asset.contains("size")) { // The asset has a size and want to be extracted first.
size = asset["size"]; // TODO can different sizes for the different variants ever occur?
}
std::unique_ptr<BaseAsset> assetHandler;
if (type == "tileset") {
assetHandler = std::make_unique<TilesetAsset>(path, start, size, asset);
} else if (type == "animation") {
assetHandler = std::make_unique<AnimationAsset>(path, start, size, asset);
} else if (type == "sprite_frame") {
assetHandler = std::make_unique<SpriteFrameAsset>(path, start, size, asset);
} else if (type == "exit_list") {
assetHandler = std::make_unique<ExitListAsset>(path, start, size, asset);
} else if (type == "frame_obj_lists") {
assetHandler = std::make_unique<FrameObjListsAsset>(path, start, size, asset);
} else if (type == "midi") {
assetHandler = std::make_unique<MidiAsset>(path, start, size, asset);
} else if (type == "aif") {
assetHandler = std::make_unique<AifAsset>(path, start, size, asset);
} else if (type == "gfx") {
assetHandler = std::make_unique<GfxAsset>(path, start, size, asset);
} else if (type == "palette") {
assetHandler = std::make_unique<PaletteAsset>(path, start, size, asset);
} else if (type == "map_gfx" || type == "map_layer1" || type == "map_layer2" || type == "metatiles_tile_types1" ||
type == "metatiles_tile_types2" || type == "metatiles_tileset1" || type == "metatiles_tileset2" ||
type == "map_mapping1" || type == "map_mapping2" || type == "tileset_mapping3" ||
type == "map_collision" || type == "unknown") {
// TODO implement conversions
assetHandler = std::make_unique<BaseAsset>(path, start, size, asset);
} else if (type == "") {
// Unknown binary asset
assetHandler = std::make_unique<BaseAsset>(path, start, size, asset);
} else {
std::cerr << "Unimplemented asset type `" << type << "`" << std::endl;
std::exit(1);
}
assetHandler->setup();
return assetHandler;
}
bool shouldExtractAsset(const std::filesystem::path& path, const std::filesystem::file_time_type& configModified) {
if (gForceExtraction) {
return true;
}
@ -199,55 +269,29 @@ bool shouldExtractFile(const std::filesystem::path& path, const std::filesystem:
}
}
void extractFile(const std::filesystem::path& path, const json& asset, const int& start, const std::vector<char>& baserom) {
std::string type = "";
// std::cout << asset << std::endl;
if (asset.contains("type")) {
type = asset["type"];
}
void extractAsset(std::unique_ptr<BaseAsset>& assetHandler, const std::vector<char>& baserom) {
// Create the parent directory
std::filesystem::path parentDir = std::filesystem::path(path);
std::filesystem::path parentDir = std::filesystem::path(assetHandler->getPath());
parentDir.remove_filename();
std::filesystem::create_directories(parentDir);
int size = 0;
if (asset.contains("size")) { // The asset has a size and want to be extracted first.
size = asset["size"]; // TODO can different sizes for the different variants ever occur?
} // If an asset has no size, the extraction tool reads the baserom iself.
std::unique_ptr<BaseAsset> assetHandler;
if (type == "tileset") {
assetHandler = std::make_unique<TilesetAsset>(path, start, size, asset);
} else if (type == "animation") {
assetHandler = std::make_unique<AnimationAsset>(path, start, size, asset);
} else if (type == "sprite_frames") { // TODO rename to sprite_frame?
assetHandler = std::make_unique<SpriteFrameAsset>(path, start, size, asset);
} else if (type == "exit_list") {
assetHandler = std::make_unique<ExitListAsset>(path, start, size, asset);
} else if (type == "frame_obj_lists") {
assetHandler = std::make_unique<FrameObjListsAsset>(path, start, size, asset);
} else if (type == "midi") {
assetHandler = std::make_unique<MidiAsset>(path, start, size, asset);
} else if (type == "aif") {
assetHandler = std::make_unique<AifAsset>(path, start, size, asset);
} else if (type == "gfx") {
assetHandler = std::make_unique<GfxAsset>(path, start, size, asset);
} else if (type == "palette") {
assetHandler = std::make_unique<PaletteAsset>(path, start, size, asset);
} else if ( type == "map_gfx" || type == "map_layer1" || type == "map_layer2" || type == "metatiles_tile_types1" ||
type == "metatiles_tile_types2" || type == "metatiles_tileset1" || type == "metatiles_tileset2" ||
type == "map_mapping1" || type == "map_mapping2" || type == "tileset_mapping3" ||
type == "map_collision" || type == "unknown") {
assetHandler = std::make_unique<BaseAsset>(path, start, size, asset);
// TODO implement conversions
} else if (type == "") {
assetHandler = std::make_unique<BaseAsset>(path, start, size, asset);
} else {
std::cerr << "Unimplemented type " << type << std::endl;
std::exit(1);
}
assetHandler->extractBinary(baserom);
}
bool shouldConvertAsset(const std::unique_ptr<BaseAsset>& assetHandler) {
(void)assetHandler;
return true; // TODO
}
void convertAsset(std::unique_ptr<BaseAsset>& assetHandler, const std::vector<char>& baserom) {
assetHandler->convertToHumanReadable(baserom);
}
bool shouldBuildAsset(const std::unique_ptr<BaseAsset>& assetHandler) {
(void)assetHandler;
return true; // TODO
}
void buildAsset(std::unique_ptr<BaseAsset>& assetHandler) {
assetHandler->buildToBinary();
}

View File

@ -0,0 +1,24 @@
#ifndef MAIN_H
#define MAIN_H
#include "util.h"
#include "assets/asset.h"
std::unique_ptr<BaseAsset> getAssetHandlerByType(const std::filesystem::path& path, const nlohmann::json& asset,
const int& currentOffset);
bool shouldExtractAsset(const std::filesystem::path& path, const std::filesystem::file_time_type& configModified);
void extractAsset(std::unique_ptr<BaseAsset>& assetHandler, const std::vector<char>& baserom);
bool shouldConvertAsset(const std::unique_ptr<BaseAsset>& assetHandler);
void convertAsset(std::unique_ptr<BaseAsset>& assetHandler, const std::vector<char>& baserom);
bool shouldBuildAsset(const std::unique_ptr<BaseAsset>& assetHandler);
void buildAsset(std::unique_ptr<BaseAsset>& assetHandler);
enum Mode { EXTRACT, CONVERT, BUILD };
// Arguments
extern bool gVerbose;
extern Mode gMode;
extern std::string gVariant;
extern std::string gAssetsFolder;
extern std::string gBaseromPath;
#endif

View File

@ -1,4 +1,6 @@
#include "reader.h"
#include "util.h"
#include <string>
std::string opt_param(const std::string& format, int defaultVal, int value) {
if (value != defaultVal) {

View File

@ -2,6 +2,7 @@
#define READER_H
#include <stdint.h>
#include <vector>
typedef uint8_t u8;
typedef uint16_t u16;
@ -12,8 +13,6 @@ typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
#include <vector>
class Reader {
public:
Reader(const std::vector<char>& baserom, int start, int size) {
@ -48,22 +47,4 @@ class Reader {
std::vector<char> data;
};
// TODO move to utils?
#include <memory>
#include <string>
#include <stdexcept>
template <typename... Args> std::string string_format(const std::string& format, Args... args) {
int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0'
if (size_s <= 0) {
throw std::runtime_error("Error during formatting.");
}
auto size = static_cast<size_t>(size_s);
auto buf = std::make_unique<char[]>(size);
std::snprintf(buf.get(), size, format.c_str(), args...);
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
}
std::string opt_param(const std::string& format, int defaultVal, int value);
#endif

View File

@ -1,15 +0,0 @@
#include "aif.h"
#include "util.h"
void AifAsset::convertToHumanReadable(const std::vector<char>& baserom) {
(void)baserom;
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
cmd.push_back(toolsPath / "aif2pcm" / "aif2pcm");
cmd.push_back(this->path);
std::filesystem::path aifPath = this->path;
aifPath.replace_extension(".aif");
cmd.push_back(aifPath);
check_call(cmd);
}

View File

@ -1,16 +0,0 @@
#include "palette.h"
#include "util.h"
void PaletteAsset::convertToHumanReadable(const std::vector<char>& baserom) {
(void)baserom;
std::filesystem::path palPath = this->path;
palPath.replace_extension(".pal");
std::filesystem::path toolsPath = "tools";
std::vector<std::string> cmd;
cmd.push_back(toolsPath / "gbagfx" / "gbagfx");
cmd.push_back(this->path);
cmd.push_back(palPath);
check_call(cmd);
}

View File

@ -1,5 +1,4 @@
#include "util.h"
#include <cassert>
#include <iostream>
void check_call(const std::vector<std::string>& cmd) {
@ -13,8 +12,6 @@ void check_call(const std::vector<std::string>& cmd) {
}
cmdstr += segment;
}
// std::cout << cmdstr << std::endl;
// assert(false);
int code = system(cmdstr.c_str());
if (code != 0) {
std::cerr << cmdstr << " failed with return code " << code << std::endl;

View File

@ -0,0 +1,38 @@
#ifndef UTIL_H
#define UTIL_H
#include <json.hpp>
#include <memory>
#include <stdexcept>
#include <stdint.h>
#include <stdlib.h>
#include <string>
#include <vector>
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
void check_call(const std::vector<std::string>& cmd);
std::string to_string(const nlohmann::json& j);
template <typename... Args> std::string string_format(const std::string& format, Args... args) {
int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0'
if (size_s <= 0) {
throw std::runtime_error("Error during formatting.");
}
auto size = static_cast<size_t>(size_s);
auto buf = std::make_unique<char[]>(size);
std::snprintf(buf.get(), size, format.c_str(), args...);
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
}
std::string opt_param(const std::string& format, int defaultVal, int value);
#endif

View File

@ -24,7 +24,6 @@
#include "asm_file.h"
#include "c_file.h"
#include "charmap.h"
#include <algorithm>
Charmap* g_charmap;
std::string g_buildName;