private bool InternalCreate(Core.Version version, ClientFeatures features) { if (version == null) { throw new ArgumentNullException(nameof(version)); } if (this.Loaded) { return(true); } if (features == ClientFeatures.None || features == ClientFeatures.Transparency) { features |= version.Value >= (ushort)DatFormat.Format_755 ? ClientFeatures.PatternZ : features; features |= version.Value >= (ushort)DatFormat.Format_960 ? ClientFeatures.Extended : features; features |= version.Value >= (ushort)DatFormat.Format_1050 ? ClientFeatures.FrameDurations : features; features |= version.Value >= (ushort)DatFormat.Format_1057 ? ClientFeatures.FrameGroups : features; } this.Version = version; this.ClientFeatures = features; this.Items.Add(100, ThingType.Create(100, ThingCategory.Item)); this.ItemCount = 100; this.Outfits.Add(1, ThingType.Create(1, ThingCategory.Outfit)); this.OutfitCount = 1; this.Effects.Add(1, ThingType.Create(1, ThingCategory.Effect)); this.EffectCount = 1; this.Missiles.Add(1, ThingType.Create(1, ThingCategory.Missile)); this.MissileCount = 1; this.Changed = true; this.Loaded = true; this.Disposed = false; return(true); }
public bool Save(string datPath, string sprPath, Core.Version version, ClientFeatures features) { if (datPath == null) { throw new ArgumentNullException(nameof(datPath)); } if (sprPath == null) { throw new ArgumentNullException(nameof(sprPath)); } if (version == null) { throw new ArgumentNullException(nameof(version)); } if (!this.Things.Save(datPath, version, features)) { return(false); } if (!this.Sprites.Save(sprPath, version, features)) { return(false); } return(true); }
private bool InternalCreate(Core.Version version, ClientFeatures features) { if (this.Compiling) { return(false); } if (this.Loaded) { return(true); } if (features == ClientFeatures.None || features == ClientFeatures.Transparency) { features |= version.Value >= (ushort)DatFormat.Format_755 ? ClientFeatures.PatternZ : features; features |= version.Value >= (ushort)DatFormat.Format_960 ? ClientFeatures.Extended : features; features |= version.Value >= (ushort)DatFormat.Format_1050 ? ClientFeatures.FrameDurations : features; features |= version.Value >= (ushort)DatFormat.Format_1057 ? ClientFeatures.FrameGroups : features; } this.Version = version; this.ClientFeatures = features; this.transparency = (features & ClientFeatures.Transparency) == ClientFeatures.Transparency ? true : false; this.headSize = (features & ClientFeatures.Extended) == ClientFeatures.Extended ? HeaderU32 : HeaderU16; this.blankSprite = new Sprite(0, this.transparency); this.sprites.Add(1, new Sprite(1, this.transparency)); this.rawSpriteCount = 0; this.Count = 1; this.Changed = true; this.Loaded = true; this.Compiling = false; this.Disposed = false; return(true); }
/// <summary> /// Reads query entity of the config. /// </summary> private static QueryEntity ReadQueryEntity(BinaryReader reader, ClientFeatures features) { Debug.Assert(reader != null); var value = new QueryEntity { KeyTypeName = reader.ReadString(), ValueTypeName = reader.ReadString(), TableName = reader.ReadString(), KeyFieldName = reader.ReadString(), ValueFieldName = reader.ReadString() }; var count = reader.ReadInt(); value.Fields = count == 0 ? null : Enumerable.Range(0, count).Select(x => ReadQueryField(reader, features)).ToList(); count = reader.ReadInt(); value.Aliases = count == 0 ? null : Enumerable.Range(0, count) .Select(x => new QueryAlias(reader.ReadString(), reader.ReadString())).ToList(); count = reader.ReadInt(); value.Indexes = count == 0 ? null : Enumerable.Range(0, count).Select(x => new QueryIndex(reader)).ToList(); return(value); }
private void CompileButton_Click(object sender, EventArgs e) { string directory = Path.Combine(PathUtils.ApplicationDirectory, "Output"); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } OpenTibia.Core.Version version = (OpenTibia.Core.Version) this.outputVersionComboBox.SelectedItem; string datPath = Path.Combine(directory, "Tibia.dat"); string sprPath = Path.Combine(directory, "Tibia.spr"); ClientFeatures features = ClientFeatures.PatternZ | ClientFeatures.Extended; features |= this.outputFrameDurationsCheckBox.Checked ? ClientFeatures.FrameDurations : features; features |= this.outputFrameGroupsCheckBox.Checked ? ClientFeatures.FrameGroups : features; try { this.compileButton.Enabled = false; this.client.Save(datPath, sprPath, version, features); } catch (Exception ex) { MessageBox.Show(ex.Message); Application.Exit(); } }
public bool CreateEmpty(Core.Version version, ClientFeatures features) { if (version == null) { throw new ArgumentNullException(nameof(version)); } this.Things = ThingTypeStorage.Create(version, features); if (this.Things == null) { return(false); } this.Sprites = SpriteStorage.Create(version, features); if (this.Sprites == null) { return(false); } this.Things.ProgressChanged += new ProgressHandler(this.StorageProgressChanged_Handler); this.Things.StorageChanged += new ThingListChangedHandler(this.ThingListChanged_Handler); this.Things.StorageCompiled += new StorageHandler(this.StorageCompiled_Handler); this.Things.StorageDisposed += new StorageHandler(this.StorageDisposed_Handler); this.Sprites.StorageChanged += new SpriteListChangedHandler(this.SpriteListChanged_Handler); this.Sprites.ProgressChanged += new ProgressHandler(this.StorageProgressChanged_Handler); this.Sprites.StorageCompiled += new StorageHandler(this.StorageCompiled_Handler); this.Sprites.StorageDisposed += new StorageHandler(this.StorageDisposed_Handler); if (this.Loaded && this.ClientLoaded != null) { this.ClientLoaded(this, new EventArgs()); } return(this.Loaded); }
public void TestGetMinVersionReturnsSpecificVersionForNewFeatures() { Assert.AreEqual(ClientSocket.Ver140, ClientFeatures.GetMinVersion(ClientOp.CachePartitions)); Assert.AreEqual(ClientSocket.Ver150, ClientFeatures.GetMinVersion(ClientOp.ClusterIsActive)); Assert.AreEqual(ClientSocket.Ver150, ClientFeatures.GetMinVersion(ClientOp.ClusterChangeState)); Assert.AreEqual(ClientSocket.Ver150, ClientFeatures.GetMinVersion(ClientOp.ClusterChangeWalState)); Assert.AreEqual(ClientSocket.Ver150, ClientFeatures.GetMinVersion(ClientOp.ClusterGetWalState)); }
public void TestGetMinVersionReturnsValueForEveryValidOp() { foreach (ClientOp clientOp in Enum.GetValues(typeof(ClientOp))) { var minVersion = ClientFeatures.GetMinVersion(clientOp); Assert.IsTrue(minVersion >= ClientSocket.Ver100); Assert.IsTrue(minVersion <= ClientSocket.CurrentProtocolVersion); } }
public static SpriteStorage Create(Core.Version version, ClientFeatures features) { SpriteStorage storage = new SpriteStorage(); if (storage.InternalCreate(version, features)) { return(storage); } return(null); }
public static SpriteStorage Load(string path, Core.Version version, ClientFeatures features) { SpriteStorage storage = new SpriteStorage(); if (storage.InternalLoad(path, version, features, false)) { return(storage); } return(null); }
public static ThingTypeStorage Load(string path, Core.Version version, ClientFeatures features) { ThingTypeStorage storage = new ThingTypeStorage(); if (storage.InternalLoad(path, version, features)) { return(storage); } return(null); }
public static byte[] Login() { String str; TCPPacketWriter packet = new TCPPacketWriter(); packet.WriteGuid(Settings.Guid); packet.WriteUInt16(0); packet.WriteByte((byte)Settings.GetReg <int>("crypto", 250)); packet.WriteUInt16(Settings.Port); packet.WriteIP("0.0.0.0"); packet.WriteUInt16(65535); packet.WriteUInt32(0); packet.WriteString(Settings.GetReg <String>("username", String.Empty), true); packet.WriteString(Settings.APP_NAME + " " + Settings.APP_VERSION, true); packet.WriteIP(Settings.LocalIP); packet.WriteIP(Settings.LocalIP); packet.WriteByte(7); packet.WriteBytes(new byte[] { 0, 0, 0 }); packet.WriteByte((byte)Settings.GetReg <int>("user_age", 0)); packet.WriteByte((byte)Settings.GetReg <int>("user_gender", 0)); packet.WriteByte((byte)Settings.GetReg <int>("user_country", 0)); str = Settings.GetReg <String>("user_region", String.Empty); if (str.Length > 30) { str = str.Substring(0, 30); } packet.WriteString(str); ClientFeatures features = (ClientFeatures)0; if (Settings.GetReg <bool>("vc_public", true)) { features |= ClientFeatures.CLIENT_SUPPORTS_OPUS_VC; features |= ClientFeatures.CLIENT_SUPPORTS_VC; } if (Settings.GetReg <bool>("vc_private", true)) { features |= ClientFeatures.CLIENT_SUPPORTS_OPUS_PM_VC; features |= ClientFeatures.CLIENT_SUPPORTS_PM_VC; } if (Settings.CanHTML) { features |= ClientFeatures.CLIENT_SUPPORTS_HTML; } packet.WriteByte((byte)features); return(packet.ToAresPacket(TCPMsg.MSG_CHAT_CLIENT_LOGIN)); }
private void Eval_UserlistItem(TCPPacketReader packet) { User u = new User(); ushort files = packet; packet.SkipBytes(4); u.ExternalIP = packet; u.Port = packet; packet.SkipBytes(4); u.SupportsPMEnc = ((ushort)packet) == 65535; packet.SkipByte(); u.Name = packet.ReadString(this.crypto); u.LocalIP = packet; u.HasFiles = ((byte)packet) == 1 && files > 0; u.Level = packet; u.Age = packet; u.Gender = packet; byte country = packet; u.Country = Helpers.CountryCodeToString(country); u.Region = packet.ReadString(this.crypto); if (packet.Remaining > 0) { ClientFeatures features = (ClientFeatures)((byte)packet); u.SupportsVC = ((features & ClientFeatures.CLIENT_SUPPORTS_VC) == ClientFeatures.CLIENT_SUPPORTS_VC); u.SupportsOpusVC = ((features & ClientFeatures.CLIENT_SUPPORTS_OPUS_VC) == ClientFeatures.CLIENT_SUPPORTS_OPUS_VC); if (u.SupportsOpusVC) { u.SupportsVC = true; } } u.IsFriend = Friends.IsFriend(u.Name); if (this.users.Find(x => x.Name == u.Name) != null) { return; } this.users.Add(u); this.Panel.Userlist.AddUserItem(u); Scripting.ScriptManager.AddUser(this.EndPoint, u); if (u.Name == this.MyName) { u.IsAway = Settings.IsAway; this.Panel.Userlist.MyLevel = u.Level; } }
/// <summary> /// Reads the config. /// </summary> public static void Read(IBinaryStream stream, CacheClientConfiguration cfg, ClientFeatures features) { Debug.Assert(stream != null); // Configuration should be read with system marshaller. var reader = BinaryUtils.Marshaller.StartUnmarshal(stream); var len = reader.ReadInt(); var pos = reader.Stream.Position; cfg.AtomicityMode = (CacheAtomicityMode)reader.ReadInt(); cfg.Backups = reader.ReadInt(); cfg.CacheMode = (CacheMode)reader.ReadInt(); cfg.CopyOnRead = reader.ReadBoolean(); cfg.DataRegionName = reader.ReadString(); cfg.EagerTtl = reader.ReadBoolean(); cfg.EnableStatistics = reader.ReadBoolean(); cfg.GroupName = reader.ReadString(); cfg.LockTimeout = reader.ReadLongAsTimespan(); cfg.MaxConcurrentAsyncOperations = reader.ReadInt(); cfg.MaxQueryIteratorsCount = reader.ReadInt(); cfg.Name = reader.ReadString(); cfg.OnheapCacheEnabled = reader.ReadBoolean(); cfg.PartitionLossPolicy = (PartitionLossPolicy)reader.ReadInt(); cfg.QueryDetailMetricsSize = reader.ReadInt(); cfg.QueryParallelism = reader.ReadInt(); cfg.ReadFromBackup = reader.ReadBoolean(); cfg.RebalanceBatchSize = reader.ReadInt(); cfg.RebalanceBatchesPrefetchCount = reader.ReadLong(); cfg.RebalanceDelay = reader.ReadLongAsTimespan(); cfg.RebalanceMode = (CacheRebalanceMode)reader.ReadInt(); cfg.RebalanceOrder = reader.ReadInt(); cfg.RebalanceThrottle = reader.ReadLongAsTimespan(); cfg.RebalanceTimeout = reader.ReadLongAsTimespan(); cfg.SqlEscapeAll = reader.ReadBoolean(); cfg.SqlIndexMaxInlineSize = reader.ReadInt(); cfg.SqlSchema = reader.ReadString(); cfg.WriteSynchronizationMode = (CacheWriteSynchronizationMode)reader.ReadInt(); cfg.KeyConfiguration = reader.ReadCollectionRaw(r => new CacheKeyConfiguration(r)); cfg.QueryEntities = reader.ReadCollectionRaw(r => ReadQueryEntity(r, features)); if (features.HasCacheConfigurationExpiryPolicyFactory()) { cfg.ExpiryPolicyFactory = ExpiryPolicySerializer.ReadPolicyFactory(reader); } Debug.Assert(len == reader.Stream.Position - pos); }
////////////////////////////////////////////////////////////////////////////////////////////// // Creates ClientFeature that holds our dimension graphics // ////////////////////////////////////////////////////////////////////////////////////////////// void CreateClientFeature(Point point1, Point point2, Point dimText, Vector normal) { Inventor.Application InvApp = AdnInventorUtilities.InvApplication; Document document = InvApp.ActiveDocument; ComponentDefinition compDef = AdnInventorUtilities.GetCompDefinition(document); object features = AdnInventorUtilities.GetProperty(compDef, "Features"); ClientFeatures clientFeatures = AdnInventorUtilities.GetProperty(features, "ClientFeatures") as ClientFeatures; ClientFeatureDefinition cfDef = clientFeatures.CreateDefinition( "Dimension Feature", null, null, null); ClientFeature clientFeature = clientFeatures.Add(cfDef, AdnInventorUtilities.AddInGuid); cfDef = clientFeature.Definition; cfDef.HighlightClientGraphicsWithFeature = true; NativeBrowserNodeDefinition nodeDef = clientFeature.BrowserNode.BrowserNodeDefinition as NativeBrowserNodeDefinition; stdole.IPictureDisp pic = PictureDispConverter.ToIPictureDisp(Resources.dimlinear); ClientNodeResource res = document.BrowserPanes.ClientNodeResources.Add( AdnInventorUtilities.AddInGuid, document.BrowserPanes.ClientNodeResources.Count + 1, pic); nodeDef.OverrideIcon = res; _clientGraphicsMng.SetGraphicsSource(clientFeature); DrawDimension(point1, point2, dimText, normal); _clientGraphicsMng.UpdateView(); }
/// <summary> /// Writes query field instance to the specified writer. /// </summary> private static void WriteQueryField(BinaryWriter writer, QueryField field, ClientFeatures features) { Debug.Assert(writer != null); writer.WriteString(field.Name); writer.WriteString(field.FieldTypeName); writer.WriteBoolean(field.IsKeyField); writer.WriteBoolean(field.NotNull); writer.WriteObject(field.DefaultValue); if (features.HasQueryFieldPrecisionAndScale()) { writer.WriteInt(field.Precision); writer.WriteInt(field.Scale); } }
public JoinBase(IClient user) { FileCount = user.FileCount; ExternalIp = user.Server.Config.HideIPs ? IPAddress.Any : user.ExternalIp; DCPort = user.ListenPort; NodeIp = user.NodeIp; NodePort = user.NodePort; Username = user.Name; LocalIp = user.Server.Config.HideIPs ? IPAddress.Any : user.LocalIp; Browsable = user.Browsable; Level = user.Admin; Age = user.Age; Gender = user.Gender; Country = user.Country; Region = user.Region; Features = user.Features; }
/// <summary> /// Read query field. /// </summary> private static QueryField ReadQueryField(BinaryReader reader, ClientFeatures features) { Debug.Assert(reader != null); var value = new QueryField { Name = reader.ReadString(), FieldTypeName = reader.ReadString(), IsKeyField = reader.ReadBoolean(), NotNull = reader.ReadBoolean(), DefaultValue = reader.ReadObject <object>() }; if (features.HasQueryFieldPrecisionAndScale()) { value.Precision = reader.ReadInt(); value.Scale = reader.ReadInt(); } return(value); }
private object BuildObject(object obj) { try { var clientFeatures = new ClientFeatures(); return(new { Client = new { IP = clientFeatures.IP, Method = clientFeatures.Method, Url = clientFeatures.URL, Date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), Log = LogType.Info.ToString() }, Entity = obj }); } catch (Exception ex) { throw ex; } }
private bool InternalLoad(string path, Core.Version version, ClientFeatures features, bool reloading) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (version == null) { throw new ArgumentNullException(nameof(version)); } if (!File.Exists(path)) { string message = $"File not found: {path}"; // TODO: ResourceManager.GetString("Exception.FileNotFound"); throw new FileNotFoundException(message, path); } if (this.Compiling) { return(false); } if (this.Loaded) { if (reloading) { this.stream.Close(); this.stream = null; } else { return(true); } } if (features == ClientFeatures.None || features == ClientFeatures.Transparency) { features |= version.Value >= (ushort)DatFormat.Format_755 ? ClientFeatures.PatternZ : features; features |= version.Value >= (ushort)DatFormat.Format_960 ? ClientFeatures.Extended : features; features |= version.Value >= (ushort)DatFormat.Format_1050 ? ClientFeatures.FrameDurations : features; features |= version.Value >= (ushort)DatFormat.Format_1057 ? ClientFeatures.FrameGroups : features; } this.stream = new FileStream(path, FileMode.Open); this.reader = new BinaryReader(this.stream); uint signature = this.reader.ReadUInt32(); if (signature != version.SprSignature) { string message = "Invalid SPR signature. Expected signature is {0:X} and loaded signature is {1:X}."; throw new Exception(string.Format(message, version.SprSignature, signature)); } if ((features & ClientFeatures.Extended) == ClientFeatures.Extended) { this.headSize = HeaderU32; this.rawSpriteCount = this.reader.ReadUInt32(); } else { this.headSize = HeaderU16; this.rawSpriteCount = this.reader.ReadUInt16(); } this.FilePath = path; this.Version = version; this.ClientFeatures = features; this.transparency = (features & ClientFeatures.Transparency) == ClientFeatures.Transparency ? true : false; this.Count = this.rawSpriteCount; this.blankSprite = new Sprite(0, this.transparency); this.Changed = false; this.Loaded = true; this.Disposed = false; return(true); }
public bool Save(string path, Core.Version version, ClientFeatures features) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (version == null) { throw new ArgumentNullException(nameof(version)); } if (this.Disposed) { throw new ObjectDisposedException(this.GetType().Name); } if (!this.Loaded || this.Compiling) { return(false); } if (features == ClientFeatures.None || features == ClientFeatures.Transparency) { features |= version.Value >= (ushort)DatFormat.Format_755 ? ClientFeatures.PatternZ : features; features |= version.Value >= (ushort)DatFormat.Format_960 ? ClientFeatures.Extended : features; features |= version.Value >= (ushort)DatFormat.Format_1050 ? ClientFeatures.FrameDurations : features; features |= version.Value >= (ushort)DatFormat.Format_1057 ? ClientFeatures.FrameGroups : features; } string directory = Path.GetDirectoryName(path); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } if (!this.Changed && this.Version.Equals(version) && this.ClientFeatures == features) { // just copy the content and reload if nothing has changed. if (this.FilePath != null && !this.FilePath.Equals(path)) { File.Copy(this.FilePath, path, true); if (!this.InternalLoad(path, version, features, true)) { return(false); } if (this.ProgressChanged != null) { this.ProgressChanged(this, 100); } if (this.StorageCompiled != null) { this.StorageCompiled(this); } } return(true); } this.compilationData = new CompilationData(); this.compilationData.Path = path; this.compilationData.TmpPath = Path.Combine(directory, Path.GetFileNameWithoutExtension(path) + ".tmp"); this.compilationData.Version = version; this.compilationData.Features = features; this.Compiling = true; this.worker.RunWorkerAsync(); return(true); }
public bool Save(string datPath, string sprPath, Core.Version version, ClientFeatures features) { if (datPath == null) { throw new ArgumentNullException("datPath"); } if (sprPath == null) { throw new ArgumentNullException("sprPath"); } if (version == null) { throw new ArgumentNullException("version"); } if (!this.Things.Save(datPath, version, features)) { return false; } if (!this.Sprites.Save(sprPath, version, features)) { return false; } return true; }
public static bool WriteTexturePatterns(ThingType thing, ClientFeatures features, BinaryWriter writer) { bool patternZEnabled = (features & ClientFeatures.PatternZ) == ClientFeatures.PatternZ; bool extendedEnabled = (features & ClientFeatures.Extended) == ClientFeatures.Extended; bool frameDurationsEnabled = (features & ClientFeatures.FrameDurations) == ClientFeatures.FrameDurations; bool frameGroupsEnabled = (features & ClientFeatures.FrameGroups) == ClientFeatures.FrameGroups; int groupCount = 1; // write frame group count. if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit) { groupCount = thing.FrameGroupCount; writer.Write((byte)groupCount); // cast to 1 byte } for (byte k = 0; k < groupCount; k++) { // write frame group type. if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit) { writer.Write(k); } FrameGroup group = thing.GetFrameGroup((FrameGroupType)k); writer.Write(group.Width); // write width writer.Write(group.Height); // write heigh // write exact size if (group.Width > 1 || group.Height > 1) { writer.Write(group.ExactSize); } writer.Write(group.Layers); // write layers writer.Write(group.PatternX); // write pattern X writer.Write(group.PatternY); // write pattern Y if (patternZEnabled) { writer.Write(group.PatternZ); // write pattern Z } writer.Write(group.Frames); // write frames if (frameDurationsEnabled && group.Frames > 1) { writer.Write((byte)group.AnimationMode); // write animation type writer.Write(group.LoopCount); // write frame strategy writer.Write(group.StartFrame); // write start frame FrameDuration[] durations = group.FrameDurations; for (int i = 0; i < durations.Length; i++) { writer.Write((uint)durations[i].Minimum); // write minimum duration writer.Write((uint)durations[i].Maximum); // write maximum duration } } uint[] sprites = group.SpriteIDs; for (int i = 0; i < sprites.Length; i++) { // write sprite index if (extendedEnabled) { writer.Write(sprites[i]); } else { writer.Write((ushort)sprites[i]); } } } return(true); }
private bool InternalLoad(string path, Core.Version version, ClientFeatures features) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (version == null) { throw new ArgumentNullException(nameof(version)); } if (!File.Exists(path)) { throw new FileNotFoundException($"File not found: {path}", path); } if (this.Loaded) { return(true); } if (features == ClientFeatures.None || features == ClientFeatures.Transparency) { features |= version.Value >= (ushort)DatFormat.Format_755 ? ClientFeatures.PatternZ : features; features |= version.Value >= (ushort)DatFormat.Format_960 ? ClientFeatures.Extended : features; features |= version.Value >= (ushort)DatFormat.Format_1050 ? ClientFeatures.FrameDurations : features; features |= version.Value >= (ushort)DatFormat.Format_1057 ? ClientFeatures.FrameGroups : features; } using (FileStream stream = new FileStream(path, FileMode.Open)) { BinaryReader reader = new BinaryReader(stream); uint signature = reader.ReadUInt32(); if (signature != version.DatSignature) { string message = "Invalid DAT signature. Expected signature is {0:X} and loaded signature is {1:X}."; throw new Exception(string.Format(message, version.DatSignature, signature)); } this.ItemCount = reader.ReadUInt16(); this.OutfitCount = reader.ReadUInt16(); this.EffectCount = reader.ReadUInt16(); this.MissileCount = reader.ReadUInt16(); int total = this.ItemCount + this.OutfitCount + this.EffectCount + this.MissileCount; int loaded = 0; // load item list. for (ushort id = 100; id <= this.ItemCount; id++) { ThingType item = new ThingType(id, ThingCategory.Item); if (!ThingTypeSerializer.ReadProperties(item, version.Format, reader) || !ThingTypeSerializer.ReadTexturePatterns(item, features, reader)) { throw new Exception("Items list cannot be loaded."); } this.Items.Add(id, item); } // update progress. if (this.ProgressChanged != null) { loaded += this.ItemCount; this.ProgressChanged(this, (loaded * 100) / total); } // load outfit list. for (ushort id = 1; id <= this.OutfitCount; id++) { ThingType outfit = new ThingType(id, ThingCategory.Outfit); if (!ThingTypeSerializer.ReadProperties(outfit, version.Format, reader) || !ThingTypeSerializer.ReadTexturePatterns(outfit, features, reader)) { throw new Exception("Outfits list cannot be loaded."); } this.Outfits.Add(id, outfit); } // update progress. if (this.ProgressChanged != null) { loaded += this.OutfitCount; this.ProgressChanged(this, (loaded * 100) / total); } // load effect list. for (ushort id = 1; id <= this.EffectCount; id++) { ThingType effect = new ThingType(id, ThingCategory.Effect); if (!ThingTypeSerializer.ReadProperties(effect, version.Format, reader) || !ThingTypeSerializer.ReadTexturePatterns(effect, features, reader)) { throw new Exception("Effects list cannot be loaded."); } this.Effects.Add(id, effect); } // update progress. if (this.ProgressChanged != null) { loaded += this.EffectCount; this.ProgressChanged(this, (loaded * 100) / total); } // load missile list. for (ushort id = 1; id <= this.MissileCount; id++) { ThingType missile = new ThingType(id, ThingCategory.Missile); if (!ThingTypeSerializer.ReadProperties(missile, version.Format, reader) || !ThingTypeSerializer.ReadTexturePatterns(missile, features, reader)) { throw new Exception("Missiles list cannot be loaded."); } this.Missiles.Add(id, missile); } // update progress. if (this.ProgressChanged != null) { loaded += this.MissileCount; this.ProgressChanged(this, (loaded * 100) / total); } } this.FilePath = path; this.Version = version; this.ClientFeatures = features; this.Changed = false; this.Loaded = true; this.Disposed = false; return(true); }
private bool InternalCreate(Core.Version version, ClientFeatures features) { if (version == null) { throw new ArgumentNullException("version"); } if (this.Loaded) { return true; } if (features == ClientFeatures.None || features == ClientFeatures.Transparency) { features |= version.Value >= (ushort)DatFormat.Format_755 ? ClientFeatures.PatternZ : features; features |= version.Value >= (ushort)DatFormat.Format_960 ? ClientFeatures.Extended : features; features |= version.Value >= (ushort)DatFormat.Format_1050 ? ClientFeatures.FrameDurations : features; features |= version.Value >= (ushort)DatFormat.Format_1057 ? ClientFeatures.FrameGroups : features; } this.Version = version; this.ClientFeatures = features; this.Items.Add(100, ThingType.Create(100, ThingCategory.Item)); this.ItemCount = 100; this.Outfits.Add(1, ThingType.Create(1, ThingCategory.Outfit)); this.OutfitCount = 1; this.Effects.Add(1, ThingType.Create(1, ThingCategory.Effect)); this.EffectCount = 1; this.Missiles.Add(1, ThingType.Create(1, ThingCategory.Missile)); this.MissileCount = 1; this.Changed = true; this.Loaded = true; this.Disposed = false; return true; }
public bool Load(string datPath, string sprPath, Core.Version version, ClientFeatures features) { if (datPath == null) { throw new ArgumentNullException("datPath"); } if (sprPath == null) { throw new ArgumentNullException("sprPath"); } if (version == null) { throw new ArgumentNullException("version"); } this.Things = ThingTypeStorage.Load(datPath, version, features); if (this.Things == null) { return false; } this.Sprites = SpriteStorage.Load(sprPath, version, features); if (this.Sprites == null) { return false; } this.Things.ProgressChanged += new ProgressHandler(this.StorageProgressChanged_Handler); this.Things.StorageChanged += new ThingListChangedHandler(this.ThingListChanged_Handler); this.Things.StorageCompiled += new EventHandler(this.StorageCompiled_Handler); this.Things.StorageDisposed += new EventHandler(this.StorageDisposed_Handler); this.Sprites.StorageChanged += new SpriteListChangedHandler(this.SpriteListChanged_Handler); this.Sprites.ProgressChanged += new ProgressHandler(this.StorageProgressChanged_Handler); this.Sprites.StorageCompiled += new EventHandler(this.StorageCompiled_Handler); this.Sprites.StorageDisposed += new EventHandler(this.StorageDisposed_Handler); if (this.Loaded && this.ClientLoaded != null) { this.ClientLoaded(this, new EventArgs()); } return this.Loaded; }
private void Eval_Join(TCPPacketReader packet) { User u = new User(); ushort files = packet; packet.SkipBytes(4); u.ExternalIP = packet; u.Port = packet; packet.SkipBytes(4); u.SupportsPMEnc = ((ushort)packet) == 65535; packet.SkipByte(); u.Name = packet.ReadString(this.crypto); u.LocalIP = packet; u.HasFiles = ((byte)packet) == 1 && files > 0; u.Level = packet; u.Age = packet; u.Gender = packet; byte country = packet; u.Country = Helpers.CountryCodeToString(country); u.Region = packet.ReadString(this.crypto); u.IsFriend = Friends.IsFriend(u.Name); if (packet.Remaining > 0) { ClientFeatures features = (ClientFeatures)((byte)packet); u.SupportsVC = ((features & ClientFeatures.CLIENT_SUPPORTS_VC) == ClientFeatures.CLIENT_SUPPORTS_VC); u.SupportsOpusVC = ((features & ClientFeatures.CLIENT_SUPPORTS_OPUS_VC) == ClientFeatures.CLIENT_SUPPORTS_OPUS_VC); if (u.SupportsOpusVC) { u.SupportsVC = true; } } User ghost = this.users.Find(x => x.Name == u.Name); if (ghost != null) { this.users.RemoveAll(x => x.Name == ghost.Name); if (ghost.Writing) { ghost.Writing = false; this.Panel.UpdateWriter(ghost); } this.Panel.Userlist.RemoveUserItem(ghost); if (ScriptEvents.OnUserParting(this, ghost)) { this.Panel.AnnounceText(GlobalSettings.GetDefaultColorString(GlobalSettings.DefaultColorType.Part, this.BlackBG) + StringTemplate.Get(STType.Messages, 12).Replace("+x", ghost.Name)); } ScriptEvents.OnUserParted(this, ghost); Scripting.ScriptManager.RemoveUser(this.EndPoint, u); ghost.Dispose(); ghost = null; } this.users.Add(u); this.Panel.Userlist.AddUserItem(u); Scripting.ScriptManager.AddUser(this.EndPoint, u); if (ScriptEvents.OnUserJoining(this, u)) { this.Panel.AnnounceText(GlobalSettings.GetDefaultColorString(GlobalSettings.DefaultColorType.Join, this.BlackBG) + StringTemplate.Get(STType.Messages, 13).Replace("+x", u.Name)); } if (u.Name == this.MyName) { u.IsAway = Settings.IsAway; this.Panel.Userlist.MyLevel = u.Level; } ScriptEvents.OnUserJoined(this, u); if (u.IsFriend) { if (!Settings.GetReg <bool>("block_friend_popup", false)) { this.ShowPopup("cb0t :: " + StringTemplate.Get(STType.Messages, 4), StringTemplate.Get(STType.Messages, 14).Replace("+x", u.Name).Replace("+y", this.Credentials.Name), PopupSound.Friend); } } }
////////////////////////////////////////////////////////////////////////////////////////////// // Example using the AdnClientGraphicsManager // ////////////////////////////////////////////////////////////////////////////////////////////// public static void DemoMng() { Inventor.Application InvApp = AdnInventorUtilities.InvApplication; Document document = InvApp.ActiveDocument; // We will use late binding to retrieve ClientFeatures collection, // so we dont need to write specific code for PartDocument and // AssemblyDocument ComponentDefinition compDef = AdnInventorUtilities.GetCompDefinition(document); object features = AdnInventorUtilities.GetProperty(compDef, "Features"); ClientFeatures clientFeatures = AdnInventorUtilities.GetProperty(features, "ClientFeatures") as ClientFeatures; ClientFeatureDefinition cfDef = clientFeatures.CreateDefinition("Graphics Feature", null, null, null); ClientFeature clientFeature = clientFeatures.Add(cfDef, AdnInventorUtilities.AddInGuid); cfDef = clientFeature.Definition; cfDef.HighlightClientGraphicsWithFeature = true; NativeBrowserNodeDefinition nodeDef = clientFeature.BrowserNode.BrowserNodeDefinition as NativeBrowserNodeDefinition; stdole.IPictureDisp pic = PictureDispConverter.ToIPictureDisp(Resources.PointImage); ClientNodeResource res = document.BrowserPanes.ClientNodeResources.Add( AdnInventorUtilities.AddInGuid, document.BrowserPanes.ClientNodeResources.Count + 1, pic); nodeDef.OverrideIcon = res; AdnClientGraphicsManager clientGraphicsMng = new AdnClientGraphicsManager( InvApp, AdnInventorUtilities.AddInGuid); clientGraphicsMng.SetGraphicsSource(clientFeature); Random rd = new Random(); TriangleGraphics graphics = clientGraphicsMng.DrawTriangle( new double[] { rd.Next(0, 10), rd.Next(0, 10), rd.Next(0, 10) }, new double[] { rd.Next(0, 10), rd.Next(0, 10), rd.Next(0, 10) }, new double[] { rd.Next(0, 10), rd.Next(0, 10), rd.Next(0, 10) }, null); int id = clientGraphicsMng.WorkingGraphics.GetDataSetFreeId(); GraphicsColorSet colorSet = clientGraphicsMng.WorkingGraphics.GraphicsDataSets.CreateColorSet(id); colorSet.Add(1, (byte)rd.Next(0, 255), (byte)rd.Next(0, 255), (byte)rd.Next(0, 255)); graphics.ColorSet = colorSet; clientGraphicsMng.UpdateView(); }
public static SpriteStorage Load(string path, Core.Version version, ClientFeatures features) { SpriteStorage storage = new SpriteStorage(); if (storage.InternalLoad(path, version, features, false)) { return storage; } return null; }
public bool Save(string path, Core.Version version, ClientFeatures features) { if (path == null) { throw new ArgumentNullException("path"); } if (version == null) { throw new ArgumentNullException("version"); } if (this.Disposed) { throw new ObjectDisposedException(this.GetType().Name); } if (!this.Loaded || this.Compiling) { return false; } if (features == ClientFeatures.None || features == ClientFeatures.Transparency) { features |= version.Value >= (ushort)DatFormat.Format_755 ? ClientFeatures.PatternZ : features; features |= version.Value >= (ushort)DatFormat.Format_960 ? ClientFeatures.Extended : features; features |= version.Value >= (ushort)DatFormat.Format_1050 ? ClientFeatures.FrameDurations : features; features |= version.Value >= (ushort)DatFormat.Format_1057 ? ClientFeatures.FrameGroups : features; } string directory = Path.GetDirectoryName(path); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } if (!this.Changed && this.Version.Equals(version) && this.ClientFeatures == features) { // just copy the content and reload if nothing has changed. if (this.FilePath != null && !this.FilePath.Equals(path)) { File.Copy(this.FilePath, path, true); if (!this.InternalLoad(path, version, features, true)) { return false; } if (this.ProgressChanged != null) { this.ProgressChanged(this, 100); } if (this.StorageCompiled != null) { this.StorageCompiled(this, new EventArgs()); } } return true; } this.compilationData = new CompilationData(); this.compilationData.Path = path; this.compilationData.TmpPath = Path.Combine(directory, Path.GetFileNameWithoutExtension(path) + ".tmp"); this.compilationData.Version = version; this.compilationData.Features = features; this.Compiling = true; this.worker.RunWorkerAsync(); return true; }
public static SpriteStorage Create(Core.Version version, ClientFeatures features) { SpriteStorage storage = new SpriteStorage(); if (storage.InternalCreate(version, features)) { return storage; } return null; }
private bool InternalLoad(string path, Core.Version version, ClientFeatures features, bool reloading) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } if (version == null) { throw new ArgumentNullException("version"); } if (!File.Exists(path)) { string message = "File not found: {0}"; // TODO: ResourceManager.GetString("Exception.FileNotFound"); throw new FileNotFoundException(string.Format(message, path), "path"); } if (this.Compiling) { return false; } if (this.Loaded) { if (reloading) { this.stream.Close(); this.stream = null; } else { return true; } } if (features == ClientFeatures.None || features == ClientFeatures.Transparency) { features |= version.Value >= (ushort)DatFormat.Format_755 ? ClientFeatures.PatternZ : features; features |= version.Value >= (ushort)DatFormat.Format_960 ? ClientFeatures.Extended : features; features |= version.Value >= (ushort)DatFormat.Format_1050 ? ClientFeatures.FrameDurations : features; features |= version.Value >= (ushort)DatFormat.Format_1057 ? ClientFeatures.FrameGroups : features; } this.stream = new FileStream(path, FileMode.Open); this.reader = new BinaryReader(this.stream); uint signature = this.reader.ReadUInt32(); if (signature != version.SprSignature) { string message = "Invalid SPR signature. Expected signature is {0:X} and loaded signature is {1:X}."; throw new Exception(string.Format(message, version.SprSignature, signature)); } if ((features & ClientFeatures.Extended) == ClientFeatures.Extended) { this.headSize = HeaderU32; this.rawSpriteCount = this.reader.ReadUInt32(); } else { this.headSize = HeaderU16; this.rawSpriteCount = this.reader.ReadUInt16(); } this.FilePath = path; this.Version = version; this.ClientFeatures = features; this.transparency = (features & ClientFeatures.Transparency) == ClientFeatures.Transparency ? true : false; this.Count = this.rawSpriteCount; this.blankSprite = new Sprite(0, this.transparency); this.Changed = false; this.Loaded = true; this.Disposed = false; return true; }
public static bool ReadTexturePatterns(ThingType thing, ClientFeatures features, BinaryReader reader) { bool patternZEnabled = (features & ClientFeatures.PatternZ) == ClientFeatures.PatternZ; bool extendedEnabled = (features & ClientFeatures.Extended) == ClientFeatures.Extended; bool frameDurationsEnabled = (features & ClientFeatures.FrameDurations) == ClientFeatures.FrameDurations; bool frameGroupsEnabled = (features & ClientFeatures.FrameGroups) == ClientFeatures.FrameGroups; byte groupCount = 1; if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit) { groupCount = reader.ReadByte(); } for (byte k = 0; k < groupCount; k++) { FrameGroupType groupType = FrameGroupType.Default; if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit) { groupType = (FrameGroupType)reader.ReadByte(); } FrameGroup group = new FrameGroup(); group.Width = reader.ReadByte(); group.Height = reader.ReadByte(); if (group.Width > 1 || group.Height > 1) { group.ExactSize = reader.ReadByte(); } else { group.ExactSize = Sprite.DefaultSize; } group.Layers = reader.ReadByte(); group.PatternX = reader.ReadByte(); group.PatternY = reader.ReadByte(); group.PatternZ = patternZEnabled ? reader.ReadByte() : (byte)1; group.Frames = reader.ReadByte(); if (frameDurationsEnabled && group.Frames > 1) { group.IsAnimation = true; group.AnimationMode = (AnimationMode)reader.ReadByte(); group.LoopCount = reader.ReadInt32(); group.StartFrame = reader.ReadSByte(); group.FrameDurations = new FrameDuration[group.Frames]; for (int i = 0; i < group.Frames; i++) { uint minimum = reader.ReadUInt32(); uint maximum = reader.ReadUInt32(); group.FrameDurations[i] = new FrameDuration(minimum, maximum); } } int totalSprites = group.GetTotalSprites(); if (totalSprites > 4096) { throw new Exception("A thing type has more than 4096 sprites."); } group.SpriteIDs = new uint[totalSprites]; if (extendedEnabled) { for (int i = 0; i < totalSprites; i++) { group.SpriteIDs[i] = reader.ReadUInt32(); } } else { for (int i = 0; i < totalSprites; i++) { group.SpriteIDs[i] = reader.ReadUInt16(); } } thing.SetFrameGroup(groupType, group); } return true; }
/// <summary> /// Writes the specified config. /// </summary> public static void Write(IBinaryStream stream, CacheClientConfiguration cfg, ClientFeatures features, bool skipCodes = false) { Debug.Assert(stream != null); Debug.Assert(cfg != null); // Configuration should be written with a system marshaller. var writer = BinaryUtils.Marshaller.StartMarshal(stream); var pos = writer.Stream.Position; writer.WriteInt(0); // Reserve for length. if (!skipCodes) { writer.WriteShort(PropertyCount); // Property count. } var code = skipCodes ? (Action <Op>)(o => { }) : o => writer.WriteShort((short)o); code(Op.AtomicityMode); writer.WriteInt((int)cfg.AtomicityMode); code(Op.Backups); writer.WriteInt(cfg.Backups); code(Op.CacheMode); writer.WriteInt((int)cfg.CacheMode); code(Op.CopyOnRead); writer.WriteBoolean(cfg.CopyOnRead); code(Op.DataRegionName); writer.WriteString(cfg.DataRegionName); code(Op.EagerTtl); writer.WriteBoolean(cfg.EagerTtl); code(Op.StatisticsEnabled); writer.WriteBoolean(cfg.EnableStatistics); code(Op.GroupName); writer.WriteString(cfg.GroupName); code(Op.DefaultLockTimeout); writer.WriteTimeSpanAsLong(cfg.LockTimeout); code(Op.MaxConcurrentAsyncOperations); writer.WriteInt(cfg.MaxConcurrentAsyncOperations); code(Op.MaxQueryIteratorsCount); writer.WriteInt(cfg.MaxQueryIteratorsCount); code(Op.Name); writer.WriteString(cfg.Name); code(Op.OnheapCacheEnabled); writer.WriteBoolean(cfg.OnheapCacheEnabled); code(Op.PartitionLossPolicy); writer.WriteInt((int)cfg.PartitionLossPolicy); code(Op.QueryDetailMetricsSize); writer.WriteInt(cfg.QueryDetailMetricsSize); code(Op.QueryParallelism); writer.WriteInt(cfg.QueryParallelism); code(Op.ReadFromBackup); writer.WriteBoolean(cfg.ReadFromBackup); code(Op.RebalanceBatchSize); writer.WriteInt(cfg.RebalanceBatchSize); code(Op.RebalanceBatchesPrefetchCount); writer.WriteLong(cfg.RebalanceBatchesPrefetchCount); code(Op.RebalanceDelay); writer.WriteTimeSpanAsLong(cfg.RebalanceDelay); code(Op.RebalanceMode); writer.WriteInt((int)cfg.RebalanceMode); code(Op.RebalanceOrder); writer.WriteInt(cfg.RebalanceOrder); code(Op.RebalanceThrottle); writer.WriteTimeSpanAsLong(cfg.RebalanceThrottle); code(Op.RebalanceTimeout); writer.WriteTimeSpanAsLong(cfg.RebalanceTimeout); code(Op.SqlEscapeAll); writer.WriteBoolean(cfg.SqlEscapeAll); code(Op.SqlIndexMaxInlineSize); writer.WriteInt(cfg.SqlIndexMaxInlineSize); code(Op.SqlSchema); writer.WriteString(cfg.SqlSchema); code(Op.WriteSynchronizationMode); writer.WriteInt((int)cfg.WriteSynchronizationMode); code(Op.KeyConfiguration); writer.WriteCollectionRaw(cfg.KeyConfiguration); code(Op.QueryEntities); writer.WriteCollectionRaw(cfg.QueryEntities, (w, qe) => WriteQueryEntity(w, qe, features)); code(Op.ExpiryPolicy); ExpiryPolicySerializer.WritePolicyFactory(writer, cfg.ExpiryPolicyFactory); // Write length (so that part of the config can be skipped). var len = writer.Stream.Position - pos - 4; writer.Stream.WriteInt(pos, len); }
////////////////////////////////////////////////////////////////////////////////////////////// // Simple example using Inventor API directly // ////////////////////////////////////////////////////////////////////////////////////////////// public static void ClientFeatureDemo() { string clientId = AdnInventorUtilities.AddInGuid; Inventor.Application InvApp = AdnInventorUtilities.InvApplication; Document document = InvApp.ActiveDocument; // We will use late binding to retrieve ClientFeatures collection, // so we dont need to write specific code for PartDocument and // AssemblyDocument ComponentDefinition compDef = AdnInventorUtilities.GetCompDefinition(document); object features = AdnInventorUtilities.GetProperty(compDef, "Features"); ClientFeatures clientFeatures = AdnInventorUtilities.GetProperty(features, "ClientFeatures") as ClientFeatures; ClientFeatureDefinition cfDef = clientFeatures.CreateDefinition("Graphics Feature", null, null, null); ClientFeature clientFeature = clientFeatures.Add(cfDef, clientId); NativeBrowserNodeDefinition nodeDef = clientFeature.BrowserNode.BrowserNodeDefinition as NativeBrowserNodeDefinition; stdole.IPictureDisp pic = PictureDispConverter.ToIPictureDisp(Resources.PointImage); ClientNodeResource res = document.BrowserPanes.ClientNodeResources.Add( clientId, document.BrowserPanes.ClientNodeResources.Count + 1, pic); nodeDef.OverrideIcon = res; cfDef = clientFeature.Definition; cfDef.HighlightClientGraphicsWithFeature = true; GraphicsDataSets sets = cfDef.GraphicsDataSetsCollection.Add2(clientId, true); GraphicsCoordinateSet coordSet = sets.CreateCoordinateSet(1); double[] coords = new double[] { 0.0, 0.0, 0.0, 5.0, 0.0, 0.0, 2.5, 5.0, 0.0 }; coordSet.PutCoordinates(ref coords); ClientGraphics cg = cfDef.ClientGraphicsCollection.Add(clientId); GraphicsNode node = cg.AddNode(1); node.RenderStyle = document.RenderStyles["Green (Flat)"]; TriangleGraphics primitive = node.AddTriangleGraphics(); primitive.CoordinateSet = coordSet; InvApp.ActiveView.Update(); }
/// <summary> /// Write query entity of the config. /// </summary> private static void WriteQueryEntity(BinaryWriter writer, QueryEntity entity, ClientFeatures features) { writer.WriteString(entity.KeyTypeName); writer.WriteString(entity.ValueTypeName); writer.WriteString(entity.TableName); writer.WriteString(entity.KeyFieldName); writer.WriteString(entity.ValueFieldName); var entityFields = entity.Fields; if (entityFields != null) { writer.WriteInt(entityFields.Count); foreach (var field in entityFields) { WriteQueryField(writer, field, features); } } else { writer.WriteInt(0); } var entityAliases = entity.Aliases; if (entityAliases != null) { writer.WriteInt(entityAliases.Count); foreach (var queryAlias in entityAliases) { writer.WriteString(queryAlias.FullName); writer.WriteString(queryAlias.Alias); } } else { writer.WriteInt(0); } var entityIndexes = entity.Indexes; if (entityIndexes != null) { writer.WriteInt(entityIndexes.Count); foreach (var index in entityIndexes) { if (index == null) { throw new InvalidOperationException("Invalid cache configuration: QueryIndex can't be null."); } index.Write(writer); } } else { writer.WriteInt(0); } }
public bool Save(string path, Core.Version version, ClientFeatures features) { if (path == null) { throw new ArgumentNullException("path"); } if (version == null) { throw new ArgumentNullException("version"); } if (this.Disposed) { throw new ObjectDisposedException(this.GetType().Name); } if (!this.Loaded) { return false; } if (features == ClientFeatures.None || features == ClientFeatures.Transparency) { features |= version.Value >= (ushort)DatFormat.Format_755 ? ClientFeatures.PatternZ : features; features |= version.Value >= (ushort)DatFormat.Format_960 ? ClientFeatures.Extended : features; features |= version.Value >= (ushort)DatFormat.Format_1050 ? ClientFeatures.FrameDurations : features; features |= version.Value >= (ushort)DatFormat.Format_1057 ? ClientFeatures.FrameGroups : features; } string directory = Path.GetDirectoryName(path); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } if (!this.Changed && this.Version.Equals(version) && this.ClientFeatures == features && this.FilePath != null && !this.FilePath.Equals(path)) { // just copy the content if nothing has changed. File.Copy(this.FilePath, path, true); if (this.ProgressChanged != null) { this.ProgressChanged(this, 100); } } else { string tmpPath = Path.Combine(directory, Path.GetFileNameWithoutExtension(path) + ".tmp"); using (BinaryWriter writer = new BinaryWriter(new FileStream(tmpPath, FileMode.Create))) { // write the signature. writer.Write(version.DatSignature); // write item, outfit, effect and missile count. writer.Write(this.ItemCount); writer.Write(this.OutfitCount); writer.Write(this.EffectCount); writer.Write(this.MissileCount); int total = this.ItemCount + this.OutfitCount + this.EffectCount + this.MissileCount; int compiled = 0; // write item list. for (ushort id = 100; id <= this.ItemCount; id++) { ThingType item = this.Items[id]; if (!ThingTypeSerializer.WriteProperties(item, this.Version.Format, writer) || !ThingTypeSerializer.WriteTexturePatterns(item, features, writer)) { throw new Exception("Items list cannot be compiled."); } } // update progress. if (this.ProgressChanged != null) { compiled += this.ItemCount; this.ProgressChanged(this, (compiled * 100) / total); } bool onlyOneGroup = ((this.ClientFeatures & ClientFeatures.FrameGroups) == ClientFeatures.FrameGroups) && ((features & ClientFeatures.FrameGroups) != ClientFeatures.FrameGroups); // write outfit list. for (ushort id = 1; id <= this.OutfitCount; id++) { ThingType outfit = onlyOneGroup ? ThingType.ToSingleFrameGroup(this.Outfits[id]) : this.Outfits[id]; if (!ThingTypeSerializer.WriteProperties(outfit, this.Version.Format, writer) || !ThingTypeSerializer.WriteTexturePatterns(outfit, features, writer)) { throw new Exception("Outfits list cannot be compiled."); } } // update progress. if (this.ProgressChanged != null) { compiled += this.OutfitCount; this.ProgressChanged(this, (compiled * 100) / total); } // write effect list. for (ushort id = 1; id <= this.EffectCount; id++) { ThingType effect = this.Effects[id]; if (!ThingTypeSerializer.WriteProperties(effect, this.Version.Format, writer) || !ThingTypeSerializer.WriteTexturePatterns(effect, features, writer)) { throw new Exception("Effects list cannot be compiled."); } } // update progress. if (this.ProgressChanged != null) { compiled += this.EffectCount; this.ProgressChanged(this, (compiled * 100) / total); } // write missile list. for (ushort id = 1; id <= this.MissileCount; id++) { ThingType missile = this.Missiles[id]; if (!ThingTypeSerializer.WriteProperties(missile, this.Version.Format, writer) || !ThingTypeSerializer.WriteTexturePatterns(missile, features, writer)) { throw new Exception("Missiles list cannot be compiled."); } } // update progress. if (this.ProgressChanged != null) { compiled += this.MissileCount; this.ProgressChanged(this, (compiled * 100) / total); } } if (File.Exists(path)) { File.Delete(path); } File.Move(tmpPath, path); } this.FilePath = path; this.Version = version; this.ClientFeatures = features; this.Changed = false; if (this.StorageCompiled != null) { this.StorageCompiled(this, new EventArgs()); } return true; }
/// <summary> /// Initializes a new instance of the <see cref="CacheClientConfiguration"/> class. /// </summary> internal CacheClientConfiguration(IBinaryStream stream, ClientFeatures features) { Debug.Assert(stream != null); ClientCacheConfigurationSerializer.Read(stream, this, features); }
public static bool WriteTexturePatterns(ThingType thing, ClientFeatures features, BinaryWriter writer) { bool patternZEnabled = (features & ClientFeatures.PatternZ) == ClientFeatures.PatternZ; bool extendedEnabled = (features & ClientFeatures.Extended) == ClientFeatures.Extended; bool frameDurationsEnabled = (features & ClientFeatures.FrameDurations) == ClientFeatures.FrameDurations; bool frameGroupsEnabled = (features & ClientFeatures.FrameGroups) == ClientFeatures.FrameGroups; byte groupCount = 1; // write frame group count. if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit) { groupCount = thing.FrameGroupCount; writer.Write(groupCount); } for (byte k = 0; k < groupCount; k++) { // write frame group type. if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit) { writer.Write(k); } FrameGroup group = thing.GetFrameGroup((FrameGroupType)k); writer.Write(group.Width); // write width writer.Write(group.Height); // write heigh // write exact size if (group.Width > 1 || group.Height > 1) { writer.Write(group.ExactSize); } writer.Write(group.Layers); // write layers writer.Write(group.PatternX); // write pattern X writer.Write(group.PatternY); // write pattern Y if (patternZEnabled) { writer.Write(group.PatternZ); // write pattern Z } writer.Write(group.Frames); // write frames if (frameDurationsEnabled && group.Frames > 1) { writer.Write((byte)group.AnimationMode); // write animation type writer.Write(group.LoopCount); // write frame strategy writer.Write(group.StartFrame); // write start frame FrameDuration[] durations = group.FrameDurations; for (int i = 0; i < durations.Length; i++) { writer.Write((uint)durations[i].Minimum); // write minimum duration writer.Write((uint)durations[i].Maximum); // write maximum duration } } uint[] sprites = group.SpriteIDs; for (int i = 0; i < sprites.Length; i++) { // write sprite index if (extendedEnabled) { writer.Write(sprites[i]); } else { writer.Write((ushort)sprites[i]); } } } return true; }
private bool InternalLoad(string path, Core.Version version, ClientFeatures features) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } if (version == null) { throw new ArgumentNullException("version"); } if (!File.Exists(path)) { throw new FileNotFoundException(string.Format("File not found: {0}", path), path); } if (this.Loaded) { return true; } if (features == ClientFeatures.None || features == ClientFeatures.Transparency) { features |= version.Value >= (ushort)DatFormat.Format_755 ? ClientFeatures.PatternZ : features; features |= version.Value >= (ushort)DatFormat.Format_960 ? ClientFeatures.Extended : features; features |= version.Value >= (ushort)DatFormat.Format_1050 ? ClientFeatures.FrameDurations : features; features |= version.Value >= (ushort)DatFormat.Format_1057 ? ClientFeatures.FrameGroups : features; } using (FileStream stream = new FileStream(path, FileMode.Open)) { BinaryReader reader = new BinaryReader(stream); uint signature = reader.ReadUInt32(); if (signature != version.DatSignature) { string message = "Invalid DAT signature. Expected signature is {0:X} and loaded signature is {1:X}."; throw new Exception(string.Format(message, version.DatSignature, signature)); } this.ItemCount = reader.ReadUInt16(); this.OutfitCount = reader.ReadUInt16(); this.EffectCount = reader.ReadUInt16(); this.MissileCount = reader.ReadUInt16(); int total = this.ItemCount + this.OutfitCount + this.EffectCount + this.MissileCount; int loaded = 0; // load item list. for (ushort id = 100; id <= this.ItemCount; id++) { ThingType item = new ThingType(id, ThingCategory.Item); if (!ThingTypeSerializer.ReadProperties(item, version.Format, reader) || !ThingTypeSerializer.ReadTexturePatterns(item, features, reader)) { throw new Exception("Items list cannot be loaded."); } this.Items.Add(id, item); } // update progress. if (this.ProgressChanged != null) { loaded += this.ItemCount; this.ProgressChanged(this, (loaded * 100) / total); } // load outfit list. for (ushort id = 1; id <= this.OutfitCount; id++) { ThingType outfit = new ThingType(id, ThingCategory.Outfit); if (!ThingTypeSerializer.ReadProperties(outfit, version.Format, reader) || !ThingTypeSerializer.ReadTexturePatterns(outfit, features, reader)) { throw new Exception("Outfits list cannot be loaded."); } this.Outfits.Add(id, outfit); } // update progress. if (this.ProgressChanged != null) { loaded += this.OutfitCount; this.ProgressChanged(this, (loaded * 100) / total); } // load effect list. for (ushort id = 1; id <= this.EffectCount; id++) { ThingType effect = new ThingType(id, ThingCategory.Effect); if (!ThingTypeSerializer.ReadProperties(effect, version.Format, reader) || !ThingTypeSerializer.ReadTexturePatterns(effect, features, reader)) { throw new Exception("Effects list cannot be loaded."); } this.Effects.Add(id, effect); } // update progress. if (this.ProgressChanged != null) { loaded += this.EffectCount; this.ProgressChanged(this, (loaded * 100) / total); } // load missile list. for (ushort id = 1; id <= this.MissileCount; id++) { ThingType missile = new ThingType(id, ThingCategory.Missile); if (!ThingTypeSerializer.ReadProperties(missile, version.Format, reader) || !ThingTypeSerializer.ReadTexturePatterns(missile, features, reader)) { throw new Exception("Missiles list cannot be loaded."); } this.Missiles.Add(id, missile); } // update progress. if (this.ProgressChanged != null) { loaded += this.MissileCount; this.ProgressChanged(this, (loaded * 100) / total); } } this.FilePath = path; this.Version = version; this.ClientFeatures = features; this.Changed = false; this.Loaded = true; this.Disposed = false; return true; }
public static ThingTypeStorage Load(string path, Core.Version version, ClientFeatures features) { ThingTypeStorage storage = new ThingTypeStorage(); if (storage.InternalLoad(path, version, features)) { return storage; } return null; }
public static bool ReadTexturePatterns(ThingType thing, ClientFeatures features, BinaryReader reader) { bool patternZEnabled = (features & ClientFeatures.PatternZ) == ClientFeatures.PatternZ; bool extendedEnabled = (features & ClientFeatures.Extended) == ClientFeatures.Extended; bool frameDurationsEnabled = (features & ClientFeatures.FrameDurations) == ClientFeatures.FrameDurations; bool frameGroupsEnabled = (features & ClientFeatures.FrameGroups) == ClientFeatures.FrameGroups; byte groupCount = 1; if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit) { groupCount = reader.ReadByte(); } for (byte k = 0; k < groupCount; k++) { FrameGroupType groupType = FrameGroupType.Default; if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit) { groupType = (FrameGroupType)reader.ReadByte(); } FrameGroup group = new FrameGroup(); group.Width = reader.ReadByte(); group.Height = reader.ReadByte(); if (group.Width > 1 || group.Height > 1) { group.ExactSize = reader.ReadByte(); } else { group.ExactSize = Sprite.DefaultSize; } group.Layers = reader.ReadByte(); group.PatternX = reader.ReadByte(); group.PatternY = reader.ReadByte(); group.PatternZ = patternZEnabled ? reader.ReadByte() : (byte)1; group.Frames = reader.ReadByte(); if (frameDurationsEnabled && group.Frames > 1) { group.IsAnimation = true; group.AnimationMode = (AnimationMode)reader.ReadByte(); group.LoopCount = reader.ReadInt32(); group.StartFrame = reader.ReadSByte(); group.FrameDurations = new FrameDuration[group.Frames]; for (int i = 0; i < group.Frames; i++) { uint minimum = reader.ReadUInt32(); uint maximum = reader.ReadUInt32(); group.FrameDurations[i] = new FrameDuration(minimum, maximum); } } int totalSprites = group.GetTotalSprites(); if (totalSprites > 4096) { throw new Exception("A thing type has more than 4096 sprites."); } group.SpriteIDs = new uint[totalSprites]; if (extendedEnabled) { for (int i = 0; i < totalSprites; i++) { group.SpriteIDs[i] = reader.ReadUInt32(); } } else { for (int i = 0; i < totalSprites; i++) { group.SpriteIDs[i] = reader.ReadUInt16(); } } thing.SetFrameGroup(groupType, group); } return(true); }
private bool InternalCreate(Core.Version version, ClientFeatures features) { if (this.Compiling) { return false; } if (this.Loaded) { return true; } if (features == ClientFeatures.None || features == ClientFeatures.Transparency) { features |= version.Value >= (ushort)DatFormat.Format_755 ? ClientFeatures.PatternZ : features; features |= version.Value >= (ushort)DatFormat.Format_960 ? ClientFeatures.Extended : features; features |= version.Value >= (ushort)DatFormat.Format_1050 ? ClientFeatures.FrameDurations : features; features |= version.Value >= (ushort)DatFormat.Format_1057 ? ClientFeatures.FrameGroups : features; } this.Version = version; this.ClientFeatures = features; this.transparency = (features & ClientFeatures.Transparency) == ClientFeatures.Transparency ? true : false; this.headSize = (features & ClientFeatures.Extended) == ClientFeatures.Extended ? HeaderU32 : HeaderU16; this.blankSprite = new Sprite(0, this.transparency); this.sprites.Add(1, new Sprite(1, this.transparency)); this.rawSpriteCount = 0; this.Count = 1; this.Changed = true; this.Loaded = true; this.Compiling = false; this.Disposed = false; return true; }