コード例 #1
0
        private static void OnLoad()
        {
            try{
                if (!File.Exists(Path.Combine("Saves/Commands/", "Commands.bin")))
                {
                    return;
                }

                using (FileStream bin = new FileStream(Path.Combine("Saves/Commands/", "Commands.bin"), FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    GenericReader reader = new BinaryFileReader(new BinaryReader(bin));

                    int version = reader.ReadInt();

                    int count = reader.ReadInt();

                    object[] obj;
                    for (int i = 0; i < count; ++i)
                    {
                        obj    = new object[3];
                        obj[0] = reader.ReadString();
                        obj[1] = reader.ReadString();
                        obj[2] = reader.ReadInt();
                        s_InitInfo.Add(obj);
                    }
                }
            }catch { Errors.Report("Commands-> OnLoad"); }
        }
コード例 #2
0
        public void Deserialize()
        {
            FileInfo info = new FileInfo("Data/VoteSystem.cfg");

            if (!info.Exists)
            {
                info.Create().Close();
            }

            if (info.Length == 0)
            {
                return;
            }

            using (BinaryReader br = new BinaryReader(info.OpenRead()))
            {
                GenericReader reader = new BinaryFileReader(br);

                int version = reader.ReadInt();

                switch (version)
                {
                case 0:
                {
                    _DefaultName     = reader.ReadString();
                    _DefaultURL      = reader.ReadString();
                    _DefaultCoolDown = reader.ReadTimeSpan();
                } break;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Loads serialized data
        /// </summary>
        private static void OnWorldLoad()
        {
            if (!File.Exists(DataFile))
            {
                return;
            }

            using (FileStream stream = new FileStream(DataFile, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                BinaryFileReader reader = new BinaryFileReader(new BinaryReader(stream));

                int version = reader.ReadInt();

                switch (version)
                {
                case 0:
                    int tableCount = reader.ReadInt();
                    PerkTable = new Dictionary <Player, Tuple <Perk, Perk> >(tableCount);

                    Player player;
                    Perk   p1, p2;

                    try
                    {
                        for (int i = 0; i < tableCount; i++)
                        {
                            player = reader.ReadMobile <Player>();

                            if (player == null || player.Deleted)
                            {
                                continue;
                            }

                            ConstructorInfo ctor = GetPerkCtor(reader.ReadString());
                            p1 = ctor.Invoke(new object[] { reader }) as Perk;

                            ctor = GetPerkCtor(reader.ReadString());
                            p2   = ctor.Invoke(new object[] { reader }) as Perk;

                            PerkTable[player] = Tuple.Create <Perk, Perk>(p1, p2);
                        }
                    }

                    catch (Exception e)
                    {
                        Utilities.ExceptionManager.LogException("Perk", e);
                    }

                    break;
                }

                reader.Close();
            }
        }
コード例 #4
0
        private void ReadRumors(BinaryFileReader reader)
        {
            uint rumNr = reader.ReadUInt32();

            Console.WriteLine("Rumor count: " + rumNr);

            for (int it = 0; it < rumNr; it++)
            {
                string name = reader.ReadString();
                string text = reader.ReadString();
                Console.WriteLine(string.Format("Rumor: name={0} text={1}", name, text));
            }
        }
コード例 #5
0
        private void ReadHeader(BinaryFileReader reader)
        {
            // Check map for validity
            // Note: disabled, causes decompression of the entire file ( = SLOW)
            //if(inputStream->getSize() < 50)
            //{
            //	throw std::runtime_error("Corrupted map file.");
            //}

            // Map version
            UInt32 byte1 = reader.ReadUInt32();

            Console.WriteLine("Map version:" + byte1);
            mapObject.Header.Version = (EMapFormat)byte1;


            mapObject.Header.AreAnyPlayers = reader.ReadBool();
            Console.WriteLine("AreAnyPlayers:" + mapObject.Header.AreAnyPlayers);

            mapObject.Header.Height = reader.ReadUInt32();
            mapObject.Header.Width  = mapObject.Header.Height;
            Console.WriteLine("Map Height and Width:" + mapObject.Header.Height);

            mapObject.Header.IsTwoLevel = reader.ReadBool();
            Console.WriteLine("twoLevel:" + mapObject.Header.IsTwoLevel);


            mapObject.Header.Name = reader.ReadString();
            Console.WriteLine("Name:" + mapObject.Header.Name);

            mapObject.Header.Description = reader.ReadString();
            Console.WriteLine("Description:" + mapObject.Header.Description);

            mapObject.Header.Difficulty = reader.ReadUInt8();
            Console.WriteLine("Difficulty:" + mapObject.Header.Difficulty);

            int heroLevelLimit = reader.ReadUInt8();

            Console.WriteLine("HeroLevelLimit:" + heroLevelLimit);


            ReadPlayerInfo(reader);

            ReadVictoryLossConditions(reader);

            ReadTeamInfo(reader);

            ReadAllowedHeroes(reader);
        }
コード例 #6
0
ファイル: MoTD.cs プロジェクト: OrbitStorm/Defiance-UOR-1.10
        private static void Deserialize()
        {
            if (File.Exists(m_FilePath))
            {
                using (FileStream fs = new FileStream(m_FilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    try
                    {
                        BinaryReader     br     = new BinaryReader(fs);
                        BinaryFileReader reader = new BinaryFileReader(br);

                        int version = reader.ReadInt();

                        int count = reader.ReadInt();
                        for (int i = 0; i < count; i++)
                        {
                            string subject = reader.ReadString();
                            string body    = reader.ReadString();

                            int       linkcount = reader.ReadInt();
                            ArrayList links     = new ArrayList();
                            for (int j = 0; j < linkcount; j++)
                            {
                                links.Add(reader.ReadString());
                            }

                            m_Messages.Add(new MotDStruct(subject, body, links));
                        }
                    }

                    catch (Exception error)
                    {
                        Console.WriteLine(error.ToString());
                    }
                    finally
                    {
                        fs.Close();
                    }
                }
            }
        }
コード例 #7
0
        public void Deserialize(BinaryFileReader reader)
        {
            int version = reader.ReadInt();

            if (version >= 0)
            {
                serialString = reader.ReadString();

                allianceLeader = reader.ReadMobile() as Player;

                int count = reader.ReadInt();

                for (int n = 1; n <= count; n++)
                {
                    membersOf.Add(reader.ReadMobile());
                }

                int guildCount = reader.ReadInt();

                for (int x = 1; x <= guildCount; x++)
                {
                    childGuilds.Add(reader.ReadGuild() as Guild);
                }

                allianceName = reader.ReadString();
                primaryHue   = reader.ReadInt();
                secondaryHue = reader.ReadInt();
                mountBody    = reader.ReadInt();
                mountID      = reader.ReadInt();

                foreach (Mobile m in membersOf)
                {
                    if (m is Player)
                    {
                        Player p = m as Player;
                        p.CurrentAlliance = this;
                    }
                }
            }
        }
コード例 #8
0
        public void Deserialize()
        {
            //Console.WriteLine("[Vote System]: Loading Config...");

            FileInfo info = new FileInfo("Data\\VoteSystem.cfg");

            if (!info.Exists)
            {
                info.Create().Close();
            }

            if (info.Length == 0)
            {
                return;
            }

            using (BinaryReader br = new BinaryReader(info.OpenRead()))
            {
                BinaryFileReader bin = new BinaryFileReader(br);

                int version = bin.ReadInt();

                switch (version)
                {
                case 1:
                    _DefaultGold = bin.ReadInt();
                    goto case 0;

                case 0:
                    _DefaultName     = bin.ReadString();
                    _DefaultURL      = bin.ReadString();
                    _DefaultCoolDown = bin.ReadTimeSpan();
                    break;
                }
                bin.Close();
            }

            //Console.WriteLine("[Vote System]: Done.");
        }
コード例 #9
0
ファイル: PlayerMacros.cs プロジェクト: uotools/JuicyUO
        private bool Unserialize(BinaryFileReader reader)
        {
            uint magic = reader.ReadUInt();

            if (magic != MAGIC)
            {
                return(false);
            }

            if (m_Macros == null)
            {
                m_Macros = new List <Action>();
            }
            m_Macros.Clear();

            int version = reader.ReadInt();
            int count   = reader.ReadInt();

            for (int i = 0; i < count; i++)
            {
                Action action = new Action();
                action.Keystroke = (WinKeys)reader.ReadUShort();
                action.Ctrl      = reader.ReadBool();
                action.Alt       = reader.ReadBool();
                action.Shift     = reader.ReadBool();
                reader.ReadBool(); // unused filler byte

                int macroCount = reader.ReadUShort();
                for (int j = 0; j < macroCount; j++)
                {
                    int type = reader.ReadInt();
                    Macro.ValueTypes valueType = (Macro.ValueTypes)reader.ReadByte();
                    if (valueType == Macro.ValueTypes.Integer)
                    {
                        action.Macros.Add(new Macro((MacroType)type, reader.ReadInt()));
                    }
                    else if (valueType == Macro.ValueTypes.String)
                    {
                        action.Macros.Add(new Macro((MacroType)type, reader.ReadString()));
                    }
                    else
                    {
                        action.Macros.Add(new Macro((MacroType)type));
                    }
                }

                m_Macros.Add(action);
            }

            return(true);
        }
コード例 #10
0
ファイル: PlayerMacros.cs プロジェクト: BclEx/object-assets
        private bool Unserialize(BinaryFileReader r)
        {
            var magic = r.ReadUInt();

            if (magic != MAGIC)
            {
                return(false);
            }

            if (_macros == null)
            {
                _macros = new List <Action>();
            }
            _macros.Clear();
            var version = r.ReadInt();
            var count   = r.ReadInt();

            for (var i = 0; i < count; i++)
            {
                var action = new Action();
                action.Keystroke = (WinKeys)r.ReadUShort();
                action.Ctrl      = r.ReadBool();
                action.Alt       = r.ReadBool();
                action.Shift     = r.ReadBool();
                r.ReadBool(); // unused filler byte

                var macroCount = r.ReadUShort();
                for (var j = 0; j < macroCount; j++)
                {
                    var type      = r.ReadInt();
                    var valueType = (Macro.ValueTypes)r.ReadByte();
                    if (valueType == Macro.ValueTypes.Integer)
                    {
                        action.Macros.Add(new Macro((MacroType)type, r.ReadInt()));
                    }
                    else if (valueType == Macro.ValueTypes.String)
                    {
                        action.Macros.Add(new Macro((MacroType)type, r.ReadString()));
                    }
                    else
                    {
                        action.Macros.Add(new Macro((MacroType)type));
                    }
                }
                _macros.Add(action);
            }

            return(true);
        }
コード例 #11
0
        public bool Unserialize(BinaryFileReader reader)
        {
            string id = reader.ReadString();

            if (id != c_SerializeIdentifier)
            {
                return(false);
            }
            int version = reader.ReadInt();

            if (version >= 0)
            {
                // version 0
                // 16 byte header
                m_PaletteZero = reader.ReadByte();
                for (int i = 0; i < 4; i++)
                {
                    m_Palettes[i] = reader.ReadByte();
                }
                for (int i = 0; i < 3; i++)
                {
                    reader.ReadByte();
                }

                m_Tilegfx.Reset();
                m_Tilegfx.NextIndex = reader.ReadInt();
                int count = reader.ReadInt();
                for (int i = 0; i < count; i++)
                {
                    int  index = reader.ReadInt();
                    byte tile  = reader.ReadByte();
                    byte page  = reader.ReadByte();
                    m_Tilegfx.AddIndexTilePage(index, tile, page);
                }

                for (int i = 0; i < TilesPerSet; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        m_Metatiles[i][j] = reader.ReadInt();
                    }
                    m_Bitfields[i]  = reader.ReadByte();
                    m_Attributes[i] = reader.ReadByte();
                }
            }
            return(true);
        }
コード例 #12
0
ファイル: ChatMessage.cs プロジェクト: zerodowned/Ulmeta
        public ChatMessage(BinaryFileReader reader)
        {
            int version = reader.ReadInt();

            switch (version)
            {
            case 1:
            case 0:
            {
                _client    = reader.ReadMobile();
                _message   = reader.ReadString();
                _recipient = reader.ReadMobile();
                _timestamp = reader.ReadDateTime();

                break;
            }
            }
        }
コード例 #13
0
        static void EventSink_WorldLoad()
        {
            logs = new List <LogObject>();
            if (!File.Exists(m_File))
            {
                return;
            }
            if (new FileInfo(m_File).Length <= 3)
            {
                return;
            }
            BinaryFileReader br = new BinaryFileReader(new BinaryReader(new FileStream(m_File, FileMode.OpenOrCreate, FileAccess.Read)));
            int read            = br.ReadInt();

            for (int i = 0; i < read; i++)
            {
                logs.Add(new LogObject(br.ReadMobile(), br.ReadString()));
            }
        }
コード例 #14
0
        private void ReadDisposedHeroes(BinaryFileReader reader)
        {
            if (mapObject.Header.Version >= EMapFormat.SOD)
            {
                int disp = reader.ReadUInt8();
                Console.WriteLine("ReadDisposedHeroes: Total=" + disp);
                for (int g = 0; g < disp; ++g)
                {
                    int    heroId   = reader.ReadUInt8();
                    int    portrait = reader.ReadUInt8();
                    string name     = reader.ReadString();
                    int    players  = reader.ReadUInt8();
                    Console.WriteLine(string.Format("ReadDisposedHeroes: id={0} portrait={1} name={2} players={3}", heroId, portrait, name, players));
                }
            }

            //omitting NULLS
            reader.Skip(31);
        }
コード例 #15
0
        private void ReadObjectTemplates(BinaryFileReader reader)
        {
            uint defAmount = reader.ReadUInt32();

            Console.WriteLine("ReadObjectTemplates totally:" + defAmount);

            // Read custom defs
            for (int idd = 0; idd < defAmount; ++idd)
            {
                string animationFile = reader.ReadString();
                Console.WriteLine("Object Animation File:" + animationFile);

                int[] blockMask = new int[6];
                int[] visitMask = new int[6];

                foreach (int val in blockMask)
                {
                    int r = reader.ReadUInt8();
                    //Console.WriteLine("BlockMask: " + r);
                }

                foreach (int val in visitMask)
                {
                    int r = reader.ReadUInt8();
                    //Console.WriteLine("VisitMask: " + r);
                }

                reader.ReadUInt16();
                int terrMask = reader.ReadUInt16();

                uint objectId      = reader.ReadUInt32();
                uint objectSubId   = reader.ReadUInt32();
                int  type          = reader.ReadUInt8();
                int  printPriority = reader.ReadUInt8() * 100;

                reader.Skip(16);
            }
        }
コード例 #16
0
ファイル: XmlAttach.cs プロジェクト: jasegiffin/JustUO
		public static void Load()
		{
			string filePath = Path.Combine("Saves/Attachments", "Attachments.bin"); // the attachment serializations
			string imaPath = Path.Combine("Saves/Attachments", "Attachments.ima"); // the item/mob attachment tables
			string fpiPath = Path.Combine("Saves/Attachments", "Attachments.fpi"); // the file position indices

			if (!File.Exists(filePath))
			{
				return;
			}

			FileStream fs = null;
			BinaryFileReader reader = null;
			FileStream imafs = null;
			BinaryFileReader imareader = null;
			FileStream fpifs = null;
			BinaryFileReader fpireader = null;

			try
			{
				fs = new FileStream(filePath, (FileMode)3, (FileAccess)1, (FileShare)1);
				reader = new BinaryFileReader(new BinaryReader(fs));
				imafs = new FileStream(imaPath, (FileMode)3, (FileAccess)1, (FileShare)1);
				imareader = new BinaryFileReader(new BinaryReader(imafs));
				fpifs = new FileStream(fpiPath, (FileMode)3, (FileAccess)1, (FileShare)1);
				fpireader = new BinaryFileReader(new BinaryReader(fpifs));
			}
			catch (Exception e)
			{
				ErrorReporter.GenerateErrorReport(e.ToString());
				return;
			}

			if (reader != null && imareader != null && fpireader != null)
			{
				// restore the current global attachment serial state
				try
				{
					ASerial.GlobalDeserialize(reader);
				}
				catch (Exception e)
				{
					ErrorReporter.GenerateErrorReport(e.ToString());
					return;
				}

				ASerial.serialInitialized = true;

				// read in the serial attachment hash table information
				int count = 0;
				try
				{
					count = reader.ReadInt();
				}
				catch (Exception e)
				{
					ErrorReporter.GenerateErrorReport(e.ToString());
					return;
				}

				for (int i = 0; i < count; i++)
				{
					// read the serial
					ASerial serialno = null;
					try
					{
						serialno = new ASerial(reader.ReadInt());
					}
					catch (Exception e)
					{
						ErrorReporter.GenerateErrorReport(e.ToString());
						return;
					}

					// read the attachment type
					string valuetype = null;
					try
					{
						valuetype = reader.ReadString();
					}
					catch (Exception e)
					{
						ErrorReporter.GenerateErrorReport(e.ToString());
						return;
					}

					// read the position of the beginning of the next attachment deser within the .bin file
					long position = 0;
					try
					{
						position = fpireader.ReadLong();
					}
					catch (Exception e)
					{
						ErrorReporter.GenerateErrorReport(e.ToString());
						return;
					}

					bool skip = false;

					XmlAttachment o = null;
					try
					{
						o = (XmlAttachment)Activator.CreateInstance(Type.GetType(valuetype), new object[] {serialno});
					}
					catch
					{
						skip = true;
					}

					if (skip)
					{
						if (!AlreadyReported(valuetype))
						{
							Console.WriteLine("\nError deserializing attachments {0}.\nMissing a serial constructor?\n", valuetype);
							ReportDeserError(valuetype, "Missing a serial constructor?");
						}
						// position the .ima file at the next deser point
						try
						{
							reader.Seek(position, SeekOrigin.Begin);
						}
						catch
						{
							ErrorReporter.GenerateErrorReport(
								"Error deserializing. Attachments save file corrupted. Attachment load aborted.");
							return;
						}
						continue;
					}

					try
					{
						o.Deserialize(reader);
					}
					catch
					{
						skip = true;
					}

					// confirm the read position
					if (reader.Position != position || skip)
					{
						if (!AlreadyReported(valuetype))
						{
							Console.WriteLine("\nError deserializing attachments {0}\n", valuetype);
							ReportDeserError(valuetype, "save file corruption or incorrect Serialize/Deserialize methods?");
						}
						// position the .ima file at the next deser point
						try
						{
							reader.Seek(position, SeekOrigin.Begin);
						}
						catch
						{
							ErrorReporter.GenerateErrorReport(
								"Error deserializing. Attachments save file corrupted. Attachment load aborted.");
							return;
						}
						continue;
					}

					// add it to the hash table
					try
					{
						AllAttachments.Add(serialno.Value, o);
					}
					catch
					{
						ErrorReporter.GenerateErrorReport(
							String.Format(
								"\nError deserializing {0} serialno {1}. Attachments save file corrupted. Attachment load aborted.\n",
								valuetype,
								serialno.Value));
						return;
					}
				}

				// read in the mobile attachment hash table information
				try
				{
					count = imareader.ReadInt();
				}
				catch (Exception e)
				{
					ErrorReporter.GenerateErrorReport(e.ToString());
					return;
				}

				for (int i = 0; i < count; i++)
				{
					Mobile key = null;
					try
					{
						key = imareader.ReadMobile();
					}
					catch (Exception e)
					{
						ErrorReporter.GenerateErrorReport(e.ToString());
						return;
					}

					int nattach = 0;
					try
					{
						nattach = imareader.ReadInt();
					}
					catch (Exception e)
					{
						ErrorReporter.GenerateErrorReport(e.ToString());
						return;
					}

					for (int j = 0; j < nattach; j++)
					{
						// and serial
						ASerial serialno = null;
						try
						{
							serialno = new ASerial(imareader.ReadInt());
						}
						catch (Exception e)
						{
							ErrorReporter.GenerateErrorReport(e.ToString());
							return;
						}

						// read the attachment type
						string valuetype = null;
						try
						{
							valuetype = imareader.ReadString();
						}
						catch (Exception e)
						{
							ErrorReporter.GenerateErrorReport(e.ToString());
							return;
						}

						// read the position of the beginning of the next attachment deser within the .bin file
						long position = 0;
						try
						{
							position = fpireader.ReadLong();
						}
						catch (Exception e)
						{
							ErrorReporter.GenerateErrorReport(e.ToString());
							return;
						}

						XmlAttachment o = FindAttachmentBySerial(serialno.Value);

						if (o == null || imareader.Position != position)
						{
							if (!AlreadyReported(valuetype))
							{
								Console.WriteLine("\nError deserializing attachments of type {0}.\n", valuetype);
								ReportDeserError(valuetype, "save file corruption or incorrect Serialize/Deserialize methods?");
							}
							// position the .ima file at the next deser point
							try
							{
								imareader.Seek(position, SeekOrigin.Begin);
							}
							catch
							{
								ErrorReporter.GenerateErrorReport(
									"Error deserializing. Attachments save file corrupted. Attachment load aborted.");
								return;
							}
							continue;
						}

						// attachment successfully deserialized so attach it
						AttachTo(key, o, false);
					}
				}

				// read in the item attachment hash table information
				try
				{
					count = imareader.ReadInt();
				}
				catch (Exception e)
				{
					ErrorReporter.GenerateErrorReport(e.ToString());
					return;
				}

				for (int i = 0; i < count; i++)
				{
					Item key = null;
					try
					{
						key = imareader.ReadItem();
					}
					catch (Exception e)
					{
						ErrorReporter.GenerateErrorReport(e.ToString());
						return;
					}

					int nattach = 0;
					try
					{
						nattach = imareader.ReadInt();
					}
					catch (Exception e)
					{
						ErrorReporter.GenerateErrorReport(e.ToString());
						return;
					}

					for (int j = 0; j < nattach; j++)
					{
						// and serial
						ASerial serialno = null;
						try
						{
							serialno = new ASerial(imareader.ReadInt());
						}
						catch (Exception e)
						{
							ErrorReporter.GenerateErrorReport(e.ToString());
							return;
						}

						// read the attachment type
						string valuetype = null;
						try
						{
							valuetype = imareader.ReadString();
						}
						catch (Exception e)
						{
							ErrorReporter.GenerateErrorReport(e.ToString());
							return;
						}

						// read the position of the beginning of the next attachment deser within the .bin file
						long position = 0;
						try
						{
							position = fpireader.ReadLong();
						}
						catch (Exception e)
						{
							ErrorReporter.GenerateErrorReport(e.ToString());
							return;
						}

						XmlAttachment o = FindAttachmentBySerial(serialno.Value);

						if (o == null || imareader.Position != position)
						{
							if (!AlreadyReported(valuetype))
							{
								Console.WriteLine("\nError deserializing attachments of type {0}.\n", valuetype);
								ReportDeserError(valuetype, "save file corruption or incorrect Serialize/Deserialize methods?");
							}
							// position the .ima file at the next deser point
							try
							{
								imareader.Seek(position, SeekOrigin.Begin);
							}
							catch
							{
								ErrorReporter.GenerateErrorReport(
									"Error deserializing. Attachments save file corrupted. Attachment load aborted.");
								return;
							}
							continue;
						}

						// attachment successfully deserialized so attach it
						AttachTo(key, o, false);
					}
				}
				if (fs != null)
				{
					fs.Close();
				}
				if (imafs != null)
				{
					imafs.Close();
				}
				if (fpifs != null)
				{
					fpifs.Close();
				}

				if (desererror != null)
				{
					ErrorReporter.GenerateErrorReport("Error deserializing particular attachments.");
				}
			}
		}
コード例 #17
0
ファイル: XNBReader.cs プロジェクト: FreeReign/UltimaXNA
        private static List<Encoder> InternalGetEncoders(GraphicsDevice device, BinaryFileReader reader)
        {
            List<Encoder> list = new List<Encoder>();
            int reader_count = reader.Read7BitEncodedInt();
            Regex regex = new Regex(@"\b([a-z0-9_]+)(,|$)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);

            for (int i = 0; i < reader_count; i++)
            {
                string reader_name = reader.ReadString();
                int reader_version = reader.ReadInt();
                string typeReaderShortName = regex.Match(reader_name).Groups[1].Value;
                if (typeReaderShortName.IndexOf("Reader") != -1)
                    typeReaderShortName = typeReaderShortName.Substring(0, typeReaderShortName.IndexOf("Reader"));
                bool isList = (reader_name.IndexOf("ListReader") != -1);

                Encoder encoder = new Encoder(typeReaderShortName, isList);
                list.Add(encoder);
            }

            return list;
        }
コード例 #18
0
        private static void Deserialize()
        {
            if (File.Exists(m_FilePath))
            {
                using (FileStream fs = new FileStream(m_FilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    try
                    {
                        BinaryReader br = new BinaryReader(fs);
                        BinaryFileReader reader = new BinaryFileReader(br);

                        int version = reader.ReadInt();

                        int count = reader.ReadInt();
                        for (int i = 0; i < count; i++)
                        {
                            string subject = reader.ReadString();
                            string body = reader.ReadString();

                            int linkcount = reader.ReadInt();
                            ArrayList links = new ArrayList();
                            for (int j = 0; j < linkcount; j++)
                                links.Add(reader.ReadString());

                            m_Messages.Add(new MotDStruct(subject, body, links));
                        }
                    }

                    catch (Exception error)
                    {
                        Console.WriteLine(error.ToString());
                    }
                    finally
                    {
                        fs.Close();
                    }
                }
            }
        }
コード例 #19
0
ファイル: VoteConfig.cs プロジェクト: FreeReign/imaginenation
		public void Deserialize()
		{
			//Console.WriteLine("[Vote System]: Loading Config...");

			FileInfo info = new FileInfo("Data\\VoteSystem.cfg");

			if (!info.Exists)
				info.Create().Close();

			if (info.Length == 0)
				return;

			using (BinaryReader br = new BinaryReader(info.OpenRead()))
			{
				BinaryFileReader bin = new BinaryFileReader(br);
	
				int version = bin.ReadInt();

			    switch(version)
			    {
                    case 1:
			            _DefaultGold = bin.ReadInt();
			            goto case 0;
                    case 0:
                        _DefaultName = bin.ReadString();
				        _DefaultURL = bin.ReadString();
				        _DefaultCoolDown = bin.ReadTimeSpan();
			            break;

			    }
				bin.Close();
			}

			//Console.WriteLine("[Vote System]: Done.");
		}
コード例 #20
0
        private void ReadPlayerInfo(BinaryFileReader reader)
        {
            for (int i = 0; i < GameConstants.PLAYER_LIMIT_T; i++)
            {
                PlayerInfo playerInfo = new PlayerInfo();

                Console.WriteLine("Reading Player [" + i.ToString() + "]");

                playerInfo.CanHumanPlay    = reader.ReadBool();
                playerInfo.CanComputerPlay = reader.ReadBool();
                Console.WriteLine("canHumanPlay: " + playerInfo.CanHumanPlay);
                Console.WriteLine("canComputerPlay: " + playerInfo.CanComputerPlay);

                if (!playerInfo.CanHumanPlay && !playerInfo.CanComputerPlay)
                {
                    switch (mapObject.Header.Version)
                    {
                    case EMapFormat.SOD:
                    case EMapFormat.WOG:
                        reader.Skip(13);
                        break;

                    case EMapFormat.AB:
                        reader.Skip(12);
                        break;

                    case EMapFormat.ROE:
                        reader.Skip(6);
                        break;
                    }
                    continue;
                }

                playerInfo.AiTactic = (EAiTactic)reader.ReadUInt8();
                Console.WriteLine("aiTactic:" + playerInfo.AiTactic);

                if (mapObject.Header.Version == EMapFormat.SOD || mapObject.Header.Version == EMapFormat.WOG)
                {
                    playerInfo.P7 = reader.ReadUInt8();
                }
                else
                {
                    playerInfo.P7 = -1;
                }

                Console.WriteLine("p7:" + playerInfo.P7);

                // Reading the Factions for Player
                playerInfo.AllowedFactions = new List <int>();
                int allowedFactionsMask = reader.ReadUInt8();
                Console.WriteLine("allowedFactionsMask:" + allowedFactionsMask);

                int totalFactionCount = GameConstants.F_NUMBER;
                if (mapObject.Header.Version != EMapFormat.ROE)
                {
                    allowedFactionsMask += reader.ReadUInt8() << 8;
                }
                else
                {
                    totalFactionCount--; //exclude conflux for ROE
                }
                for (int fact = 0; fact < totalFactionCount; ++fact)
                {
                    if ((allowedFactionsMask & (1 << fact)) > 0)
                    {
                        playerInfo.AllowedFactions.Add(fact);
                    }
                }

                playerInfo.IsFactionRandom = reader.ReadBool();
                playerInfo.HasMainTown     = reader.ReadBool();
                Console.WriteLine("isFactionRandom:" + playerInfo.IsFactionRandom);
                Console.WriteLine("hasMainTown:" + playerInfo.HasMainTown);

                if (playerInfo.HasMainTown)
                {
                    /// Added in new version, not tested yet
                    if (mapObject.Header.Version != EMapFormat.ROE)
                    {
                        playerInfo.GenerateHeroAtMainTown = reader.ReadBool();
                        playerInfo.GenerateHero           = reader.ReadBool();
                    }
                    else
                    {
                        playerInfo.GenerateHeroAtMainTown = true;
                        playerInfo.GenerateHero           = false;
                    }

                    var townPosition = reader.ReadPosition();
                    Console.WriteLine(string.Format("Main Town Position: {0}, {1}, {2}", townPosition.PosX, townPosition.PosY, townPosition.PosZ));
                    playerInfo.MainTownPosition = townPosition;
                }

                playerInfo.HasRandomHero = reader.ReadBool();
                Console.WriteLine("hasRandomHero:" + playerInfo.HasRandomHero);

                playerInfo.MainCustomHeroId = reader.ReadUInt8();
                Console.WriteLine("mainCustomHeroId:" + playerInfo.MainCustomHeroId);

                if (playerInfo.MainCustomHeroId != 0xff)
                {
                    playerInfo.MainCustomHeroPortrait = reader.ReadUInt8();
                    if (playerInfo.MainCustomHeroPortrait == 0xff)
                    {
                        playerInfo.MainCustomHeroPortrait = -1;
                    }

                    playerInfo.MainCustomHeroName = reader.ReadString();
                    Console.WriteLine("mainCustomHeroPortrait:" + playerInfo.MainCustomHeroPortrait);
                    Console.WriteLine("heroName:" + playerInfo.MainCustomHeroName);
                }
                else
                {
                    playerInfo.MainCustomHeroId = -1;
                }

                if (mapObject.Header.Version != EMapFormat.ROE)
                {
                    playerInfo.PowerPlaceHolders = reader.ReadUInt8();
                    int heroCount = reader.ReadUInt8();
                    reader.Skip(3);

                    playerInfo.HeroIds = new List <HeroIdentifier>();
                    for (int pp = 0; pp < heroCount; ++pp)
                    {
                        HeroIdentifier heroId = new HeroIdentifier();
                        heroId.Id   = reader.ReadUInt8();
                        heroId.Name = reader.ReadString();
                        playerInfo.HeroIds.Add(heroId);
                    }
                }
            }
        }
コード例 #21
0
ファイル: Perk.cs プロジェクト: zerodowned/Ulmeta
        /// <summary>
        /// Loads serialized data
        /// </summary>
        private static void OnWorldLoad()
        {
            if (!File.Exists(DataFile))
            {
                return;
            }

            using (FileStream stream = new FileStream(DataFile, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                BinaryFileReader reader = new BinaryFileReader(new BinaryReader(stream));

                int version = reader.ReadInt();

                switch (version)
                {
                case 0:
                    int tableCount = reader.ReadInt();
                    PerkTable = new Dictionary <Player, Tuple <Perk, Perk> >(tableCount);

                    Player player;
                    Perk   p1, p2;

                    try
                    {
                        for (int i = 0; i < tableCount; i++)
                        {
                            player = reader.ReadMobile <Player>();

                            if (player == null || player.Deleted)
                            {
                                continue;
                            }

                            ConstructorInfo ctor = GetPerkCtor(reader.ReadString());
                            p1 = ctor.Invoke(new object[] { reader }) as Perk;

                            ctor = GetPerkCtor(reader.ReadString());
                            p2   = ctor.Invoke(new object[] { reader }) as Perk;

                            PerkTable[player] = Tuple.Create <Perk, Perk>(p1, p2);
                        }
                    }

                    catch (Exception e)
                    {
                        //Console.WriteLine();
                        //Utility.PushColor(ConsoleColor.Yellow);
                        //Console.Write("Warning: ");
                        //Utility.PushColor(ConsoleColor.White);
                        //Console.WriteLine("[Perks, OnWorldLoad ("+e.Message+")]");

                        //if (e.InnerException != null)
                        //Console.WriteLine("[Inner Exception: (" + e.InnerException + ")]");
                    }

                    break;
                }

                reader.Close();
            }
        }
コード例 #22
0
        private void ReadPredefinedHeroes(BinaryFileReader reader)
        {
            if (mapObject.Header.Version == EMapFormat.WOG || mapObject.Header.Version == EMapFormat.SOD)
            {
                for (int z = 0; z < GameConstants.HEROES_QUANTITY; z++)
                {
                    Console.WriteLine(string.Format("===Reading Predefined Hero [{0}]", z));

                    int custom = reader.ReadUInt8();
                    if (custom == 0)
                    {
                        Console.WriteLine("is not custom.");
                        continue;
                    }

                    // Create Hero
                    bool hasExp = reader.ReadBool();
                    if (hasExp)
                    {
                        uint exp = reader.ReadUInt32();
                        Console.WriteLine("Has exp:" + exp);
                    }

                    bool hasSecondSkills = reader.ReadBool();
                    if (hasSecondSkills)
                    {
                        uint howMany = reader.ReadUInt32();
                        Console.WriteLine("Has Second Skills count=" + howMany);

                        for (int yy = 0; yy < howMany; ++yy)
                        {
                            int first  = reader.ReadUInt8();
                            int second = reader.ReadUInt8();
                            Console.WriteLine(string.Format("Skill First: {0} Second: {1}", first, second));
                        }
                    }

                    // Set Artifacts
                    bool artSet = reader.ReadBool();
                    if (artSet)
                    {
                        Console.WriteLine("Artifact is set.");

                        if (false)
                        {
                            // Already set the pack
                        }

                        for (int pom = 0; pom < 16; pom++)
                        {
                            LoadArtifactToSlot(reader, null, pom);
                        }

                        if (true)
                        {
                            LoadArtifactToSlot(reader, null, 0);   //catapult
                        }

                        LoadArtifactToSlot(reader, null, 0);   //SpellBook


                        // Misc5 possibly
                        LoadArtifactToSlot(reader, null, 0);   //Misc

                        // Backpack items
                        int amount = reader.ReadUInt16();
                        Console.WriteLine("Backpack item amount:" + amount);
                        for (int ss = 0; ss < amount; ++ss)
                        {
                            LoadArtifactToSlot(reader, null, 0);
                        }
                    }

                    bool hasCustomBio = reader.ReadBool();
                    if (hasCustomBio)
                    {
                        string biography = reader.ReadString();
                        Console.WriteLine("biography: " + biography);
                    }

                    int sex = reader.ReadUInt8();
                    Console.WriteLine("sex: " + sex);

                    // Spells
                    bool hasCustomSpells = reader.ReadBool();
                    if (hasCustomSpells)
                    {
                        HashSet <int> spells = new HashSet <int>();
                        reader.ReadBitMask(spells, 9, GameConstants.SPELLS_QUANTITY, false);
                        Console.WriteLine("Spells: " + JsonConvert.SerializeObject(spells));
                    }

                    bool hasCustomPrimSkills = reader.ReadBool();
                    if (hasCustomPrimSkills)
                    {
                        Console.WriteLine("Has Custom Primary Skills.");
                        for (int xx = 0; xx < GameConstants.PRIMARY_SKILLS; xx++)
                        {
                            int value = reader.ReadUInt8();
                            Console.WriteLine("Primary Skills: " + value);
                        }
                    }
                }
            }
        }
コード例 #23
0
        private static void OnLoad()
        {
            try{
                if (!File.Exists(Path.Combine("Saves/Chat/", "Chat.bin")))
                {
                    return;
                }

                using (FileStream bin = new FileStream(Path.Combine("Saves/Chat/", "Chat.bin"), FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    GenericReader reader = new BinaryFileReader(new BinaryReader(bin));

                    int version = reader.ReadInt();

                    if (version >= 12)
                    {
                        s_PublicPlusIRC = reader.ReadBool();
                    }

                    if (version >= 11)
                    {
                        s_FilterPenalty = (FilterPenalty)reader.ReadInt();
                    }

                    if (version >= 10)
                    {
                        s_AllianceChat = reader.ReadBool();
                    }

                    if (version >= 9)
                    {
                        s_AllowFaction = reader.ReadBool();
                    }

                    if (version >= 8)
                    {
                        s_GuildMenuAccess = reader.ReadBool();
                    }

                    if (version >= 7)
                    {
                        s_MaxPmHistory = reader.ReadInt();
                    }

                    if (version >= 6)
                    {
                        s_IrcAutoReconnect = reader.ReadBool();
                    }

                    if (version >= 5)
                    {
                        s_IrcMaxAttempts = reader.ReadInt();
                    }

                    if (version >= 4)
                    {
                        s_IrcAutoConnect = reader.ReadBool();
                    }

                    if (version >= 3)
                    {
                        s_IrcStaffColor = (IrcColor)reader.ReadInt();
                    }

                    if (version >= 2)
                    {
                        s_IrcNick = reader.ReadString();
                    }

                    if (version >= 1)
                    {
                        s_IrcEnabled = reader.ReadBool();
                        s_IrcServer  = reader.ReadString();
                        s_IrcRoom    = reader.ReadString();
                        s_IrcPort    = reader.ReadInt();
                    }

                    if (version >= 0)
                    {
                        int count = reader.ReadInt();

                        for (int i = 0; i < count; ++i)
                        {
                            s_Filters.Add(reader.ReadString());
                        }

                        s_SpamLimiter     = reader.ReadDouble();
                        s_FilterBanLength = reader.ReadDouble();

                        if (version < 11)
                        {
                            reader.ReadBool();                     // FilterBan removed
                        }
                        s_ShowLocation = reader.ReadBool();
                        s_ShowStaff    = reader.ReadBool();
                        s_PublicStyle  = (PublicStyle)reader.ReadInt();

                        count = reader.ReadInt();
                        ChatInfo info;

                        for (int i = 0; i < count; ++i)
                        {
                            info = new ChatInfo(reader.ReadMobile());
                            if (!info.Load(reader))
                            {
                                return;
                            }
                        }
                    }

                    reader.End();
                }

                if (s_IrcAutoConnect)
                {
                    IrcConnection.Connection.Connect();
                }
            }catch { Errors.Report("ChatInfo-> OnLoad"); }
        }
コード例 #24
0
ファイル: Data.cs プロジェクト: furkanugur/imaginenation
        public static void LoadGlobalOptions()
        {
            if (!File.Exists(Path.Combine(General.SavePath, "GlobalOptions.bin")))
            {
                return;
            }

            using (FileStream bin = new FileStream(Path.Combine(General.SavePath, "GlobalOptions.bin"), FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                GenericReader reader = new BinaryFileReader(new BinaryReader(bin));

                int version = reader.ReadInt();

                if (version >= 2)
                {
                    s_MultiPort = reader.ReadInt();
                }
                if (version >= 2)
                {
                    s_MultiServer = reader.ReadString();
                }

                int count = 0;
                if (version >= 1)
                {
                    count = reader.ReadInt();
                    Notification not = null;
                    for (int i = 0; i < count; ++i)
                    {
                        not = new Notification();
                        not.Load(reader);
                    }
                }

                count = reader.ReadInt();
                string txt = "";
                for (int i = 0; i < count; ++i)
                {
                    txt = reader.ReadString();
                    if (!s_Filters.Contains(txt))
                    {
                        s_Filters.Add(txt);
                    }
                }

                s_FilterPenalty = (FilterPenalty)reader.ReadInt();
                if (version >= 1)
                {
                    s_MacroPenalty = (MacroPenalty)reader.ReadInt();
                }
                s_MaxMsgs         = reader.ReadInt();
                s_ChatSpam        = reader.ReadInt();
                s_MsgSpam         = reader.ReadInt();
                s_RequestSpam     = reader.ReadInt();
                s_FilterBanLength = reader.ReadInt();
                s_FilterWarnings  = reader.ReadInt();
                if (version >= 1)
                {
                    s_AntiMacroDelay = reader.ReadInt();
                }
                s_IrcPort          = reader.ReadInt();
                s_IrcMaxAttempts   = reader.ReadInt();
                s_IrcEnabled       = reader.ReadBool();
                s_IrcAutoConnect   = reader.ReadBool();
                s_IrcAutoReconnect = reader.ReadBool();
                s_FilterSpeech     = reader.ReadBool();
                s_FilterMsg        = reader.ReadBool();
                s_Debug            = reader.ReadBool();
                s_LogChat          = reader.ReadBool();
                s_LogPms           = reader.ReadBool();
                s_IrcStaffColor    = (IrcColor)reader.ReadInt();
                s_IrcServer        = reader.ReadString();
                s_IrcRoom          = reader.ReadString();
                s_IrcNick          = reader.ReadString();
                s_TotalChats       = reader.ReadULong() - 1;
            }
        }
コード例 #25
0
ファイル: FDFile.cs プロジェクト: zerodowned/angelisland
        public static void On_RHFile(CommandEventArgs e)
        {
            if (e.Arguments.Length != 1)
            {
                e.Mobile.SendMessage("Usage: [LoadCont <filename>");
                return;
            }

            try
            {
                int       loaded = 0;
                int       count;
                LogHelper log = new LogHelper(e.Arguments[0] + " LoadCont.log");
                log.Log(LogType.Text, String.Format("Reload process initiated by {0}, with {1} as backup data.", e.Mobile, e.Arguments[0]));

                using (FileStream idxfs = new FileStream(e.Arguments[0] + ".idx", FileMode.Open, FileAccess.Read))
                {
                    using (FileStream binfs = new FileStream(e.Arguments[0] + ".bin", FileMode.Open, FileAccess.Read))
                    {
                        GenericReader bin = new BinaryFileReader(new BinaryReader(binfs));
                        GenericReader idx = new BinaryFileReader(new BinaryReader(idxfs));

                        count = idx.ReadInt();
                        if (count == -1)
                        {
                            log.Log(LogType.Text, "No item data to reload.");                             // do nothing
                        }
                        else
                        {
                            ArrayList items = new ArrayList(count);
                            log.Log(LogType.Text, String.Format("Attempting to reload {0} items.", count));

                            Type[]   ctortypes = new Type[] { typeof(Serial) };
                            object[] ctorargs  = new object[1];

                            for (int i = 0; i < count; i++)
                            {
                                string type     = idx.ReadString();
                                Serial serial   = (Serial)idx.ReadInt();
                                long   position = idx.ReadLong();
                                int    length   = idx.ReadInt();

                                Type t = ScriptCompiler.FindTypeByFullName(type);
                                if (t == null)
                                {
                                    Console.WriteLine("Warning: Tried to load nonexistent type {0}. Ignoring item.", type);
                                    log.Log(String.Format("Warning: Tried to load nonexistent type {0}. Ignoring item.", type));
                                    continue;
                                }

                                ConstructorInfo ctor = t.GetConstructor(ctortypes);
                                if (ctor == null)
                                {
                                    Console.WriteLine("Warning: Tried to load type {0} which has no serialization constructor. Ignoring item.", type);
                                    log.Log(String.Format("Warning: Tried to load type {0} which has no serialization constructor. Ignoring item.", type));
                                    continue;
                                }

                                Item item = null;
                                try
                                {
                                    if (World.FindItem(serial) != null)
                                    {
                                        log.Log(LogType.Item, World.FindItem(serial), "Serial already in use!! Loading of saved item failed.");
                                    }
                                    else if (!World.IsReserved(serial))
                                    {
                                        log.Log(String.Format("Serial {0} is not reserved!! Loading of saved item failed.", serial));
                                    }
                                    else
                                    {
                                        ctorargs[0] = serial;
                                        item        = (Item)(ctor.Invoke(ctorargs));
                                    }
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.LogException(ex);
                                    Console.WriteLine("An exception occurred while trying to invoke {0}'s serialization constructor.", t.FullName);
                                    Console.WriteLine(ex.ToString());
                                    log.Log(String.Format("An exception occurred while trying to invoke {0}'s serialization constructor.", t.FullName));
                                    log.Log(ex.ToString());
                                }

                                if (item != null)
                                {
                                    World.FreeSerial(serial);

                                    World.AddItem(item);
                                    items.Add(new object[] { item, position, length });
                                    log.Log(String.Format("Successfully created item {0}", item));
                                }
                            }

                            for (int i = 0; i < items.Count; i++)
                            {
                                object[] entry    = (object[])items[i];
                                Item     item     = entry[0] as Item;
                                long     position = (long)entry[1];
                                int      length   = (int)entry[2];

                                if (item != null)
                                {
                                    bin.Seek(position, SeekOrigin.Begin);

                                    try
                                    {
                                        item.Deserialize(bin);

                                        // take care of parent hierarchy
                                        object p = item.Parent;
                                        if (p is Item)
                                        {
                                            ((Item)p).RemoveItem(item);
                                            item.Parent = null;
                                            ((Item)p).AddItem(item);
                                        }
                                        else if (p is Mobile)
                                        {
                                            ((Mobile)p).RemoveItem(item);
                                            item.Parent = null;
                                            ((Mobile)p).AddItem(item);
                                        }
                                        else
                                        {
                                            item.Delta(ItemDelta.Update);
                                        }

                                        item.ClearProperties();

                                        object rp = item.RootParent;
                                        if (rp is Item)
                                        {
                                            ((Item)rp).UpdateTotals();
                                        }
                                        else if (rp is Mobile)
                                        {
                                            ((Mobile)rp).UpdateTotals();
                                        }
                                        else
                                        {
                                            item.UpdateTotals();
                                        }

                                        if (bin.Position != (position + length))
                                        {
                                            throw new Exception(String.Format("Bad serialize on {0}", item));
                                        }

                                        log.Log(LogType.Item, item, "Successfully loaded.");
                                        loaded++;
                                    }
                                    catch (Exception ex)
                                    {
                                        LogHelper.LogException(ex);
                                        Console.WriteLine("Caught exception while deserializing {0}:", item);
                                        Console.WriteLine(ex.ToString());
                                        Console.WriteLine("Deleting item.");
                                        log.Log(String.Format("Caught exception while deserializing {0}:", item));
                                        log.Log(ex.ToString());
                                        log.Log("Deleting item.");
                                        item.Delete();
                                    }
                                }
                            }
                        }
                        idx.Close();
                        bin.Close();
                    }
                }

                Console.WriteLine("Attempted to load {0} items: {1} loaded, {2} failed.", count, loaded, count - loaded);
                log.Log(String.Format("Attempted to load {0} items: {1} loaded, {2} failed.", count, loaded, count - loaded));
                e.Mobile.SendMessage("Attempted to load {0} items: {1} loaded, {2} failed.", count, loaded, count - loaded);
                log.Finish();
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
                Console.WriteLine(ex.ToString());
                e.Mobile.SendMessage("Exception: {0}", ex.Message);
            }
        }
コード例 #26
0
        public static bool ImportBuilding(string filename)
        {
            bool finished = false;
            string binpath = Path.Combine(BaseBuilding.SavePath, filename + ".bin");

            if (File.Exists(binpath))
            {
                using (FileStream bin = CustomSaving.GetFileStream(binpath))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));
                    try
                    {
                        int count = reader.ReadInt();
                        for (int i = 0; i < count; i++)
                        {
                            string name = reader.ReadString();
                            int type = reader.ReadInt();

                            switch (type)
                            {
                                case 0: m_BuildingTable[name] = new BuildingEntry(reader, type); break;
                                case 1: m_BuildingTable[name] = new ComponentEntry(reader); break;
                                case 2: m_BuildingTable[name] = new AddonEntry(reader); break;
                            }
                        }
                        finished = true;
                    }
                    catch (Exception error)
                    {
                        Console.WriteLine(error.ToString());
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
            }
            return finished;
        }
コード例 #27
0
        public static void Load()
        {
            if (!Directory.Exists("Saves/ACC"))
            {
                return;
            }

            string   filename  = "acc.sav";
            string   path      = @"Saves/ACC/";
            string   pathNfile = path + filename;
            DateTime start     = DateTime.Now;

            Console.WriteLine();
            Console.WriteLine("----------");
            Console.WriteLine("Loading ACC...");

            try
            {
                using (FileStream m_FileStream = new FileStream(pathNfile, FileMode.Open, FileAccess.Read))
                {
                    BinaryReader     m_BinaryReader = new BinaryReader(m_FileStream);
                    BinaryFileReader reader         = new BinaryFileReader(m_BinaryReader);

                    if (m_RegSystems == null)
                    {
                        m_RegSystems = new Dictionary <string, bool>();
                    }

                    int Count = reader.ReadInt();
                    for (int i = 0; i < Count; i++)
                    {
                        string system  = reader.ReadString();
                        Type   t       = ScriptCompiler.FindTypeByFullName(system);
                        bool   enabled = reader.ReadBool();

                        if (t != null)
                        {
                            m_RegSystems[system] = enabled;

                            if (m_RegSystems[system])
                            {
                                ACCSystem sys = (ACCSystem)Activator.CreateInstance(t);
                                if (sys != null)
                                {
                                    sys.StartLoad(path);
                                }
                            }
                        }
                    }

                    reader.Close();
                    m_FileStream.Close();
                }

                Console.WriteLine("Done in {0:F1} seconds.", (DateTime.Now - start).TotalSeconds);
                Console.WriteLine("----------");
                Console.WriteLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed. Exception: " + e);
            }
        }
コード例 #28
0
        public static void Load()
        {
            try
            {
                if (!File.Exists(Path.Combine(General.SavePath, "Channels.bin")))
                {
                    PredefinedChannels();
                    return;
                }

                using (FileStream bin = new FileStream(Path.Combine(General.SavePath, "Channels.bin"), FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    GenericReader reader = new BinaryFileReader(new BinaryReader(bin));

                    int version = reader.ReadInt();

                    int     count = reader.ReadInt();
                    Channel c;
                    for (int i = 0; i < count; ++i)
                    {
                        c = Activator.CreateInstance(ScriptCompiler.FindTypeByFullName(reader.ReadString())) as Channel;
                        if (c == null)
                        {
                            c = new Channel();
                            c.Load(reader);
                            s_Channels.Remove(c);
                        }
                        else
                        {
                            c.Load(reader);
                        }
                    }
                }

                PredefinedChannels();
            }
            catch (Exception e)
            {
                Errors.Report(General.Local(186));
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Source);
                Console.WriteLine(e.StackTrace);
            }
        }