skadistats.clarity.source.Source Java Examples

The following examples show how to use skadistats.clarity.source.Source. 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: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void readHeader(Source source) throws IOException {
    header = CsGoClarityMessages.CsGoDemoHeader.newBuilder()
            .setDemoprotocol(source.readFixedInt32())
            .setNetworkprotocol(source.readFixedInt32())
            .setServername(readHeaderString(source))
            .setClientname(readHeaderString(source))
            .setMapname(readHeaderString(source))
            .setGamedirectory(readHeaderString(source))
            .setPlaybackTime(Float.intBitsToFloat(source.readFixedInt32()))
            .setPlaybackTicks(source.readFixedInt32())
            .setPlaybackFrames(source.readFixedInt32())
            .setSignonlength(source.readFixedInt32())
            .build();
    millisPerTick = header.getPlaybackTime() * 1000.0f / header.getPlaybackTicks();
}
 
Example #2
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Demo.CDemoStringTables parse(Source source) throws IOException {
    BitStream bs = BitStream.createBitStream(ZeroCopy.wrap(readPacket(source)));
    Demo.CDemoStringTables.Builder b = Demo.CDemoStringTables.newBuilder();
    int nTables = bs.readUBitInt(8);
    for (int t = 0; t < nTables; t++) {
        Demo.CDemoStringTables.table_t.Builder tb = b.addTablesBuilder();
        tb.setTableName(bs.readString(4095));
        int nStrings = bs.readUBitInt(16);
        for (int s = 0; s < nStrings; s++) {
            readItem(bs, tb.addItemsBuilder());
        }
        if (bs.readBitFlag()) {
            nStrings = bs.readUBitInt(16);
            for (int s = 0; s < nStrings; s++) {
                readItem(bs, tb.addItemsClientsideBuilder());
            }
        }
    }
    return b.build();
}
 
Example #3
Source File: AllChatProcessor.java    From clarity-examples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // 1) create an input source from the replay
    Source source = new MappedFileSource("replay.dem");
    // 2) create a simple runner that will read the replay once
    SimpleRunner runner = new SimpleRunner(source);
    // 3) create an instance of your processor
    AllChatProcessor processor = new AllChatProcessor();
    // 4) and hand it over to the runner
    runner.runWith(processor);
}
 
Example #4
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Demo.CDemoUserCmd parse(Source source) throws IOException {
    return Demo.CDemoUserCmd.newBuilder()
            .setCmdNumber(source.readFixedInt32())
            .setData(ZeroCopy.wrap(readPacket(source)))
            .build();
}
 
Example #5
Source File: AbstractDotaEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public int determineLastTick(Source source) throws IOException {
    int backup = source.getPosition();
    source.setPosition(8);
    source.setPosition(source.readFixedInt32());
    source.skipVarInt32();
    int lastTick = source.readVarInt32();
    source.setPosition(backup);
    return lastTick;
}
 
Example #6
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public <T extends GeneratedMessage> PacketInstance<T> getNextPacketInstance(final Source source) throws IOException {
    final int kind = source.readByte() & 0xFF;
    final int tick = source.readFixedInt32();
    source.skipBytes(1); // playerSlot
    if (kind > handlers.length) {
        throw new UnsupportedOperationException("kind " + kind + " not implemented");
    }
    final Handler<T> handler = (Handler<T>) handlers[kind - 1];
    return new PacketInstance<T>() {
        @Override
        public int getKind() {
            return kind;
        }
        @Override
        public int getTick() {
            return tick;
        }
        @Override
        public Class<T> getMessageClass() {
            return handler.clazz;
        }
        @Override
        public ResetRelevantKind getResetRelevantKind() {
            return handler.resetRelevantKind;
        }
        @Override
        public T parse() throws IOException {
            return handler.parse(source);
        }
        @Override
        public void skip() throws IOException {
            handler.skip(source);
        }
    };
}
 
Example #7
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Demo.CDemoPacket parse(Source source) throws IOException {
    readCommandInfo(source);
    return Demo.CDemoPacket.newBuilder()
            .setSequenceIn(source.readFixedInt32())
            .setSequenceOutAck(source.readFixedInt32())
            .setData(ZeroCopy.wrap(readPacket(source)))
            .build();
}
 
Example #8
Source File: PacketReader.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public byte[] readFromSource(Source source, int size, boolean isCompressed) throws IOException {
    byte[] buf = new byte[size];
    source.readBytes(buf, 0, size);
    if (isCompressed) {
        return Snappy.uncompress(buf);
    } else {
        return buf;
    }
}
 
Example #9
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void skip(Source source) throws IOException {
    skipPacket(source);
}
 
Example #10
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Demo.CDemoSendTables parse(Source source) throws IOException {
    return Demo.CDemoSendTables.newBuilder()
            .setData(ZeroCopy.wrap(readPacket(source)))
            .build();
}
 
Example #11
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Demo.CDemoStop parse(Source source) throws IOException {
    return Demo.CDemoStop.newBuilder().build();
}
 
Example #12
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void skip(Source source) throws IOException {
    // do nothing
}
 
Example #13
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Demo.CDemoCustomData parse(Source source) throws IOException {
    return Demo.CDemoCustomData.newBuilder()
            .setData(ZeroCopy.wrap(readPacket(source)))
            .build();
}
 
Example #14
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void skip(Source source) throws IOException {
    skipPacket(source);
}
 
Example #15
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void skip(Source source) throws IOException {
    skipPacket(source);
}
 
Example #16
Source File: DotaS2EngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void readHeader(Source source) throws IOException {
    source.skipBytes(8);
}
 
Example #17
Source File: DotaS2EngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void skipHeader(Source source) throws IOException {
    source.skipBytes(8);
}
 
Example #18
Source File: AbstractFileRunner.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public AbstractFileRunner(Source source, EngineType engineType) throws IOException {
    super(engineType);
    engineType.readHeader(source);
    this.source = source;
    this.tick = -1;
}
 
Example #19
Source File: AbstractFileRunner.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected void initAndRunWith(Object... processors) throws IOException {
    initWithProcessors(this, getEngineType(), source, processors);
    engineType.emitHeader();
    context.createEvent(OnInputSource.class, Source.class, LoopController.class).raise(source, loopController);
}
 
Example #20
Source File: AbstractFileRunner.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Source getSource() {
    return source;
}
 
Example #21
Source File: SimpleRunner.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public SimpleRunner(Source s) throws IOException {
    super(s, s.readEngineType());
    this.loopController = new LoopController(controllerFunc);
}
 
Example #22
Source File: RealtimeRunner.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public RealtimeRunner(Source s) throws IOException {
    this(s, Duration.ZERO);
}
 
Example #23
Source File: RealtimeRunner.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public RealtimeRunner(Source s, Duration delay) throws IOException {
    super(s);
    setDelay(delay);
    startTime = now();
}
 
Example #24
Source File: ControllableRunner.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public ControllableRunner(Source s) throws IOException {
    super(s, s.readEngineType());
    upcomingTick = tick;
    wantedTick = tick;
    this.loopController = new LockingLoopController(normalLoopControl);
}
 
Example #25
Source File: Util.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static String readFixedZeroTerminated(Source source, int length) throws IOException {
    byte[] buf = new byte[length];
    source.readBytes(buf, 0, length);
    return zeroTerminatedToString(buf);
}
 
Example #26
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void skipCommandInfo(Source source) throws IOException {
    source.skipBytes(152);
}
 
Example #27
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public int determineLastTick(Source source) throws IOException {
    return header.getPlaybackTicks();
}
 
Example #28
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private byte[] readPacket(Source source) throws IOException {
    int size = source.readFixedInt32();
    return packetReader.readFromSource(source, size, false);
}
 
Example #29
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void skipPacket(Source source) throws IOException {
    source.skipBytes(source.readFixedInt32());
}
 
Example #30
Source File: CsGoEngineType.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void readCommandInfo(Source source) throws IOException {
    source.skipBytes(152);
}