public JObject ToJson() { JObject json = new JObject(); json["assethash"] = AssetHash.ToString(); json["amount"] = Amount.ToString(); json["lastupdatedblock"] = LastUpdatedBlock; return(json); }
public JObject ToJson() { JObject json = new JObject(); json["asset_hash"] = AssetHash.ToArray().ToHexString(); json["amount"] = Amount.ToString(); json["last_updated_block"] = LastUpdatedBlock.ToString(); return(json); }
public void TestHash() { var obj1 = new TestAssetClonerObject { Name = "Test1", SubObject = new TestAssetClonerObject() { Name = "Test2" }, ObjectWithAttachedReference = new TestObjectReference() }; // Create a fake reference to make sure that the attached reference will not be serialized var attachedReference = AttachedReferenceManager.GetOrCreateAttachedReference(obj1.ObjectWithAttachedReference); attachedReference.Url = "just_for_test"; attachedReference.Id = Guid.NewGuid(); // Setup some proper id on objects so serialization is stable IdentifiableHelper.SetId(obj1, new Guid("EC86143E-896F-45C5-9A4D-627317D22955")); IdentifiableHelper.SetId(obj1.SubObject, new Guid("34E160CD-1D94-468E-8BFD-F82FF96013FC")); var obj2 = (TestAssetClonerObject)AssetCloner.Clone(obj1); var hash1 = AssetHash.Compute(obj1); var hash2 = AssetHash.Compute(obj2); Assert.AreEqual(hash1, hash2); obj1.Name = "Yes"; var hash11 = AssetHash.Compute(obj1); Assert.AreNotEqual(hash11, hash2); obj1.Name = "Test1"; var hash12 = AssetHash.Compute(obj1); Assert.AreEqual(hash12, hash2); // Test the same with overrides var objDesc = TypeDescriptorFactory.Default.Find(typeof(TestAssetClonerObject)); var memberDesc = objDesc.Members.First(t => t.Name == "Name"); obj1.SetOverride(memberDesc, OverrideType.New); obj1.SubObject.SetOverride(memberDesc, OverrideType.Sealed); obj2 = (TestAssetClonerObject)AssetCloner.Clone(obj1); var hash1WithOverrides = AssetHash.Compute(obj1); var hash2WithOverrides = AssetHash.Compute(obj2); Assert.AreNotEqual(hash1, hash1WithOverrides); Assert.AreNotEqual(hash2, hash2WithOverrides); Assert.AreEqual(hash1WithOverrides, hash2WithOverrides); }
private static bool CompareAssets(Asset left, Asset right) { // Computes the hash on the clone (so that we don't have a .Base/.BaseParts in them // TODO: We might want to store the hash in the asset in order to avoid a recompute at load time // (but would require a compute at save time) var baseId = AssetHash.Compute(left); var newBaseCopyId = AssetHash.Compute(right); // If the old base and new base are similar (including ids and overrides), we don't need to perform a merge return(baseId == newBaseCopyId); }
public JObject ToJson(ProtocolSettings protocolSettings) { JObject json = new JObject(); json["timestamp"] = TimestampMS; json["assethash"] = AssetHash.ToString(); json["transferaddress"] = UserScriptHash?.ToAddress(protocolSettings.AddressVersion); json["amount"] = Amount.ToString(); json["blockindex"] = BlockIndex; json["transfernotifyindex"] = TransferNotifyIndex; json["txhash"] = TxHash.ToString(); return(json); }
public JObject ToJson() { JObject json = new JObject(); json["timestamp"] = TimestampMS; json["asset_hash"] = AssetHash.ToString(); json["transfer_address"] = UserScriptHash.ToAddress(); json["amount"] = Amount.ToString(); json["block_index"] = BlockIndex; json["transfer_notify_index"] = TransferNotifyIndex; json["tx_hash"] = TxHash.ToString(); return(json); }
public static uint GetAssetTypeId <T>(SageGame game) where T : BaseAsset { var type = typeof(T); var attributes = type.GetCustomAttributes(typeof(AssetTypeIdOverrideAttribute), false); foreach (var attribute in attributes.Cast <AssetTypeIdOverrideAttribute>()) { if (attribute.Game == game) { return((uint)attribute.Type); } } return(AssetHash.GetHashCaseSensitive(type.Name)); }
public void TestHash() { var obj1 = new TestAssetClonerObject { Name = "Test1", SubObject = new TestAssetClonerObject() { Name = "Test2" }, ObjectWithAttachedReference = new TestObjectReference() }; // Create a fake reference to make sure that the attached reference will not be serialized var attachedReference = AttachedReferenceManager.GetOrCreateAttachedReference(obj1.ObjectWithAttachedReference); attachedReference.Url = "just_for_test"; attachedReference.Id = AssetId.New(); var obj2 = AssetCloner.Clone(obj1); var hash1 = AssetHash.Compute(obj1); var hash2 = AssetHash.Compute(obj2); Assert.AreEqual(hash1, hash2); obj1.Name = "Yes"; var hash11 = AssetHash.Compute(obj1); Assert.AreNotEqual(hash11, hash2); obj1.Name = "Test1"; var hash12 = AssetHash.Compute(obj1); Assert.AreEqual(hash12, hash2); obj2 = AssetCloner.Clone(obj1); var hash1WithOverrides = AssetHash.Compute(obj1); var hash2WithOverrides = AssetHash.Compute(obj2); Assert.AreEqual(hash1WithOverrides, hash2WithOverrides); }
private bool MergeAsset(AssetItem item, AssetItem existingBase, List <AssetBase> existingBaseParts) { // No need to clone existingBaseParts as they are already cloned var baseCopy = (Asset)AssetCloner.Clone(item.Asset.Base?.Asset); var newBaseCopy = (Asset)AssetCloner.Clone(existingBase?.Asset); // Computes the hash on the clone (so that we don't have a .Base/.BaseParts in them // TODO: We might want to store the hash in the asset in order to avoid a recompute at load time // (but would require a compute at save time) var baseId = AssetHash.Compute(baseCopy); var newBaseCopyId = AssetHash.Compute(newBaseCopy); // If the old base and new base are similar (including ids and overrides), we don't need to perform a merge if (baseId == newBaseCopyId) { return(true); } // Delegates actual merge to the asset implem var result = item.Asset.Merge(baseCopy, newBaseCopy, existingBaseParts); if (result.HasErrors) { result.CopyTo(log); return(false); } item.Asset = (Asset)result.Asset; if (item.Asset.Base != null) { item.Asset.Base = newBaseCopy != null ? new AssetBase(item.Asset.Base.Location, newBaseCopy) : null; } // Use new existing base parts if (existingBaseParts != null) { item.Asset.BaseParts = existingBaseParts; } item.IsDirty = true; return(true); }
public string Generate(string path) { var models = new ESOModel[4]; for (short x = 0; x < level.Size.Width; x++) { for (short y = 0; y < level.Size.Length; y++) { for (short z = 0; z < level.Size.Height; z++) { var info = GetInformation(x, y, z); if (info.Height < 0) { continue; } var theme = themes[info.Theme]; if (models[theme] == null) { models[theme] = new ESOModel(ESOModel.Flags.Normals | ESOModel.Flags.TexCoords) { MaterialAsset = AssetHash.Parse(Materials[theme] + ModelsNamespace) } } ; var model = models[theme]; short x1 = (short)(x + 1), y1 = (short)(y + 1), z1 = (short)(z + 1); float texY1 = 1 - z * 0.25F, texY = texY1 - 0.25F; if (GetInformation(x, y, z1).Height < 1 && (Math.Abs(x - level.ExitPoint.X) > 1 || Math.Abs(y - level.ExitPoint.Y) > 1 || z1 != level.ExitPoint.Z)) { model.Vertices.Add(Transform(new Vec3(x, z1, y))); model.Vertices.Add(Transform(new Vec3(x1, z1, y))); model.Vertices.Add(Transform(new Vec3(x, z1, y1))); model.Vertices.Add(Transform(new Vec3(x, z1, y1))); model.Vertices.Add(Transform(new Vec3(x1, z1, y))); model.Vertices.Add(Transform(new Vec3(x1, z1, y1))); model.Normals.AddRange(YNormals); float texX = ((x + y) & 1) == 0 ? 0.51F : 0.76F, texX1 = texX + 0.23F; model.TexCoords.Add(new Vec2(texX, texY)); model.TexCoords.Add(new Vec2(texX1, texY)); model.TexCoords.Add(new Vec2(texX, texY1)); model.TexCoords.Add(new Vec2(texX, texY1)); model.TexCoords.Add(new Vec2(texX1, texY)); model.TexCoords.Add(new Vec2(texX1, texY1)); } if (info.Height <= 0) { continue; } var zB = z1 - info.Height; texY1 -= 0.25F * (1 - info.Height); if (GetInformation(x1, y, z).Height < info.Height) { model.Vertices.Add(Transform(new Vec3(x1, zB, y))); model.Vertices.Add(Transform(new Vec3(x1, zB, y1))); model.Vertices.Add(Transform(new Vec3(x1, z1, y))); model.Vertices.Add(Transform(new Vec3(x1, zB, y1))); model.Vertices.Add(Transform(new Vec3(x1, z1, y1))); model.Vertices.Add(Transform(new Vec3(x1, z1, y))); model.Normals.AddRange(XNormals); model.TexCoords.Add(new Vec2(0.49F, texY1)); model.TexCoords.Add(new Vec2(0.26F, texY1)); model.TexCoords.Add(new Vec2(0.49F, texY)); model.TexCoords.Add(new Vec2(0.26F, texY1)); model.TexCoords.Add(new Vec2(0.26F, texY)); model.TexCoords.Add(new Vec2(0.49F, texY)); } if (GetInformation(x, y1, z).Height < info.Height) { model.Vertices.Add(Transform(new Vec3(x, zB, y1))); model.Vertices.Add(Transform(new Vec3(x, z1, y1))); model.Vertices.Add(Transform(new Vec3(x1, zB, y1))); model.Vertices.Add(Transform(new Vec3(x, z1, y1))); model.Vertices.Add(Transform(new Vec3(x1, z1, y1))); model.Vertices.Add(Transform(new Vec3(x1, zB, y1))); model.Normals.AddRange(ZNormals); model.TexCoords.Add(new Vec2(0.01F, texY1)); model.TexCoords.Add(new Vec2(0.01F, texY)); model.TexCoords.Add(new Vec2(0.24F, texY1)); model.TexCoords.Add(new Vec2(0.01F, texY)); model.TexCoords.Add(new Vec2(0.24F, texY)); model.TexCoords.Add(new Vec2(0.24F, texY1)); } } } } string fileName = Path.GetFileNameWithoutExtension(path) + ".rmdl", result; models = models.Where(model => model != null).ToArray(); new ESO { AssetHeader = new AssetHeader(AssetUtil.EngineVersion.Version1804Edge, fileName, "models"), Models = models, Header = new ESOHeader { V01 = 1, V02 = 4096, V20 = 1, NumModels = models.Length, ScaleXYZ = 1, Scale = new Vec3(0.1F, 0.1F, 0.1F), Translate = Translates[themes[0]], NodeChild = AssetHash.Parse(ChildModels[themes[0]] + ModelsNamespace), BoundingMin = Transform(new Vec3()), BoundingMax = Transform(new Vec3(level.Size.Width, level.Size.Height, level.Size.Length)) } }.Save(result = Path.Combine(Path.GetDirectoryName(path), AssetUtil.CrcFullName(fileName, "models") + ".eso")); return(result); } }
protected void SetNameAndInstanceId(string typeName, string name) { Name = name; FullName = $"{typeName}:{name}"; InstanceId = AssetHash.GetHash(name); }