Exemplo n.º 1
0
        public void Compile(List <string> f)
        {
            matEntries.Clear();
            visEntries.Clear();
            Nodes.Clear();
            unknown    = Convert.ToUInt32(f[1].Split(',')[1]);
            frameCount = Convert.ToUInt32(f[2].Split(',')[1]);
            startFrame = 0;
            endFrame   = frameCount - 1;
            frameRate  = Convert.ToUInt32(f[3].Split(',')[1]);
            int l = 3;

            try
            {
                while (l < f.Count)
                {
                    if (f[l++].StartsWith("---"))
                    {
                        if (l >= f.Count)
                        {
                            break;
                        }
                        if (f[l].StartsWith("Material"))
                        {
                            l++;
                            MatEntry m = new MatEntry();
                            m.name = f[l];
                            l++;
                            m.matHash = Convert.ToInt32(f[l].Split(',')[1], 16);
                            l++;
                            m.hasPat = Convert.ToBoolean(f[l].Split(',')[1]);
                            l++;
                            if (!f[l].StartsWith("###"))
                            {
                                m.matHash2 = Convert.ToInt32(f[l].Split(',')[1], 16);
                                l++;
                            }
                            while (l < f.Count - 1 && (f[l].StartsWith("###") || string.IsNullOrWhiteSpace(f[l])))
                            {
                                if (f[++l].StartsWith("Material Property"))
                                {
                                    l++;
                                    MatData md = new MatData();
                                    md.name     = f[l++];
                                    md.unknown  = Convert.ToInt32(f[l++].Split(',')[1]);
                                    md.unknown2 = Convert.ToInt32(f[l++].Split(',')[1]);
                                    md.animType = Convert.ToUInt16(f[l++].Split(',')[1]);
                                    bool                 keyed        = (f[l++].Split(',')[1].Equals("Keyed") || f[l].Split(',')[1].Equals("keyed"));
                                    int                  lastFrame    = 0;
                                    MatData.frame        lastKeyframe = null;
                                    List <MatData.frame> frames       = new List <MatData.frame>();
                                    while (l < f.Count && !f[l].StartsWith("---") && !f[l].StartsWith("###"))
                                    {
                                        if (keyed)
                                        {
                                            int           currentFrame = frames.Count, fnum = Convert.ToInt32(f[l].Split(',')[0]);
                                            MatData.frame tempFrame = new MatData.frame();
                                            tempFrame.values = new float[f[l].Split(',').Length - 1];
                                            int i = 0;
                                            foreach (string value in (new List <string>(f[l].Split(',')).GetRange(1, f[l].Split(',').Length - 1)))
                                            {
                                                tempFrame.values[i++] = Convert.ToSingle(value);
                                            }
                                            if (lastKeyframe == null)
                                            {
                                                while (currentFrame <= fnum)
                                                {
                                                    frames.Add(tempFrame);
                                                    currentFrame = frames.Count;
                                                }
                                            }
                                            else
                                            {
                                                while (currentFrame <= fnum)
                                                {
                                                    List <float> thisFrame = new List <float>();
                                                    for (int k = 0; k < lastKeyframe.values.Length; k++)
                                                    {
                                                        float slope = (tempFrame.values[k] - lastKeyframe.values[k]) / (float)(fnum - lastFrame);
                                                        thisFrame.Add(lastKeyframe.values[k] + (slope * (currentFrame - lastFrame)));
                                                    }
                                                    frames.Add(new MatData.frame()
                                                    {
                                                        values = thisFrame.ToArray()
                                                    });
                                                    currentFrame = frames.Count;
                                                }
                                            }
                                            lastFrame    = fnum;
                                            lastKeyframe = tempFrame;
                                        }
                                        else
                                        {
                                            float[] values = new float[f[l].Split(',').Length];
                                            int     i      = 0;
                                            foreach (string value in f[l].Split(','))
                                            {
                                                values[i++] = Convert.ToSingle(value);
                                            }

                                            frames.Add(new MatData.frame()
                                            {
                                                values = values
                                            });
                                        }
                                        l++;
                                    }
                                    md.frames = frames;
                                    if (md.frames.Count > 0)
                                    {
                                        md.valueCount = md.frames[0].values.Length;
                                    }
                                    m.properties.Add(md);
                                }
                                else if (f[l + 1].StartsWith("PAT0"))
                                {
                                    l += 2;
                                    PatData p = new PatData();
                                    p.defaultTexId = Convert.ToInt32(f[l++].Split(',')[1]);
                                    int keyFrameCount = Convert.ToInt32(f[l++].Split(',')[1]);
                                    p.unknown = Convert.ToInt32(f[l++].Split(',')[1]);
                                    for (int i = 0; i < keyFrameCount; i++)
                                    {
                                        p.keyframes.Add(new PatData.keyframe()
                                        {
                                            frameNum = Convert.ToInt32(f[l].Split(',')[1]), texId = Convert.ToInt32(f[l++].Split(',')[3], 16)
                                        });
                                    }
                                    m.pat0 = p;
                                }
                            }
                            //while (l < f.Count && !f[l].StartsWith("---"))
                            //    l++;

                            matEntries.Add(m);
                        }
                        else if (f[l].StartsWith("VIS0"))
                        {
                            l++;
                            VisEntry v = new VisEntry();
                            v.name       = f[l++];
                            v.frameCount = Convert.ToInt32(f[l++].Split(',')[1]);
                            int keyframeCount = Convert.ToInt32(f[l++].Split(',')[1]);
                            v.unk1 = Convert.ToBoolean(f[l++].Split(',')[1]);
                            v.unk2 = Convert.ToBoolean(f[l++].Split(',')[1]);
                            for (int i = 0; i < keyframeCount; i++)
                            {
                                v.frames.Add(new VisEntry.frame()
                                {
                                    frameNum = Convert.ToInt16(f[l].Split(',')[1]), state = Convert.ToByte(f[l].Split(',')[3]), unknown = Convert.ToByte(f[l++].Split(',')[1])
                                });
                            }
                            visEntries.Add(v);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                MessageBox.Show($"Failed to build MTA\nError on line {l}\n{ex.ToString()}", "MTA Build Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //throw;
            }
        }
Exemplo n.º 2
0
 public StandardKeyframe(int frame, MatData.frame data, string type)
 {
     this.frame = frame;
     this.data  = data;
     this.type  = type;
 }