Example #1
0
        public static ShadowSpline FromFile(string FileName)
        {
            string[]     SplineFile          = File.ReadAllLines(FileName);
            ShadowSpline Temp                = new ShadowSpline();
            List <ShadowSplineVertex> Points = new List <ShadowSplineVertex>();

            foreach (string j in SplineFile)
            {
                if (j.StartsWith("v"))
                {
                    string[] a = Regex.Replace(j, @"\s+", " ").Split();
                    Points.Add(new ShadowSplineVertex()
                    {
                        Position = new Vector3(Convert.ToSingle(a[1]), Convert.ToSingle(a[2]), Convert.ToSingle(a[3]))
                    });
                }
            }

            Temp.Vertices = Points.ToArray();
            Temp.SetRenderStuff(Program.MainForm.renderer);
            return(Temp);
        }
Example #2
0
        private static List <ShadowSpline> ReadShadowSplineFile(string fileName)
        {
            if (File.Exists(fileName))
            {
                byte[]       fileContents = File.ReadAllBytes(fileName);
                Archive      shadowDATONE = Archive.FromONEFile(ref fileContents);
                BinaryReader splineReader = null;

                foreach (var file in shadowDATONE.Files)
                {
                    if (file.Name == "PATH.PTP")
                    {
                        splineReader = new BinaryReader(new MemoryStream(file.DecompressThis()));
                        break;
                    }
                }

                if (splineReader == null)
                {
                    return(new List <ShadowSpline>());
                }

                try
                {
                    if (littleEndian)
                    {
                        DontSwitch = true;
                    }

                    List <ShadowSpline> splineList = new List <ShadowSpline>();

                    splineReader.BaseStream.Position = 0x4;
                    int sec5offset = Switch(splineReader.ReadInt32());
                    int sec5length = Switch(splineReader.ReadInt32());

                    splineReader.BaseStream.Position = 0x20;
                    List <int> offsetList = new List <int>();

                    int a = Switch(splineReader.ReadInt32());

                    while (a != 0)
                    {
                        offsetList.Add(a + 0x20);
                        a = Switch(splineReader.ReadInt32());
                    }

                    foreach (int i in offsetList)
                    {
                        splineReader.BaseStream.Position = i;

                        ShadowSpline spline         = new ShadowSpline();
                        int          amountOfPoints = Switch(splineReader.ReadInt32());

                        splineReader.BaseStream.Position += 8;

                        spline.Setting1 = splineReader.ReadByte();
                        spline.Setting2 = splineReader.ReadByte();
                        spline.Setting3 = splineReader.ReadByte();
                        spline.Setting4 = splineReader.ReadByte();

                        splineReader.BaseStream.Position += 0xC;

                        spline.SettingInt = Switch(splineReader.ReadInt32());

                        splineReader.BaseStream.Position += 0xC;

                        int nameOffset = Switch(splineReader.ReadInt32());

                        spline.Vertices = new ShadowSplineVertex[amountOfPoints];

                        for (int j = 0; j < amountOfPoints; j++)
                        {
                            ShadowSplineVertex vertex = new ShadowSplineVertex
                            {
                                Position = new Vector3(Switch(splineReader.ReadSingle()), Switch(splineReader.ReadSingle()), Switch(splineReader.ReadSingle())),
                                Rotation = new Vector3(Switch(splineReader.ReadSingle()), Switch(splineReader.ReadSingle()), Switch(splineReader.ReadSingle()))
                            };
                            splineReader.BaseStream.Position += 0x4;
                            vertex.Unknown = Switch(splineReader.ReadInt32());

                            spline.Vertices[j] = vertex;
                        }

                        splineReader.BaseStream.Position = nameOffset + 0x20;
                        spline.Name = ReadString(splineReader);

                        splineList.Add(spline);
                    }

                    splineReader.BaseStream.Position = sec5offset + 0x20 + splineList.Count;

                    for (int i = 0; i < splineList.Count; i++)
                    {
                        byte byte0 = splineReader.ReadByte();

                        if (byte0 >= 0x80)
                        {
                            byte byte1 = splineReader.ReadByte();
                            splineList[i].UnknownSec5Bytes = new byte[] { byte0, byte1 };
                        }
                        else
                        {
                            splineList[i].UnknownSec5Bytes = new byte[] { byte0 }
                        };

                        splineReader.ReadByte();
                    }

                    splineReader.Close();

                    DontSwitch = false;
                    return(splineList);
                }
                catch
                {
                    littleEndian = true;
                    return(ReadShadowSplineFile(fileName));
                }
            }

            return(new List <ShadowSpline>());
        }
Example #3
0
 public void Add(string objFile)
 {
     Splines.Add(ShadowSpline.FromFile(objFile));
     Splines.Last().SetRenderStuff(Program.MainForm.renderer);
 }