Java Code Examples for skadistats.clarity.processor.stringtables.StringTables

The following examples show how to use skadistats.clarity.processor.stringtables.StringTables. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: parser   Source File: Parse.java    License: MIT License 5 votes vote down vote up
/**
 * Uses "EntityNames" string table and Entities processor
 * @param ctx Context
 * @param eHero Hero entity
 * @param idx 0-5 - inventory, 6-8 - backpack, 9-16 - stash
 * @return {@code null} - empty slot. Throws @{@link UnknownItemFoundException} if item information can't be extracted
 */
private Item getHeroItem(Context ctx, Entity eHero, int idx) throws UnknownItemFoundException {
    StringTable stEntityNames = ctx.getProcessor(StringTables.class).forName("EntityNames");
    Entities entities = ctx.getProcessor(Entities.class);

    Integer hItem = eHero.getProperty("m_hItems." + Util.arrayIdxToString(idx));
    if (hItem == 0xFFFFFF) {
        return null;
    }
    Entity eItem = entities.getByHandle(hItem);
    if(eItem == null) {
        throw new UnknownItemFoundException(String.format("Can't find item by its handle (%d)", hItem));
    }
    String itemName = stEntityNames.getNameByIndex(eItem.getProperty("m_pEntity.m_nameStringableIndex"));
    if(itemName == null) {
        throw new UnknownItemFoundException("Can't get item name from EntityName string table");
    }

    Item item = new Item();
    item.id = itemName;
    int numCharges = eItem.getProperty("m_iCurrentCharges");
    if(numCharges != 0) {
        item.num_charges = numCharges;
    }
    int numSecondaryCharges = eItem.getProperty("m_iSecondaryCharges");
    if(numSecondaryCharges != 0) {
        item.num_secondary_charges = numSecondaryCharges;
    }

    return item;
}
 
Example 2
public void runSeek(String[] args) throws Exception {
    Runner runner = new SimpleRunner(new MappedFileSource(args[0])).runWith(this);
    StringTables st = runner.getContext().getProcessor(StringTables.class);
    for (String name : names) {
        StringTable t = st.forName(name);
        System.out.println(t.toString());
    }
}
 
Example 3
public void run(String[] args) throws Exception {
    long tStart = System.currentTimeMillis();

    String demoName = args[0];

    SimpleRunner r = new SimpleRunner(new MappedFileSource(demoName)).runWith(this);

    Context ctx = r.getContext();

    File dir = new File(String.format("baselines%s%s", File.separator, ctx.getBuildNumber() == -1 ? "latest" : ctx.getBuildNumber()));
    if (!dir.exists()) {
        dir.mkdirs();
    }

    FieldReader fieldReader = ctx.getEngineType().getNewFieldReader();

    StringTables stringTables = ctx.getProcessor(StringTables.class);
    DTClasses dtClasses = ctx.getProcessor(DTClasses.class);
    StringTable baselines = stringTables.forName("instancebaseline");

    for (int i = 0; i < baselines.getEntryCount(); i++) {
        DTClass dtClass = dtClasses.forClassId(Integer.valueOf(baselines.getNameByIndex(i)));
        String fileName = String.format("%s%s%s.txt", dir.getPath(), File.separator, dtClass.getDtName());
        log.info("writing {}", fileName);
        fieldReader.DEBUG_STREAM = new PrintStream(new FileOutputStream(fileName), true, "UTF-8");
        BitStream bs = BitStream.createBitStream(baselines.getValueByIndex(i));
        try {
            fieldReader.readFields(bs, dtClass, dtClass.getEmptyState(), null, true);
            if (bs.remaining() < 0 || bs.remaining() > 7) {
                log.info("-- OFF: {} remaining", bs.remaining());
            }
        } catch (Exception e) {
            log.info("-- FAIL: {}", e.getMessage());
            e.printStackTrace(fieldReader.DEBUG_STREAM);
        } finally {
        }
    }

    long tMatch = System.currentTimeMillis() - tStart;
    log.info("total time taken: {}s", (tMatch) / 1000.0);
}