예제 #1
0
        private static void Main(string[] args)
        {
            try
            {
                Dictionary<string, RS5DirectoryEntry> directory = OpenRS5Files();
                Console.Write("Processing environment ... ");
                SubStream environdata = directory["environment"].Data.Chunks["DATA"].Data;
                using (Stream environfile = File.Create("environment.bin"))
                {
                    environdata.CopyTo(environfile);
                }
                RS5Environment environ = new RS5Environment(environdata);
                Dictionary<string, List<AnimationClip>> animclips = ProcessEnvironmentAnimations(environ);
                Console.WriteLine("Done");
                XElement environ_xml = environ.ToXML();

                try
                {
                    environ_xml.Save("environment.xml");
                    WriteRS5Contents(directory, animclips);
                }
                catch (UnauthorizedAccessException)
                {
                    System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
                    string exepath = Path.GetDirectoryName(asm.Location);
                    Console.WriteLine("Unable to write to working directory {0}", Environment.CurrentDirectory);
                    Console.WriteLine("Do you want to write to the directory the executable is in?");
                    Console.WriteLine("({0})", exepath);
                    Console.Write("[y/N] ");
                    ConsoleKeyInfo keyinfo = Console.ReadKey(false);
                    Console.WriteLine();
                    if (keyinfo.KeyChar == 'y' || keyinfo.KeyChar == 'Y')
                    {
                        Environment.CurrentDirectory = exepath;
                        environ_xml.Save("environment.xml");
                        WriteRS5Contents(directory, animclips);
                    }
                }
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("Unable to load RS5 files");
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Caught exception: {0}\n\nPlease report this to Ben Peddell <*****@*****.**>", ex.ToString());
            }

            Console.Error.Write("Press any key to exit");
            Console.ReadKey(true);
        }
예제 #2
0
        private static Dictionary<string, List<AnimationClip>> ProcessEnvironmentAnimations(RS5Environment environ)
        {
            Dictionary<string, List<AnimationClip>> animclips = new Dictionary<string, List<AnimationClip>>(StringComparer.InvariantCultureIgnoreCase);

            #region animals
            foreach (KeyValuePair<string, dynamic> animal_kvp in environ.Data["animals"])
            {
                string key = animal_kvp.Key;
                dynamic animal = animal_kvp.Value;
                string modelset = "animals\\" + key;
                string modelname = animal["model"];
                if (modelset.ToLower().StartsWith(modelname.ToLower()))
                {
                    modelset = modelset.Substring(modelname.Length);
                    if (modelset.StartsWith("_"))
                    {
                        modelset = modelset.Substring(1);
                    }
                }
                modelset = Path.GetFileName(modelset);
                Dictionary<string, dynamic> animations = animal["animations"];
                foreach (KeyValuePair<string, dynamic> anim_kvp in animations)
                {
                    string animname = (modelset == "" ? "" : (modelset + ".")) + anim_kvp.Key;
                    string animparamstring = anim_kvp.Value;
                    Dictionary<string, string> animparams = animparamstring.Split(',').Select(v => v.Split(new char[] { '=' }, 2)).Where(v => v.Length == 2).ToDictionary(v => v[0], v => v[1]);
                    int startframe = Int32.Parse(animparams["F1"]);
                    int endframe = Int32.Parse(animparams["F2"]);
                    float framerate = animparams.ContainsKey("rate") ? Single.Parse(animparams["rate"]) : 60.0F;
                    if (!animclips.ContainsKey(modelname))
                    {
                        animclips[modelname] = new List<AnimationClip>();
                    }
                    animclips[modelname].Add(new AnimationClip { ModelName = modelname, Name = animname, StartFrame = startframe, NumFrames = endframe - startframe, FrameRate = framerate });
                }
            }
            #endregion

            #region creature movements
            foreach (KeyValuePair<string, dynamic> movement_kvp in environ.Data["creature"]["navigation"]["MOVEMENTS"])
            {
                string animname = movement_kvp.Key;
                string animparamstring = movement_kvp.Value;
                Dictionary<string, string> animparams = animparamstring.Split(',').Select(v => v.Split(new char[] { '=' }, 2)).Where(v => v.Length == 2).ToDictionary(v => v[0], v => v[1], StringComparer.InvariantCultureIgnoreCase);
                if (animparams.ContainsKey("F1") && animparams.ContainsKey("F2"))
                {
                    int startframe = Int32.Parse(animparams["F1"]);
                    int endframe = Int32.Parse(animparams["F2"]);
                    float framerate = animparams.ContainsKey("rate") ? Single.Parse(animparams["rate"]) : 60.0F;
                    foreach (string modelname in new string[]{ "creature", "creature_ik" })
                    {
                        if (!animclips.ContainsKey(modelname))
                        {
                            animclips[modelname] = new List<AnimationClip>();
                        }
                        animclips[modelname].Add(new AnimationClip { ModelName = modelname, Name = animname, StartFrame = startframe, NumFrames = endframe - startframe, FrameRate = framerate });
                    }
                }
            }
            #endregion

            #region hand animations
            foreach (KeyValuePair<string, dynamic> handanim_kvp in environ.Data["player"]["hand_animations"])
            {
                string animname = handanim_kvp.Key;
                Dictionary<string, dynamic> animparams = handanim_kvp.Value;
                if (animparams.ContainsKey("frames"))
                {
                    int startframe = animparams["frames"][0];
                    int endframe = animparams["frames"][1];
                    float framerate = 24.0F;
                    foreach (string modelname in new string[] { "hands", "hands_synth", "hands_ending" })
                    {
                        if (!animclips.ContainsKey(modelname))
                        {
                            animclips[modelname] = new List<AnimationClip>();
                        }
                        animclips[modelname].Add(new AnimationClip { ModelName = modelname, Name = animname, StartFrame = startframe, NumFrames = endframe - startframe, FrameRate = framerate });
                    }
                }
            }
            #endregion

            #region hand animations with game objects
            foreach (KeyValuePair<string, dynamic> obj_kvp in environ.Data["game_objects"])
            {
                string animname = obj_kvp.Key;
                Dictionary<string, dynamic> obj = obj_kvp.Value;
                if (obj.ContainsKey("SCRIPT"))
                {
                    Dictionary<string, dynamic> script = obj["SCRIPT"];
                    if (script.ContainsKey("frames"))
                    {
                        int startframe = script["frames"][0];
                        int endframe = script["frames"][1];

                        foreach (string modelname in new string[] { "hands", "hands_synth", "hands_ending" })
                        {

                            float framerate = 24.0F;
                            if (!animclips.ContainsKey(modelname))
                            {
                                animclips[modelname] = new List<AnimationClip>();
                            }
                            animclips[modelname].Add(new AnimationClip { ModelName = modelname, Name = animname, StartFrame = startframe, NumFrames = endframe - startframe, FrameRate = framerate });
                        }
                    }
                }
            }
            #endregion

            return animclips;
        }