Ejemplo n.º 1
0
        public static Event Deserialize(string s, MovesetNode node)
        {
            if (String.IsNullOrEmpty(s))
            {
                return(null);
            }

            try
            {
                string[] lines = s.Split('|');

                if (lines[0].Length != 8)
                {
                    return(null);
                }

                Event newEv = new Event();

                string id       = lines[0];
                uint   idNumber = Convert.ToUInt32(id, 16);

                newEv.EventID = idNumber;

                uint             _event = newEv.EventID;
                EventInformation info   = newEv.Info;

                for (int i = 0; i < newEv._numArgs; i++)
                {
                    string[] pLines = lines[i + 1].Split('\\');

                    int type = int.Parse(pLines[0]);

                    if (type == 2) //Offset
                    {
                        string[]         oLines = pLines[1].Split(',');
                        int              list = int.Parse(oLines[0]), type2 = int.Parse(oLines[1]), index = int.Parse(oLines[2]);
                        ScriptOffsetInfo w = new ScriptOffsetInfo((ListValue)list, (TypeValue)type2, index);
                        EventOffset      o = (EventOffset)newEv.NewParam(i, 0, ParamType.Offset);
                        o._script     = node.GetScript(w);
                        o._offsetInfo = w;
                    }
                    else
                    {
                        int value = int.Parse(pLines[1]);
                        newEv.NewParam(i, value, type);
                    }
                }

                return(newEv);
            }
            catch { return(null); }
        }
Ejemplo n.º 2
0
        public override void PostParse()
        {
            //Get script node using raw offset
            //This happens in post parse so that all scripts have been parsed already

            MovesetNode node = (MovesetNode)_root;

            SakuraiEntryNode e     = _root.GetEntry(RawOffset);
            bool             exist = e != null && e is Event;

            _offsetInfo = node.GetScriptLocation(RawOffset);

            Script a;

            if (_offsetInfo._list == ListValue.Null && !exist)
            {
                node.SubRoutines.Add(a = Parse <Script>(RawOffset));
            }
            else if (_offsetInfo._list != ListValue.References)
            {
                a = node.GetScript(_offsetInfo);
            }
            else
            {
                if (_externalEntry == null && _offsetInfo._index >= 0 && _offsetInfo._index < _root.ReferenceList.Count)
                {
                    _externalEntry = _root.ReferenceList[_offsetInfo._index];
                    _externalEntry.References.Add(this);
                }
                return;
            }

            if (a == null)
            {
                a = GetScript();
            }

            if (a != null)
            {
                a._actionRefs.Add(this);
            }
            else
            {
                throw new Exception("Script not found.");
            }

            _script = a;
        }
Ejemplo n.º 3
0
        internal void LinkScript()
        {
            MovesetNode node = (MovesetNode)_root;

            SakuraiEntryNode e     = _root.GetEntry(RawOffset);
            bool             exist = e != null && e is Event;

            _offsetInfo = node.GetScriptLocation(RawOffset);

            Script a;

            if (_offsetInfo.list == ListValue.Null && !exist)
            {
                node.SubRoutines.Add(a = Parse <Script>(RawOffset));
            }
            else if (_offsetInfo.list != ListValue.References)
            {
                a = node.GetScript(_offsetInfo);
            }
            else
            {
                if (_externalEntry == null && _offsetInfo.index >= 0 && _offsetInfo.index < _root.ReferenceList.Count)
                {
                    _externalEntry = _root.ReferenceList[_offsetInfo.index];
                    _externalEntry.References.Add(this);
                }
                return;
            }

            if (a == null)
            {
                a = GetScript();
            }

            if (a != null)
            {
                a._actionRefs.Add(this);
            }
            else
            {
                throw new Exception("Script not found.");
            }

            _script = a;
        }
Ejemplo n.º 4
0
        private unsafe void RenderOffensiveCollision(Vector3 cam)
        {
            MovesetNode node = Root;

            ResourceNode[] bl = _model._linker.BoneCache;

            int boneindex = (int)_parameters[0] >> 16;
            int size      = HitboxSize;
            int angle     = _parameters[2];

            node.GetBoneIndex(ref boneindex);

            if (boneindex == 0) //If a hitbox is on TopN, make it follow TransN
            {
                //Use assigned references
                if (node.Data != null)
                {
                    boneindex = node.Data._misc._boneRefs[4].boneIndex;
                    node.GetBoneIndex(ref boneindex);
                }
                else //Search manually
                {
                    int transindex = 0;
                    foreach (MDL0BoneNode bn in bl)
                    {
                        if (bn.Name.Equals("TransN"))
                        {
                            break;
                        }
                        transindex++;
                    }
                    if (transindex != bl.Length)
                    {
                        boneindex = transindex;
                    }
                }
            }

            MDL0BoneNode b;

            b = bl[boneindex] as MDL0BoneNode;

            Matrix     r         = b.Matrix.GetRotationMatrix();
            FrameState state     = b.Matrix.Derive();
            Vector3    bonePos   = state._translate;
            Vector3    globalPos = r.Multiply(new Vector3(Util.UnScalar(_parameters[6]), Util.UnScalar(_parameters[7]), Util.UnScalar(_parameters[8])) / state._scale);

            Matrix  m         = Matrix.TransformMatrix(new Vector3(1), state._rotate, globalPos + bonePos);
            Vector3 resultPos = m.GetPoint();

            int id = (int)_parameters[0] & 0xFFFF;

            RunTime.MainWindow.ModelPanel.CurrentViewport.ScreenText[id.ToString()] =
                RunTime.MainWindow.ModelPanel.CurrentViewport.Camera.Project(resultPos);

            m = Matrix.TransformMatrix(new Vector3(Util.UnScalar(size)), new Vector3(), resultPos);
            GL.PushMatrix();
            GL.MultMatrix((float *)&m);
            int    res       = 16;
            double drawAngle = 360.0 / res;

            Vector3 color = Util.GetTypeColor(flags.Type);

            GL.Color4((color._x / 255.0f), (color._y / 225.0f), (color._z / 255.0f), 0.5f);

            GLDisplayList spheres = TKContext.GetSphereList();

            spheres.Call();

            //Angle indicator
            double rangle = angle / 180.0 * Math.PI;

            //Apply color
            color = Util.GetEffectColor(flags.Effect);
            GL.Color4((color._x / 255.0f), (color._y / 225.0f), (color._z / 255.0f), 0.75f);

            GL.PushMatrix();
            if (angle == 361) //Sakurai angle
            {
                m = Matrix.TransformMatrix(new Vector3(0.5f), (globalPos + bonePos).LookatAngles(cam) * Maths._rad2degf, new Vector3(0));
                GL.MultMatrix((float *)&m);
                GL.Begin(BeginMode.Quads);
                for (int i = 0; i < 16; i += 2)
                {
                    GL.Vertex3(Math.Cos((i - 1) * Math.PI / 8) * 0.5, Math.Sin((i - 1) * Math.PI / 8) * 0.5, 0);
                    GL.Vertex3(Math.Cos(i * Math.PI / 8), Math.Sin(i * Math.PI / 8), 0);
                    GL.Vertex3(Math.Cos((i + 1) * Math.PI / 8) * 0.5, Math.Sin((i + 1) * Math.PI / 8) * 0.5, 0);
                    GL.Vertex3(0, 0, 0);
                }
                GL.End();
            }
            else
            {
                long a         = -angle; //Otherwise 90 would point down
                int  angleflip = 0;
                if (resultPos._z < 0)
                {
                    angleflip = 180;
                }
                m = Matrix.TransformMatrix(new Vector3(1), new Vector3(a, angleflip, 0), new Vector3());
                GL.MultMatrix((float *)&m);
                GL.Begin(BeginMode.Quads);
                // left face
                GL.Vertex3(0.1, 0.1, 0);
                GL.Vertex3(0.1, 0.1, 1);
                GL.Vertex3(0.1, -0.1, 1);
                GL.Vertex3(0.1, -0.1, 0);
                // right face
                GL.Vertex3(-0.1, -0.1, 0);
                GL.Vertex3(-0.1, -0.1, 1);
                GL.Vertex3(-0.1, 0.1, 1);
                GL.Vertex3(-0.1, 0.1, 0);
                // top face
                GL.Vertex3(-0.1, 0.1, 0);
                GL.Vertex3(-0.1, 0.1, 1);
                GL.Vertex3(0.1, 0.1, 1);
                GL.Vertex3(0.1, 0.1, 0);
                // bottom face
                GL.Vertex3(0.1, -0.1, 0);
                GL.Vertex3(0.1, -0.1, 1);
                GL.Vertex3(-0.1, -0.1, 1);
                GL.Vertex3(-0.1, -0.1, 0);
                // front face
                GL.Vertex3(-0.1, -0.1, 1);
                GL.Vertex3(0.1, -0.1, 1);
                GL.Vertex3(0.1, 0.1, 1);
                GL.Vertex3(-0.1, 0.1, 1);
                // back face
                GL.Vertex3(-0.1, 0.1, 0);
                GL.Vertex3(0.1, 0.1, 0);
                GL.Vertex3(0.1, -0.1, 0);
                GL.Vertex3(-0.1, -0.1, 0);
                GL.End();
            }
            GL.PopMatrix();

            // border
            GLDisplayList rings = TKContext.GetRingList();

            for (int i = -5; i <= 5; i++)
            {
                GL.PushMatrix();
                m = Matrix.TransformMatrix(new Vector3(1 + 0.0025f * i), (globalPos + bonePos).LookatAngles(cam) * Maths._rad2degf, new Vector3());
                GL.MultMatrix((float *)&m);
                if (flags.Clang)
                {
                    rings.Call();
                }
                else
                {
                    for (double j = 0; j < 360 / (drawAngle / 2); j += 2)
                    {
                        double ang1 = (j * (drawAngle / 2)) / 180 * Math.PI;
                        double ang2 = ((j + 1) * (drawAngle / 2)) / 180 * Math.PI;
                        GL.Begin(BeginMode.LineStrip);
                        GL.Vertex3(Math.Cos(ang1), Math.Sin(ang1), 0);
                        GL.Vertex3(Math.Cos(ang2), Math.Sin(ang2), 0);
                        GL.End();
                    }
                }
                GL.PopMatrix();
            }

            GL.PopMatrix();
            GL.PopMatrix();
        }
        private void ParseScripts(bint *hdr, int[] sizes)
        {
            Script             s = null;
            int                size, count;
            bint *             actionOffset;
            List <List <int> > list;

            MovesetNode node = _root as MovesetNode;

            sSubActionFlags *sflags = (sSubActionFlags *)Address(hdr[0]);
            sActionFlags *   aflags = (sActionFlags *)Address(hdr[6]);

            //Collect offsets first
            size = sizes[9];
            for (int i = 9; i < 11; i++)
            {
                if (hdr[i] < 0)
                {
                    continue;
                }
                actionOffset = (bint *)Address(hdr[i]);
                for (int x = 0; x < size / 4; x++)
                {
                    node._scriptOffsets[0][i - 9].Add(actionOffset[x]);
                }
            }
            size = sizes[12];
            for (int i = 12; i < 16; i++)
            {
                if (hdr[i] < 0)
                {
                    continue;
                }
                actionOffset = (bint *)Address(hdr[i]);
                for (int x = 0; x < size / 4; x++)
                {
                    node._scriptOffsets[1][i - 12].Add(actionOffset[x]);
                }
            }

            //Now parse scripts using collected offsets
            //The offsets are stored in the root in order to find scripts later

            //Actions first
            ActionEntry ag;

            list          = node._scriptOffsets[0];
            count         = list[0].Count;
            node._actions = new BindingList <ActionEntry>();
            for (int i = 0; i < count; i++)
            {
                sActionFlags flag = aflags[i];
                node.Actions.Add(ag = new ActionEntry(flag, i, i + 274));
                for (int x = 0; x < 2; x++)
                {
                    if (i < list[x].Count && list[x][i] > 0)
                    {
                        s = Parse <Script>(list[x][i]);
                    }
                    else
                    {
                        s = new Script();
                    }
                    ag.SetWithType(x, s);
                }
            }

            //Now subactions
            SubActionEntry sg;

            list        = node._scriptOffsets[1];
            count       = list[0].Count;
            _subActions = new BindingList <SubActionEntry>();
            for (int i = 0; i < count; i++)
            {
                sSubActionFlags flag = sflags[i];
                _subActions.Add(sg = new SubActionEntry(flag, flag._stringOffset > 0 ? new String((sbyte *)Address(flag._stringOffset)) : "<null>", i));
                for (int x = 0; x < 4; x++)
                {
                    if (i < list[x].Count && list[x][i] > 0)
                    {
                        s = Parse <Script>(list[x][i]);
                    }
                    else
                    {
                        s = new Script();
                    }
                    sg.SetWithType(x, s);
                }
            }
        }
Ejemplo n.º 6
0
        private void ParseScripts(bint *hdr, int[] sizes)
        {
            Script s = null;
            int    size, count, offset;
            bint * actionOffset;

            MovesetNode node = _root as MovesetNode;

            //Collect offsets first
            for (int i = 0; i < 2; i++)
            {
                if ((offset = hdr[i + 4]) < 0)
                {
                    continue;
                }

                actionOffset = (bint *)Address(offset);
                for (int x = 0; x < sizes[i + 4] / 4; x++)
                {
                    node._scriptOffsets[0][i].Add(*actionOffset++);
                }
            }

            List <uint>[] flags = new List <uint>[] { new List <uint>(), new List <uint>() };
            for (int i = 0; i < 2; i++)
            {
                size = _root.GetSize(offset = hdr[i + 19]);
                if (offset > 0)
                {
                    actionOffset = (bint *)Address(offset);
                    for (int x = 0; x < size / 16; x++)
                    {
                        node._scriptOffsets[i + 3][0].Add(*actionOffset++);
                        flags[i].Add((uint)(int)*actionOffset++);
                    }
                }
            }

            //Now parse scripts

            ActionEntry        ag;
            List <List <int> > actionOffsets = node._scriptOffsets[0];

            count         = Math.Max(actionOffsets[0].Count, actionOffsets[1].Count);
            node._actions = new BindingList <ActionEntry>();
            for (int i = 0; i < count; i++)
            {
                node.Actions.Add(ag = new ActionEntry(new sActionFlags(), i, i));
                for (int x = 0; x < 2; x++)
                {
                    if (i < actionOffsets[x].Count && actionOffsets[x][i] > 0)
                    {
                        s = Parse <Script>(actionOffsets[x][i]);
                    }
                    else
                    {
                        s = new Script();
                    }
                    ag.SetWithType(x, s);
                }
            }

            _flashOverlays = new BindingList <CommonAction>();
            _screenTints   = new BindingList <CommonAction>();
            BindingList <CommonAction>[] lists = new BindingList <CommonAction>[]
            {
                _flashOverlays,
                _screenTints
            };

            CommonAction ca;

            for (int x = 0; x < 2; x++)
            {
                List <int> offsets = node._scriptOffsets[x + 3][0];
                count = offsets.Count;
                for (int i = 0; i < count; i++)
                {
                    uint flag = flags[x][i];
                    ca = i < offsets.Count && offsets[i] > 0 ?
                         Parse <CommonAction>(offsets[i], flag) :
                         new CommonAction(flag);
                    ca._index = i;
                    lists[x].Add(ca);
                }
            }
        }