public static LuaConstant ReadConstant(KOARBinaryReader br) { int type = br.ReadInt(1); switch (type) { case 0: return(new LuaConstantNil()); case 1: return(new LuaConstantBool(br.ReadInt(1) == 1)); case 3: return(new LuaConstantNumber(br.ReadInt())); case 4: String s = br.ReadString(); return(new LuaConstantString(s.Substring(0, s.Length - 1))); case 11: return(new LuaConstantUI64(br.ReadUInt64())); default: throw new NotSupportedException(String.Format("constant type {0} is not supported", type)); } }
public override void Load(Stream stream) { KOARBinaryReader br = new KOARBinaryReader(stream); _fileIDs = new List <uint>(); _symbol_names = new List <string>(); _name_hashes = new List <uint>(); var count = br.ReadInt(); Int32 char_array_offset = 8 + count * 12; for (int i = 0; i < count; i++) { _fileIDs.Add(br.ReadUInt()); Int32 str_start = br.ReadInt(); Int32 str_end = br.ReadInt(); br.SavePosition(); br.SetOffset(char_array_offset + str_start); string s = br.ReadString(str_end - str_start); _symbol_names.Add(s); _name_hashes.Add(Utils.SH(s)); br.LoadPosition(); } br.Close(); }
public override void Load(Stream stream) { KOARBinaryReader br = new KOARBinaryReader(stream); br.ReadUInt(); // Always 1 Int32 count = br.ReadInt(); _fileIDs = new List <uint>(); // First list - fileIDs for (int i = 0; i < count; i++) { _fileIDs.Add(br.ReadUInt()); } // Second list - hashes if (br.IsEOF()) { _hashes = null; } else { _hashes = new List <uint>(); for (int i = 0; i < count; i++) { _hashes.Add(br.ReadUInt()); } } br.Close(); }
public override void Load(Stream stream) { KOARBinaryReader br = new KOARBinaryReader(stream); br.ReadInt(); // Always 0 br.ReadInt(); // Always 0 Int32 count1 = br.ReadInt(); Int32 count2 = br.ReadInt(); _records = new List <BundleRecord>(); for (int i = 0; i < count1; i++) { UInt32 fileID = br.ReadUInt(); _records.Add(new BundleRecord(fileID)); } for (int i = 0; i < count1; i++) { _records[i].type = (byte)br.ReadInt(1); } for (int i = 0; i < count1; i++) { _records[i].unknown = (byte)br.ReadInt(1); } for (int i = 0; i < count1; i++) { _records[i].bundle = br.ReadInt(1) == 1; } // TODO: add second list br.Close(); }
public override void Load(Stream stream) { KOARBinaryReader br = new KOARBinaryReader(stream); // Metadata Module = br.ReadString(); PrehashedFunctions = new List <string>(); var count = br.ReadInt(); for (int i = 0; i < count; i++) { PrehashedFunctions.Add(br.ReadString()); } br.ReadInt(); // Size of Lua chunk // Lua // header _header = new LuaHeader(); _header.Singature = br.ReadUInt(); _header.Version = (byte)br.ReadInt(1); _header.Format = (byte)br.ReadInt(1); _header.Endian = (LuaHeader.ChunkEndian)br.ReadInt(1); _header.SizeOfInt = (byte)br.ReadInt(1); _header.SizeOfSize_T = (byte)br.ReadInt(1); _header.SizeOfInstruction = (byte)br.ReadInt(1); _header.SizeOfLuaNumber = (byte)br.ReadInt(1); _header.IntegralFlag = (byte)br.ReadInt(1); _header.Unknown1 = (byte)br.ReadInt(1); _header.Unknown2 = (byte)br.ReadInt(1); if (_header.Endian == LuaHeader.ChunkEndian.big) { br.SetLittleEndian(false); } // value types br.Read(224); // main function Root = LuaFunction.ReadFunction(br); // KoreVM footer _footer = br.Read(8); br.Close(); }
public static LuaFunction ReadFunction(KOARBinaryReader br) { LuaFunction func = new LuaFunction(); // header func.Source = br.ReadString(); func.Name = br.ReadString(); func.LinesDefined = new Tuple <int, int>(br.ReadInt(), br.ReadInt()); func.Upvalues_Count = br.ReadInt(); func.Arguments = br.ReadInt(); func.Vararg = (byte)br.ReadInt(1); func.StackSize = br.ReadInt(); // instructions int count = br.ReadInt(); for (int i = 0; i < count; i++) { func.Instructions.Add(new LuaInstruction(br.ReadUInt())); } // constants count = br.ReadInt(); for (int i = 0; i < count; i++) { func.Constants.Add(LuaConstant.ReadConstant(br)); } // functions count = br.ReadInt(); for (int i = 0; i < count; i++) { func.Functions.Add(LuaFunction.ReadFunction(br)); } // Debug lists // source lines count = br.ReadInt(); for (int i = 0; i < count; i++) { func.Debug_SourceLines.Add(br.ReadInt()); } // locals count = br.ReadInt(); for (int i = 0; i < count; i++) { String name = br.ReadString(); int line_start = br.ReadInt(); int line_end = br.ReadInt(); func.Debug_Locals.Add(new Tuple <string, int, int>(name, line_start, line_end)); } // upvalues count = br.ReadInt(); for (int i = 0; i < count; i++) { func.Debug_UpvalueNames.Add(br.ReadString()); } return(func); }
private void Load(KOARBinaryReader br) { List <BxmlRecord> records = new List <BxmlRecord>(); var count = br.ReadInt(); for (int i = 0; i < count; i++) { BxmlRecord record = new BxmlRecord(); record.Parent = br.ReadInt(); record.FirstChild = br.ReadInt(); record.Next = br.ReadInt(); record.PropertiesCount = br.ReadInt(); record.PropertiesStartIndex = br.ReadInt(); records.Add(record); } List <UInt32> properties = new List <UInt32>(); count = br.ReadInt(); for (int i = 0; i < count; i++) { properties.Add(br.ReadUInt()); } List <UInt32> tags = new List <UInt32>(); count = br.ReadInt(); for (int i = 0; i < count; i++) { tags.Add(br.ReadUInt()); } List <String> strings = new List <string>(); count = br.ReadInt(); for (int i = 0; i < count; i++) { String s = br.ReadString(); //s = s.Replace("\x0d\x0a", "\\n"); strings.Add(s); } List <UInt32> loc_keys = new List <uint>(); count = br.ReadInt(); for (int i = 0; i < count; i++) { loc_keys.Add(br.ReadUInt()); } // Rebuilding XML Xml = new XDocument(); List <XElement> XmlRecords = new List <XElement>(); for (int i = 0; i < records.Count; i++) { XElement elem = new XElement("ELEMENT"); XmlRecords.Add(elem); if (records[i].Parent != -1) { XmlRecords[records[i].Parent].Add(elem); } for (int j = records[i].PropertiesStartIndex; j < records[i].PropertiesStartIndex + records[i].PropertiesCount; j++) { var tag_index = (int)properties[j] & 0x00000fff; var data_index = (int)(properties[j] & 0x00fff000) >> 12; var data_type = (properties[j] & 0xff000000) >> 24; var tag_name = GetTagName(tags[tag_index]); String data = ""; if (data_type == 0x60) { // string data = strings[data_index]; } else if (data_type == 0x80) { // loc_key data = String.Format("loc_key:{0}", loc_keys[data_index].ToString("X")); } if (j == records[i].PropertiesStartIndex) { elem.Name = tag_name; if (_unmodified || records[i].FirstChild == -1) { elem.Value = data; } } else { elem.Add(new XAttribute(tag_name, data)); } } } Xml.Add(XmlRecords[0]); }