Java Code Examples for skadistats.clarity.model.StringTable
The following examples show how to use
skadistats.clarity.model.StringTable. 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: clarity Source File: PlayerInfo.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
@OnStringTableEntry("userinfo") public void onEntry(StringTable table, int index, String key, ByteString value) throws IOException { PlayerInfoType current = null; if (value != null && value.size() != 0) { current = new PlayerInfoType(value); } int i = index + 1; PlayerInfoType last = playerInfos.get(i); if (current == last) return; if (current != null && last != null && current.equals(last)) return; if (current == null) { playerInfos.remove(i); } else { playerInfos.put(i, current); } evPlayerInfo.raise(i, current); }
Example 2
Source Project: clarity Source File: S1StringTableEmitter.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
@OnMessage(S1NetMessages.CSVCMsg_CreateStringTable.class) public void onCreateStringTable(S1NetMessages.CSVCMsg_CreateStringTable message) { if (isProcessed(message.getName())) { StringTable table = new StringTable( message.getName(), message.getMaxEntries(), message.getUserDataFixedSize(), message.getUserDataSize(), message.getUserDataSizeBits(), message.getFlags() ); decodeEntries(table, message.getStringData(), message.getNumEntries()); table.markInitialState(); evCreated.raise(numTables, table); } numTables++; }
Example 3
Source Project: clarity Source File: Modifiers.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
@OnStringTableEntry("ActiveModifiers") public void onTableEntry(StringTable table, int index, String key, ByteString value) throws InvalidProtocolBufferException { if (value != null) { DotaModifiers.CDOTAModifierBuffTableEntry message; try { message = DotaModifiers.CDOTAModifierBuffTableEntry.parseFrom(value); } catch (InvalidProtocolBufferException ex) { message = (DotaModifiers.CDOTAModifierBuffTableEntry) ex.getUnfinishedMessage(); byte[] b = ZeroCopy.extract(value); log.error("failed to parse CDOTAModifierBuffTableEntry, returning incomplete message. Only %d/%d bytes parsed.", message.getSerializedSize(), value.size()); for (String line : formatHexDump(b, 0, b.length).split("\n")) { log.info("%s", line); } } evEntry.raise(message); } }
Example 4
Source Project: parser Source File: Parse.java License: MIT License | 5 votes |
/** * 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 5
Source Project: clarity-examples Source File: Main.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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 6
Source Project: clarity Source File: BaseStringTableEmitter.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@Initializer(OnStringTableEntry.class) public void initStringTableEntryEvent(final EventListener<OnStringTableEntry> eventListener) { final String tableName = eventListener.getAnnotation().value(); requestedTables.add(tableName); if ("*".equals(tableName)) { updateEventTables = requestedTables; } else { updateEventTables.add(tableName); } eventListener.setInvocationPredicate(args -> { StringTable t = (StringTable) args[0]; return "*".equals(tableName) || t.getName().equals(tableName); }); }
Example 7
Source Project: clarity Source File: BaseStringTableEmitter.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@OnMessage(Demo.CDemoStringTables.class) public void onStringTables(Demo.CDemoStringTables packet) { for (Demo.CDemoStringTables.table_t tt : packet.getTablesList()) { StringTable table = stringTables.byName.get(tt.getTableName()); if (table == null) { continue; } applyFullStringTables(table, tt); for (int i = 0; i < table.getEntryCount(); i++) { raise(table, i, table.getNameByIndex(i), table.getValueByIndex(i)); } } }
Example 8
Source Project: clarity Source File: S1StringTableEmitter.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@OnMessage(NetMessages.CSVCMsg_UpdateStringTable.class) public void onUpdateStringTable(NetMessages.CSVCMsg_UpdateStringTable message) { StringTable table = stringTables.forId(message.getTableId()); if (table != null) { decodeEntries(table, message.getStringData(), message.getNumChangedEntries()); } }
Example 9
Source Project: clarity Source File: StringTables.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@OnStringTableCreated public void onStringTableCreated(int tableNum, StringTable table) { if (byId.containsKey(tableNum) || byName.containsKey(table.getName())) { throw new ClarityException("String table %d (%s) already exists!", tableNum, table.getName()); } byId.put(tableNum, table); byName.put(table.getName(), table); }
Example 10
Source Project: clarity Source File: S2StringTableEmitter.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@OnMessage(S2NetMessages.CSVCMsg_CreateStringTable.class) public void onCreateStringTable(S2NetMessages.CSVCMsg_CreateStringTable message) throws IOException { if (isProcessed(message.getName())) { StringTable table = new StringTable( message.getName(), null, message.getUserDataFixedSize(), message.getUserDataSize(), message.getUserDataSizeBits(), message.getFlags() ); ByteString data = message.getStringData(); if (message.getDataCompressed()) { byte[] dst; if (context.getBuildNumber() != -1 && context.getBuildNumber() <= 962) { dst = LZSS.unpack(data); } else { dst = Snappy.uncompress(ZeroCopy.extract(data)); } data = ZeroCopy.wrap(dst); } decodeEntries(table, data, message.getNumEntries()); table.markInitialState(); evCreated.raise(numTables, table); } numTables++; }
Example 11
Source Project: clarity Source File: S2StringTableEmitter.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@OnMessage(NetMessages.CSVCMsg_UpdateStringTable.class) public void onUpdateStringTable(NetMessages.CSVCMsg_UpdateStringTable message) throws IOException { StringTable table = stringTables.forId(message.getTableId()); if (table != null) { decodeEntries(table, message.getStringData(), message.getNumChangedEntries()); } }
Example 12
Source Project: clarity Source File: Entities.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@OnStringTableEntry(BASELINE_TABLE) public void onBaselineEntry(StringTable table, int index, String key, ByteString value) { Integer dtClassId = Integer.valueOf(key); rawBaselines.put(dtClassId, value); if (classBaselines != null) { classBaselines[dtClassId].reset(); } }
Example 13
Source Project: clarity-examples Source File: Main.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
@OnStringTableCreated public void onStringTableCreated(int numTables, StringTable table) { names.add(table.getName()); System.out.println(table.getName()); }
Example 14
Source Project: clarity-examples Source File: Main.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
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); }
Example 15
Source Project: clarity Source File: S1CombatLogEntry.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
public S1CombatLogEntry(S1CombatLogIndices indices, StringTable combatLogNames, GameEvent event) { this.indices = indices; this.combatLogNames = combatLogNames; this.e = event; }
Example 16
Source Project: clarity Source File: S2CombatLogEntry.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
public S2CombatLogEntry(StringTable combatLogNames, DotaUserMessages.CMsgDOTACombatLogEntry entry) { this.combatLogNames = combatLogNames; this.e = entry; }
Example 17
Source Project: clarity Source File: BaseStringTableEmitter.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
protected void raise(StringTable table, int index, String name, ByteString value) { updateEvent.raise(table, index, name, value); }
Example 18
Source Project: clarity Source File: S1StringTableEmitter.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
private void decodeEntries(StringTable table, ByteString encodedData, int numEntries) { BitStream stream = BitStream.createBitStream(encodedData); int bitsPerIndex = Util.calcBitsNeededFor(table.getMaxEntries() - 1); String[] keyHistory = new String[KEY_HISTORY_SIZE]; boolean mysteryFlag = stream.readBitFlag(); int index = -1; for (int i = 0; i < numEntries; i++) { // read index if (stream.readBitFlag()) { index++; } else { index = stream.readUBitInt(bitsPerIndex); } // read name String name = null; if (stream.readBitFlag()) { if (mysteryFlag && stream.readBitFlag()) { throw new ClarityException("mystery_flag assert failed!"); } if (stream.readBitFlag()) { int base = i > KEY_HISTORY_SIZE ? i : 0; int offs = stream.readUBitInt(5); int len = stream.readUBitInt(5); String str = keyHistory[(base + offs) & KEY_HISTORY_MASK]; name = str.substring(0, len) + stream.readString(MAX_NAME_LENGTH); } else { name = stream.readString(MAX_NAME_LENGTH); } } // read value ByteString data = null; if (stream.readBitFlag()) { int bitLength; if (table.getUserDataFixedSize()) { bitLength = table.getUserDataSizeBits(); } else { bitLength = stream.readUBitInt(14) * 8; } byte[] valueBuf = new byte[(bitLength + 7) / 8]; stream.readBitsIntoByteArray(valueBuf, bitLength); data = ZeroCopy.wrap(valueBuf); } int entryCount = table.getEntryCount(); if (index < entryCount) { // update old entry table.setValueForIndex(index, data); assert(name == null || Objects.equals(name, table.getNameByIndex(index))); name = table.getNameByIndex(index); } else if (index == entryCount) { // add a new entry assert(name != null); table.addEntry(name, data); } else { throw new IllegalStateException("index > entryCount"); } keyHistory[i & KEY_HISTORY_MASK] = name; raise(table, index, name, data); } }
Example 19
Source Project: clarity Source File: StringTables.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
public StringTable forName(String name) { return byName.get(name); }
Example 20
Source Project: clarity Source File: StringTables.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
public StringTable forId(int id) { return byId.get(id); }
Example 21
Source Project: clarity Source File: S2StringTableEmitter.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
private void decodeEntries(StringTable table, ByteString encodedData, int numEntries) throws IOException { BitStream stream = BitStream.createBitStream(encodedData); String[] keyHistory = new String[KEY_HISTORY_SIZE]; int index = -1; for (int i = 0; i < numEntries; i++) { // read index if (stream.readBitFlag()) { index++; } else { index += stream.readVarUInt() + 2; } // read name String name = null; if (stream.readBitFlag()) { if (stream.readBitFlag()) { int base = i > KEY_HISTORY_SIZE ? i : 0; int offs = stream.readUBitInt(5); int len = stream.readUBitInt(5); String str = keyHistory[(base + offs) & KEY_HISTORY_MASK]; name = str.substring(0, len) + stream.readString(MAX_NAME_LENGTH); } else { name = stream.readString(MAX_NAME_LENGTH); } } // read value ByteString data = null; if (stream.readBitFlag()) { boolean isCompressed = false; int bitLength; if (table.getUserDataFixedSize()) { bitLength = table.getUserDataSizeBits(); } else { if ((table.getFlags() & 0x1) != 0) { // this is the case for the instancebaseline for console recorded replays isCompressed = stream.readBitFlag(); } bitLength = stream.readUBitInt(17) * 8; } int byteLength = (bitLength + 7) / 8; byte[] valueBuf; if (isCompressed) { stream.readBitsIntoByteArray(tempBuf, bitLength); int byteLengthUncompressed = Snappy.uncompressedLength(tempBuf, 0, byteLength); valueBuf = new byte[byteLengthUncompressed]; Snappy.rawUncompress(tempBuf, 0, byteLength, valueBuf, 0); } else { valueBuf = new byte[byteLength]; stream.readBitsIntoByteArray(valueBuf, bitLength); } data = ZeroCopy.wrap(valueBuf); } int entryCount = table.getEntryCount(); if (index < entryCount) { // update old entry table.setValueForIndex(index, data); assert(name == null || Objects.equals(name, table.getNameByIndex(index))); name = table.getNameByIndex(index); } else if (index == entryCount) { // add a new entry assert(name != null); table.addEntry(name, data); } else { throw new IllegalStateException("index > entryCount"); } keyHistory[i & KEY_HISTORY_MASK] = name; raise(table, index, name, data); } }