shithub: pokecrystal

Download patch

ref: 71073a5f3bcbf4f2725e16bdce147c070c8b833e
parent: e791c5392b19f589c51afd98666d19e778278847
author: Rangi <[email protected]>
date: Tue Mar 9 15:43:24 EST 2021

Verify RAM table lengths

--- a/constants/map_object_constants.asm
+++ b/constants/map_object_constants.asm
@@ -112,6 +112,8 @@
 MAPOBJECT_EVENT_FLAG       rw ; c
                            rb_skip 2
 MAPOBJECT_LENGTH EQU _RS
+NUM_OBJECTS EQU 16
+PLAYER_OBJECT EQU 0
 
 ; SpriteMovementData struct members (see data/sprites/map_objects.asm)
 rsreset
--- a/constants/wram_constants.asm
+++ b/constants/wram_constants.asm
@@ -184,10 +184,6 @@
 	const FRIDAY    ; 5
 	const SATURDAY  ; 6
 
-; wMapObjects::
-PLAYER_OBJECT EQU 0
-NUM_OBJECTS   EQU 16
-
 ; wStatusFlags::
 	const_def
 	const STATUSFLAGS_POKEDEX_F                  ; 0
--- a/sram.asm
+++ b/sram.asm
@@ -6,6 +6,7 @@
 SECTION "SRAM Bank 0", SRAM
 
 sPartyMail::
+	table_width MAIL_STRUCT_LENGTH, sPartyMail
 sPartyMon1Mail:: mailmsg sPartyMon1Mail
 sPartyMon2Mail:: mailmsg sPartyMon2Mail
 sPartyMon3Mail:: mailmsg sPartyMon3Mail
@@ -12,8 +13,10 @@
 sPartyMon4Mail:: mailmsg sPartyMon4Mail
 sPartyMon5Mail:: mailmsg sPartyMon5Mail
 sPartyMon6Mail:: mailmsg sPartyMon6Mail
+	assert_table_length PARTY_LENGTH
 
 sPartyMailBackup::
+	table_width MAIL_STRUCT_LENGTH, sPartyMailBackup
 sPartyMon1MailBackup:: mailmsg sPartyMon1MailBackup
 sPartyMon2MailBackup:: mailmsg sPartyMon2MailBackup
 sPartyMon3MailBackup:: mailmsg sPartyMon3MailBackup
@@ -20,9 +23,11 @@
 sPartyMon4MailBackup:: mailmsg sPartyMon4MailBackup
 sPartyMon5MailBackup:: mailmsg sPartyMon5MailBackup
 sPartyMon6MailBackup:: mailmsg sPartyMon6MailBackup
+	assert_table_length PARTY_LENGTH
 
 sMailboxCount:: db
 sMailboxes::
+	table_width MAIL_STRUCT_LENGTH, sMailboxes
 sMailbox1::  mailmsg sMailbox1
 sMailbox2::  mailmsg sMailbox2
 sMailbox3::  mailmsg sMailbox3
@@ -33,9 +38,11 @@
 sMailbox8::  mailmsg sMailbox8
 sMailbox9::  mailmsg sMailbox9
 sMailbox10:: mailmsg sMailbox10
+	assert_table_length MAILBOX_CAPACITY
 
 sMailboxCountBackup:: db
 sMailboxesBackup::
+	table_width MAIL_STRUCT_LENGTH, sMailboxesBackup
 sMailbox1Backup::  mailmsg sMailbox1Backup
 sMailbox2Backup::  mailmsg sMailbox2Backup
 sMailbox3Backup::  mailmsg sMailbox3Backup
@@ -46,6 +53,7 @@
 sMailbox8Backup::  mailmsg sMailbox8Backup
 sMailbox9Backup::  mailmsg sMailbox9Backup
 sMailbox10Backup:: mailmsg sMailbox10Backup
+	assert_table_length MAILBOX_CAPACITY
 
 sMysteryGiftData::
 sMysteryGiftItem:: db
@@ -145,6 +153,7 @@
 SECTION "SRAM Hall of Fame", SRAM
 
 sHallOfFame::
+	table_width HOF_LENGTH, sHallOfFame
 sHallOfFame01:: hall_of_fame sHallOfFame01
 sHallOfFame02:: hall_of_fame sHallOfFame02
 sHallOfFame03:: hall_of_fame sHallOfFame03
@@ -175,6 +184,7 @@
 sHallOfFame28:: hall_of_fame sHallOfFame28
 sHallOfFame29:: hall_of_fame sHallOfFame29
 sHallOfFame30:: hall_of_fame sHallOfFame30
+	assert_table_length NUM_HOF_TEAMS
 sHallOfFameEnd::
 
 
--- a/wram.asm
+++ b/wram.asm
@@ -20,16 +20,17 @@
 wMusicPlaying:: db
 
 wAudio::
-
+	table_width CHANNEL_STRUCT_LENGTH, wAudio
 wChannel1:: channel_struct wChannel1
 wChannel2:: channel_struct wChannel2
 wChannel3:: channel_struct wChannel3
 wChannel4:: channel_struct wChannel4
-
+	assert_table_length NUM_MUSIC_CHANS
 wChannel5:: channel_struct wChannel5
 wChannel6:: channel_struct wChannel6
 wChannel7:: channel_struct wChannel7
 wChannel8:: channel_struct wChannel8
+	assert_table_length NUM_CHANNELS
 
 	ds 1
 
@@ -224,6 +225,7 @@
 	ds NUM_SPRITEANIMDICT_ENTRIES * 2
 
 wSpriteAnimationStructs::
+	table_width SPRITEANIMSTRUCT_LENGTH, wSpriteAnimationStructs
 ; field  0:   index
 ; fields 1-3: loaded from SpriteAnimSeqData
 wSpriteAnim1::  sprite_anim_struct wSpriteAnim1
@@ -236,6 +238,7 @@
 wSpriteAnim8::  sprite_anim_struct wSpriteAnim8
 wSpriteAnim9::  sprite_anim_struct wSpriteAnim9
 wSpriteAnim10:: sprite_anim_struct wSpriteAnim10
+	assert_table_length NUM_SPRITE_ANIM_STRUCTS
 wSpriteAnimationStructsEnd::
 
 NEXTU
@@ -322,6 +325,7 @@
 SECTION "Sprites", WRAM0
 
 wVirtualOAM::
+	table_width SPRITEOAMSTRUCT_LENGTH, wVirtualOAM
 wVirtualOAMSprite00:: sprite_oam_struct wVirtualOAMSprite00
 wVirtualOAMSprite01:: sprite_oam_struct wVirtualOAMSprite01
 wVirtualOAMSprite02:: sprite_oam_struct wVirtualOAMSprite02
@@ -362,6 +366,7 @@
 wVirtualOAMSprite37:: sprite_oam_struct wVirtualOAMSprite37
 wVirtualOAMSprite38:: sprite_oam_struct wVirtualOAMSprite38
 wVirtualOAMSprite39:: sprite_oam_struct wVirtualOAMSprite39
+	assert_table_length NUM_SPRITE_OAM_STRUCTS
 wVirtualOAMEnd::
 
 
@@ -981,6 +986,7 @@
 UNION
 ; link player data
 wLinkPlayerData::
+	table_width PARTYMON_STRUCT_LENGTH, wLinkPlayerData
 wLinkPlayerPartyMon1:: party_struct wLinkPlayerPartyMon1
 wLinkPlayerPartyMon2:: party_struct wLinkPlayerPartyMon2
 wLinkPlayerPartyMon3:: party_struct wLinkPlayerPartyMon3
@@ -987,6 +993,7 @@
 wLinkPlayerPartyMon4:: party_struct wLinkPlayerPartyMon4
 wLinkPlayerPartyMon5:: party_struct wLinkPlayerPartyMon5
 wLinkPlayerPartyMon6:: party_struct wLinkPlayerPartyMon6
+	assert_table_length PARTY_LENGTH
 wLinkPlayerPartyMonOTNames:: ds NAME_LENGTH * PARTY_LENGTH
 wLinkPlayerPartyMonNicks:: ds MON_NAME_LENGTH * PARTY_LENGTH
 
@@ -993,6 +1000,7 @@
 NEXTU
 ; time capsule party data
 wTimeCapsulePlayerData::
+	table_width REDMON_STRUCT_LENGTH, wTimeCapsulePlayerData
 wTimeCapsulePartyMon1:: red_party_struct wTimeCapsulePartyMon1
 wTimeCapsulePartyMon2:: red_party_struct wTimeCapsulePartyMon2
 wTimeCapsulePartyMon3:: red_party_struct wTimeCapsulePartyMon3
@@ -999,6 +1007,7 @@
 wTimeCapsulePartyMon4:: red_party_struct wTimeCapsulePartyMon4
 wTimeCapsulePartyMon5:: red_party_struct wTimeCapsulePartyMon5
 wTimeCapsulePartyMon6:: red_party_struct wTimeCapsulePartyMon6
+	assert_table_length PARTY_LENGTH
 wTimeCapsulePartyMonOTNames:: ds NAME_LENGTH * PARTY_LENGTH
 wTimeCapsulePartyMonNicks:: ds MON_NAME_LENGTH * PARTY_LENGTH
 
@@ -2558,6 +2567,7 @@
 UNION
 ; ot party mons
 wOTPartyMons::
+	table_width PARTYMON_STRUCT_LENGTH, wOTPartyMons
 wOTPartyMon1:: party_struct wOTPartyMon1
 wOTPartyMon2:: party_struct wOTPartyMon2
 wOTPartyMon3:: party_struct wOTPartyMon3
@@ -2564,6 +2574,7 @@
 wOTPartyMon4:: party_struct wOTPartyMon4
 wOTPartyMon5:: party_struct wOTPartyMon5
 wOTPartyMon6:: party_struct wOTPartyMon6
+	assert_table_length PARTY_LENGTH
 wOTPartyMonsEnd::
 
 wOTPartyMonOT:: ds NAME_LENGTH * PARTY_LENGTH
@@ -2719,6 +2730,7 @@
 wFollowMovementQueue:: ds 5
 
 wObjectStructs::
+	table_width OBJECT_LENGTH, wObjectStructs
 wPlayerStruct::   object_struct wPlayer
 wObject1Struct::  object_struct wObject1
 wObject2Struct::  object_struct wObject2
@@ -2732,6 +2744,7 @@
 wObject10Struct:: object_struct wObject10
 wObject11Struct:: object_struct wObject11
 wObject12Struct:: object_struct wObject12
+	assert_table_length NUM_OBJECT_STRUCTS
 
 wCmdQueue:: ds CMDQUEUE_CAPACITY * CMDQUEUE_ENTRY_SIZE
 
@@ -2738,6 +2751,7 @@
 	ds 40
 
 wMapObjects::
+	table_width MAPOBJECT_LENGTH, wMapObjects
 wPlayerObject:: map_object wPlayer
 wMap1Object::   map_object wMap1
 wMap2Object::   map_object wMap2
@@ -2754,6 +2768,7 @@
 wMap13Object::  map_object wMap13
 wMap14Object::  map_object wMap14
 wMap15Object::  map_object wMap15
+	assert_table_length NUM_OBJECTS
 
 wObjectMasks:: ds NUM_OBJECTS
 
@@ -3117,6 +3132,7 @@
 wPartyEnd::     db ; older code doesn't check wPartyCount
 
 wPartyMons::
+	table_width PARTYMON_STRUCT_LENGTH, wPartyMons
 wPartyMon1:: party_struct wPartyMon1
 wPartyMon2:: party_struct wPartyMon2
 wPartyMon3:: party_struct wPartyMon3
@@ -3123,6 +3139,7 @@
 wPartyMon4:: party_struct wPartyMon4
 wPartyMon5:: party_struct wPartyMon5
 wPartyMon6:: party_struct wPartyMon6
+	assert_table_length PARTY_LENGTH
 
 wPartyMonOT:: ds NAME_LENGTH * PARTY_LENGTH
 
@@ -3343,6 +3360,7 @@
 	ds NUM_BATTLEANIMTILEDICT_ENTRIES * 2
 
 wActiveAnimObjects::
+	table_width BATTLEANIMSTRUCT_LENGTH, wActiveAnimObjects
 wAnimObject01:: battle_anim_struct wAnimObject01
 wAnimObject02:: battle_anim_struct wAnimObject02
 wAnimObject03:: battle_anim_struct wAnimObject03
@@ -3353,13 +3371,16 @@
 wAnimObject08:: battle_anim_struct wAnimObject08
 wAnimObject09:: battle_anim_struct wAnimObject09
 wAnimObject10:: battle_anim_struct wAnimObject10
+	assert_table_length NUM_ANIM_OBJECTS
 
 wActiveBGEffects::
+	table_width BG_EFFECT_STRUCT_LENGTH, wActiveBGEffects
 wBGEffect1:: battle_bg_effect wBGEffect1
 wBGEffect2:: battle_bg_effect wBGEffect2
 wBGEffect3:: battle_bg_effect wBGEffect3
 wBGEffect4:: battle_bg_effect wBGEffect4
 wBGEffect5:: battle_bg_effect wBGEffect5
+	assert_table_length NUM_BG_EFFECTS
 
 wLastAnimObjectIndex:: db