Ejemplo n.º 1
0
        public CtfFile(string _fileName, System.IO.Stream fileStream, CtfEditorGamePage _page)
            : base(_fileName, fileStream, _page)
        {
            int flag = -1;

            using (CtfBinaryReader reader = new CtfBinaryReader(EndianBitConverter.Little, fileStream))
            {
                foreach (CtfEntryInfo entryInfo in parentPage.ctfEntryInfo)
                {
                    try
                    {
                        if (entryInfo.name == "magic")
                        {
                            entry.Add(entryInfo.id, reader.ReadInt32());
                        }
                        else if (entryInfo.name == "flag")
                        {
                            entry.Add(entryInfo.id, reader.ReadInt32());
                            flag = (int)entry[entryInfo.id];
                        }
                        else if (entryInfo.IsUsed(flag))
                        {
                            if (entryInfo.linkID != -1)
                            {
                                CtfEntryInfo linkedEntryInfo = parentPage.ctfEntryInfo.First(x => x.refID == entryInfo.linkID);
                                if (Convert.ToBoolean(entry[linkedEntryInfo.id]))
                                {
                                    entry.Add(entryInfo.id, reader.ReadEntryData(entryInfo.type));
                                }
                            }
                            else
                            {
                                entry.Add(entryInfo.id, reader.ReadEntryData(entryInfo.type));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message + Environment.NewLine + entryInfo.id + " " + entryInfo.name);
                    }
                }
                CtfEntryInfo last = parentPage.ctfEntryInfo.Last(x => x.minFlag == 0);
                if (!entry.ContainsKey(last.id))
                {
                    throw new Exception("Reader did not read last required value");
                }
                // Use -1 For Dirt 3, hopefully won't cause problems with other games
                //System.Windows.Forms.MessageBox.Show(reader.BaseStream.Position + " " + reader.BaseStream.Length);
                if (reader.BaseStream.Position < reader.BaseStream.Length - 1)
                {
                    throw new Exception("Reader did not reach end of file!");
                }

                parentPage.files.Add(this);
            }
        }
Ejemplo n.º 2
0
        public CtfFile(string _fileName, System.IO.Stream fileStream, CtfEditorGamePage _page)
            : base(_fileName, fileStream, _page)
        {
            int flag = -1;

            using (CtfBinaryReader reader = new CtfBinaryReader(EndianBitConverter.Little, fileStream))
            {
                foreach (CtfEntryInfo entryInfo in parentPage.ctfEntryInfo)
                {
                    try
                    {
                        if (entryInfo.name == "magic")
                        {
                            entry.Add(entryInfo.id, reader.ReadInt32());
                        }
                        else if (entryInfo.name == "flag")
                        {
                            entry.Add(entryInfo.id, reader.ReadInt32());
                            flag = (int)entry[entryInfo.id];
                        }
                        else if (entryInfo.IsUsed(flag))
                        {
                            if (entryInfo.linkID != -1)
                            {
                                CtfEntryInfo linkedEntryInfo = parentPage.ctfEntryInfo.First(x => x.refID == entryInfo.linkID);
                                if (Convert.ToBoolean(entry[linkedEntryInfo.id]))
                                {
                                    entry.Add(entryInfo.id, reader.ReadEntryData(entryInfo.type));
                                }
                            }
                            else
                            {
                                entry.Add(entryInfo.id, reader.ReadEntryData(entryInfo.type));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message + Environment.NewLine + entryInfo.id + " " + entryInfo.name);
                    }
                }
                CtfEntryInfo last = parentPage.ctfEntryInfo.Last(x => x.minFlag == 0);
                if (!entry.ContainsKey(last.id))
                {
                    throw new Exception("Reader did not read last required value");
                }
                // Use -1 For Dirt 3, hopefully won't cause problems with other games
                //System.Windows.Forms.MessageBox.Show(reader.BaseStream.Position + " " + reader.BaseStream.Length);
                if (reader.BaseStream.Position < reader.BaseStream.Length - 1)
                {
                    throw new Exception("Reader did not reach end of file!");
                }

                parentPage.files.Add(this);
            }
        }