public static void Main(string[] args) { string file = File.ReadAllText(args[0]); SpriteMap map = null; FlashFile v = null; if (file.StartsWith("{\"ATLAS")) { map = JsonConvert.DeserializeObject <SpriteMap>(file); } else { v = JsonConvert.DeserializeObject <FlashFile>(file); } Console.WriteLine("Converting gaming"); string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; xml += "\n<TextureAtlas imagePath=\"" + (v == null ? map.Meta.Image : v.Meta.Image) + "\">"; xml += "\n<!-- Created with Kades Custom Converter -->"; if (map == null) { foreach (KeyValuePair <string, FrameValue> fv in v.Frames) { xml += $"\n<SubTexture name=\"{fv.Key}\" x=\"{fv.Value.Frame.X}\" y=\"{fv.Value.Frame.Y}\" width=\"{fv.Value.Frame.W}\" height=\"{fv.Value.Frame.H}\" frameX=\"-{fv.Value.SpriteSourceSize.X}\" frameY=\"-{fv.Value.SpriteSourceSize.Y}\" frameWidth=\"{fv.Value.SpriteSourceSize.W}\" frameHeight=\"{fv.Value.SpriteSourceSize.H}\"/>"; } } else { foreach (SpriteElement fv in map.Atlas.Sprites) { xml += $"\n<SubTexture name=\"{fv.Sprite.Name}\" x=\"{fv.Sprite.X}\" y=\"{fv.Sprite.Y}\" width=\"{fv.Sprite.W}\" height=\"{fv.Sprite.H}\" frameX=\"-{fv.Sprite.X}\" frameY=\"-{fv.Sprite.Y}\" frameWidth=\"{fv.Sprite.W}\" frameHeight=\"{fv.Sprite.H}\"/>"; } } xml += "\n</TextureAtlas>"; File.WriteAllText((map == null ? v.Meta.Image.Split('.')[0] : map.Meta.Image.Split(('.'))[0]) + ".xml", xml); }
private static void Main(string[] args) { var flash = new FlashFile(TargetSwf); // Disassemble. flash.Disassemble(); // Iterate through all abc tags. foreach (var abc in flash.AbcFiles) { // Iterate through all classes. foreach (var clazz in abc.Classes) { // We don't care about these ok. if (clazz.QName.Namespace.Name.StartsWith("FilePrivateNS")) { continue; } // Find a private trait. var trait = clazz.Traits .Concat(clazz.Instance.Traits) .FirstOrDefault(x => x.QName.Namespace.Kind == NamespaceKind.Private); if (trait == null) { continue; } // Parse original names. var names = trait.QName.Namespace.Name.Split(new [] { ':' }, 2, StringSplitOptions.None); var privNamespace = names.Length == 2 ? names[0] : string.Empty; var privClass = names.Length == 2 ? names[1] : names[0]; var oldNamespace = clazz.QName.Namespace.Name; var oldClass = clazz.QName.Name; var wasModified = false; // Fix namespace. if (!privNamespace.Equals(oldNamespace)) { clazz.QName.Namespace.NameIndex = abc.Pool.AddConstant(privNamespace); wasModified = true; } // Fix class name. if (!privClass.Equals(oldClass)) { clazz.QName.NameIndex = abc.Pool.AddConstant(privClass); wasModified = true; } if (!wasModified) { continue; } // Apply fix. Console.WriteLine($"Patch {oldNamespace,-6} {oldClass, -6} => {privNamespace} {privClass}"); } } // Reassemble. var destination = TargetSwf.Replace(".swf", ".deob.swf"); using (var fileStream = File.Open(destination, FileMode.Create)) using (var fileWriter = new FlashWriter(fileStream)) { flash.Assemble(fileWriter, CompressionKind.ZLIB); } }