// we use a postfix patch on RootMenuRev2.createElements to find and resize all parts of the "open game" dialogue to fit the new delete button, after that we clear out the original button container and replace them with our own buttons.
        private static void Postfix(RootMenuRev2 __instance, ref GuiElement ___popupLoad, ref ScrollCanvas ___scrollLoadCanvas, ref List <GuiElement> ___popupCanvas)
        {
            int   num3      = 300;
            Color fontColor = new Color(226, 252, 255, 210);

            ___popupLoad.width = 450;
            bool openMP2 = CONFIG.openMP; // a check if we have the multiplayer version of the game is probably redundant at this point, but it will do no harm.

            if (!openMP2)
            {
                foreach (var entry in ___popupLoad.elementList)
                {
                    if (entry.name == "load scroll")
                    {
                        entry.width = 450;
                        foreach (var entry2 in ___scrollLoadCanvas.elementList)
                        {
                            entry2.width = 436;
                        }
                    }
                    else
                    {
                        entry.elementList.Clear();
                        entry.width = 450;
                        entry.AddButton("Load", SCREEN_MANAGER.white, 2, 2, num3 / 2 - 2 - 1, 36, new BasicButton.ClickEvent(DeleteWorldSaves.MyRootMenuRev2.loadGame), SCREEN_MANAGER.FF16, fontColor);               // calling "DeleteWorldSaves.MyRootMenuRev2.loadGame" instead of RootMenuRev2.loadGame, private delegated methods have to be replaced by our own, not sure if it is posible to call and modify them with reflections, at this point this is the only solution a could think of.
                        entry.AddButton("Close", SCREEN_MANAGER.white, 2, 2, num3 / 2 - 2 - 1, 36, new BasicButton.ClickEvent(__instance.actionCloseLoad), SCREEN_MANAGER.FF16, fontColor);                            // we can use the original RootMenuRev2.actionCloseLoad method bacause it is public and can be accessed by harmony via instance of "RootMenuRev2"
                        entry.AddButton("Delete", SCREEN_MANAGER.white, 2, 2, num3 / 2 - 2 - 1, 36, new BasicButton.ClickEvent(DeleteWorldSaves.MyRootMenuRev2.deleteSave), SCREEN_MANAGER.FF16, CONFIG.textColorRed); // this is our new delete button with red text
                    }
                }
                // adding a confirmation dialogue
                ___popupCanvas.Add(new Canvas("confirm delete worldsave", SCREEN_MANAGER.white, 600, 600, 0, 0, 300, 80, SortType.vertical, new Color(14, 18, 19, 245)));
                DeleteWorldSaves.MyRootMenuRev2.popupConfirmDelete = ___popupCanvas.Last <GuiElement>();
                DeleteWorldSaves.MyRootMenuRev2.popupConfirmDelete.addLabel("Confirm delete", SCREEN_MANAGER.FF20, 70, 0, 150, 40, CONFIG.textBrightColor);
                DeleteWorldSaves.MyRootMenuRev2.popupConfirmDelete.AddCanvas("confirm delete worldsave buttons", SCREEN_MANAGER.white, 0, 0, 300, 40, SortType.horizontal);
                GuiElement guiElement6 = DeleteWorldSaves.MyRootMenuRev2.popupConfirmDelete.elementList.Last <GuiElement>();
                guiElement6.AddButton("Confirm", SCREEN_MANAGER.white, 0, 0, 150, 40, new BasicButton.ClickEvent(DeleteWorldSaves.MyRootMenuRev2.actionConfirmDelete), SCREEN_MANAGER.FF16, CONFIG.textColorRed);
                guiElement6.AddButton("Cancel", SCREEN_MANAGER.white, 0, 0, 150, 40, new BasicButton.ClickEvent(DeleteWorldSaves.MyRootMenuRev2.actionCancelDelete), SCREEN_MANAGER.FF16, CONFIG.textBrightColor);
                DeleteWorldSaves.MyRootMenuRev2.popupConfirmDelete.isVisible = false;
            }
        }
        //modifying WTF backdrop loading process with harmony for testing purposes

        /*
         * private static bool BACKDROPLoadPrefix(GraphicsDevice device, IServiceProvider services, ref ContentManager ___content, ref RenderTarget2D ___backdropTarget, ref RenderTarget2D ___occlusionTarget)
         * {
         *      ___content = new ContentManager(services, "Content");
         *      BACKDROP.defaultLight = default(LightSettings);
         *      BACKDROP.defaultLight.ambLightColor = new Color(0.2f, 0.2f, 0.2f, 1f);
         *      BACKDROP.defaultLight.lightIntensity = 1.3f;
         *      BACKDROP.defaultLight.lightColor = new Color(0.67f, 0.88f, 1f, 1f);
         *      BACKDROP.defaultLight.fogColor = new Color(0, 0, 0, 0);
         *      BACKDROP.defaultLight.bloomSettings = new BloomSettings(0.8f, 31f, 2.4f, 1f, 0.9f, 1f, 0.81f);
         *      BACKDROP.defaultLightShafts = new LightShaftSettings(0.11f, 1.05f, 0.9f, 0.998f, 400f);
         *      BACKDROP.stationSpawnSectors.Add(new Color(180, 180, 180));
         *      BACKDROP.stationSpawnSectors.Add(new Color(90, 90, 90));
         *      BACKDROP.stationSpawnSectors.Add(new Color(255, 200, 70));
         *      BACKDROP.stationSpawnSectors.Add(new Color(128, 100, 35));
         *
         *      //BACKDROP.makeTarget(device);
         *      if (___backdropTarget != null)
         *      {
         *              ___backdropTarget.Dispose();
         *      }
         *      if (___occlusionTarget != null)
         *      {
         *              ___occlusionTarget.Dispose();
         *      }
         *      PresentationParameters presentationParameters = device.PresentationParameters;
         *      SurfaceFormat preferredFormat = SurfaceFormat.HalfVector4;
         *      ___backdropTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height, false, preferredFormat, DepthFormat.Depth24, presentationParameters.MultiSampleCount, RenderTargetUsage.PreserveContents);
         *      ___occlusionTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height, false, SurfaceFormat.Alpha8, DepthFormat.None, presentationParameters.MultiSampleCount, RenderTargetUsage.DiscardContents);
         *
         *
         *      Dictionary<Color, BackdropExt> dictionary = new Dictionary<Color, BackdropExt>();
         *      Dictionary<Color, TerrainGenerator> dictionary2 = new Dictionary<Color, TerrainGenerator>();
         *      Dictionary<Color, LightSettings> dictionary3 = new Dictionary<Color, LightSettings>();
         *      Dictionary<Color, LightShaftSettings> dictionary4 = new Dictionary<Color, LightShaftSettings>();
         *      Dictionary<Color, string[]> dictionary5 = new Dictionary<Color, string[]>();
         *      Dictionary<Color, IconBatch> dictionary6 = new Dictionary<Color, IconBatch>();
         *      Dictionary<Color, string> dictionary7 = new Dictionary<Color, string>();
         *      if (Directory.Exists(Directory.GetCurrentDirectory() + "\\Extensions\\"))
         *      {
         *              string[] libraries = DATA_FOLDER.getLibraries();
         *              List<Assembly> list = new List<Assembly>(libraries.Length);
         *              foreach (string text in libraries)
         *              {
         *                      if (!text.Contains("WTFModLoader.dll") && !text.Contains("0Harmony.dll") && !text.Contains("Newtonsoft.Json.dll") && !text.Contains("SimpleInjector.dll"))
         *                      {
         *                              try
         *                              {
         *                                      Assembly item = Assembly.UnsafeLoadFrom(text);
         *                                      list.Add(item);
         *                              }
         *                              catch
         *                              {
         *                                      SCREEN_MANAGER.debug1 = "failed to load an extension:" + text;
         *                              }
         *                      }
         *              }
         *              Type typeFromHandle = typeof(ExtensionLoader);
         *              List<Type> list2 = new List<Type>();
         *              foreach (Assembly assembly in list)
         *              {
         *                      if (assembly != null)
         *                      {
         *                              try
         *                              {
         *                                      foreach (Type type in assembly.GetTypes())
         *                                      {
         *                                              if (!type.IsInterface && !type.IsAbstract && type.GetInterface(typeFromHandle.FullName) != null)
         *                                              {
         *                                                      list2.Add(type);
         *                                              }
         *                                      }
         *                              }
         *                              catch
         *                              {
         *                                      SCREEN_MANAGER.debug1 += "Skipped loading extension with invalid format/n";
         *                              }
         *                      }
         *              }
         *              List<ExtensionLoader> list3 = new List<ExtensionLoader>(list2.Count);
         *              foreach (Type type2 in list2)
         *              {
         *                      ExtensionLoader item2 = (ExtensionLoader)Activator.CreateInstance(type2);
         *                      list3.Add(item2);
         *              }
         *              BACKDROP.preloadRequired = new List<Color>();
         *              BACKDROP.sectorArt = new Dictionary<string, TextureBatch>();
         *              foreach (ExtensionLoader extensionLoader in list3)
         *              {
         *                      if (CONFIG.debugExtensions)
         *                      {
         *                              extensionLoader.load(dictionary, BACKDROP.sectorArt, dictionary2, dictionary3, dictionary4, dictionary5, BACKDROP.preloadRequired, dictionary6, dictionary7, BACKDROP.mapDataFiles, BACKDROP.interestIcons, BACKDROP.mapInfo);
         *                      }
         *                      else
         *                      {
         *                              try
         *                              {
         *                                      extensionLoader.load(dictionary, BACKDROP.sectorArt, dictionary2, dictionary3, dictionary4, dictionary5, BACKDROP.preloadRequired, dictionary6, dictionary7, BACKDROP.mapDataFiles, BACKDROP.interestIcons, BACKDROP.mapInfo);
         *                              }
         *                              catch (Exception ex)
         *                              {
         *                                      SCREEN_MANAGER.debug1 = SCREEN_MANAGER.debug1 + "\nFailed to load an extension:\n" + ex.Message;
         *                              }
         *                      }
         *              }
         *              //BACKDROP.getBackdopData();
         *              BACKDROP.mapData = new Dictionary<Rectangle, string>();
         *              if (BACKDROP.mapDataFiles != null && BACKDROP.mapDataFiles.Count > 0)
         *              {
         *                      string[] array = BACKDROP.mapDataFiles.ToArray();
         *                      for (int i = 0; i < array.Length; i++)
         *                      {
         *                              try
         *                              {
         *                                      if (File.Exists(array[i]))
         *                                      {
         *                                              string[] array2 = Path.GetFileNameWithoutExtension(array[i]).Split(new char[]
         *                                              {
         *                                              '_'
         *                                              });
         *                                              int x = int.Parse(array2[0]);
         *                                              int y = int.Parse(array2[1]);
         *                                              using (FileStream fileStream = new FileStream(array[i], FileMode.Open, FileAccess.Read))
         *                                              {
         *                                                      BitmapFrame bitmapFrame = new PngBitmapDecoder(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default).Frames[0];
         *                                                      int pixelWidth = bitmapFrame.PixelWidth;
         *                                                      int pixelHeight = bitmapFrame.PixelHeight;
         *                                                      Rectangle key = new Rectangle(x, y, pixelWidth, pixelHeight);
         *                                                      BACKDROP.mapData[key] = array[i];
         *                                              }
         *                                      }
         *                              }
         *                              catch
         *                              {
         *                              }
         *                      }
         *              }
         *
         *      }
         *      foreach (Color color in dictionary.Keys)
         *      {
         *              UniversalBackdrop universalBackdrop = new UniversalBackdrop(dictionary[color]);
         *              universalBackdrop.onFirstLoad(color, device, new ModDataTextureFinder());
         *              try
         *              {
         *                      BACKDROP.addBackdrop(color, universalBackdrop);
         *              }
         *              catch (Exception ex2)
         *              {
         *                      SCREEN_MANAGER.debug1 = SCREEN_MANAGER.debug1 + ex2.Message + "\n";
         *              }
         *      }
         *      foreach (Color color2 in dictionary2.Keys)
         *      {
         *              TerrainGenerator mod = dictionary2[color2];
         *              try
         *              {
         *                      BACKDROP.addGenerator(color2, mod);
         *              }
         *              catch (Exception ex3)
         *              {
         *                      SCREEN_MANAGER.debug1 = SCREEN_MANAGER.debug1 + ex3.Message + "\n";
         *              }
         *      }
         *      foreach (Color color3 in dictionary3.Keys)
         *      {
         *              LightSettings mod2 = dictionary3[color3];
         *              try
         *              {
         *                      BACKDROP.addLightSettings(color3, mod2);
         *              }
         *              catch (Exception ex4)
         *              {
         *                      SCREEN_MANAGER.debug1 = SCREEN_MANAGER.debug1 + ex4.Message + "\n";
         *              }
         *      }
         *      foreach (Color color4 in dictionary4.Keys)
         *      {
         *              LightShaftSettings mod3 = dictionary4[color4];
         *              try
         *              {
         *                      BACKDROP.addLightShaftSettings(color4, mod3);
         *              }
         *              catch (Exception ex5)
         *              {
         *                      SCREEN_MANAGER.debug1 = SCREEN_MANAGER.debug1 + ex5.Message + "\n";
         *              }
         *      }
         *      foreach (Color color5 in dictionary5.Keys)
         *      {
         *              string[] mod4 = dictionary5[color5];
         *              try
         *              {
         *                      BACKDROP.addAudioSettings(color5, mod4);
         *              }
         *              catch (Exception ex6)
         *              {
         *                      SCREEN_MANAGER.debug1 = SCREEN_MANAGER.debug1 + ex6.Message + "\n";
         *              }
         *      }
         *      foreach (Color color6 in dictionary6.Keys)
         *      {
         *              IconBatch mod5 = dictionary6[color6];
         *              try
         *              {
         *                      BACKDROP.addIcon(color6, mod5);
         *              }
         *              catch (Exception ex7)
         *              {
         *                      SCREEN_MANAGER.debug1 = SCREEN_MANAGER.debug1 + ex7.Message + "\n";
         *              }
         *      }
         *      foreach (Color color7 in dictionary7.Keys)
         *      {
         *              string mod6 = dictionary7[color7];
         *              try
         *              {
         *                      BACKDROP.addIconTechnique(color7, mod6);
         *              }
         *              catch (Exception ex8)
         *              {
         *                      SCREEN_MANAGER.debug1 = SCREEN_MANAGER.debug1 + ex8.Message + "\n";
         *              }
         *      }
         *      foreach (string key in BACKDROP.sectorArt.Keys)
         *      {
         *              BACKDROP.sectorArt[key].onFirstLoad(new ModDataTextureFinder());
         *      }
         *      return false;
         * }
         */

        private static void RootMenuRev2ConstructorPostfix(RootMenuRev2 __instance, ref int ___coreMenuWidth)
        {
            WTFRootMenu.instance = __instance;
            WTFRootMenu.mods     = new WidgetMods(new WidgetMods.CloseEvent(WTFRootMenu.closeSettings));
            ___coreMenuWidth    += 124;
        }