Example usage for org.apache.poi.xssf.usermodel XSSFSheet getRow

List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet getRow

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFSheet getRow.

Prototype

@Override
public XSSFRow getRow(int rownum) 

Source Link

Document

Returns the logical row ( 0-based).

Usage

From source file:ReadSheet2.java

public HashMap readTable4(String path) throws IOException {

    HashMap<String, Object> table4 = new HashMap();
    HashMap<String, Object> cutverification = new HashMap();
    HashMap<String, Object> cpiverification = new HashMap();

    FileInputStream fs = new FileInputStream(new File(path));
    XSSFWorkbook wb = new XSSFWorkbook(fs);
    XSSFSheet sheet = wb.getSheetAt(2);

    String temp = reader.getValue(sheet.getRow(26).getCell(0)).toString();
    String key = temp.substring(0, 13);
    String value = temp.substring(13);
    if (temp.length() > 13) {
        cpiverification.put(key, value);
    } else/*from   w ww  . j  ava  2  s .  com*/
        cpiverification.put(temp, "");

    String temp1 = reader.getValue(sheet.getRow(27).getCell(0)).toString();
    String key1 = temp1.substring(0, 10);
    String value1 = temp1.substring(10);
    if (temp1.length() > 10) {
        cpiverification.put(key1, value1);
    } else
        cpiverification.put(temp1, "");

    table4.put("CPI VERIFICATION", cpiverification);
    //------------------------------------

    String temp2 = reader.getValue(sheet.getRow(26).getCell(16)).toString();
    String key2 = temp2.substring(0, 22);
    String value2 = temp2.substring(22);
    if (temp2.length() > 22) {
        cutverification.put(key2, value2);
    } else
        cutverification.put(temp2, "");

    String temp3 = reader.getValue(sheet.getRow(27).getCell(16)).toString();
    String key3 = temp3.substring(0, 10);
    String value3 = temp3.substring(10);
    if (temp3.length() > 10) {
        cutverification.put(key3, value3);
    } else
        cutverification.put(temp3, "");

    table4.put("Cut BANK VERIFICATION", cutverification);
    return table4;

}

From source file:MonsterStatIndexer.java

License:Open Source License

private static void doit1(int skip, int column, XSSFSheet sheet, Callback callback) throws IOException {
    columnsUsed.remove(column);/*from w w  w  .j a  v  a2  s .  c  o  m*/

    FileInputStream stream = new FileInputStream("Dominions4.exe");
    stream.skip(Starts.MONSTER);
    int rowNumber = 1;
    int i = 0;
    byte[] c = new byte[2];
    stream.skip(skip);
    while ((stream.read(c, 0, 2)) != -1) {
        String high = String.format("%02X", c[1]);
        String low = String.format("%02X", c[0]);
        XSSFRow row = sheet.getRow(rowNumber);
        rowNumber++;
        XSSFCell cell = row.getCell(column, Row.CREATE_NULL_AS_BLANK);
        int value = Integer.decode("0X" + high + low);
        if (callback != null) {
            cell.setCellValue(callback.found(Integer.toString(value)));
        } else {
            cell.setCellValue(Integer.decode("0X" + high + low));
        }
        stream.skip(254l);
        i++;
        if (i >= Starts.MONSTER_COUNT) {
            break;
        }
    }
    stream.close();
}

From source file:MonsterStatIndexer.java

License:Open Source License

private static void doit2(XSSFSheet sheet, String attr, int column, Callback callback, boolean append)
        throws IOException {
    columnsUsed.remove(column);//from w w  w.  j a va2 s .co m

    FileInputStream stream = new FileInputStream("Dominions4.exe");
    stream.skip(Starts.MONSTER);
    int rowNumber = 1;
    int i = 0;
    int k = 0;
    int pos = -1;
    long numFound = 0;
    byte[] c = new byte[2];
    stream.skip(64);
    while ((stream.read(c, 0, 2)) != -1) {
        String high = String.format("%02X", c[1]);
        String low = String.format("%02X", c[0]);
        int weapon = Integer.decode("0X" + high + low);
        if (weapon == 0) {
            boolean found = false;
            int value = 0;
            stream.skip(46l - numFound * 2l);
            // Values
            for (int x = 0; x < numFound; x++) {
                byte[] d = new byte[4];
                stream.read(d, 0, 4);
                String high1 = String.format("%02X", d[3]);
                String low1 = String.format("%02X", d[2]);
                high = String.format("%02X", d[1]);
                low = String.format("%02X", d[0]);
                //System.out.print(low + high + " ");
                if (x == pos) {
                    value = new BigInteger(high1 + low1 + high + low, 16).intValue();
                    //System.out.print(fire);
                    found = true;
                }
                //stream.skip(2);
            }

            //System.out.println("");
            XSSFRow row = sheet.getRow(rowNumber);
            rowNumber++;
            XSSFCell cell = row.getCell(column, Row.CREATE_NULL_AS_BLANK);
            if (found) {
                if (callback == null) {
                    if (append) {
                        String origVal = cell.getStringCellValue();
                        cell.setCellValue(origVal + value);
                    } else {
                        cell.setCellValue(value);
                    }
                } else {
                    if (append) {
                        String origVal = cell.getStringCellValue();
                        if (callback.found(Integer.toString(value)) != null) {
                            cell.setCellValue(origVal + callback.found(Integer.toString(value)));
                        }
                    } else {
                        if (callback.found(Integer.toString(value)) != null) {
                            cell.setCellValue(callback.found(Integer.toString(value)));
                        }
                    }
                }
            } else {
                if (callback == null) {
                    cell.setCellValue("");
                } else {
                    if (callback.notFound() != null) {
                        cell.setCellValue(callback.notFound());
                    }
                }
            }
            stream.skip(254l - 46l - numFound * 4l);
            numFound = 0;
            pos = -1;
            k = 0;
            i++;
        } else {
            //System.out.print(low + high + " ");
            if (attr.indexOf(low + high) != -1) {
                if (pos == -1) {
                    pos = k;
                }
            }
            k++;
            numFound++;
        }
        if (i >= Starts.MONSTER_COUNT) {
            break;
        }
    }
    stream.close();
}

From source file:MonsterStatIndexer.java

License:Open Source License

public static void run() {
    FileInputStream stream = null;
    try {/*from w  w  w . j  a  v  a 2  s.  c  o m*/
        long startIndex = Starts.MONSTER;
        int ch;

        stream = new FileInputStream("Dominions4.exe");
        stream.skip(startIndex);

        XSSFWorkbook wb = MonsterStatIndexer.readFile("BaseU.xlsx");
        FileOutputStream fos = new FileOutputStream("NewBaseU.xlsx");
        XSSFSheet sheet = wb.getSheetAt(0);

        XSSFRow titleRow = sheet.getRow(0);
        int cellNum = 0;
        XSSFCell titleCell = titleRow.getCell(cellNum);
        Set<String> skip = new HashSet<String>(Arrays.asList(SkipColumns));
        while (titleCell != null) {
            String stringCellValue = titleCell.getStringCellValue();
            if (!skip.contains(stringCellValue)) {
                columnsUsed.put(cellNum, stringCellValue);
            }
            cellNum++;
            titleCell = titleRow.getCell(cellNum);
        }

        // Name
        InputStreamReader isr = new InputStreamReader(stream, "ISO-8859-1");
        Reader in = new BufferedReader(isr);
        int rowNumber = 1;
        while ((ch = in.read()) > -1) {
            StringBuffer name = new StringBuffer();
            while (ch != 0) {
                name.append((char) ch);
                ch = in.read();
            }
            if (name.length() == 0) {
                continue;
            }
            if (name.toString().equals("end")) {
                break;
            }
            in.close();

            stream = new FileInputStream("Dominions4.exe");
            startIndex = startIndex + 256l;
            stream.skip(startIndex);
            isr = new InputStreamReader(stream, "ISO-8859-1");
            in = new BufferedReader(isr);

            //System.out.println(name);

            XSSFRow row = sheet.getRow(rowNumber);
            XSSFCell cell1 = row.getCell(0, Row.CREATE_NULL_AS_BLANK);
            cell1.setCellValue(rowNumber);
            rowNumber++;
            XSSFCell cell = row.getCell(1, Row.CREATE_NULL_AS_BLANK);
            cell.setCellValue(name.toString());
        }
        in.close();
        stream.close();

        // AP
        doit1(40, 31, sheet);

        // MM
        doit1(42, 30, sheet);

        // Size
        doit1(44, 19, sheet);

        // ressize
        doit1(44, 20, sheet);
        doit2(sheet, "0901", 20, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });

        // HP
        doit1(46, 21, sheet);

        // Prot
        doit1(48, 22, sheet);

        // STR
        doit1(50, 25, sheet);

        // ENC
        doit1(52, 29, sheet);

        // Prec
        doit1(54, 28, sheet);

        // ATT
        doit1(56, 26, sheet);

        // Def
        doit1(58, 27, sheet);

        // MR
        doit1(60, 23, sheet);

        // Mor
        doit1(62, 24, sheet);

        // wpn1
        doit1(208, 2, sheet, new CallbackAdapter() {
            @Override
            public String found(String value) {
                if (Integer.parseInt(value) == 0) {
                    return "";
                }
                return value;
            }
        });

        // wpn2
        doit1(210, 3, sheet, new CallbackAdapter() {
            @Override
            public String found(String value) {
                if (Integer.parseInt(value) == 0) {
                    return "";
                }
                return value;
            }
        });

        // wpn3
        doit1(212, 4, sheet, new CallbackAdapter() {
            @Override
            public String found(String value) {
                if (Integer.parseInt(value) == 0) {
                    return "";
                }
                return value;
            }
        });

        // wpn4
        doit1(214, 5, sheet, new CallbackAdapter() {
            @Override
            public String found(String value) {
                if (Integer.parseInt(value) == 0) {
                    return "";
                }
                return value;
            }
        });

        // wpn5
        doit1(216, 6, sheet, new CallbackAdapter() {
            @Override
            public String found(String value) {
                if (Integer.parseInt(value) == 0) {
                    return "";
                }
                return value;
            }
        });

        // wpn6
        doit1(218, 7, sheet, new CallbackAdapter() {
            @Override
            public String found(String value) {
                if (Integer.parseInt(value) == 0) {
                    return "";
                }
                return value;
            }
        });

        // wpn7
        doit1(220, 8, sheet, new CallbackAdapter() {
            @Override
            public String found(String value) {
                if (Integer.parseInt(value) == 0) {
                    return "";
                }
                return value;
            }
        });

        // armor1
        doit1(228, 9, sheet, new CallbackAdapter() {
            @Override
            public String found(String value) {
                if (Integer.parseInt(value) == 0) {
                    return "";
                }
                return value;
            }
        });

        // armor2
        doit1(230, 10, sheet, new CallbackAdapter() {
            @Override
            public String found(String value) {
                if (Integer.parseInt(value) == 0) {
                    return "";
                }
                return value;
            }
        });

        // armor3
        doit1(232, 11, sheet, new CallbackAdapter() {
            @Override
            public String found(String value) {
                if (Integer.parseInt(value) == 0) {
                    return "";
                }
                return value;
            }
        });

        // basecost
        doit1(234, 15, sheet);

        stream = new FileInputStream("Dominions4.exe");
        stream.skip(Starts.MONSTER);
        rowNumber = 1;
        // res
        int i = 0;
        byte[] c = new byte[2];
        stream.skip(236);
        while ((stream.read(c, 0, 2)) != -1) {
            String high = String.format("%02X", c[1]);
            String low = String.format("%02X", c[0]);
            //System.out.println(Integer.decode("0X" + high + low));
            XSSFRow row = sheet.getRow(rowNumber);
            rowNumber++;
            XSSFCell cell = row.getCell(18, Row.CREATE_NULL_AS_BLANK);
            int tmp = new BigInteger(high + low, 16).intValue();
            if (tmp < 1000) {
                cell.setCellValue(Integer.decode("0X" + high + low));
            } else {
                cell.setCellValue(new BigInteger("FFFF" + high + low, 16).intValue());
            }
            stream.skip(254l);
            i++;
            if (i >= Starts.MONSTER_COUNT) {
                break;
            }
        }
        stream.close();

        // additional leadership
        doit2(sheet, "9D00", 35, new Callback() {

            @Override
            public String notFound() {
                return "40";
            }

            @Override
            public String found(String value) {
                return Integer.toString(Integer.parseInt(value) + 40);
            }
        });

        // itemslots defaults
        doit2(sheet, "B600", 40, new CallbackAdapter() {
            // hand
            @Override
            public String notFound() {
                return "2";
            }
        });
        doit2(sheet, "B600", 41, new CallbackAdapter() {
            // head
            @Override
            public String notFound() {
                return "1";
            }
        });
        doit2(sheet, "B600", 42, new CallbackAdapter() {
            // body
            @Override
            public String notFound() {
                return "1";
            }
        });
        doit2(sheet, "B600", 43, new CallbackAdapter() {
            // foot
            @Override
            public String notFound() {
                return "1";
            }
        });
        doit2(sheet, "B600", 44, new CallbackAdapter() {
            // misc
            @Override
            public String notFound() {
                return "2";
            }
        });

        // Large bitmap
        for (String[] pair : DOTHESE) {
            columnsUsed.remove(Integer.parseInt(pair[1]));
            rowNumber = 1;
            boolean[] boolArray = largeBitmap(pair[0]);
            for (boolean found : boolArray) {
                XSSFRow row = sheet.getRow(rowNumber);
                rowNumber++;
                XSSFCell cell = row.getCell(Integer.parseInt(pair[1]), Row.CREATE_NULL_AS_BLANK);
                if (found) {
                    if (pair[0].equals("slow_to_recruit")) {
                        cell.setCellValue(2);
                    } else if (pair[0].equals("heat")) {
                        cell.setCellValue(3);
                    } else if (pair[0].equals("cold")) {
                        cell.setCellValue(3);
                    } else if (pair[0].equals("stealthy40")) {
                        String additional = getAttr("6C00", rowNumber - 1);
                        boolean glamour = false;
                        if (largeBitmap("illusion")[rowNumber - 2]) {
                            glamour = true;
                        }
                        cell.setCellValue(40 + Integer.parseInt(additional.equals("") ? "0" : additional)
                                + (glamour ? 25 : 0));
                    } else if (pair[0].equals("coldres15")) {
                        String additional = getAttr("C900", rowNumber - 1);
                        boolean cold = false;
                        if (largeBitmap("cold")[rowNumber - 2] || getAttr("DC00", rowNumber - 1).length() > 0) {
                            cold = true;
                        }
                        cell.setCellValue(15 + Integer.parseInt(additional.equals("") ? "0" : additional)
                                + (cold ? 10 : 0));
                    } else if (pair[0].equals("fireres15")) {
                        String additional = getAttr("C600", rowNumber - 1);
                        boolean heat = false;
                        if (largeBitmap("heat")[rowNumber - 2] || getAttr("3C01", rowNumber - 1).length() > 0) {
                            heat = true;
                        }
                        cell.setCellValue(15 + Integer.parseInt(additional.equals("") ? "0" : additional)
                                + (heat ? 10 : 0));
                    } else if (pair[0].equals("poisonres15")) {
                        String additional = getAttr("C800", rowNumber - 1);
                        boolean poisoncloud = false;
                        if (largeBitmap("undead")[rowNumber - 2] || largeBitmap("inanimate")[rowNumber - 2]
                                || getAttr("6A00", rowNumber - 1).length() > 0) {
                            poisoncloud = true;
                        }
                        cell.setCellValue(15 + Integer.parseInt(additional.equals("") ? "0" : additional)
                                + (poisoncloud ? 10 : 0));
                    } else if (pair[0].equals("shockres15")) {
                        String additional = getAttr("C700", rowNumber - 1);
                        cell.setCellValue(15 + Integer.parseInt(additional.equals("") ? "0" : additional));
                    } else if (pair[0].equals("noleader")) {
                        String additional = getAttr("9D00", rowNumber - 1);
                        XSSFCell baseLeaderCell = row.getCell(248, Row.CREATE_NULL_AS_BLANK);
                        baseLeaderCell.setCellValue("0");
                        if (!"".equals(additional)) {
                            cell.setCellValue(additional);
                        } else {
                            cell.setCellValue("0");
                        }
                    } else if (pair[0].equals("poorleader")) {
                        String additional = getAttr("9D00", rowNumber - 1);
                        XSSFCell baseLeaderCell = row.getCell(248, Row.CREATE_NULL_AS_BLANK);
                        baseLeaderCell.setCellValue("10");
                        if (!"".equals(additional)) {
                            cell.setCellValue(Integer.toString(10 + Integer.parseInt(additional)));
                        } else {
                            cell.setCellValue("10");
                        }
                    } else if (pair[0].equals("goodleader")) {
                        String additional = getAttr("9D00", rowNumber - 1);
                        XSSFCell baseLeaderCell = row.getCell(248, Row.CREATE_NULL_AS_BLANK);
                        baseLeaderCell.setCellValue("80");
                        if (!"".equals(additional)) {
                            cell.setCellValue(Integer.toString(80 + Integer.parseInt(additional)));
                        } else {
                            cell.setCellValue("80");
                        }
                    } else if (pair[0].equals("expertleader")) {
                        String additional = getAttr("9D00", rowNumber - 1);
                        XSSFCell baseLeaderCell = row.getCell(248, Row.CREATE_NULL_AS_BLANK);
                        baseLeaderCell.setCellValue("120");
                        if (!"".equals(additional)) {
                            cell.setCellValue(Integer.toString(120 + Integer.parseInt(additional)));
                        } else {
                            cell.setCellValue("120");
                        }
                    } else if (pair[0].equals("superiorleader")) {
                        String additional = getAttr("9D00", rowNumber - 1);
                        XSSFCell baseLeaderCell = row.getCell(248, Row.CREATE_NULL_AS_BLANK);
                        baseLeaderCell.setCellValue("160");
                        if (!"".equals(additional)) {
                            cell.setCellValue(Integer.toString(160 + Integer.parseInt(additional)));
                        } else {
                            cell.setCellValue("160");
                        }
                    } else if (pair[0].equals("poormagicleader")) {
                        cell.setCellValue("10");
                    } else if (pair[0].equals("okmagicleader")) {
                        cell.setCellValue("40");
                    } else if (pair[0].equals("goodmagicleader")) {
                        cell.setCellValue("80");
                    } else if (pair[0].equals("expertmagicleader")) {
                        cell.setCellValue("120");
                    } else if (pair[0].equals("superiormagicleader")) {
                        cell.setCellValue("160");
                    } else if (pair[0].equals("poorundeadleader")) {
                        cell.setCellValue("10");
                    } else if (pair[0].equals("okundeadleader")) {
                        cell.setCellValue("40");
                    } else if (pair[0].equals("goodundeadleader")) {
                        cell.setCellValue("80");
                    } else if (pair[0].equals("expertundeadleader")) {
                        cell.setCellValue("120");
                    } else if (pair[0].equals("superiorundeadleader")) {
                        cell.setCellValue("160");
                    } else if (pair[0].equals("misc2")) {
                        XSSFCell handCell = row.getCell(40, Row.CREATE_NULL_AS_BLANK);
                        handCell.setCellValue(0);
                        XSSFCell headCell = row.getCell(41, Row.CREATE_NULL_AS_BLANK);
                        headCell.setCellValue(0);
                        XSSFCell bodyCell = row.getCell(42, Row.CREATE_NULL_AS_BLANK);
                        bodyCell.setCellValue(0);
                        XSSFCell footCell = row.getCell(43, Row.CREATE_NULL_AS_BLANK);
                        footCell.setCellValue(0);
                        XSSFCell miscCell = row.getCell(44, Row.CREATE_NULL_AS_BLANK);
                        miscCell.setCellValue(2);
                    } else if (pair[0].equals("mounted")) {
                        XSSFCell footCell = row.getCell(43, Row.CREATE_NULL_AS_BLANK);
                        footCell.setCellValue(0);
                    } else {
                        cell.setCellValue(1);
                    }
                } else {
                    if (pair[0].equals("slow_to_recruit")) {
                        cell.setCellValue(1);
                    } else if (pair[0].equals("heat")) {
                        cell.setCellValue(getAttr("3C01", rowNumber - 1));
                    } else if (pair[0].equals("cold")) {
                        cell.setCellValue(getAttr("DC00", rowNumber - 1));
                    } else if (pair[0].equals("coldres15")) {
                        boolean cold = false;
                        if (largeBitmap("cold")[rowNumber - 2] || getAttr("DC00", rowNumber - 1).length() > 0) {
                            cold = true;
                        }
                        String additional = getAttr("C900", rowNumber - 1);
                        int coldres = Integer.parseInt(additional.equals("") ? "0" : additional)
                                + (cold ? 10 : 0);
                        cell.setCellValue(coldres == 0 ? "" : Integer.toString(coldres));
                    } else if (pair[0].equals("fireres15")) {
                        boolean heat = false;
                        if (largeBitmap("heat")[rowNumber - 2] || getAttr("3C01", rowNumber - 1).length() > 0) {
                            heat = true;
                        }
                        String additional = getAttr("C600", rowNumber - 1);
                        int coldres = Integer.parseInt(additional.equals("") ? "0" : additional)
                                + (heat ? 10 : 0);
                        cell.setCellValue(coldres == 0 ? "" : Integer.toString(coldres));
                    } else if (pair[0].equals("poisonres15")) {
                        boolean poisoncloud = false;
                        if (largeBitmap("undead")[rowNumber - 2] || largeBitmap("inanimate")[rowNumber - 2]
                                || getAttr("6A00", rowNumber - 1).length() > 0) {
                            poisoncloud = true;
                        }
                        String additional = getAttr("C800", rowNumber - 1);
                        int poisonres = Integer.parseInt(additional.equals("") ? "0" : additional)
                                + (poisoncloud ? 10 : 0);
                        cell.setCellValue(poisonres == 0 ? "" : Integer.toString(poisonres));
                    } else if (pair[0].equals("shockres15")) {
                        String additional = getAttr("C700", rowNumber - 1);
                        int shockres = Integer.parseInt(additional.equals("") ? "0" : additional);
                        cell.setCellValue(shockres == 0 ? "" : Integer.toString(shockres));
                    } else if (pair[0].equals("stealthy40")) {
                        String additional = getAttr("6C00", rowNumber - 1);
                        cell.setCellValue(additional == null || additional.equals("") ? "" : additional);
                    } else if (pair[0].equals("immobile") || pair[0].equals("teleport")
                            || pair[0].equals("float") || pair[0].equals("bluntres")
                            || pair[0].equals("slashres") || pair[0].equals("pierceres")) {
                        cell.setCellValue("");
                    } else if (pair[0].equals("noleader") || pair[0].equals("poorleader")
                            || pair[0].equals("goodleader") || pair[0].equals("expertleader")
                            || pair[0].equals("superiorleader") || pair[0].equals("poormagicleader")
                            || pair[0].equals("okmagicleader") || pair[0].equals("goodmagicleader")
                            || pair[0].equals("expertmagicleader") || pair[0].equals("superiormagicleader")
                            || pair[0].equals("poorundeadleader") || pair[0].equals("okundeadleader")
                            || pair[0].equals("goodundeadleader") || pair[0].equals("expertundeadleader")
                            || pair[0].equals("superiorundeadleader") || pair[0].equals("misc2")) {
                    } else {
                        cell.setCellValue(0);
                    }
                }
            }
        }

        /*stream = new FileInputStream("Dominions4.exe");         
        stream.skip(Starts.MONSTER);
        i = 0;
        c = new byte[16];
        stream.skip(240);
        while ((stream.read(c, 0, 16)) != -1) {
           boolean found = false;
           System.out.print("(" + (i+1) + ") ");
           String high = String.format("%02X", c[1]);
           String low = String.format("%02X", c[0]);
           //System.out.print(high + low + " ");
           int val = Integer.decode("0X" + high + low);
           if (val > 0) {
              System.out.print("1:{");
              for (int j=0; j < 16; j++) {
          if ((val & MASK[j]) != 0) {
             System.out.print((found?",":"") + (value1[j].equals("")?("*****"+(j+1)+"*****"):value1[j]));
             found = true;
          }
              }
              System.out.print("}");
           }
           high = String.format("%02X", c[3]);
           low = String.format("%02X", c[2]);
           //System.out.print(high + low + " ");
           val = Integer.decode("0X" + high + low);
           if (val > 0) {
              System.out.print(" 2:{");
              found = false;
              for (int j=0; j < 16; j++) {
          if ((val & MASK[j]) != 0) {
             System.out.print((found?",":"") + (value2[j].equals("")?("*****"+(j+1)+"*****"):value2[j]));
             found = true;
          }
              }
              System.out.print("}");
           }
           high = String.format("%02X", c[5]);
           low = String.format("%02X", c[4]);
           //System.out.print(high + low + " ");
           val = Integer.decode("0X" + high + low);
           if (val > 0) {
              System.out.print(" 3:{");
              found = false;
              for (int j=0; j < 16; j++) {
          if ((val & MASK[j]) != 0) {
             System.out.print((found?",":"") + (value3[j].equals("")?("*****"+(j+1)+"*****"):value3[j]));
             found = true;
          }
              }
              System.out.print("}");
           }
                
           high = String.format("%02X", c[7]);
           low = String.format("%02X", c[6]);
           //System.out.print(high + low + " ");
           val = Integer.decode("0X" + high + low);
           if (val > 0) {
              System.out.print(" 4:{");
              found = false;
              for (int j=0; j < 16; j++) {
          if ((val & MASK[j]) != 0) {
             System.out.print((found?",":"") + (value4[j].equals("")?("*****"+(j+1)+"*****"):value4[j]));
             found = true;
          }
              }
              System.out.print("}");
           }
                
           high = String.format("%02X", c[9]);
           low = String.format("%02X", c[8]);
           //System.out.print(high + low + " ");
           val = Integer.decode("0X" + high + low);
           if (val > 0) {
              System.out.print(" 5:{");
              found = false;
              for (int j=0; j < 16; j++) {
          if ((val & MASK[j]) != 0) {
             System.out.print((found?",":"") + (value5[j].equals("")?("*****"+(j+1)+"*****"):value5[j]));
             found = true;
          }
              }
              System.out.print("}");
           }
           high = String.format("%02X", c[11]);
           low = String.format("%02X", c[10]);
           //System.out.print(high + low + " ");
           val = Integer.decode("0X" + high + low);
           if (val > 0) {
              System.out.print(" 6:{");
              found = false;
              for (int j=0; j < 16; j++) {
          if ((val & MASK[j]) != 0) {
             System.out.print((found?",":"") + (value6[j].equals("")?(j+1):value6[j]));
             found = true;
          }
              }
              System.out.print("}");
           }
           high = String.format("%02X", c[13]);
           low = String.format("%02X", c[12]);
           //System.out.print(high + low + " ");
           val = Integer.decode("0X" + high + low);
           if (val > 0) {
              System.out.print(" 7:{");
              found = false;
              for (int j=0; j < 16; j++) {
          if ((val & MASK[j]) != 0) {
             System.out.print((found?",":"") + (value7[j].equals("")?(j+1):value7[j]));
             found = true;
          }
              }
              System.out.print("}");
           }
           high = String.format("%02X", c[15]);
           low = String.format("%02X", c[14]);
           //System.out.print(high + low + " ");
           val = Integer.decode("0X" + high + low);
           if (val > 0) {
              System.out.print(" 8:{");
              found = false;
              for (int j=0; j < 16; j++) {
          if ((val & MASK[j]) != 0) {
             System.out.print((found?",":"") + (value8[j].equals("")?(j+1):value8[j]));
             found = true;
          }
              }
              System.out.print("}");
           }
                   
           if (!found) {
              //System.out.println("");
           }
           System.out.println(" ");
           stream.skip(240l);
           i++;
           if (i >= Starts.MONSTER_COUNT) {
              break;
           }
        }
        stream.close();*/

        // realm
        stream = new FileInputStream("Dominions4.exe");
        stream.skip(Starts.MONSTER);
        i = 0;
        int k = 0;
        Set<Integer> posSet = new HashSet<Integer>();
        long numFound = 0;
        c = new byte[2];
        stream.skip(64);
        while ((stream.read(c, 0, 2)) != -1) {
            String high = String.format("%02X", c[1]);
            String low = String.format("%02X", c[0]);
            int weapon = Integer.decode("0X" + high + low);
            if (weapon == 0) {
                stream.skip(46l - numFound * 2l);
                int numRealms = 0;
                // Values
                for (int x = 0; x < numFound; x++) {
                    byte[] d = new byte[4];
                    stream.read(d, 0, 4);
                    String high1 = String.format("%02X", d[3]);
                    String low1 = String.format("%02X", d[2]);
                    high = String.format("%02X", d[1]);
                    low = String.format("%02X", d[0]);
                    //System.out.print(low + high + " ");
                    if (posSet.contains(x)) {
                        int fire = new BigInteger(high1 + low1 + high + low, 16).intValue();//Integer.decode("0X" + high + low);
                        //System.out.print(i+1 + "\t" + fire);
                        //System.out.println("");
                        XSSFRow row = sheet.getRow(i + 1);
                        XSSFCell cell = row.getCell(233 + numRealms, Row.CREATE_NULL_AS_BLANK);
                        cell.setCellValue(fire);
                        numRealms++;
                    }
                    //stream.skip(2);
                }

                //               System.out.println("");
                stream.skip(254l - 46l - numFound * 4l);
                numFound = 0;
                posSet.clear();
                k = 0;
                i++;
            } else {
                //System.out.print(low + high + " ");
                if ((low + high).equals("AA01")) {
                    posSet.add(k);
                }
                k++;
                numFound++;
            }
            if (i >= Starts.MONSTER_COUNT) {
                break;
            }
        }
        stream.close();

        // patience
        doit2(sheet, "CD01", 104);

        // stormimmune
        doit2(sheet, "AF00", 94, new CallbackAdapter() {
            @Override
            public String notFound() {
                return "0";
            }
        });

        // regeneration
        doit2(sheet, "BD00", 151);

        // secondshape
        doit2(sheet, "C200", 210);

        // firstshape
        doit2(sheet, "C300", 209);

        // shapechange
        doit2(sheet, "C100", 208);

        // secondtmpshape
        doit2(sheet, "C400", 211);

        // landshape
        doit2(sheet, "F500", 212);

        // watershape
        doit2(sheet, "F600", 213);

        // forestshape
        doit2(sheet, "4201", 214);

        // plainshape
        doit2(sheet, "4301", 215);

        // damagerev
        doit2(sheet, "CA00", 144, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return Integer.toString(Integer.parseInt(value) - 1);
            }
        });

        // bloodvengeance
        doit2(sheet, "9E01", 231);

        // nobadevents
        doit2(sheet, "EB00", 178);

        // bringeroffortune
        doit2(sheet, "E400", 232);

        // darkvision
        doit2(sheet, "1901", 133);

        // fear
        doit2(sheet, "B700", 138);

        // voidsanity
        doit2(sheet, "1501", 132);

        // standard
        doit2(sheet, "6700", 117);

        // formationfighter
        doit2(sheet, "6E01", 115);

        // undisciplined
        doit2(sheet, "6F01", 114);

        // bodyguard
        doit2(sheet, "9801", 121);

        // summon
        doit2(sheet, "A400,A500,A600", 223);
        doit2(sheet, "A400", 224, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return "1";
            }

            @Override
            public String notFound() {
                return null;
            }
        });
        doit2(sheet, "A500", 224, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return "2";
            }

            @Override
            public String notFound() {
                return null;
            }
        });
        doit2(sheet, "A600", 224, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return "3";
            }

            @Override
            public String notFound() {
                return null;
            }
        });
        doit2(sheet, "A400,A500,A600", 224, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return null;
            }
        });

        // inspirational
        doit2(sheet, "7001", 118);

        // pillagebonus
        doit2(sheet, "8300", 187);

        // berserk
        doit2(sheet, "BE00", 139);

        // pathcost
        doit2(sheet, "F300", 45);

        // default startdom
        doit2(sheet, "F300", 46, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return "1";
            }
        });
        // startdom
        doit2(sheet, "F200", 46, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });

        // waterbreathing
        doit2(sheet, "6F00", 122);

        // batstartsum1
        doit2(sheet, "B401", 227);
        // batstartsum2
        doit2(sheet, "B501", 228);
        // batstartsum3
        doit2(sheet, "B601", 236);
        // batstartsum4
        doit2(sheet, "B701", 237);
        // batstartsum5
        doit2(sheet, "B801", 238);

        // batstartsum1d6
        doit2(sheet, "B901", 239);
        // batstartsum2d6
        doit2(sheet, "BA01", 240);
        // batstartsum3d6
        doit2(sheet, "BB01", 241);
        // batstartsum4d6
        doit2(sheet, "BC01", 242);
        // batstartsum5d6
        doit2(sheet, "BD01", 243);
        // batstartsum6d6
        doit2(sheet, "BE01", 244);

        // autosummon (#summon1-5)
        doit2(sheet, "F100,6B00,8F00", 225);
        doit2(sheet, "F100", 226, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return "?";
            }

            @Override
            public String notFound() {
                return null;
            }
        });
        doit2(sheet, "6B00", 226, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return "?";
            }

            @Override
            public String notFound() {
                return null;
            }
        });
        doit2(sheet, "8F00", 226, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return "?";
            }

            @Override
            public String notFound() {
                return null;
            }
        });
        doit2(sheet, "F100,6B00,8F00", 226, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return null;
            }
        });

        // domsummon
        doit2(sheet, "A101,DB00", 229);
        doit2(sheet, "A101", 230, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return "?";
            }

            @Override
            public String notFound() {
                return null;
            }
        });
        doit2(sheet, "DB00", 230, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return "?";
            }

            @Override
            public String notFound() {
                return null;
            }
        });
        doit2(sheet, "A101,DB00", 230, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return null;
            }
        });

        // turmoil summon
        doit2(sheet, "AD00", 245);

        // cold summon
        doit2(sheet, "9200", 246);

        // stormpower
        doit2(sheet, "AE00", 161);

        // firepower
        doit2(sheet, "B100", 162);

        // coldpower
        doit2(sheet, "B000", 163);

        // darkpower
        doit2(sheet, "2501", 164);

        // chaospower
        doit2(sheet, "A001", 165);

        // magicpower
        doit2(sheet, "4401", 166);

        // winterpower
        doit2(sheet, "EA00", 167);

        // springpower
        doit2(sheet, "E700", 168);

        // summerpower
        doit2(sheet, "E800", 169);

        // fallpower
        doit2(sheet, "E900", 170);

        // nametype
        doit2(sheet, "FB00", 219);

        // blind
        doit2(sheet, "AB00", 134, new CallbackAdapter() {
            @Override
            public String notFound() {
                return "0";
            }
        });

        // eyes
        doit2(sheet, "B200", 279, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return Integer.toString((Integer.parseInt(value) + 2));
            }
        });

        // supplybonus
        doit2(sheet, "7A00", 192);

        // slave
        doit2(sheet, "7C01", 116);

        // awe
        doit2(sheet, "6900", 136);

        // siegebonus
        doit2(sheet, "7D00", 190);

        // researchbonus
        doit2(sheet, "7900", 195);

        // chaosrec
        doit2(sheet, "CA01", 186);

        // invulnerability
        doit2(sheet, "7E01", 124);

        // iceprot
        doit2(sheet, "BF00", 123);

        // reinvigoration
        doit2(sheet, "7500", 34, new CallbackAdapter() {
            @Override
            public String notFound() {
                return "0";
            }
        });

        // ambidextrous
        doit2(sheet, "D900", 32, new CallbackAdapter() {
            @Override
            public String notFound() {
                return "0";
            }
        });

        // spy
        doit2(sheet, "D600", 102, new CallbackAdapter() {
            @Override
            public String notFound() {
                return "0";
            }
        });

        // scale walls
        doit2(sheet, "E301", 247);

        // dream seducer (succubus)
        doit2(sheet, "D200", 106, new CallbackAdapter() {
            @Override
            public String notFound() {
                return "0";
            }
        });

        // seduction
        doit2(sheet, "2A01", 105, new CallbackAdapter() {
            @Override
            public String notFound() {
                return "0";
            }
        });

        // assassin
        doit2(sheet, "D500", 103, new CallbackAdapter() {
            @Override
            public String notFound() {
                return "0";
            }
        });

        // explode on death
        doit2(sheet, "2901", 249);

        // taskmaster
        doit2(sheet, "7B01", 119);

        // unique
        doit2(sheet, "1301", 216, new CallbackAdapter() {
            @Override
            public String notFound() {
                return "0";
            }
        });

        // poisoncloud
        doit2(sheet, "6A00", 145);

        // startaff
        doit2(sheet, "B900", 250);

        // uwregen
        doit2(sheet, "DD00", 251);

        // patrolbonus
        doit2(sheet, "AA00", 188);

        // castledef
        doit2(sheet, "D700", 189);

        // sailsz
        doit2(sheet, "7000", 98, new CallbackAdapter() {
            @Override
            public String notFound() {
                return "0";
            }
        });

        // maxsailsz
        doit2(sheet, "9A01", 99);

        // incunrest
        doit2(sheet, "DF00", 193, new CallbackAdapter() {
            @Override
            public String found(String value) {
                double val = Double.parseDouble(value) / 10d;
                if (val < 1 && val > -1) {
                    return Double.toString(val);
                }
                return Integer.toString((int) val);
            }
        });

        // barbs
        doit2(sheet, "BC00", 153, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return "1";
            }

            @Override
            public String notFound() {
                return "0";
            }
        });

        // inn
        doit2(sheet, "4E01", 47);

        // stonebeing
        doit2(sheet, "1801", 80, new CallbackAdapter() {
            @Override
            public String notFound() {
                return "0";
            }
        });

        // shrinkhp
        doit2(sheet, "5001", 252);

        // growhp
        doit2(sheet, "4F01", 253);

        // transformation
        doit2(sheet, "FD01", 254);

        // heretic
        doit2(sheet, "B800", 206);

        // popkill
        doit2(sheet, "2001", 194, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return Integer.toString(Integer.parseInt(value) * 10);
            }
        });

        // autohealer
        doit2(sheet, "6201", 175);

        // fireshield
        doit2(sheet, "A300", 142);

        // startingaff
        doit2(sheet, "E200", 255);

        // fixedresearch
        doit2(sheet, "F800", 256);

        // divineins
        doit2(sheet, "C201", 257);

        // halt
        doit2(sheet, "4701", 137);

        // crossbreeder
        doit2(sheet, "AF01", 201);

        // reclimit
        doit2(sheet, "7D01", 14);

        // fixforgebonus
        doit2(sheet, "C501", 172);

        // mastersmith
        doit2(sheet, "6B01", 173);

        // lamiabonus
        doit2(sheet, "A900", 258);

        // homesick
        doit2(sheet, "FD00", 113);

        // banefireshield
        doit2(sheet, "DE00", 143);

        // animalawe
        doit2(sheet, "A200", 135);

        // autodishealer
        doit2(sheet, "6301", 176);

        // shatteredsoul
        doit2(sheet, "4801", 181);

        // voidsum
        doit2(sheet, "CE00", 205);

        // makepearls
        doit2(sheet, "AE01", 202);

        // inspiringres
        doit2(sheet, "5501", 197);

        // drainimmune
        doit2(sheet, "1101", 196);

        // diseasecloud
        doit2(sheet, "AC00", 146);

        // inquisitor
        doit2(sheet, "D300", 74, new CallbackAdapter() {
            @Override
            public String notFound() {
                return "0";
            }
        });

        // beastmaster
        doit2(sheet, "7101", 120);

        // douse
        doit2(sheet, "7400", 198);

        // preanimator
        doit2(sheet, "6C01", 259);

        // dreanimator
        doit2(sheet, "6D01", 260);

        // mummify
        doit2(sheet, "FF01", 261);

        // onebattlespell
        doit2(sheet, "D100", 262);

        // fireattuned
        doit2(sheet, "F501", 263);

        // airattuned
        doit2(sheet, "F601", 264);

        // waterattuned
        doit2(sheet, "F701", 265);

        // earthattuned
        doit2(sheet, "F801", 266);

        // astralattuned
        doit2(sheet, "F901", 267);

        // deathattuned
        doit2(sheet, "FA01", 268);

        // natureattuned
        doit2(sheet, "FB01", 269);

        // bloodattuned
        doit2(sheet, "FC01", 270);

        // magicboost F
        doit2(sheet, "0A00", 271);

        // magicboost A
        doit2(sheet, "0B00", 272);

        // magicboost W
        doit2(sheet, "0C00", 273);

        // magicboost E
        doit2(sheet, "0D00", 274);

        // magicboost S
        doit2(sheet, "0E00", 275);

        // magicboost D
        doit2(sheet, "0F00", 276);

        // magicboost N
        doit2(sheet, "1000", 277);

        // magicboost ALL
        doit2(sheet, "1600", 278);

        // heatrec
        doit2(sheet, "EA01", 280, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return "1";
            }
        });

        // coldrec
        doit2(sheet, "EB01", 281, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return "1";
            }
        });

        // spread chaos
        doit2(sheet, "D801", 282, new CallbackAdapter() {
            @Override
            public String found(String value) {
                if (value.equals("100")) {
                    return "1";
                }
                return "";
            }
        });

        // spread death
        doit2(sheet, "D801", 283, new CallbackAdapter() {
            @Override
            public String found(String value) {
                if (value.equals("103")) {
                    return "1";
                }
                return "";
            }
        });

        // corpseeater
        doit2(sheet, "EC00", 284);

        // poisonskin
        doit2(sheet, "0602", 285);

        // bug
        doit2(sheet, "AB01", 286);

        // uwbug
        doit2(sheet, "AC01", 287);

        // gemprod fire
        doit2(sheet, "1E00", 185, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return value + "F";
            }
        });

        // gemprod air
        doit2(sheet, "1F00", 185, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return value + "A";
            }

            @Override
            public String notFound() {
                return null;
            }
        }, true);

        // gemprod water
        doit2(sheet, "2000", 185, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return value + "W";
            }

            @Override
            public String notFound() {
                return null;
            }
        }, true);

        // gemprod earth
        doit2(sheet, "2100", 185, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return value + "E";
            }

            @Override
            public String notFound() {
                return null;
            }
        }, true);

        // gemprod astral
        doit2(sheet, "2200", 185, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return value + "S";
            }

            @Override
            public String notFound() {
                return null;
            }
        }, true);

        // gemprod death
        doit2(sheet, "2300", 185, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return value + "D";
            }

            @Override
            public String notFound() {
                return null;
            }
        }, true);

        // gemprod nature
        doit2(sheet, "2400", 185, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return value + "N";
            }

            @Override
            public String notFound() {
                return null;
            }
        }, true);

        // gemprod blood
        doit2(sheet, "2500", 185, new CallbackAdapter() {
            @Override
            public String found(String value) {
                return value + "B";
            }

            @Override
            public String notFound() {
                return null;
            }
        }, true);

        // itemslots
        doit2(sheet, "B600", 40, new CallbackAdapter() {
            // hand
            @Override
            public String found(String value) {
                int numHands = 0;
                int val = Integer.parseInt(value);
                if ((val & 0x0002) != 0) {
                    numHands++;
                }
                if ((val & 0x0004) != 0) {
                    numHands++;
                }
                if ((val & 0x0008) != 0) {
                    numHands++;
                }
                if ((val & 0x0010) != 0) {
                    numHands++;
                }
                return Integer.toString(numHands);
            }

            @Override
            public String notFound() {
                return null;
            }
        });
        doit2(sheet, "B600", 41, new CallbackAdapter() {
            // head
            @Override
            public String found(String value) {
                int numHeads = 0;
                int val = Integer.parseInt(value);
                if ((val & 0x0080) != 0) {
                    numHeads++;
                }
                if ((val & 0x0100) != 0) {
                    numHeads++;
                }
                if ((val & 0x0200) != 0) {
                    numHeads++;
                }
                return Integer.toString(numHeads);
            }

            @Override
            public String notFound() {
                return null;
            }
        });
        doit2(sheet, "B600", 42, new CallbackAdapter() {
            // body
            @Override
            public String found(String value) {
                int numBody = 0;
                int val = Integer.parseInt(value);
                if ((val & 0x0400) != 0) {
                    numBody++;
                }
                return Integer.toString(numBody);
            }

            @Override
            public String notFound() {
                return null;
            }
        });
        doit2(sheet, "B600", 43, new CallbackAdapter() {
            // foot
            @Override
            public String found(String value) {
                int numFoot = 0;
                int val = Integer.parseInt(value);
                if ((val & 0x0800) != 0) {
                    numFoot++;
                }
                return Integer.toString(numFoot);
            }

            @Override
            public String notFound() {
                return null;
            }
        });
        doit2(sheet, "B600", 44, new CallbackAdapter() {
            // misc
            @Override
            public String found(String value) {
                int numMisc = 0;
                int val = Integer.parseInt(value);
                if ((val & 0x1000) != 0) {
                    numMisc++;
                }
                if ((val & 0x2000) != 0) {
                    numMisc++;
                }
                if ((val & 0x4000) != 0) {
                    numMisc++;
                }
                if ((val & 0x8000) != 0) {
                    numMisc++;
                }
                if ((val & 0x10000) != 0) {
                    numMisc++;
                }
                return Integer.toString(numMisc);
            }

            @Override
            public String notFound() {
                return null;
            }
        });

        // startage
        doit2(sheet, "1D01", 38, new CallbackAdapter() {
            @Override
            public String found(String value) {
                int age = Integer.parseInt(value);
                if (age == -1) {
                    age = 0;
                }
                return Integer.toString((int) (age + age * .1));
            }

            @Override
            public String notFound() {
                return null;
            }
        });

        // maxage
        doit2(sheet, "1C01", 39, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });

        stream = new FileInputStream("Dominions4.exe");
        stream.skip(Starts.MONSTER_MAGIC);

        // magic
        c = new byte[4];
        while ((stream.read(c, 0, 4)) != -1) {
            String high = String.format("%02X", c[1]);
            String low = String.format("%02X", c[0]);
            if ((high + low).equals("FFFF")) {
                break;
            }
            int id = Integer.decode("0X" + high + low);
            Magic monMagic = monsterMagic.get(id);
            if (monMagic == null) {
                monMagic = new Magic();
                monsterMagic.put(id, monMagic);
            }

            //System.out.print("id: " + Integer.decode("0X" + high + low));
            stream.read(c, 0, 4);
            high = String.format("%02X", c[1]);
            low = String.format("%02X", c[0]);
            int path = Integer.decode("0X" + high + low);
            //System.out.print(" path: " + Integer.decode("0X" + high + low));
            stream.read(c, 0, 4);
            high = String.format("%02X", c[1]);
            low = String.format("%02X", c[0]);
            int value = Integer.decode("0X" + high + low);
            //System.out.println(" value: " + Integer.decode("0X" + high + low));
            switch (path) {
            case 0:
                monMagic.F = value;
                break;
            case 1:
                monMagic.A = value;
                break;
            case 2:
                monMagic.W = value;
                break;
            case 3:
                monMagic.E = value;
                break;
            case 4:
                monMagic.S = value;
                break;
            case 5:
                monMagic.D = value;
                break;
            case 6:
                monMagic.N = value;
                break;
            case 7:
                monMagic.B = value;
                break;
            case 8:
                monMagic.H = value;
                break;
            default:
                RandomMagic monRandomMagic = null;
                List<RandomMagic> randomMagicList = monMagic.rand;
                if (randomMagicList == null) {
                    randomMagicList = new ArrayList<RandomMagic>();
                    monRandomMagic = new RandomMagic();
                    if (path == 50) {
                        monRandomMagic.mask = 32640;
                        monRandomMagic.nbr = 1;
                        monRandomMagic.link = value;
                        monRandomMagic.rand = 100;
                    } else if (path == 51) {
                        monRandomMagic.mask = 1920;
                        monRandomMagic.nbr = 1;
                        monRandomMagic.link = value;
                        monRandomMagic.rand = 100;
                    } else {
                        monRandomMagic.mask = path;
                        monRandomMagic.nbr = 1;
                        if (value > 100) {
                            monRandomMagic.link = value / 100;
                            monRandomMagic.rand = 100;
                        } else {
                            monRandomMagic.link = 1;
                            monRandomMagic.rand = value;
                        }
                    }
                    randomMagicList.add(monRandomMagic);
                    monMagic.rand = randomMagicList;
                } else {
                    boolean found = false;
                    for (RandomMagic ranMagic : randomMagicList) {
                        if (ranMagic.mask == path && ranMagic.rand == value) {
                            ranMagic.nbr++;
                            found = true;
                        }
                        if (ranMagic.mask == 32640 && path == 50 && ranMagic.link == value) {
                            ranMagic.nbr++;
                            found = true;
                        }
                        if (ranMagic.mask == 1920 && path == 51 && ranMagic.link == value) {
                            ranMagic.nbr++;
                            found = true;
                        }
                    }
                    if (!found) {
                        monRandomMagic = new RandomMagic();
                        if (path == 50) {
                            monRandomMagic.mask = 32640;
                            monRandomMagic.nbr = 1;
                            monRandomMagic.link = value;
                            monRandomMagic.rand = 100;
                        } else if (path == 51) {
                            monRandomMagic.mask = 1920;
                            monRandomMagic.nbr = 1;
                            monRandomMagic.link = value;
                            monRandomMagic.rand = 100;
                        } else {
                            monRandomMagic.mask = path;
                            monRandomMagic.nbr = 1;
                            if (value > 100) {
                                monRandomMagic.link = value / 100;
                                monRandomMagic.rand = 100;
                            } else {
                                monRandomMagic.link = 1;
                                monRandomMagic.rand = value;
                            }
                        }
                        randomMagicList.add(monRandomMagic);
                    }
                }
            }
        }
        for (int j = 1; j < Starts.MONSTER_COUNT; j++) {
            Magic monMagic = monsterMagic.get(j);
            if (monMagic != null) {
                XSSFRow row = sheet.getRow(j);
                XSSFCell cell = row.getCell(48, Row.CREATE_NULL_AS_BLANK);
                cell.setCellValue(magicStrip(monMagic.F));
                cell = row.getCell(49, Row.CREATE_NULL_AS_BLANK);
                cell.setCellValue(magicStrip(monMagic.A));
                cell = row.getCell(50, Row.CREATE_NULL_AS_BLANK);
                cell.setCellValue(magicStrip(monMagic.W));
                cell = row.getCell(51, Row.CREATE_NULL_AS_BLANK);
                cell.setCellValue(magicStrip(monMagic.E));
                cell = row.getCell(52, Row.CREATE_NULL_AS_BLANK);
                cell.setCellValue(magicStrip(monMagic.S));
                cell = row.getCell(53, Row.CREATE_NULL_AS_BLANK);
                cell.setCellValue(magicStrip(monMagic.D));
                cell = row.getCell(54, Row.CREATE_NULL_AS_BLANK);
                cell.setCellValue(magicStrip(monMagic.N));
                cell = row.getCell(55, Row.CREATE_NULL_AS_BLANK);
                cell.setCellValue(magicStrip(monMagic.B));
                cell = row.getCell(56, Row.CREATE_NULL_AS_BLANK);
                cell.setCellValue(magicStrip(monMagic.H));
                //System.out.print(magout(monMagic.F) + magout(monMagic.A ) + magout(monMagic.W) + magout(monMagic.E) + magout(monMagic.S) + magout(monMagic.D) + magout(monMagic.N) + magout(monMagic.B) + magout(monMagic.H));

                if (monMagic.rand != null) {
                    int count = 0;
                    for (RandomMagic ranMag : monMagic.rand) {
                        cell = row.getCell(57 + count * 4, Row.CREATE_NULL_AS_BLANK);
                        cell.setCellValue(magicStrip(ranMag.rand));
                        cell = row.getCell(58 + count * 4, Row.CREATE_NULL_AS_BLANK);
                        cell.setCellValue(magicStrip(ranMag.nbr));
                        cell = row.getCell(59 + count * 4, Row.CREATE_NULL_AS_BLANK);
                        cell.setCellValue(magicStrip(ranMag.link));
                        cell = row.getCell(60 + count * 4, Row.CREATE_NULL_AS_BLANK);
                        cell.setCellValue(magicStrip(ranMag.mask));
                        count++;
                        //System.out.print(ranMag.rand + "\t" + ranMag.nbr + "\t" + ranMag.link + "\t" + ranMag.mask + "\t");
                    }
                }
            }
            //System.out.println("");
        }
        stream.close();

        wb.write(fos);
        fos.close();

        for (String col : columnsUsed.values()) {
            System.out.println(col);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:ItemStatIndexer.java

License:Open Source License

private static void doit(XSSFSheet sheet, String attr, int column, Callback callback) throws IOException {
    columnsUsed.remove(column);/*from  w ww . ja va2 s  .c  o  m*/

    FileInputStream stream = new FileInputStream("Dominions4.exe");
    stream.skip(Starts.ITEM);
    int rowNumber = 1;
    int i = 0;
    int k = 0;
    int pos = -1;
    long numFound = 0;
    byte[] c = new byte[2];
    stream.skip(120);
    while ((stream.read(c, 0, 2)) != -1) {
        String high = String.format("%02X", c[1]);
        String low = String.format("%02X", c[0]);
        int weapon = Integer.decode("0X" + high + low);
        if (weapon == 0) {
            boolean found = false;
            int value = 0;
            stream.skip(18l - numFound * 2l);
            // Values
            for (int x = 0; x < numFound; x++) {
                byte[] d = new byte[4];
                stream.read(d, 0, 4);
                String high1 = String.format("%02X", d[3]);
                String low1 = String.format("%02X", d[2]);
                high = String.format("%02X", d[1]);
                low = String.format("%02X", d[0]);
                if (x == pos) {
                    value = new BigInteger(high1 + low1 + high + low, 16).intValue();
                    //System.out.print(value);
                    found = true;
                }
                //stream.skip(2);
            }

            //System.out.println("");
            XSSFRow row = sheet.getRow(rowNumber);
            rowNumber++;
            XSSFCell cell = row.getCell(column, Row.CREATE_NULL_AS_BLANK);
            if (found) {
                if (callback == null) {
                    cell.setCellValue(value);
                } else {
                    if (callback.found(Integer.toString(value)) != null) {
                        cell.setCellValue(callback.found(Integer.toString(value)));
                    }
                }
            } else {
                if (callback == null) {
                    cell.setCellValue("");
                } else {
                    if (callback.notFound() != null) {
                        cell.setCellValue(callback.notFound());
                    }
                }
            }
            stream.skip(206l - 18l - numFound * 4l);
            numFound = 0;
            pos = -1;
            k = 0;
            i++;
        } else {
            //System.out.print(low + high + " ");
            if ((low + high).equals(attr)) {
                pos = k;
            }
            k++;
            numFound++;
        }
        if (i >= Starts.ITEM_COUNT) {
            break;
        }
    }
    stream.close();

}

From source file:ItemStatIndexer.java

License:Open Source License

public static void run() {
    FileInputStream stream = null;
    try {//from   ww w  .  ja v  a  2s  . com
        long startIndex = Starts.ITEM;
        int ch;

        stream = new FileInputStream("Dominions4.exe");
        stream.skip(startIndex);

        XSSFWorkbook wb = ItemStatIndexer.readFile("BaseI.xlsx");
        FileOutputStream fos = new FileOutputStream("NewBaseI.xlsx");
        XSSFSheet sheet = wb.getSheetAt(0);

        XSSFRow titleRow = sheet.getRow(0);
        int cellNum = 0;
        XSSFCell titleCell = titleRow.getCell(cellNum);
        Set<String> skip = new HashSet<String>(Arrays.asList(SkipColumns));
        while (titleCell != null) {
            String stringCellValue = titleCell.getStringCellValue();
            if (!skip.contains(stringCellValue)) {
                columnsUsed.put(cellNum, stringCellValue);
            }
            cellNum++;
            titleCell = titleRow.getCell(cellNum);
        }

        // Name
        InputStreamReader isr = new InputStreamReader(stream, "ISO-8859-1");
        Reader in = new BufferedReader(isr);
        int rowNumber = 1;
        while ((ch = in.read()) > -1) {
            StringBuffer name = new StringBuffer();
            while (ch != 0) {
                name.append((char) ch);
                ch = in.read();
            }
            if (name.length() == 0) {
                continue;
            }
            if (name.toString().equals("end")) {
                break;
            }
            in.close();

            stream = new FileInputStream("Dominions4.exe");
            startIndex = startIndex + 208l;
            stream.skip(startIndex);
            isr = new InputStreamReader(stream, "ISO-8859-1");
            in = new BufferedReader(isr);

            //System.out.println(name);

            XSSFRow row = sheet.getRow(rowNumber);
            XSSFCell cell1 = row.getCell(0, Row.CREATE_NULL_AS_BLANK);
            cell1.setCellValue(rowNumber);
            rowNumber++;
            XSSFCell cell = row.getCell(1, Row.CREATE_NULL_AS_BLANK);
            cell.setCellValue(name.toString());
        }
        in.close();
        stream.close();

        stream = new FileInputStream("Dominions4.exe");
        stream.skip(Starts.ITEM);
        rowNumber = 1;
        // Const level
        int i = 0;
        byte[] c = new byte[1];
        stream.skip(36);
        while ((stream.read(c, 0, 1)) != -1) {
            XSSFRow row = sheet.getRow(rowNumber);
            rowNumber++;
            XSSFCell cell = row.getCell(3, Row.CREATE_NULL_AS_BLANK);
            if (c[0] == -1) {
                //System.out.println("");
                cell.setCellValue("");
            } else {
                //System.out.println(c[0]*2);
                cell.setCellValue(c[0] * 2);
            }
            stream.skip(207l);
            i++;
            if (i >= Starts.ITEM_COUNT) {
                break;
            }
        }
        stream.close();

        stream = new FileInputStream("Dominions4.exe");
        stream.skip(Starts.ITEM);
        rowNumber = 1;
        // Mainpath
        String[] paths = { "F", "A", "W", "E", "S", "D", "N", "B" };
        i = 0;
        c = new byte[1];
        stream.skip(37);
        while ((stream.read(c, 0, 1)) != -1) {
            XSSFRow row = sheet.getRow(rowNumber);
            rowNumber++;
            XSSFCell cell = row.getCell(4, Row.CREATE_NULL_AS_BLANK);
            if (c[0] == -1) {
                //System.out.println("");
                cell.setCellValue("");
            } else {
                //System.out.println(paths[c[0]]);
                cell.setCellValue(paths[c[0]]);
            }
            stream.skip(207l);
            i++;
            if (i >= Starts.ITEM_COUNT) {
                break;
            }
        }
        stream.close();

        stream = new FileInputStream("Dominions4.exe");
        stream.skip(Starts.ITEM);
        rowNumber = 1;
        // main level
        i = 0;
        c = new byte[1];
        stream.skip(39);
        while ((stream.read(c, 0, 1)) != -1) {
            XSSFRow row = sheet.getRow(rowNumber);
            rowNumber++;
            XSSFCell cell = row.getCell(5, Row.CREATE_NULL_AS_BLANK);
            if (c[0] == -1) {
                //System.out.println("");
                cell.setCellValue("");
            } else {
                //System.out.println(c[0]);
                cell.setCellValue(c[0]);
            }
            stream.skip(207l);
            i++;
            if (i >= Starts.ITEM_COUNT) {
                break;
            }
        }
        stream.close();

        stream = new FileInputStream("Dominions4.exe");
        stream.skip(Starts.ITEM);
        rowNumber = 1;
        // Secondary path
        i = 0;
        c = new byte[1];
        stream.skip(38);
        while ((stream.read(c, 0, 1)) != -1) {
            XSSFRow row = sheet.getRow(rowNumber);
            rowNumber++;
            XSSFCell cell = row.getCell(6, Row.CREATE_NULL_AS_BLANK);
            if (c[0] == -1) {
                //System.out.println("");
                cell.setCellValue("");
            } else {
                //System.out.println(paths[c[0]]);
                cell.setCellValue(paths[c[0]]);
            }
            stream.skip(207l);
            i++;
            if (i >= Starts.ITEM_COUNT) {
                break;
            }
        }
        stream.close();

        stream = new FileInputStream("Dominions4.exe");
        stream.skip(Starts.ITEM);
        rowNumber = 1;
        // Secondary level
        i = 0;
        c = new byte[1];
        stream.skip(40);
        while ((stream.read(c, 0, 1)) != -1) {
            XSSFRow row = sheet.getRow(rowNumber);
            rowNumber++;
            XSSFCell cell = row.getCell(7, Row.CREATE_NULL_AS_BLANK);
            if (c[0] == -1 || c[0] == 0) {
                //System.out.println("");
                cell.setCellValue("");
            } else {
                //System.out.println(c[0]);
                cell.setCellValue(c[0]);
            }
            stream.skip(207l);
            i++;
            if (i >= Starts.ITEM_COUNT) {
                break;
            }
        }
        stream.close();

        stream = new FileInputStream("Dominions4.exe");
        stream.skip(Starts.ITEM);
        rowNumber = 1;
        // Weapon
        i = 0;
        c = new byte[2];
        stream.skip(44);
        while ((stream.read(c, 0, 2)) != -1) {
            XSSFRow row = sheet.getRow(rowNumber);
            rowNumber++;
            XSSFCell cell = row.getCell(8, Row.CREATE_NULL_AS_BLANK);
            String high = String.format("%02X", c[1]);
            String low = String.format("%02X", c[0]);
            int weapon = Integer.decode("0X" + high + low);
            if (weapon == 0) {
                //System.out.println("");
                cell.setCellValue("");
            } else {
                //System.out.println(Integer.decode("0X" + high + low));
                cell.setCellValue(Integer.decode("0X" + high + low));
            }
            stream.skip(206l);
            i++;
            if (i >= Starts.ITEM_COUNT) {
                break;
            }
        }
        stream.close();

        stream = new FileInputStream("Dominions4.exe");
        stream.skip(Starts.ITEM);
        rowNumber = 1;
        // Armor
        i = 0;
        c = new byte[2];
        stream.skip(46);
        while ((stream.read(c, 0, 2)) != -1) {
            XSSFRow row = sheet.getRow(rowNumber);
            rowNumber++;
            XSSFCell cell = row.getCell(9, Row.CREATE_NULL_AS_BLANK);
            String high = String.format("%02X", c[1]);
            String low = String.format("%02X", c[0]);
            int weapon = Integer.decode("0X" + high + low);
            if (weapon == 0) {
                //System.out.println("");
                cell.setCellValue("");
            } else {
                //System.out.println(Integer.decode("0X" + high + low));
                cell.setCellValue(Integer.decode("0X" + high + low));
            }
            stream.skip(206l);
            i++;
            if (i >= Starts.ITEM_COUNT) {
                break;
            }
        }
        stream.close();

        stream = new FileInputStream("Dominions4.exe");
        stream.skip(Starts.ITEM);
        rowNumber = 1;
        startIndex = Starts.ITEM;
        // Itemspell
        stream.skip(48);
        startIndex = startIndex + 48l;
        i = 0;
        isr = new InputStreamReader(stream, "ISO-8859-1");
        in = new BufferedReader(isr);
        while ((ch = in.read()) > -1) {
            StringBuffer name = new StringBuffer();
            while (ch != 0) {
                name.append((char) ch);
                ch = in.read();
            }
            in.close();

            stream = new FileInputStream("Dominions4.exe");
            startIndex = startIndex + 208l;
            stream.skip(startIndex);
            isr = new InputStreamReader(stream, "ISO-8859-1");
            in = new BufferedReader(isr);

            //System.out.println(name);
            XSSFRow row = sheet.getRow(rowNumber);
            rowNumber++;
            XSSFCell cell = row.getCell(130, Row.CREATE_NULL_AS_BLANK);
            cell.setCellValue(name.toString());
            i++;
            if (i >= Starts.ITEM_COUNT) {
                break;
            }
        }
        in.close();
        stream.close();

        stream = new FileInputStream("Dominions4.exe");
        stream.skip(Starts.ITEM);
        rowNumber = 1;
        startIndex = Starts.ITEM;
        // Startbattlespell and Autocombatspell
        stream.skip(84);
        startIndex = startIndex + 84l;
        i = 0;
        isr = new InputStreamReader(stream, "ISO-8859-1");
        in = new BufferedReader(isr);
        while ((ch = in.read()) > -1) {
            StringBuffer name = new StringBuffer();
            while (ch != 0) {
                name.append((char) ch);
                ch = in.read();
            }
            in.close();

            int blankCol = 129;
            int column = 128;
            if (hasAttr("8500", startIndex + 36l)) {
                column = 129;
                blankCol = 128;
            }
            stream = new FileInputStream("Dominions4.exe");
            startIndex = startIndex + 208l;
            stream.skip(startIndex);
            isr = new InputStreamReader(stream, "ISO-8859-1");
            in = new BufferedReader(isr);

            //System.out.println(name);
            XSSFRow row = sheet.getRow(rowNumber);
            rowNumber++;
            XSSFCell cell = row.getCell(column, Row.CREATE_NULL_AS_BLANK);
            cell.setCellValue(name.toString());
            XSSFCell blankcell = row.getCell(blankCol, Row.CREATE_NULL_AS_BLANK);
            blankcell.setCellValue("");
            i++;
            if (i >= Starts.ITEM_COUNT) {
                break;
            }
        }
        in.close();
        stream.close();

        // Fireres
        doit(sheet, "C600", 11);

        // Coldres
        doit(sheet, "C900", 12);

        // Poisonres
        doit(sheet, "C800", 13);

        // Shockres
        doit(sheet, "C700", 10);

        // Leadership
        doit(sheet, "9D00", 61);

        // str
        doit(sheet, "9700", 28);

        // fixforge
        doit(sheet, "C501", 18);

        // magic leadership
        doit(sheet, "9E00", 63);

        // undead leadership
        doit(sheet, "9F00", 62);

        // inspirational leadership
        doit(sheet, "7001", 64);

        // morale
        doit(sheet, "3401", 27);

        // penetration
        doit(sheet, "A100", 36);

        // pillage
        doit(sheet, "8300", 113);

        // fear
        doit(sheet, "B700", 66);

        // mr
        doit(sheet, "A000", 26);

        // taint
        doit(sheet, "0601", 60);

        // reinvigoration
        doit(sheet, "7500", 35);

        // awe
        doit(sheet, "6900", 67);

        // F
        doit(sheet, "0A00", 73);

        // A
        doit(sheet, "0B00", 74);

        // W
        doit(sheet, "0C00", 75);

        // E
        doit(sheet, "0D00", 76);

        // S
        doit(sheet, "0E00", 77);

        // D
        doit(sheet, "0F00", 78);

        // N
        doit(sheet, "1000", 79);

        // B
        doit(sheet, "1100", 80);

        // H
        doit(sheet, "1200", 81);

        // elemental
        doit(sheet, "1400", 73, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1400", 74, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1400", 75, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1400", 76, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });

        // sorcery
        doit(sheet, "1500", 77, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1500", 78, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1500", 79, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1500", 80, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });

        // all paths
        doit(sheet, "1600", 73, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1600", 74, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1600", 75, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1600", 76, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1600", 77, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1600", 78, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1600", 79, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1600", 80, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });

        // fire ritual range
        doit(sheet, "2800", 82);

        // air ritual range
        doit(sheet, "2900", 83);

        // water ritual range
        doit(sheet, "2A00", 84);

        // earth ritual range
        doit(sheet, "2B00", 85);

        // astral ritual range
        doit(sheet, "2C00", 86);

        // death ritual range
        doit(sheet, "2D00", 87);

        // nature ritual range
        doit(sheet, "2E00", 88);

        // blood ritual range
        doit(sheet, "2F00", 89);

        // elemental range
        doit(sheet, "1700", 82, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1700", 83, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1700", 84, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1700", 85, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });

        // sorcery range
        doit(sheet, "1800", 86, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1800", 87, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1800", 88, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1800", 89, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });

        // all range
        doit(sheet, "1900", 82, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1900", 83, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1900", 84, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1900", 85, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1900", 86, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1900", 87, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1900", 88, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "1900", 89, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });

        // darkvision
        doit(sheet, "1901", 14);

        // limited regeneration
        doit(sheet, "CE01", 16);

        // regeneration
        doit(sheet, "BD00", 141);

        // waterbreathing
        doit(sheet, "6E00", 47);

        // airbreathing
        doit(sheet, "8100", 49);

        // stealthb
        doit(sheet, "8601", 38);

        // stealth
        doit(sheet, "6C00", 37);

        // att
        doit(sheet, "9600", 29);

        // def
        doit(sheet, "7901", 30);

        // woundfend
        doit(sheet, "9601", 17);

        // berserk
        doit(sheet, "BE00", 106);

        // aging
        doit(sheet, "2F01", 145);

        // ivylord
        doit(sheet, "6500", 126);

        // forest
        doit(sheet, "A601", 39);

        // waste
        doit(sheet, "A701", 41);

        // mount
        doit(sheet, "A501", 40);

        // swamp
        doit(sheet, "A801", 42);

        // researchbonus
        doit(sheet, "7900", 118);

        // gitfofwater
        doit(sheet, "6F00", 48);

        // corpselord
        doit(sheet, "9A00", 146);

        // lictorlord
        doit(sheet, "6600", 147);

        // sumauto
        doit(sheet, "8B00", 134);

        // bloodsac
        doit(sheet, "D800", 148);

        // mastersmith
        doit(sheet, "6B01", 149);

        // alch
        doit(sheet, "8400", 21);

        // eyeloss
        doit(sheet, "7E00", 150);

        // armysize
        doit(sheet, "A301", 151);

        // defender
        doit(sheet, "8900", 152);

        // Hack for Forbidden Light
        doit(sheet, "7700", 73, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }

            @Override
            public String found(String value) {
                return "2";
            }
        });
        doit(sheet, "7700", 77, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }

            @Override
            public String found(String value) {
                return "2";
            }
        });

        // cannotwear
        doit(sheet, "C701", 153, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });
        doit(sheet, "C801", 153, new CallbackAdapter() {
            @Override
            public String notFound() {
                return null;
            }
        });

        // sailsz
        doit(sheet, "7000", 45);

        // maxsail
        doit(sheet, "9A01", 46);

        // flytr
        doit(sheet, "7100", 50);

        // protf
        doit(sheet, "7F01", 24);

        // heretic
        doit(sheet, "B800", 119);

        // autodishealer
        doit(sheet, "6301", 19);

        // patrolbonus
        doit(sheet, "AA00", 114);

        // prec
        doit(sheet, "B500", 31);

        // tmpfiregems
        doit(sheet, "5801", 90);
        // tmpairgems
        doit(sheet, "5901", 91);
        // tmpwatergems
        doit(sheet, "5A01", 92);
        // tmpearthgems
        doit(sheet, "5B01", 93);
        // tmpastralgems
        doit(sheet, "5C01", 94);
        // tmpdeathgems
        doit(sheet, "5D01", 95);
        // tmpnaturegems
        doit(sheet, "5E01", 96);
        // tmpbloodgems
        doit(sheet, "5F01", 97);

        // healer
        doit(sheet, "6201", 20);

        // supplybonus
        doit(sheet, "7A00", 117);

        // mapspeed
        doit(sheet, "A901", 33);

        // restricted
        stream = new FileInputStream("Dominions4.exe");
        stream.skip(Starts.ITEM);
        i = 0;
        int k = 0;
        Set<Integer> posSet = new HashSet<Integer>();
        long numFound = 0;
        c = new byte[2];
        stream.skip(120);
        while ((stream.read(c, 0, 2)) != -1) {
            String high = String.format("%02X", c[1]);
            String low = String.format("%02X", c[0]);
            int weapon = Integer.decode("0X" + high + low);
            if (weapon == 0) {
                stream.skip(18l - numFound * 2l);
                int numRealms = 0;
                // Values
                for (int x = 0; x < numFound; x++) {
                    byte[] d = new byte[4];
                    stream.read(d, 0, 4);
                    String high1 = String.format("%02X", d[3]);
                    String low1 = String.format("%02X", d[2]);
                    high = String.format("%02X", d[1]);
                    low = String.format("%02X", d[0]);
                    //System.out.print(low + high + " ");
                    if (posSet.contains(x)) {
                        int fire = new BigInteger(high1 + low1 + high + low, 16).intValue();//Integer.decode("0X" + high + low);
                        //System.out.print(i+1 + "\t" + fire);
                        //System.out.println("");
                        XSSFRow row = sheet.getRow(i + 1);
                        XSSFCell cell = row.getCell(142 + numRealms, Row.CREATE_NULL_AS_BLANK);
                        cell.setCellValue(fire - 100);
                        numRealms++;
                    }
                    //stream.skip(2);
                }

                //               System.out.println("");
                stream.skip(206l - 18l - numFound * 4l);
                numFound = 0;
                posSet.clear();
                k = 0;
                i++;
            } else {
                //System.out.print(low + high + " ");
                if ((low + high).equals("1601")) {
                    posSet.add(k);
                }
                k++;
                numFound++;
            }
            if (i >= Starts.ITEM_COUNT) {
                break;
            }
        }
        stream.close();

        // Large bitmap
        for (String[] pair : DOTHESE) {
            columnsUsed.remove(Integer.parseInt(pair[1]));
            rowNumber = 1;
            boolean[] boolArray = largeBitmap(pair[0]);
            for (boolean found : boolArray) {
                XSSFRow row = sheet.getRow(rowNumber);
                rowNumber++;
                XSSFCell cell = row.getCell(Integer.parseInt(pair[1]), Row.CREATE_NULL_AS_BLANK);
                if (found) {
                    if (pair[0].equals("airshield")) {
                        cell.setCellValue(80);
                    } else {
                        cell.setCellValue(1);
                    }
                } else {
                    cell.setCellValue("");
                }
            }
        }

        stream = new FileInputStream("Dominions4.exe");
        stream.skip(Starts.ITEM);
        i = 0;
        c = new byte[24];
        stream.skip(184);
        while ((stream.read(c, 0, 24)) != -1) {
            boolean found = false;
            System.out.print("(" + (i + 1) + ") ");
            String high = String.format("%02X", c[1]);
            String low = String.format("%02X", c[0]);
            //System.out.print(high + low + " ");
            int val = Integer.decode("0X" + high + low);
            if (val > 0) {
                System.out.print("1:{");
                for (int j = 0; j < 16; j++) {
                    if ((val & MASK[j]) != 0) {
                        System.out.print((found ? "," : "")
                                + (value1[j].equals("") ? ("*****" + (j + 1) + "*****") : value1[j]));
                        found = true;
                    }
                }
                System.out.print("}");
            }
            high = String.format("%02X", c[3]);
            low = String.format("%02X", c[2]);
            //System.out.print(high + low + " ");
            val = Integer.decode("0X" + high + low);
            if (val > 0) {
                System.out.print(" 2:{");
                found = false;
                for (int j = 0; j < 16; j++) {
                    if ((val & MASK[j]) != 0) {
                        System.out.print((found ? "," : "")
                                + (value2[j].equals("") ? ("*****" + (j + 1) + "*****") : value2[j]));
                        found = true;
                    }
                }
                System.out.print("}");
            }
            high = String.format("%02X", c[5]);
            low = String.format("%02X", c[4]);
            //System.out.print(high + low + " ");
            val = Integer.decode("0X" + high + low);
            if (val > 0) {
                System.out.print(" 3:{");
                found = false;
                for (int j = 0; j < 16; j++) {
                    if ((val & MASK[j]) != 0) {
                        System.out.print((found ? "," : "")
                                + (value3[j].equals("") ? ("*****" + (j + 1) + "*****") : value3[j]));
                        found = true;
                    }
                }
                System.out.print("}");
            }

            high = String.format("%02X", c[7]);
            low = String.format("%02X", c[6]);
            //System.out.print(high + low + " ");
            val = Integer.decode("0X" + high + low);
            if (val > 0) {
                System.out.print(" 4:{");
                found = false;
                for (int j = 0; j < 16; j++) {
                    if ((val & MASK[j]) != 0) {
                        System.out.print((found ? "," : "")
                                + (value4[j].equals("") ? ("*****" + (j + 1) + "*****") : value4[j]));
                        found = true;
                    }
                }
                System.out.print("}");
            }

            high = String.format("%02X", c[9]);
            low = String.format("%02X", c[8]);
            //System.out.print(high + low + " ");
            val = Integer.decode("0X" + high + low);
            if (val > 0) {
                System.out.print(" 5:{");
                found = false;
                for (int j = 0; j < 16; j++) {
                    if ((val & MASK[j]) != 0) {
                        System.out.print((found ? "," : "")
                                + (value5[j].equals("") ? ("*****" + (j + 1) + "*****") : value5[j]));
                        found = true;
                    }
                }
                System.out.print("}");
            }
            high = String.format("%02X", c[11]);
            low = String.format("%02X", c[10]);
            //System.out.print(high + low + " ");
            val = Integer.decode("0X" + high + low);
            if (val > 0) {
                System.out.print(" 6:{");
                found = false;
                for (int j = 0; j < 16; j++) {
                    if ((val & MASK[j]) != 0) {
                        System.out.print((found ? "," : "")
                                + (value6[j].equals("") ? ("*****" + (j + 1) + "*****") : value6[j]));
                        found = true;
                    }
                }
                System.out.print("}");
            }
            high = String.format("%02X", c[13]);
            low = String.format("%02X", c[12]);
            //System.out.print(high + low + " ");
            val = Integer.decode("0X" + high + low);
            if (val > 0) {
                System.out.print(" 7:{");
                found = false;
                for (int j = 0; j < 16; j++) {
                    if ((val & MASK[j]) != 0) {
                        System.out.print((found ? "," : "")
                                + (value7[j].equals("") ? ("*****" + (j + 1) + "*****") : value7[j]));
                        found = true;
                    }
                }
                System.out.print("}");
            }
            high = String.format("%02X", c[15]);
            low = String.format("%02X", c[14]);
            //System.out.print(high + low + " ");
            val = Integer.decode("0X" + high + low);
            if (val > 0) {
                System.out.print(" 8:{");
                found = false;
                for (int j = 0; j < 16; j++) {
                    if ((val & MASK[j]) != 0) {
                        System.out.print((found ? "," : "")
                                + (value8[j].equals("") ? ("*****" + (j + 1) + "*****") : value8[j]));
                        found = true;
                    }
                }
                System.out.print("}");
            }
            high = String.format("%02X", c[17]);
            low = String.format("%02X", c[16]);
            //System.out.print(high + low + " ");
            val = Integer.decode("0X" + high + low);
            if (val > 0) {
                System.out.print(" 9:{");
                found = false;
                for (int j = 0; j < 16; j++) {
                    if ((val & MASK[j]) != 0) {
                        System.out.print((found ? "," : "")
                                + (value9[j].equals("") ? ("*****" + (j + 1) + "*****") : value9[j]));
                        found = true;
                    }
                }
                System.out.print("}");
            }
            high = String.format("%02X", c[19]);
            low = String.format("%02X", c[18]);
            //System.out.print(high + low + " ");
            val = Integer.decode("0X" + high + low);
            if (val > 0) {
                System.out.print(" 10:{");
                found = false;
                for (int j = 0; j < 16; j++) {
                    if ((val & MASK[j]) != 0) {
                        System.out.print((found ? "," : "")
                                + (value10[j].equals("") ? ("*****" + (j + 1) + "*****") : value10[j]));
                        found = true;
                    }
                }
                System.out.print("}");
            }
            high = String.format("%02X", c[21]);
            low = String.format("%02X", c[20]);
            //System.out.print(high + low + " ");
            val = Integer.decode("0X" + high + low);
            if (val > 0) {
                System.out.print(" 11:{");
                found = false;
                for (int j = 0; j < 16; j++) {
                    if ((val & MASK[j]) != 0) {
                        System.out.print((found ? "," : "")
                                + (value11[j].equals("") ? ("*****" + (j + 1) + "*****") : value11[j]));
                        found = true;
                    }
                }
                System.out.print("}");
            }
            high = String.format("%02X", c[23]);
            low = String.format("%02X", c[22]);
            //System.out.print(high + low + " ");
            val = Integer.decode("0X" + high + low);
            if (val > 0) {
                System.out.print(" 12:{");
                found = false;
                for (int j = 0; j < 16; j++) {
                    if ((val & MASK[j]) != 0) {
                        System.out.print((found ? "," : "")
                                + (value12[j].equals("") ? ("*****" + (j + 1) + "*****") : value12[j]));
                        found = true;
                    }
                }
                System.out.print("}");
            }

            if (!found) {
                //System.out.println("");
            }
            System.out.println(" ");
            stream.skip(184l);
            i++;
            if (i >= Starts.ITEM_COUNT) {
                break;
            }
        }
        stream.close();

        wb.write(fos);
        fos.close();

        for (String col : columnsUsed.values()) {
            System.out.println(col);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:accounts.ExcelUtils.java

License:Apache License

public Map<String, Map<TRId, TR>> processAllSheets(String filename, Map<String, BankAccount> baMap,
        String accountName) throws IOException, DBException {
    Map<String, Map<TRId, TR>> excelTrMap = new TreeMap<>();
    FileInputStream file = new FileInputStream(new File(filename));

    // Get the workbook instance for XLS file
    XSSFWorkbook workbook = new XSSFWorkbook(file);
    for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
        XSSFSheet sheet = workbook.getSheetAt(i);
        String sheetName = workbook.getSheetName(i);
        if ("RentalSummary".equalsIgnoreCase(sheetName) || "CompanySummary".equalsIgnoreCase(sheetName)
                || "PersonalSummary".equalsIgnoreCase(sheetName)) {
            continue;
        }//from   www  .j a  v a2 s.c om
        if (accountName != null && !accountName.equalsIgnoreCase(sheetName)) {
            continue;
        }
        Map<TRId, TR> mapTr = new HashMap<>();
        excelTrMap.put(sheetName, mapTr);
        System.out.println("Processing sheet: " + sheetName);
        BankAccount ba = baMap.get(sheetName);
        if (ba == null) {
            throw new IOException("Unknown bank account name in excel=" + sheetName);
        }

        for (int rownum = 1; rownum <= sheet.getLastRowNum(); rownum++) {
            Row row = sheet.getRow(rownum);

            // Get iterator to all cells of current row

            TR tr = DBFactory.inst().createCorrespondingTRObj(ba);
            tr.setDate(row.getCell(0).getDateCellValue());
            tr.setDescription(row.getCell(1).getStringCellValue());
            tr.setDebit((float) row.getCell(2).getNumericCellValue());
            tr.setComment(row.getCell(3).getStringCellValue());
            tr.setTrType(row.getCell(4).getStringCellValue());
            tr.setTaxCategory(row.getCell(5).getStringCellValue());
            tr.setProperty(row.getCell(6).getStringCellValue());
            tr.setOtherEntity(row.getCell(7).getStringCellValue());
            String locked = row.getCell(8).getStringCellValue();
            tr.setLocked("YES".equalsIgnoreCase(locked));
            tr.setTrId();
            mapTr.put(tr.getTrId(), tr);

        }
    }
    return excelTrMap;

}

From source file:accounts.ExcelUtils.java

License:Apache License

public Map<String, Map<TRId, TR>> processAllSheets(String filename) throws IOException {
    Map<String, Map<TRId, TR>> excelTrMap = new TreeMap<>();
    FileInputStream file = new FileInputStream(new File(filename));

    // Get the workbook instance for XLS file
    XSSFWorkbook workbook = new XSSFWorkbook(file);
    for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
        XSSFSheet sheet = workbook.getSheetAt(i);
        String sheetName = workbook.getSheetName(i);
        Map<TRId, TR> mapTr = new HashMap<>();
        excelTrMap.put(sheetName, mapTr);
        System.out.println("Processing sheet: " + sheetName);

        // Get iterator to all the rows in current sheet
        Iterator<Row> rowIterator = sheet.iterator();

        for (int rownum = 1; rownum <= sheet.getLastRowNum(); rownum++) {
            Row row = sheet.getRow(rownum);

            // Get iterator to all cells of current row

            TR tr = new TRNonDB();
            tr.setDate(row.getCell(0).getDateCellValue());
            tr.setDescription(row.getCell(1).getStringCellValue());
            tr.setDebit((float) row.getCell(2).getNumericCellValue());
            tr.setComment(row.getCell(3).getStringCellValue());
            tr.setTrType(row.getCell(4).getStringCellValue());
            tr.setTaxCategory(row.getCell(5).getStringCellValue());
            tr.setProperty(row.getCell(6).getStringCellValue());
            tr.setOtherEntity(row.getCell(7).getStringCellValue());
            String lockedStr = row.getCell(7).getStringCellValue();
            if ("YES".equalsIgnoreCase(lockedStr) || "TRUE".equalsIgnoreCase(lockedStr)) {
                tr.setLocked(true);//from   w  w w. j  a  v a2s.co  m
            }
            tr.setTrId();
            mapTr.put(tr.getTrId(), tr);

        }
    }
    return excelTrMap;

}

From source file:achmad.rifai.admin.ui.Opener.java

private void barang() {
    try {/*from w  w w  . j  av  a 2s. c o  m*/
        achmad.rifai.erp1.util.Db d = achmad.rifai.erp1.util.Work.loadDB();
        org.apache.poi.xssf.usermodel.XSSFWorkbook w = new org.apache.poi.xssf.usermodel.XSSFWorkbook(f);
        org.apache.poi.xssf.usermodel.XSSFSheet s = w.getSheet("barang");
        java.util.List<achmad.rifai.erp1.entity.Barang> l = new java.util.LinkedList<>();
        int x = 1;
        String st = s.getRow(x).getCell(0).getStringCellValue();
        while (!st.isEmpty()) {
            org.apache.poi.xssf.usermodel.XSSFRow r = s.getRow(x);
            achmad.rifai.erp1.entity.Barang b = new achmad.rifai.erp1.entity.Barang();
            b.setKode(r.getCell(0).getStringCellValue());
            b.setNama(r.getCell(1).getStringCellValue());
            b.setHarga(org.joda.money.Money.parse(r.getCell(2).getStringCellValue()));
            b.setStok(Integer.parseInt(r.getCell(3).getStringCellValue()));
            b.setSatuan(r.getCell(4).getStringCellValue());
            b.setDeleted(Boolean.parseBoolean(r.getCell(5).getStringCellValue()));
            x++;
            st = s.getRow(x).getCell(0).getStringCellValue();
            l.add(b);
        }
        progBarang.setValue(50);
        for (int c = 0; c < l.size(); x++) {
            new achmad.rifai.erp1.entity.dao.DAOBarang(d).insert(l.get(c));
            progBarang.setValue((((1 + c) * 50) / l.size()) + 50);
        }
        d.close();
    } catch (Exception ex) {
        achmad.rifai.erp1.util.Db.hindar(ex);
    }
    progBarang.setValue(100);
}

From source file:achmad.rifai.admin.ui.Opener.java

private void absen() {
    try {// w  w w. ja  va 2 s . c o  m
        achmad.rifai.erp1.util.Db d = achmad.rifai.erp1.util.Work.loadDB();
        org.apache.poi.xssf.usermodel.XSSFWorkbook w = new org.apache.poi.xssf.usermodel.XSSFWorkbook(f);
        org.apache.poi.xssf.usermodel.XSSFSheet s = w.getSheet("absen");
        java.util.List<achmad.rifai.erp1.entity.BukuAbsen> l = new java.util.LinkedList<>();
        int x = 2;
        String st = s.getRow(x).getCell(0).getStringCellValue();
        while (!st.isEmpty()) {
            achmad.rifai.erp1.entity.BukuAbsen b = new achmad.rifai.erp1.entity.BukuAbsen();
            int y = x;
            org.apache.poi.xssf.usermodel.XSSFRow r1 = s.getRow(x), r2 = s.getRow(y);
            boolean trus = true;
            b.setTgl(r1.getCell(0).getStringCellValue());
            b.setDeleted(Boolean.parseBoolean(r1.getCell(3).getStringCellValue()));
            java.util.List<achmad.rifai.erp1.entity.Absen> l2 = new java.util.LinkedList<>();
            while (trus || null == r2.getCell(0)) {
                trus = false;
                Absen a = new Absen();
                a.setS(r2.getCell(1).getStringCellValue());
                a.setL(Absen.Jenise.valueOf(r2.getCell(2).getStringCellValue()));
                l2.add(a);
                y++;
                r2 = s.getRow(y);
            }
            b.setL(l2);
            l.add(b);
            x = y + 1;
            st = s.getRow(x).getCell(0).getStringCellValue();
        }
        progAbsen.setValue(50);
        for (int c = 0; c < l.size(); c++) {
            new achmad.rifai.erp1.entity.dao.DAOBukuAbsen(d).insert(l.get(c));
            progAbsen.setValue((((1 + c) * 50) / l.size()) + 50);
        }
        d.close();
    } catch (Exception ex) {
        achmad.rifai.erp1.util.Db.hindar(ex);
    }
    progAbsen.setValue(100);
}