Example #1
0
 static void WriteNodeV2(LUtfNode node, BinaryWriter writer, Dictionary <string, int> strOff,
                         Dictionary <LUtfNode, int> datOff, ref int myIdx, bool last)
 {
     writer.Write(strOff[node.Name]); //nameOffset
     if (node.Data != null)
     {
         myIdx++;
         if (!last)
         {
             writer.Write(myIdx);
         }
         else
         {
             writer.Write((uint)0);
         }
         if (node.CompressedData != null)
         {
             writer.Write((byte)10);  //Type 10: compressed deflate
             writer.Write(datOff[node]);
             writer.Write(node.CompressedData.Length);
         }
         else if (node.Data.Length > 8)
         {
             writer.Write((byte)1);  //Type 1: Data Offset + Size
             writer.Write(datOff[node]);
             writer.Write(node.Data.Length);
         }
         else
         {
             writer.Write((byte)(node.Data.Length + 1)); //Type 2-9: Embedded Data
             writer.Write(node.Data);
             for (int i = node.Data.Length; i < 8; i++)
             {
                 writer.Write((byte)0);  //padding
             }
         }
     }
     else
     {
         long indexPos = writer.BaseStream.Position;
         writer.Write((uint)0);  //sibling index
         writer.Write((byte)0);  //folder
         myIdx++;
         writer.Write(myIdx);
         writer.Write((uint)0);  //padding
         for (int i = 0; i < node.Children.Count; i++)
         {
             WriteNodeV2(node.Children[i], writer, strOff, datOff, ref myIdx, i == (node.Children.Count - 1));
         }
         if (!last)
         {
             //write sibling index
             var mPos = writer.BaseStream.Position;
             writer.BaseStream.Seek(indexPos, SeekOrigin.Begin);
             writer.Write(myIdx);
             writer.BaseStream.Seek(mPos, SeekOrigin.Begin);
         }
     }
 }
Example #2
0
        void WriteNode(LUtfNode node, BinaryWriter writer, Dictionary <string, int> strOff, Dictionary <LUtfNode, int> datOff, bool last)
        {
            if (node.Data != null)
            {
                if (last)
                {
                    writer.Write((int)0);                     //no siblings
                }
                else
                {
                    writer.Write((int)(writer.BaseStream.Position + sizeof(int) * 11)); //peerOffset
                }
                writer.Write(strOff[node.Name]);                                        //nameOffset
                writer.Write((int)LL.NodeFlags.Leaf);                                   //leafNode
                writer.Write((int)0);                                                   //padding
                writer.Write(datOff[node]);                                             //dataOffset
                int dataAlloc = node.Data.Length + 3 & ~3;
                writer.Write(dataAlloc);                                                //allocatedSize (?)
                writer.Write(node.Data.Length);                                         //usedSize
                writer.Write(node.Data.Length);                                         //uncompressedSize

                writer.Write(-2037297339);
                writer.Write(-2037297339);
                writer.Write(-2037297339);
                return;
            }

            long startPos = writer.BaseStream.Position;

            writer.Write((int)0);                                 //peerOffset
            writer.Write(strOff[node.Name]);
            writer.Write((int)LL.NodeFlags.Intermediate);         //intermediateNode
            writer.Write((int)0);                                 //padding
            writer.Write((int)(writer.BaseStream.Position + 28)); //children start immediately after node
            writer.Write((int)0);                                 //allocatedSize
            writer.Write((int)0);                                 //usedSize
            writer.Write((int)0);                                 //uncompressedSize
            writer.Write(-2037297339);
            writer.Write(-2037297339);
            writer.Write(-2037297339);
            //There should be 3 more DWORDS here but we can safely not write them for FL
            for (int i = 0; i < node.Children.Count; i++)
            {
                WriteNode(node.Children[i], writer, strOff, datOff, i == (node.Children.Count - 1));
            }
            if (!last)             //if there's siblings
            {
                var endPos = writer.BaseStream.Position;
                writer.BaseStream.Seek(startPos, SeekOrigin.Begin);
                writer.Write((int)endPos);
                writer.BaseStream.Seek(endPos, SeekOrigin.Begin);
            }
        }
Example #3
0
        public static EditableUtf UncompressedFromFile(IconType type, string iconName, string filename, bool alpha)
        {
            var texNode = new LUtfNode()
            {
                Children = new List <LUtfNode>()
            };

            texNode.Children.Add(new LUtfNode()
            {
                Name = "MIP0", Data = TextureImport.TGANoMipmap(filename, true)
            });
            return(Generate(type, iconName, texNode, alpha));
        }
Example #4
0
        static LL.Node ExportNode(LUtfNode n)
        {
            if (n.Data != null)
            {
                return(new LL.LeafNode(n.Name, n.Data));
            }
            var children = new List <LL.Node>();

            foreach (var child in n.Children)
            {
                children.Add(ExportNode(child));
            }
            return(new LL.IntermediateNode(n.Name, children));
        }
Example #5
0
        public static EditableUtf CompressedFromFile(IconType type, string iconName, string filename, bool alpha)
        {
            var ddsNode = new LUtfNode()
            {
                Children = new List <LUtfNode>()
            };

            ddsNode.Children.Add(new LUtfNode()
            {
                Name = "MIPS",
                Data = TextureImport.CreateDDS(filename, alpha ? DDSFormat.DXT5 : DDSFormat.DXT1, MipmapMethod.None, true, true)
            });
            return(Generate(type, iconName, ddsNode, alpha));
        }
Example #6
0
        string GetUtfPath(LUtfNode n)
        {
            List <string> strings = new List <string>();
            LUtfNode      node    = n;

            while (node.Name != "/" && node.Name != "\\")
            {
                strings.Add(node.Name);
                node = node.Parent;
            }
            strings.Reverse();
            var path = "/" + string.Join("/", strings);

            return(path);
        }
Example #7
0
        public static List <LUtfNode> TGAMipmaps(string input, MipmapMethod mipm, bool flip)
        {
            var raw   = ReadFile(input, flip);
            var mips  = Crunch.GenerateMipmaps(raw.Data, raw.Width, raw.Height, (CrnglueMipmaps)mipm);
            var nodes = new List <LUtfNode>(mips.Count);

            for (int i = 0; i < mips.Count; i++)
            {
                var n = new LUtfNode {
                    Name = "MIP" + i, Data = TargaRGBA(mips[i].Bytes, mips[i].Width, mips[i].Height)
                };
                nodes.Add(n);
            }
            return(nodes);
        }
Example #8
0
        public LUtfNode MakeCopy()
        {
            var copy = new LUtfNode();

            copy.Name = Name;
            copy.Data = Data;
            if (Children != null)
            {
                copy.Children = new List <LUtfNode>(Children.Count);
                foreach (var child in Children)
                {
                    var newch = child.MakeCopy();
                    newch.Parent = copy;
                    copy.Children.Add(newch);
                }
            }
            return(copy);
        }
Example #9
0
        LUtfNode ConvertNode(LL.Node node, LUtfNode parent)
        {
            var n = new LUtfNode();

            n.Name   = node.Name;
            n.Parent = parent;
            if (node is LL.IntermediateNode)
            {
                var im = (LL.IntermediateNode)node;
                n.Children = new List <LUtfNode>();
                foreach (var child in im)
                {
                    n.Children.Add(ConvertNode(child, n));
                }
            }
            else
            {
                var lf = (LL.LeafNode)node;
                n.Data = lf.ByteArrayData;
            }
            return(n);
        }
Example #10
0
 public static LL.IntermediateNode NodeToEngine(LUtfNode node)
 {
     return(ExportNode(node) as LL.IntermediateNode);
 }
Example #11
0
 public EditableUtf()
 {
     Root          = new LUtfNode();
     Root.Name     = "/";
     Root.Children = new List <LUtfNode>();
 }
Example #12
0
        public static EditableUtf Generate(IconType type, string iconName, LUtfNode textureNode, bool alpha)
        {
            var    modelFile    = new EditableUtf();
            var    unique       = IdSalt.New();
            string textureName  = $"data.icon.{iconName}.{unique}.tga";
            string materialName = $"data.icon.{iconName}.{unique}";
            string meshName     = $"data.icon.{iconName}.lod0-{unique}.vms";
            //VMeshLibrary
            var geom = new Geometry();

            geom.Vertices = type == IconType.Commodity ? vertices_commodity : vertices_ship;
            geom.Indices  = new Indices()
            {
                Indices16 = (type == IconType.Commodity ? indices_commodity : indices_ship)
            };
            geom.Attributes = VertexAttributes.Position | VertexAttributes.Normal | VertexAttributes.Texture1;
            geom.Groups     = new TriangleGroup[]
            {
                new TriangleGroup()
                {
                    BaseVertex = 0, StartIndex = 0, Material = new SimpleMesh.Material()
                    {
                        Name = materialName
                    }, IndexCount = 6
                }
            };
            geom.CalculateBounds();
            var vmsLib = new LUtfNode()
            {
                Name = "VMeshLibrary", Parent = modelFile.Root, Children = new List <LUtfNode>()
            };

            modelFile.Root.Children.Add(vmsLib);
            var vmsName = new LUtfNode()
            {
                Name = meshName, Parent = vmsLib, Children = new List <LUtfNode>()
            };

            vmsLib.Children.Add(vmsName);
            vmsName.Children.Add(new LUtfNode()
            {
                Name   = "VMeshData",
                Parent = vmsName,
                Data   = GeometryWriter.VMeshData(geom)
            });
            //VMeshPart
            var vmeshPart = new LUtfNode()
            {
                Name = "VMeshPart", Parent = modelFile.Root, Children = new List <LUtfNode>()
            };

            modelFile.Root.Children.Add(vmeshPart);
            vmeshPart.Children.Add(new LUtfNode()
            {
                Name = "VMeshRef", Parent = vmeshPart, Data = GeometryWriter.VMeshRef(geom, meshName)
            });

            //Texture
            var textureLibrary = new LUtfNode()
            {
                Name   = "Texture Library",
                Parent = modelFile.Root
            };

            textureLibrary.Children = new List <LUtfNode>();
            var clonedTex = textureNode.MakeCopy();

            clonedTex.Parent = textureLibrary;
            clonedTex.Name   = textureName;
            textureLibrary.Children.Add(clonedTex);
            modelFile.Root.Children.Add(textureLibrary);
            //Material
            var materialLibrary = new LUtfNode()
            {
                Name   = "Material Library",
                Parent = modelFile.Root
            };

            materialLibrary.Children = new List <LUtfNode>();
            var material = new LUtfNode()
            {
                Name   = materialName,
                Parent = materialLibrary
            };

            material.Children = new List <LUtfNode>();
            material.Children.Add(new LUtfNode()
            {
                Name   = "Type",
                Parent = material,
                Data   = Encoding.ASCII.GetBytes(alpha ? "DcDtOcOt" : "DcDt")
            });
            material.Children.Add(new LUtfNode()
            {
                Name   = "Dt_name",
                Parent = material,
                Data   = Encoding.ASCII.GetBytes(textureName)
            });
            material.Children.Add(new LUtfNode()
            {
                Name   = "Dt_flags",
                Parent = material,
                Data   = BitConverter.GetBytes((int)SamplerFlags.Default)
            });
            materialLibrary.Children.Add(material);
            modelFile.Root.Children.Add(materialLibrary);

            return(modelFile);
        }
Example #13
0
        public static EditableUtf Generate(string iconName, LUtfNode textureNode, bool alpha)
        {
            var    modelFile    = new EditableUtf();
            var    unique       = IdSalt.New();
            string textureName  = $"data.icon.{iconName}.{unique}.tga";
            string materialName = $"data.icon.{iconName}.{unique}";
            string meshName     = $"data.icon.{iconName}.lod0-{unique}.vms";
            //VMeshLibrary
            var geom = new ColladaGeometry();

            geom.Vertices  = vertices;
            geom.Indices   = indices;
            geom.FVF       = D3DFVF.NORMAL | D3DFVF.XYZ | D3DFVF.TEX1;
            geom.Drawcalls = new[]
            {
                new ColladaDrawcall()
                {
                    StartVertex = 0, EndVertex = 3, Material = new ColladaMaterial()
                    {
                        Name = materialName
                    }, StartIndex = 0, TriCount = 2
                }
            };
            geom.CalculateDimensions();
            var vmsLib = new LUtfNode()
            {
                Name = "VMeshLibrary", Parent = modelFile.Root, Children = new List <LUtfNode>()
            };

            modelFile.Root.Children.Add(vmsLib);
            var vmsName = new LUtfNode()
            {
                Name = meshName, Parent = vmsLib, Children = new List <LUtfNode>()
            };

            vmsLib.Children.Add(vmsName);
            vmsName.Children.Add(new LUtfNode()
            {
                Name   = "VMeshData",
                Parent = vmsName,
                Data   = geom.VMeshData()
            });
            //VMeshPart
            var vmeshPart = new LUtfNode()
            {
                Name = "VMeshPart", Parent = modelFile.Root, Children = new List <LUtfNode>()
            };

            modelFile.Root.Children.Add(vmeshPart);
            vmeshPart.Children.Add(new LUtfNode()
            {
                Name = "VMeshRef", Parent = vmeshPart, Data = geom.VMeshRef(meshName)
            });

            //Texture
            var textureLibrary = new LUtfNode()
            {
                Name   = "Texture Library",
                Parent = modelFile.Root
            };

            textureLibrary.Children = new List <LUtfNode>();
            var clonedTex = textureNode.MakeCopy();

            clonedTex.Parent = textureLibrary;
            clonedTex.Name   = textureName;
            textureLibrary.Children.Add(clonedTex);
            modelFile.Root.Children.Add(textureLibrary);
            //Material
            var materialLibrary = new LUtfNode()
            {
                Name   = "Material Library",
                Parent = modelFile.Root
            };

            materialLibrary.Children = new List <LUtfNode>();
            var material = new LUtfNode()
            {
                Name   = materialName,
                Parent = materialLibrary
            };

            material.Children = new List <LUtfNode>();
            material.Children.Add(new LUtfNode()
            {
                Name   = "Type",
                Parent = material,
                Data   = Encoding.ASCII.GetBytes(alpha ? "DcDtOcOt" : "DcDt")
            });
            material.Children.Add(new LUtfNode()
            {
                Name   = "Dt_name",
                Parent = material,
                Data   = Encoding.ASCII.GetBytes(textureName)
            });
            material.Children.Add(new LUtfNode()
            {
                Name   = "Dt_flags",
                Parent = material,
                Data   = BitConverter.GetBytes((int)SamplerFlags.Default)
            });
            materialLibrary.Children.Add(material);
            modelFile.Root.Children.Add(materialLibrary);

            return(modelFile);
        }