Java Code Examples for skadistats.clarity.processor.runner.Context

The following examples show how to use skadistats.clarity.processor.runner.Context. 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   Author: odota   File: Parse.java    License: MIT License 6 votes vote down vote up
@OnMessage(CDOTAUserMsg_LocationPing.class)
public void onPlayerPing(Context ctx, CDOTAUserMsg_LocationPing message) {
    pingCount += 1;
    if (pingCount > 10000) {
        return;
    }

    Entry entry = new Entry(time);
    entry.type = "pings";
    entry.slot = message.getPlayerId();
    /*
    System.err.println(message);
    player_id: 7
    location_ping {
      x: 5871
      y: 6508
      target: -1
      direct_ping: false
      type: 0
    }
    */
    //we could get the ping coordinates/type if we cared
    //entry.key = String.valueOf(message.getOrderType());
    output(entry);
}
 
Example #2
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 6 votes vote down vote up
@OnEntityEntered
public void onEntityEntered(Context ctx, Entity e) {
    if (e.getDtClass().getDtName().equals("CDOTAWearableItem")) {
    	Integer accountId = getEntityProperty(e, "m_iAccountID", null);
    	Integer itemDefinitionIndex = getEntityProperty(e, "m_iItemDefinitionIndex", null);
    	Integer ownerHandle = getEntityProperty(e, "m_hOwnerEntity", null);
        Entity owner = ctx.getProcessor(Entities.class).getByHandle(ownerHandle);
    	//System.err.format("%s,%s\n", accountId, itemDefinitionIndex);
    	if (accountId > 0)
    	{
        	// Get the owner (a hero entity)
        	Integer playerId = getEntityProperty(owner, "m_iPlayerID", null);
    	    Long accountId64 = 76561197960265728L + accountId;
    	    Integer playerSlot = steamid_to_playerslot.get(accountId64);
    		cosmeticsMap.put(itemDefinitionIndex, playerSlot);
    	}
    }
}
 
Example #3
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 6 votes vote down vote up
private List<Item> getHeroInventory(Context ctx, Entity eHero) {
    List<Item> inventoryList = new ArrayList<>(6);

    for (int i = 0; i < 6; i++) {
        try {
            Item item = getHeroItem(ctx, eHero, i);
            if(item != null) {
                inventoryList.add(item);
            }
        }
        catch (Exception e) {
            System.err.println(e);
        }
    }

    return inventoryList;
}
 
Example #4
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 6 votes vote down vote up
private Entry buildWardEntry(Context ctx, Entity e) { 
    Entry entry = new Entry(time); 
        boolean isObserver = !e.getDtClass().getDtName().contains("TrueSight"); 
    Integer x = getEntityProperty(e, "CBodyComponent.m_cellX", null); 
    Integer y = getEntityProperty(e, "CBodyComponent.m_cellY", null); 
    Integer z = getEntityProperty(e, "CBodyComponent.m_cellZ", null); 
    Integer life_state = getEntityProperty(e, "m_lifeState", null); 
    Integer[] pos = {x, y}; 
    entry.x = x; 
    entry.y = y; 
    entry.z = z; 
    entry.type = isObserver ? "obs" : "sen"; 
    entry.entityleft = life_state == 1; 
    entry.key = Arrays.toString(pos); 
    entry.ehandle = e.getHandle(); 
 
    if (entry.entityleft) { 
        entry.type += "_left"; 
    }
    
    Integer owner = getEntityProperty(e, "m_hOwnerEntity", null); 
    Entity ownerEntity = ctx.getProcessor(Entities.class).getByHandle(owner); 
    entry.slot = ownerEntity != null ? (Integer) getEntityProperty(ownerEntity, "m_iPlayerID", null) : null; 
    
    return entry; 
}
 
Example #5
Source Project: clarity-examples   Author: skadistats   File: Main.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void run(String[] args) throws Exception {
    final Context ctx = new SimpleRunner(new MappedFileSource(args[0])).runWith(this).getContext();
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                MainWindow window = new MainWindow();
                window.getClassTree().setModel(new DefaultTreeModel(new TreeConstructor(ctx.getProcessor(DTClasses.class)).construct()));
                window.getFrame().setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

}
 
Example #6
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 5 votes vote down vote up
@OnMessage(CDOTAUserMsg_SpectatorPlayerUnitOrders.class)
public void onSpectatorPlayerUnitOrders(Context ctx, CDOTAUserMsg_SpectatorPlayerUnitOrders message) {
    Entry entry = new Entry(time);
    entry.type = "actions";
    //the entindex points to a CDOTAPlayer.  This is probably the player that gave the order.
    Entity e = ctx.getProcessor(Entities.class).getByIndex(message.getEntindex());
    entry.slot = getEntityProperty(e, "m_iPlayerID", null);
    //Integer handle = (Integer)getEntityProperty(e, "m_hAssignedHero", null);
    //Entity h = ctx.getProcessor(Entities.class).getByHandle(handle);
    //System.err.println(h.getDtClass().getDtName());
    //break actions into types?
    entry.key = String.valueOf(message.getOrderType());
    //System.err.println(message);
    output(entry);
}
 
Example #7
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 5 votes vote down vote up
@OnMessage(CDOTAUserMsg_ChatEvent.class)
public void onChatEvent(Context ctx, CDOTAUserMsg_ChatEvent message) {
    Integer player1 = message.getPlayerid1();
    Integer player2 = message.getPlayerid2();
    Integer value = message.getValue();
    String type = String.valueOf(message.getType());
    Entry entry = new Entry(time);
    entry.type = type;
    entry.player1 = player1;
    entry.player2 = player2;
    entry.value = value;
    output(entry);
}
 
Example #8
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 5 votes vote down vote up
@OnMessage(CDOTAUserMsg_ChatWheel.class)
public void onChatWheel(Context ctx, CDOTAUserMsg_ChatWheel message) {
	Entry entry = new Entry(time);
	entry.type = "chatwheel";
	entry.slot = message.getPlayerId();
	entry.key = String.valueOf(message.getChatMessageId());
	output(entry);
}
 
Example #9
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 5 votes vote down vote up
@OnMessage(CUserMsg_SayText2.class)
public void onAllChatS1(Context ctx, CUserMsg_SayText2 message) {
    Entry entry = new Entry(time);
    entry.unit =  String.valueOf(message.getPrefix());
    entry.key =  String.valueOf(message.getText());
    entry.type = "chat";
    output(entry);
}
 
Example #10
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 5 votes vote down vote up
@OnMessage(CUserMessageSayText2.class)
public void onAllChatS2(Context ctx, CUserMessageSayText2 message) {
    Entry entry = new Entry(time);
    entry.unit = String.valueOf(message.getParam1());
    entry.key = String.valueOf(message.getParam2());
    Entity e = ctx.getProcessor(Entities.class).getByIndex(message.getEntityindex());
    entry.slot = getEntityProperty(e, "m_iPlayerID", null);
    entry.type = "chat";
    output(entry);
}
 
Example #11
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 5 votes vote down vote up
@OnMessage(CDemoFileInfo.class)
public void onFileInfo(Context ctx, CDemoFileInfo message) {
    //beware of 4.2b limit!  we don't currently do anything with this, so we might be able to just remove this
    //we can't use the value field since it takes Integers
    //Entry matchIdEntry = new Entry();
    //matchIdEntry.type = "match_id";
    //matchIdEntry.value = message.getGameInfo().getDota().getMatchId();
    //output(matchIdEntry);
    
    // Extracted cosmetics data from CDOTAWearableItem entities
	Entry cosmeticsEntry = new Entry();
	cosmeticsEntry.type = "cosmetics";
	cosmeticsEntry.key = new Gson().toJson(cosmeticsMap);
	output(cosmeticsEntry);

    // Dota plus hero levels
    Entry dotaPlusEntry = new Entry();
    dotaPlusEntry.type = "dotaplus";
    dotaPlusEntry.key = new Gson().toJson(dotaplusxpMap);
    output(dotaPlusEntry);

    //emit epilogue event to mark finish
    Entry epilogueEntry = new Entry();
    epilogueEntry.type = "epilogue";
    epilogueEntry.key = new Gson().toJson(message);
    output(epilogueEntry);
}
 
Example #12
Source Project: parser   Author: odota   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 #13
Source Project: parser   Author: odota   File: Wards.java    License: MIT License 5 votes vote down vote up
@OnEntityCreated
public void onCreated(Context ctx, Entity e) {      
    if (!isWard(e)) return;
    
    FieldPath lifeStatePath;
    
    clearCachedState(e);
    ensureFieldPathForEntityInitialized(e);
    if ((lifeStatePath = getFieldPathForEntity(e)) != null) {
        processLifeStateChange(e, lifeStatePath);
    }
}
 
Example #14
Source Project: parser   Author: odota   File: Wards.java    License: MIT License 5 votes vote down vote up
@OnEntityUpdated
public void onUpdated(Context ctx, Entity e, FieldPath[] fieldPaths, int num) {
    FieldPath p;
    if ((p = getFieldPathForEntity(e)) != null) {
        for (int i = 0; i < num; i++) {
            if (fieldPaths[i].equals(p)) {
                toProcess.add(new ProcessEntityCommand(e, p));
                break;
            }
        }
    }
}
 
Example #15
Source Project: parser   Author: odota   File: Wards.java    License: MIT License 5 votes vote down vote up
@OnCombatLogEntry
public void onCombatLogEntry(Context ctx, CombatLogEntry entry) {
    if (!isWardDeath(entry)) return;
    
    String killer;
    if ((killer = entry.getDamageSourceName()) != null) {
        wardKillersByWardClass.get(entry.getTargetName()).add(killer);
    }
}
 
Example #16
Source Project: parser   Author: odota   File: Wards.java    License: MIT License 5 votes vote down vote up
@OnTickEnd
public void onTickEnd(Context ctx, boolean synthetic) {
    if (!synthetic) return;
    
    ProcessEntityCommand cmd;
    while ((cmd = toProcess.poll()) != null) {
        processLifeStateChange(cmd.entity, cmd.fieldPath);
    }
}
 
Example #17
Source Project: clarity-examples   Author: skadistats   File: Main.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnTickEnd
public void onTickEnd(Context ctx, boolean synthetic) {
    log.info("tick {}, synthetic {}, had {} messages", tick, synthetic, count);
    if (synthetic && count > 0) {
        throw new RuntimeException("oops 1");
    }
    if (!synthetic && count == 0) {
        throw new RuntimeException("oops 2");
    }
}
 
Example #18
Source Project: clarity-examples   Author: skadistats   File: Main.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityPropertyChanged(classPattern = "CDOTA_Unit_Hero_.*", propertyPattern = "m_lifeState")
public void onEntityPropertyChanged(Context ctx, Entity e, FieldPath fp) {
    System.out.format(
            "%6d %s: %s = %s\n",
            ctx.getTick(),
            e.getDtClass().getDtName(),
            e.getDtClass().getNameForFieldPath(fp),
            e.getPropertyForFieldPath(fp)
    );
}
 
Example #19
Source Project: clarity-examples   Author: skadistats   File: SpawnsAndDeaths.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityCreated
public void onCreated(Context ctx, Entity e) {
    clearCachedState(e);
    ensureFieldPathForEntityInitialized(e);
    FieldPath p = getFieldPathForEntity(e);
    if (p != null) {
        processLifeStateChange(e, p);
    }
}
 
Example #20
Source Project: clarity-examples   Author: skadistats   File: SpawnsAndDeaths.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityUpdated
public void onUpdated(Context ctx, Entity e, FieldPath[] fieldPaths, int num) {
    FieldPath p = getFieldPathForEntity(e);
    if (p != null) {
        for (int i = 0; i < num; i++) {
            if (fieldPaths[i].equals(p)) {
                processLifeStateChange(e, p);
                break;
            }
        }
    }
}
 
Example #21
Source Project: clarity-examples   Author: skadistats   File: Main.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnMessage(GeneratedMessage.class)
public void onMessage(Context ctx, GeneratedMessage message) {
    if (message instanceof S1NetMessages.CSVCMsg_VoiceData || message instanceof S2NetMessages.CSVCMsg_VoiceData) {
        return;
    }
    log.info("{}: {}", ctx.getTick(), message.getClass().getSimpleName());
}
 
Example #22
Source Project: clarity-examples   Author: skadistats   File: Main.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnMessage(Demo.CDemoSendTables.class)
public void onSendTables(Context ctx, Demo.CDemoSendTables message) throws IOException {
    CodedInputStream cis = CodedInputStream.newInstance(ZeroCopy.extract(message.getData()));
    int size = cis.readRawVarint32();
    S2NetMessages.CSVCMsg_FlattenedSerializer fs = Packet.parse(S2NetMessages.CSVCMsg_FlattenedSerializer.class, ZeroCopy.wrap(cis.readRawBytes(size)));

    Set<String> baseTypes = new TreeSet<>();
    for (S2NetMessages.ProtoFlattenedSerializer_t s : fs.getSerializersList()) {
        for (int fi : s.getFieldsIndexList()) {
            S2NetMessages.ProtoFlattenedSerializerField_t f = fs.getFields(fi);
            FieldType ft = new FieldType(fs.getSymbols(f.getVarTypeSym()));
            if (!f.hasFieldSerializerNameSym()) {
                int l = 0;
                do {
                    baseTypes.add(ft.getBaseType().toUpperCase());
                    if ("CUTLVECTOR".equals(ft.getBaseType().toUpperCase())) {
                        ft = ft.getGenericType();
                    } else {
                        ft = null;
                    }
                    l++;
                } while (l <= 1 && ft != null);
            }
        }
    }
    dump(ctx, fs);
}
 
Example #23
Source Project: clarity-examples   Author: skadistats   File: Main.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void dump(Context ctx, S2NetMessages.CSVCMsg_FlattenedSerializer fs) throws FileNotFoundException {
    String fileName = "flattables_" + ctx.getBuildNumber() + ".txt";
    log.info("writing {}", fileName);
    PrintStream out = new PrintStream(new FileOutputStream(fileName));
    for (S2NetMessages.ProtoFlattenedSerializer_t s : fs.getSerializersList()) {
        out.println("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
        out.format("%s(%s)\n", fs.getSymbols(s.getSerializerNameSym()), s.getSerializerVersion());
        out.println("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
        for (int fi : s.getFieldsIndexList()) {
            S2NetMessages.ProtoFlattenedSerializerField_t f = fs.getFields(fi);
            String line = String.format(
                "type: %-50s name: %-30s node: %-41s serializer: %-35s flags: %8s bitcount: %3s low: %9s high: %9s",
                String.format("%s%s", fs.getSymbols(f.getVarTypeSym()), f.hasVarEncoderSym() ? String.format(" {%s}", fs.getSymbols(f.getVarEncoderSym())) : ""),
                fs.getSymbols(f.getVarNameSym()),
                fs.getSymbols(f.getSendNodeSym()),
                f.hasFieldSerializerNameSym() ? String.format("%s(%s)", fs.getSymbols(f.getFieldSerializerNameSym()), f.getFieldSerializerVersion()) : "-",
                f.hasEncodeFlags() ? Integer.toHexString(f.getEncodeFlags()) : "-",
                f.hasBitCount() ? f.getBitCount() : "-",
                f.hasLowValue() ? f.getLowValue() : "-",
                f.hasHighValue() ? f.getHighValue() : "-"
            );
            out.println(line);
        }
        out.println();
        out.println();
    }
}
 
Example #24
Source Project: clarity   Author: skadistats   File: AbstractInvocationPoint.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean hasContextParameter() {
    Class<?>[] parameterTypes = method.getParameterTypes();
    if (parameterTypes.length == 0) {
        return false;
    }
    if (parameterTypes[0].isAssignableFrom(Context.class)) {
        return true;
    }
    return false;
}
 
Example #25
Source Project: clarity   Author: skadistats   File: AbstractInvocationPoint.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void bind(Context ctx) throws IllegalAccessException {
    log.debug("bind %s to context", method);
    MethodHandle boundHandle = MethodHandles.publicLookup().unreflect(method).bindTo(ctx.getProcessor(processorClass));
    if (hasContextParameter()) {
        boundHandle = boundHandle.bindTo(ctx);
    }
    this.methodHandle = boundHandle.asSpreader(Object[].class, arity);
}
 
Example #26
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 4 votes vote down vote up
public void onMessage(Context ctx, GeneratedMessage message) {
    System.err.println(message.getClass().getName());
    System.out.println(message.toString());
}
 
Example #27
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 4 votes vote down vote up
@OnMessage(CMsgDOTAMatch.class)
public void onDotaMatch(Context ctx, CMsgDOTAMatch message)
{
    //TODO could use this for match overview data for uploads
    //System.err.println(message);
}
 
Example #28
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 4 votes vote down vote up
@OnCombatLogEntry
public void onCombatLogEntry(Context ctx, CombatLogEntry cle) {
    try 
    {
        time = Math.round(cle.getTimestamp());
        //create a new entry
        Entry combatLogEntry = new Entry(time);
        combatLogEntry.type = cle.getType().name();
        //translate the fields using string tables if necessary (get*Name methods)
        combatLogEntry.attackername = cle.getAttackerName();
        combatLogEntry.targetname = cle.getTargetName();
        combatLogEntry.sourcename = cle.getDamageSourceName();
        combatLogEntry.targetsourcename = cle.getTargetSourceName();
        combatLogEntry.inflictor = cle.getInflictorName();
        combatLogEntry.attackerhero = cle.isAttackerHero();
        combatLogEntry.targethero = cle.isTargetHero();
        combatLogEntry.attackerillusion = cle.isAttackerIllusion();
        combatLogEntry.targetillusion = cle.isTargetIllusion();
        combatLogEntry.value = cle.getValue();
        float stunDuration = cle.getStunDuration();
        if (stunDuration > 0) {
        	combatLogEntry.stun_duration = stunDuration;
        }
        float slowDuration = cle.getSlowDuration();
        if (slowDuration > 0) {
        	combatLogEntry.slow_duration = slowDuration;
        }
        //value may be out of bounds in string table, we can only get valuename if a purchase (type 11)
        if (cle.getType() == DOTA_COMBATLOG_TYPES.DOTA_COMBATLOG_PURCHASE) {
            combatLogEntry.valuename = cle.getValueName();
        }
        else if (cle.getType() == DOTA_COMBATLOG_TYPES.DOTA_COMBATLOG_GOLD) {
            combatLogEntry.gold_reason = cle.getGoldReason();
        }
        else if (cle.getType() == DOTA_COMBATLOG_TYPES.DOTA_COMBATLOG_XP) {
            combatLogEntry.xp_reason = cle.getXpReason();
        }
        
        combatLogEntry.greevils_greed_stack = greevilsGreedVisitor.visit(time, cle);
        TrackStatus trackStatus = trackVisitor.visit(time, cle);
        if (trackStatus != null) {
        	combatLogEntry.tracked_death = trackStatus.tracked;
        	combatLogEntry.tracked_sourcename = trackStatus.inflictor;
        }
        if (combatLogEntry.type.equals("DOTA_COMBATLOG_GAME_STATE") && combatLogEntry.value == 6) {
            postGame = true;
        }
        if (combatLogEntry.type.equals("DOTA_COMBATLOG_GAME_STATE") && combatLogEntry.value == 5) {
            //alternate to combat log for getting game zero time (looks like this is set at the same time as the game start, so it's not any better for streaming)
            // int currGameStartTime = Math.round( (float) grp.getProperty("m_pGameRules.m_flGameStartTime"));
            if (gameStartTime == 0) {
                gameStartTime = combatLogEntry.time;
                flushLogBuffer();
            }
        }
        if (cle.getType().ordinal() <= 19) {	
            output(combatLogEntry);
 }
    }
    catch(Exception e)
    {
        System.err.println(e);
        System.err.println(cle);
    }
}
 
Example #29
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 4 votes vote down vote up
@OnWardKilled 
public void onWardKilled(Context ctx, Entity e, String killerHeroName) { 
    Entry wardEntry = buildWardEntry(ctx, e); 
    wardEntry.attackername = killerHeroName; 
    output(wardEntry); 
}
 
Example #30
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 4 votes vote down vote up
@OnWardExpired 
@OnWardPlaced 
public void onWardExistenceChanged(Context ctx, Entity e) { 
    output(buildWardEntry(ctx, e)); 
}