def _ParseBattlePartyWeights(df, row, area="", address=0, header=False):
    if header:
        for colname in ["Weight", "Party Data", "Stage Data"]:
            row.append(colname)
    else:
        dat = g_DatabufMap[area]
        row.append(dat.read_u32(address + 0))
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 4),
                                    "BattleLoadoutParams_t"))
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 8),
                                    "BattleStageData_t"))
def _ParseBattleUnitEntry(df, row, area="", address=0, header=False):
    if header:
        for colname in [
                "Unit Type", "Item Table", "X Pos", "Y Pos", "Z Pos",
                "Attack Phase", "Alliance", "Alternate Form"
        ]:
            row.append(colname)
    else:
        dat = g_DatabufMap[area]
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 0x0),
                                    "BattleUnitParams_t"))
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 0x2c),
                                    "ItemDropWeight_t"))
        row.append(dat.read_float(address + 0xc))
        row.append(dat.read_float(address + 0x10))
        row.append(dat.read_float(address + 0x14))
        row.append(hex(dat.read_u32(address + 0x8)))
        row.append(dat.read_u8(address + 0x4))
        row.append(dat.read_u8(address + 0x1f))
def _ParseBattleStageData(df, row, area="", address=0, header=False):
    if header:
        for colname in [
                "Global Stage Data Dir", "Specific Stage Data Dir", "A1 Layer",
                "A2 Layer", "B Layer", "Ceiling", "Init Event", "A1 Event",
                "A2 Event", "B Event", "Unknown Event 1", "Unknown Event 2",
                "Scroll Event", "Rotate Event", "Unknown Bools"
        ]:
            row.append(colname)
    else:
        dat = g_DatabufMap[area]
        row.append(_ParseJisString(dat, address + 0))
        row.append(_ParseJisString(dat, address + 4))
        # Summarize what background layers exist and which actors are targets.
        target_types = ["None", "Party", "Enemies", "All"]
        a1_targets, b_targets = 3, 3
        a1, a2, b, ceiling = "None", "None", "None", "None"
        if dat.read_u32(address + 0x10 + 0x1c) != 0:
            targets = dat.read_u32(address + 0x10 + 0x64)
            if targets & 0xf:
                a1_targets &= ~1
            if targets & 0x10:
                a1_targets &= ~2
        if dat.read_u32(address + 0xd0 + 0x1c) != 0:
            targets = dat.read_u32(address + 0xd0 + 0x64)
            if targets & 0xf:
                b_targets &= ~1
            if targets & 0x10:
                b_targets &= ~2
        for idx in range(dat.read_u32(address + 0x8)):
            obj_address = dat.read_u32(address + 0xc) + idx * 0x18
            obj_layer = dat.read_s16(obj_address + 0x6)
            if obj_layer == 0:
                a1 = target_types[a1_targets]
            elif obj_layer == 1:
                a2 = "Yes"
            elif obj_layer == 2:
                b = target_types[b_targets]
            elif obj_layer == 6:
                ceiling = "Yes"
        row.append(a1)
        row.append(a2)
        row.append(b)
        row.append(ceiling)
        # Store event info, etc. (Probably not too important).
        for idx in range(8):
            row.append(
                maplib.LookupSymbolName(
                    df, area, dat.read_u32(address + 0x190 + idx * 4),
                    "EventScript_t"))
        row.append(hex(dat.read_u32(address + 0x1b0)))
def _ParseBattleParty(df, row, area="", address=0, header=False):
    if header:
        for colname in [
                "Num Units", "Unit Entry Data", "Held Weight", "Random Weight",
                "None Weight", "HP Drop Table", "FP Drop Table", "Unknown"
        ]:
            row.append(colname)
    else:
        dat = g_DatabufMap[area]
        row.append(dat.read_u32(address + 0))
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 4),
                                    "BattleUnitEntry_t"))
        row.append(dat.read_u32(address + 0x8))
        row.append(dat.read_u32(address + 0xc))
        row.append(dat.read_u32(address + 0x10))
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 0x14),
                                    "PointDropWeights_t"))
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 0x18),
                                    "PointDropWeights_t"))
        row.append(hex(dat.read_u32(address + 0x1c)))
def _ParseBattleUnitParts(df, row, area="", address=0, header=False):
    if header:
        for colname in [
                "Index",
                "Name",
                "Model Name",
                "Default Def",
                "Default Def Attr.",
                "Default Pose Table",
        ]:
            row.append(colname)

        # Headers for bitfield flags.
        _ParseFlagAttributesIndividually(row,
                                         attr_map=g_UnitPartsAttributeFlags,
                                         header=True)
        _ParseFlagAttributesIndividually(
            row, attr_map=g_UnitPartsCounterAttributeFlags, header=True)
    else:
        dat = g_DatabufMap[area]
        row.append(hex(dat.read_u32(address + 0x0)))
        row.append(_ParseJisString(dat, address + 0x4))
        row.append(_ParseJisString(dat, address + 0x8))
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 0x38),
                                    "BattleUnitDefense_t"))
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 0x3c),
                                    "BattleUnitDefenseAttr_t"))
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 0x48),
                                    "BattleUnitPoseTable_t"))
        # Bitfield flags.
        _ParseFlagAttributesIndividually(row, dat, address + 0x40,
                                         g_UnitPartsAttributeFlags)
        _ParseFlagAttributesIndividually(row, dat, address + 0x44,
                                         g_UnitPartsCounterAttributeFlags)
def _ParseBattleSetup(df, row, area="", address=0, header=False):
    if header:
        for colname in [
                "Battle Name", "Secondary Name", "Music Name",
                "Default Loadouts", "Loadout Flag", "Alternate Loadouts",
                "Max Audience", "Toad", "X-Naut", "Boo", "Hammer Bro",
                "Dull Bones", "Shy Guy", "Dayzee", "Puni", "Koopa",
                "Bulky Bob-omb", "Goomba", "Piranha Plant"
        ]:
            row.append(colname)
    else:
        dat = g_DatabufMap[area]
        row.append(_ParseJisString(dat, address + 0))
        row.append(_ParseJisString(dat, address + 4))
        row.append(_ParseJisString(dat, address + 0x40))
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 0x14),
                                    "BattleWeightedLoadout_t"))

        flag_id = dat.read_s32(address + 0xc)
        if flag_id == -1 or flag_id == 0:
            row.append("")
            row.append("")
        else:
            row.append(hex(flag_id + 130000000))
            row.append(
                maplib.LookupSymbolName(df, area, dat.read_u32(address + 0x10),
                                        "BattleWeightedLoadout_t"))

        row.append(dat.read_s32(address + 0x1c) > 0)
        for x in range(12):
            low_aud_weight = dat.read_s8(address + 0x20 + x * 2)
            high_aud_weight = dat.read_s8(address + 0x21 + x * 2)
            if low_aud_weight == high_aud_weight:
                row.append(low_aud_weight)
            else:
                row.append("%d-%d" % (low_aud_weight, high_aud_weight))
def _ParseItemParams(df, row, area="", address=0, header=False):
    if header:
        for colname in [
                "Item Id", "Name Key", "Description Key",
                "Menu Description Key", "Locations Usable", "Type Sort Order",
                "Buy Price", "Discount Buy Price", "Star Piece Price",
                "Sell Price", "BP Cost", "HP Restored", "FP Restored",
                "Icon ID", "Attack Params"
        ]:
            row.append(colname)
    else:
        dat = g_DatabufMap[area]
        row.append(_ParseJisString(dat, address + 0))
        row.append(_ParseJisString(dat, address + 4))
        row.append(_ParseJisString(dat, address + 8))
        row.append(_ParseJisString(dat, address + 0xc))
        location_flags = dat.read_s16(address + 0x10)
        locations = []
        if location_flags & 1:
            locations.append("Shop")
        if location_flags & 2:
            locations.append("Battle")
        if location_flags & 4:
            locations.append("Field")
        row.append("|".join(locations))
        row.append(dat.read_s16(address + 0x12))
        row.append(dat.read_s16(address + 0x14))
        row.append(dat.read_s16(address + 0x16))
        row.append(dat.read_s16(address + 0x18))
        row.append(dat.read_s16(address + 0x1a))
        row.append(dat.read_u8(address + 0x1c))
        row.append(dat.read_u8(address + 0x1d))
        row.append(dat.read_u8(address + 0x1e))
        row.append(hex(dat.read_u16(address + 0x20)))
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 0x24),
                                    "AttackParams_t"))
def _ParseBattleUnit(df, row, area="", address=0, header=False):
    if header:
        for colname in [
                "Id",
                "Enemy Name",
                "Name Key",
                "Max HP",
                "Max FP",
                "Danger HP",
                "Peril HP",
                "Level",
                "Bonus EXP",
                "Bonus Coin",
                "Bonus Coin Rate",
                "Base Coin",
                "Run Rate",
                "PB Minimum Cap",
                "Turn Order",
                "Turn Order Variance",
                "Swallowable",
                "Ultra Hammer Knock Chance",
                "Kiss Thief Threshold",
                "Default Attributes",
                "Default Status Vuln.",
                "Parts",
                "Init Script",
                "Data Table",
        ]:
            row.append(colname)
    else:
        dat = g_DatabufMap[area]
        row.append("0x%02x" % (dat.read_u32(address + 0x0), ))
        row.append(g_EnemyIds[dat.read_u32(address + 0x0)])
        row.append(_ParseJisString(dat, address + 0x4))
        row.append(dat.read_u16(address + 0x8))
        row.append(dat.read_u16(address + 0xa))
        row.append(dat.read_u8(address + 0xc))
        row.append(dat.read_u8(address + 0xd))
        row.append(dat.read_u8(address + 0xe))
        row.append(dat.read_u8(address + 0xf))
        row.append(dat.read_u8(address + 0x10))
        row.append(dat.read_u8(address + 0x11))
        row.append(dat.read_u8(address + 0x12))
        row.append(dat.read_u8(address + 0x13))
        row.append(dat.read_u16(address + 0x14))
        row.append(dat.read_u8(address + 0x88))
        row.append(dat.read_u8(address + 0x89))
        row.append("Yes" if dat.read_u8(address + 0x8a) == 0 else "No")
        row.append(dat.read_u8(address + 0x8c))
        row.append(dat.read_u8(address + 0x8d))
        # Parse default BattleUnitAttribute flags.
        row.append(
            _ParseFlagAttributes(dat, address + 0xac, {
                0x2: "Ceiling",
                0x4: "Floating",
            }))
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 0xb0),
                                    "BattleUnitStatusVulnerability_t"))
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 0xb8),
                                    "BattleUnitParts_t"))
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 0xbc),
                                    "EventScript_t"))
        row.append(
            maplib.LookupSymbolName(df, area, dat.read_u32(address + 0xc0),
                                    "BattleUnitDataTable_t"))
def _ParseAttackParams(df, row, area="", address=0, header=False):
    if header:
        for colname in [
                "Name Key",
                "Icon?",
                "Associated Item",
                "Base Accuracy",
                "Base FP Cost",
                "Base SP Cost",
                "Superguardable",
                "Stylish Multiplier",
                "Bingo Slot Chance",
                "Damage Function",
                "Damage Param1",
                "Damage Param2",
                "Damage Param3",
                "Damage Param4",
                "Damage Param5",
                "Damage Param6",
                "Damage Param7",
                "Damage Param8",
                "FP Damage Function",
                "FP Damage Param1",
                "FP Damage Param2",
                "FP Damage Param3",
                "FP Damage Param4",
                "FP Damage Param5",
                "FP Damage Param6",
                "FP Damage Param7",
                "FP Damage Param8",
                "Element",
                "After-Hit Effect",
                "Weapon AC Level",
                "AC Message Key",
                "Attack Script",
                # Status effect parameters.
                "Sleep Chance",
                "Sleep Time",
                "Stop Chance",
                "Stop Time",
                "Dizzy Chance",
                "Dizzy Time",
                "Poison Chance",
                "Poison Time",
                "Poison Strength",
                "Confuse Chance",
                "Confuse Time",
                "Electric Chance",
                "Electric Time",
                "Dodgy Chance",
                "Dodgy Time",
                "Burn Chance",
                "Burn Time",
                "Freeze Chance",
                "Freeze Time",
                "Size Change Chance",
                "Size Change Time",
                "Size Change Strength",
                "ATK Change Chance",
                "ATK Change Time",
                "ATK Change Strength",
                "DEF Change Chance",
                "DEF Change Time",
                "DEF Change Strength",
                "Allergic Chance",
                "Allergic Time",
                "OHKO Chance",
                "Charge Strength",
                "Fast Chance",
                "Fast Time",
                "Slow Chance",
                "Slow Time",
                "Fright Chance",
                "Gale Force Chance",
                "Payback Time",
                "Hold Fast Time",
                "Invisible Chance",
                "Invisible Time",
                "HP-Regen Time",
                "HP-Regen Strength",
                "FP-Regen Time",
                "FP-Regen Strength",
                # Stage hazard parameters.
                "BG A1+A2 Fall Weight",
                "BG A1 Fall Weight",
                "BG A2 Fall Weight",
                "BG No A1-A2 Fall Weight",
                "BG B Fall Chance",
                "Nozzle Turn Chance",
                "Nozzle Fire Chance",
                "Ceiling Fall Chance",
                "Object Fall Chance",
                "Unknown Stage Hazard Chance",
        ]:
            row.append(colname)

        # Headers for bitfield flags.
        _ParseFlagAttributesIndividually(row,
                                         attr_map=g_AttackTargetClassFlags,
                                         header=True)
        _ParseFlagAttributesIndividually(row,
                                         attr_map=g_AttackTargetPropertyFlags,
                                         header=True)
        _ParseFlagAttributesIndividually(row,
                                         attr_map=g_AttackSpecialPropertyFlags,
                                         header=True)
        _ParseFlagAttributesIndividually(
            row, attr_map=g_AttackCounterResistanceFlags, header=True)
        _ParseFlagAttributesIndividually(row,
                                         attr_map=g_AttackTargetWeightingFlags,
                                         header=True)
    else:
        # For diagnostics.
        print("%s 0x%08x" % (area, address))

        dat = g_DatabufMap[area]
        row.append(_ParseJisString(dat, address + 0x0))
        row.append(hex(dat.read_u16(address + 0x4)))
        row.append(g_ItemIds[dat.read_s32(address + 0x8)])
        row.append(dat.read_u8(address + 0x10))
        row.append(dat.read_u8(address + 0x11))
        row.append(dat.read_u8(address + 0x12))
        row.append("Yes" if dat.read_u8(address + 0x13) else "No")
        row.append(dat.read_u8(address + 0x18))
        row.append(dat.read_u8(address + 0x1a))
        if dat.read_u32(address + 0x1c):
            row.append(
                maplib.LookupSymbolName(df, area,
                                        dat.read_u32(address + 0x1c)))
        else:
            row.append("NULL")
        for idx in range(0x20, 0x40, 4):
            row.append(dat.read_s32(address + idx))
        if dat.read_u32(address + 0x40):
            row.append(
                maplib.LookupSymbolName(df, area,
                                        dat.read_u32(address + 0x40)))
        else:
            row.append("NULL")
        for idx in range(0x44, 0x64, 4):
            row.append(dat.read_s32(address + idx))
        element_types = ["Normal", "Fire", "Ice", "Explosion", "Electric"]
        row.append(element_types[dat.read_u8(address + 0x6c)])
        row.append(hex(dat.read_u8(address + 0x6d)))
        row.append(dat.read_u8(address + 0x6e))
        row.append(_ParseJisString(dat, address + 0x70))
        if dat.read_u32(address + 0xb0):
            row.append(
                maplib.LookupSymbolName(df, area, dat.read_u32(address + 0xb0),
                                        "EventScript_t"))
        else:
            row.append("NULL")
        # Status effect parameters.
        for idx in range(0x80, 0xae):
            row.append(dat.read_s8(address + idx))
        # Stage hazard parameters.
        for idx in range(0xb4, 0xbe):
            row.append(dat.read_s8(address + idx))
        # Bitfield flags.
        _ParseFlagAttributesIndividually(row, dat, address + 0x64,
                                         g_AttackTargetClassFlags)
        _ParseFlagAttributesIndividually(row, dat, address + 0x68,
                                         g_AttackTargetPropertyFlags)
        _ParseFlagAttributesIndividually(row, dat, address + 0x74,
                                         g_AttackSpecialPropertyFlags)
        _ParseFlagAttributesIndividually(row, dat, address + 0x78,
                                         g_AttackCounterResistanceFlags)
        _ParseFlagAttributesIndividually(row, dat, address + 0x7c,
                                         g_AttackTargetWeightingFlags)