static void Main(string[] args) { if (args[0].EndsWith("spr_db.bin")) { var SpriteDb = BinaryFile.Load <SpriteDatabase>(args[0]); foreach (var SpriteSet in SpriteDb.SpriteSets) { Console.WriteLine(SpriteSet.Name); SpriteSet.Id = MurmurHash.Calculate(SpriteSet.Name); Console.WriteLine("Murmur Hashed Id: " + SpriteSet.Id + "\n"); foreach (var Sprite in SpriteSet.Sprites) { Console.WriteLine(Sprite.Name); Sprite.Id = MurmurHash.Calculate(Sprite.Name); Console.WriteLine("Murmur Hashed Id: " + Sprite.Id + "\n"); } } SpriteDb.Save(args[0]); } if (args[0].EndsWith("aet_db.bin")) { var AetDb = BinaryFile.Load <AetDatabase>(args[0]); foreach (var AetSet in AetDb.AetSets) { AetSet.SpriteSetId = MurmurHash.Calculate(AetSet.Name.Replace("AET_", "SPR_")); } AetDb.Save(args[0]); } }
public void Save(Stream destination, Skeleton skeleton, bool leaveOpen = false) { if (skeleton != null) { mBinding?.Unbind(skeleton); } // Force modern format if we are saving motions individually if (!Format.IsModern()) { Format = BinaryFormat.F2nd; } if (!string.IsNullOrEmpty(Name)) { Id = MurmurHash.Calculate(Name); } foreach (var boneInfo in BoneInfos.Where(boneInfo => !string.IsNullOrEmpty(boneInfo.Name))) { boneInfo.Id = MurmurHash.Calculate(boneInfo.Name); } Save(destination, leaveOpen); }
private static Texture CreateTextureFromFilePath(string filePath, TextureFormat formatHint, string texturesDirectoryPath, TextureSet textureSet) { string textureName = Path.GetFileNameWithoutExtension(filePath); var texture = textureSet.Textures.FirstOrDefault(x => x.Name.Equals(textureName, StringComparison.OrdinalIgnoreCase)); if (texture != null) { return(texture); } string newFilePath = FindTexturePath(filePath, texturesDirectoryPath); if (string.IsNullOrEmpty(newFilePath)) { return(null); } texture = TextureEncoder.EncodeFromFile(newFilePath, formatHint, true); texture.Name = textureName; texture.Id = MurmurHash.Calculate(textureName); textureSet.Textures.Add(texture); return(texture); }
private static Object CreateObjectFromAiNode(Ai.Node aiNode, Ai.Scene aiScene, ObjectSet objectSet, string texturesDirectoryPath) { var obj = new Object(); obj.Name = aiNode.Name; obj.Id = MurmurHash.Calculate(aiNode.Name); obj.Skin = new Skin(); var aabb = new AxisAlignedBoundingBox(); CreateRecursively(aiNode); void CreateRecursively(Ai.Node aiChildNode) { if (aiChildNode.HasMeshes) { var meshes = CreateMeshesFromAiNode(aiChildNode, aiScene, obj, ref aabb, objectSet, texturesDirectoryPath); if (meshes?.Count > 0) { obj.Meshes.AddRange(meshes); } } foreach (var aiAlsoChildNode in aiChildNode.Children) { CreateRecursively(aiAlsoChildNode); } } obj.BoundingSphere = aabb.ToBoundingSphere(); if (obj.Skin.Bones.Count > 0) { foreach (var boneInfo in obj.Skin.Bones) { var aiBoneNode = aiScene.RootNode.FindNode(boneInfo.Name); if (aiBoneNode.Parent == null || aiBoneNode.Parent == aiScene.RootNode) { continue; } boneInfo.Parent = obj.Skin.Bones.FirstOrDefault(x => x.Name == aiBoneNode.Parent.Name); } } else { obj.Skin = null; } return(obj); }
public override void Write(EndianBinaryWriter writer, ISection section = null) { if (section != null) { WriteModern(); } else { WriteClassic(); } void WriteClassic() { var paramWriter = new ParameterTreeWriter(); writer.WriteLine("# This file was generated automatically. DO NOT EDIT."); foreach (var parameter in Parameters) { parameter.Write(paramWriter); } paramWriter.Flush(writer.BaseStream); } void WriteModern() { if (section.Format == BinaryFormat.X) { writer.Write(Parameters.Count); writer.WriteNulls(2 * sizeof(uint)); writer.ScheduleWriteOffset(16, AlignmentMode.Left, WriteParameters); writer.WriteNulls(2 * sizeof(ulong)); } else { writer.Write(Parameters.Count); writer.ScheduleWriteOffset(16, AlignmentMode.Left, WriteParameters); writer.WriteNulls(4 * sizeof(uint)); } } void WriteParameters() { foreach (var parameter in Parameters.OrderBy(x => MurmurHash.Calculate(x.Name))) { parameter.Write(writer); } } }
internal void Write(EndianBinaryWriter writer) { // X if (writer.AddressSpace == AddressSpace.Int64) { writer.Write(Type); writer.Write(Radius); writer.Write(( ulong )MurmurHash.Calculate(Bone0.Name)); writer.Write(( ulong )MurmurHash.Calculate(Bone1.Name)); writer.WriteNulls(8); writer.Write(Bone0.Position); writer.WriteNulls(4); writer.Write(Bone1.Position); writer.WriteNulls(4); writer.AddStringToStringTable(Bone0.Name); writer.AddStringToStringTable(Bone1.Name); } // F 2nd else { writer.Write(Type); writer.Write(( byte )0xD); writer.Align(4); writer.Write(( ulong )MurmurHash.Calculate(Bone0.Name)); writer.Write(( ulong )MurmurHash.Calculate(Bone1.Name)); writer.Write(Radius); writer.Write(Bone0.Position); writer.Write(Bone1.Position); writer.Write(( byte )0xD); writer.Align(4); writer.AddStringToStringTable(Bone0.Name); writer.AddStringToStringTable(Bone1.Name); } }
private void OnGenerateMurmurHashes(object sender, EventArgs e) { while (true) { using (var inputDialog = new InputDialog() { WindowTitle = "Enter input" }) { if (inputDialog.ShowDialog() != DialogResult.OK) { break; } uint hash = MurmurHash.Calculate(inputDialog.Input); MessageBox.Show($"{inputDialog.Input}: 0x{hash:X8} ({hash})", Program.Name, MessageBoxButtons.OK, MessageBoxIcon.None); } } }
internal void Write(EndianBinaryWriter writer) { writer.Write(Force); writer.Write(ForceGain); writer.Write(AirResistance); if (writer.AddressSpace == AddressSpace.Int64) { writer.WriteNulls(4); } writer.Write(RotationY); writer.Write(RotationZ); writer.Write(InitRotationY); writer.Write(InitRotationZ); writer.Write(HingeY); writer.Write(HingeZ); writer.AddStringToStringTable(Name); int collisionCount = Math.Min(12, Collisions.Count); for (int i = 0; i < collisionCount; i++) { Collisions[i].Write(writer); } for (int i = 0; i < 12 - collisionCount; i++) { OsageCollisionParameter.WriteNull(writer); } writer.WriteNulls(4); writer.Write(Friction); writer.Write(WindAffection); writer.WriteNulls(4); // X if (writer.AddressSpace == AddressSpace.Int64) { writer.Write(Bocs.Count); writer.Write(CollisionType); writer.ScheduleWriteOffsetIf(Bocs.Count > 0, 16, AlignmentMode.Left, WriteBocs); writer.Write(Nodes.Count); writer.WriteNulls(8); writer.Write(( ulong )MurmurHash.Calculate(Name)); writer.ScheduleWriteOffsetIf(Nodes.Count > 0, 16, AlignmentMode.Left, WriteNodes); } // F 2nd else { writer.Write(Bocs.Count); writer.ScheduleWriteOffsetIf(Bocs.Count > 0, 16, AlignmentMode.Left, WriteBocs); writer.Write(CollisionType); writer.WriteNulls(4); writer.Write(( ulong )MurmurHash.Calculate(Name)); writer.Write(Nodes.Count); writer.ScheduleWriteOffsetIf(Nodes.Count > 0, 16, AlignmentMode.Left, WriteNodes); } void WriteBocs() { foreach (var boc in Bocs) { boc.Write(writer); } } void WriteNodes() { foreach (var node in Nodes) { node.Write(writer); } } }
public void Unbind(Skeleton skeleton, MotionDatabase motionDatabase = null) { Parent.KeySets.Clear(); Parent.BoneInfos.Clear(); foreach (var boneBinding in skeleton.MotionBoneNames .Where(x => motionDatabase == null || motionDatabase.BoneNames.Contains(x, StringComparer.OrdinalIgnoreCase)) .Select(x => BoneBindings.Find(y => y.Name.Equals(x, StringComparison.OrdinalIgnoreCase)) ?? new BoneBinding { Name = x }) .OrderBy(x => sReferenceIndices.TryGetValue(x.Name, out int index) ? index : int.MaxValue)) { var bone = skeleton.GetBone(boneBinding.Name); if (bone != null) { if (bone.Type != BoneType.Rotation) { UnbindPosition(boneBinding); } if (bone.Type != BoneType.Position) { UnbindRotation(boneBinding); } } AddBone(boneBinding.Name); } AddBone("gblctr"); UnbindPosition(GlobalTransformation); AddBone("kg_ya_ex"); UnbindRotation(GlobalTransformation); Parent.KeySets.Add(new KeySet()); void UnbindPosition(BoneBinding boneBinding) { Parent.KeySets.Add(boneBinding.Position?.X ?? new KeySet()); Parent.KeySets.Add(boneBinding.Position?.Y ?? new KeySet()); Parent.KeySets.Add(boneBinding.Position?.Z ?? new KeySet()); } void UnbindRotation(BoneBinding boneBinding) { Parent.KeySets.Add(boneBinding.Rotation?.X ?? new KeySet()); Parent.KeySets.Add(boneBinding.Rotation?.Y ?? new KeySet()); Parent.KeySets.Add(boneBinding.Rotation?.Z ?? new KeySet()); } void AddBone(string name) { Parent.BoneInfos.Add(new BoneInfo { Name = name, Id = ( uint? )motionDatabase?.BoneNames?.FindIndex( x => x.Equals(name, StringComparison.OrdinalIgnoreCase)) ?? MurmurHash.Calculate(name) }); } }
protected override void Initialize() { AddImportHandler <Texture>(filePath => { var texture = TextureEncoder.EncodeFromFile(filePath, TextureFormat.Unknown, Parent.FindParent <SpriteSetNode>() == null); { texture.Name = Path.GetFileNameWithoutExtension(filePath); texture.Id = MurmurHash.Calculate(texture.Name); } Data.Textures.Add(texture); }); AddExportHandler <TextureSet>(filePath => Data.Save(filePath)); AddReplaceHandler <TextureSet>(BinaryFile.Load <TextureSet>); AddCustomHandler("Export All", () => { string filePath = ModuleExportUtilities.SelectModuleExport <Texture>( "Select a folder to export textures to.", "Enter into a directory and press Save"); if (string.IsNullOrEmpty(filePath)) { return; } string directoryPath = Path.GetDirectoryName(filePath); string extension = Path.GetExtension(filePath).Trim('.'); foreach (var texture in Data.Textures) { TextureDecoder.DecodeToFile(texture, Path.Combine(directoryPath, $"{texture.Name}.{extension}")); } }, Keys.Control | Keys.Shift | Keys.E); AddCustomHandler("Export All (Flipped)", () => { string filePath = ModuleExportUtilities.SelectModuleExport <Bitmap>( "Select a folder to export textures to.", "Enter into a directory and press Save"); if (string.IsNullOrEmpty(filePath)) { return; } string directoryPath = Path.GetDirectoryName(filePath); string extension = Path.GetExtension(filePath).Trim('.'); foreach (var texture in Data.Textures) { using (var bitmap = TextureDecoder.DecodeToBitmap(texture)) { bitmap.RotateFlip(RotateFlipType.Rotate180FlipX); bitmap.Save(Path.Combine(directoryPath, $"{texture.Name}.{extension}")); } } }); AddCustomHandlerSeparator(); AddDirtyCustomHandler("Replace All", () => { var fileNames = ModuleImportUtilities.SelectModuleImportMultiselect <Texture>(); if (fileNames == null) { return(false); } bool any = false; foreach (string fileName in fileNames) { string textureName = Path.GetFileNameWithoutExtension(fileName); int textureIndex = Data.Textures.FindIndex(x => x.Name.Equals(textureName, StringComparison.OrdinalIgnoreCase)); if (textureIndex == -1) { continue; } any = true; var texture = Data.Textures[textureIndex]; var newTexture = TextureEncoder.EncodeFromFile(fileName, texture.IsYCbCr ? TextureFormat.RGBA8 : texture.Format, texture.MipMapCount != 1); newTexture.Name = texture.Name; newTexture.Id = texture.Id; Data.Textures[textureIndex] = newTexture; } return(any); }, Keys.Control | Keys.Shift | Keys.R, CustomHandlerFlags.Repopulate | CustomHandlerFlags.ClearMementos); AddDirtyCustomHandler("Replace All (Flipped)", () => { var fileNames = ModuleImportUtilities.SelectModuleImportMultiselect <Bitmap>(); if (fileNames == null) { return(false); } bool any = false; foreach (string fileName in fileNames) { // Boy do I love duplicate code C: string textureName = Path.GetFileNameWithoutExtension(fileName); int textureIndex = Data.Textures.FindIndex(x => x.Name.Equals(textureName, StringComparison.OrdinalIgnoreCase)); if (textureIndex == -1) { continue; } any = true; var texture = Data.Textures[textureIndex]; Texture newTexture; using (var bitmap = new Bitmap(fileName)) { bitmap.RotateFlip(RotateFlipType.Rotate180FlipX); newTexture = TextureEncoder.EncodeFromBitmap(bitmap, texture.IsYCbCr ? TextureFormat.RGBA8 : texture.Format, texture.MipMapCount != 1); } newTexture.Name = texture.Name; newTexture.Id = texture.Id; Data.Textures[textureIndex] = newTexture; } return(any); }, Keys.None, CustomHandlerFlags.Repopulate | CustomHandlerFlags.ClearMementos); base.Initialize(); }