#ifdef MEDIA042_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void F0333_INVENTORY_OpenAndDrawChest(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0692_T_Thing, P0693_ps_Container, P0694_B_PressingEye)
#endif
THING               P0692_T_Thing       SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
REGISTER CONTAINER* P0693_ps_Container  SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
CONTAINER*          P0693_ps_Container  SEPARATOR
#endif
BOOLEAN             P0694_B_PressingEye FINAL_SEPARATOR
{
        REGISTER int16_t L1017_i_ChestSlotIndex;
        REGISTER THING L1018_T_Thing;
#ifdef MEDIA178_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED /* CHANGE7_14_FIX Useless code removed */
        REGISTER int16_t L1020_i_Unreferenced; /* BUG0_00 Useless code */
        REGISTER int16_t L1021_i_Unreferenced; /* BUG0_00 Useless code */
        char L1022_ac_Unreferenced[40]; /* BUG0_00 Useless code */
#endif
#ifdef MEDIA345_S21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE8_08_FIX */
        REGISTER int16_t L1019_i_ThingCount;
#endif


#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        G0424_i_PanelContent = M569_PANEL_CHEST;
#endif
#ifdef MEDIA278_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE7_27_FIX Avoids opening a chest that is already open. In previous versions, this can occur when an object that has a modifier on a champion statistic (as applied by F0299_CHAMPION_ApplyObjectModifiersToStatistics) is placed in an appropriate slot or removed from that slot (for example placing Crown Of Nerra on the head or a Moonstone around the neck). This causes a refresh of the chest contents on screen where objects in the chest are reorganized so that there is no empty slot between them */
        if (G0426_T_OpenChest == P0692_T_Thing)
                return;
#endif
#ifdef MEDIA343_S21E_P20JA /* CHANGE8_09_FIX If another chest is already open, close it before opening the specified one */
        if (G0426_T_OpenChest != C0xFFFF_THING_NONE) {
#endif
#ifdef MEDIA346_S21E_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                F0334_INVENTORY_CloseChest();
#endif
#ifdef MEDIA343_S21E_P20JA /* CHANGE8_09_FIX */
        }
#endif
        G0426_T_OpenChest = P0692_T_Thing;
        if (!P0694_B_PressingEye) {
                F0038_OBJECT_DrawIconInSlotBox(C09_SLOT_BOX_INVENTORY_ACTION_HAND, C145_ICON_CONTAINER_CHEST_OPEN);
        }
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        M519_F0020_MAIN_BlitToViewport(F0489_MEMORY_GetNativeBitmapOrGraphic(C025_GRAPHIC_PANEL_OPEN_CHEST), G0032_ai_Graphic562_Box_Panel, C072_BYTE_WIDTH, C08_COLOR_RED, 73);
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        F0658_BlitBitmapIndexToZoneIndexWithTransparency(C025_GRAPHIC_PANEL_OPEN_CHEST, C101_ZONE_PANEL, C08_COLOR_RED);
#endif
        L1017_i_ChestSlotIndex = 0;
        L1018_T_Thing = P0693_ps_Container->Slot;
#ifdef MEDIA345_S21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE8_08_FIX */
        L1019_i_ThingCount = 0;
#endif
        while (L1018_T_Thing != C0xFFFE_THING_ENDOFLIST) {
#ifdef MEDIA345_S21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE8_08_FIX Make sure that no more than the first 8 objects in a chest are drawn */
                if (++L1019_i_ThingCount > 8) {
                        break;
                }
#endif
                F0038_OBJECT_DrawIconInSlotBox(L1017_i_ChestSlotIndex + C38_SLOT_BOX_CHEST_FIRST_SLOT, F0033_OBJECT_GetIconIndex(L1018_T_Thing));
                G0425_aT_ChestSlots[L1017_i_ChestSlotIndex++] = L1018_T_Thing;
                L1018_T_Thing = F0159_DUNGEON_GetNextThing(L1018_T_Thing);
        }
        while (L1017_i_ChestSlotIndex < 8) {
#ifdef MEDIA045_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
                F0038_OBJECT_DrawIconInSlotBox(L1017_i_ChestSlotIndex + C38_SLOT_BOX_CHEST_FIRST_SLOT, C0xFFFF_ICON_NONE);
#endif
#ifdef MEDIA670_F31E_F31J
                F0038_OBJECT_DrawIconInSlotBox(L1017_i_ChestSlotIndex + C38_SLOT_BOX_CHEST_FIRST_SLOT, -1);
#endif
                G0425_aT_ChestSlots[L1017_i_ChestSlotIndex++] = C0xFFFF_THING_NONE;
        }
}

void F0334_INVENTORY_CloseChest(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
#ifdef MEDIA069_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER CONTAINER* L1027_ps_Container;
        REGISTER GENERIC* L1028_ps_Generic;
#endif
#ifdef MEDIA488_F20E_F20J
        register CONTAINER* L1027_ps_Container;/* ANOMALY_FMT register keyword required */
        register GENERIC* L1028_ps_Generic;/* ANOMALY_FMT register keyword required */
#endif
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L1025_i_ChestSlotIndex;
#endif
#ifdef MEDIA070_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
        REGISTER THING L1023_T_Thing;
#endif
#ifdef MEDIA488_F20E_F20J
        register THING L1023_T_Thing;/* ANOMALY_FMT register keyword required */
#endif
#ifdef MEDIA670_F31E_F31J
        REGISTER THING L1023_T_Thing;
#endif
        REGISTER THING L1024_T_PreviousThing;
#ifdef MEDIA014_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J
        REGISTER int16_t L1025_i_ChestSlotIndex;
#endif
        REGISTER BOOLEAN L1026_B_ProcessFirstChestSlot;


        L1026_B_ProcessFirstChestSlot = C1_TRUE;
        if (G0426_T_OpenChest == C0xFFFF_THING_NONE)
                return;
        L1027_ps_Container = (CONTAINER*)F0156_DUNGEON_GetThingData(G0426_T_OpenChest);
        G0426_T_OpenChest = C0xFFFF_THING_NONE;
        L1027_ps_Container->Slot = C0xFFFE_THING_ENDOFLIST;
        for (L1025_i_ChestSlotIndex = 0; L1025_i_ChestSlotIndex < 8; L1025_i_ChestSlotIndex++) {
                if ((L1023_T_Thing = G0425_aT_ChestSlots[L1025_i_ChestSlotIndex]) != C0xFFFF_THING_NONE) {
#ifdef MEDIA348_S21E_X30J_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE8_09_FIX Make sure things are erased in chest slots */
                        G0425_aT_ChestSlots[L1025_i_ChestSlotIndex] = C0xFFFF_THING_NONE;
#endif
                        if (L1026_B_ProcessFirstChestSlot) {
                                L1026_B_ProcessFirstChestSlot = C0_FALSE;
                                L1028_ps_Generic = (GENERIC*)F0156_DUNGEON_GetThingData(L1023_T_Thing);
                                L1028_ps_Generic->Next = C0xFFFE_THING_ENDOFLIST;
                                L1027_ps_Container->Slot = L1024_T_PreviousThing = L1023_T_Thing;
                        } else {
                                F0163_DUNGEON_LinkThingToList(L1023_T_Thing, L1024_T_PreviousThing, CM1_MAPX_NOT_ON_A_SQUARE, 0);
                                L1024_T_PreviousThing = L1023_T_Thing;
                        }
                }
        }
}
#endif
