示例#1
0
        /// <summary>
        /// Add prop script
        /// </summary>
        /// <param name="vector"></param>
        public void AddNpc(Vector vector)
        {
            var propScript = new NpcProp
            {
                Position = vector
            };

            Props.Add(propScript);

            Added?.Invoke(this, new AddedArgs(propScript, typeof(NpcProp)));
        }
示例#2
0
        /// <summary>
        /// Update a prop nflavor script
        /// </summary>
        /// <param name="index"></param>
        /// <param name="prop"></param>
        public void UpdateNpc(int index, NpcProp prop)
        {
            Props[index] = prop;

            Updated?.Invoke(this, new UpdatedArgs(index, prop, typeof(NpcProp)));
        }
示例#3
0
        /// <summary>
        /// Load existing nflavor script
        /// </summary>
        /// <param name="buffer"></param>
        public void Load(byte[] buffer)
        {
            try
            {
                using (MemoryReader mem = new MemoryReader(buffer))
                {
                    /*Sign = Encoding.Default.GetString()*/ mem.ReadBytes(16);
                    Version = mem.ReadInt32();

#if DEBUG == false
                    if (!SupportedVersion.Contains(Version))
                    {
                        Parent.Log(Levels.Error, $"Failed\n");
                        Parent.Log(Levels.Fatal, $"Nfs::Load<Version> -> Incompatible version {Version} is not supported\n");
                        return;
                    }
#endif

                    /* nfs.dwEventLocationOffset = */
                    mem.ReadInt32();
                    /* nfs.dwEventScriptOffset = */ mem.ReadInt32();
                    /* nfs.dwPropScriptOffset = */ mem.ReadInt32();

                    var nLocationCount = mem.ReadInt32();
                    Respawns = new List <Respawn>();

                    for (int i = 0; i < nLocationCount; i++)
                    {
                        var location = new Respawn();

                        location.Rectangle.LeftTop = new Vector
                        {
                            X = mem.ReadInt32() * Global.TileLenght / Global.ScaleRatio,
                            Y = mem.ReadInt32() * Global.TileLenght / Global.ScaleRatio
                        }
                        .Rotate180FlipY();

                        location.Rectangle.RightBottom = new Vector
                        {
                            X = mem.ReadInt32() * Global.TileLenght / Global.ScaleRatio,
                            Y = mem.ReadInt32() * Global.TileLenght / Global.ScaleRatio
                        }
                        .Rotate180FlipY();

                        var stringSize = mem.ReadInt32();
                        location.Description = Encoding.Default.GetString(mem.ReadBytes(stringSize));
                        Respawns.Add(location);
                    }

                    var nScriptCount = mem.ReadInt32();

                    for (int i = 0; i < nScriptCount; i++)
                    {
                        var index          = mem.ReadInt32();
                        var nFunctionCount = mem.ReadInt32();

                        for (int f = 0; f < nFunctionCount; f++)
                        {
                            /* function.nTrigger = */ mem.ReadInt32();
                            var nStringSize    = mem.ReadInt32();
                            var FunctionString = Encoding.Default.GetString(mem.ReadBytes(nStringSize));
                            Respawns[index].Scripts.Add(FunctionString);
                        }
                    }

                    var nPropCount = mem.ReadInt32();
                    Props = new List <NpcProp>();

                    for (int i = 0; i < nPropCount; i++)
                    {
                        var propScript = new NpcProp();
                        propScript.PropId = mem.ReadInt32();

                        var vector = new Vector
                        {
                            X = mem.ReadSingle() / 7.875f,
                            Y = mem.ReadSingle() / 7.875f
                        };

                        propScript.Position = vector.Rotate180FlipY();
                        propScript.ModelId  = mem.ReadInt16();
                        var nFunctionCount = mem.ReadInt32();

                        for (int f = 0; f < nFunctionCount; f++)
                        {
                            /* function.nTrigger = */ mem.ReadInt32();
                            var nStringSize    = mem.ReadInt32();
                            var FunctionString = Encoding.Default.GetString(mem.ReadBytes(nStringSize));
                            propScript.Scripts.Add(FunctionString);
                        }

                        Props.Add(propScript);
                    }
                }

                Render();
                Parent.Log(Levels.Success, "Ok\n");
            }
            catch (Exception exception)
            {
                Dispose();
                Parent.Log(Levels.Error, "Failed\n");
                Parent.Log(Levels.Fatal, $"Nfs::Load<Exception> -> {exception}\n");
            }
        }