Пример #1
0
        private void toolImportFilter_Click(object sender, EventArgs e)
        {
            using (var open = new OpenFileDialog {
                Filter = "INI File|*.ini"
            })
            {
                if (open.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var import = IniSerializer.Deserialize <List <Filter> >(open.FileName);

                if (import.Count == 0)
                {
                    MessageBox.Show("This file doesn't contain any filters.", "Import error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                using (var window = new FilterSelect(import))
                {
                    if (window.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    foreach (int i in window.SelectedFilters)
                    {
                        Program.Settings.Filters.Add(window.FilterList[i]);
                    }
                }
            }
        }
Пример #2
0
            /// <summary>
            /// Load from a file (VMS or INI)
            /// </summary>
            public static VMS_DLC LoadFile(string filename)
            {
                switch (Path.GetExtension(filename.ToLowerInvariant()))
                {
                case ".vms":
                    return(new VMS_DLC(File.ReadAllBytes(filename)));

                case ".ini":
                    break;

                default:
                    System.Windows.Forms.MessageBox.Show("Unknown file format. Use VMS or INI.");
                    return(new VMS_DLC());
                }
                VMS_DLC header = IniSerializer.Deserialize <VMS_DLC>(filename);

                header.Icon        = new Bitmap(Path.ChangeExtension(filename, ".bmp"));
                header.SoundData   = new byte[0];
                header.TextureData = File.ReadAllBytes(Path.ChangeExtension(filename, ".pvm"));
                if (File.Exists(Path.ChangeExtension(filename, ".bin")))
                {
                    header.ModelData = FraGag.Compression.Prs.Compress(File.ReadAllBytes(Path.ChangeExtension(filename, ".bin")));
                }
                else
                {
                    header.ModelData = ConvertModel(Path.ChangeExtension(filename, ".sa1mdl"));
                }
                if (header.ContainsSound)
                {
                    header.SoundData = File.ReadAllBytes(Path.ChangeExtension(filename, ".mlt"));
                }
                return(header);
            }
Пример #3
0
        //public ObjListEditor()
        public ObjListEditor(string objlistpath, string objdefspath, string folder, IniDataSALVL lvlconfig)
        {
            InitializeComponent();
            salvl         = lvlconfig;
            modFolder     = folder;
            objListString = Path.Combine(folder, objlistpath);
            isSA2         = salvl.IsSA2;
            saved         = true;
            if (File.Exists(objListString))
            {
                ObjectListEntry[] objListArr = ObjectList.Load(objListString, isSA2);
                objList = new List <ObjectListEntry>(objListArr);
            }

            if (objdefspath == "" || !File.Exists(Path.Combine(folder, objdefspath)))
            {
                DialogResult error = MessageBox.Show(("Level Object Definitions not found. Please select a location to save the Definitions file."), "Definitions Not Located", MessageBoxButtons.OK);
                if (error == DialogResult.OK)
                {
                    CreateDefaultObjDefs();
                }
            }
            else
            {
                objDefString = Path.Combine(folder, objdefspath);
                if (File.Exists(objDefString))
                {
                    objDefinitions = IniSerializer.Deserialize <Dictionary <string, ObjectData> >(objDefString);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Create a PAK archive from a folder produced by ArchiveTool or PAKTool.
        /// </summary>
        static void BuildPAK(string filePath)
        {
            Console.WriteLine("Building PAK from folder: {0}", Path.GetFullPath(filePath));
            outputPath = Path.Combine(Environment.CurrentDirectory, filePath);
            Environment.CurrentDirectory = Path.GetDirectoryName(outputPath);
            string inipath = Path.Combine(Path.GetFileNameWithoutExtension(outputPath), Path.GetFileNameWithoutExtension(outputPath) + ".ini");

            if (!File.Exists(inipath))
            {
                Console.WriteLine("PAK INI file not found: {0}", inipath);
                Console.WriteLine("The folder must contain either index.txt or an INI file to be recognized as a buildable archive folder.");
                Console.WriteLine("Press ENTER to exit.");
                Console.ReadLine();
                return;
            }
            PAKFile.PAKIniData list = IniSerializer.Deserialize <PAKFile.PAKIniData>(inipath);
            PAKFile            pak  = new PAKFile()
            {
                FolderName = list.FolderName
            };

            foreach (KeyValuePair <string, PAKFile.PAKIniItem> item in list.Items)
            {
                Console.WriteLine("Adding file: {0}", item.Key);
                pak.Entries.Add(new PAKFile.PAKEntry(item.Key, item.Value.LongPath, File.ReadAllBytes(Path.Combine(Path.GetFileNameWithoutExtension(outputPath), item.Key))));
            }
            Console.WriteLine("Output file: {0}", Path.ChangeExtension(outputPath, "pak"));
            pak.Save(Path.ChangeExtension(outputPath, "pak"));
            Console.WriteLine("Done!");
        }
Пример #5
0
        public static DllIniData LoadMultiINI(List <string> fileName,
                                              ref Dictionary <string, bool> defaultExportState)
        {
            defaultExportState.Clear();
            DllIniData             newIniData = new DllIniData();
            List <DllDataItemInfo> curItems   = new List <DllDataItemInfo>();

            foreach (string arrFile in fileName)
            {
                DllIniData IniData = IniSerializer.Deserialize <DllIniData>(arrFile);

                Environment.CurrentDirectory = Path.GetDirectoryName(arrFile);

                foreach (KeyValuePair <string, FileTypeHash> item in IniData.Files)
                {
                    bool modified = HelperFunctions.FileHash(item.Key) != item.Value.Hash;
                    defaultExportState.Add(item.Key, modified);
                }

                foreach (DllDataItemInfo item in IniData.DataItems)
                {
                    CheckItems(item, IniData, ref defaultExportState);

                    curItems.Add(item);
                }
            }
            newIniData.DataItems = curItems;

            return(newIniData);
        }
Пример #6
0
        /// <summary>
        /// Attempts to load settings from ConfigFile.
        /// </summary>
        /// <returns>DialogResult.OK on success, DialogResult.Ignore if the file doesn't exist,
        /// and whatever is returned by the input from MessageBox if an error occurs.</returns>
        public static DialogResult LoadSettings()
        {
            DialogResult result;

            do
            {
                try
                {
                    if (File.Exists(Config))
                    {
                        Settings = IniSerializer.Deserialize <ProgramSettings>(Config);
                        result   = DialogResult.OK;
                    }
                    else
                    {
                        Settings.Filters.AddRange(DefaultFilters);
                        result = DialogResult.Ignore;
                    }
                }
                catch (Exception ex)
                {
                    result = MessageBox.Show("Too Lazy to Read was unable to load your settings?!\n\n"
                                             + ex.Message,
                                             "Error loading configuration", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
                }
            } while (result == DialogResult.Retry);

            return(result);
        }
Пример #7
0
        private void PopulateListBox()
        {
            listBox1.BeginUpdate();
            listBox1.Items.Clear();
            string objListPath = Path.Combine(folder, levels[keyList[lstLevelSelect.SelectedIndex]].ObjectList);
            string objDefPath  = Path.Combine(folder, levels[keyList[lstLevelSelect.SelectedIndex]].ObjectDefinition);

            objList = new List <ObjectListEntry>(ObjectList.Load(objListPath, salvl.IsSA2));
            objDefs = IniSerializer.Deserialize <Dictionary <string, ObjectData> >(objDefPath);

            foreach (ObjectListEntry obj in objList)
            {
                string key = obj.Name;
                string val;

                if (objDefs[obj.Name].Name != null)
                {
                    val = objDefs[obj.Name].Name;
                }
                else
                {
                    val = obj.Name;
                }

                KeyValuePair <string, string> entry = new KeyValuePair <string, string>(key, val);
                listBox1.Items.Add(entry);
                listBox1.DisplayMember = "Value";
            }
            listBox1.EndUpdate();
        }
Пример #8
0
        /// <summary>
        /// Sets the path for a specified game in GamePaths.ini.
        /// </summary>
        public static void SetGamePath(string gameName, string gamePath)
        {
            Dictionary <string, string> gamePathsList;
            string appdata           = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SA Tools");
            string gamePathsFilePath = Path.Combine(appdata, "GamePaths.ini");

            if (File.Exists(gamePathsFilePath))
            {
                gamePathsList = IniSerializer.Deserialize <Dictionary <string, string> >(gamePathsFilePath);
            }
            else
            {
                if (!Directory.Exists(appdata))
                {
                    Directory.CreateDirectory(appdata);
                }
                gamePathsList = new Dictionary <string, string>();
            }
            if (gamePathsList.ContainsKey(gameName))
            {
                gamePathsList[gameName] = gamePath;
            }
            else
            {
                gamePathsList.Add(gameName, gamePath);
            }
            IniSerializer.Serialize(gamePathsList, gamePathsFilePath);
        }
Пример #9
0
        public static GameInfo Load(string filename)
        {
            Dictionary <string, Dictionary <string, string> > ini = IniFile.Load(filename);
            string userfile = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename) + ".user" + Path.GetExtension(filename));

            if (File.Exists(userfile))
            {
                ini = IniFile.Combine(ini, IniFile.Load(userfile));
            }
            GameInfo result = IniSerializer.Deserialize <GameInfo>(ini);

            if (result.MappingsVersion == EngineVersion.Invalid)
            {
                result.MappingsVersion = result.EngineVersion;
            }
            if (result.DPLCVersion == EngineVersion.Invalid)
            {
                result.DPLCVersion = result.MappingsVersion;
            }
            if (result.GameName == null)
            {
                result.GameName = result.EngineVersion.ToString();
            }
            return(result);
        }
Пример #10
0
        static void Main(string[] args)
        {
            Queue <string> argq = new Queue <string>(args);
            string         inifilename;

            if (argq.Count > 0)
            {
                inifilename = argq.Dequeue();
                Console.WriteLine("INI File: {0}", inifilename);
            }
            else
            {
                Console.Write("INI File: ");
                inifilename = Console.ReadLine();
            }
            Dictionary <int, string> modelnames = IniSerializer.Deserialize <Dictionary <int, string> >(inifilename, inisettings);
            string mdlfilename;

            if (argq.Count > 0)
            {
                mdlfilename = argq.Dequeue();
                Console.WriteLine("Model File: {0}", mdlfilename);
            }
            else
            {
                Console.Write("Model File: ");
                mdlfilename = Console.ReadLine();
            }
            ModelFile model = new ModelFile(mdlfilename);

            NJS_OBJECT[] objects = model.Model.GetObjects();
            string       repmdlfilename;

            if (argq.Count > 0)
            {
                repmdlfilename = argq.Dequeue();
                Console.WriteLine("Replacement Model File: {0}", repmdlfilename);
            }
            else
            {
                Console.Write("Replacement Model File: ");
                repmdlfilename = Console.ReadLine();
            }
            ModelFile repmodel = new ModelFile(repmdlfilename);

            NJS_OBJECT[] repobjects = repmodel.Model.GetObjects();
            if (objects.Length != repobjects.Length)
            {
                Console.WriteLine("Models have different structures, the game may crash.");
            }
            foreach (KeyValuePair <int, string> item in modelnames.ToList())
            {
                if (objects.Any((obj) => obj.Name == item.Value))
                {
                    modelnames[item.Key] = repobjects[Array.IndexOf(objects, objects.Single((o) => o.Name == item.Value))].Name;
                }
            }
            ModelFile.CreateFile(mdlfilename, repmodel.Model, null, null, repmodel.Author, repmodel.Description, "replaceMDL", repmodel.Metadata, repmodel.Format);
            IniSerializer.Serialize(modelnames, inisettings, inifilename);
        }
Пример #11
0
        public static Settings Load()
        {
            filename = Path.Combine(Application.StartupPath, "SonLVL.ini");
            if (File.Exists(filename))
            {
                Settings result = IniSerializer.Deserialize <Settings>(filename);
                switch (result.CurrentTab)
                {
                case Tab.Chunks:
                    result.CurrentTab    = Tab.Art;
                    result.CurrentArtTab = ArtTab.Chunks;
                    break;

                case Tab.Blocks:
                    result.CurrentTab    = Tab.Art;
                    result.CurrentArtTab = ArtTab.Blocks;
                    break;

                case Tab.Tiles:
                    result.CurrentTab    = Tab.Art;
                    result.CurrentArtTab = ArtTab.Tiles;
                    break;

                case Tab.Solids:
                    result.CurrentTab    = Tab.Art;
                    result.CurrentArtTab = ArtTab.Solids;
                    break;
                }
                return(result);
            }
            else
            {
                Settings result = new Settings();
                // Import old style settings
                // Any new settings should not be added to the old settings class, and should have defaults applied here.
                Properties.Settings oldset = Properties.Settings.Default;
                result.ShowHUD  = oldset.ShowHUD;
                result.Emulator = oldset.Emulator;
                result.MRUList  = new List <string>();
                if (oldset.MRUList != null)
                {
                    foreach (string item in oldset.MRUList)
                    {
                        if (!string.IsNullOrEmpty(item))
                        {
                            result.MRUList.Add(item);
                        }
                    }
                }
                result.ShowGrid  = oldset.ShowGrid;
                result.GridColor = oldset.GridColor;
                result.Username  = oldset.Username;
                result.IncludeObjectsInForegroundSelection = oldset.IncludeObjectsInForegroundSelection;
                result.TransparentBackFGBGExport           = true;
                result.ViewLowPlane = result.ViewHighPlane = true;
                result.ZoomLevel    = "1x";
                result.ShowMenu     = true;
                return(result);
            }
        }
Пример #12
0
        // Loads a split INI file and lists all filenames by address in ascending order, as well as saves a sorted INI file
        static void SplitLF(string[] args)
        {
            string  inifilename = args[0];
            IniData inifile     = IniSerializer.Deserialize <IniData>(inifilename);

            inifile.Files = SortIniData(inifile.Files);
            IniSerializer.Serialize(inifile, Path.GetFileNameWithoutExtension(inifilename) + "_sorted.ini");
        }
Пример #13
0
        /*[IniName("map")]
         * public string MappingsFile { get; set; }
         * [IniName("mapgame")]
         * public EngineVersion MappingsGame { get; set; }
         * [IniName("mapfmt")]
         * public MappingsFormat MappingsFormat { get; set; }
         * [IniName("dplc")]
         * public string DPLCFile { get; set; }
         * [IniName("dplcgame")]
         * public EngineVersion DPLCGame { get; set; }
         * [IniName("dplcfmt")]
         * public MappingsFormat DPLCFormat { get; set; }
         * [IniName("anim")]
         * public string AnimationFile { get; set; }
         * [IniName("animfmt")]
         * public MappingsFormat AnimationFormat { get; set; }
         * [IniName("startpal")]
         * public int StartPalette { get; set; }*/

        public static Dictionary <string, AnimationInfo> Load(string filename)
        {
            Dictionary <string, Dictionary <string, string> > ini = IniFile.Load(filename);
            string userfile = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename) + ".user" + Path.GetExtension(filename));

            if (File.Exists(userfile))
            {
                ini = IniFile.Combine(ini, IniFile.Load(userfile));
            }
            Dictionary <string, AnimationInfo> result = IniSerializer.Deserialize <Dictionary <string, AnimationInfo> >(ini);

            foreach (KeyValuePair <string, AnimationInfo> anim in result)
            {
                /*if (anim.Value.MappingsGame == EngineVersion.Invalid)
                 *      anim.Value.MappingsGame = anim.Value.Game;
                 * if (anim.Value.DPLCGame == EngineVersion.Invalid)
                 *      anim.Value.DPLCGame = anim.Value.Game;
                 * if (anim.Value.MappingsFormat == MappingsFormat.Invalid)
                 *      anim.Value.MappingsFormat = MappingsFormat.Binary;
                 * if (anim.Value.DPLCFormat == MappingsFormat.Invalid)
                 *      anim.Value.DPLCFormat = MappingsFormat.Binary;
                 * if (anim.Value.AnimationFormat == MappingsFormat.Invalid)
                 *      anim.Value.AnimationFormat = MappingsFormat.Binary;*/
                Dictionary <string, string> inisection = ini[anim.Key];
                List <byte> frmspd = new List <byte>();
                Dictionary <string, int> frmspr = new Dictionary <string, int>();
                anim.Value.SprList = new List <SpriteInfo[]>();
                for (int i = 0; i < anim.Value.Frames.Length; i++)
                {
                    string sprName = anim.Value.Frames[i].Sprite;
                    if (anim.Value.Frames[i].Speed >= 0xF0)
                    {
                        frmspd.Add(0);
                        frmspd.Add(anim.Value.Frames[i].Speed);
                        break;
                    }

                    if (!frmspr.ContainsKey(sprName))
                    {
                        frmspr[sprName] = anim.Value.SprList.Count;

                        string[]     vals    = inisection[sprName].Split('|');
                        SpriteInfo[] sprinfs = new SpriteInfo[vals.Length];
                        for (int j = 0; j < vals.Length; j++)
                        {
                            sprinfs[j] = new SpriteInfo(vals[j]);
                        }
                        anim.Value.SprList.Add(sprinfs);
                    }
                    frmspd.Add((byte)frmspr[sprName]);
                    frmspd.Add((byte)(anim.Value.Frames[i].Speed * 2));
                }
                anim.Value.Animation = new Animation(frmspd.ToArray(), 0, anim.Key + "_Load");
            }
            return(result);
        }
Пример #14
0
 private void importToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog a = new OpenFileDialog()
     {
         DefaultExt = "txt",
         Filter = "Font data|fontdata.txt|All Files|*.*",
         Multiselect = false
     })
     {
         if (a.ShowDialog(this) == DialogResult.OK)
         {
             FontINI ini = new FontINI();
             ini   = IniSerializer.Deserialize <FontINI>(a.FileName);
             files = new List <FontItem>();
             listBox1.Items.Clear();
             listBox1.BeginUpdate();
             for (int i = 0; i < (ini.chars.Count) / 256 + Math.Min(1 * (ini.chars.Count) % 256, 1); i++)
             {
                 if (!File.Exists(Path.GetDirectoryName(a.FileName) + "\\fontsheet" + i.ToString() + ".png"))
                 {
                     break;
                 }
                 Bitmap sheetbmp = new Bitmap(Image.FromFile(Path.GetDirectoryName(a.FileName) + "\\fontsheet" + i.ToString() + ".png"));
                 for (int u = 0; u < 256; u++)
                 {
                     if (i * 256 + u >= ini.chars.Count)
                     {
                         break;
                     }
                     FontItem item    = new FontItem();
                     Bitmap   charbmp = new Bitmap(24, 24);
                     using (var canvas = Graphics.FromImage(charbmp))
                     {
                         Text = "Importing character " + u.ToString() + " of " + ini.chars.Count.ToString();
                         canvas.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                         canvas.DrawImage(sheetbmp, new Rectangle(0, 0, 24, 24), new Rectangle((u % 16) * 24, (u / 16) * 24, 24, 24), GraphicsUnit.Pixel);
                         canvas.Save();
                         item.bits      = new BitmapBits(charbmp.Clone(new Rectangle(0, 0, 24, 24), PixelFormat.Format1bppIndexed));
                         item.ID        = ushort.Parse(ini.chars[i * 256 + u].id, System.Globalization.NumberStyles.HexNumber);
                         item.miscdata  = StrToByteArray(ini.chars[i * 256 + u].md);
                         item.character = ini.chars[i * 256 + u].ch;
                         files.Add(item);
                     }
                 }
             }
             for (int z = 0; z < files.Count; z++)
             {
                 listBox1.Items.Add(files[z].ID.ToString("X4") + ' ' + files[z].character);
             }
             listBox1.EndUpdate();
             listBox1.SelectedIndex = 0;
             Text = "SADXFontEdit - " + a.FileName + " / Total characters: " + files.Count.ToString();
             extractAllToolStripMenuItem.Enabled = saveAsToolStripMenuItem.Enabled = exportIndividualCharactersToolStripMenuItem.Enabled = true;
         }
     }
 }
Пример #15
0
        private List <string> FindRelevantINIFiles(string file, Templates.SplitTemplate splitTemplate)
        {
            bool          dllmode     = false;
            string        extension   = Path.GetExtension(file).ToLowerInvariant();
            List <string> relevantini = new List <string>();

            if (extension == ".dll")
            {
                if (file.ToLowerInvariant().Contains("_orig"))
                {
                    file = file.ToLowerInvariant().Replace("_orig", "");
                }
                dllmode = true;
            }
            else if (extension == ".nb")
            {
                return(relevantini);
            }
            Console.WriteLine("Finding relevant split INI files for {0} in {1}", Path.GetFileName(file), splitTemplate.GameInfo.DataFolder);
            foreach (Templates.SplitEntry entry in splitTemplate.SplitEntries)
            {
                if ((Path.GetFileName(entry.SourceFile).ToLowerInvariant() == Path.GetFileName(file).ToLowerInvariant()) || (Path.GetFileName(entry.SourceFile).ToLowerInvariant() == Path.GetFileName(Path.ChangeExtension(file, ".prs")).ToLowerInvariant()))
                {
                    string inifilename = Path.Combine(templateFolder, splitTemplate.GameInfo.DataFolder, entry.IniFile + ".ini");
                    if (dllmode)
                    {
                        SplitTools.SplitDLL.IniDataSplitDLL inifile = IniSerializer.Deserialize <SplitTools.SplitDLL.IniDataSplitDLL>(inifilename);
                        if (inifile.ModuleName != null)
                        {
                            relevantini.Add(Path.GetFullPath(inifilename));
                            Console.WriteLine("Found split file {0}", inifilename);
                        }
                    }
                    else
                    {
                        string             filewithoutprs = Path.ChangeExtension(file, ".bin");
                        SplitTools.IniData inifile        = IniSerializer.Deserialize <SplitTools.IniData>(inifilename);
                        if (inifile.DataFilename != null && (inifile.DataFilename.ToLowerInvariant() == Path.GetFileName(file).ToLowerInvariant() || inifile.DataFilename.ToLowerInvariant() == Path.GetFileName(filewithoutprs).ToLowerInvariant()))
                        {
                            relevantini.Add(Path.GetFullPath(inifilename));
                            Console.WriteLine("Found split file {0}", inifilename);
                        }
                        else if (inifile.DataFilename != null)
                        {
                            Console.WriteLine("Datafilename: {0}", inifile.DataFilename);
                        }
                        else
                        {
                            Console.WriteLine("Datafilename in {0} is null", inifilename);
                        }
                    }
                }
            }
            return(relevantini);
        }
Пример #16
0
        private List <string> FindRelevantINIFiles(string file, string inilocation)
        {
            bool          dllmode     = false;
            string        extension   = Path.GetExtension(file).ToLowerInvariant();
            List <string> relevantini = new List <string>();

            if (extension == ".dll")
            {
                dllmode = true;
            }
            else if (extension == ".nb")
            {
                return(relevantini);
            }
            if (findAll)
            {
                Console.WriteLine("Finding relevant split INI files for {0} in {1}", Path.GetFileName(file), inilocation);
                string[] inifiles = System.IO.Directory.GetFiles(inilocation, "*.ini", SearchOption.AllDirectories);
                for (int u = 0; u < inifiles.Length; u++)
                {
                    if (inifiles[u].ToLowerInvariant().Contains("_data") || inifiles[u].ToLowerInvariant().Contains("output"))
                    {
                        continue;
                    }
                    if (dllmode)
                    {
                        SA_Tools.SplitDLL.IniData inifile = IniSerializer.Deserialize <SA_Tools.SplitDLL.IniData>(inifiles[u]);
                        if (inifile.ModuleName != null && inifile.ModuleName.ToLowerInvariant() == Path.GetFileNameWithoutExtension(file).ToLowerInvariant())
                        {
                            relevantini.Add(Path.GetFullPath(inifiles[u]));
                            Console.WriteLine("Found split file {0}", inifiles[u]);
                        }
                    }
                    else
                    {
                        SA_Tools.IniData inifile = IniSerializer.Deserialize <SA_Tools.IniData>(inifiles[u]);
                        if (inifile.DataFilename != null && inifile.DataFilename.ToLowerInvariant() == Path.GetFileName(file).ToLowerInvariant())
                        {
                            relevantini.Add(Path.GetFullPath(inifiles[u]));
                            Console.WriteLine("Found split file {0}", inifiles[u]);
                        }
                        else if (inifile.DataFilename != null)
                        {
                            Console.WriteLine("Datafilename: {0}", inifile.DataFilename);
                        }
                        else
                        {
                            Console.WriteLine("Datafilename in {0} is null", inifiles[u]);
                        }
                    }
                }
            }
            return(relevantini);
        }
Пример #17
0
        public static void BuildNBFile(string filename, string dest, int verbose = 0)
        {
            // Needs update to use filenames from an INI file
            Dictionary <int, string> sectionlist = IniSerializer.Deserialize <Dictionary <int, string> >(filename);
            List <byte> result = new List <byte>();

            result.AddRange(BitConverter.GetBytes(0x04424A4E));
            int numfiles = sectionlist.Count;

            result.AddRange(BitConverter.GetBytes(numfiles));
            foreach (var item in sectionlist)
            {
                string insidepath = Path.Combine(Environment.CurrentDirectory, Path.GetFileNameWithoutExtension(filename), item.Key.ToString("D2"));
                byte[] writeout;
                // Convert models and motions to BIN
                if (item.Value != "NULL")
                {
                    switch (Path.GetExtension(item.Value).ToLowerInvariant())
                    {
                    case ".sa1mdl":
                        ModelFile mdlfile = new ModelFile(insidepath + ".sa1mdl");
                        writeout = GetSections(mdlfile.Model);
                        result.AddRange(BitConverter.GetBytes((ushort)1));
                        result.AddRange(BitConverter.GetBytes((ushort)0xCDCD));
                        result.AddRange(BitConverter.GetBytes((uint)writeout.Length));
                        result.AddRange(writeout);
                        File.WriteAllBytes(insidepath + ".bin", writeout);
                        break;

                    case ".saanim":
                        NJS_MOTION mot = NJS_MOTION.Load(insidepath + ".saanim");
                        if (verbose > 1)
                        {
                            Console.WriteLine("Section {0}", item.Key);
                        }
                        writeout = GetSections(mot, verbose);
                        result.AddRange(BitConverter.GetBytes((ushort)3));
                        result.AddRange(BitConverter.GetBytes((ushort)0xCDCD));
                        result.AddRange(BitConverter.GetBytes((uint)writeout.Length));
                        result.AddRange(writeout);
                        File.WriteAllBytes(insidepath + ".bin", writeout);
                        break;
                    }
                }
                else
                {
                    result.AddRange(BitConverter.GetBytes((ushort)0));
                    result.AddRange(BitConverter.GetBytes((ushort)0xCDCD));
                    result.AddRange(BitConverter.GetBytes((uint)0));
                }
                //Build the NB file
                File.WriteAllBytes(dest, result.ToArray());
            }
        }
Пример #18
0
        /// <summary>
        /// Gets the path for a specified game from GamePaths.ini.
        /// </summary>
        /// <returns>Path string</returns>
        public static string GetGamePath(string gameName)
        {
            string gamePathsFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SA Tools", "GamePaths.ini");

            if (!File.Exists(gamePathsFile))
            {
                return("");
            }
            Dictionary <string, string> gamePathsList = IniSerializer.Deserialize <Dictionary <string, string> >(gamePathsFile);

            return(gamePathsList.ContainsKey(gameName) ? gamePathsList[gameName] : "");
        }
Пример #19
0
            public static Settings_SA2EventViewer Load()
            {
                string path = GetSettingsPath();

                if (File.Exists(path))
                {
                    return(IniSerializer.Deserialize <Settings_SA2EventViewer>(path));
                }
                else
                {
                    return(new Settings_SA2EventViewer());
                }
            }
Пример #20
0
            public static Settings_SA2MessageFileEditor Load()
            {
                string path = GetSettingsPath();

                if (File.Exists(path))
                {
                    return(IniSerializer.Deserialize <Settings_SA2MessageFileEditor>(path));
                }
                else
                {
                    return(new Settings_SA2MessageFileEditor());
                }
            }
Пример #21
0
        public static GameInfo Load(string filename)
        {
            Dictionary <string, Dictionary <string, string> > ini = IniFile.Load(filename);
            string userfile = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename) + ".user" + Path.GetExtension(filename));

            if (File.Exists(userfile))
            {
                ini = IniFile.Combine(ini, IniFile.Load(userfile));
            }
            GameInfo result = IniSerializer.Deserialize <GameInfo>(ini);

            return(result);
        }
Пример #22
0
        public static ProjectFile Load(string filename)
        {
            ProjectFile result = IniSerializer.Deserialize <ProjectFile>(filename);

            if (result.MappingsGame == EngineVersion.Invalid)
            {
                result.MappingsGame = result.Game;
            }
            if (result.DPLCGame == EngineVersion.Invalid)
            {
                result.DPLCGame = result.MappingsGame;
            }
            return(result);
        }
Пример #23
0
 private void LoadINI(string filename)
 {
     CloseChildWindows();
     Program.IniData = IniSerializer.Deserialize <IniData>(filename);
     windowToolStripMenuItem.Enabled = true;
     if (Settings.MRUList.Contains(filename))
     {
         recentProjectsToolStripMenuItem.DropDownItems.RemoveAt(Settings.MRUList.IndexOf(filename));
         Settings.MRUList.Remove(filename);
     }
     Settings.MRUList.Insert(0, filename);
     recentProjectsToolStripMenuItem.DropDownItems.Insert(0, new ToolStripMenuItem(filename));
     Environment.CurrentDirectory = Path.GetDirectoryName(filename);
 }
Пример #24
0
        // Loads a split INI file and a list of filenames and replaces INI filenames for models and animations with the names specified in the list
        static void SplitRF(string[] args)
        {
            string  inifilename  = args[0];
            string  listfilename = args[1];
            IniData inifile      = IniSerializer.Deserialize <IniData>(inifilename);

            string[] list = File.ReadAllLines(listfilename);
            int      n    = 0;
            Dictionary <int, string> filenames = new Dictionary <int, string>();
            Dictionary <string, SA_Tools.FileInfo> fileinfo_new = new Dictionary <string, SA_Tools.FileInfo>();

            foreach (KeyValuePair <string, SA_Tools.FileInfo> fileinfo in inifile.Files)
            {
                if (list.Length <= n)
                {
                    Console.WriteLine("Item outside of bounds!");
                    continue;
                }
                if (!((list[n].Length >= 6 && list[n].Substring(0, 6) == "DELETE")))
                {
                    Console.WriteLine("{0}", list[n]);
                    fileinfo.Value.Filename = list[n];
                    filenames.Add(fileinfo.Value.Address, list[n]);
                    fileinfo_new.Add(fileinfo.Value.Address.ToString("X8"), fileinfo.Value);
                }
                else
                {
                    Console.WriteLine("Deleted: {0}", fileinfo.Value.Filename);
                }
                n++;
            }
            // Relink animations
            foreach (KeyValuePair <string, SA_Tools.FileInfo> fileinfo in inifile.Files)
            {
                if (fileinfo.Value.CustomProperties.ContainsKey("animations"))
                {
                    string[] anims = fileinfo.Value.CustomProperties["animations"].Split(',');
                    for (int a = 0; a < anims.Length; a++)
                    {
                        string newfilename           = filenames[int.Parse(Path.GetFileNameWithoutExtension(anims[a]), System.Globalization.NumberStyles.AllowHexSpecifier)];
                        System.Text.StringBuilder sb = new System.Text.StringBuilder(1024);
                        PathRelativePathTo(sb, Path.GetFullPath(fileinfo.Value.Filename), 0, Path.GetFullPath(newfilename), 0);
                        anims[a] = sb.ToString();
                    }
                    fileinfo.Value.CustomProperties["animations"] = string.Join(",", anims);
                }
            }
            inifile.Files = fileinfo_new;
            IniSerializer.Serialize(inifile, Path.GetFileNameWithoutExtension(inifilename) + "_replaced.ini");
        }
Пример #25
0
 private void openToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog fd = new OpenFileDialog()
     {
         DefaultExt = "ini", Filter = "INI Files|*.ini"
     })
         if (fd.ShowDialog(this) == DialogResult.OK)
         {
             IniData ini = IniSerializer.Deserialize <IniData>(fd.FileName);
             filename = Path.Combine(Path.GetDirectoryName(fd.FileName),
                                     ini.Files.First((item) => item.Value.Type == "stageselectlist").Value.Filename);
             levels = new List <StageSelectLevel>(StageSelectLevelList.Load(filename));
             string resdir = Path.Combine(Path.GetDirectoryName(fd.FileName), ini.SystemFolder);
             using (Device d3ddevice = new Device(0, DeviceType.Hardware, dummyPanel.Handle, CreateFlags.SoftwareVertexProcessing, new PresentParameters[] { new PresentParameters()
                                                                                                                                                             {
                                                                                                                                                                 Windowed = true, SwapEffect = SwapEffect.Discard, EnableAutoDepthStencil = true, AutoDepthStencilFormat = DepthFormat.D24X8
                                                                                                                                                             } }))
             {
                 using (Stream str = new MemoryStream(
                            new PAKFile(Path.Combine(resdir, @"SOC\stageMapBG.pak")).Files.Find(
                                (a) => a.Name.Equals(@"stagemapbg\stagemap.dds")).Data))
                     bgtex = LoadDDS(str, d3ddevice);
                 if (File.Exists(Path.Combine(resdir, @"PRS\stageMap.pak")))
                 {
                     List <PAKFile.File> files = new PAKFile(Path.Combine(resdir, @"PRS\stageMap.pak")).Files;
                     byte[] inf = files.Find((a) => a.Name.Equals(@"stagemap\stagemap.inf")).Data;
                     uitexs = new Bitmap[inf.Length / 0x3C];
                     for (int i = 0; i < uitexs.Length; i++)
                     {
                         using (Stream str = new MemoryStream(files.Find(
                                                                  (a) => a.Name.Equals(@"stagemap\" + Encoding.ASCII.GetString(inf, i * 0x3C, 0x1c).TrimEnd('\0') + ".dds")).Data))
                             uitexs[i] = LoadDDS(str, d3ddevice);
                     }
                 }
                 else
                 {
                     uitexs = TextureArchive.GetTextures(Path.Combine(resdir, "stageMap.prs")).Select((tex) => tex.Image).ToArray();
                 }
             }
             saveToolStripMenuItem.Enabled = panel1.Enabled = panel2.Enabled = true;
             selected                = 0;
             level.SelectedIndex     = (int)levels[selected].Level;
             character.SelectedIndex = (int)levels[selected].Character;
             column.Value            = levels[selected].Column;
             row.Value               = levels[selected].Row;
             DrawLevel();
         }
 }
Пример #26
0
        public static ProjectManagerSettings Load(string iniPath)
        {
            if (File.Exists(iniPath))
            {
                return((ProjectManagerSettings)IniSerializer.Deserialize(typeof(ProjectManagerSettings), iniPath));
            }
            else
            {
                ProjectManagerSettings result = new ProjectManagerSettings()
                {
                    SA2PCPath  = "",
                    SADXPCPath = ""
                };

                return(result);
            }
        }
Пример #27
0
        public static DllIniData LoadINI(string fileName,
                                         ref Dictionary <string, bool> defaultExportState)
        {
            defaultExportState.Clear();

            DllIniData IniData = IniSerializer.Deserialize <DllIniData>(fileName);

            Environment.CurrentDirectory = Path.GetDirectoryName(fileName);

            foreach (KeyValuePair <string, FileTypeHash> item in IniData.Files)
            {
                bool modified = HelperFunctions.FileHash(item.Key) != item.Value.Hash;
                defaultExportState.Add(item.Key, modified);
            }

            return(IniData);
        }
Пример #28
0
        /// <summary>
        /// Create a PAK archive from a folder produced by ArchiveTool or PAKTool.
        /// </summary>
        static void BuildPAK(string[] args)
        {
            filePath = args[1];
            Console.WriteLine("Building PAK from folder: {0}", Path.GetFullPath(filePath));
            outputPath = Path.Combine(Environment.CurrentDirectory, filePath);
            Environment.CurrentDirectory = Path.GetDirectoryName(outputPath);
            Dictionary <string, PAKFile.PAKIniItem> list = IniSerializer.Deserialize <Dictionary <string, PAKFile.PAKIniItem> >(Path.Combine(Path.GetFileNameWithoutExtension(outputPath), Path.GetFileNameWithoutExtension(outputPath) + ".ini"));
            PAKFile pak = new PAKFile();

            foreach (KeyValuePair <string, PAKFile.PAKIniItem> item in list)
            {
                Console.WriteLine("Adding file: {0}", item.Key);
                pak.Entries.Add(new PAKFile.PAKEntry(item.Key, item.Value.LongPath, File.ReadAllBytes(item.Key)));
            }
            Console.WriteLine("Output file: {0}", Path.ChangeExtension(outputPath, "pak"));
            pak.Save(Path.ChangeExtension(outputPath, "pak"));
        }
Пример #29
0
        public static ProjectSettings Load(string iniPath)
        {
            if (File.Exists(iniPath))
            {
                return((ProjectSettings)IniSerializer.Deserialize(typeof(ProjectSettings), iniPath));
            }
            else
            {
                ProjectSettings result = new ProjectSettings()
                {
                    AutoUpdate      = false,
                    UpdateFrequency = Frequency.monthly,
                    HubTheme        = Themes.light,
                };

                return(result);
            }
        }
Пример #30
0
        public static SAToolsHubSettings Load(string iniPath)
        {
            if (File.Exists(iniPath))
            {
                return((SAToolsHubSettings)IniSerializer.Deserialize(typeof(SAToolsHubSettings), iniPath));
            }
            else
            {
                SAToolsHubSettings result = new SAToolsHubSettings()
                {
                    UpdateCheck = false,
                    UpdateUnit  = UpdateUnits.Weeks,
                    HubTheme    = Themes.light,
                };

                return(result);
            }
        }