Beispiel #1
0
        /// <summary>
        /// Resizes doggos to the given facttor
        /// </summary>
        /// <param name="Factor">Resize factor (1.0=Original)</param>
        /// <param name="Offset">Z-Offset of doggo</param>
        /// <remarks>Making doggos larger requires you to move them up</remarks>
        private void ResizeDoggos(float Factor, int Offset)
        {
            var Doggos = F.Entries.Where(m => m.ObjectData.Name == "");

            InfoChange(SaveFileHelper.ItemResizer(Doggos, Factor, Offset), "doggos");
            FeatureReport.Used(FeatureReport.Feature.QuickAction);
        }
Beispiel #2
0
        /// <summary>
        /// Shows help for the current form
        /// </summary>
        /// <param name="FormName">Name of the form that requested the help</param>
        public static void ShowHelp(string FormName)
        {
            Log.Write("Requesting help for {0}", FormName);
            var F = GetForm <frmHelp>();

            //Show new form if not already there
            if (F == null)
            {
                F = new frmHelp();
                F.Show();
            }
            else
            {
                //Bring existing content to the front
                F.BringToFront();
                F.Focus();
            }

            string HelpText = ToString(GetResource("SatisfactorySaveEditor.Help._no.txt"));

            try
            {
                F.HelpText = ToString(GetResource($"SatisfactorySaveEditor.Help.{FormName}.txt"));
            }
            catch
            {
                F.HelpText = string.Format(HelpText, $"SatisfactorySaveEditor.Help.{FormName}.txt");
            }
            FeatureReport.Used(FeatureReport.Feature.HelpRequest);
        }
        private void btnExport_Click(object sender, EventArgs e)
        {
            var ItemName = ((ShortName)cbItem.SelectedItem).Long;
            var Items    = F.Entries.Where(m => m.ObjectData.Name == ItemName);

            //Filter if needed
            if (rbRange.Checked)
            {
                Items = Items.Skip((int)nudStart.Value - 1).Take((int)nudCount.Value);
            }
            if (Items.Count() > 0)
            {
                var Ser = new XmlSerializer(typeof(SaveFileEntry[]));
                Clipboard.Clear();
                using (var SW = new StringWriter())
                {
                    Ser.Serialize(SW, Items.ToArray());
                    Clipboard.SetText(SW.ToString());
                    FeatureReport.Used(FeatureReport.Feature.XmlExport);
                    MessageBox.Show(
                        $"{Items.Count()} entr{(Items.Count() == 1 ? "y" : "ies")} Exported to clipboard",
                        "Export", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                Log.Write("{0}: Exported {1} items", GetType().Name, Items.Count());
            }
        }
Beispiel #4
0
 private void extractAudioToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (QuickPlay.HasQuickPlay)
     {
         //Allow only one extractor to run but don't make it a modal window
         var f = Tools.GetForm <frmAudioExtract>();
         if (f == null)
         {
             f = new frmAudioExtract();
             f.Show();
             FeatureReport.Used(FeatureReport.Feature.ExtractAudio);
         }
         else
         {
             f.Show();
             f.BringToFront();
             f.Focus();
         }
     }
     else
     {
         extractAudioToolStripMenuItem.Enabled = false;
         var T = new Thread(delegate()
         {
             QuickPlay.ResetQuickPlay();
             QuickPlay.CheckQuickPlay();
         });
         T.IsBackground = true;
         T.Start();
     }
 }
Beispiel #5
0
        /// <summary>
        /// Opens the given save file and sets initial values for variables
        /// </summary>
        /// <param name="SaveFileName">Save file full name and path</param>
        public void OpenFile(string SaveFileName)
        {
            Log.Write("{0}: Loading {1}", GetType().Name, SaveFileName);
            try
            {
                using (var FS = File.OpenRead(SaveFileName))
                {
                    F = SaveFile.Open(FS);
                    if (F == null)
                    {
                        throw new InvalidDataException("We are unable to load your save file. It looks invalid.");
                    }
                    FileName    = SaveFileName;
                    HasChange   = false;
                    NameChanged = false;
                    SetTitle();
                    if (S.ShowLimited)
                    {
                        S.ShowLimited = false;
                        MessageBox.Show(@"This is still in development and functionality is limited.
If something breaks, please open an issue on GitHub so we can fix it.", "Limited Functionality", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    RedrawMap();
                    FeatureReport.Used(FeatureReport.Feature.OpenFile);
                    Log.Write("{0}: File loaded. {1} entries total", GetType().Name, F.Entries.Count);
                }
            }
            catch (Exception ex)
            {
                Log.Write(new Exception("Unable to load the save file. File probably in use or broken.", ex));
                Tools.E($"Unable to load the specified file\r\n{ex.Message}", "File read error");
            }
        }
Beispiel #6
0
        private void rangeDeleterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (F != null)
            {
                if (S.ShowRangeDeleterHint)
                {
                    MessageBox.Show(@"The range deleter can be a bit difficult to use.
By default it only selects player built structures except the HUB components.
Be careful when adding additional entries.

Remember, you can press [F1] on any window to get detailed help.", "Range Deleter", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    S.ShowRangeDeleterHint = false;
                }
                using (var Region = new frmRegionDeleter(F))
                {
                    if (Region.ShowDialog() == DialogResult.OK)
                    {
                        HasChange = true;
                        RedrawMap();
                        SetTitle();
                        FeatureReport.Used(FeatureReport.Feature.DeleteByArea);
                    }
                }
            }
        }
Beispiel #7
0
 /// <summary>
 /// Shows the save file manager form
 /// </summary>
 private void ShowManagerForm()
 {
     using (var manager = new frmManager(S))
     {
         FeatureReport.Used(FeatureReport.Feature.Manager);
         manager.ShowDialog();
     }
 }
Beispiel #8
0
 private void restoreBerriesToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (F != null)
     {
         InfoChange(SaveFileHelper.RestoreBerries(F), "berries, nuts and mushrooms");
         FeatureReport.Used(FeatureReport.Feature.QuickAction);
     }
 }
Beispiel #9
0
 private void removeAnimalPartsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (F != null)
     {
         InfoChange(SaveFileHelper.RemoveAnimalParts(F), "animal parts (organs, etc)");
         FeatureReport.Used(FeatureReport.Feature.QuickAction);
     }
 }
Beispiel #10
0
 private void restorePlantsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (F != null)
     {
         InfoChange(SaveFileHelper.RestorePlants(F), "plants and trees");
         FeatureReport.Used(FeatureReport.Feature.QuickAction);
     }
 }
Beispiel #11
0
 private void removeLizardDoggosToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (F != null && MessageBox.Show("You're about to make a big mistake. Delete the space rabits?", "Abandon Doggos", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
     {
         InfoChange(SaveFileHelper.RemoveLizardDoggos(F), "Doggos");
         FeatureReport.Used(FeatureReport.Feature.QuickAction);
     }
 }
Beispiel #12
0
 private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (var frmS = new frmSettings(S))
     {
         frmS.ShowDialog();
         HandleSettingsChange();
         FeatureReport.Used(FeatureReport.Feature.ChangeSettings);
     }
 }
Beispiel #13
0
 private void spawnerToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (F != null)
     {
         if (MessageBox.Show(@"Removes all spawner entries. This does not removed spawned animals", "Animal spawner", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
         {
             InfoChange(SaveFileHelper.RemoveCreatureSpawner(F), "spawner");
             FeatureReport.Used(FeatureReport.Feature.QuickAction);
         }
     }
 }
Beispiel #14
0
 private void itemCounterToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (F != null)
     {
         using (var Counter = new frmCounter(F.Entries))
         {
             Counter.ShowDialog();
             FeatureReport.Used(FeatureReport.Feature.CountItems);
         }
     }
 }
Beispiel #15
0
 private void evilToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (F != null)
     {
         if (MessageBox.Show(@"Remove animals that are hostile to the player?", "Hostile Animals", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
         {
             InfoChange(SaveFileHelper.RemoveEvilCreatures(F), "animals");
             FeatureReport.Used(FeatureReport.Feature.QuickAction);
         }
     }
 }
Beispiel #16
0
 private void restoreSlugsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (F != null)
     {
         if (MessageBox.Show(@"Restore all slugs?", "Restors Slugs", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
         {
             InfoChange(SaveFileHelper.RestoreSlugs(F), "slugs");
             FeatureReport.Used(FeatureReport.Feature.QuickAction);
         }
     }
 }
Beispiel #17
0
 private void niceToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (F != null)
     {
         if (MessageBox.Show(@"Remove animals that generally are friendly to the player (excluding doggos)?", "Friendly Animals", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
         {
             InfoChange(SaveFileHelper.RemoveNiceCreatures(F), "animals");
             FeatureReport.Used(FeatureReport.Feature.QuickAction);
         }
     }
 }
Beispiel #18
0
        private void restorePickupsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (F != null)
            {
                if (MessageBox.Show(@"This only restores the items around drop pods and not the hard drives.
Really continue?", "Surplus drives", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                {
                    InfoChange(SaveFileHelper.RestorePickups(F), "items");
                    FeatureReport.Used(FeatureReport.Feature.QuickAction);
                }
            }
        }
Beispiel #19
0
        private void resetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (F != null)
            {
                if (MessageBox.Show(@"This resets all drop pods to their initial state.
This means you can recover harddrives from them again.
You will likely end up with more drives than there are recipes in the game.
To just restore the collectable items around them, use the 'Restore Pickups' option instead.
Really continue?", "Surplus drives", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                {
                    InfoChange(SaveFileHelper.RestoreDropPods(F), "drop pods");
                    FeatureReport.Used(FeatureReport.Feature.QuickAction);
                }
            }
        }
Beispiel #20
0
 private void btnClose_Click(object sender, EventArgs e)
 {
     //Disregard user random Id setting if reports are disabled
     CurrentSettings.UseRandomId = cbRandom.Checked && !cbStopReporting.Checked;
     //User disabled reports
     if (!CurrentSettings.DisableUsageReport && cbStopReporting.Checked)
     {
         FeatureReport.Used(FeatureReport.Feature.DisableReport);
         FeatureReport.Report();
         CurrentSettings.ReportId = FeatureReport.Id = Guid.Empty;
     }
     else if (CurrentSettings.ReportId == Guid.Empty && !cbStopReporting.Checked)
     {
         //Generate a new Id if reports are enabled and no Id is present
         CurrentSettings.ReportId = FeatureReport.Id = Guid.NewGuid();
     }
     Close();
 }
Beispiel #21
0
 private void editHeaderToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (F != null)
     {
         using (var FH = new frmHeaderEditor(F))
         {
             if (FH.ShowDialog() == DialogResult.OK)
             {
                 NameChanged |= (F.SessionName != FH.SessionName);
                 F.SetSessionName(FH.SessionName);
                 F.PlayTime = TimeSpan.Parse(FH.PlayTime);
                 HasChange  = true;
                 SetTitle();
                 FeatureReport.Used(FeatureReport.Feature.EditHeader);
             }
         }
     }
 }
Beispiel #22
0
        /// <summary>
        /// Disables image rendering and dependents of rendered images
        /// </summary>
        private void DisableImageRendering()
        {
            if (InvokeRequired)
            {
                Invoke((MethodInvoker)DisableImageRendering);
            }
            else
            {
                if (RenderImage)
                {
                    FeatureReport.Used(FeatureReport.Feature.RendererCrash);
                    RenderImage = false;
                    resetRendererToolStripMenuItem.Visible = true;
                    Tools.E(@"Map image rendering has been temporarily disabled due to an error.
This is usually the result of memory constraints.
Images are generated again once you restart the application or use the 'Reset Renderer' menu option in 'Settings'.", "Map Image");
                }
            }
        }
Beispiel #23
0
 private void clearStringListToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (F != null)
     {
         if (F.StringList.Count > 0)
         {
             if (MessageBox.Show("Really clear the list of items/objects you picked up and/or destroyed?", "Clear String List", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
             {
                 int C = F.StringList.Count;
                 F.StringList.Clear();
                 InfoChange(C, "String list");
                 FeatureReport.Used(FeatureReport.Feature.ClearStringList);
             }
         }
         else
         {
             InfoChange(0, "String list");
         }
     }
 }
Beispiel #24
0
        private void deleterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (F != null)
            {
                if (S.ShowDeletionHint)
                {
                    MessageBox.Show(@"Deletion is dangerous.
- The object deleter will not validate your choices (you can delete the HUB)
- The object deleter will not handle dependencies. Example: Deleting containers leaves stray inventory entries behind in the save file.", "Deleter", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    S.ShowDeletionHint = false;
                }
                using (var Deleter = new frmDeleter(F))
                {
                    if (Deleter.ShowDialog() == DialogResult.OK)
                    {
                        HasChange = true;
                        SetTitle();
                        FeatureReport.Used(FeatureReport.Feature.DeleteByType);
                    }
                }
            }
        }
Beispiel #25
0
        private void duplicatorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (F != null)
            {
                if (S.ShowDuplicationHint)
                {
                    MessageBox.Show(@"Duplication is dangerous. The duplicator will not check if duplication makes sense at all.
Some objects will show weird behaviour once duplicated.
Container duplicates for example will share the inventory.", "Duplicator", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    S.ShowDuplicationHint = false;
                }
                using (var Cloner = new frmDuplicator(F))
                {
                    if (Cloner.ShowDialog() == DialogResult.OK)
                    {
                        HasChange = true;
                        SetTitle();
                        FeatureReport.Used(FeatureReport.Feature.DuplicateItems);
                    }
                }
            }
        }
Beispiel #26
0
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (F != null)
            {
                if (NameChanged || MessageBox.Show(@"It's recommended that you change the session name to avoid confusion.
It's totally fine to not change it but different session names makes it easier to tell them apart.

Proceed WITHOUT changing it?", "Session Name Change recommended", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    if (SFD.ShowDialog() == DialogResult.OK)
                    {
                        using (var FS = File.Create(SFD.FileName))
                        {
                            F.Export(FS);
                        }
                        FileName  = SFD.FileName;
                        HasChange = false;
                        SetTitle();
                        FeatureReport.Used(FeatureReport.Feature.SaveFile);
                    }
                }
            }
        }
Beispiel #27
0
        private void backupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var Node = GetSelectedFile();

            if (Node != null)
            {
                SFD.FileName         = Node.Text + ".sav.gz";
                SFD.InitialDirectory = Path.GetDirectoryName(((LocalFileView)Node.Tag).FullFile);

                if (SFD.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        double Perc = 0;
                        using (var IN = File.OpenRead(GetName(Node)))
                        {
                            Perc = IN.Length;
                            using (var FS = File.Create(SFD.FileName))
                            {
                                using (var OUT = new GZipStream(FS, CompressionLevel.Optimal, true))
                                {
                                    IN.CopyTo(OUT);
                                }
                                Perc = FS.Position / Perc * 100;
                            }
                        }
                        FeatureReport.Used(FeatureReport.Feature.DoBackup);
                        MessageBox.Show($"Backup complete. Reduced to {Math.Round(Perc)}% of original size", "Backup", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        Log.Write(new Exception("Unable to perform a backup", ex));
                        Tools.E($"Unable to back up your savegame\r\n{ex.Message}", "Backup Error");
                    }
                }
            }
        }
Beispiel #28
0
        /// <summary>
        /// Saves the current file
        /// </summary>
        /// <remarks>This also handles creating backups and resetting the <see cref="HasChange"/> value</remarks>
        private void SaveCurrent()
        {
            var Backup = Path.ChangeExtension(FileName, ".sav.gz");

            if (!File.Exists(Backup))
            {
                if (Compression.CompressFile(FileName, Backup))
                {
                    Log.Write("{0}: Created backup file {1}", GetType().Name, Backup);
                    MessageBox.Show($"Because this is your first time overwriting this file, a backup ({Path.GetFileName(Backup)}) has been created in the same directory.", "Backup created", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    if (MessageBox.Show($"Unable to create a backup. You can try using the Save file manager to manually create one. Still continue to save the file?", "Backup failed", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.No)
                    {
                        Log.Write("{0}: Unable to create backup. User exit", GetType().Name);
                        return;
                    }
                    Log.Write("{0}: Unable to create backup. User continue", GetType().Name);
                }
            }
            try
            {
                using (var FS = File.Create(FileName))
                {
                    F.Export(FS);
                }
                HasChange = false;
                SetTitle();
                FeatureReport.Used(FeatureReport.Feature.SaveFile);
            }
            catch (Exception ex)
            {
                Log.Write(new Exception("Unable to save changes", ex));
                Tools.E($"Unable to save your file. Make sure it's not currently loaded in Satisfactory or another application.\r\n{ex.Message}", "Saving changes");
            }
        }
Beispiel #29
0
        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            FeatureReport.Used(FeatureReport.Feature.TerminateByError);
            FeatureReport.Report();
            if (e.ExceptionObject is Exception)
            {
                Log.Write("{0}: Unhandled exception", nameof(ErrorHandler));
                Log.Write((Exception)e.ExceptionObject);
            }
            else
            {
                Log.Write("{0}: Unhandled Exception: {1}", nameof(ErrorHandler), e.ExceptionObject == null ? "<no data given>" : e.ExceptionObject.ToString());
            }
            using (var f = new frmErrorHandler((Exception)e.ExceptionObject, this))
            {
                f.ShowDialog();
            }
            Log.Write("{0}: Application terminating abnormally", nameof(ErrorHandler));
            Log.Close();
            Process P = Process.GetCurrentProcess();

            P.Kill();
            P.WaitForExit();
        }
Beispiel #30
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (OFD.ShowDialog() == DialogResult.OK)
            {
                FileStream FS;
                try
                {
                    FS = File.OpenRead(OFD.FileName);
                }
                catch (Exception ex)
                {
                    Log.Write(new Exception($"Unable to import {OFD.FileName}", ex));
                    Tools.E($"Unable to open the selected file.\r\n{ex.Message}", "Import error");
                    return;
                }
                using (FS)
                {
                    var NewName = Path.GetFileName(OFD.FileName);
                    if (NewName.ToLower().Contains(".sav"))
                    {
                        //Make .sav the last part of the name
                        NewName = NewName.Substring(0, NewName.ToLower().LastIndexOf(".sav")) + ".sav";
                        if (NewName == ".sav")
                        {
                            NewName = "Import.sav";
                        }
                    }
                    else
                    {
                        //Add .sav extension because it's not there
                        NewName += ".sav";
                    }
                    //Make name unique
                    int i = 1;
                    while (File.Exists(Path.Combine(Program.SaveDirectory, NewName)))
                    {
                        NewName = NewName.Substring(0, NewName.Length - 4) + $"_{i++}.sav";
                    }

                    //Check if selected file is actually a (somewhat) valid save game
                    var F = SaveFile.Open(FS);
                    if (F == null)
                    {
                        NewName = Path.Combine(Program.SaveDirectory, NewName);
                        if (MessageBox.Show("This file doesn't looks like it's a save file. Import anyways?", "Incompatible file", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                        {
                            //User decided to copy anyway. Decompress the file now as needed
                            FS.Seek(0, SeekOrigin.Begin);
                            if (Tools.IsGzFile(FS))
                            {
                                Log.Write("{0}: looks compressed: {1}", GetType().Name, OFD.FileName);
                                try
                                {
                                    using (var GZS = new GZipStream(FS, CompressionMode.Decompress))
                                    {
                                        //Try to manually decompress a few bytes before fully copying.
                                        //This will throw an exception for files that are not decompressable before the output file is created
                                        byte[] Data = new byte[100];
                                        int    R    = GZS.Read(Data, 0, Data.Length);
                                        using (var OUT = File.Create(NewName))
                                        {
                                            OUT.Write(Data, 0, R);
                                            GZS.CopyTo(OUT);
                                        }
                                    }
                                    InitFiles();
                                    FeatureReport.Used(FeatureReport.Feature.RestoreBackup);
                                }
                                catch (Exception ex)
                                {
                                    Log.Write(new Exception($"Unable to decompress {OFD.FileName}", ex));
                                    Tools.E($"File looks compressed, but we are unable to decompress it.\r\n{ex.Message}", "Decompression error");
                                }
                            }
                            else
                            {
                                Log.Write("{0}: Importing uncompressed {1}", GetType().Name, OFD.FileName);
                                //File is not compressed. Just copy as-is
                                using (var OUT = File.Create(NewName))
                                {
                                    FS.CopyTo(OUT);
                                    InitFiles();
                                }
                            }
                        }
                    }
                    else
                    {
                        //Supply the NewName path to have a name that's not a conflict by default
                        using (var Ren = new frmRename(F.SessionName, Path.GetFileNameWithoutExtension(NewName)))
                        {
                            if (Ren.ShowDialog() == DialogResult.OK)
                            {
                                NewName = Path.Combine(Program.SaveDirectory, Ren.RenameFileName + ".sav");
                                if (!File.Exists(NewName) || MessageBox.Show($"There is already a file named {Ren.RenameFileName}.sav. Overwrite this file?", "Confirm overwrite", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                                {
                                    F.SessionName = Ren.RenameSessionName;
                                    using (var OUT = File.Create(NewName))
                                    {
                                        F.Export(OUT);
                                    }
                                    InitFiles();
                                }
                                else
                                {
                                    Log.Write("{0}: import destination exists: User cancelled", GetType().Name);
                                }
                            }
                        }
                    }
                }
            }
        }