public Bncd(File f)
    {
        ArrayReader inp = new ArrayReader(f.getContents());
        inp.readInt(); //Magic;
        unk = inp.readShort();
        int entryCount = inp.readShort();
        int entriesOffset = inp.readInt();
        int subEntriesOffset = inp.readInt();
        int dataOffset = inp.readInt();
        int dataSize = inp.readInt();

        inp.seek(entriesOffset);

        //Stores tilenum, tilecount to imageid
        HashMap<Integer, Integer> imagesDict = new HashMap<>();

        for (int entryId = 0; entryId < entryCount; entryId++)
        {
            BncdEntry e = new BncdEntry();
            e.width = inp.readByte();
            e.height = inp.readByte();

            int subEntryIdx = inp.readShort();
            int subEntryCt = inp.readShort();

            inp.savePos();
            inp.seek(subEntriesOffset + subEntryIdx * 12);
            for (int i = 0; i < subEntryCt; i++)
            {
                BncdSubEntry se = new BncdSubEntry();
                e.subEntries.add(se);

                se.oamAttr0 = inp.readShort();
                se.oamAttr1 = inp.readShort();
                se.unk = inp.readInt();
                se.tileNumber = inp.readShort();
                se.tileCount = inp.readShort();

                int imageCode = (int) ((se.tileNumber << 16) | se.tileCount);
                int imageId = imagesDict.size();
                if (imagesDict.containsKey(imageCode))
                    imageId = imagesDict.get(imageCode);
                else
                {
                    imagesDict.put(imageCode, imageId);
                    BncdImage img = new BncdImage();
                    images.add(img);
                    img.tileNumber = se.tileNumber;
                    img.tileCount = se.tileCount;

                    int oamShape = se.oamAttr0 >> 14;
                    int oamSize = se.oamAttr1 >> 14;

                    img.tileWidth = widths[oamSize][oamShape];
                }

                se.imageId = imageId;
            }
            inp.loadPos();
        }

        /*        LevelChooser.showImgMgr();
         int tileLen = 8 * 8 / 2;
         for (BncdImage img : images)
         {
         File imgFile = new InlineFile(f, (int) dataOffset + img.tileNumber * tileLen, img.tileCount * tileLen, f.name);
         LevelChooser.imgMgr.m.addImage(new Image2D(imgFile, 8 * img.tileWidth, true, false));
         }*/
    }