skadistats.clarity.processor.runner.Context Java Examples

The following examples show how to use skadistats.clarity.processor.runner.Context. 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 File: Parse.java    From parser with 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 File: Parse.java    From parser with 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 File: Parse.java    From parser with 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 File: Main.java    From clarity-examples with 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 #5
Source File: Parse.java    From parser with 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 #6
Source File: Main.java    From clarity-examples with 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 #7
Source File: SpawnsAndDeaths.java    From clarity-examples with 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 #8
Source File: Main.java    From clarity-examples with 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 #9
Source File: Wards.java    From parser with 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 #10
Source File: Wards.java    From parser with 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 #11
Source File: SpawnsAndDeaths.java    From clarity-examples with 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 #12
Source File: Wards.java    From parser with 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 #13
Source File: Wards.java    From parser with 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 File: Main.java    From clarity-examples with 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 #15
Source File: Main.java    From clarity-examples with 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 #16
Source File: Main.java    From clarity-examples with 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 #17
Source File: Parse.java    From parser with 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 #18
Source File: AbstractInvocationPoint.java    From clarity with 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 #19
Source File: Parse.java    From parser with 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 #20
Source File: Parse.java    From parser with 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 #21
Source File: Parse.java    From parser with 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 #22
Source File: Parse.java    From parser with 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 #23
Source File: Parse.java    From parser with 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 #24
Source File: Parse.java    From parser with 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 #25
Source File: AbstractInvocationPoint.java    From clarity with 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 File: SpawnsAndDeaths.java    From clarity-examples with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void init(Context ctx) {
}
 
Example #27
Source File: SpawnsAndDeaths.java    From clarity-examples with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@OnEntityDeleted
public void onDeleted(Context ctx, Entity e) {
    clearCachedState(e);
}
 
Example #28
Source File: SpawnsAndDeaths.java    From clarity-examples with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Initializer(OnEntityDied.class)
public void initOnEntityDied(final Context ctx, final EventListener<OnEntityDied> eventListener) {
    init(ctx);
    evDied = ctx.createEvent(OnEntityDied.class, Entity.class);
}
 
Example #29
Source File: SpawnsAndDeaths.java    From clarity-examples with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Initializer(OnEntityDying.class)
public void initOnEntityDying(final Context ctx, final EventListener<OnEntityDying> eventListener) {
    init(ctx);
    evDying = ctx.createEvent(OnEntityDying.class, Entity.class);
}
 
Example #30
Source File: Parse.java    From parser with 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);
}