Exemplo n.º 1
0
        private static void GenerateCitiesDatabase()
        {
            Dictionary <FAR3Entry, string> CityEntries = new Dictionary <FAR3Entry, string>();

            AddFilesFromDir(GlobalSettings.Default.StartupPath + "cities\\", "", ref CityEntries);
            WriteCSEnum("packingslips\\CitiesFileIDs.cs", "CitiesFileIDs", CityEntries);

            StreamWriter Writer = new StreamWriter(File.Create(GlobalSettings.Default.StartupPath +
                                                               "packingslips\\cities.xml"));

            Writer.WriteLine("<?xml version=\"1.0\"?>");
            Writer.WriteLine("<AssetList>");

            //For some really weird reason, "key" and "assetID" are written in reverse order...
            foreach (KeyValuePair <FAR3Entry, string> KVP in CityEntries)
            {
                if (KVP.Value.Contains(".dat"))
                {
                    Writer.WriteLine("  " + "<DefineAssetString key=\"" + KVP.Value +
                                     "\" assetID=\"" + "0x" + string.Format("{0:X}", HelperFuncs.ToID(KVP.Key.TypeID, KVP.Key.FileID)) + "\"/>");
                }
                else
                {
                    DirectoryInfo DirInfo = new DirectoryInfo(KVP.Value);
                    Writer.WriteLine("  " + "<DefineAssetString key=\"" + DirInfo.Parent + "\\" +
                                     Path.GetFileName(KVP.Value) + "\" assetID=\"" + "0x" +
                                     string.Format("{0:X}", HelperFuncs.ToID(KVP.Key.TypeID, KVP.Key.FileID)) + "\"/>");
                }
            }

            Writer.WriteLine("</AssetList>");
            Writer.Close();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates a database of the files in the uigraphics folder,
        /// as well as a *.cs file with an enumeration of the same files
        /// and their corresponding FileIDs.
        /// </summary>
        private static void GenerateUIGraphicsDatabase()
        {
            Dictionary <FAR3Entry, string> UIEntries = new Dictionary <FAR3Entry, string>();

            AddFilesFromDir(GlobalSettings.Default.StartupPath + "uigraphics\\", "", ref UIEntries);

            Directory.CreateDirectory("packingslips");
            WriteCSEnum("packingslips\\UIFileIDs.cs", "UIFileIDs", UIEntries);

            StreamWriter Writer = new StreamWriter(File.Create(GlobalSettings.Default.StartupPath +
                                                               "packingslips\\uigraphics.xml"));

            Writer.WriteLine("<?xml version=\"1.0\"?>");
            Writer.WriteLine("<AssetList>");

            //For some really weird reason, "key" and "assetID" are written in reverse order...
            //UI entries need to be padded out with extra 0s because there are duplicate entries.
            foreach (KeyValuePair <FAR3Entry, string> KVP in UIEntries)
            {
                if (KVP.Value.Contains(".dat"))
                {
                    /*Writer.WriteLine("  " + "<DefineAssetString key=\"" + KVP.Value +
                     *  "\" assetID=\"" + "0x" +
                     *  HelperFuncs.ApplyPadding(string.Format("{0:X}", KVP.Key.TypeID)) +
                     *  HelperFuncs.ApplyPadding(string.Format("{0:X}", KVP.Key.FileID))
                     *  .Replace("0x", "") + "\"/>");*/
                    Writer.WriteLine("  " + "<DefineAssetString key=\"" + KVP.Value +
                                     "\" assetID=\"" + "0x" +
                                     string.Format("{0:X}", HelperFuncs.ToID(KVP.Key.TypeID, KVP.Key.FileID)) + "\"/>");
                }
                else
                {
                    /*DirectoryInfo DirInfo = new DirectoryInfo(KVP.Value);
                     * Writer.WriteLine("  " + "<DefineAssetString key=\"" + DirInfo.Parent + "\\" +
                     *  Path.GetFileName(KVP.Value) + "\" assetID=\"" +
                     *  HelperFuncs.ApplyPadding(string.Format("{0:X}", KVP.Key.TypeID)) +
                     *  HelperFuncs.ApplyPadding(string.Format("{0:X}",
                     *  KVP.Key.FileID)).Replace("0x", "") + "\"/>");*/
                    DirectoryInfo DirInfo = new DirectoryInfo(KVP.Value);
                    Writer.WriteLine("  " + "<DefineAssetString key=\"" + DirInfo.Parent + "\\" +
                                     Path.GetFileName(KVP.Value) + "\" assetID=\"" +
                                     string.Format("{0:X}", HelperFuncs.ToID(KVP.Key.TypeID, KVP.Key.FileID)) + "\"/>");
                }
            }

            Writer.WriteLine("</AssetList>");
            Writer.Close();
        }
Exemplo n.º 3
0
        private static void WriteCSEnum(string Path, string EnumName, Dictionary <FAR3Entry, string> Entries)
        {
            StreamWriter Writer = new StreamWriter(File.Create(Path));

            Writer.WriteLine("using System;");
            Writer.WriteLine("");
            Writer.WriteLine("namespace TSOClient");
            Writer.WriteLine("{");
            Writer.WriteLine("  //Generated by Mr. Shipper - filenames have been sanitized, and does not match");
            Writer.WriteLine("  //actual filenames character for character!");
            Writer.WriteLine("  partial class FileIDs");
            Writer.WriteLine("  {");
            Writer.WriteLine("      public enum " + EnumName + " : long");
            Writer.WriteLine("      {");

            int StopCounter = 0;

            foreach (KeyValuePair <FAR3Entry, string> KVP in Entries)
            {
                StopCounter++;

                if (StopCounter < Entries.Count)
                {
                    Writer.WriteLine("          " + HelperFuncs.SanitizeFilename(KVP.Key.Filename.Replace("\\", "_")) + " = " +
                                     "0x" + string.Format("{0:X}", HelperFuncs.ToID(KVP.Key.TypeID, KVP.Key.FileID)) + ",");
                }
                else
                {
                    Writer.WriteLine("          " + HelperFuncs.SanitizeFilename(KVP.Key.Filename.Replace("\\", "_")) + " = " +
                                     "0x" + string.Format("{0:X}", HelperFuncs.ToID(KVP.Key.TypeID, KVP.Key.FileID)));
                }
            }

            Writer.WriteLine("      };");
            Writer.WriteLine("  }");
            Writer.WriteLine("}");
            Writer.Close();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds files from a specified directory to a dictionary of entries.
        /// </summary>
        /// <param name="EntryDir">The directory to scan for entries.</param>
        /// <param name="Filetype">A fully qualified lowercase filetype to scan for (can be empty).</param>
        /// <param name="Entries">The Dictionary to add entries to.</param>
        private static void AddFilesFromDir(string EntryDir, string Filetype, ref Dictionary <FAR3Entry, string> Entries)
        {
            string[] Dirs = Directory.GetDirectories(EntryDir);

            foreach (string Dir in Dirs)
            {
                if (Filetype != "")
                {
                    if (Dir.Contains(Filetype))
                    {
                        string[] Files   = Directory.GetFiles(Dir);
                        string[] SubDirs = Directory.GetDirectories(Dir);
                        foreach (string Fle in Files)
                        {
                            if (Fle.Contains(".dat"))
                            {
                                FAR3Archive Archive = new FAR3Archive(Fle);
                                Archive.ReadArchive(true);

                                foreach (FAR3Entry Entry in Archive.GrabAllEntries())
                                {
                                    Entries.Add(Entry, Fle.Replace(GlobalSettings.Default.StartupPath, ""));
                                }
                            }
                            else
                            {
                                FAR3Entry Entry = new FAR3Entry();
                                Entry.Filename = Fle.Replace(GlobalSettings.Default.StartupPath, "");
                                Entry.FileID   = HelperFuncs.GetFileID(Entry);
                                Entry.TypeID   = HelperFuncs.GetTypeID(Path.GetExtension(Fle));

                                HelperFuncs.CheckCollision(Entry.FileID, Entries);

                                //Ignore fonts to minimize the risk of ID collisions.
                                if (!Entry.Filename.Contains(".ttf"))
                                {
                                    if (!Entry.Filename.Contains(".ffn"))
                                    {
                                        Entries.Add(Entry, Entry.Filename);
                                    }
                                }
                            }
                        }

                        foreach (string SubDir in SubDirs)
                        {
                            Files = Directory.GetFiles(SubDir);
                            foreach (string SubFle in Files)
                            {
                                if (SubFle.Contains(".dat"))
                                {
                                    FAR3Archive Archive = new FAR3Archive(SubFle);
                                    Archive.ReadArchive(false);

                                    foreach (FAR3Entry Entry in Archive.GrabAllEntries())
                                    {
                                        Entries.Add(Entry, SubFle.Replace(GlobalSettings.Default.StartupPath, ""));
                                    }
                                }
                                else
                                {
                                    FAR3Entry Entry = new FAR3Entry();
                                    Entry.Filename = SubFle.Replace(GlobalSettings.Default.StartupPath, "");
                                    Entry.FileID   = HelperFuncs.GetFileID(Entry);
                                    Entry.TypeID   = HelperFuncs.GetTypeID(Path.GetExtension(SubFle));

                                    HelperFuncs.CheckCollision(Entry.FileID, Entries);

                                    //Ignore fonts to minimize the risk of ID collisions.
                                    if (!Entry.Filename.Contains(".ttf"))
                                    {
                                        if (!Entry.Filename.Contains(".ffn"))
                                        {
                                            Entries.Add(Entry, Entry.Filename);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else //Filetype was empty, so just add all filetypes found...
                {
                    string[] Files   = Directory.GetFiles(Dir);
                    string[] SubDirs = Directory.GetDirectories(Dir);
                    foreach (string Fle in Files)
                    {
                        if (Fle.Contains(".dat"))
                        {
                            FAR3Archive Archive = new FAR3Archive(Fle);
                            Archive.ReadArchive(true);

                            foreach (FAR3Entry Entry in Archive.GrabAllEntries())
                            {
                                Entries.Add(Entry, Fle.Replace(GlobalSettings.Default.StartupPath, ""));
                            }
                        }
                        else
                        {
                            FAR3Entry Entry = new FAR3Entry();
                            Entry.Filename = Fle.Replace(GlobalSettings.Default.StartupPath, "");
                            Entry.FileID   = HelperFuncs.GetFileID(Entry);
                            Entry.TypeID   = HelperFuncs.GetTypeID(Path.GetExtension(Fle));

                            HelperFuncs.CheckCollision((ulong)(((ulong)Entry.FileID) << 32 | ((ulong)(Entry.TypeID >> 32))), Entries);

                            //Ignore fonts to minimize the risk of ID collisions.
                            if (!Entry.Filename.Contains(".ttf"))
                            {
                                if (!Entry.Filename.Contains(".ffn"))
                                {
                                    Entries.Add(Entry, Entry.Filename);
                                }
                            }
                        }
                    }

                    foreach (string SubDir in SubDirs)
                    {
                        Files = Directory.GetFiles(SubDir);
                        foreach (string SubFle in Files)
                        {
                            if (SubFle.Contains(".dat"))
                            {
                                FAR3Archive Archive = new FAR3Archive(SubFle);
                                Archive.ReadArchive(true);

                                foreach (FAR3Entry Entry in Archive.GrabAllEntries())
                                {
                                    Entries.Add(Entry, SubFle.Replace(GlobalSettings.Default.StartupPath, ""));
                                }
                            }
                            else
                            {
                                FAR3Entry Entry = new FAR3Entry();
                                Entry.Filename = SubFle.Replace(GlobalSettings.Default.StartupPath, "");
                                Entry.FileID   = HelperFuncs.GetFileID(Entry);
                                Entry.TypeID   = HelperFuncs.GetTypeID(Path.GetExtension(SubFle));

                                HelperFuncs.CheckCollision((ulong)(((ulong)Entry.FileID) << 32 | ((ulong)(Entry.TypeID >> 32))), Entries);

                                //Ignore fonts to minimize the risk of ID collisions.
                                if (!Entry.Filename.Contains(".ttf"))
                                {
                                    if (!Entry.Filename.Contains(".ffn"))
                                    {
                                        Entries.Add(Entry, Entry.Filename);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        private static void GenerateCollectionsDatabase()
        {
            Dictionary <FAR3Entry, string> CollectionEntries = new Dictionary <FAR3Entry, string>();

            AddFilesFromDir(GlobalSettings.Default.StartupPath + "avatardata\\bodies\\", "collections", ref CollectionEntries);
            AddFilesFromDir(GlobalSettings.Default.StartupPath + "avatardata\\heads\\", "collections", ref CollectionEntries);
            AddFilesFromDir(GlobalSettings.Default.StartupPath + "avatardata2\\bodies\\", "collections", ref CollectionEntries);
            AddFilesFromDir(GlobalSettings.Default.StartupPath + "avatardata2\\heads\\", "collections", ref CollectionEntries);
            AddFilesFromDir(GlobalSettings.Default.StartupPath + "avatardata3\\bodies\\", "collections", ref CollectionEntries);
            AddFilesFromDir(GlobalSettings.Default.StartupPath + "avatardata3\\heads\\", "collections", ref CollectionEntries);

            StreamWriter Writer = new StreamWriter(File.Create("packingslips\\CollectionsFileIDs.cs"));

            Writer.WriteLine("using System;");
            Writer.WriteLine("");
            Writer.WriteLine("namespace TSOClient");
            Writer.WriteLine("{");
            Writer.WriteLine("  //Generated by Mr. Shipper - filenames have been sanitized, and does not match");
            Writer.WriteLine("  //actual filenames character for character!");
            Writer.WriteLine("  partial class FileIDs");
            Writer.WriteLine("  {");
            Writer.WriteLine("      public enum CollectionsFileIDs : long");
            Writer.WriteLine("      {");

            int StopCounter = 0;

            foreach (KeyValuePair <FAR3Entry, string> KVP in CollectionEntries)
            {
                StopCounter++;

                if (StopCounter < CollectionEntries.Count)
                {
                    Writer.WriteLine("          " + HelperFuncs.SanitizeFilename(Path.GetFileName(KVP.Key.Filename)) + " = " +
                                     "0x" + string.Format("{0:X}", HelperFuncs.ToID(KVP.Key.TypeID, KVP.Key.FileID)) + ",");
                }
                else
                {
                    Writer.WriteLine("          " + HelperFuncs.SanitizeFilename(Path.GetFileName(KVP.Key.Filename)) + " = " +
                                     "0x" + string.Format("{0:X}", HelperFuncs.ToID(KVP.Key.TypeID, KVP.Key.FileID)));
                }
            }

            Writer.WriteLine("      };");
            Writer.WriteLine("  }");
            Writer.WriteLine("}");
            Writer.Close();

            Writer = new StreamWriter(File.Create(GlobalSettings.Default.StartupPath +
                                                  "packingslips\\collections.xml"));
            Writer.WriteLine("<?xml version=\"1.0\"?>");
            Writer.WriteLine("<AssetList>");

            //For some really weird reason, "key" and "assetID" are written in reverse order...
            foreach (KeyValuePair <FAR3Entry, string> KVP in CollectionEntries)
            {
                if (KVP.Value.Contains(".dat"))
                {
                    Writer.WriteLine("  " + "<DefineAssetString key=\"" + KVP.Value +
                                     "\" assetID=\"" + "0x" + string.Format("{0:X}", HelperFuncs.ToID(KVP.Key.TypeID, KVP.Key.FileID)) + "\"/>");
                }
                else
                {
                    DirectoryInfo DirInfo = new DirectoryInfo(KVP.Value);
                    Writer.WriteLine("  " + "<DefineAssetString key=\"" + DirInfo.Parent + "\\" +
                                     Path.GetFileName(KVP.Value) + "\" assetID=\"" + "0x" +
                                     string.Format("{0:X}", HelperFuncs.ToID(KVP.Key.TypeID, KVP.Key.FileID)) + "\"/>");
                }
            }

            Writer.WriteLine("</AssetList>");
            Writer.Close();
        }