Ejemplo n.º 1
0
        public static MagickImage parseImgFile(CrpReader reader, uint fileSize)
        {
            MagickImage retVal = new MagickImage(reader.ReadBytes((int)fileSize));

            retVal.Format = MagickFormat.Png;
            return(retVal);
        }
Ejemplo n.º 2
0
        public static Dictionary <string, dynamic> parseGameObj(CrpReader reader, bool saveFile, string saveFileName, long fileSize, bool verbose)
        {
            Dictionary <string, dynamic> retVal = new Dictionary <string, dynamic>();

            long fileContentBegin = reader.BaseStream.Position;

            retVal["tag"]     = reader.ReadString();
            retVal["layer"]   = reader.ReadInt32();
            retVal["enabled"] = reader.ReadBoolean();

            int numProperties = reader.ReadInt32();

            for (int i = 0; i < numProperties; i++)
            {
                bool isNull = reader.ReadBoolean();
                if (!isNull)
                {
                    string assemblyQualifiedName = reader.ReadString();
                    string propertyType          = assemblyQualifiedName.Split(new char[] { ',' })[0];
                    string propertyName          = i + "_" + propertyType;

                    if (propertyType.Contains("[]"))
                    {
                        retVal[propertyName] = reader.readUnityArray(propertyType);
                    }
                    else
                    {
                        retVal[propertyName] = reader.readUnityObj(propertyType);
                    }
                }
            }

            if ((reader.BaseStream.Position - fileContentBegin) != fileSize)
            {
                int bytesToRead = (int)(fileSize - (reader.BaseStream.Position - fileContentBegin));
                reader.ReadBytes(bytesToRead);
            }
            string json = JsonConvert.SerializeObject(retVal, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter());

            if (verbose)
            {
                Console.WriteLine(json);
            }

            if (saveFile)
            {
                StreamWriter file = new StreamWriter(new FileStream(saveFileName + ".json", FileMode.Create));
                file.Write(json);
                file.Close();
            }

            return(retVal);
        }
Ejemplo n.º 3
0
        public static Dictionary<string, dynamic> parseInfoGen(CrpReader reader, bool saveFile, string saveFileName, long fileSize, bool verbose)
        {
            Dictionary<string, dynamic> retVal = new Dictionary<string, dynamic>();

            long fileContentBegin = reader.BaseStream.Position;

            int numProperties = reader.ReadInt32();
            for (int i = 0; i < numProperties; i++)
            {
                bool isNull = reader.ReadBoolean();
                if (!isNull)
                {
                    string assemblyQualifiedName = reader.ReadString();
                    string propertyType = assemblyQualifiedName.Split(new char[] { ',' })[0];
                    string propertyName = reader.ReadString();
                    if (propertyType.Contains("[]"))
                    {
                        retVal[propertyName] = reader.readUnityArray(propertyType);
                    }
                    else
                    {
                        retVal[propertyName] = reader.readUnityObj(propertyType);
                    }

                }
            }

            if ((reader.BaseStream.Position - fileContentBegin) != fileSize)
            {
                int bytesToRead = (int)(fileSize - (reader.BaseStream.Position - fileContentBegin));
                reader.ReadBytes(bytesToRead);
            }
            string json = JsonConvert.SerializeObject(retVal, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter());
            string fileName = saveFileName + ".json";
            if (verbose)
            {
                Console.WriteLine("Read info file {0}", fileName);
                Console.WriteLine(json);
            }
            if (saveFile)
            {
                StreamWriter file = new StreamWriter(new FileStream(fileName, FileMode.Create));
                file.Write(json);
                file.Close();
            }

            return retVal;
        }
Ejemplo n.º 4
0
        public static Mesh parseMesh(CrpReader reader, bool saveFile, string saveFileName, long fileSize, bool verbose)
        {
            long fileContentBegin = reader.BaseStream.Position;

            Mesh retVal = new Mesh();

            retVal.vertices     = reader.readUnityArray("UnityEngine.Vector3");
            retVal.colors       = reader.readUnityArray("UnityEngine.Color");
            retVal.uv           = reader.readUnityArray("UnityEngine.Vector2");
            retVal.normals      = reader.readUnityArray("UnityEngine.Vector3");
            retVal.tangents     = reader.readUnityArray("UnityEngine.Vector4");
            retVal.boneWeights  = reader.readUnityArray("UnityEngine.BoneWeight");
            retVal.bindPoses    = reader.readUnityArray("UnityEngine.Matrix4x4");
            retVal.subMeshCount = reader.ReadInt32();
            for (int i = 0; i < retVal.subMeshCount; i++)
            {
                int[] triangles = reader.readUnityArray("System.Int32");
                retVal.triangles.AddRange(triangles);
            }

            if ((reader.BaseStream.Position - fileContentBegin) != fileSize)
            {
                int bytesToRead = (int)(fileSize - (reader.BaseStream.Position - fileContentBegin));
                reader.ReadBytes(bytesToRead);
            }
            string fileName = saveFileName + ".obj";

            if (verbose)
            {
                Console.WriteLine("Read {0} bytes into image file {1}", (reader.BaseStream.Position - fileContentBegin), fileName);
            }
            if (saveFile)
            {
                StreamWriter file = new StreamWriter(new FileStream(fileName, FileMode.Create));
                file.Write(retVal.exportObj());
                file.Close();
            }
            return(retVal);
        }
Ejemplo n.º 5
0
        public static MaterialStub parseMaterial(CrpReader reader, bool saveFile, string saveFileName, long fileSize, bool verbose)
        {
            long         fileContentBegin = reader.BaseStream.Position;
            MaterialStub retVal           = new MaterialStub();

            retVal.shaderName    = reader.ReadString();
            retVal.numProperties = reader.ReadInt32();
            for (int i = 0; i < retVal.numProperties; i++)
            {
                int    propertyType = reader.ReadInt32();
                string propertyName = reader.ReadString();
                switch (propertyType)
                {
                case 0:
                    retVal.colors[propertyName] = reader.singlarObjParser["UnityEngine.Color"]();
                    break;

                case 1:
                    retVal.vectors[propertyName] = reader.singlarObjParser["UnityEngine.Vector4"]();
                    break;

                case 2:
                    retVal.floats[propertyName] = reader.ReadSingle();
                    break;

                case 3:
                    bool isNull = reader.ReadBoolean();
                    if (!isNull)
                    {
                        retVal.textures[propertyName] = reader.ReadString();
                    }
                    else
                    {
                        retVal.textures[propertyName] = "";
                    }
                    break;
                }
            }

            if ((reader.BaseStream.Position - fileContentBegin) != fileSize)
            {
                int bytesToRead = (int)(fileSize - (reader.BaseStream.Position - fileContentBegin));
                reader.ReadBytes(bytesToRead);
            }
            string fileName = saveFileName + ".json";
            string json     = JsonConvert.SerializeObject(retVal, Formatting.Indented);

            if (verbose)
            {
                Console.WriteLine("Read info file {0}", fileName);
                Console.WriteLine(json);
            }
            if (saveFile)
            {
                StreamWriter file = new StreamWriter(new FileStream(saveFileName + ".json", FileMode.Create));
                file.Write(json);
                file.Close();
            }

            return(retVal);
        }