public static ScriptNode[] FromData(TagInterface.Data data) { int position = 56; int node_count = BitConverter.ToInt16(data.Value, 46); ScriptNode[] value = new ScriptNode[node_count]; // element count System.Diagnostics.Debug.WriteLine("node count: " + node_count); for (int x = 0; x < node_count; x++, position += 0x14) { var v = value[x] = new ScriptNode(); v.nodeIndex = x; v.index = BitConverter.ToInt16(data.Value, position + OffsetIndex); //position += 2; v.opcode = BitConverter.ToInt16(data.Value, position + OffsetOpcode); //position += 2; v.type = BitConverter.ToInt16(data.Value, position + OffsetType); //position += 2; v.pointerType = BitConverter.ToInt16(data.Value, position + OffsetPointerType); //position += 2; // TODO: change this to ToInt32 to make it big endian compatible v.nextExpression.Index = BitConverter.ToUInt16(data.Value, position + OffsetNextExp); //position += 2; v.nextExpression.Salt = BitConverter.ToInt16(data.Value, position + OffsetNextExp + 2); //position += 2; v.pointer = BitConverter.ToInt32(data.Value, position + OffsetPointer); //position += 4; v.data[0] = data.Value[position + OffsetData]; //position += 1; v.data[1] = data.Value[position + OffsetData + 1]; //position += 1; v.data[2] = data.Value[position + OffsetData + 2]; //position += 1; v.data[3] = data.Value[position + OffsetData + 3]; //position += 1; } return(value); }
/// <summary> /// Postprocess tag data that has been streamed to a cache block /// </summary> /// <param name="locator">Offset of the tag data header in the section</param> /// <param name="data"></param> /// <returns></returns> internal bool ReconstructTagData(short locator, TagInterface.Data data) { int index = 0; IO.EndianReader er; if (GeometryBlock == null) { return(false); } foreach (geometry_block_resource_block gb in Resources) { er = new BlamLib.IO.EndianReader(GeometryBlock[index]); switch (gb.Type.Value) { #region TagData case (int)geometry_block_resource_type.TagData: if (gb.PrimaryLocater.Value == locator) { data.Reset(er.ReadBytes(gb.Size)); } break; #endregion } index++; er.Close(); er = null; } return(true); }
public static ScriptStringEntry[] FromData(TagInterface.Data data, byte garbage_id) { int offset = 0; System.Text.StringBuilder stringEntry; ScriptStringEntry[] ste; List <ScriptStringEntry> value = new List <ScriptStringEntry>(); for (int x = 0; x < data.Size; x++) { stringEntry = new StringBuilder(); byte btchar = 0; #region (try to) get the string entry... try { do { if (offset < data.Size) { btchar = data[offset]; if (btchar != 0) { stringEntry.Append((char)btchar); } } offset++; } while ((btchar != 0 || btchar != garbage_id) && offset < data.Size); } catch (IndexOutOfRangeException ex) { throw new Debug.ExceptionLog(ex, "Offset was outside the bounds of the data array."); } #endregion // ...and add it value.Add(new ScriptStringEntry(stringEntry.ToString(), offset - (stringEntry.Length + 1))); // we're in the padding area now if (btchar == garbage_id) { break; } } bool found_empty = false; for (int x = 0; x < value.Count; x++) { if (!found_empty) // do this shit until we find the first empty string... { found_empty = value[x].Data == ""; continue; } // then do this for every empty string we may find if (value[x].Data == "" && found_empty) { value.RemoveAt(x--); } } // find the shit we only care for and return it ste = new ScriptStringEntry[value.Count]; for (int x = 0; x < value.Count; x++) { ste[x] = value[x]; } return(ste); }