using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.ServiceProcess; using System.Text; using System.Threading; using CS; using FilterAPI; using FilterAPI.Networking; using FilterZone.LocalHandlers; using FilterZone.LocalNetworking; using FilterZone.ZoneHandlers; using FilterZone.ZoneNetworking; using SHN; using TXT; namespace FilterZone { internal class Program { public static String ZoneID; public static Config Conf; public static Database SQL; public static Item ItemCreator; public static SHNFile ItemInfo; public static SHNFile MobInfo; public static SHNFile MapInfo; public static SHNFile QuestData; public static SHNFile QuestDialog; public static SHNFile ActiveSkill; public static SHNFile AbStateView; public static SHNFile Riding; public static SHNFile Produce; public static SHNFile PassiveSkill; public static SHNFile AntiAutoSkillLearn; public static SHNFile AntiAutoPassiveLearn; public static ShineTable Field; public static Dictionary> ClassSkills = new Dictionary>(); public static Dictionary> ClassPassives = new Dictionary>(); public static LocalClient LocalClient; public static LocalHandlerLoader LocalHandlers; public static ZoneHandlerLoader ZoneHandlers; public static ConcurrentDictionary ZoneClients = new ConcurrentDictionary(); public static Byte R = 255; public static Byte G = 255; public static Byte B = 255; public static ServiceBase[] ServicesToRun; private static void Main() { if (Environment.UserInteractive) { Service s = new Service(); s.Init(true); while (true) { Thread.Sleep(1); } } else { ServicesToRun = new ServiceBase[] { new Service() }; ServiceBase.Run(ServicesToRun); } } public static void LoadSHNs() { MethodInfo CryptoMethod = CSFile.LoadCode(Conf.GetConfigValue("SHNCryptoFile"), "SHN.SHNCrypto", Conf.GetConfigValue("SHNCryptoName")); AbStateView = new SHNFile(String.Format("{0}AbStateView.shn", Conf.GetConfigValue("ServerSHNPath")), CryptoMethod); if (AbStateView.Type == SHNType.TextData) { AbStateView.SHNEncoding = Encoding.ASCII; } else { AbStateView.SHNEncoding = Encoding.GetEncoding("ISO-8859-1"); } if (AbStateView.Type != SHNType.QuestData) { AbStateView.Read(); } else { AbStateView.ReadQuest(); } ActiveSkill = new SHNFile(String.Format("{0}ActiveSkill.shn", Conf.GetConfigValue("ServerSHNPath")), CryptoMethod); if (ActiveSkill.Type == SHNType.TextData) { ActiveSkill.SHNEncoding = Encoding.ASCII; } else { ActiveSkill.SHNEncoding = Encoding.GetEncoding("ISO-8859-1"); } if (ActiveSkill.Type != SHNType.QuestData) { ActiveSkill.Read(); } else { ActiveSkill.ReadQuest(); } ActiveSkill.DisallowRowChanges(); ItemInfo = new SHNFile(String.Format("{0}ItemInfo.shn", Conf.GetConfigValue("ServerSHNPath")), CryptoMethod); if (ItemInfo.Type == SHNType.TextData) { ItemInfo.SHNEncoding = Encoding.ASCII; } else { ItemInfo.SHNEncoding = Encoding.GetEncoding("ISO-8859-1"); } if (ItemInfo.Type != SHNType.QuestData) { ItemInfo.Read(); } else { ItemInfo.ReadQuest(); } ItemInfo.DisallowRowChanges(); PassiveSkill = new SHNFile(String.Format("{0}PassiveSkill.shn", Conf.GetConfigValue("ServerSHNPath")), CryptoMethod); if (PassiveSkill.Type == SHNType.TextData) { PassiveSkill.SHNEncoding = Encoding.ASCII; } else { PassiveSkill.SHNEncoding = Encoding.GetEncoding("ISO-8859-1"); } if (PassiveSkill.Type != SHNType.QuestData) { PassiveSkill.Read(); } else { PassiveSkill.ReadQuest(); } PassiveSkill.DisallowRowChanges(); AntiAutoSkillLearn = new SHNFile(String.Format("{0}AntiAutoSkillLearn.shn", Conf.GetConfigValue("FilterSHNPath")), CryptoMethod); if (AntiAutoSkillLearn.Type == SHNType.TextData) { AntiAutoSkillLearn.SHNEncoding = Encoding.ASCII; } else { AntiAutoSkillLearn.SHNEncoding = Encoding.GetEncoding("ISO-8859-1"); } if (AntiAutoSkillLearn.Type != SHNType.QuestData) { AntiAutoSkillLearn.Read(); } else { AntiAutoSkillLearn.ReadQuest(); } AntiAutoSkillLearn.DisallowRowChanges(); AntiAutoPassiveLearn = new SHNFile(String.Format("{0}AntiAutoPassiveLearn.shn", Conf.GetConfigValue("FilterSHNPath")), CryptoMethod); if (AntiAutoPassiveLearn.Type == SHNType.TextData) { AntiAutoPassiveLearn.SHNEncoding = Encoding.ASCII; } else { AntiAutoPassiveLearn.SHNEncoding = Encoding.GetEncoding("ISO-8859-1"); } if (AntiAutoPassiveLearn.Type != SHNType.QuestData) { AntiAutoPassiveLearn.Read(); } else { AntiAutoPassiveLearn.ReadQuest(); } AntiAutoPassiveLearn.DisallowRowChanges(); foreach (DataRow Row in ItemInfo.Table.Rows.Cast().Where(ItemArray => Convert.ToByte(ItemArray.ItemArray[4]) == 11).ToList()) { String InxName = Row.ItemArray[1].ToString(); Byte DemandLv = Convert.ToByte(Row.ItemArray[9]); Int32 WhoEquip = Convert.ToInt32(Row.ItemArray[29]); Boolean IsMultiClass; Byte ClassID = Classes.ConvertToClassID(WhoEquip, out IsMultiClass); DataRow ActiveSkillRow; DataRow PassiveSkillRow; if ((ActiveSkillRow = ActiveSkill.Table.Rows.Cast().Where(ItemArray => Convert.ToString(ItemArray.ItemArray[1]) == InxName).FirstOrDefault()) != null) { Int32 SkillID = Convert.ToInt32(ActiveSkillRow.ItemArray[0]); if (!ClassSkills.ContainsKey(ClassID)) { ClassSkills.Add(ClassID, new List()); } if (AntiAutoSkillLearn.Table.Rows.Cast().Where(ItemArray => Convert.ToInt32(ItemArray.ItemArray[0]) == SkillID).FirstOrDefault() == null) { if (ClassID != 0) { ClassSkills[ClassID].Add(new Object[] { DemandLv, SkillID }); } if (ClassID != 0 && IsMultiClass) { ClassSkills[Convert.ToByte(ClassID + 1)].Add(new Object[] { DemandLv, SkillID }); } } } if ((PassiveSkillRow = PassiveSkill.Table.Rows.Cast().Where(ItemArray => Convert.ToString(ItemArray.ItemArray[1]) == InxName).FirstOrDefault()) != null) { Int32 PassiveID = Convert.ToInt32(PassiveSkillRow.ItemArray[0]); if (!ClassPassives.ContainsKey(ClassID)) { ClassPassives.Add(ClassID, new List()); } if (AntiAutoPassiveLearn.Table.Rows.Cast().Where(ItemArray => Convert.ToInt32(ItemArray.ItemArray[0]) == PassiveID).FirstOrDefault() == null) { if (ClassID != 0) { ClassPassives[ClassID].Add(new Object[] { DemandLv, PassiveID }); } if (ClassID != 0 && IsMultiClass) { ClassPassives[Convert.ToByte(ClassID + 1)].Add(new Object[] { DemandLv, PassiveID }); } } } } ItemInfo = new SHNFile(String.Format("{0}ItemInfo.shn", Conf.GetConfigValue("ServerSHNPath")), CryptoMethod); if (ItemInfo.Type == SHNType.TextData) { ItemInfo.SHNEncoding = Encoding.ASCII; } else { ItemInfo.SHNEncoding = Encoding.GetEncoding("ISO-8859-1"); } if (ItemInfo.Type != SHNType.QuestData) { ItemInfo.Read(); } else { ItemInfo.ReadQuest(); } ItemInfo.DisallowRowChanges(); MobInfo = new SHNFile(String.Format("{0}MobInfo.shn", Conf.GetConfigValue("ServerSHNPath")), CryptoMethod); if (MobInfo.Type == SHNType.TextData) { MobInfo.SHNEncoding = Encoding.ASCII; } else { MobInfo.SHNEncoding = Encoding.GetEncoding("ISO-8859-1"); } if (MobInfo.Type != SHNType.QuestData) { MobInfo.Read(); } else { MobInfo.ReadQuest(); } MobInfo.DisallowRowChanges(); MapInfo = new SHNFile(String.Format("{0}MapInfo.shn", Conf.GetConfigValue("ServerSHNPath")), CryptoMethod); if (MapInfo.Type == SHNType.TextData) { MapInfo.SHNEncoding = Encoding.ASCII; } else { MapInfo.SHNEncoding = Encoding.GetEncoding("ISO-8859-1"); } if (MapInfo.Type != SHNType.QuestData) { MapInfo.Read(); } else { MapInfo.ReadQuest(); } MapInfo.DisallowRowChanges(); QuestData = new SHNFile(String.Format("{0}QuestData.shn", Conf.GetConfigValue("ServerSHNPath")), CryptoMethod); if (QuestData.Type == SHNType.TextData) { QuestData.SHNEncoding = Encoding.ASCII; } else { QuestData.SHNEncoding = Encoding.GetEncoding("ISO-8859-1"); } if (QuestData.Type != SHNType.QuestData) { QuestData.Read(); } else { QuestData.ReadQuest(); } QuestData.DisallowRowChanges(); QuestDialog = new SHNFile(String.Format("{0}QuestDialog.shn", Conf.GetConfigValue("ServerSHNPath")), CryptoMethod); if (QuestDialog.Type == SHNType.TextData) { QuestDialog.SHNEncoding = Encoding.ASCII; } else { QuestDialog.SHNEncoding = Encoding.GetEncoding("ISO-8859-1"); } if (QuestDialog.Type != SHNType.QuestData) { QuestDialog.Read(); } else { QuestDialog.ReadQuest(); } QuestDialog.DisallowRowChanges(); ActiveSkill = new SHNFile(String.Format("{0}ActiveSkill.shn", Conf.GetConfigValue("ServerSHNPath")), CryptoMethod); if (ActiveSkill.Type == SHNType.TextData) { ActiveSkill.SHNEncoding = Encoding.ASCII; } else { ActiveSkill.SHNEncoding = Encoding.GetEncoding("ISO-8859-1"); } if (ActiveSkill.Type != SHNType.QuestData) { ActiveSkill.Read(); } else { ActiveSkill.ReadQuest(); } ActiveSkill.DisallowRowChanges(); AbStateView = new SHNFile(String.Format("{0}AbStateView.shn", Conf.GetConfigValue("ServerSHNPath")), CryptoMethod); if (AbStateView.Type == SHNType.TextData) { AbStateView.SHNEncoding = Encoding.ASCII; } else { AbStateView.SHNEncoding = Encoding.GetEncoding("ISO-8859-1"); } if (AbStateView.Type != SHNType.QuestData) { AbStateView.Read(); } else { AbStateView.ReadQuest(); } AbStateView.DisallowRowChanges(); Riding = new SHNFile(String.Format("{0}Riding.shn", Conf.GetConfigValue("ServerSHNPath")), CryptoMethod); if (Riding.Type == SHNType.TextData) { Riding.SHNEncoding = Encoding.ASCII; } else { Riding.SHNEncoding = Encoding.GetEncoding("ISO-8859-1"); } if (Riding.Type != SHNType.QuestData) { Riding.Read(); } else { Riding.ReadQuest(); } Riding.DisallowRowChanges(); Produce = new SHNFile(String.Format("{0}Produce.shn", Conf.GetConfigValue("ServerSHNPath")), CryptoMethod); if (Produce.Type == SHNType.TextData) { Produce.SHNEncoding = Encoding.ASCII; } else { Produce.SHNEncoding = Encoding.GetEncoding("ISO-8859-1"); } if (Produce.Type != SHNType.QuestData) { Produce.Read(); } else { Produce.ReadQuest(); } Produce.DisallowRowChanges(); Field = new ShineTable(String.Format("{0}Field.txt", Conf.GetConfigValue("ServerShinePath"))); Field.Read(); } public static void SendConsoleText(ConsoleColor WriteColor, String Text, params Object[] Args) { String FormattedText = String.Format(Text, Args); using (var ClientPacket = new Packet(NETCMD.LOCAL_CONS_TEXT)) { ClientPacket.PacketWriter.Write(ConsoleColorConverter.ConsoleColorToID(WriteColor)); ClientPacket.PacketWriter.Write(String.Format("Zone{0}", ZoneID)); ClientPacket.PacketWriter.Write(FormattedText); if (LocalClient != null) { LocalClient.SendPacket(ClientPacket); } } } } }