public TngFile(System.IO.Stream fileStream)
        {
            using (TngBinaryReader reader = new TngBinaryReader(EndianBitConverter.Little, fileStream))
            {
                magic = reader.ReadInt32();
                if (magic != 100)
                {
                    throw new Exception("This is not a tng file!");
                }
                entryCount = reader.ReadInt32();
                infoSize = reader.ReadInt32();
                long endInfoLocation = reader.BaseStream.Position + infoSize;

                TngInfo info;
                TngInfo = new SortedDictionary<int, TngInfo>();
                while (reader.BaseStream.Position < endInfoLocation)
                {
                    info = new TngInfo(reader, this);
                }

                TngEntry = new TngEntry[entryCount];
                TngEntry tngEntry;
                for (int i = 0; i < entryCount; i++)
                {
                    tngEntry = new TngEntry(reader, this);
                    TngEntry[tngEntry.Id] = tngEntry;
                }
            }
        }
Example #2
0
        public TngFile(System.IO.Stream fileStream)
        {
            using (TngBinaryReader reader = new TngBinaryReader(EndianBitConverter.Little, fileStream))
            {
                magic = reader.ReadInt32();
                if (magic != 100)
                {
                    throw new Exception("This is not a tng file!");
                }
                entryCount = reader.ReadInt32();
                infoSize   = reader.ReadInt32();
                long endInfoLocation = reader.BaseStream.Position + infoSize;

                TngInfo info;
                TngInfo = new SortedDictionary <int, TngInfo>();
                while (reader.BaseStream.Position < endInfoLocation)
                {
                    info = new TngInfo(reader, this);
                }

                TngEntry = new TngEntry[entryCount];
                TngEntry tngEntry;
                for (int i = 0; i < entryCount; i++)
                {
                    tngEntry = new TngEntry(reader, this);
                    TngEntry[tngEntry.Id] = tngEntry;
                }
            }
        }
Example #3
0
        public TngEntry(TngBinaryReader reader, TngFile file, bool isParent = true)
        {
            File   = file;
            InfoId = reader.ReadInt32();
            Data   = new Dictionary <string, object>();

            if (isParent)
            {
                Id = reader.ReadInt16();
                Data.Add("InstructionCode", reader.ReadInt32());
                switch ((int)Data["InstructionCode"])
                {
                case 0:
                    Data.Add("Val", reader.ReadSingle());
                    break;

                case 1:
                    Data.Add("LinkedInfoId", reader.ReadInt32());
                    Data.Add("Val", reader.ReadSingle());
                    break;

                default:
                    throw new Exception("Invalid instruction code!");
                }

                Data.Add("InstructionCode2", reader.ReadInt32());
                switch ((int)Data["InstructionCode2"])
                {
                case 4:
                case 1:
                case 0:
                    Data.Add("Val2", reader.ReadSingle());
                    Data.Add("Val3", reader.ReadSingle());
                    break;

                case 3:
                    Data.Add("LinkedInfoId2", reader.ReadInt32());
                    break;

                default:
                    throw new Exception("Invalid instruction code 2! " + reader.BaseStream.Position);
                }

                ChildEntry = new TngEntry[reader.ReadInt32()];
                for (int i = 0; i < ChildEntry.Length; i++)
                {
                    ChildEntry[i] = new TngEntry(reader, file, false);
                }
            }
            else
            {
                Id = -1;
                Data.Add("Val", reader.ReadSingle());
                Data.Add("Val2", reader.ReadSingle());
                Data.Add("Num", reader.ReadInt32());
                ChildEntry = new TngEntry[0];
            }
        }
        public TngEntry(TngBinaryReader reader, TngFile file, bool isParent = true)
        {
            File = file;
            InfoId = reader.ReadInt32();
            Data = new Dictionary<string, object>();

            if (isParent)
            {
                Id = reader.ReadInt16();
                Data.Add("InstructionCode", reader.ReadInt32());
                switch ((int)Data["InstructionCode"])
                {
                    case 0:
                        Data.Add("Val", reader.ReadSingle());
                        break;
                    case 1:
                        Data.Add("LinkedInfoId", reader.ReadInt32());
                        Data.Add("Val", reader.ReadSingle());
                        break;
                    default:
                        throw new Exception("Invalid instruction code!");
                }

                Data.Add("InstructionCode2", reader.ReadInt32());
                switch ((int)Data["InstructionCode2"])
                {
                    case 4:
                    case 1:
                    case 0:
                        Data.Add("Val2", reader.ReadSingle());
                        Data.Add("Val3", reader.ReadSingle());
                        break;
                    case 3:
                        Data.Add("LinkedInfoId2", reader.ReadInt32());
                        break;
                    default:
                        throw new Exception("Invalid instruction code 2! " + reader.BaseStream.Position);
                }

                ChildEntry = new TngEntry[reader.ReadInt32()];
                for (int i = 0; i < ChildEntry.Length; i++)
                {
                    ChildEntry[i] = new TngEntry(reader, file, false);
                }
            }
            else
            {
                Id = -1;
                Data.Add("Val", reader.ReadSingle());
                Data.Add("Val2", reader.ReadSingle());
                Data.Add("Num", reader.ReadInt32());
                ChildEntry = new TngEntry[0];
            }
        }
Example #5
0
        public TreeNode CreateTreeViewNode(TngEntry entry)
        {
            TreeNode treeNode = new TreeNode();

            treeNode.Text = entry.Name;
            treeNode.Tag  = entry;
            foreach (TngEntry subEntry in entry.ChildEntry)
            {
                treeNode.Nodes.Add(CreateTreeViewNode(subEntry));
            }
            return(treeNode);
        }
 public TreeNode CreateTreeViewNode(TngEntry entry)
 {
     TreeNode treeNode = new TreeNode();
     treeNode.Text = entry.Name;
     treeNode.Tag = entry;
     foreach (TngEntry subEntry in entry.ChildEntry)
     {
         treeNode.Nodes.Add(CreateTreeViewNode(subEntry));
     }
     return treeNode;
 }